[svn] assuan - r322 - in trunk: . doc src

svn author marcus cvs at cvs.gnupg.org
Wed Nov 25 18:55:27 CET 2009


Author: marcus
Date: 2009-11-25 18:55:26 +0100 (Wed, 25 Nov 2009)
New Revision: 322

Modified:
   trunk/NEWS
   trunk/doc/ChangeLog
   trunk/doc/assuan.texi
   trunk/src/ChangeLog
   trunk/src/assuan-pipe-server.c
   trunk/src/assuan.h
   trunk/src/libassuan.def
   trunk/src/libassuan.vers
   trunk/src/system.c
Log:
doc/
2009-11-25  Marcus Brinkmann  <marcus at g10code.de>

	* assuan.texi (Data Types): Document assuan_fdopen.

src/
2009-11-25  Marcus Brinkmann  <marcus at 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).


Modified: trunk/doc/ChangeLog
===================================================================
--- trunk/doc/ChangeLog	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/doc/ChangeLog	2009-11-25 17:55:26 UTC (rev 322)
@@ -1,3 +1,7 @@
+2009-11-25  Marcus Brinkmann  <marcus at g10code.de>
+
+	* assuan.texi (Data Types): Document assuan_fdopen.
+
 2009-11-24  Marcus Brinkmann  <marcus at g10code.de>
 
 	* assuan.texi: Remove assuan_disconnect, assuan_deinit_server.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/ChangeLog	2009-11-25 17:55:26 UTC (rev 322)
@@ -1,3 +1,15 @@
+2009-11-25  Marcus Brinkmann  <marcus at 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 at g10code.de>
 
 	* assuan.h (struct _assuan_peercred) [_WIN32]: Define dummy member

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/NEWS	2009-11-25 17:55:26 UTC (rev 322)
@@ -55,6 +55,8 @@
 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.

Modified: trunk/doc/assuan.texi
===================================================================
--- trunk/doc/assuan.texi	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/doc/assuan.texi	2009-11-25 17:55:26 UTC (rev 322)
@@ -556,13 +556,21 @@
 @end deftp
 
 
+ at deftypefun assuan_fd_t assuan_fdopen (@w{int @var{fd}})
+Create an assuan file descriptor from a POSIX (libc) file descriptor
+ at var{fd}.  On Unix, this is equivalent to @code{dup}, while on Windows
+this will retrieve the underlying system handle with
+ at code{_get_osfhandle} and duplicate that.
+ at 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 @@
 
   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 @@
 handles are connected to a pipe.  The initialization is thus done
 using the function:
 
- at deftypefun gpg_error_t assuan_init_pipe_server (@w{assuan_context_t *@var{r_ctx}}, @w{int @var{filedes}[2]})
+ at 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

Modified: trunk/src/assuan-pipe-server.c
===================================================================
--- trunk/src/assuan-pipe-server.c	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/assuan-pipe-server.c	2009-11-25 17:55:26 UTC (rev 322)
@@ -51,7 +51,7 @@
 /* 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 @@
     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))

Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/assuan.h	2009-11-25 17:55:26 UTC (rev 322)
@@ -91,7 +91,9 @@
 #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
    file permissions a nonce is used which is expected by th server as
@@ -358,7 +360,8 @@
 
 
 /*-- 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

Modified: trunk/src/libassuan.def
===================================================================
--- trunk/src/libassuan.def	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/libassuan.def	2009-11-25 17:55:26 UTC (rev 322)
@@ -92,6 +92,7 @@
     __assuan_socketpair			@71
     __assuan_spawn			@72
     __assuan_usleep			@73
+    assuan_fdopen			@74
 
 ; END
 

Modified: trunk/src/libassuan.vers
===================================================================
--- trunk/src/libassuan.vers	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/libassuan.vers	2009-11-25 17:55:26 UTC (rev 322)
@@ -29,6 +29,7 @@
     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;

Modified: trunk/src/system.c
===================================================================
--- trunk/src/system.c	2009-11-24 17:46:57 UTC (rev 321)
+++ trunk/src/system.c	2009-11-25 17:55:26 UTC (rev 322)
@@ -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 *




More information about the Gnupg-commits mailing list