- if (keyid < 0x100000000LL) {
- fetch_key(keyid, &publickey, false);
- keyid = get_keyid(publickey);
- free_publickey(publickey);
+ curkey = keys;
+ while (*curkey != NULL) {
+ get_fingerprint((*curkey)->publickey, &fp);
+
+ intrans = dbctx->starttrans(dbctx);
+
+ logthing(LOGTHING_INFO,
+ "Fetching key, result: %d",
+ dbctx->fetch_key_fp(dbctx, &fp, &oldkey,
+ intrans));
+
+ /*
+ * If we already have the key stored in the DB then merge it
+ * with the new one that's been supplied. Otherwise the key
+ * we've just got is the one that goes in the DB and also the
+ * one that we send out.
+ */
+ if (oldkey != NULL) {
+ merge_keys(oldkey, *curkey);
+ if ((*curkey)->sigs == NULL &&
+ (*curkey)->uids == NULL &&
+ (*curkey)->subkeys == NULL) {
+ tmp = *curkey;
+ *curkey = (*curkey)->next;
+ tmp->next = NULL;
+ free_publickey(tmp);
+ } else {
+ logthing(LOGTHING_INFO,
+ "Merged key; storing updated key.");
+ dbctx->store_key(dbctx, oldkey, intrans,
+ true);
+ curkey = &(*curkey)->next;
+ }
+ free_publickey(oldkey);
+ oldkey = NULL;
+ } else {
+ logthing(LOGTHING_INFO,
+ "Storing completely new key.");
+ dbctx->store_key(dbctx, *curkey, intrans, false);
+ newkeys++;
+ curkey = &(*curkey)->next;
+ }
+ dbctx->endtrans(dbctx);