From 5b3d8162b493332971c00b21aa0ac67faa4ff85f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 3 Sep 2001 18:41:53 +0000 Subject: Some changes --- gpgme/encrypt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 2 deletions(-) (limited to 'gpgme/encrypt.c') diff --git a/gpgme/encrypt.c b/gpgme/encrypt.c index bff4153d..00531a01 100644 --- a/gpgme/encrypt.c +++ b/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 * */ -- cgit v1.2.3