From fdbee6b2113f2b8bd45bd481e2c8848ea4d99a7c Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 30 Jan 2003 11:54:23 +0000 Subject: [PATCH] doc/ 2003-01-30 Marcus Brinkmann * gpgme.texi (Engine Information): Rewritten. gpgme/ 2003-01-30 Marcus Brinkmann * gpgme.h (enum GpgmeProtocol): Remove GPGME_PROTOCOL_AUTO. * gpgme.c (gpgme_set_protocol): Don't handle GPGME_PROTOCOL_AUTO. (gpgme_get_protocol_name): New function. * engine-backend.h (struct engine_ops): New member get_req_version, remove member check_version. * engine.h (_gpgme_Engine_get_version): New prototype. * rungpg.c (gpg_get_req_version): New function. (gpg_check_version): Function removed. (_gpgme_engine_ops_gpg): Add gpg_get_req_version, remove gpg_check_version. * engine-gpgsm.c (gpgsm_get_req_version): New function. (gpgsm_check_version): Function removed. (_gpgme_engine_ops_gpgsm): Add gpgsm_get_req_version, remove gpgsm_check_version. * engine.c: Include ops.h. (_gpgme_engine_get_req_version): New function. (gpgme_engine_check_version): Rewritten. * version.c (gpgme_get_engine_info): Rewritten. * gpgme.h (gpgme_engine_info): New structure. (GpgmeEngineInfo): New type. tests/ 2003-01-30 Marcus Brinkmann * Makefile.am (TESTS): Add t-engine-info. * t-engine-info.c: New file. * gpg/t-encrypt.c (main): Don't print engine info. * gpg/t-eventloop.c (main): Likewise. * gpg/t-encrypt-sign.c (main): Likewise. * gpgsm/t-encrypt.c (main): Likewise. --- doc/ChangeLog | 4 ++ doc/gpgme.texi | 104 ++++++++++++++++++++++++++----------- gpgme/ChangeLog | 24 +++++++++ gpgme/engine-backend.h | 2 +- gpgme/engine-gpgsm.c | 9 ++-- gpgme/engine.c | 34 +++++++----- gpgme/engine.h | 3 ++ gpgme/gpgme.c | 18 ++++++- gpgme/gpgme.h | 26 +++++++++- gpgme/rungpg.c | 9 ++-- gpgme/version.c | 84 ++++++++++++++---------------- tests/ChangeLog | 9 ++++ tests/Makefile.am | 2 +- tests/gpg/t-encrypt-sign.c | 38 +++++++------- tests/gpg/t-encrypt.c | 38 +++++++------- tests/gpg/t-eventloop.c | 38 +++++++------- tests/gpgsm/t-encrypt.c | 38 +++++++------- tests/t-engine-info.c | 92 ++++++++++++++++++++++++++++++++ 18 files changed, 388 insertions(+), 184 deletions(-) create mode 100644 tests/t-engine-info.c diff --git a/doc/ChangeLog b/doc/ChangeLog index 9edc0bc..ab3a6ae 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2003-01-30 Marcus Brinkmann + + * gpgme.texi (Engine Information): Rewritten. + 2003-01-29 Marcus Brinkmann * gpgme.texi (I/O Callback Interface): Document new even diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 6b82298..8b4cf11 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -609,41 +609,87 @@ and @code{GPGME_Invalid_Engine} if it is not. @section Engine Information @cindex engine, information about -@deftypefun {const char *} gpgme_get_engine_info (void) -The function @code{gpgme_get_engine_info} returns an @acronym{XML} -string containing information about the available protocols and the -engine which implement them. The following information is returned -for each engine: - -@table @samp -@item -The name of the protocol. -@item -The version of the engine. -@item -The path to the engine binary. +@deftp {Data type} {GpgmeEngineInfo} +@tindex GpgmeProtocol +The @code{GpgmeEngineInfo} type specifies a pointer to a structure +describing a crypto backend engine. The structure contains the +following elements: + +@table @code +@item GpgmeEngineInfo next +This is a pointer to the next engine info structure in the linked +list, or @code{NULL} if this is the last element. + +@item GpgmeProtocol protocol +This is the protocol for which the crypo engine is used. You can +convert this to a string with @code{gpgme_get_protocol_name} for +printing. + +@item const char *path +This is a string holding the path to the executable of the crypto +engine. Currently, it is never @code{NULL}, but using @code{NULL} is +reserved for future use, so always check before you use it. + +@item const char *version +This is a string containing the version number of the crypto engine. +It might be @code{NULL} if the version number can not be determined, +for example because the executable doesn't exist or is invalid. + +@item const char *req_version +This is a string containing the minimum required version number of the +crypto engine for @acronym{GPGME} to work correctly. This is the +version number that @code{gpgme_engine_check_version} verifies +against. Currently, it is never @code{NULL}, but using @code{NULL} is +reserved for future use, so always check before you use it. @end table +@end deftp -A string is always returned. If an error occurs, the string will -contain an @samp{} tag with a description of the failure. +@deftypefun GpgmeError gpgme_get_engine_info (GpgmeEngineInfo *info) +The function @code{gpgme_get_engine_info} returns a linked list of +engine info structures in @var{info}. Each info structure describes +one configured crypto backend engine. + +The memory for the info structures is allocated the first time this +function is invoked, and must not be freed by the caller. + +This function returns @code{GPGME_No_Error} if successful, and +@code{GPGME_Out_Of_Core} if not enough memory is available for the +operation. @end deftypefun -Here is the example output of what @code{gpgme_get_engine_info} might -return on your system: +Here is the example how you can provide more diagnostics if you +receive an error message which indicates that the crypto engine is +invalid. @example - - - OpenPGP - 1.0.6 - /usr/bin/gpg - - - CMS - 0.0.0 - /usr/bin/gpgsm - - +GpgmeCtx ctx; +GpgmeError err; + +[...] + +if (err == GPGME_Invalid_Engine) + @{ + GpgmeEngineInfo info; + err = gpgme_get_engine_info (&info); + if (!err) + @{ + while (info && info->protocol != gpgme_get_protocol (ctx)) + info = info->next; + if (!info) + fprintf (stderr, "GPGME compiled without support for protocol %s", + gpgme_get_protocol_name (info->protocol)); + else if (info->path && !info->version) + fprintf (stderr, "Engine %s not installed properly", + info->path); + else if (info->path && info->version && info->req_version) + fprintf (stderr, "Engine %s version %s installed, " + "but at least version %s required", info->path, + info->version, info->req_version); + else + fprintf (stderr, "Unknown problem with engine for protocol %s", + gpgme_get_protocol_name (info->protocol)); + @} + @} @end example diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index fef9872..b143582 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,27 @@ +2003-01-30 Marcus Brinkmann + + * gpgme.h (enum GpgmeProtocol): Remove GPGME_PROTOCOL_AUTO. + * gpgme.c (gpgme_set_protocol): Don't handle GPGME_PROTOCOL_AUTO. + (gpgme_get_protocol_name): New function. + + * engine-backend.h (struct engine_ops): New member + get_req_version, remove member check_version. + * engine.h (_gpgme_Engine_get_version): New prototype. + * rungpg.c (gpg_get_req_version): New function. + (gpg_check_version): Function removed. + (_gpgme_engine_ops_gpg): Add gpg_get_req_version, remove + gpg_check_version. + * engine-gpgsm.c (gpgsm_get_req_version): New function. + (gpgsm_check_version): Function removed. + (_gpgme_engine_ops_gpgsm): Add gpgsm_get_req_version, remove + gpgsm_check_version. + * engine.c: Include ops.h. + (_gpgme_engine_get_req_version): New function. + (gpgme_engine_check_version): Rewritten. + * version.c (gpgme_get_engine_info): Rewritten. + * gpgme.h (gpgme_engine_info): New structure. + (GpgmeEngineInfo): New type. + 2003-01-29 Marcus Brinkmann * types.h: Remove byte and ulong types. diff --git a/gpgme/engine-backend.h b/gpgme/engine-backend.h index 84da0c5..b291f05 100644 --- a/gpgme/engine-backend.h +++ b/gpgme/engine-backend.h @@ -34,7 +34,7 @@ struct engine_ops /* Static functions. */ const char *(*get_path) (void); const char *(*get_version) (void); - GpgmeError (*check_version) (void); + const char *(*get_req_version) (void); GpgmeError (*new) (void **r_engine); /* Member functions. */ diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index 190eeb5..38c2c0f 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -113,11 +113,10 @@ gpgsm_get_version (void) } -static GpgmeError -gpgsm_check_version (void) +static const char * +gpgsm_get_req_version (void) { - return _gpgme_compare_versions (gpgsm_get_version (), NEED_GPGSM_VERSION) - ? 0 : GPGME_Invalid_Engine; + return NEED_GPGSM_VERSION; } @@ -1437,7 +1436,7 @@ struct engine_ops _gpgme_engine_ops_gpgsm = /* Static functions. */ _gpgme_get_gpgsm_path, gpgsm_get_version, - gpgsm_check_version, + gpgsm_get_req_version, gpgsm_new, /* Member functions. */ diff --git a/gpgme/engine.c b/gpgme/engine.c index fcb6790..131a0de 100644 --- a/gpgme/engine.c +++ b/gpgme/engine.c @@ -27,6 +27,7 @@ #include "gpgme.h" #include "util.h" #include "sema.h" +#include "ops.h" #include "engine.h" #include "engine-backend.h" @@ -54,7 +55,7 @@ static struct engine_ops *engine_ops[] = const char * _gpgme_engine_get_path (GpgmeProtocol proto) { - if (proto > sizeof (engine_ops) / sizeof (engine_ops[0])) + if (proto > DIM (engine_ops)) return NULL; if (engine_ops[proto] && engine_ops[proto]->get_path) @@ -68,7 +69,7 @@ _gpgme_engine_get_path (GpgmeProtocol proto) const char * _gpgme_engine_get_version (GpgmeProtocol proto) { - if (proto > sizeof (engine_ops) / sizeof (engine_ops[0])) + if (proto > DIM (engine_ops)) return NULL; if (engine_ops[proto] && engine_ops[proto]->get_version) @@ -78,20 +79,27 @@ _gpgme_engine_get_version (GpgmeProtocol proto) } +/* Get the required version number of the engine for PROTOCOL. */ +const char * +_gpgme_engine_get_req_version (GpgmeProtocol proto) +{ + if (proto > DIM (engine_ops)) + return NULL; + + if (engine_ops[proto] && engine_ops[proto]->get_req_version) + return (*engine_ops[proto]->get_req_version) (); + else + return NULL; +} + + /* Verify the version requirement for the engine for PROTOCOL. */ GpgmeError gpgme_engine_check_version (GpgmeProtocol proto) { - if (proto > sizeof (engine_ops) / sizeof (engine_ops[0])) - return GPGME_Invalid_Value; - - if (!engine_ops[proto]) - return GPGME_Invalid_Engine; - - if (engine_ops[proto]->check_version) - return (*engine_ops[proto]->check_version) (); - else - return 0; + return _gpgme_compare_versions (_gpgme_engine_get_version (proto), + _gpgme_engine_get_req_version (proto)) + ? 0 : GPGME_Invalid_Engine; } @@ -142,7 +150,7 @@ _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine) const char *path; const char *version; - if (proto > sizeof (engine_ops) / sizeof (engine_ops[0])) + if (proto > DIM (engine_ops)) return GPGME_Invalid_Value; if (!engine_ops[proto]) diff --git a/gpgme/engine.h b/gpgme/engine.h index d24169c..746de6f 100644 --- a/gpgme/engine.h +++ b/gpgme/engine.h @@ -29,6 +29,9 @@ const char *_gpgme_engine_get_path (GpgmeProtocol proto); /* Get the version number of the engine for PROTOCOL. */ const char *_gpgme_engine_get_version (GpgmeProtocol proto); +/* Get the version number of the engine for PROTOCOL. */ +const char *_gpgme_engine_req_version (GpgmeProtocol proto); + /* Verify the version requirement for the engine for PROTOCOL. */ const char *_gpgme_engine_get_info (GpgmeProtocol proto); diff --git a/gpgme/gpgme.c b/gpgme/gpgme.c index 472f9f1..d7e0056 100644 --- a/gpgme/gpgme.c +++ b/gpgme/gpgme.c @@ -209,8 +209,6 @@ gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol protocol) case GPGME_PROTOCOL_CMS: ctx->use_cms = 1; break; - case GPGME_PROTOCOL_AUTO: - return GPGME_Not_Implemented; default: return GPGME_Invalid_Value; } @@ -229,6 +227,22 @@ gpgme_get_protocol (GpgmeCtx ctx) } +const char * +gpgme_get_protocol_name (GpgmeProtocol protocol) +{ + switch (protocol) + { + case GPGME_PROTOCOL_OpenPGP: + return "OpenPGP"; + + case GPGME_PROTOCOL_CMS: + return "CMS"; + + default: + return NULL; + } +} + /** * gpgme_set_armor: * @ctx: the context diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 1cea05e..341a32d 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -218,7 +218,6 @@ typedef enum { GPGME_PROTOCOL_OpenPGP = 0, /* The default mode. */ GPGME_PROTOCOL_CMS = 1, - GPGME_PROTOCOL_AUTO = 2 } GpgmeProtocol; @@ -312,6 +311,26 @@ typedef enum { #define GPGME_KEYLIST_MODE_EXTERN 2 #define GPGME_KEYLIST_MODE_SIGS 4 +/* The engine information structure. */ +struct _gpgme_engine_info +{ + struct _gpgme_engine_info *next; + + /* The protocol ID. */ + GpgmeProtocol protocol; + + /* The path to the engine binary. */ + const char *path; + + /* The version string of the installed engine. */ + const char *version; + + /* The minimum version required for GPGME. */ + const char *req_version; +}; +typedef struct _gpgme_engine_info *GpgmeEngineInfo; + + /* Types for callback functions. */ /* Request a passphrase from the user. */ @@ -343,6 +362,9 @@ GpgmeError gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol proto); /* Get the protocol used with CTX */ GpgmeProtocol gpgme_get_protocol (GpgmeCtx ctx); +/* Get the string describing protocol PROTO, or NULL if invalid. */ +const char *gpgme_get_protocol_name (GpgmeProtocol proto); + /* If YES is non-zero, enable armor mode in CTX, disable it otherwise. */ void gpgme_set_armor (GpgmeCtx ctx, int yes); @@ -798,7 +820,7 @@ GpgmeError gpgme_op_trustlist_end (GpgmeCtx ctx); const char *gpgme_check_version (const char *req_version); /* Retrieve information about the backend engines. */ -const char *gpgme_get_engine_info (void); +GpgmeError gpgme_get_engine_info (GpgmeEngineInfo *engine_info); /* Return a string describing ERR. */ const char *gpgme_strerror (GpgmeError err); diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 80981ae..ca1cb0b 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -248,11 +248,10 @@ gpg_get_version (void) } -static GpgmeError -gpg_check_version (void) +static const char * +gpg_get_req_version (void) { - return _gpgme_compare_versions (gpg_get_version (), NEED_GPG_VERSION) - ? 0 : GPGME_Invalid_Engine; + return NEED_GPG_VERSION; } @@ -1646,7 +1645,7 @@ struct engine_ops _gpgme_engine_ops_gpg = /* Static functions. */ _gpgme_get_gpg_path, gpg_get_version, - gpg_check_version, + gpg_get_req_version, gpg_new, /* Member functions. */ diff --git a/gpgme/version.c b/gpgme/version.c index 03cdb32..1af91cf 100644 --- a/gpgme/version.c +++ b/gpgme/version.c @@ -1,6 +1,6 @@ /* version.c - version check Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002 g10 Code GmbH + Copyright (C) 2001, 2002, 2003 g10 Code GmbH This file is part of GPGME. @@ -134,65 +134,57 @@ gpgme_check_version (const char *req_version) return _gpgme_compare_versions (VERSION, req_version); } -/** - * gpgme_get_engine_info: - * - * 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 - * engines. - **/ -const char * -gpgme_get_engine_info () + +/* Get the information about the configured and installed engines. A + pointer to the first engine in the statically allocated linked list + is returned in *INFO. If an error occurs, it is returned. */ +GpgmeError +gpgme_get_engine_info (GpgmeEngineInfo *info) { - static const char *engine_info; + static GpgmeEngineInfo engine_info; DEFINE_STATIC_LOCK (engine_info_lock); LOCK (engine_info_lock); if (!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; + GpgmeEngineInfo *lastp = &engine_info; + GpgmeProtocol proto_list[] = { GPGME_PROTOCOL_OpenPGP, + GPGME_PROTOCOL_CMS }; + int proto; - if (!openpgp_info && !cms_info) - info = "\n\n"; - else if (!openpgp_info || !cms_info) + for (proto = 0; proto < DIM (proto_list); proto++) { - const char *fmt = "\n" - "%s" - "\n"; + const char *path = _gpgme_engine_get_path (proto_list[proto]); - info = malloc (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 = malloc (strlen (fmt) + strlen (openpgp_info) - + strlen (cms_info) + 1); - if (info) - sprintf (info, fmt, openpgp_info, cms_info); + if (!path) + continue; + + *lastp = malloc (sizeof (*engine_info)); + if (!*lastp) + { + while (engine_info) + { + GpgmeEngineInfo next_info = engine_info->next; + free (engine_info); + engine_info = next_info; + } + UNLOCK (engine_info_lock); + return GPGME_Out_Of_Core; + } + + (*lastp)->protocol = proto_list[proto]; + (*lastp)->path = path; + (*lastp)->version = _gpgme_engine_get_version (proto_list[proto]); + (*lastp)->req_version + = _gpgme_engine_get_req_version (proto_list[proto]); + lastp = &(*lastp)->next; } - if (!info) - info = "\n" - " Out of core\n" - "\n"; - engine_info = info; } UNLOCK (engine_info_lock); - return engine_info; + *info = engine_info; + return 0; } - #define LINELENGTH 80 diff --git a/tests/ChangeLog b/tests/ChangeLog index 1ca88b5..425884b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2003-01-30 Marcus Brinkmann + + * Makefile.am (TESTS): Add t-engine-info. + * t-engine-info.c: New file. + * gpg/t-encrypt.c (main): Don't print engine info. + * gpg/t-eventloop.c (main): Likewise. + * gpg/t-encrypt-sign.c (main): Likewise. + * gpgsm/t-encrypt.c (main): Likewise. + 2002-12-24 Marcus Brinkmann * gpgsm/t-verify.c (main): Adjust caller of gpgme_op_verify. diff --git a/tests/Makefile.am b/tests/Makefile.am index b367917..aa1da79 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,7 +21,7 @@ TESTS_ENVIRONMENT = GNUPGHOME=. -TESTS = t-version t-data +TESTS = t-version t-data t-engine-info EXTRA_DIST = t-data-1.txt t-data-2.txt diff --git a/tests/gpg/t-encrypt-sign.c b/tests/gpg/t-encrypt-sign.c index 1517db0..dfd54be 100644 --- a/tests/gpg/t-encrypt-sign.c +++ b/tests/gpg/t-encrypt-sign.c @@ -1,23 +1,22 @@ /* t-encrypt-sign.c - regression test - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 g10 Code GmbH - * - * 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 - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include @@ -94,7 +93,6 @@ main (int argc, char **argv ) err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); - puts ( gpgme_get_engine_info() ); do { err = gpgme_new (&ctx); diff --git a/tests/gpg/t-encrypt.c b/tests/gpg/t-encrypt.c index 14a407d..fa55fd6 100644 --- a/tests/gpg/t-encrypt.c +++ b/tests/gpg/t-encrypt.c @@ -1,23 +1,22 @@ /* t-encrypt.c - regression test - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001 g10 Code GmbH - * - * 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 - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include @@ -74,7 +73,6 @@ main (int argc, char **argv) err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); - puts ( gpgme_get_engine_info() ); do { err = gpgme_new (&ctx); diff --git a/tests/gpg/t-eventloop.c b/tests/gpg/t-eventloop.c index 887de64..71998bd 100644 --- a/tests/gpg/t-eventloop.c +++ b/tests/gpg/t-eventloop.c @@ -1,23 +1,22 @@ /* t-eventloop.c - regression test - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 g10 Code GmbH - * - * 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 - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include @@ -205,7 +204,6 @@ main (int argc, char *argv[]) err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); - puts (gpgme_get_engine_info ()); do { diff --git a/tests/gpgsm/t-encrypt.c b/tests/gpgsm/t-encrypt.c index 4999685..a6f80a4 100644 --- a/tests/gpgsm/t-encrypt.c +++ b/tests/gpgsm/t-encrypt.c @@ -1,23 +1,22 @@ /* t-encrypt.c - regression test - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001 g10 Code GmbH - * - * 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 - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include @@ -92,7 +91,6 @@ main (int argc, char **argv ) err = gpgme_engine_check_version (GPGME_PROTOCOL_CMS); fail_if_err (err); - puts ( gpgme_get_engine_info() ); do { err = gpgme_new (&ctx); diff --git a/tests/t-engine-info.c b/tests/t-engine-info.c new file mode 100644 index 0000000..e4d0eda --- /dev/null +++ b/tests/t-engine-info.c @@ -0,0 +1,92 @@ +/* t-engine-info.c - Regression test for gpgme_get_engine_info. + Copyright (C) 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include + + +#define fail_if_err(err) \ + do \ + { \ + if (err) \ + { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror (err)); \ + exit (1); \ + } \ + } \ + while (0) + + +void +check_engine_info (GpgmeEngineInfo info, GpgmeProtocol protocol, + const char *path, const char *req_version) +{ + if (info->protocol != protocol) + { + fprintf (stderr, "Unexpected protocol %i (expected %i instead)\n", + info->protocol, protocol); + exit (1); + } + if (strcmp (info->path, path)) + { + fprintf (stderr, "Unexpected path to executable %s (expected %s instead)", + info->path, path); + exit (1); + } + if (strcmp (info->req_version, req_version)) + { + fprintf (stderr, "Unexpected required version %s (expected %s instead)", + info->req_version, req_version); + exit (1); + } +} + + +int +main (int argc, char **argv ) +{ + GpgmeEngineInfo info; + GpgmeError err; + + err = gpgme_get_engine_info (&info); + fail_if_err (err); + + check_engine_info (info, GPGME_PROTOCOL_OpenPGP, GPG_PATH, NEED_GPG_VERSION); + + info = info->next; +#ifdef GPGSM_PATH + check_engine_info (info, GPGME_PROTOCOL_CMS, GPGSM_PATH, NEED_GPGSM_VERSION); +#else + if (info) + { + fprintf (stderr, "Unexpected engine info.\n"); + exit (1); + } +#endif + + return 0; +} -- 2.26.2