diff options
author | Werner Koch <[email protected]> | 2001-09-03 18:41:53 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2001-09-03 18:41:53 +0000 |
commit | 5b3d8162b493332971c00b21aa0ac67faa4ff85f (patch) | |
tree | df8f7aa953acdab62f120f375cd1b9128b603454 /gpgme/encrypt.c | |
parent | Fixed long standing listing bug. (diff) | |
download | gpgme-5b3d8162b493332971c00b21aa0ac67faa4ff85f.tar.gz gpgme-5b3d8162b493332971c00b21aa0ac67faa4ff85f.zip |
Some changes
Diffstat (limited to '')
-rw-r--r-- | gpgme/encrypt.c | 103 |
1 files changed, 101 insertions, 2 deletions
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, "<GnupgOperationInfo>\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; + } + + _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"); +} + + + + + 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 * */ |