[Gpa-commits] r792 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jan 18 02:21:38 CET 2008


Author: marcus
Date: 2008-01-18 02:21:37 +0100 (Fri, 18 Jan 2008)
New Revision: 792

Added:
   trunk/src/get-path.c
   trunk/src/get-path.h
Modified:
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/gpa.c
   trunk/src/helpmenu.c
   trunk/src/w32reg.c
   trunk/src/w32reg.h
Log:
2008-01-18  Marcus Brinkmann  <marcus at g10code.de>

	* Makefile.am (gpa_SOURCES): Add get-path.h and get-path.c.  Move
	w32reg.h and w32reg.c to ...
	(gpa_w32_sources): ... here.
	* get-path.h, get-path.c: New files.
	* w32reg.h, w32reg.c: Beautify.  Use g_malloc instead of malloc.
	* gpa.c: Don't include <time.h> or "w32reg.h".  Include
	<glib/gstdio.h> and "get-path.h".  Move the home dir stuff to
	get-path.c.  Beautify a bit.
	(gpa_exec_dir): Remove global variable.
	(copyright): Add g10 Code GmbH.
	(main): Don't initialize gpa_exec_dir.  Use g_mkdir instead of
	mkdir.  Move call to srand to ...
	* helpmenu.c (help_about): ... here.  Include <time.h>.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/ChangeLog	2008-01-18 01:21:37 UTC (rev 792)
@@ -1,3 +1,19 @@
+2008-01-18  Marcus Brinkmann  <marcus at g10code.de>
+
+	* Makefile.am (gpa_SOURCES): Add get-path.h and get-path.c.  Move
+	w32reg.h and w32reg.c to ...
+	(gpa_w32_sources): ... here.
+	* get-path.h, get-path.c: New files.
+	* w32reg.h, w32reg.c: Beautify.  Use g_malloc instead of malloc.
+	* gpa.c: Don't include <time.h> or "w32reg.h".  Include
+	<glib/gstdio.h> and "get-path.h".  Move the home dir stuff to
+	get-path.c.  Beautify a bit.
+	(gpa_exec_dir): Remove global variable.
+	(copyright): Add g10 Code GmbH.
+	(main): Don't initialize gpa_exec_dir.  Use g_mkdir instead of
+	mkdir.  Move call to srand to ...
+	* helpmenu.c (help_about): ... here.  Include <time.h>.
+
 2008-01-17  Marcus Brinkmann  <marcus at g10code.de>
 
 	* gpa.c (create_dialog): Switch "apply" and "reset" button.

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/Makefile.am	2008-01-18 01:21:37 UTC (rev 792)
@@ -14,7 +14,8 @@
 
 gpa_res_ldflag = -Wl,gpa-resource.o
 gpa_deps = gpa-resource.o
-gpa_w32_sources = w32-afunix.c w32-afunix.h
+gpa_w32_sources = w32reg.h w32reg.c w32-afunix.h w32-afunix.c
+
 else
 gpa_res_ldflag =
 gpa_deps =
@@ -33,7 +34,8 @@
 gpa_LDFLAGS = $(gpa_res_ldflag)
 gpa_DEPENDENCIES = $(gpa_deps)
 
-gpa_SOURCES = gpa.c gpa.h i18n.h options.h \
+gpa_SOURCES = get-path.h get-path.c \
+	      gpa.c gpa.h i18n.h options.h \
 	      gpawindowkeeper.c gpawindowkeeper.h \
 	      gtktools.c gtktools.h  \
 	      helpmenu.c helpmenu.h	  \
@@ -59,7 +61,6 @@
 	      gpapastrings.c gpapastrings.h\
 	      gpa_license.c gpa_license.h \
 	      keyserver.c keyserver.h \
-              w32reg.c w32reg.h \
 	      hidewnd.c hidewnd.h \
 	      keytable.c keytable.h \
 	      gpgmetools.h gpgmetools.c \

