From: Marcus Brinkmann Date: Tue, 18 Dec 2001 22:21:06 +0000 (+0000) Subject: 2001-12-18 Marcus Brinkmann X-Git-Tag: gpgme-0-3-0~14 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a3d0634e976984e781c989d44a218e661a39c874;p=gpgme.git 2001-12-18 Marcus Brinkmann * version.c (gpgme_get_engine_info): Reimplemented. (gpgme_check_engine): Reimplemented. (_gpgme_compare_versions): Return NULL if MY_VERSION is NULL. * engine.c: Include `io.h'. (gpgme_engine_get_info): New function. * engine.h (gpgme_engine_check_version, _gpgme_engine_get_info): Add prototype. --- diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index defb9ed..8bccdb9 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,14 @@ +2001-12-18 Marcus Brinkmann + + * version.c (gpgme_get_engine_info): Reimplemented. + (gpgme_check_engine): Reimplemented. + (_gpgme_compare_versions): Return NULL if MY_VERSION is NULL. + + * engine.c: Include `io.h'. + (gpgme_engine_get_info): New function. + * engine.h (gpgme_engine_check_version, _gpgme_engine_get_info): + Add prototype. + 2001-12-18 Marcus Brinkmann * rungpg.c (struct reap_s, reap_list, reap_list_lock): Moved to ... diff --git a/gpgme/engine.c b/gpgme/engine.c index 3c250c9..5e0117b 100644 --- a/gpgme/engine.c +++ b/gpgme/engine.c @@ -29,6 +29,7 @@ #include "gpgme.h" #include "util.h" #include "sema.h" +#include "io.h" #include "engine.h" #include "rungpg.h" @@ -103,6 +104,46 @@ gpgme_engine_check_version (GpgmeProtocol proto) } } +const char * +_gpgme_engine_get_info (GpgmeProtocol proto) +{ + static const char fmt[] = " \n" + " %s\n" + " %s\n" + " %s\n" + " \n"; + static const char *const strproto[3] = { "OpenPGP", "CMS", NULL }; + static const char *engine_info[3]; /* FIXME: MAX_PROTO + 1*/ + const char *path; + const char *version; + char *info; + + if (proto > 2 /* FIXME MAX_PROTO */ || !strproto[proto]) + return NULL; + + /* FIXME: Make sure that only one instance does run. */ + if (engine_info[proto]) + return engine_info[proto]; + + path = _gpgme_engine_get_path (proto); + version = _gpgme_engine_get_version (proto); + + if (!path || !version) + return NULL; + + info = xtrymalloc (strlen(fmt) + strlen(strproto[proto]) + strlen(path) + + strlen (version) + 1); + if (!info) + info = " \n" + " Out of core\n" + " "; + else + sprintf (info, fmt, strproto[proto], version, path); + engine_info[proto] = info; + + return engine_info[proto]; +} + GpgmeError _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine) { diff --git a/gpgme/engine.h b/gpgme/engine.h index 23be9dc..e7b7cbc 100644 --- a/gpgme/engine.h +++ b/gpgme/engine.h @@ -27,6 +27,8 @@ const char *_gpgme_engine_get_path (GpgmeProtocol proto); const char *_gpgme_engine_get_version (GpgmeProtocol proto); +GpgmeError gpgme_engine_check_version (GpgmeProtocol proto); +const char * _gpgme_engine_get_info (GpgmeProtocol proto); GpgmeError _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine); void _gpgme_engine_release (EngineObject engine); void _gpgme_engine_set_status_handler (EngineObject engine, diff --git a/gpgme/version.c b/gpgme/version.c index b2146db..27d720b 100644 --- a/gpgme/version.c +++ b/gpgme/version.c @@ -35,7 +35,6 @@ static const char *get_engine_info (void); - static void do_subsystem_inits (void) { @@ -47,8 +46,6 @@ do_subsystem_inits (void) _gpgme_key_cache_init (); } - - static const char* parse_version_number ( const char *s, int *number ) { @@ -64,7 +61,6 @@ parse_version_number ( const char *s, int *number ) return val < 0? NULL : s; } - static const char * parse_version_string( const char *s, int *major, int *minor, int *micro ) { @@ -92,6 +88,8 @@ _gpgme_compare_versions (const char *my_version, if (!req_version) return my_version; + if (!my_version) + return NULL; my_plvl = parse_version_string (my_version, &my_major, &my_minor, &my_micro); if (!my_plvl) @@ -114,7 +112,6 @@ _gpgme_compare_versions (const char *my_version, return NULL; } - /** * gpgme_check_version: * @req_version: A string with a version @@ -139,56 +136,73 @@ gpgme_check_version (const char *req_version) /** * gpgme_get_engine_info: * - * Return information about the underlying crypto engine. This is an - * XML string with various information. To get the version of the - * crypto engine it should be sufficient to grep for the first - * version tag and use it's content. A string is - * always returned even if the crypto engine is not installed; in this - * case a XML string with some error information is returned. + * Return information about the underlying crypto engines. This is an + * XML string with various information. A string is always returned + * even if the crypto engines is not installed; in this case a XML + * string with some error information is returned. * - * Return value: A XML string with information about the crypto engine. + * Return value: A XML string with information about the crypto + * engines. **/ const char * gpgme_get_engine_info () { - do_subsystem_inits (); - return get_engine_info (); + static const char *engine_info; + const char *openpgp_info = _gpgme_engine_get_info (GPGME_PROTOCOL_OpenPGP); + const char *cms_info = _gpgme_engine_get_info (GPGME_PROTOCOL_CMS); + char *info; + + /* FIXME: Make sure that only one instance does run. */ + if (engine_info) + return engine_info; + + if (!openpgp_info && !cms_info) + info = "\n\n"; + else if (!openpgp_info || !cms_info) + { + const char *fmt = "\n" + "%s" + "\n"; + + info = xtrymalloc (strlen(fmt) + strlen(openpgp_info + ? openpgp_info : cms_info) + 1); + if (info) + sprintf (info, fmt, openpgp_info ? openpgp_info : cms_info); + } + else + { + const char *fmt = "\n" + "%s%s" + "\n"; + info = xtrymalloc (strlen(fmt) + strlen(openpgp_info) + + strlen (cms_info) + 1); + if (info) + sprintf (info, fmt, openpgp_info, cms_info); + } + if (!info) + info = "\n" + " Out of core\n" + "\n"; + engine_info = info; + return engine_info; } /** * gpgme_check_engine: * - * Check whether the installed crypto engine matches the requirement of - * GPGME. + * Check whether the installed crypto engine for the OpenPGP protocol + * matches the requirement of GPGME. This function is deprecated, + * instead use gpgme_engine_get_info() with the specific protocol you + * need. * * Return value: 0 or an error code. **/ GpgmeError gpgme_check_engine () { - const char *info = gpgme_get_engine_info (); - const char *s, *s2; - - s = strstr (info, ""); - if (s) { - s += 9; - s2 = strchr (s, '<'); - if (s2) { - char *ver = xtrymalloc (s2 - s + 1); - if (!ver) - return mk_error (Out_Of_Core); - memcpy (ver, s, s2-s); - ver[s2-s] = 0; - s = _gpgme_compare_versions ( ver, NEED_GPG_VERSION ); - xfree (ver); - if (s) - return 0; - } - } - return mk_error (Invalid_Engine); + return gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); } - #define LINELENGTH 80 @@ -253,77 +267,3 @@ _gpgme_get_program_version (const char *const path) return NULL; } - -static const char * -get_engine_info (void) -{ - static const char *engine_info =NULL; - GpgmeError err = 0; - const char *path = NULL; - char *version; - - /* FIXME: make sure that only one instance does run */ - if (engine_info) - return engine_info; - - path = _gpgme_get_gpg_path (); - if (!path) - { - engine_info = "\n" - " Not supported\n" - "\n"; - goto leave; - } - version = _gpgme_get_program_version (path); - - if (version) { - const char *fmt; - char *p; - - fmt = "\n" - " \n" - " %s\n" - " %s\n" - " \n" - "\n"; - /*(yes, I know that we allocating 2 extra bytes)*/ - p = xtrymalloc ( strlen(fmt) + strlen(path) - + strlen (version) + 1); - if (!p) { - err = mk_error (Out_Of_Core); - goto leave; - } - sprintf (p, fmt, version, path); - engine_info = p; - xfree (version); - } - else { - err = mk_error (General_Error); - } - - leave: - if (err) { - const char *fmt; - const char *errstr = gpgme_strerror (err); - char *p; - - fmt = "\n" - " \n" - " %s\n" - " %s\n" - " \n" - "\n"; - - p = xtrymalloc ( strlen(fmt) + strlen(errstr) + strlen(path) + 1); - if (p) { - sprintf (p, fmt, errstr, path); - engine_info = p; - } - else { - engine_info = "\n" - " Out of core\n" - "\n"; - } - } - return engine_info; -}