summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Brinkmann <mb@g10code.com>2009-11-25 17:55:26 +0000
committerMarcus Brinkmann <mb@g10code.com>2009-11-25 17:55:26 +0000
commitb41cc03c891deac4bb35af3c88f8b635ebfb632c (patch)
treeccf200bd7e05c36da7a9ccf04a9b0e8bd9464be8
parentabcfd15596e44ada3ff58a6510639f9760b98b61 (diff)
downloadlibassuan-b41cc03c891deac4bb35af3c88f8b635ebfb632c.tar.gz
doc/
2009-11-25 Marcus Brinkmann <marcus@g10code.de> * assuan.texi (Data Types): Document assuan_fdopen. src/ 2009-11-25 Marcus Brinkmann <marcus@g10code.de> * assuan.h (assuan_init_pipe_server): Change type of filedes to assuan_fd_t. (assuan_fdopen): New prototype. * libassuan.vers, libassuan.def: Add assuan_fdopen. * system.c (assuan_fdopen): New function. * assuan-pipe-server.c (assuan_init_pipe_server): Change type of filedes to assuan_fd_t. No longer translate fd to handle. Don't set to binary either (that doesn't do anything for handles, it only affects the libc fd).
-rw-r--r--NEWS2
-rw-r--r--doc/ChangeLog4
-rw-r--r--doc/assuan.texi18
-rw-r--r--src/ChangeLog12
-rw-r--r--src/assuan-pipe-server.c11
-rw-r--r--src/assuan.h5
-rw-r--r--src/libassuan.def1
-rw-r--r--src/libassuan.vers1
-rw-r--r--src/system.c21
9 files changed, 61 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 61212ab..f16d56c 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,8 @@ assuan_pipe_connect CHANGED: Take ctx arg instead of pointer to ctx.
assuan_pipe_connect_ext REMOVED
assuan_init_pipe_server CHANGED: Take ctx arg instead of pointer to ctx.
CHANGED: Swallows fds (are closed at end).
+ CHANGED: Take assuan_fd_t.
+assuan_fdopen NEW
assuan_set_io_hooks REMOVED: Will come back in expanded form.
assuan_io_hooks_t REMOVED: Will come back in expanded form.
assuan_io_monitor_t CHANGED: Add a hook data argument.
diff --git a/doc/ChangeLog b/doc/ChangeLog
index b64b303..c647072 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2009-11-25 Marcus Brinkmann <marcus@g10code.de>
+
+ * assuan.texi (Data Types): Document assuan_fdopen.
+
2009-11-24 Marcus Brinkmann <marcus@g10code.de>
* assuan.texi: Remove assuan_disconnect, assuan_deinit_server.
diff --git a/doc/assuan.texi b/doc/assuan.texi
index 66e6907..914ffd9 100644
--- a/doc/assuan.texi
+++ b/doc/assuan.texi
@@ -556,13 +556,21 @@ used to specify invalid Assuan file descriptors.
@end deftp
+@deftypefun assuan_fd_t assuan_fdopen (@w{int @var{fd}})
+Create an assuan file descriptor from a POSIX (libc) file descriptor
+@var{fd}. On Unix, this is equivalent to @code{dup}, while on Windows
+this will retrieve the underlying system handle with
+@code{_get_osfhandle} and duplicate that.
+@end deftypefun
+
+
@node Initializing the library
@section Initializing the library
In general the library requires no initialization. There are however
some initialization hooks provided which are often useful. These
should be called as early as possible and in a multi-threaded
-application before a second thread is created.
+application before a second thread is created.
These functions initialize default values that are used at context
creation with @code{assuan_new}. As there can only be one default,
@@ -1194,10 +1202,10 @@ command_handler (int fd)
if (fd == -1)
@{
- int filedes[2];
+ assuan_fd_t filedes[2];
- filedes[0] = 0;
- filedes[1] = 1;
+ filedes[0] = assuan_fd_from_posix (0);
+ filedes[1] = assuan_fd_from_posix (1);
rc = assuan_init_pipe_server (&ctx, filedes);
@}
else
@@ -1216,7 +1224,7 @@ code assumes that the server's @code{stdin} and @code{stdout} file
handles are connected to a pipe. The initialization is thus done
using the function:
-@deftypefun gpg_error_t assuan_init_pipe_server (@w{assuan_context_t *@var{r_ctx}}, @w{int @var{filedes}[2]})
+@deftypefun gpg_error_t assuan_init_pipe_server (@w{assuan_context_t *@var{r_ctx}}, @w{assuan_fd_t @var{filedes}[2]})
The function takes the two file descriptors from @var{filedes} and
returns a new Assuan context at @var{r_ctx}. As usual, a return value
diff --git a/src/ChangeLog b/src/ChangeLog
index ce14714..83c91db 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
+2009-11-25 Marcus Brinkmann <marcus@g10code.de>
+
+ * assuan.h (assuan_init_pipe_server): Change type of filedes to
+ assuan_fd_t.
+ (assuan_fdopen): New prototype.
+ * libassuan.vers, libassuan.def: Add assuan_fdopen.
+ * system.c (assuan_fdopen): New function.
+ * assuan-pipe-server.c (assuan_init_pipe_server): Change type of
+ filedes to assuan_fd_t. No longer translate fd to handle. Don't
+ set to binary either (that doesn't do anything for handles, it
+ only affects the libc fd).
+
2009-11-24 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (struct _assuan_peercred) [_WIN32]: Define dummy member
diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c
index f195697..cb15de4 100644
--- a/src/assuan-pipe-server.c
+++ b/src/assuan-pipe-server.c
@@ -51,7 +51,7 @@ is_valid_socket (const char *s)
/* This actually is a int file descriptor (and not assuan_fd_t) as
_get_osfhandle is called on W32 systems. */
gpg_error_t
-assuan_init_pipe_server (assuan_context_t ctx, int filedes[2])
+assuan_init_pipe_server (assuan_context_t ctx, assuan_fd_t filedes[2])
{
const char *s;
unsigned long ul;
@@ -65,13 +65,8 @@ assuan_init_pipe_server (assuan_context_t ctx, int filedes[2])
return rc;
#ifdef HAVE_W32_SYSTEM
- /* MS Windows has so many different types of handle that one needs
- to tranlsate them at many place forth and back. Also make sure
- that the file descriptors are in binary mode. */
- setmode (filedes[0], O_BINARY);
- setmode (filedes[1], O_BINARY);
- infd = (void*)_get_osfhandle (filedes[0]);
- outfd = (void*)_get_osfhandle (filedes[1]);
+ infd = filedes[0];
+ outfd = filedes[1];
#else
s = getenv ("_assuan_connection_fd");
if (s && *s && is_valid_socket (s))
diff --git a/src/assuan.h b/src/assuan.h
index 33afc63..0fb1795 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -91,6 +91,8 @@ typedef int assuan_fd_t;
#define ASSUAN_INVALID_PID ((pid_t) -1)
#endif
+assuan_fd_t assuan_fdopen (int fd);
+
/* Assuan features an emulation of Unix domain sockets based on a
local TCP connections. To implement access permissions based on
@@ -358,7 +360,8 @@ gpg_error_t assuan_close_output_fd (assuan_context_t ctx);
/*-- assuan-pipe-server.c --*/
-gpg_error_t assuan_init_pipe_server (assuan_context_t ctx, int filedes[2]);
+gpg_error_t assuan_init_pipe_server (assuan_context_t ctx,
+ assuan_fd_t filedes[2]);
/*-- assuan-socket-server.c --*/
#define ASSUAN_SOCKET_SERVER_FDPASSING 1
diff --git a/src/libassuan.def b/src/libassuan.def
index ccb774b..510d081 100644
--- a/src/libassuan.def
+++ b/src/libassuan.def
@@ -92,6 +92,7 @@ EXPORTS
__assuan_socketpair @71
__assuan_spawn @72
__assuan_usleep @73
+ assuan_fdopen @74
; END
diff --git a/src/libassuan.vers b/src/libassuan.vers
index 722caa3..587127e 100644
--- a/src/libassuan.vers
+++ b/src/libassuan.vers
@@ -29,6 +29,7 @@ LIBASSUAN_1.0 {
assuan_command_parse_fd;
assuan_ctx_set_system_hooks;
assuan_end_confidential;
+ assuan_fdopen;
assuan_get_active_fds;
assuan_get_assuan_log_prefix;
assuan_get_command_name;
diff --git a/src/system.c b/src/system.c
index ab9e5a1..852ec11 100644
--- a/src/system.c
+++ b/src/system.c
@@ -44,6 +44,27 @@
#endif
+assuan_fd_t
+assuan_fdopen (int fd)
+{
+#ifdef HAVE_W32_SYSTEM
+ assuan_fd_t ifd = (assuan_fd_t) _get_osfhandle (fd);
+ assuan_fd_t ofd;
+
+ if (! DuplicateHandle(GetCurrentProcess(), hfd,
+ GetCurrentProcess(), &ofd, 0,
+ TRUE, DUPLICATE_SAME_ACCESS))
+ {
+ errno = EIO;
+ return ASSUAN_INVALID_FD:
+ }
+ return ofd;
+#else
+ return dup (fd);
+#endif
+}
+
+
/* Manage memory specific to a context. */
void *