Added: trunk/src/get-path.c
===================================================================
--- trunk/src/get-path.c	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/get-path.c	2008-01-18 01:21:37 UTC (rev 792)
@@ -0,0 +1,209 @@
+/* get-path.c - Find a system path.
+   Copyright (C) 2000-2002 G-N-U GmbH.
+   Copyright (C) 2005, 2008 g10 Code GmbH.
+
+   This file is part of GPA.
+
+   GPA is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GPA is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GPA; if not, write to the Free Software Foundation, Inc.,
+   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glib.h>
+
+#include "get-path.h"
+
+
+#ifdef G_OS_WIN32
+
+#include <unistd.h>
+
+#include <windows.h> 
+
+#include "w32reg.h"
+
+#ifndef CSIDL_APPDATA
+#define CSIDL_APPDATA 0x001a
+#endif
+#ifndef CSIDL_LOCAL_APPDATA
+#define CSIDL_LOCAL_APPDATA 0x001c
+#endif
+#ifndef CSIDL_FLAG_CREATE
+#define CSIDL_FLAG_CREATE 0x8000
+#endif
+
+#define RTLD_LAZY 0
+
+#define DIM(v)	(sizeof (v) / sizeof ((v)[0]))
+
+
+const char *
+w32_strerror (int w32_errno)
+{
+  static char strerr[256];
+  int ec = (int) GetLastError ();
+  
+  if (w32_errno == 0)
+    w32_errno = ec;
+  FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, w32_errno,
+                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+                 strerr, DIM (strerr) - 1, NULL);
+  return strerr;
+}
+
+
+static __inline__ void *
+dlopen (const char *name, int flag)
+{
+  void *hd = LoadLibrary (name);
+  return hd;
+}
+
+
+static __inline__ void *
+dlsym (void *hd, const char *sym)
+{
+  if (hd && sym)
+    {
+      void *fnc = GetProcAddress (hd, sym);
+      if (! fnc)
+        return NULL;
+      return fnc;
+    }
+  return NULL;
+}
+
+
+static __inline__ const char *
+dlerror (void)
+{
+  return w32_strerror (0);
+}
+
+
+static __inline__ int
+dlclose (void *hd)
+{
+  if (hd)
+    {
+      FreeLibrary (hd);
+      return 0;
+    }
+  return -1;
+}  
+
+
+static HRESULT
+w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d, LPSTR e)
+{
+  static int initialized;
+  static HRESULT (WINAPI *func) (HWND, int, HANDLE, DWORD, LPSTR);
+
+  if (! initialized)
+    {
+      static char *dllnames[] = { "shell32.dll", "shfolder.dll", NULL };
+      void *handle;
+      int i;
+
+      initialized = 1;
+
+      for (i = 0, handle = NULL; ! handle && dllnames[i]; i++)
+        {
+          handle = dlopen (dllnames[i], RTLD_LAZY);
+          if (handle)
+            {
+              func = dlsym (handle, "SHGetFolderPathA");
+              if (! func)
+                {
+                  dlclose (handle);
+                  handle = NULL;
+                }
+            }
+        }
+    }
+
+  if (func)
+    return func (a, b, c, d, e);
+  else
+    return -1;
+}
+
+#endif	/* G_OS_WIN32 */
+
+
+/* Get the path to the default home directory.  */
+gchar *
+default_homedir (void)
+{
+  gchar *dir;
+
+  dir = (gchar *) g_getenv ("GNUPGHOME");
+  if (dir && dir[0])
+    dir = g_strdup (dir);
+
+#ifdef G_OS_WIN32
+
+  if (! dir)
+    {
+      dir = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG", "HomeDir");
+      if (dir && ! dir[0])
+	{
+	  g_free (dir);
+	  dir = NULL;
+	}
+    }
+	
+  if (! dir)
+    {
+      char path[MAX_PATH];
+
+      /* It might be better to use LOCAL_APPDATA because this is
+         defined as "non roaming" and thus more likely to be kept
+         locally.  For private keys this is desired.  However, given
+         that many users copy private keys anyway forth and back,
+         using a system roaming serives might be better than to let
+         them do it manually.  A security conscious user will anyway
+         use the registry entry to have better control.  */
+      if (w32_shgetfolderpath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 
+                               NULL, 0, path) >= 0)
+        {
+	  dir = g_build_filename (path, "gnupg", NULL);
+
+          /* Try to create the directory if it does not yet exists.
+             NOTE: This relies on the fact that the homedir is a
+             sub-directory of an existing directory (APPDATA).  */
+          if (access (dir, F_OK))
+            CreateDirectory (dir, NULL);
+        }
+    }
+
+  if (!dir)
+    dir = g_strdup ("C:\\gnupg");
+
+#else
+
+  if (! dir)
+    {
+      const gchar *home;
+
+      home = g_getenv ("HOME");
+      dir = g_build_filename (home ? home : "/", ".gnupg", NULL);
+    }
+
+#endif	/* ! G_OS_WIN32 */
+
+  return dir;
+}

Added: trunk/src/get-path.h
===================================================================
--- trunk/src/get-path.h	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/get-path.h	2008-01-18 01:21:37 UTC (rev 792)
@@ -0,0 +1,27 @@
+/* get-path.h - Find a system path.
+   Copyright (C) 2008 g10 Code GmbH.
+
+   This file is part of GPA.
+
+   GPA is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GPA is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifndef GET_PATH_H
+#define GET_PATH_H
+
+/* Get the path to the default home directory.  */
+gchar *default_homedir (void);
+
+#endif	/* GET_PATH_H */
+

