2002-01-30  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Importing Keys): Add reference to gpgme_get_op_info.

gpgme/
2002-01-30  Marcus Brinkmann  <marcus@g10code.de>

	* import.c (struct import_result_s): New structure.
	(_gpgme_release_import_result): New function.
	(append_xml_impinfo): Likewise.
	(import_status_handler): Implement.
	* gpgme.c (_gpgme_release_result): Add call to
	_gpgme_release_import_result.
	* ops.h (_gpgme_release_impoer_result): Add prototype.
	* types.h (ImportResult): New type.
	* context.h (gpgme_context_s): Add ImportResult to member result.

	* encrypt.c (gpgme_op_encrypt): Code clean up.

tests/
2002-01-30  Marcus Brinkmann  <marcus@g10code.de>

	* gpg/t-import.c (print_op_info): New function.
	(main): Use it.
This commit is contained in:
Marcus Brinkmann 2002-01-30 21:52:32 +00:00
parent 1677f80d7e
commit 088c044792
11 changed files with 270 additions and 90 deletions

View File

@ -1,3 +1,7 @@
2002-01-30 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Importing Keys): Add reference to gpgme_get_op_info.
2002-01-30 Marcus Brinkmann <marcus@g10code.de> 2002-01-30 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi: Some spell checking. * gpgme.texi: Some spell checking.

View File

@ -1529,6 +1529,9 @@ The function @code{gpgme_op_import} adds the keys in the data buffer
The format of @var{keydata} can be @var{ASCII} armored, for example, The format of @var{keydata} can be @var{ASCII} armored, for example,
but the details are specific to the crypto engine. but the details are specific to the crypto engine.
More information about the import is available with
@code{gpgme_get_op_info}. @xref{Detailed Results}.
The function returns @code{GPGME_No_Error} if the import was completed The function returns @code{GPGME_No_Error} if the import was completed
successfully, @code{GPGME_Invalid_Value} if @var{keydata} if @var{ctx} 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 or @var{keydata} is not a valid pointer, and @code{GPGME_No_Data} if

View File

@ -1,3 +1,17 @@
2002-01-30 Marcus Brinkmann <marcus@g10code.de>
* import.c (struct import_result_s): New structure.
(_gpgme_release_import_result): New function.
(append_xml_impinfo): Likewise.
(import_status_handler): Implement.
* gpgme.c (_gpgme_release_result): Add call to
_gpgme_release_import_result.
* ops.h (_gpgme_release_impoer_result): Add prototype.
* types.h (ImportResult): New type.
* context.h (gpgme_context_s): Add ImportResult to member result.
* encrypt.c (gpgme_op_encrypt): Code clean up.
2002-01-30 Marcus Brinkmann <marcus@g10code.de> 2002-01-30 Marcus Brinkmann <marcus@g10code.de>
* gpgme.h: Add lots of comment and fix the formatting. Add * gpgme.h: Add lots of comment and fix the formatting. Add

View File

@ -68,6 +68,7 @@ struct gpgme_context_s {
SignResult sign; SignResult sign;
EncryptResult encrypt; EncryptResult encrypt;
PassphraseResult passphrase; PassphraseResult passphrase;
ImportResult import;
} result; } result;
GpgmeData notation; /* last signature notation */ GpgmeData notation; /* last signature notation */

View File

