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}})
+2002-06-26 Werner Koch <wk@gnupg.org>
+
+ * 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 <wk@gnupg.org>
* engine-gpgsm.c (_gpgme_gpgsm_set_io_cbs) [ENABLE_GPGSM]: Fixed
struct import_result_s
{
+ int any_imported;
GpgmeData xmlinfo;
};
#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",
*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. */
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, "</");
break;
case STATUS_IMPORTED:
+ ctx->result.import->any_imported = 1;
case STATUS_IMPORT_RES:
append_xml_impinfo (&ctx->result.import->xmlinfo, code, args);
break;
*
* 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)
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;
}
+
return buf;
}
+static void
+print_op_info (GpgmeCtx c)
+{
+ char *s = gpgme_get_op_info (c, 0);
+
+ if (!s)
+ puts ("<!-- no operation info available -->");
+ else {
+ puts (s);
+ free (s);
+ }
+}
+
+
int
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);
fail_if_err (err);
err = gpgme_op_import (ctx, in);
+ print_op_info (ctx);
fail_if_err (err);
gpgme_data_release (in);