Modified: trunk/src/gpa.c
===================================================================
--- trunk/src/gpa.c	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/gpa.c	2008-01-18 01:21:37 UTC (rev 792)
@@ -1,6 +1,6 @@
 /* gpa.c - The GNU Privacy Assistant main file.
    Copyright (C) 2000-2002 G-N-U GmbH.
-   Copyright (C) 2005 g10 Code GmbH.
+   Copyright (C) 2005, 2008 g10 Code GmbH.
 
    This file is part of GPA.
 
@@ -14,11 +14,13 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with GPA; if not, write to the Free Software Foundation, Inc.,
-   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
 
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <gtk/gtk.h>
 
@@ -26,11 +28,13 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <assert.h>
-#include <time.h>
 
 #include <gpgme.h>
 #include <getopt.h>
 
+#include <glib/gstdio.h>
+
+#include "get-path.h"
 #include "gpapastrings.h"
 #include "gpa.h"
 #include "gpawindowkeeper.h"
@@ -44,7 +48,6 @@
 #include "confdialog.h"
 
 #ifdef __MINGW32__
-#include "w32reg.h"
 #include "hidewnd.h"
 #endif
 
@@ -52,169 +55,10 @@
 #include "icons.h"
 
 /* Global variables */
-gchar *gpa_exec_dir;
 gchar *gnupg_homedir;
 int cms_hack;
 
-#ifdef G_OS_WIN32
-#include <windows.h> 
-#ifndef CSIDL_APPDATA
-#define CSIDL_APPDATA 0x001a
-#endif
-#ifndef CSIDL_LOCAL_APPDATA
-#define CSIDL_LOCAL_APPDATA 0x001c
-#endif
-#ifndef CSIDL_FLAG_CREATE
-#define CSIDL_FLAG_CREATE 0x8000
-#endif
-#define DIM(v)		     (sizeof(v)/sizeof((v)[0]))
 
-#define RTLD_LAZY 0
-const char *
-w32_strerror (int w32_errno)
-{
-  static char strerr[256];
-  int ec = (int)GetLastError ();
-
-  if (w32_errno == 0)
-    w32_errno = ec;
-  FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, w32_errno,
-                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-                 strerr, DIM (strerr)-1, NULL);
-  return strerr;
-}
-
-static __inline__ void *
-dlopen (const char * name, int flag)
-{
-  void * hd = LoadLibrary (name);
-  return hd;
-}
-
-static __inline__ void *
-dlsym (void * hd, const char * sym)
-{
-  if (hd && sym)
-    {
-      void * fnc = GetProcAddress (hd, sym);
-      if (!fnc)
-        return NULL;
-      return fnc;
-    }
-  return NULL;
-}
-
-
-static __inline__ const char *
-dlerror (void)
-{
-  return w32_strerror (0);
-}
-
-
-static __inline__ int
-dlclose (void * hd)
-{
-  if (hd)
-    {
-      FreeLibrary (hd);
-      return 0;
-    }
-  return -1;
-}  
-
-static HRESULT
-w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d, LPSTR e)
-{
-  static int initialized;
-  static HRESULT (WINAPI * func)(HWND,int,HANDLE,DWORD,LPSTR);
-
-  if (!initialized)
-    {
-      static char *dllnames[] = { "shell32.dll", "shfolder.dll", NULL };
-      void *handle;
-      int i;
-
-      initialized = 1;
-
-      for (i=0, handle = NULL; !handle && dllnames[i]; i++)
-        {
-          handle = dlopen (dllnames[i], RTLD_LAZY);
-          if (handle)
-            {
-              func = dlsym (handle, "SHGetFolderPathA");
-              if (!func)
-                {
-                  dlclose (handle);
-                  handle = NULL;
-                }
-            }
-        }
-    }
-
-  if (func)
-    return func (a,b,c,d,e);
-  else
-    return -1;
-}
-#endif
-
-
-static gchar *
-default_homedir (void)
-{
-  char *dir;
-
-  dir = getenv("GNUPGHOME");
-  if (dir)
-    dir = g_strdup (dir);
-#ifdef G_OS_WIN32
-  if (!dir || !*dir)
-    {
-      char *tmp = read_w32_registry_string (NULL,
-                                            "Software\\GNU\\GnuPG", "HomeDir");
-      if (tmp)
-        {
-          dir = g_strdup (tmp);
-          free (tmp);
-        }
-    }
-  if (!dir || !*dir)
-    {
-      char path[MAX_PATH];
-      
-      /* It might be better to use LOCAL_APPDATA because this is
-         defined as "non roaming" and thus more likely to be kept
-         locally.  For private keys this is desired.  However, given
-         that many users copy private keys anyway forth and back,
-         using a system roaming serives might be better than to let
-         them do it manually.  A security conscious user will anyway
-         use the registry entry to have better control.  */
-      if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, 
-                               NULL, 0, path) >= 0) 
-        {
-	  dir = g_build_filename (path, "gnupg", NULL);
-
-          /* Try to create the directory if it does not yet
-             exists.  */
-          if (access (dir, F_OK))
-            CreateDirectory (dir, NULL);
-        }
-    }
-#endif /* W32 */
-  if (!dir || !*dir)
-    {
-#ifdef G_OS_WIN32
-      dir = g_strdup ("c:\\gnupg");
-#else
-      dir = g_build_filename (getenv("HOME")?getenv("HOME"):"/",
-                              ".gnupg", NULL);
-#endif
-    }
-  return dir;
-}
-
-
 /* Return a malloced string with the locale dir.  Return NULL on
    error. */
 static char *
