X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/5b3f77c7fbafb036d20a1577ed74f475e94ed821..0211c730256c9bbaf10a569c88f7df0ef882311e:/keydb.c diff --git a/keydb.c b/keydb.c index 339450b..2abfa02 100644 --- a/keydb.c +++ b/keydb.c @@ -23,6 +23,7 @@ #include "keystructs.h" #include "mem.h" #include "merge.h" +#include "openpgp.h" #include "parsekey.h" #include "sendsync.h" @@ -42,7 +43,7 @@ char *generic_keyid2uid(uint64_t keyid) publickey != NULL) { curuid = publickey->uids; while (curuid != NULL && buf[0] == 0) { - if (curuid->packet->tag == 13) { + if (curuid->packet->tag == OPENPGP_PACKET_UID) { snprintf(buf, 1023, "%.*s", (int) curuid->packet->length, curuid->packet->data); @@ -105,16 +106,24 @@ struct ll *generic_cached_getkeysigs(uint64_t keyid) struct stats_key *key = NULL; struct stats_key *signedkey = NULL; struct ll *cursig = NULL; + struct ll *sigs = NULL; bool revoked = false; if (keyid == 0) { return NULL; } - key = createandaddtohash(keyid); + key = findinhash(keyid); - if (key->gotsigs == false) { - key->sigs = config.dbbackend->getkeysigs(key->keyid, &revoked); + if (key == NULL || key->gotsigs == false) { + sigs = config.dbbackend->getkeysigs(keyid, &revoked); + if (sigs == NULL) { + return NULL; + } + if (key == NULL) { + key = createandaddtohash(keyid); + } + key->sigs = sigs; key->revoked = revoked; for (cursig = key->sigs; cursig != NULL; cursig = cursig->next) { @@ -177,7 +186,7 @@ int generic_update_keys(struct openpgp_publickey **keys, bool sendsync) for (curkey = *keys; curkey != NULL; curkey = curkey->next) { intrans = config.dbbackend->starttrans(); logthing(LOGTHING_INFO, - "Fetching key 0x%llX, result: %d", + "Fetching key 0x%" PRIX64 ", result: %d", get_keyid(curkey), config.dbbackend->fetch_key(get_keyid(curkey), &oldkey, intrans)); @@ -205,7 +214,8 @@ int generic_update_keys(struct openpgp_publickey **keys, bool sendsync) prev = curkey; logthing(LOGTHING_INFO, "Merged key; storing updated key."); - store_key(oldkey, intrans, true); + config.dbbackend->store_key(oldkey, intrans, + true); } free_publickey(oldkey); oldkey = NULL;