[svn] GpgEX - r47 - in trunk: . src
svn author marcus
cvs at cvs.gnupg.org
Tue Feb 5 00:04:13 CET 2008
Author: marcus
Date: 2008-02-05 00:04:12 +0100 (Tue, 05 Feb 2008)
New Revision: 47
Modified:
trunk/configure.ac
trunk/src/ChangeLog
trunk/src/client.cc
Log:
2008-02-04 Marcus Brinkmann <marcus at g10code.de>
* client.cc (send_one_option, getinfo_pid_cb, send_options): New
functions.
(uiserver_connect): Take new argument HWND. Call send_options.
(client_t::call_assuan): Pass window handle to uiserver_connect.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2008-01-07 22:27:04 UTC (rev 46)
+++ trunk/src/ChangeLog 2008-02-04 23:04:12 UTC (rev 47)
@@ -1,3 +1,10 @@
+2008-02-04 Marcus Brinkmann <marcus at g10code.de>
+
+ * client.cc (send_one_option, getinfo_pid_cb, send_options): New
+ functions.
+ (uiserver_connect): Take new argument HWND. Call send_options.
+ (client_t::call_assuan): Pass window handle to uiserver_connect.
+
2008-01-07 Marcus Brinkmann <marcus at g10code.de>
* client.cc (default_uiserver_cmdline): Invoke GUI server with
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2008-01-07 22:27:04 UTC (rev 46)
+++ trunk/configure.ac 2008-02-04 23:04:12 UTC (rev 47)
@@ -186,7 +186,8 @@
AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_USER_1,
[The default error source for GpgEX.])
-# We need the declaration for the function GetUserDefaultUILanguage.
+# We need the declaration for the function GetUserDefaultUILanguage
+# and AllowSetForegroundWindow.
AC_DEFINE(WINVER, 0x500, [Version of Windows API])
#
Modified: trunk/src/client.cc
===================================================================
--- trunk/src/client.cc 2008-01-07 22:27:04 UTC (rev 46)
+++ trunk/src/client.cc 2008-02-04 23:04:12 UTC (rev 47)
@@ -1,5 +1,5 @@
/* client.cc - gpgex assuan client implementation
- Copyright (C) 2007 g10 Code GmbH
+ Copyright (C) 2007, 2008 g10 Code GmbH
This file is part of GpgEX.
@@ -168,11 +168,78 @@
}
+/* Send options to the UI server and return the server's PID. */
+static gpg_error_t
+send_one_option (assuan_context_t ctx, const char *name, const char *value)
+{
+ gpg_error_t err;
+ char buffer[1024];
+
+ if (! value || ! *value)
+ err = 0; /* Avoid sending empty strings. */
+ else
+ {
+ snprintf (buffer, sizeof (buffer), "OPTION %s=%s", name, value);
+ err = assuan_transact (ctx, buffer, NULL, NULL, NULL, NULL, NULL, NULL);
+ }
+
+ return err;
+}
+
+
static int
-uiserver_connect (assuan_context_t *ctx)
+getinfo_pid_cb (void *opaque, const void *buffer, size_t length)
{
+ pid_t *pid = (pid_t *) opaque;
+
+ *pid = (pid_t) strtoul ((char *) buffer, NULL, 10);
+
+ return 0;
+}
+
+
+static gpg_error_t
+send_options (assuan_context_t ctx, HWND hwnd, pid_t *r_pid)
+{
+ gpg_error_t rc = 0;
+ char numbuf[50];
+
+ TRACE_BEG (DEBUG_ASSUAN, "client_t::send_options", ctx);
+
+ *r_pid = (pid_t) (-1);
+ rc = assuan_transact (ctx, "GETINFO pid", getinfo_pid_cb, r_pid,
+ NULL, NULL, NULL, NULL);
+ if (! rc && *r_pid == (pid_t) (-1))
+ {
+ (void) TRACE_LOG ("server did not return a PID");
+ rc = gpg_error (GPG_ERR_ASSUAN_SERVER_FAULT);
+ }
+
+ if (! rc && *r_pid != (pid_t) (-1)
+ && ! AllowSetForegroundWindow (*r_pid))
+ {
+ (void) TRACE_LOG ("AllowSetForegroundWindow (%u) failed");
+ TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
+
+ /* Ignore the error, though. */
+ }
+
+ if (! rc && hwnd)
+ {
+ snprintf (numbuf, sizeof (numbuf), "%lx", (unsigned long) hwnd);
+ rc = send_one_option (ctx, "window-id", numbuf);
+ }
+
+ return TRACE_GPGERR (rc);
+}
+
+
+static int
+uiserver_connect (assuan_context_t *ctx, HWND hwnd)
+{
int rc;
const char *socket_name = NULL;
+ pid_t pid;
TRACE_BEG (DEBUG_ASSUAN, "client_t::uiserver_connect", ctx);
@@ -205,6 +272,14 @@
break;
}
}
+
+ if (! rc)
+ {
+ rc = send_options (*ctx, hwnd, &pid);
+ assuan_disconnect (*ctx);
+ *ctx = NULL;
+ }
+
return TRACE_GPGERR (rc);
}
@@ -219,7 +294,7 @@
TRACE_BEG2 (DEBUG_ASSUAN, "client_t::call_assuan", this,
"%s on %u files", cmd, filenames.size ());
- rc = uiserver_connect (&ctx);
+ rc = uiserver_connect (&ctx, this->window);
if (rc)
goto leave;
More information about the Gnupg-commits
mailing list