@@ -241,7 +85,6 @@
 }
 
 
-
 static void
 i18n_init (void)
 {
@@ -262,9 +105,7 @@
 }
 
 
-/*
- *  Manage the two main windows and the settings dialog.
- */
+/* Manage the two main windows and the settings dialog.  */
 
 static GtkWidget *keyringeditor = NULL;
 static GtkWidget *settings_dialog = NULL;
@@ -350,19 +191,14 @@
   return keyringeditor;
 }
 
+
 GtkWidget *
 gpa_get_settings_dialog (void)
 {
   return settings_dialog;
 }
 
-static void
-dummy_log_func (const gchar *log_domain, GLogLevelFlags log_level,
-                const gchar *message, gpointer user_data)
-{
-  /* empty */
-}
-
+
 typedef struct
 {
   gboolean start_keyring_editor;
@@ -371,6 +207,7 @@
   gchar *options_filename;
 } GpaCommandLineArgs;
 
+
 struct option longopts[] =
 {
   { "version", no_argument, NULL, 'v' },
@@ -384,6 +221,7 @@
   { NULL, 0, NULL, 0 }
 };
 
+
 struct
 {
   char short_opt;
@@ -391,22 +229,24 @@
   char *description;
 } option_desc[] = 
 {
-  {'h', "help", N_("display this help and exit")},
-  {'v', "version", N_("output version information and exit")},
-  {'k', "keyring", N_("open keyring editor (default)")},
-  {'f', "files", N_("open filemanager")},
-  {'s', "server", N_("start only the UI server")},
-  {'o', "options", N_("read options from file")},
-  {'x', "cms", "enable CMS hack"},
-  {0, NULL, NULL}
+  { 'h', "help", N_("display this help and exit") },
+  { 'v', "version", N_("output version information and exit") },
+  { 'k', "keyring", N_("open keyring editor (default)") },
+  { 'f', "files", N_("open filemanager") },
+  { 's', "server", N_("start only the UI server") },
+  { 'o', "options", N_("read options from file") },
+  { 'x', "cms", "enable CMS hack" },
+  { 0, NULL, NULL }
 };
 
-/* The copyright notice */
+
+/* The copyright notice.  */
 const char *copyright = 
 "Copyright (C) 2000-2002 Miguel Coca, G-N-U GmbH, Intevation GmbH.\n"
+"Copyright (C) 2008 g10 Code GmbH.\n"
 "This program comes with ABSOLUTELY NO WARRANTY.\n"
 "This is free software, and you are welcome to redistribute it\n"
-"under certain conditions. See the file COPYING for details.\n";
+"under certain conditions.  See the file COPYING for details.\n";
 
 static void
 print_copyright (void)
@@ -414,25 +254,30 @@
   printf ("%s %s\n%s", PACKAGE, VERSION, copyright);
 }
 
