[Gpg4win-commits] r464 - in trunk: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Aug 13 06:11:28 CEST 2007
Author: marcus
Date: 2007-08-13 06:11:27 +0200 (Mon, 13 Aug 2007)
New Revision: 464
Modified:
trunk/ChangeLog
trunk/src/g4wihelp.c
trunk/src/inst-gnupg.nsi
Log:
2007-08-13 Marcus Brinkmann <marcus at g10code.de>
* src/g4wihelp.c (config_init, config_fetch): New functions.
* src/inst-gnupg.nsi: Install gpg.conf AppData if configured.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-08-10 15:11:06 UTC (rev 463)
+++ trunk/ChangeLog 2007-08-13 04:11:27 UTC (rev 464)
@@ -1,3 +1,8 @@
+2007-08-13 Marcus Brinkmann <marcus at g10code.de>
+
+ * src/g4wihelp.c (config_init, config_fetch): New functions.
+ * src/inst-gnupg.nsi: Install gpg.conf AppData if configured.
+
2007-08-10 Marcus Brinkmann <marcus at g10code.de>
* patches/claws-mail-3.0.0-rc2/01-w32-logo.patch,
Modified: trunk/src/g4wihelp.c
===================================================================
--- trunk/src/g4wihelp.c 2007-08-10 15:11:06 UTC (rev 463)
+++ trunk/src/g4wihelp.c 2007-08-13 04:11:27 UTC (rev 464)
@@ -577,3 +577,238 @@
return;
}
+
+#include <stdio.h>
+
+/* Extract config file parameters. FIXME: Not particularly robust.
+ We expect some reasonable formatting. The parser below is very
+ limited. It expects a command line option /c=FILE or /C=FILE,
+ where FILE must be enclosed in double-quotes if it contains spaces.
+ That file should contain a single section [gpg4win] and KEY=VALUE
+ pairs for each additional configuration file to install. Comments
+ are supported only on lines by themselves. VALUE can be quoted in
+ double-quotes, but does not need to be, unless it has whitespace at
+ the beginning or end. KEY can, for example, be "gpg.conf" (without
+ the quotes). */
+void
+config_init (HWND hwndParent, int string_size, char *variables,
+ stack_t **stacktop, extra_parameters_t *extra,
+ char **keys, char **values, int max)
+{
+ /* First, parse the command line. */
+ char *cmdline;
+ char *begin = NULL;
+ char *end = NULL;
+ char mark;
+ char *fname;
+ char *ptr;
+ FILE *conf;
+
+ *keys = NULL;
+ *values = NULL;
+
+ cmdline = getuservariable (INST_CMDLINE);
+
+ mark = (*cmdline == '"') ? (cmdline++, '"') : ' ';
+ while (*cmdline && *cmdline != mark)
+ cmdline++;
+ if (mark == '"' && *cmdline)
+ cmdline++;
+ while (*cmdline && *cmdline == ' ')
+ cmdline++;
+
+ while (*cmdline)
+ {
+ /* We are at the beginning of a new argument. */
+ if (cmdline[0] == '/' && (cmdline[1] == 'C' || cmdline[1] == 'c')
+ && cmdline[2] == '=')
+ {
+ cmdline += 3;
+ begin = cmdline;
+ }
+
+ while (*cmdline && *cmdline != ' ')
+ {
+ /* Skip over quoted parts. */
+ if (*cmdline == '"')
+ {
+ cmdline++;
+ while (*cmdline && *cmdline != '"')
+ cmdline++;
+ if (*cmdline)
+ cmdline++;
+ }
+ else
+ cmdline++;
+ }
+ if (begin && !end)
+ {
+ end = cmdline - 1;
+ break;
+ }
+ }
+
+ if (!begin || begin > end)
+ return;
+
+ /* Strip quotes. */
+ if (*begin == '"' && *end == '"')
+ {
+ begin++;
+ end--;
+ }
+ if (begin > end)
+ return;
+
+ fname = malloc (end - begin + 2);
+ if (!fname)
+ return;
+
+ ptr = fname;
+ while (begin <= end)
+ *(ptr++) = *(begin++);
+ *ptr = '\0';
+
+ conf = fopen (fname, "r");
+ free (fname);
+ if (!conf)
+ return;
+
+ while (max - 1 > 0)
+ {
+ char line[256];
+ char *ptr2;
+
+ if (fgets (line, sizeof (line), conf) == NULL)
+ break;
+ ptr = &line[strlen (line)];
+ while (ptr > line && (ptr[-1] == '\n' || ptr[-1] == '\r'
+ || ptr[-1] == ' ' || ptr[-1] == '\t'))
+ ptr--;
+ *ptr = '\0';
+
+ ptr = line;
+ while (*ptr && (*ptr == ' ' || *ptr == '\t'))
+ ptr++;
+ /* Ignore comment lines. */
+ /* FIXME: Ignore section markers. */
+ if (*ptr == '\0' || *ptr == ';' || *ptr == '[')
+ continue;
+ begin = ptr;
+ while (*ptr && *ptr != '=' && *ptr != ' ' && *ptr != '\t')
+ ptr++;
+ end = ptr - 1;
+ while (*ptr && (*ptr == ' ' || *ptr == '\t'))
+ ptr++;
+ if (*ptr != '=')
+ continue;
+ ptr++;
+
+ if (begin > end)
+ continue;
+
+ /* We found a key. */
+ *keys = malloc (end - begin + 2);
+ if (!keys)
+ return;
+ ptr2 = *keys;
+ while (begin <= end)
+ *(ptr2++) = *(begin++);
+ *ptr2 = '\0';
+
+ *values = NULL;
+
+ while (*ptr && (*ptr == ' ' || *ptr == '\t'))
+ ptr++;
+ begin = ptr;
+ /* In this case, end points to the byte after the value, which
+ is OK because that is '\0'. */
+ end = &line[strlen (line)];
+ if (begin > end)
+ begin = end;
+
+ /* Strip quotes. */
+ if (*begin == '"' && end[-1] == '"')
+ {
+ begin++;
+ end--;
+ *end = '\0';
+ }
+ if (begin > end)
+ return;
+
+ *values = malloc (end - begin + 1);
+ ptr2 = *values;
+ while (begin <= end)
+ *(ptr2++) = *(begin++);
+
+ keys++;
+ values++;
+ max--;
+ }
+
+ fclose (conf);
+ *keys = NULL;
+ *values = NULL;
+}
+
+
+void __declspec(dllexport)
+config_fetch (HWND hwndParent, int string_size, char *variables,
+ stack_t **stacktop, extra_parameters_t *extra)
+{
+ SC_HANDLE service;
+ const char *result = NULL;
+ char key[256];
+#define MAX_KEYS 64
+ int err = 0;
+ static int initialised = 0;
+ static char *keys[MAX_KEYS];
+ static char *values[MAX_KEYS];
+ int i;
+
+ g_hwndParent = hwndParent;
+ EXDLL_INIT();
+
+ /* The expected stack layout: key. */
+ if (popstring (key, sizeof (key)))
+ err = 1;
+ if (err)
+ {
+ setuservariable (INST_R0, "");
+ return;
+ }
+
+ if (initialised == 0)
+ {
+ initialised = 1;
+ config_init (hwndParent, string_size, variables,
+ stacktop, extra, keys, values, MAX_KEYS);
+ }
+
+#if 0
+ MessageBox(g_hwndParent, "Configuration File:", 0, MB_OK);
+ i = 0;
+ while (keys[i])
+ {
+ char buf[256];
+ sprintf (buf, "%s=%s\r\n", keys[i], values[i]);
+ MessageBox(g_hwndParent, buf, 0, MB_OK);
+ i++;
+ }
+#endif
+
+ i = 0;
+ while (keys[i])
+ {
+ if (!strcmp (keys[i], key))
+ {
+ setuservariable (INST_R0, values[i]);
+ return;
+ }
+ i++;
+ }
+
+ setuservariable (INST_R0, "");
+ return;
+}
Modified: trunk/src/inst-gnupg.nsi
===================================================================
--- trunk/src/inst-gnupg.nsi 2007-08-10 15:11:06 UTC (rev 463)
+++ trunk/src/inst-gnupg.nsi 2007-08-13 04:11:27 UTC (rev 464)
@@ -62,7 +62,18 @@
SetOutPath "$INSTDIR\gnupg.nls"
File "${prefix}/share/gnupg/de.mo"
+ # If requested, install the configured gpg.conf.
+ Var /GLOBAL ConfigGPGConf
+ g4wihelp::config_fetch "gpg.conf"
+ StrCpy $ConfigGPGConf $R0
+ StrCmp $ConfigGPGConf "" no_config_gpg_conf
+ ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" AppData
+ StrCmp $0 "" no_config_gpg_conf
+ SetOutPath "$0\gnupg"
+ CopyFiles $ConfigGPGConf "$0\gnupg\gpg.conf"
+ no_config_gpg_conf:
+
WriteRegStr HKLM "Software\GNU\GnuPG" "Install Directory" $INSTDIR
# Add the public directory to the PATH
More information about the Gpg4win-commits
mailing list