@ -59,82 +59,82 @@ _gpgme_release_encrypt_result (EncryptResult result)
static void static void
append_xml_encinfo (GpgmeData *rdh, char *args) append_xml_encinfo (GpgmeData *rdh, char *args)
{ {
GpgmeData dh; GpgmeData dh;
char helpbuf[100]; char helpbuf[100];
if ( !*rdh ) { if (!*rdh)
if (gpgme_data_new (rdh)) { {
return; /* fixme: We are ignoring out-of-core */ if (gpgme_data_new (rdh))
} return; /* FIXME: We are ignoring out-of-core. */
dh = *rdh; dh = *rdh;
_gpgme_data_append_string (dh, "<GnupgOperationInfo>\n"); _gpgme_data_append_string (dh, "<GnupgOperationInfo>\n");
} }
else { else
dh = *rdh; {
_gpgme_data_append_string (dh, " </encryption>\n"); dh = *rdh;
_gpgme_data_append_string (dh, " </encryption>\n");
} }
if (!args) { /* just close the XML containter */ if (!args)
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n"); {
return; /* Just close the XML containter. */
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n");
return;
} }
_gpgme_data_append_string (dh, " <encryption>\n" _gpgme_data_append_string (dh, " <encryption>\n"
" <error>\n" " <error>\n"
" <invalidRecipient/>\n"); " <invalidRecipient/>\n");
sprintf (helpbuf, " <reason>%d</reason>\n", atoi (args)); sprintf (helpbuf, " <reason>%d</reason>\n", atoi (args));
_gpgme_data_append_string (dh, helpbuf); _gpgme_data_append_string (dh, helpbuf);
SKIP_TOKEN_OR_RETURN (args); SKIP_TOKEN_OR_RETURN (args);
_gpgme_data_append_string (dh, " <name>"); _gpgme_data_append_string (dh, " <name>");
_gpgme_data_append_percentstring_for_xml (dh, args); _gpgme_data_append_percentstring_for_xml (dh, args);
_gpgme_data_append_string (dh, "</name>\n" _gpgme_data_append_string (dh, "</name>\n"
" </error>\n"); " </error>\n");
} }
static void static void
encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
{ {
if (ctx->out_of_core) if (ctx->out_of_core)
return; return;
if (!ctx->result.encrypt) if (!ctx->result.encrypt)
{ {
ctx->result.encrypt = xtrycalloc (1, sizeof *ctx->result.encrypt); ctx->result.encrypt = xtrycalloc (1, sizeof *ctx->result.encrypt);
if (!ctx->result.encrypt) if (!ctx->result.encrypt)
{ {
ctx->out_of_core = 1; ctx->out_of_core = 1;
return; return;
} }
}
switch (code) {
case STATUS_EOF:
if (ctx->result.encrypt->xmlinfo) {
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, NULL);
_gpgme_set_op_info (ctx, ctx->result.encrypt->xmlinfo);
ctx->result.encrypt->xmlinfo = NULL;
}
break;
case STATUS_INV_RECP:
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, args);
break;
case STATUS_NO_RECP:
ctx->result.encrypt->no_recipients = 1; /* i.e. no usable ones */
break;
default:
break;
} }
} switch (code)
{
case STATUS_EOF:
if (ctx->result.encrypt->xmlinfo)
{
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, NULL);
_gpgme_set_op_info (ctx, ctx->result.encrypt->xmlinfo);
ctx->result.encrypt->xmlinfo = NULL;
}
break;
case STATUS_INV_RECP:
append_xml_encinfo (&ctx->result.encrypt->xmlinfo, args);
break;
case STATUS_NO_RECP:
ctx->result.encrypt->no_recipients = 1; /* i.e. no usable ones */
break;
default:
break;
}
}
GpgmeError GpgmeError
@ -213,28 +213,30 @@ gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain,
* Return value: 0 on success or an errorcode. * Return value: 0 on success or an errorcode.
**/ **/
GpgmeError GpgmeError
gpgme_op_encrypt ( GpgmeCtx c, GpgmeRecipients recp, gpgme_op_encrypt (GpgmeCtx ctx, GpgmeRecipients recp,
GpgmeData in, GpgmeData out ) GpgmeData plain, GpgmeData cipher)
{ {
int err = gpgme_op_encrypt_start ( c, recp, in, out ); int err = gpgme_op_encrypt_start (ctx, recp, plain, cipher);
if ( !err ) { if (!err)
gpgme_wait (c, 1); {
if (!c->result.encrypt) gpgme_wait (ctx, 1);
err = mk_error (General_Error); if (!ctx->result.encrypt)
else if (c->out_of_core) err = mk_error (General_Error);
err = mk_error (Out_Of_Core); else if (ctx->out_of_core)
else { err = mk_error (Out_Of_Core);
if (c->result.encrypt->no_recipients) else
err = mk_error (No_Recipients); {
if (ctx->result.encrypt->no_recipients)
err = mk_error (No_Recipients);
} }
/* Old gpg versions don't return status info for invalid /* Old gpg versions don't return status info for invalid
* recipients, so we simply check whether we got any output at recipients, so we simply check whether we got any output at
* all and if not assume that we don't have valid recipients all, and if not we assume that we don't have valid
* */ recipients. */
if (!err && gpgme_data_get_type (out) == GPGME_DATA_TYPE_NONE) if (!err && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE)
err = mk_error (No_Recipients); err = mk_error (No_Recipients);
} }
return err; return err;
} }