-/* Help option */
+
+/* Print usage information.  */
 static void
 usage (void)
 {
   int i;
   
   print_copyright ();
-  printf ("%s\n", _("Syntax: gpa [options]\n"
+
+  printf ("%s\n", _("Syntax: gpa [OPTION...] [FILE...]\n"
                     "Graphical frontend to GnuPG\n"));
   printf ("%s:\n\n", _("Options"));
+
   for (i = 0; option_desc[i].long_opt; i++)
     {
       printf (" -%c, --%s\t\t%s\n", option_desc[i].short_opt,
               option_desc[i].long_opt, _(option_desc[i].description));
     }
+
   printf ("\n%s", _("Please report bugs to <" PACKAGE_BUGREPORT ">.\n"));
 }
 
-/* Parse the command line. */
+
+/* Parse the command line.  */
 static void
 parse_command_line (int argc, char **argv, GpaCommandLineArgs *args)
 {
@@ -479,14 +324,21 @@
     }
 }
 
-/*
- *   Main function
- */
+
+static void
+dummy_log_func (const gchar *log_domain, GLogLevelFlags log_level,
+                const gchar *message, gpointer user_data)
+{
+  /* Nothing to be done.  */
+}
+
+
 int
-main (int argc, char **argv)
+main (int argc, char *argv[])
 {
-  char *configname = NULL, *keyservers_configname = NULL;
-  GpaCommandLineArgs args = {FALSE, FALSE, FALSE, NULL};
+  char *configname = NULL;
+  char *keyservers_configname = NULL;
+  GpaCommandLineArgs args = { FALSE, FALSE, FALSE, NULL };
   int i;
   GError *err = NULL;
 
@@ -497,8 +349,8 @@
   parse_command_line (argc, argv, &args);
 
 
-  /* Disable logging to prevent MS Windows NT from opening a console.
-   */
+  /* Disable logging to prevent MS Windows NT from opening a
+     console.  */
   g_log_set_handler ("Glib", G_LOG_LEVEL_CRITICAL
                              | G_LOG_LEVEL_WARNING
                              | G_LOG_LEVEL_MESSAGE
@@ -514,10 +366,6 @@
                             | G_LOG_LEVEL_MESSAGE
                             | G_LOG_LEVEL_INFO, dummy_log_func, NULL);
 
-  /* Find out where our executable lives */
-  gpa_exec_dir = g_path_get_dirname (argv[0]);
-
-  srand (time (NULL)); /* the about dialog uses rand() */
   gtk_init (&argc, &argv);
   i18n_init ();
   /* Default icon for all windows */
@@ -528,10 +376,10 @@
   gnupg_homedir = default_homedir ();
 
 #ifdef IS_DEVELOPMENT_VERSION
-  fprintf (stderr, "NOTE: this is a development version!\n");
+  fprintf (stderr, "NOTE: This is a development version!\n");
 #endif
 
-  /* Initialize GPGME */
+  /* Initialize GPGME.  */
   gpgme_check_version (NULL);
 #ifdef USE_SIMPLE_GETTEXT
   /* FIXME */
@@ -542,15 +390,14 @@
 #endif
 #endif
 
-  /* Locate GPA's configuration file.
-   */
-  if (!args.options_filename)
+  /* Locate GPA's configuration file.  */
+  if (! args.options_filename)
     {
       /* This is on the cheesy side.  GnuPG can not create a key if
 	 its home directory is missing.  We give it a bit of a jump
 	 start here.  */
-      if (!g_file_test (gnupg_homedir, G_FILE_TEST_IS_DIR))
-	mkdir (gnupg_homedir, 0700);
+      if (! g_file_test (gnupg_homedir, G_FILE_TEST_IS_DIR))
+	g_mkdir (gnupg_homedir, 0700);
       configname = g_build_filename (gnupg_homedir, "gpa.conf", NULL);
     }
   else
@@ -560,57 +407,52 @@
   gpa_options_set_file (gpa_options_get_instance (), configname);
   g_free (configname);
 
-  /* Locate the list of keyservers.
-   */
+  /* Locate the list of keyservers.  */
   keyservers_configname = g_build_filename (gnupg_homedir, "keyservers", NULL);
-  /* Read the list of available keyservers.
-   */
+
+  /* Read the list of available keyservers.  */
   keyserver_read_list (keyservers_configname);
 
-  /* Now, make sure there are reasonable defaults for the default key and
-   * keyserver */
-/*   gpa_options_update_default_key (gpa_options_get_instance ()); */
-/*   if (!gpa_options_get_default_keyserver (gpa_options_get_instance ())) */
-/*     { */
-/*       GList *keyservers = keyserver_get_as_glist (); */
-/*       gpa_options_set_default_keyserver (gpa_options_get_instance (), */
-/* 					 keyservers->data); */
-/*     } */
+#if 0
+  /* Now, make sure there are reasonable defaults for the default key
+    and keyserver.  */
+  gpa_options_update_default_key (gpa_options_get_instance ());
+  if (!gpa_options_get_default_keyserver (gpa_options_get_instance ()))
+    {
+      GList *keyservers = keyserver_get_as_glist ();
+      gpa_options_set_default_keyserver (gpa_options_get_instance (),
+					 keyservers->data);
+    }
+#endif
 
 #ifndef G_OS_WIN32
-  /* Internationalisation with gtk+-2.0 wants UTF8 instead of the
-   * character set determined by `locale'.
-   */
+  /* Internationalisation with gtk+-2.0 wants UTF-8 instead of the
+     character set determined by `locale'.  */
   putenv ("OUTPUT_CHARSET=utf8");
 #endif
 
   /* Fire up the server.  */
   gpa_start_server ();
 
-  if (!args.start_only_server)
+  if (! args.start_only_server)
     {
       /* Don't open the keyring editor if any files are given on the
-       * command line */
+         command line */
       if (args.start_keyring_editor && (optind >= argc))
-        {
-          gpa_open_keyring_editor ();
-        }
+	gpa_open_keyring_editor ();
   
       if (args.start_file_manager || (optind < argc))
-        {
-          gpa_open_filemanager ();
-        }
+	gpa_open_filemanager ();
 
-      /* If there are any command line arguments that are not options, try
-       * to open them as files in the filemanager */
+      /* If there are any command line arguments that are not options,
+	 try to open them as files in the filemanager */
       for (i = optind; i < argc; i++)
-        {
-          gpa_file_manager_open_file (GPA_FILE_MANAGER
-                                      (gpa_file_manager_get_instance ()),
-                                      argv[i]);
-        }
+	gpa_file_manager_open_file (GPA_FILE_MANAGER
+				    (gpa_file_manager_get_instance ()),
+				    argv[i]);
     }
 
   gtk_main ();
+
   return 0;
 }

Modified: trunk/src/helpmenu.c
===================================================================
--- trunk/src/helpmenu.c	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/helpmenu.c	2008-01-18 01:21:37 UTC (rev 792)
@@ -24,6 +24,7 @@
 #include "gpa.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
 #include <string.h>
 #include <gtk/gtk.h>
 #include "gpawindowkeeper.h"
@@ -194,6 +195,8 @@
       int i;
 #endif
 
+      srand (time (NULL)); /* the about dialog uses rand() */
+
       about_dialog = gtk_dialog_new ();
       gtk_window_set_title (GTK_WINDOW (about_dialog), _("About GPA"));
       gtk_window_set_policy (GTK_WINDOW (about_dialog), FALSE, FALSE, FALSE);

Modified: trunk/src/w32reg.c
===================================================================
--- trunk/src/w32reg.c	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/w32reg.c	2008-01-18 01:21:37 UTC (rev 792)
@@ -1,179 +1,197 @@
-/* w32reg.c -  MS-Windows Registry access
- *	Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
- */
+/* w32reg.c - MS-Windows Registry access
+   Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2008 g10 Code GmbH.
 
-#include <config.h>
-#if defined (_WIN32) || defined (__CYGWIN32__)
- /* This module is only used in this environment */
+   This file is part of GPA.
 
+   GPA is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GPA is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glib.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+
 #include <windows.h>
 
+
 static HKEY
-get_root_key(const char *root)
+get_root_key (const char *root)
 {
-    HKEY root_key;
-	
-    if( !root )
-        root_key = HKEY_CURRENT_USER;
-    else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) )
-	root_key = HKEY_CLASSES_ROOT;
-    else if( !strcmp( root, "HKEY_CURRENT_USER" ) )
-	root_key = HKEY_CURRENT_USER;
-    else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) )
-	root_key = HKEY_LOCAL_MACHINE;
-    else if( !strcmp( root, "HKEY_USERS" ) )
-	root_key = HKEY_USERS;
-    else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) )
-	root_key = HKEY_PERFORMANCE_DATA;
-    else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) )
-	root_key = HKEY_CURRENT_CONFIG;
-    else
-        return NULL;
-	
-    return root_key;
+  HKEY root_key;
+  
+  if (!root)
+    root_key = HKEY_CURRENT_USER;
+  else if (!strcmp( root, "HKEY_CLASSES_ROOT"))
+    root_key = HKEY_CLASSES_ROOT;
+  else if (!strcmp( root, "HKEY_CURRENT_USER"))
+    root_key = HKEY_CURRENT_USER;
+  else if (!strcmp( root, "HKEY_LOCAL_MACHINE"))
+    root_key = HKEY_LOCAL_MACHINE;
+  else if (!strcmp( root, "HKEY_USERS"))
+    root_key = HKEY_USERS;
+  else if (!strcmp( root, "HKEY_PERFORMANCE_DATA"))
+    root_key = HKEY_PERFORMANCE_DATA;
+  else if (!strcmp( root, "HKEY_CURRENT_CONFIG"))
+    root_key = HKEY_CURRENT_CONFIG;
+  else
+    return NULL;
+  
+  return root_key;
 }
 
 
