[svn] assuan - r401 - in trunk: contrib contrib/conf-w32ce-msc src
svn author wk
cvs at cvs.gnupg.org
Tue Dec 14 12:21:26 CET 2010
Author: wk
Date: 2010-12-14 12:21:25 +0100 (Tue, 14 Dec 2010)
New Revision: 401
Modified:
trunk/contrib/ChangeLog
trunk/contrib/conf-w32ce-msc/config.h
trunk/src/ChangeLog
trunk/src/assuan-socket-connect.c
trunk/src/gpgcedev.c
trunk/src/gpgcemgr.c
Log:
Typo fixes.
Improved gpgcemgr
Modified: trunk/contrib/ChangeLog
===================================================================
--- trunk/contrib/ChangeLog 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/contrib/ChangeLog 2010-12-14 11:21:25 UTC (rev 401)
@@ -6,6 +6,8 @@
2010-11-15 Werner Koch <wk at g10code.com>
+ * conf-w32ce-msc/config.h (strdup, strcasecmp): Add macros.
+
* conf-w32ce-msc/build.mk (copy-static-source): Create stdint.h.
(all): Add ws2.lib
(clean): New.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/src/ChangeLog 2010-12-14 11:21:25 UTC (rev 401)
@@ -1,3 +1,8 @@
+2010-12-14 Werner Koch <wk at g10code.com>
+
+ * gpgcemgr.c (wchar_to_utf8, utf8_to_wchar, set_show_registry): New.
+ (main): Add commands --gpgme-log and --gnupg-log.
+
2010-11-17 Marcus Brinkmann <mb at g10code.com>
* vasprintf.c (int_vasprintf) [HAVE_W32CE_SYSTEM && _MSC_VER]:
Modified: trunk/contrib/conf-w32ce-msc/config.h
===================================================================
--- trunk/contrib/conf-w32ce-msc/config.h 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/contrib/conf-w32ce-msc/config.h 2010-12-14 11:21:25 UTC (rev 401)
@@ -179,6 +179,10 @@
/* snprintf is not part of oldnames.lib thus we redefine it here. */
#define snprintf _snprintf
+/* We also need to define these functions. */
+#define strdup _strdup
+#define strcasecmp _stricmp
+
#endif /*_ASSUAN_CONFIG_H_INCLUDED*/
Modified: trunk/src/assuan-socket-connect.c
===================================================================
--- trunk/src/assuan-socket-connect.c 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/src/assuan-socket-connect.c 2010-12-14 11:21:25 UTC (rev 401)
@@ -116,7 +116,7 @@
assuan://[<ip6addr>]:<port>
Connect using TCP to PORT of the server with the numerical
- IPADDR. Not that the '[' and ']' are literal characters.
+ IPADDR. Note that '[' and ']' are literal characters.
*/
gpg_error_t
Modified: trunk/src/gpgcedev.c
===================================================================
--- trunk/src/gpgcedev.c 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/src/gpgcedev.c 2010-12-14 11:21:25 UTC (rev 401)
@@ -1464,8 +1464,8 @@
}
if (opnctx->is_log)
{
- log_debug ("GPG_IOControl (ctx=%i): error: invalid code for log device\n",
- opnctx_arg);
+ log_debug ("GPG_IOControl (ctx=%i): error: invalid code %u"
+ " for log device\n", opnctx_arg, (unsigned int)code);
SetLastError (ERROR_INVALID_PARAMETER);
goto leave;
}
Modified: trunk/src/gpgcemgr.c
===================================================================
--- trunk/src/gpgcemgr.c 2010-11-17 16:49:53 UTC (rev 400)
+++ trunk/src/gpgcemgr.c 2010-12-14 11:21:25 UTC (rev 401)
@@ -30,17 +30,67 @@
#define GPGCEDEV_PREFIX L"GPG"
+static char *
+wchar_to_utf8 (const wchar_t *string)
+{
+ int n;
+ size_t length = wcslen (string);
+ char *result;
+
+ n = WideCharToMultiByte (CP_UTF8, 0, string, length, NULL, 0, NULL, NULL);
+ if (n < 0 || (n+1) <= 0)
+ abort ();
+
+ result = malloc (n+1);
+ if (!result)
+ abort ();
+ n = WideCharToMultiByte (CP_ACP, 0, string, length, result, n, NULL, NULL);
+ if (n < 0)
+ abort ();
+
+ result[n] = 0;
+ return result;
+}
+
+
+static wchar_t *
+utf8_to_wchar (const char *string)
+{
+ int n;
+ size_t nbytes;
+ wchar_t *result;
+
+ if (!string)
+ abort ();
+
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
+ if (n < 0)
+ abort ();
+ nbytes = (size_t)(n+1) * sizeof(*result);
+ if (nbytes / sizeof(*result) != (n+1))
+ abort ();
+ result = malloc (nbytes);
+ if (!result)
+ abort ();
+
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
+ if (n < 0)
+ abort ();
+ return result;
+}
+
+
static int
install (void)
{
HKEY handle;
DWORD disp, dw;
+ int rc;
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME, 0, NULL, 0,
- KEY_WRITE, NULL, &handle, &disp))
+ if ((rc=RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME, 0, NULL, 0,
+ KEY_WRITE, NULL, &handle, &disp)))
{
- fprintf (stderr, PGM": error creating registry key 1: rc=%d\n",
- (int)GetLastError ());
+ fprintf (stderr, PGM": error creating registry key 1: rc=%d\n", rc);
return 1;
}
@@ -56,11 +106,10 @@
fprintf (stderr, PGM": registry key 1 created\n");
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME2, 0, NULL, 0,
- KEY_WRITE, NULL, &handle, &disp))
+ if ((rc=RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME2, 0, NULL, 0,
+ KEY_WRITE, NULL, &handle, &disp)))
{
- fprintf (stderr, PGM": error creating registry key 2: rc=%d\n",
- (int)GetLastError ());
+ fprintf (stderr, PGM": error creating registry key 2: rc=%d\n", rc);
return 1;
}
@@ -128,12 +177,12 @@
{
HKEY handle;
DWORD disp;
+ int rc;
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME, 0, NULL, 0,
- KEY_WRITE, NULL, &handle, &disp))
+ if ((rc=RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME, 0, NULL, 0,
+ KEY_WRITE, NULL, &handle, &disp)))
{
- fprintf (stderr, PGM": error creating debug registry key: rc=%d\n",
- (int)GetLastError ());
+ fprintf (stderr, PGM": error creating debug registry key: rc=%d\n", rc);
return 1;
}
@@ -149,12 +198,12 @@
{
HKEY handle;
DWORD disp;
+ int rc;
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME2, 0, NULL, 0,
- KEY_WRITE, NULL, &handle, &disp))
+ if ((rc=RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME2, 0, NULL, 0,
+ KEY_WRITE, NULL, &handle, &disp)))
{
- fprintf (stderr, PGM": error creating debug registry key: rc=%d\n",
- (int)GetLastError ());
+ fprintf (stderr, PGM": error creating debug registry key: rc=%d\n", rc);
return 1;
}
@@ -335,6 +384,79 @@
}
#endif
+
+static void
+set_show_registry (const wchar_t *key, const wchar_t *name, const char *value)
+{
+ HKEY handle;
+ DWORD disp, nbytes, n1, type;
+ int rc;
+
+ if ((rc=RegCreateKeyEx (HKEY_LOCAL_MACHINE, key, 0, NULL, 0,
+ KEY_WRITE, NULL, &handle, &disp)))
+ {
+ fprintf (stderr, PGM": error creating registry key: rc=%d\n", rc);
+ return;
+ }
+
+ if (value && !stricmp (value, "none"))
+ {
+ if ((rc=RegDeleteValue (handle, name)))
+ fprintf (stderr, PGM": error deleting registry value: rc=%d\n", rc);
+ }
+ else if (value)
+ {
+ wchar_t *tmp = utf8_to_wchar (value);
+ if ((rc=RegSetValueEx (handle, name, 0, REG_SZ,
+ (void*)tmp, wcslen (tmp)*sizeof(wchar_t))))
+ fprintf (stderr, PGM": error setting registry value: rc=%d\n", rc);
+ free (tmp);
+ }
+ else
+ {
+ nbytes = 2;
+ if ((rc=RegQueryValueEx (handle, name, 0, NULL, NULL, &nbytes)))
+ {
+ if (rc == ERROR_FILE_NOT_FOUND)
+ fprintf (stderr, PGM": registry value not set\n");
+ else
+ fprintf (stderr, PGM": error reading registry value: rc=%d\n", rc);
+ }
+ else
+ {
+ char *result = malloc ((n1=nbytes+2));
+ if (!result)
+ fprintf (stderr, PGM": malloc failed: rc=%d\n",
+ (int)GetLastError ());
+ else if ((rc=RegQueryValueEx (handle, name, 0, &type,
+ (void*)result, &n1)))
+ {
+ fprintf (stderr, PGM": error reading registry value (2): "
+ "rc=%d\n", rc);
+ free (result);
+ }
+ else
+ {
+ result[nbytes] = 0; /* Make sure it is a string. */
+ result[nbytes+1] = 0;
+ if (type == REG_SZ)
+ {
+ wchar_t *tmp = (void*)result;
+ result = wchar_to_utf8 (tmp);
+ free (tmp);
+ printf ("%s\n", result);
+ }
+ else
+ fprintf (stderr, PGM": registry value is not a string\n");
+ free (result);
+ }
+ }
+ }
+
+ RegCloseKey (handle);
+}
+
+
int
main (int argc, char **argv)
@@ -427,7 +549,7 @@
DWORD nwritten;
int i;
- for (i=0; i < 5; i++)
+ for (i=0; i < 3; i++)
{
if (!WriteFile (hd, marktwain, strlen (marktwain),
&nwritten, NULL))
@@ -449,9 +571,30 @@
result = enable_log (1);
else if (argc > 1 && !strcmp (argv[1], "--disable-log"))
result = enable_log (0);
- else
+ else if (argc > 1 && !strcmp (argv[1], "--gpgme-log"))
+ set_show_registry (L"Software\\GNU\\gpgme", L"debug",
+ argc > 2? argv[2] : NULL);
+ else if (argc > 1 && !strcmp (argv[1], "--gnupg-log"))
+ set_show_registry (L"Software\\GNU\\GnuPG", L"DefaultLogFile",
+ argc > 2? argv[2] : NULL);
+ else
{
- fprintf (stderr, "usage: " PGM " --register|--deactivate|--activate\n");
+ fprintf (stderr,
+ "usage: " PGM " COMMAND\n"
+ "Commands are:\n"
+ " --register Register the GPGCEDEV device\n"
+ " --deactivate Deactivate the GPGCEDEV device\n"
+ " --activate Activate the GPGCEDEV devive\n"
+ " --enable-debug Enable debugging of GPGCEDEV device\n"
+ " --disable-debug Disable debugging of GPGCEDEV device\n"
+ " --gravity Show output of the gravity sensor\n"
+ " --enable-log Enable logging via \"GPG2:\"\n"
+ " --disable-log Disable logging via \"GPG2:\"\n"
+ " --log Write a test string to \"GPG2:\"\n"
+ " --gpgme-log [ARG] Show or set GPGME log output\n"
+ " --gnupg-log [ARG] Show or set GnuPG default log file\n"
+ " (No ARG shows, \"none\" disables)\n"
+ );
result = 1;
}
More information about the Gnupg-commits
mailing list