From: Werner Koch Date: Wed, 26 Jun 2002 12:49:59 +0000 (+0000) Subject: * gpgsm/t-import.c (print_op_info): New. X-Git-Tag: gpgme-1.2.0@1385~920 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7bee5c61d56b0c360e896fb8e4007f0870b8b5d0;p=gpgme.git * gpgsm/t-import.c (print_op_info): New. (main): Print operation info. * engine-gpgsm.c (map_assuan_error): Map No_Data_Available to EOF. * import.c (append_xml_impinfo): Kludge to print fingerprint instead of keyid for use with gpgsm. (import_status_handler): Set a flag to know whether any import occured. (gpgme_op_import): Reurn -1 if no certificate ewas imported. * gpgme.texi (Importing Keys): Document the return value -1 of gpgme_op_import. --- diff --git a/trunk/doc/ChangeLog b/trunk/doc/ChangeLog index 3c9cee8..fcf65e3 100644 --- a/trunk/doc/ChangeLog +++ b/trunk/doc/ChangeLog @@ -1,3 +1,8 @@ +2002-06-26 Werner Koch + + * gpgme.texi (Importing Keys): Document the return value -1 of + gpgme_op_import. + 2002-06-20 Werner Koch * gpgme.texi (Verify): Explain the new whatidx variable. diff --git a/trunk/doc/gpgme.texi b/trunk/doc/gpgme.texi index 9f07ee9..24e9f92 100644 --- a/trunk/doc/gpgme.texi +++ b/trunk/doc/gpgme.texi @@ -1900,8 +1900,9 @@ More information about the import is available with The function returns @code{GPGME_No_Error} if the import was completed successfully, @code{GPGME_Invalid_Value} if @var{keydata} if @var{ctx} -or @var{keydata} is not a valid pointer, and @code{GPGME_No_Data} if -@var{keydata} is an empty data buffer. +or @var{keydata} is not a valid pointer, @code{GPGME_No_Data} if +@var{keydata} is an empty data buffer, and @code{GPGME_EOF} if the +operation was completed successfully but no data was actually imported. @end deftypefun @deftypefun GpgmeError gpgme_op_import_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{keydata}}) diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 35550fc..4ae4046 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,13 @@ +2002-06-26 Werner Koch + + * engine-gpgsm.c (map_assuan_error): Map No_Data_Available to EOF. + + * import.c (append_xml_impinfo): Kludge to print fingerprint + instead of keyid for use with gpgsm. + (import_status_handler): Set a flag to know whether any import + occured. + (gpgme_op_import): Reurn -1 if no certificate ewas imported. + 2002-06-25 Werner Koch * engine-gpgsm.c (_gpgme_gpgsm_set_io_cbs) [ENABLE_GPGSM]: Fixed diff --git a/trunk/gpgme/engine-gpgsm.c b/trunk/gpgme/engine-gpgsm.c index 2dfdf35..67f1e7c 100644 --- a/trunk/gpgme/engine-gpgsm.c +++ b/trunk/gpgme/engine-gpgsm.c @@ -220,8 +220,10 @@ map_assuan_error (AssuanError err) case ASSUAN_Unsupported_Algorithm: return mk_error (Not_Implemented); /* XXX Argh. */ - /* These are errors internal to GPGME. */ case ASSUAN_No_Data_Available: + return mk_error (EOF); + + /* These are errors internal to GPGME. */ case ASSUAN_No_Input: case ASSUAN_No_Output: case ASSUAN_Invalid_Command: diff --git a/trunk/gpgme/import.c b/trunk/gpgme/import.c index 493b301..754bdb9 100644 --- a/trunk/gpgme/import.c +++ b/trunk/gpgme/import.c @@ -32,6 +32,7 @@ struct import_result_s { + int any_imported; GpgmeData xmlinfo; }; @@ -55,6 +56,8 @@ append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args) #define MAX_IMPORTED_FIELDS 14 static const char *const imported_fields[MAX_IMPORTED_FIELDS] = { "keyid", "username", 0 }; + static const char *const imported_fields_x509[MAX_IMPORTED_FIELDS] + = { "fpr", 0 }; static const char *const import_res_fields[MAX_IMPORTED_FIELDS] = { "count", "no_user_id", "imported", "imported_rsa", "unchanged", "n_uids", "n_subk", "n_sigs", "s_sigsn_revoc", @@ -88,6 +91,11 @@ append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args) *args++ = '\0'; } } + + /* gpgsm does not print a useful user ID and uses a fingerprint + instead of the key ID. */ + if (code == STATUS_IMPORTED && field[0] && strlen (field[0]) > 16) + field_name = imported_fields_x509; } /* Initialize the data buffer if necessary. */ @@ -116,7 +124,7 @@ append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args) for (i = 0; field_name[i]; i++) { _gpgme_data_append_string (dh, " <"); - _gpgme_data_append_string (dh, field_name[i]); + _gpgme_data_append_string (dh, field_name[i]); _gpgme_data_append_string (dh, ">"); _gpgme_data_append_string (dh, field[i]); _gpgme_data_append_string (dh, "result.import->any_imported = 1; case STATUS_IMPORT_RES: append_xml_impinfo (&ctx->result.import->xmlinfo, code, args); break; @@ -211,7 +220,7 @@ gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata) * * Import all key material from @keydata into the key database. * - * Return value: o on success or an error code. + * Return value: 0 on success or an error code. **/ GpgmeError gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata) @@ -219,5 +228,8 @@ gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata) GpgmeError err = _gpgme_op_import_start (ctx, 1, keydata); if (!err) err = _gpgme_wait_one (ctx); + if (!err && (!ctx->result.import || !ctx->result.import->any_imported)) + err = -1; /* Nothing at all imported. */ return err; } + diff --git a/trunk/tests/ChangeLog b/trunk/tests/ChangeLog index adbcc48..f22e1ab 100644 --- a/trunk/tests/ChangeLog +++ b/trunk/tests/ChangeLog @@ -1,3 +1,8 @@ +2002-06-26 Werner Koch + + * gpgsm/t-import.c (print_op_info): New. + (main): Print operation info. + 2002-06-25 Werner Koch * gpgsm/Makefile.am (DISTCLEANFILES): new. diff --git a/trunk/tests/gpgsm/t-import.c b/trunk/tests/gpgsm/t-import.c index f62ff00..974cdd9 100644 --- a/trunk/tests/gpgsm/t-import.c +++ b/trunk/tests/gpgsm/t-import.c @@ -57,6 +57,20 @@ make_filename (const char *fname) return buf; } +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + int main (int argc, char **argv) { @@ -76,6 +90,7 @@ main (int argc, char **argv) fail_if_err (err); err = gpgme_op_import (ctx, in); + print_op_info (ctx); fail_if_err (err); gpgme_data_release (in); @@ -84,6 +99,7 @@ main (int argc, char **argv) fail_if_err (err); err = gpgme_op_import (ctx, in); + print_op_info (ctx); fail_if_err (err); gpgme_data_release (in);