-/****************
- * Return a string from the Win32 Registry or NULL in case of
- * error.  Caller must release the return value.   A NULL for root
- * is an alias for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn.
- * NOTE: The value is allocated with a plain malloc() - use free() and not
- * the usual xfree()!!!
- */
+/* Return a string from the Win32 Registry or NULL in case of error.
+   Caller must release the return value with g_free ().  A NULL for
+   root is an alias for HKEY_CURRENT_USER with a fallback for
+   HKEY_LOCAL_MACHINE.  */
 char *
-read_w32_registry_string( const char *root, const char *dir, const char *name )
+read_w32_registry_string (const char *root, const char *dir, const char *name)
 {
-    HKEY root_key, key_handle;
-    DWORD n1, nbytes, type;
-    char *result = NULL;
+  HKEY root_key;
+  HKEY key_handle;
+  DWORD n1;
+  DWORD nbytes;
+  DWORD type;
+  char *result = NULL;
 
-    if ( !(root_key = get_root_key(root) ) )
+  root_key = get_root_key (root);
+  if (! root_key)
+    return NULL;
+
+  if (RegOpenKeyEx (root_key, dir, 0, KEY_READ, &key_handle))
+    {
+      if (root)
+	/* No need for a RegClose, so return directly.  */
 	return NULL;
+      
+      /* It seems to be common practise to fall back to HKLM.  */
+      if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle))
+	/* Still no need for a RegClose, so return directly.  */
+	return NULL;
+    }
 
