From: Werner Koch Date: Mon, 17 Sep 2001 10:36:05 +0000 (+0000) Subject: Fixed a keylisting bug X-Git-Tag: gpgme-0-3-0~137 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b4eddd304269da30d29fc1a272237e706773ea2e;p=gpgme.git Fixed a keylisting bug --- diff --git a/NEWS b/NEWS index 110e5ab..7363158 100644 --- a/NEWS +++ b/NEWS @@ -10,7 +10,7 @@ Noteworthy changes in version 0.2.3 (2001-09-17) * Added a simple encryption component for MS-Windows; however the build procedure might have some problems. -o + Noteworthy changes in version 0.2.2 (2001-06-12) ------------------------------------------------ diff --git a/configure.in b/configure.in index 34ea269..65c02a6 100644 --- a/configure.in +++ b/configure.in @@ -31,7 +31,7 @@ AM_MAINTAINER_MODE # AGE, set REVISION to 0. # 3. Interfaces removed (BAD, breaks upward compatibility): Increment # CURRENT, set AGE and REVISION to 0. -AM_INIT_AUTOMAKE(gpgme,0.2.3) +AM_INIT_AUTOMAKE(gpgme,0.2.3a) # LIBGPGME_LT_CURRENT=4 LIBGPGME_LT_AGE=4 diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index ff788bf..35353ce 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,11 @@ +2001-09-17 Werner Koch + + * keylist.c (finish_key): Shortcut for no tmp_key. Changed all + callers to use this function without a check for tmp_key. + + * keylist.c (gpgme_op_keylist_next): Reset the key_cond after + emptying the queue. Bug reported by Rick van Rein. + 2001-09-12 Werner Koch * data.c (gpgme_data_rewind): Allow rewind for callbacks. diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index b806d64..4d89984 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -88,7 +88,7 @@ typedef enum { GPGME_No_Passphrase = 19, GPGME_Canceled = 20, GPGME_Invalid_Key = 21, - GPGME_Invalid_Engine = 22, + GPGME_Invalid_Engine = 22 } GpgmeError; typedef enum { diff --git a/gpgme/keylist.c b/gpgme/keylist.c index 44f1489..ebdb707 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -44,8 +44,7 @@ keylist_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) switch (code) { case STATUS_EOF: - if (ctx->tmp_key) - finish_key (ctx); + finish_key (ctx); break; default: @@ -157,8 +156,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) if ( ctx->out_of_core ) return; if (!line) { /* EOF */ - if (ctx->tmp_key) - finish_key (ctx); + finish_key (ctx); return; } @@ -198,8 +196,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) return; } rectype = RT_PUB; - if ( ctx->tmp_key ) - finish_key ( ctx ); + finish_key ( ctx ); assert ( !ctx->tmp_key ); ctx->tmp_key = key; } @@ -210,8 +207,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) return; } rectype = RT_SEC; - if ( ctx->tmp_key ) - finish_key ( ctx ); + finish_key ( ctx ); assert ( !ctx->tmp_key ); ctx->tmp_key = key; } @@ -345,29 +341,30 @@ finish_key ( GpgmeCtx ctx ) GpgmeKey key = ctx->tmp_key; struct key_queue_item_s *q, *q2; - assert (key); - ctx->tmp_key = NULL; - - _gpgme_key_cache_add (key); - - q = xtrymalloc ( sizeof *q ); - if ( !q ) { - gpgme_key_release (key); - ctx->out_of_core = 1; - return; - } - q->key = key; - q->next = NULL; - /* fixme: lock queue. Use a tail pointer? */ - if ( !(q2 = ctx->key_queue) ) - ctx->key_queue = q; - else { - for ( ; q2->next; q2 = q2->next ) - ; - q2->next = q; + if (key) { + ctx->tmp_key = NULL; + + _gpgme_key_cache_add (key); + + q = xtrymalloc ( sizeof *q ); + if ( !q ) { + gpgme_key_release (key); + ctx->out_of_core = 1; + return; + } + q->key = key; + q->next = NULL; + /* fixme: lock queue. Use a tail pointer? */ + if ( !(q2 = ctx->key_queue) ) + ctx->key_queue = q; + else { + for ( ; q2->next; q2 = q2->next ) + ; + q2->next = q; + } + ctx->key_cond = 1; + /* fixme: unlock queue */ } - ctx->key_cond = 1; - /* fixme: unlock queue */ } @@ -482,6 +479,8 @@ gpgme_op_keylist_next ( GpgmeCtx c, GpgmeKey *r_key ) } q = c->key_queue; c->key_queue = q->next; + if (!c->key_queue) + c->key_cond = 0; *r_key = q->key; xfree (q); diff --git a/gpgme/wait.c b/gpgme/wait.c index 26b86d0..a474126 100644 --- a/gpgme/wait.c +++ b/gpgme/wait.c @@ -139,7 +139,7 @@ _gpgme_remove_proc_from_wait_queue ( int pid ) * @hang: * * Wait for a finished request, if @c is given the function does only - * wait on a finsihed request for that context, otherwise it will return + * wait on a finished request for that context, otherwise it will return * on any request. When @hang is true the function will wait, otherwise * it will return immediately when there is no pending finished request. * diff --git a/tests/t-keylist.c b/tests/t-keylist.c index aa82a5b..9a81c12 100644 --- a/tests/t-keylist.c +++ b/tests/t-keylist.c @@ -94,6 +94,34 @@ doit ( GpgmeCtx ctx, const char *pattern ) } +/* + * Check that there are no problems when we are using two context for + * listing keys. + */ +static void +check_two_contexts (void) +{ + GpgmeError err; + GpgmeCtx ctx1, ctx2; + GpgmeKey key; + + err = gpgme_new(&ctx1); fail_if_err (err); + err = gpgme_op_keylist_start(ctx1, "", 1); fail_if_err (err); + err = gpgme_new(&ctx2); fail_if_err (err); + err = gpgme_op_keylist_start(ctx2, "", 1); fail_if_err (err); + + while ( (err=gpgme_op_keylist_next(ctx2, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); + while ( (err=gpgme_op_keylist_next(ctx1, &key)) != GPGME_EOF) { + gpgme_key_release (key); + } + if (err != GPGME_EOF) + fail_if_err (err); +} + int main (int argc, char **argv ) { @@ -112,6 +140,9 @@ main (int argc, char **argv ) } pattern = argc? *argv : NULL; + err = gpgme_check_engine(); + fail_if_err (err); + err = gpgme_new (&ctx); fail_if_err (err); gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */ @@ -121,6 +152,8 @@ main (int argc, char **argv ) } while ( loop ); gpgme_release (ctx); + check_two_contexts (); + return 0; }