Lookup the path in the Registry
authorWerner Koch <wk@gnupg.org>
Tue, 30 Jan 2001 16:00:50 +0000 (16:00 +0000)
committerWerner Koch <wk@gnupg.org>
Tue, 30 Jan 2001 16:00:50 +0000 (16:00 +0000)
AUTHORS
TODO
gpgme/ChangeLog
gpgme/Makefile.am
gpgme/debug.c
gpgme/posix-util.c [new file with mode: 0644]
gpgme/rungpg.c
gpgme/util.h
gpgme/w32-util.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..20ea6e00a4afbe6ac29301e324d595b7fb412d40 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -0,0 +1,9 @@
+Program: gpgme
+Maintainer: Werner Koch <wk@gnupg.org>
+
+
+FSF <gnu@gnu.org>
+    * Code taken from GnuPG: gpgme/w32-util.c 
+
+Werner Koch <wk@gnupg.org>
+    * Design and most stuff.
diff --git a/TODO b/TODO
index 59a6d8c877d995c228c1d3bcf78385b0b33f8615..a829ea0e796678644aff1a5e27f5c5e3a2753cda 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,6 +5,6 @@
 * Allow to use GTK's main loop instead of the select stuff in
   wait.c
 
-* Remove all that funny exit code handling - we donn't need it.
+* Remove all that funny exit code handling - we don't need it.
 
 
index 03c72d3f7f81a335a88c7c56e49fb735975eddaa..0f704a5aa1e376df7e9984530e9806990441fc65 100644 (file)
@@ -1,5 +1,9 @@
 2001-01-30  Werner Koch  <wk@gnupg.org>
 
+       * posix-util.c, w32-util.c: New.
+       (_gpgme_get_gpg_path): New, suggested by Jan-Oliver.
+       * rungpg.c (_gpgme_gpg_spawn): Use new function to get GPG's path.
+
        * signers.c (gpgme_signers_add): Ooops, one should test code and
        not just write it; the newarr was not assigned.  Thanks to José
        for pointing this out.  Hmmm, still not tested, why shoudl a coder
index 20944ac821b8d6debc01107821ee4014c4cd7e47..59faab48d70bc677ef79d79149bb5e49ed662c98 100644 (file)
@@ -13,7 +13,8 @@ libgpgme_la_LDFLAGS = -version-info \
 libgpgme_la_INCLUDES = -I$(top_srcdir)/lib 
 
 libgpgme_la_SOURCES = \
-       gpgme.h types.h util.h util.c debug.c \
+       gpgme.h types.h \
+       util.h util.c posix-util.c w32-util.c \
        context.h ops.h \
        data.c recipient.c signers.c \
         wait.c wait.h \
@@ -31,7 +32,7 @@ libgpgme_la_SOURCES = \
         rungpg.c rungpg.h status-table.h \
        sema.h posix-sema.c w32-sema.c \
        syshdr.h io.h posix-io.c w32-io.c \
-       gpgme.c version.c errors.c
+       gpgme.c debug.c version.c errors.c
 
 
 errors.c : gpgme.h
index f41929b3b98253e2829aab3987d76b45606919e4..7cb5121d952157946f616c0309e92065501eae89 100644 (file)
@@ -94,7 +94,7 @@ _gpgme_debug_begin ( void **helper, int level, const char *text)
         return;
     }
 
-    /* Oh what a pitty sthat we don't have a asprintf or snprintf under
+    /* Oh what a pitty that we don't have a asprintf or snprintf under
      * Windoze.  We definitely should write our own clib for W32! */
     sprintf ( ctl->fname, "/tmp/gpgme_debug.%d.%p", getpid (), ctl );
     ctl->fp = fopen (ctl->fname, "w+");
diff --git a/gpgme/posix-util.c b/gpgme/posix-util.c
new file mode 100644 (file)
index 0000000..3c0c692
--- /dev/null
@@ -0,0 +1,45 @@
+/* posix-util.c - Utility functions for Posix
+ *     Copyright (C) 2001 Werner Koch (dd9jn)
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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
+ */
+
+
+#include <config.h>
+#ifndef HAVE_DOSISH_SYSTEM
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "util.h"
+
+
+const char *
+_gpgme_get_gpg_path (void)
+{
+    return GPG_PATH;
+}
+
+
+#endif /*!HAVE_DOSISH_SYSTEM*/
+
+
+
+
+
index 101d9a9fa8a55a5364c1aec87a4053fe3ddb64f5..8c9d2b77c385d77daa80fb4bfe67bb374d19a607 100644 (file)
@@ -718,7 +718,8 @@ _gpgme_gpg_spawn( GpgObject gpg, void *opaque )
     fd_parent_list[n].dup_to = -1;
 
 
-    pid = _gpgme_io_spawn (GPG_PATH, gpg->argv, fd_child_list, fd_parent_list);
+    pid = _gpgme_io_spawn (_gpgme_get_gpg_path (),
+                           gpg->argv, fd_child_list, fd_parent_list);
     xfree (fd_child_list);
     if (pid == -1) {
         return mk_error (Exec_Error);
index 65bfa2b4190aca4958013d4f6edec7dc6fbffaef..0d901e65374b028378b1b20c3590f627408a2a7e 100644 (file)
@@ -119,6 +119,11 @@ char *stpcpy (char *a, const char *b);
 
 
 
+/*-- {posix,w32}-util.c --*/
+const char *_gpgme_get_gpg_path (void);
+
+
+
 #endif /* UTIL_H */
 
 
diff --git a/gpgme/w32-util.c b/gpgme/w32-util.c
new file mode 100644 (file)
index 0000000..f1001a6
--- /dev/null
@@ -0,0 +1,114 @@
+/* w32-util.c - Utility functions for the W32 API
+ *     Copyright (C) 2001 Werner Koch (dd9jn)
+ *      Copyright (C) 1999 Free Software Foundation, Inc
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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.
+ *
+ * GPGME 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
+ */
+
+
+#include <config.h>
+#ifdef HAVE_DOSISH_SYSTEM
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <windows.h>
+#include "syshdr.h"
+
+#include "util.h"
+
+/****************
+ * 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 fro HKEY_CURRENT_USER
+ */
+static char *
+read_w32_registry_string ( const char *root,
+                           const char *dir, const char *name )
+{
+    HKEY root_key, key_handle;
+    DWORD n1, nbytes;
+    char *result = NULL;
+
+    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;
+
+    if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) )
+        return NULL; /* no need for a RegClose, so return direct */
+
+    nbytes = 1;
+    if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) )
+        goto leave;
+    result = xtrymalloc( (n1=nbytes+1) );
+    if( !result )
+        goto leave;
+    if( RegQueryValueEx( key_handle, name, 0, NULL, result, &n1 ) ) {
+        xfree(result); result = NULL;
+        goto leave;
+    }
+    result[nbytes] = 0; /* make sure it is really a string  */
+
+  leave:
+    RegCloseKey( key_handle );
+    return result;
+}
+
+
+const char *
+_gpgme_get_gpg_path (void)
+{
+    static char *gpg_program = NULL;
+    
+    if (!gpg_program) {
+        gpg_program = read_w32_registry_string ( NULL,
+                                  "Software\\GNU\\GnuPG", "gpgProgram" );
+        if (!gpg_program)
+            gpg_program = GPG_PATH;
+    }
+    
+    return gpg_program;
+}
+
+
+
+
+#endif /*HAVE_DOSISH_SYSTEM*/
+
+
+
+
+