View File

@ -86,6 +86,7 @@ _gpgme_release_result (GpgmeCtx ctx)
_gpgme_release_sign_result (ctx->result.sign); _gpgme_release_sign_result (ctx->result.sign);
_gpgme_release_encrypt_result (ctx->result.encrypt); _gpgme_release_encrypt_result (ctx->result.encrypt);
_gpgme_release_passphrase_result (ctx->result.passphrase); _gpgme_release_passphrase_result (ctx->result.passphrase);
_gpgme_release_import_result (ctx->result.import);
memset (&ctx->result, 0, sizeof (ctx->result)); memset (&ctx->result, 0, sizeof (ctx->result));
_gpgme_set_op_info (ctx, NULL); _gpgme_set_op_info (ctx, NULL);
} }

View File

@ -1,6 +1,6 @@
/* import.c - encrypt functions /* import.c - encrypt functions
* Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -29,15 +29,146 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
static void
import_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) struct import_result_s
{ {
DEBUG2 ("import_status: code=%d args=`%s'\n", code, args ); GpgmeData xmlinfo;
/* FIXME: We have to check here whether the import actually worked };
* and maybe it is a good idea to save some statistics and provide
* a progress callback */
void
_gpgme_release_import_result (ImportResult result)
{
if (!result)
return;
gpgme_data_release (result->xmlinfo);
xfree (result);
} }
/* Parse the args and append the information to the XML structure in
the data buffer. With args of NULL the xml structure is
closed. */
static void
append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args)
{
#define MAX_IMPORTED_FIELDS 13
static char *imported_fields[MAX_IMPORTED_FIELDS]
= { "keyid", "username", 0 };
static char *import_res_fields[MAX_IMPORTED_FIELDS]
= { "count", "no_user_id", "imported", "imported_rsa",
"unchanged", "n_uids", "n_subk", "n_sigs", "s_sigsn_revoc",
"sec_read", "sec_imported", "sec_dups", "skipped_new", 0 };
char *field[MAX_IMPORTED_FIELDS];
char **field_name = 0;
GpgmeData dh;
int i;
/* Verify that we can use the args. */
if (code != STATUS_EOF)
{
if (!args)
return;
if (code == STATUS_IMPORTED)
field_name = imported_fields;
else if (code == STATUS_IMPORT_RES)
field_name = import_res_fields;
else
return;
for (i = 0; field_name[i]; i++)
{
field[i] = args;
if (field_name[i + 1])
{
args = strchr (args, ' ');
if (!args)
return; /* Invalid line. */
*args++ = '\0';
}
}
}
/* Initialize the data buffer if necessary. */
if (!*rdh)
{
if (gpgme_data_new (rdh))
return; /* FIXME: We are ignoring out-of-core. */
dh = *rdh;
_gpgme_data_append_string (dh, "<GnupgOperationInfo>\n");
}
else
dh = *rdh;
if (code == STATUS_EOF)
{
/* Just close the XML containter. */
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n");
}
else
{
if (code == STATUS_IMPORTED)
_gpgme_data_append_string (dh, " <import>\n");
else if (code == STATUS_IMPORT_RES)
_gpgme_data_append_string (dh, " <importResult>\n");
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, ">");
_gpgme_data_append_string (dh, field[i]);
_gpgme_data_append_string (dh, "</");
_gpgme_data_append_string (dh, field_name[i]);
_gpgme_data_append_string (dh, ">\n");
}
if (code == STATUS_IMPORTED)
_gpgme_data_append_string (dh, " </import>\n");
else if (code == STATUS_IMPORT_RES)
_gpgme_data_append_string (dh, " </importResult>\n");
}
}
static void
import_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
{
if (ctx->out_of_core)
return;
if (!ctx->result.import)
{
ctx->result.import = xtrycalloc (1, sizeof *ctx->result.import);
if (!ctx->result.import)
{
ctx->out_of_core = 1;
return;
}
}
switch (code)
{
case STATUS_EOF:
if (ctx->result.import->xmlinfo)
{
append_xml_impinfo (&ctx->result.import->xmlinfo, code, NULL);
_gpgme_set_op_info (ctx, ctx->result.import->xmlinfo);
ctx->result.import->xmlinfo = NULL;
}
break;
case STATUS_IMPORTED:
case STATUS_IMPORT_RES:
append_xml_impinfo (&ctx->result.import->xmlinfo, code, args);
break;
default:
break;
}
}
GpgmeError GpgmeError
gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata) gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)
{ {
@ -79,6 +210,7 @@ gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)
return err; return err;
} }
/** /**
* gpgme_op_import: * gpgme_op_import:
* @c: Context * @c: Context
@ -96,7 +228,3 @@ gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata)
gpgme_wait (ctx, 1); gpgme_wait (ctx, 1);
return err; return err;
} }

View File

@ -95,6 +95,9 @@ void _gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code,
GpgmeError _gpgme_passphrase_start (GpgmeCtx ctx); GpgmeError _gpgme_passphrase_start (GpgmeCtx ctx);
GpgmeError _gpgme_passphrase_result (GpgmeCtx ctx); GpgmeError _gpgme_passphrase_result (GpgmeCtx ctx);
/*-- import.c --*/
void _gpgme_release_import_result (ImportResult res);
/*-- version.c --*/ /*-- version.c --*/
const char *_gpgme_compare_versions (const char *my_version, const char *_gpgme_compare_versions (const char *my_version,
const char *req_version); const char *req_version);

