2001-11-15 Marcus Brinkmann <marcus@g10code.de>

* verify.c (_gpgme_release_verify_result): Rename RES to RESULT.
	Rename R2 to NEXT_RESULT.
	(intersect_stati): Rename RES to RESULT.
	(gpgme_get_sig_status): Likewise.  Do not check return_type, but
	the member verify of result.
	(gpgme_get_sig_key): Likewise.

	* sign.c (_gpgme_release_sign_result): Rename RES to RESULT.  If
	RESULT is zero, return.
	(sign_status_handler, command_handler): Do not check return_type,
	but the member sign of result.
	(gpgme_op_sign): Likewise.  Drop assertion.

	* encrypt.c (_gpgme_release_encrypt_result): Rename RES to RESULT.
	If RESULT is zero, return.
	(encrypt_status_handler): Do not check return_type, but the member
	encrypt of result.
	(gpgme_op_encrypt): Likewise.  Drop assertion.

	* decrypt.c (_gpgme_release_decrypt_result): Rename RES to RESULT.
	(create_result_struct): Do not set result_type.
	(command_handler, decrypt_status_handler): Do not check
	return_type, but the member decrypt of result.
	(gpgme_op_decrypt): Likewise.  Drop assertion.

	* context.h (enum ResultType): Removed.
	(struct gpgme_context_s): Remove member result_type.
	(struct result): Replaces union result.
	* gpgme.c: Include string.h.
	(_gpgme_release_result): Release all members of c->result, which
	is now a struct.  Zero out all members of the struct afterwards.
This commit is contained in:
Marcus Brinkmann 2001-11-15 21:32:09 +00:00
parent 49a25a82e2
commit 9144124a61
7 changed files with 236 additions and 242 deletions

View File

@ -1,3 +1,37 @@
2001-11-15 Marcus Brinkmann <marcus@g10code.de>
* verify.c (_gpgme_release_verify_result): Rename RES to RESULT.
Rename R2 to NEXT_RESULT.
(intersect_stati): Rename RES to RESULT.
(gpgme_get_sig_status): Likewise. Do not check return_type, but
the member verify of result.
(gpgme_get_sig_key): Likewise.
* sign.c (_gpgme_release_sign_result): Rename RES to RESULT. If
RESULT is zero, return.
(sign_status_handler, command_handler): Do not check return_type,
but the member sign of result.
(gpgme_op_sign): Likewise. Drop assertion.
* encrypt.c (_gpgme_release_encrypt_result): Rename RES to RESULT.
If RESULT is zero, return.
(encrypt_status_handler): Do not check return_type, but the member
encrypt of result.
(gpgme_op_encrypt): Likewise. Drop assertion.
* decrypt.c (_gpgme_release_decrypt_result): Rename RES to RESULT.
(create_result_struct): Do not set result_type.
(command_handler, decrypt_status_handler): Do not check
return_type, but the member decrypt of result.
(gpgme_op_decrypt): Likewise. Drop assertion.
* context.h (enum ResultType): Removed.
(struct gpgme_context_s): Remove member result_type.
(struct result): Replaces union result.
* gpgme.c: Include string.h.
(_gpgme_release_result): Release all members of c->result, which
is now a struct. Zero out all members of the struct afterwards.
2001-11-11 Marcus Brinkmann <marcus@g10code.de> 2001-11-11 Marcus Brinkmann <marcus@g10code.de>
* rungpg.c (_gpgme_gpg_release): Release GPG->cmd.cb_data. * rungpg.c (_gpgme_gpg_release): Release GPG->cmd.cb_data.

View File

