1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-18 14:17:03 +01:00

gpg: Minor cleanup for key listing related code.

* g10/getkey.c (get_pubkey_next): Divert to getkey_next.
(get_pubkey_end): Move code to getkey_end.
* g10/keydb.c (keydb_search_reset): Add a debug statement.
(dump_search_desc): Add arg HD and print the handle.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2014-11-02 16:31:30 +01:00
parent a929f36693
commit 440e8f5170
2 changed files with 19 additions and 21 deletions

View File

@ -928,26 +928,13 @@ get_pubkey_bynames (GETKEY_CTX * retctx, PKT_public_key * pk,
int int
get_pubkey_next (GETKEY_CTX ctx, PKT_public_key * pk, KBNODE * ret_keyblock) get_pubkey_next (GETKEY_CTX ctx, PKT_public_key * pk, KBNODE * ret_keyblock)
{ {
int rc; return gpg_err_code (getkey_next (ctx, pk, ret_keyblock));
rc = lookup (ctx, ret_keyblock, 0);
if (!rc && pk && ret_keyblock)
pk_from_block (ctx, pk, *ret_keyblock);
return rc;
} }
void void
get_pubkey_end (GETKEY_CTX ctx) get_pubkey_end (GETKEY_CTX ctx)
{ {
if (ctx) getkey_end (ctx);
{
memset (&ctx->kbpos, 0, sizeof ctx->kbpos);
keydb_release (ctx->kr_handle);
free_strlist (ctx->extra_list);
if (!ctx->not_allocated)
xfree (ctx);
}
} }
@ -1257,7 +1244,14 @@ getkey_next (getkey_ctx_t ctx, PKT_public_key *pk, kbnode_t *ret_keyblock)
void void
getkey_end (getkey_ctx_t ctx) getkey_end (getkey_ctx_t ctx)
{ {
get_pubkey_end (ctx); if (ctx)
{
memset (&ctx->kbpos, 0, sizeof ctx->kbpos);
keydb_release (ctx->kr_handle);
free_strlist (ctx->extra_list);
if (!ctx->not_allocated)
xfree (ctx);
}
} }

View File

@ -603,8 +603,8 @@ keydb_release (KEYDB_HANDLE hd)
/* Set a flag on handle to not use cached results. This is required /* Set a flag on handle to not use cached results. This is required
for updating a keyring. Fixme: Using a new parameter for keydb_new for updating a keyring and for key listins. Fixme: Using a new
might be a better solution. */ parameter for keydb_new might be a better solution. */
void void
keydb_disable_caching (KEYDB_HANDLE hd) keydb_disable_caching (KEYDB_HANDLE hd)
{ {
@ -1328,6 +1328,9 @@ keydb_search_reset (KEYDB_HANDLE hd)
if (DBG_CLOCK) if (DBG_CLOCK)
log_clock ("keydb_search_reset"); log_clock ("keydb_search_reset");
if (DBG_CACHE)
log_debug ("keydb_search: reset (hd=%p)", hd);
hd->skipped_long_blobs = 0; hd->skipped_long_blobs = 0;
hd->current = 0; hd->current = 0;
hd->found = -1; hd->found = -1;
@ -1351,7 +1354,8 @@ keydb_search_reset (KEYDB_HANDLE hd)
static void static void
dump_search_desc (const char *text, KEYDB_SEARCH_DESC *desc, size_t ndesc) dump_search_desc (KEYDB_HANDLE hd, const char *text,
KEYDB_SEARCH_DESC *desc, size_t ndesc)
{ {
int n; int n;
const char *s; const char *s;
@ -1382,7 +1386,7 @@ dump_search_desc (const char *text, KEYDB_SEARCH_DESC *desc, size_t ndesc)
default: s = "?"; break; default: s = "?"; break;
} }
if (!n) if (!n)
log_debug ("%s: mode=%s", text, s); log_debug ("%s: mode=%s (hd=%p)", text, s, hd);
else else
log_debug ("%*s mode=%s", (int)strlen (text), "", s); log_debug ("%*s mode=%s", (int)strlen (text), "", s);
if (desc[n].mode == KEYDB_SEARCH_MODE_LONG_KID) if (desc[n].mode == KEYDB_SEARCH_MODE_LONG_KID)
@ -1418,7 +1422,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
log_clock ("keydb_search enter"); log_clock ("keydb_search enter");
if (DBG_CACHE) if (DBG_CACHE)
dump_search_desc ("keydb_search", desc, ndesc); dump_search_desc (hd, "keydb_search", desc, ndesc);
if (!hd->no_caching if (!hd->no_caching
&& ndesc == 1 && ndesc == 1