-    if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) )
-      {
-        if (root)
-          return NULL; /* no need for a RegClose, so return direct */
-        /* It seems to be common practise to fall back to HKLM. */
-        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
-          return NULL; /* still no need for a RegClose, so return direct */
-      }
+  nbytes = 1;
+  if (RegQueryValueEx (key_handle, name, 0, NULL, NULL, &nbytes))
+    {
+      if (root)
+	goto leave;
 
-    nbytes = 1;
-    if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) {
-        if (root)
-            goto leave;
-        /* Try to fallback to HKLM also vor a missing value.  */
-        RegCloseKey (key_handle);
-        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
-            return NULL; /* Nope.  */
-        if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes))
-            goto leave;
-    }
-    result = malloc( (n1=nbytes+1) );
-    if( !result )
+      /* Try to fallback to HKLM also for a missing value.  */
+      RegCloseKey (key_handle);
+      if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle))
+	return NULL;
+
+      if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes))
 	goto leave;
-    if( RegQueryValueEx( key_handle, name, 0, &type, result, &n1 ) ) {
-	free(result); result = NULL;
-	goto leave;
     }
-    result[nbytes] = 0; /* make sure it is really a string  */
-    if (type == REG_EXPAND_SZ && strchr (result, '%')) {
-        char *tmp;
+  n1 = nbytes + 1;
+  result = g_malloc (n1);
+  if (RegQueryValueEx (key_handle, name, 0, &type, result, &n1))
+    {
+      g_free (result);
+      result = NULL;
+      goto leave;
+    }
+
+  /* Make sure it is really a string.  */
+  result[nbytes] = 0;
+  if (type == REG_EXPAND_SZ && strchr (result, '%'))
+    {
+      char *tmp;
         
-        n1 += 1000;
-        tmp = malloc (n1+1);
-        if (!tmp)
-            goto leave;
-        nbytes = ExpandEnvironmentStrings (result, tmp, n1);
-        if (nbytes && nbytes > n1) {
-            free (tmp);
-            n1 = nbytes;
-            tmp = malloc (n1 + 1);
-            if (!tmp)
-                goto leave;
-            nbytes = ExpandEnvironmentStrings (result, tmp, n1);
-            if (nbytes && nbytes > n1) {
-                free (tmp); /* oops - truncated, better don't expand at all */
-                goto leave;
+      n1 += 1000;
+      tmp = g_malloc (n1 + 1);
+      nbytes = ExpandEnvironmentStrings (result, tmp, n1);
+      if (nbytes && nbytes > n1)
+	{
+	  free (tmp);
+	  n1 = nbytes;
+	  tmp = g_malloc (n1 + 1);
+	  nbytes = ExpandEnvironmentStrings (result, tmp, n1);
+	  if (nbytes && nbytes > n1)
+	    {
+	      /* Oops: truncated, better don't expand at all.  */
+	      free (tmp);
+	      goto leave;
             }
-            tmp[nbytes] = 0;
-            free (result);
-            result = tmp;
+	  tmp[nbytes] = 0;
+	  g_free (result);
+	  result = tmp;
         }
-        else if (nbytes) { /* okay, reduce the length */
-            tmp[nbytes] = 0;
-            free (result);
-            result = malloc (strlen (tmp)+1);
-            if (!result)
-                result = tmp;
-            else {
-                strcpy (result, tmp);
-                free (tmp);
-            }
+      else if (nbytes)
+	{
+	  /* Okay, reduce the length.  */
+	  tmp[nbytes] = 0;
+	  free (result);
+	  result = g_malloc (strlen (tmp) + 1);
+	  strcpy (result, tmp);
+	  g_free (tmp);
+	}
+      else
+	{
+	  /* Error - don't expand.  */
+	  g_free (tmp);
         }
-        else {  /* error - don't expand */
-            free (tmp);
-        }
     }
-
-  leave:
-    RegCloseKey( key_handle );
-    return result;
+  
+ leave:
+  RegCloseKey (key_handle);
+  return result;
 }
 
 
+/* Write string VALUE into the W32 Registry ROOT, DIR and NAME.  If
+   NAME does not exist, it is created.  */
 int
-write_w32_registry_string(const char *root, const char *dir, 
-                          const char *name, const char *value)
+write_w32_registry_string (const char *root, const char *dir, 
+                           const char *name, const char *value)
 {
-    HKEY root_key, reg_key;
-	
-    if ( !(root_key = get_root_key(root) ) )
-	return -1;
+  HKEY root_key;
+  HKEY reg_key;
+  
+  root_key = get_root_key (root);
+  if (! root_key)
+    return -1;
 
-    if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key ) 
-         != ERROR_SUCCESS )
-	return -1;
+  if (RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, &reg_key))
+    return -1;
 	
-    if ( RegSetValueEx( reg_key, name, 0, REG_SZ, (BYTE *)value, 
-                        strlen( value ) ) != ERROR_SUCCESS ) {
-        if ( RegCreateKey( root_key, name, &reg_key ) != ERROR_SUCCESS ) {
-            RegCloseKey(reg_key);
-            return -1;
+  if (RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value, 
+		     strlen( value ) ) != ERROR_SUCCESS)
+    {
+      if (RegCreateKey (root_key, name, &reg_key))
+	{
+	  RegCloseKey (reg_key);
+	  return -1;
         }
-        if ( RegSetValueEx( reg_key, name, 0, REG_SZ, (BYTE *)value,
-                            strlen( value ) ) != ERROR_SUCCESS ) {
-            RegCloseKey(reg_key);
-            return -1;
+
+      if (RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *) value,
+			 strlen (value)))
+	{
+	  RegCloseKey(reg_key);
+	  return -1;
         }
     }
 
-    RegCloseKey( reg_key );
-	
-    return 0;
+  RegCloseKey (reg_key);
+  
+  return 0;
 }