@ -26,15 +26,6 @@
#include "types.h" #include "types.h"
#include "rungpg.h" /* for GpgObject */ #include "rungpg.h" /* for GpgObject */
typedef enum {
RESULT_TYPE_NONE = 0,
RESULT_TYPE_VERIFY,
RESULT_TYPE_DECRYPT,
RESULT_TYPE_SIGN,
RESULT_TYPE_ENCRYPT
} ResultType;
struct key_queue_item_s { struct key_queue_item_s {
struct key_queue_item_s *next; struct key_queue_item_s *next;
GpgmeKey key; GpgmeKey key;
@ -71,8 +62,7 @@ struct gpgme_context_s {
int signers_size; /* size of the following array */ int signers_size; /* size of the following array */
GpgmeKey *signers; GpgmeKey *signers;
ResultType result_type; struct {
union {
VerifyResult verify; VerifyResult verify;
DecryptResult decrypt; DecryptResult decrypt;
SignResult sign; SignResult sign;

View File

@ -29,8 +29,8 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
struct decrypt_result_s
struct decrypt_result_s { {
int no_passphrase; int no_passphrase;
int okay; int okay;
int failed; int failed;
@ -40,27 +40,23 @@ struct decrypt_result_s {
int bad_passphrase; int bad_passphrase;
}; };
void void
_gpgme_release_decrypt_result ( DecryptResult res ) _gpgme_release_decrypt_result (DecryptResult result)
{ {
if (!res ) if (!result)
return; return;
xfree (res->passphrase_info); xfree (result->passphrase_info);
xfree (res->userid_hint); xfree (result->userid_hint);
xfree (res); xfree (result);
} }
static GpgmeError static GpgmeError
create_result_struct (GpgmeCtx ctx) create_result_struct (GpgmeCtx ctx)
{ {
assert (!ctx->result.decrypt); assert (!ctx->result.decrypt);
ctx->result.decrypt = xtrycalloc (1, sizeof *ctx->result.decrypt); ctx->result.decrypt = xtrycalloc (1, sizeof *ctx->result.decrypt);
if ( !ctx->result.decrypt ) { if (!ctx->result.decrypt)
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
}
ctx->result_type = RESULT_TYPE_DECRYPT;
return 0; return 0;
} }
@ -69,13 +65,14 @@ decrypt_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
{ {
if ( ctx->out_of_core ) if ( ctx->out_of_core )
return; return;
if ( ctx->result_type == RESULT_TYPE_NONE ) { if (! ctx->result.decrypt)
if ( create_result_struct ( ctx ) ) { {
if (create_result_struct (ctx))
{
ctx->out_of_core = 1; ctx->out_of_core = 1;
return; return;
} }
} }
assert ( ctx->result_type == RESULT_TYPE_DECRYPT );
switch (code) { switch (code) {
case STATUS_EOF: case STATUS_EOF:
@ -128,10 +125,12 @@ command_handler ( void *opaque, GpgStatusCode code, const char *key )
{ {
GpgmeCtx c = opaque; GpgmeCtx c = opaque;
if ( c->result_type == RESULT_TYPE_NONE ) { if (! c->result.decrypt)
if ( create_result_struct ( c ) ) { {
if (create_result_struct (c))
{
c->out_of_core = 1; c->out_of_core = 1;
return NULL; return;
} }
} }
@ -258,18 +257,18 @@ gpgme_op_decrypt_start ( GpgmeCtx c,
* Return value: 0 on success or an errorcode. * Return value: 0 on success or an errorcode.
**/ **/
GpgmeError GpgmeError
gpgme_op_decrypt ( GpgmeCtx c, gpgme_op_decrypt (GpgmeCtx c, GpgmeData in, GpgmeData out)
GpgmeData in, GpgmeData out )
{ {
GpgmeError err = gpgme_op_decrypt_start (c, in, out); GpgmeError err = gpgme_op_decrypt_start (c, in, out);
if ( !err ) { if (!err)
{
gpgme_wait (c, 1); gpgme_wait (c, 1);
if ( c->result_type != RESULT_TYPE_DECRYPT ) if (!c->result.decrypt)
err = mk_error (General_Error); err = mk_error (General_Error);
else if (c->out_of_core) else if (c->out_of_core)
err = mk_error (Out_Of_Core); err = mk_error (Out_Of_Core);
else { else
assert ( c->result.decrypt ); {
if (c->result.decrypt->no_passphrase) if (c->result.decrypt->no_passphrase)
err = mk_error (No_Passphrase); err = mk_error (No_Passphrase);
else if (c->result.decrypt->failed) else if (c->result.decrypt->failed)
@ -281,12 +280,3 @@ gpgme_op_decrypt ( GpgmeCtx c,
} }
return err; return err;
} }

View File

@ -36,22 +36,21 @@
return; /* oops */ \ return; /* oops */ \
} while (0) } while (0)
struct encrypt_result_s
{
struct encrypt_result_s {
int no_recipients; int no_recipients;
GpgmeData xmlinfo; GpgmeData xmlinfo;
}; };
void void
_gpgme_release_encrypt_result (EncryptResult res) _gpgme_release_encrypt_result (EncryptResult result)
{ {
gpgme_data_release (res->xmlinfo); if (!result)
xfree (res); return;
gpgme_data_release (result->xmlinfo);
xfree (result);
} }
/* /*
* Parse the args and save the information * Parse the args and save the information
* in an XML structure. * in an XML structure.
@ -103,16 +102,15 @@ encrypt_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
{ {
if (ctx->out_of_core) if (ctx->out_of_core)
return; return;
if ( ctx->result_type == RESULT_TYPE_NONE ) { if (!ctx->result.encrypt)
assert ( !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;
} }
ctx->result_type = RESULT_TYPE_ENCRYPT;
} }
assert ( ctx->result_type == RESULT_TYPE_ENCRYPT );
switch (code) { switch (code) {
case STATUS_EOF: case STATUS_EOF:
@ -230,12 +228,11 @@ gpgme_op_encrypt ( GpgmeCtx c, GpgmeRecipients recp,
int err = gpgme_op_encrypt_start ( c, recp, in, out ); int err = gpgme_op_encrypt_start ( c, recp, in, out );
if ( !err ) { if ( !err ) {
gpgme_wait (c, 1); gpgme_wait (c, 1);
if ( c->result_type != RESULT_TYPE_ENCRYPT ) if (!c->result.encrypt)
err = mk_error (General_Error); err = mk_error (General_Error);
else if (c->out_of_core) else if (c->out_of_core)
err = mk_error (Out_Of_Core); err = mk_error (Out_Of_Core);
else { else {
assert ( c->result.encrypt );
if (c->result.encrypt->no_recipients) if (c->result.encrypt->no_recipients)
err = mk_error (No_Recipients); err = mk_error (No_Recipients);
} }

View File

@ -22,6 +22,7 @@
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include "util.h" #include "util.h"
@ -83,25 +84,11 @@ gpgme_release ( GpgmeCtx c )
void void
_gpgme_release_result (GpgmeCtx c) _gpgme_release_result (GpgmeCtx c)
{ {
switch (c->result_type) {
case RESULT_TYPE_NONE:
break;
case RESULT_TYPE_VERIFY:
_gpgme_release_verify_result (c->result.verify); _gpgme_release_verify_result (c->result.verify);
break;
case RESULT_TYPE_DECRYPT:
_gpgme_release_decrypt_result (c->result.decrypt); _gpgme_release_decrypt_result (c->result.decrypt);
break;
case RESULT_TYPE_SIGN:
_gpgme_release_sign_result (c->result.sign); _gpgme_release_sign_result (c->result.sign);
break;
case RESULT_TYPE_ENCRYPT:
_gpgme_release_encrypt_result (c->result.encrypt); _gpgme_release_encrypt_result (c->result.encrypt);
break; memset (&c->result, 0, sizeof (c->result));
}
c->result.verify = NULL;
c->result_type = RESULT_TYPE_NONE;
_gpgme_set_op_info (c, NULL); _gpgme_set_op_info (c, NULL);
} }

View File

@ -36,10 +36,8 @@
return; /* oops */ \ return; /* oops */ \
} while (0) } while (0)
struct sign_result_s
{
struct sign_result_s {
int no_passphrase; int no_passphrase;
int okay; int okay;
void *last_pw_handle; void *last_pw_handle;
@ -49,17 +47,17 @@ struct sign_result_s {
GpgmeData xmlinfo; GpgmeData xmlinfo;
}; };
void void
_gpgme_release_sign_result ( SignResult res ) _gpgme_release_sign_result (SignResult result)
{ {
gpgme_data_release (res->xmlinfo); if (!result)
xfree (res->userid_hint); return;
xfree (res->passphrase_info); gpgme_data_release (result->xmlinfo);
xfree (res); xfree (result->userid_hint);
xfree (result->passphrase_info);
xfree (result);
} }
/* parse the args and save the information /* parse the args and save the information
* <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr> * <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
* in an XML structure. With args of NULL the xml structure is closed. * in an XML structure. With args of NULL the xml structure is closed.
@ -145,16 +143,15 @@ sign_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
{ {
if (ctx->out_of_core) if (ctx->out_of_core)
return; return;
if ( ctx->result_type == RESULT_TYPE_NONE ) { if (!ctx->result.sign)
assert ( !ctx->result.sign ); {
ctx->result.sign = xtrycalloc (1, sizeof *ctx->result.sign); ctx->result.sign = xtrycalloc (1, sizeof *ctx->result.sign);
if ( !ctx->result.sign ) { if (!ctx->result.sign)
{
ctx->out_of_core = 1; ctx->out_of_core = 1;
return; return;
} }
ctx->result_type = RESULT_TYPE_SIGN;
} }
assert ( ctx->result_type == RESULT_TYPE_SIGN );
switch (code) { switch (code) {
case STATUS_EOF: case STATUS_EOF:
@ -207,14 +204,14 @@ command_handler ( void *opaque, GpgStatusCode code, const char *key )
{ {
GpgmeCtx c = opaque; GpgmeCtx c = opaque;
if ( c->result_type == RESULT_TYPE_NONE ) { if (!c->result.sign)
assert ( !c->result.sign ); {
c->result.sign = xtrycalloc (1, sizeof *c->result.sign); c->result.sign = xtrycalloc (1, sizeof *c->result.sign);
if ( !c->result.sign ) { if (!c->result.sign)
{
c->out_of_core = 1; c->out_of_core = 1;
return NULL; return NULL;
} }
c->result_type = RESULT_TYPE_SIGN;
} }
if ( !code ) { if ( !code ) {
@ -378,17 +375,15 @@ gpgme_op_sign ( GpgmeCtx c, GpgmeData in, GpgmeData out, GpgmeSigMode mode )
GpgmeError err = gpgme_op_sign_start ( c, in, out, mode ); GpgmeError err = gpgme_op_sign_start ( c, in, out, mode );
if ( !err ) { if ( !err ) {
gpgme_wait (c, 1); gpgme_wait (c, 1);
if ( c->result_type != RESULT_TYPE_SIGN ) if (!c->result.sign)
err = mk_error (General_Error); err = mk_error (General_Error);
else if (c->out_of_core) else if (c->out_of_core)
err = mk_error (Out_Of_Core); err = mk_error (Out_Of_Core);
else { else {
assert ( c->result.sign );
if (c->result.sign->no_passphrase) if (c->result.sign->no_passphrase)
err = mk_error (No_Passphrase); err = mk_error (No_Passphrase);
else if (!c->result.sign->okay) else if (!c->result.sign->okay)
err = mk_error (No_Data); /* Hmmm: choose a better error? */ err = mk_error (No_Data); /* Hmmm: choose a better error? */
} }
c->pending = 0; c->pending = 0;
} }

View File

@ -30,29 +30,32 @@
#include "ops.h" #include "ops.h"
#include "key.h" #include "key.h"
struct verify_result_s { struct verify_result_s
{
struct verify_result_s *next; struct verify_result_s *next;
GpgmeSigStat status; GpgmeSigStat status;
GpgmeData notation; /* we store an XML fragment here */ GpgmeData notation; /* We store an XML fragment here. */
int collecting; /* private to finish_sig() */ int collecting; /* Private to finish_sig(). */
int notation_in_data; /* private to add_notation() */ int notation_in_data; /* Private to add_notation(). */
char fpr[41]; /* fingerprint of a good signature or keyid of a bad one*/ char fpr[41]; /* Fingerprint of a good signature or keyid of
ulong timestamp; /* signature creation time */ a bad one. */
ulong timestamp; /* Signature creation time. */
}; };
void void
_gpgme_release_verify_result ( VerifyResult res ) _gpgme_release_verify_result (VerifyResult result)
{ {
while (res) { while (result)
VerifyResult r2 = res->next; {
gpgme_data_release ( res->notation ); VerifyResult next_result = result->next;
xfree (res); gpgme_data_release (result->notation);
res = r2; xfree (result);
result = next_result;
} }
} }
/* fixme: check that we are adding this to the correct signature */ /* FIXME: Check that we are adding this to the correct signature. */
static void static void
add_notation ( GpgmeCtx ctx, GpgStatusCode code, const char *data ) add_notation ( GpgmeCtx ctx, GpgStatusCode code, const char *data )
{ {
@ -133,16 +136,15 @@ verify_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
if ( ctx->out_of_core ) if ( ctx->out_of_core )
return; return;
if ( ctx->result_type == RESULT_TYPE_NONE ) { if (!ctx->result.verify)
assert ( !ctx->result.verify ); {
ctx->result.verify = xtrycalloc (1, sizeof *ctx->result.verify); ctx->result.verify = xtrycalloc (1, sizeof *ctx->result.verify);
if ( !ctx->result.verify ) { if (!ctx->result.verify)
{
ctx->out_of_core = 1; ctx->out_of_core = 1;
return; return;
} }
ctx->result_type = RESULT_TYPE_VERIFY;
} }
assert ( ctx->result_type == RESULT_TYPE_VERIFY );
if (code == STATUS_GOODSIG if (code == STATUS_GOODSIG
|| code == STATUS_BADSIG || code == STATUS_ERRSIG) { || code == STATUS_BADSIG || code == STATUS_ERRSIG) {
@ -293,12 +295,13 @@ gpgme_op_verify_start ( GpgmeCtx c, GpgmeData sig, GpgmeData text )
* Figure out a common status value for all signatures * Figure out a common status value for all signatures
*/ */
static GpgmeSigStat static GpgmeSigStat
intersect_stati ( VerifyResult res ) intersect_stati (VerifyResult result)
{ {
GpgmeSigStat status = res->status; GpgmeSigStat status = result->status;
for (res=res->next; res; res = res->next) { for (result = result->next; result; result = result->next)
if (status != res->status ) {
if (status != result->status)
return GPGME_SIG_STAT_DIFF; return GPGME_SIG_STAT_DIFF;
} }
return status; return status;
@ -344,13 +347,12 @@ gpgme_op_verify ( GpgmeCtx c, GpgmeData sig, GpgmeData text,
rc = gpgme_op_verify_start ( c, sig, text ); rc = gpgme_op_verify_start ( c, sig, text );
if ( !rc ) { if ( !rc ) {
gpgme_wait (c, 1); gpgme_wait (c, 1);
if ( c->result_type != RESULT_TYPE_VERIFY ) if (!c->result.verify)
rc = mk_error (General_Error); rc = mk_error (General_Error);
else if (c->out_of_core) else if (c->out_of_core)
rc = mk_error (Out_Of_Core); rc = mk_error (Out_Of_Core);
else { else {
assert ( c->result.verify ); /* FIXME: Put all notation data into one XML fragment. */
/* fixme: Put all notation data into one XML fragment */
if ( c->result.verify->notation ) { if ( c->result.verify->notation ) {
GpgmeData dh = c->result.verify->notation; GpgmeData dh = c->result.verify->notation;
@ -386,21 +388,22 @@ const char *
gpgme_get_sig_status (GpgmeCtx c, int idx, gpgme_get_sig_status (GpgmeCtx c, int idx,
GpgmeSigStat *r_stat, time_t *r_created) GpgmeSigStat *r_stat, time_t *r_created)
{ {
VerifyResult res; VerifyResult result;
if (!c || c->pending || c->result_type != RESULT_TYPE_VERIFY ) if (!c || c->pending || !c->result.verify)
return NULL; /* No results yet or verification error */ return NULL; /* No results yet or verification error. */
for (res = c->result.verify; res && idx>0 ; res = res->next, idx--) for (result = c->result.verify;
result && idx > 0; result = result->next, idx--)
; ;
if (!res) if (!result)
return NULL; /* No more signatures */ return NULL; /* No more signatures. */
if (r_stat) if (r_stat)
*r_stat = res->status; *r_stat = result->status;
if (r_created) if (r_created)
*r_created = res->timestamp; *r_created = result->timestamp;
return res->fpr; return result->fpr;
} }
@ -418,40 +421,38 @@ gpgme_get_sig_status (GpgmeCtx c, int idx,
GpgmeError GpgmeError
gpgme_get_sig_key (GpgmeCtx c, int idx, GpgmeKey *r_key) gpgme_get_sig_key (GpgmeCtx c, int idx, GpgmeKey *r_key)
{ {
VerifyResult res; VerifyResult result;
GpgmeError err = 0; GpgmeError err = 0;
if (!c || !r_key) if (!c || !r_key)
return mk_error (Invalid_Value); return mk_error (Invalid_Value);
if (c->pending || c->result_type != RESULT_TYPE_VERIFY ) if (c->pending || !c->result.verify)
return mk_error (Busy); return mk_error (Busy);
for (res = c->result.verify; res && idx>0 ; res = res->next, idx--) for (result = c->result.verify;
result && idx > 0; result = result->next, idx--)
; ;
if (!res) if (!result)
return mk_error (EOF); return mk_error (EOF);
if (strlen(res->fpr) < 16) /* we have at least an key ID */ if (strlen(result->fpr) < 16) /* We have at least a key ID. */
return mk_error (Invalid_Key); return mk_error (Invalid_Key);
*r_key = _gpgme_key_cache_get (res->fpr); *r_key = _gpgme_key_cache_get (result->fpr);
if (!*r_key) { if (!*r_key)
{
GpgmeCtx listctx; GpgmeCtx listctx;
/* Fixme: This can be optimized by keeping /* Fixme: This can be optimized by keeping an internal context
* an internal context used for such key listings */ used for such key listings. */
if ( (err=gpgme_new (&listctx)) ) err = gpgme_new (&listctx);
if (err)
return err; return err;
gpgme_set_keylist_mode (listctx, c->keylist_mode); gpgme_set_keylist_mode (listctx, c->keylist_mode);
if ( !(err=gpgme_op_keylist_start (listctx, res->fpr, 0 )) ) err = gpgme_op_keylist_start (listctx, result->fpr, 0);
if (!err)
err = gpgme_op_keylist_next (listctx, r_key); err = gpgme_op_keylist_next (listctx, r_key);
gpgme_release (listctx); gpgme_release (listctx);
} }
return err; return err;
} }