X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_db4.c;h=85aeab559e9c60a7f6300401d176bfd6c19f5ee7;hb=ea9ac7c3b327dc0c69f7c770d26c3372065aa5f1;hp=b443942aea33530a8db6c97001896dcccd226075;hpb=6fcdf43b866c8199065bdf5bfc05942ed79bde16;p=onak.git diff --git a/keydb_db4.c b/keydb_db4.c index b443942..85aeab5 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -332,6 +332,55 @@ static void db4_initdb(bool readonly) return; } +/** + * getfullkeyid - Maps a 32bit key id to a 64bit one. + * @keyid: The 32bit keyid. + * + * This function maps a 32bit key id to the full 64bit one. It returns the + * full keyid. If the key isn't found a keyid of 0 is returned. + */ +static uint64_t db4_getfullkeyid(uint64_t keyid) +{ + DBT key, data; + DBC *cursor = NULL; + uint32_t shortkeyid = 0; + int ret = 0; + + if (keyid < 0x100000000LL) { + ret = id32db->cursor(id32db, + txn, + &cursor, + 0); /* flags */ + + shortkeyid = keyid & 0xFFFFFFFF; + + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + key.data = &shortkeyid; + key.size = sizeof(shortkeyid); + data.flags = DB_DBT_MALLOC; + + ret = cursor->c_get(cursor, + &key, + &data, + DB_SET); + + if (ret == 0) { + keyid = *(uint64_t *) data.data; + + if (data.data != NULL) { + free(data.data); + data.data = NULL; + } + } + + ret = cursor->c_close(cursor); + cursor = NULL; + } + + return keyid; +} + /** * fetch_key - Given a keyid fetch the key from storage. * @keyid: The keyid to fetch. @@ -354,7 +403,7 @@ static int db4_fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, struct buffer_ctx fetchbuf; if (keyid < 0x100000000LL) { - keyid = getfullkeyid(keyid); + keyid = db4_getfullkeyid(keyid); } memset(&key, 0, sizeof(key)); @@ -426,6 +475,7 @@ static int db4_fetch_key_text(const char *search, struct ll *curword = NULL; struct keyarray keylist = { NULL, 0, 0 }; struct keyarray newkeylist = { NULL, 0, 0 }; + int firstpass = 1; numkeys = 0; searchtext = strdup(search); @@ -458,8 +508,12 @@ static int db4_fetch_key_text(const char *search, data.data)[i]; } - if (keylist.count == 0 || - array_find(&keylist, keyid)) { + /* + * Only add the keys containing this word if this is + * our first pass (ie we have no existing key list), + * or the key contained a previous word. + */ + if (firstpass || array_find(&keylist, keyid)) { array_add(&newkeylist, keyid); } @@ -481,6 +535,7 @@ static int db4_fetch_key_text(const char *search, } ret = cursor->c_close(cursor); cursor = NULL; + firstpass = 0; db4_endtrans(); } llfree(wordlist, NULL); @@ -1011,55 +1066,6 @@ static int db4_iterate_keys(void (*iterfunc)(void *ctx, return numkeys; } -/** - * getfullkeyid - Maps a 32bit key id to a 64bit one. - * @keyid: The 32bit keyid. - * - * This function maps a 32bit key id to the full 64bit one. It returns the - * full keyid. If the key isn't found a keyid of 0 is returned. - */ -static uint64_t db4_getfullkeyid(uint64_t keyid) -{ - DBT key, data; - DBC *cursor = NULL; - uint32_t shortkeyid = 0; - int ret = 0; - - if (keyid < 0x100000000LL) { - ret = id32db->cursor(id32db, - txn, - &cursor, - 0); /* flags */ - - shortkeyid = keyid & 0xFFFFFFFF; - - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - key.data = &shortkeyid; - key.size = sizeof(shortkeyid); - data.flags = DB_DBT_MALLOC; - - ret = cursor->c_get(cursor, - &key, - &data, - DB_SET); - - if (ret == 0) { - keyid = *(uint64_t *) data.data; - - if (data.data != NULL) { - free(data.data); - data.data = NULL; - } - } - - ret = cursor->c_close(cursor); - cursor = NULL; - } - - return keyid; -} - /* * Include the basic keydb routines. */