-
-#endif /* __MINGW32__ || __CYGWIN32__ */

Modified: trunk/src/w32reg.h
===================================================================
--- trunk/src/w32reg.h	2008-01-17 22:40:09 UTC (rev 791)
+++ trunk/src/w32reg.h	2008-01-18 01:21:37 UTC (rev 792)
@@ -1,26 +1,36 @@
-/* w32reg.h
- *	Copyright (C) 1998 Free Software Foundation, Inc.
- *
- * This file is part of GNUPG.
- *
- * GNUPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GNUPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+/* w32reg.h - MS-Windows Registry access
+   Copyright (C) 1998 Free Software Foundation, Inc.
+   Copyright (C) 2008 g10 Code GmbH.
+
+   This file is part of GPA.
+
+   GPA is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   GPA is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
 #ifndef W32REG_H
 #define W32REG_H
 
-char *read_w32_registry_string( const char *root,
-				const char *dir, const char *name );
+/* Return a string from the Win32 Registry or NULL in case of error.
+   Caller must release the return value with g_free ().  A NULL for
+   root is an alias for HKEY_CURRENT_USER with a fallback for
+   HKEY_LOCAL_MACHINE.  */
+char *read_w32_registry_string (const char *root,
+				const char *dir, const char *name);
 
-#endif /* W32REG_H */
+/* Write string VALUE into the W32 Registry ROOT, DIR and NAME.  If
+   NAME does not exist, it is created.  */
+int write_w32_registry_string (const char *root, const char *dir, 
+			       const char *name, const char *value);
+
+#endif	/* W32REG_H */



More information about the Gpa-commits mailing list