From: Werner Koch Date: Tue, 30 Jan 2001 16:00:50 +0000 (+0000) Subject: Lookup the path in the Registry X-Git-Tag: gpgme-1.2.0@1385~1343 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ecedadb70083f7c7393c2f5d4a97fffde3e920cc;p=gpgme.git Lookup the path in the Registry --- diff --git a/trunk/AUTHORS b/trunk/AUTHORS index e69de29..20ea6e0 100644 --- a/trunk/AUTHORS +++ b/trunk/AUTHORS @@ -0,0 +1,9 @@ +Program: gpgme +Maintainer: Werner Koch + + +FSF + * Code taken from GnuPG: gpgme/w32-util.c + +Werner Koch + * Design and most stuff. diff --git a/trunk/TODO b/trunk/TODO index 59a6d8c..a829ea0 100644 --- a/trunk/TODO +++ b/trunk/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. diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 03c72d3..0f704a5 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,5 +1,9 @@ 2001-01-30 Werner Koch + * 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 diff --git a/trunk/gpgme/Makefile.am b/trunk/gpgme/Makefile.am index 20944ac..59faab4 100644 --- a/trunk/gpgme/Makefile.am +++ b/trunk/gpgme/Makefile.am @@ -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 diff --git a/trunk/gpgme/debug.c b/trunk/gpgme/debug.c index f41929b..7cb5121 100644 --- a/trunk/gpgme/debug.c +++ b/trunk/gpgme/debug.c @@ -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/trunk/gpgme/posix-util.c b/trunk/gpgme/posix-util.c new file mode 100644 index 0000000..3c0c692 --- /dev/null +++ b/trunk/gpgme/posix-util.c @@ -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 +#ifndef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include + +#include "util.h" + + +const char * +_gpgme_get_gpg_path (void) +{ + return GPG_PATH; +} + + +#endif /*!HAVE_DOSISH_SYSTEM*/ + + + + + diff --git a/trunk/gpgme/rungpg.c b/trunk/gpgme/rungpg.c index 101d9a9..8c9d2b7 100644 --- a/trunk/gpgme/rungpg.c +++ b/trunk/gpgme/rungpg.c @@ -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); diff --git a/trunk/gpgme/util.h b/trunk/gpgme/util.h index 65bfa2b..0d901e6 100644 --- a/trunk/gpgme/util.h +++ b/trunk/gpgme/util.h @@ -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/trunk/gpgme/w32-util.c b/trunk/gpgme/w32-util.c new file mode 100644 index 0000000..f1001a6 --- /dev/null +++ b/trunk/gpgme/w32-util.c @@ -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 +#ifdef HAVE_DOSISH_SYSTEM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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*/ + + + + +