From cdf43d2f08eb34e44e9769280758cef2b53fceed Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 3 Sep 2001 18:41:53 +0000 Subject: [PATCH] Some changes --- trunk/gpgme/ChangeLog | 11 +++++ trunk/gpgme/context.h | 2 + trunk/gpgme/encrypt.c | 103 ++++++++++++++++++++++++++++++++++++++- trunk/gpgme/gpgme.c | 3 ++ trunk/gpgme/ops.h | 3 ++ trunk/gpgme/posix-util.c | 4 +- trunk/gpgme/recipient.c | 9 +++- trunk/gpgme/rungpg.h | 3 +- trunk/gpgme/types.h | 4 ++ trunk/jnlib/ChangeLog | 4 ++ trunk/jnlib/logging.c | 4 +- trunk/tests/t-encrypt.c | 15 ++++++ 12 files changed, 157 insertions(+), 8 deletions(-) diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index fedd4b1..5437ad5 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,5 +1,16 @@ +2001-09-03 Werner Koch + + * rungpg.h: Added STATUS_INV_RECP. + * gpgme.c (_gpgme_release_result): Add support for new + EncryptResult object. + * encrypt.c (append_xml_encinfo): New. + (encrypt_status_handler): Add some status parsing. + (_gpgme_release_encrypt_result): New. + 2001-08-29 Werner Koch + * recipient.c (gpgme_recipients_release): Free the list. By Timo. + * keylist.c (keylist_colon_handler): Do a finish key if we receive an EOF here. This is probably the reason for a lot of bugs related to keylisting. It is so obvious. Kudos to Enno Cramer diff --git a/trunk/gpgme/context.h b/trunk/gpgme/context.h index 662889f..ad5886c 100644 --- a/trunk/gpgme/context.h +++ b/trunk/gpgme/context.h @@ -31,6 +31,7 @@ typedef enum { RESULT_TYPE_VERIFY, RESULT_TYPE_DECRYPT, RESULT_TYPE_SIGN, + RESULT_TYPE_ENCRYPT } ResultType; @@ -72,6 +73,7 @@ struct gpgme_context_s { VerifyResult verify; DecryptResult decrypt; SignResult sign; + EncryptResult encrypt; } result; GpgmeData notation; /* last signature notation */ diff --git a/trunk/gpgme/encrypt.c b/trunk/gpgme/encrypt.c index bff4153..00531a0 100644 --- a/trunk/gpgme/encrypt.c +++ b/trunk/gpgme/encrypt.c @@ -29,10 +29,106 @@ #include "context.h" #include "ops.h" +#define SKIP_TOKEN_OR_RETURN(a) do { \ + while (*(a) && *(a) != ' ') (a)++; \ + while (*(a) == ' ') (a)++; \ + if (!*(a)) \ + return; /* oops */ \ +} while (0) + + + +struct encrypt_result_s { + GpgmeData xmlinfo; +}; + + +void +_gpgme_release_encrypt_result (EncryptResult res) +{ + gpgme_data_release (res->xmlinfo); + xfree (res); +} + + +/* + * Parse the args and save the information + * in an XML structure. + * With args of NULL the xml structure is closed. + */ +static void +append_xml_encinfo (GpgmeData *rdh, char *args) +{ + 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, "\n"); + } + else { + dh = *rdh; + _gpgme_data_append_string (dh, " \n"); + } + + if (!args) { /* just close the XML containter */ + _gpgme_data_append_string (dh, "\n"); + return; + } + + _gpgme_data_append_string (dh, " \n" + " \n" + " \n"); + + sprintf (helpbuf, " %d\n", atoi (args)); + _gpgme_data_append_string (dh, helpbuf); + SKIP_TOKEN_OR_RETURN (args); + + _gpgme_data_append_string (dh, " "); + _gpgme_data_append_percentstring_for_xml (dh, args); + _gpgme_data_append_string (dh, "\n" + " \n"); +} + + + + + static void encrypt_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) { - DEBUG2 ("encrypt_status: code=%d args=`%s'\n", code, args ); + if ( ctx->out_of_core ) + return; + if ( ctx->result_type == RESULT_TYPE_NONE ) { + assert ( !ctx->result.encrypt ); + ctx->result.encrypt = xtrycalloc ( 1, sizeof *ctx->result.encrypt ); + if ( !ctx->result.encrypt ) { + ctx->out_of_core = 1; + return; + } + ctx->result_type = RESULT_TYPE_ENCRYPT; + } + assert ( ctx->result_type == RESULT_TYPE_ENCRYPT ); + + 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; + + default: + break; + } } @@ -48,6 +144,9 @@ gpgme_op_encrypt_start ( GpgmeCtx c, GpgmeRecipients recp, fail_on_pending_request( c ); c->pending = 1; + _gpgme_release_result (c); + c->out_of_core = 0; + /* do some checks */ if ( !gpgme_recipients_count ( recp ) ) { /* Fixme: In this case we should do symmentric encryption */ @@ -127,7 +226,7 @@ gpgme_op_encrypt ( GpgmeCtx c, GpgmeRecipients recp, if ( !rc ) { gpgme_wait (c, 1); c->pending = 0; - /* FIXME: gpg does not return status info for invalid + /* FIXME: 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 * */ diff --git a/trunk/gpgme/gpgme.c b/trunk/gpgme/gpgme.c index 1140c4c..b34fbde 100644 --- a/trunk/gpgme/gpgme.c +++ b/trunk/gpgme/gpgme.c @@ -95,6 +95,9 @@ _gpgme_release_result ( GpgmeCtx c ) case RESULT_TYPE_SIGN: _gpgme_release_sign_result ( c->result.sign ); break; + case RESULT_TYPE_ENCRYPT: + _gpgme_release_encrypt_result ( c->result.encrypt ); + break; } c->result.verify = NULL; diff --git a/trunk/gpgme/ops.h b/trunk/gpgme/ops.h index 20a551b..638e781 100644 --- a/trunk/gpgme/ops.h +++ b/trunk/gpgme/ops.h @@ -76,6 +76,9 @@ void _gpgme_release_decrypt_result ( DecryptResult res ); /*-- sign.c --*/ void _gpgme_release_sign_result ( SignResult res ); +/*-- encrypt.c --*/ +void _gpgme_release_encrypt_result ( EncryptResult res ); + #endif /* OPS_H */ diff --git a/trunk/gpgme/posix-util.c b/trunk/gpgme/posix-util.c index 34150fb..2478063 100644 --- a/trunk/gpgme/posix-util.c +++ b/trunk/gpgme/posix-util.c @@ -34,9 +34,9 @@ const char * _gpgme_get_gpg_path (void) { - /* #warning Forced to development version + #warning Forced to take GPG development version return "/home/wk/work/gnupg-stable/g10/gpg"; - */ + return GPG_PATH; } diff --git a/trunk/gpgme/recipient.c b/trunk/gpgme/recipient.c index c9a217e..522f679 100644 --- a/trunk/gpgme/recipient.c +++ b/trunk/gpgme/recipient.c @@ -43,7 +43,14 @@ gpgme_recipients_new (GpgmeRecipients *r_rset) void gpgme_recipients_release ( GpgmeRecipients rset ) { - /* fixme: release the linked list */ + if (rset) { + struct user_id_s *u, *u2; + + for (u = rset->list; u; u = u2) { + u2 = u->next; + xfree(u); + } + } xfree ( rset ); } diff --git a/trunk/gpgme/rungpg.h b/trunk/gpgme/rungpg.h index 6323d59..3c2da5d 100644 --- a/trunk/gpgme/rungpg.h +++ b/trunk/gpgme/rungpg.h @@ -86,7 +86,8 @@ typedef enum { STATUS_NOTATION_DATA , STATUS_POLICY_URL , STATUS_BEGIN_STREAM , - STATUS_END_STREAM + STATUS_END_STREAM , + STATUS_INV_RECP } GpgStatusCode; typedef void (*GpgStatusHandler)( GpgmeCtx, GpgStatusCode code, char *args ); diff --git a/trunk/gpgme/types.h b/trunk/gpgme/types.h index 4aa0df7..774e30e 100644 --- a/trunk/gpgme/types.h +++ b/trunk/gpgme/types.h @@ -61,6 +61,10 @@ typedef struct decrypt_result_s *DecryptResult; struct sign_result_s; typedef struct sign_result_s *SignResult; +/*-- encrypt.c --*/ +struct encrypt_result_s; +typedef struct encrypt_result_s *EncryptResult; + /*-- key.c --*/ diff --git a/trunk/jnlib/ChangeLog b/trunk/jnlib/ChangeLog index 9325368..92ce65a 100644 --- a/trunk/jnlib/ChangeLog +++ b/trunk/jnlib/ChangeLog @@ -1,3 +1,7 @@ +2001-08-30 Werner Koch + + * logging.c (log_printf): Don't pass NULL instead of arg_ptr. + 2001-07-19 Werner Koch * stringhelp.c (ascii_memistr,ascii_isupper,ascii_islower, diff --git a/trunk/jnlib/logging.c b/trunk/jnlib/logging.c index f03c5c4..dc439ff 100644 --- a/trunk/jnlib/logging.c +++ b/trunk/jnlib/logging.c @@ -224,10 +224,10 @@ log_debug( const char *fmt, ... ) void log_printf( const char *fmt, ... ) { - va_list arg_ptr ; + va_list arg_ptr = 0; if( !fmt ) { - do_logv( MY_LOG_BEGIN, NULL, NULL ); + do_logv( MY_LOG_BEGIN, NULL, arg_ptr ); } else { va_start( arg_ptr, fmt ) ; diff --git a/trunk/tests/t-encrypt.c b/trunk/tests/t-encrypt.c index bbb5557..02ef11f 100644 --- a/trunk/tests/t-encrypt.c +++ b/trunk/tests/t-encrypt.c @@ -32,6 +32,20 @@ exit (1); } \ } while(0) +static void +print_op_info (GpgmeCtx c) +{ + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else { + puts (s); + free (s); + } +} + + static void print_data ( GpgmeData dh ) { @@ -84,6 +98,7 @@ main (int argc, char **argv ) err = gpgme_op_encrypt (ctx, rset, in, out ); + print_op_info (ctx); fail_if_err (err); fflush (NULL); -- 2.26.2