diff options
| -rw-r--r-- | doc/ChangeLog | 4 | ||||
| -rw-r--r-- | doc/gpgme.texi | 3 | ||||
| -rw-r--r-- | gpgme/ChangeLog | 14 | ||||
| -rw-r--r-- | gpgme/context.h | 1 | ||||
| -rw-r--r-- | gpgme/encrypt.c | 154 | ||||
| -rw-r--r-- | gpgme/gpgme.c | 1 | ||||
| -rw-r--r-- | gpgme/import.c | 148 | ||||
| -rw-r--r-- | gpgme/ops.h | 3 | ||||
| -rw-r--r-- | gpgme/types.h | 4 | ||||
| -rw-r--r-- | tests/ChangeLog | 5 | ||||
| -rw-r--r-- | tests/gpg/t-import.c | 17 | 
11 files changed, 267 insertions, 87 deletions
| diff --git a/doc/ChangeLog b/doc/ChangeLog index c3850209..bfe382e2 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,9 @@  2002-01-30  Marcus Brinkmann  <[email protected]> +	* gpgme.texi (Importing Keys): Add reference to gpgme_get_op_info. + +2002-01-30  Marcus Brinkmann  <[email protected]> +  	* gpgme.texi: Some spell checking.  2002-01-30  Marcus Brinkmann  <[email protected]> diff --git a/doc/gpgme.texi b/doc/gpgme.texi index e4731270..44b69970 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -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,  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  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 diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 2c0851f0..010c21eb 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,5 +1,19 @@  2002-01-30  Marcus Brinkmann  <[email protected]> +	* 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  <[email protected]> +  	* gpgme.h: Add lots of comment and fix the formatting.  Add  	gpgme_trustlist_end prototype. diff --git a/gpgme/context.h b/gpgme/context.h index df2f40ae..02d39545 100644 --- a/gpgme/context.h +++ b/gpgme/context.h @@ -68,6 +68,7 @@ struct gpgme_context_s {          SignResult sign;          EncryptResult encrypt;          PassphraseResult passphrase; +        ImportResult import;      } result;      GpgmeData notation;    /* last signature notation */ diff --git a/gpgme/encrypt.c b/gpgme/encrypt.c index 3c457f0d..43d1b2c9 100644 --- a/gpgme/encrypt.c +++ b/gpgme/encrypt.c @@ -59,84 +59,84 @@ _gpgme_release_encrypt_result (EncryptResult result)  static void  append_xml_encinfo (GpgmeData *rdh, char *args)  { -    GpgmeData dh; -    char helpbuf[100]; +  GpgmeData dh; +  char helpbuf[100]; -    if ( !*rdh ) { -        if (gpgme_data_new (rdh)) { -            return; /* fixme: We are ignoring out-of-core */ -        } -        dh = *rdh; -        _gpgme_data_append_string (dh, "<GnupgOperationInfo>\n"); +  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; -        _gpgme_data_append_string (dh, "  </encryption>\n"); +  else +    { +      dh = *rdh; +      _gpgme_data_append_string (dh, "  </encryption>\n");      } -    if (!args) { /* just close the XML containter */ -        _gpgme_data_append_string (dh, "</GnupgOperationInfo>\n"); -        return; +  if (!args) +    { +      /* Just close the XML containter.  */ +      _gpgme_data_append_string (dh, "</GnupgOperationInfo>\n"); +      return;      } -    _gpgme_data_append_string (dh, "  <encryption>\n" -                                   "    <error>\n" -                                   "      <invalidRecipient/>\n"); +  _gpgme_data_append_string (dh, "  <encryption>\n" +			     "    <error>\n" +			     "      <invalidRecipient/>\n"); -    sprintf (helpbuf, "      <reason>%d</reason>\n", atoi (args)); -    _gpgme_data_append_string (dh, helpbuf); -    SKIP_TOKEN_OR_RETURN (args); - -    _gpgme_data_append_string (dh, "      <name>"); -    _gpgme_data_append_percentstring_for_xml (dh, args); -    _gpgme_data_append_string (dh, "</name>\n" -                                   "    </error>\n"); +  sprintf (helpbuf, "      <reason>%d</reason>\n", atoi (args)); +  _gpgme_data_append_string (dh, helpbuf); +  SKIP_TOKEN_OR_RETURN (args); + +  _gpgme_data_append_string (dh, "      <name>"); +  _gpgme_data_append_percentstring_for_xml (dh, args); +  _gpgme_data_append_string (dh, "</name>\n" +			     "    </error>\n");  } - - -  static void  encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)  { -    if (ctx->out_of_core) -      return; -    if (!ctx->result.encrypt) -      { -        ctx->result.encrypt = xtrycalloc (1, sizeof *ctx->result.encrypt); -        if (!ctx->result.encrypt) -	  { -            ctx->out_of_core = 1; -            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; +  if (ctx->out_of_core) +    return; +  if (!ctx->result.encrypt) +    { +      ctx->result.encrypt = xtrycalloc (1, sizeof *ctx->result.encrypt); +      if (!ctx->result.encrypt) +	{ +	  ctx->out_of_core = 1; +	  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; +      break; -      case STATUS_INV_RECP: -        append_xml_encinfo (&ctx->result.encrypt->xmlinfo, args); -        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; +    case STATUS_NO_RECP: +      ctx->result.encrypt->no_recipients = 1; /* i.e. no usable ones */ +      break; -      default: -        break; +    default: +      break;      } -  } -  GpgmeError  gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain,  			GpgmeData ciph) @@ -213,28 +213,30 @@ gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain,   * Return value:  0 on success or an errorcode.    **/  GpgmeError -gpgme_op_encrypt ( GpgmeCtx c, GpgmeRecipients recp, -                   GpgmeData in, GpgmeData out ) +gpgme_op_encrypt (GpgmeCtx ctx, GpgmeRecipients recp, +		  GpgmeData plain, GpgmeData cipher)  { -    int err = gpgme_op_encrypt_start ( c, recp, in, out ); -    if ( !err ) { -        gpgme_wait (c, 1); -        if (!c->result.encrypt) -            err = mk_error (General_Error); -        else if (c->out_of_core) -            err = mk_error (Out_Of_Core); -        else { -            if (c->result.encrypt->no_recipients)  -                err = mk_error (No_Recipients); +  int err = gpgme_op_encrypt_start (ctx, recp, plain, cipher); +  if (!err) +    { +      gpgme_wait (ctx, 1); +      if (!ctx->result.encrypt) +	err = mk_error (General_Error); +      else if (ctx->out_of_core) +	err = mk_error (Out_Of_Core); +      else +	{ +	  if (ctx->result.encrypt->no_recipients)  +	    err = mk_error (No_Recipients);          } -        /* Old gpg versions don't return status info for invalid -         * recipients, so we simply check whether we got any output at -         * all and if not assume that we don't have valid recipients -         * */ -        if (!err && gpgme_data_get_type (out) == GPGME_DATA_TYPE_NONE) -            err = mk_error (No_Recipients); +      /* Old gpg versions don't return status info for invalid +	 recipients, so we simply check whether we got any output at +	 all, and if not we assume that we don't have valid +	 recipients.  */ +      if (!err && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE) +	err = mk_error (No_Recipients);      } -    return err; +  return err;  } diff --git a/gpgme/gpgme.c b/gpgme/gpgme.c index fe848327..25e6b617 100644 --- a/gpgme/gpgme.c +++ b/gpgme/gpgme.c @@ -86,6 +86,7 @@ _gpgme_release_result (GpgmeCtx ctx)    _gpgme_release_sign_result (ctx->result.sign);    _gpgme_release_encrypt_result (ctx->result.encrypt);    _gpgme_release_passphrase_result (ctx->result.passphrase); +  _gpgme_release_import_result (ctx->result.import);    memset (&ctx->result, 0, sizeof (ctx->result));    _gpgme_set_op_info (ctx, NULL);  } diff --git a/gpgme/import.c b/gpgme/import.c index 2f830c7e..81990572 100644 --- a/gpgme/import.c +++ b/gpgme/import.c @@ -1,6 +1,6 @@  /* import.c -  encrypt functions   *	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.   * @@ -29,15 +29,146 @@  #include "context.h"  #include "ops.h" + +struct import_result_s +{ +  GpgmeData xmlinfo; +}; + + +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 -import_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) +append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args)  { -    DEBUG2 ("import_status: code=%d args=`%s'\n", code, args ); -    /* 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 */ +#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  gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)  { @@ -79,6 +210,7 @@ gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)    return err;  } +  /**   * gpgme_op_import:   * @c: Context  @@ -96,7 +228,3 @@ gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata)      gpgme_wait (ctx, 1);    return err;  } - - - - diff --git a/gpgme/ops.h b/gpgme/ops.h index 93103b57..dcdeba7e 100644 --- a/gpgme/ops.h +++ b/gpgme/ops.h @@ -95,6 +95,9 @@ void _gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code,  GpgmeError _gpgme_passphrase_start (GpgmeCtx ctx);  GpgmeError _gpgme_passphrase_result (GpgmeCtx ctx); +/*-- import.c --*/ +void _gpgme_release_import_result (ImportResult res); +  /*-- version.c --*/  const char *_gpgme_compare_versions (const char *my_version,  				     const char *req_version); diff --git a/gpgme/types.h b/gpgme/types.h index 8f80a0b3..71dab9a4 100644 --- a/gpgme/types.h +++ b/gpgme/types.h @@ -76,7 +76,9 @@ typedef struct encrypt_result_s *EncryptResult;  struct passphrase_result_s;  typedef struct passphrase_result_s *PassphraseResult; -/*-- key.c --*/ +/*-- import.c --*/ +struct import_result_s; +typedef struct import_result_s *ImportResult;  #endif /* TYPES_H */ diff --git a/tests/ChangeLog b/tests/ChangeLog index 3fec7f7a..e7369522 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2002-01-30  Marcus Brinkmann  <[email protected]> + +	* gpg/t-import.c (print_op_info): New function. +	(main): Use it. +  2002-01-22  Marcus Brinkmann  <[email protected]>  	* gpg/t-signers.c (passphrase_cb): Change type of r_hd to void**. diff --git a/tests/gpg/t-import.c b/tests/gpg/t-import.c index 25ea20f5..7bf21244 100644 --- a/tests/gpg/t-import.c +++ b/tests/gpg/t-import.c @@ -54,6 +54,21 @@ mk_fname ( const char *fname )      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 )  { @@ -72,6 +87,7 @@ main (int argc, char **argv )      err = gpgme_op_import (ctx, in );      fail_if_err (err); +    print_op_info (ctx);      gpgme_data_release (in); @@ -80,6 +96,7 @@ main (int argc, char **argv )      err = gpgme_op_import (ctx, in );      fail_if_err (err); +    print_op_info (ctx);      gpgme_data_release (in);      gpgme_release (ctx); | 