View File

@ -76,7 +76,9 @@ typedef struct encrypt_result_s *EncryptResult;
struct passphrase_result_s; struct passphrase_result_s;
typedef struct passphrase_result_s *PassphraseResult; typedef struct passphrase_result_s *PassphraseResult;
/*-- key.c --*/ /*-- import.c --*/
struct import_result_s;
typedef struct import_result_s *ImportResult;
#endif /* TYPES_H */ #endif /* TYPES_H */

View File

@ -1,3 +1,8 @@
2002-01-30 Marcus Brinkmann <marcus@g10code.de>
* gpg/t-import.c (print_op_info): New function.
(main): Use it.
2002-01-22 Marcus Brinkmann <marcus@g10code.de> 2002-01-22 Marcus Brinkmann <marcus@g10code.de>
* gpg/t-signers.c (passphrase_cb): Change type of r_hd to void**. * gpg/t-signers.c (passphrase_cb): Change type of r_hd to void**.

View File

@ -54,6 +54,21 @@ mk_fname ( const char *fname )
return buf; 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 int
main (int argc, char **argv ) main (int argc, char **argv )
{ {
@ -72,6 +87,7 @@ main (int argc, char **argv )
err = gpgme_op_import (ctx, in ); err = gpgme_op_import (ctx, in );
fail_if_err (err); fail_if_err (err);
print_op_info (ctx);
gpgme_data_release (in); gpgme_data_release (in);
@ -80,6 +96,7 @@ main (int argc, char **argv )
err = gpgme_op_import (ctx, in ); err = gpgme_op_import (ctx, in );
fail_if_err (err); fail_if_err (err);
print_op_info (ctx);
gpgme_data_release (in); gpgme_data_release (in);
gpgme_release (ctx); gpgme_release (ctx);