X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=keymerge.c;h=fb95c2d49d8043f0cbf424dfc3f05c2f7ca6c5ba;hb=8e58a1769ce5e492dd68904dfc81b6e077fc2a3a;hp=09d71fc898227d6536b6ed416a98c96006c98d9f;hpb=4b8483ae278577a3adc8d84da81d77019704466f;p=onak.git diff --git a/keymerge.c b/keymerge.c index 09d71fc..fb95c2d 100644 --- a/keymerge.c +++ b/keymerge.c @@ -17,11 +17,15 @@ #include "merge.h" #include "parsekey.h" -int stdin_getchar(void *ctx, unsigned char *c) +int stdin_getchar(void *ctx, size_t count, unsigned char *c) { int ic; - ic = getchar(); - *c = ic; + + do { + ic = getchar(); + *c = ic; + c++; + } while ((ic != EOF) && (--count > 0)); return (ic == EOF); } @@ -36,54 +40,22 @@ int main(int argc, char *argv[]) struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; struct openpgp_publickey *keys = NULL; - struct openpgp_publickey *prev = NULL; - struct openpgp_publickey *curkey = NULL; - struct openpgp_publickey *oldkey = NULL; - int newkeys = 0; int rc = EXIT_SUCCESS; dearmor_openpgp_stream(stdin_getchar, NULL, &packets); - parse_keys(packets, &keys); - free_packet_list(packets); - packets = NULL; - - initdb(); - for (curkey = keys; curkey != NULL; curkey = curkey->next) { - fprintf(stderr, "Dealing with key.\n"); - fprintf(stderr, "fetch_key: %d\n", - fetch_key(get_keyid(curkey), &oldkey)); + if (packets != NULL) { + parse_keys(packets, &keys); + free_packet_list(packets); + packets = NULL; - /* - * 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) { - fprintf(stderr, "merge_keys: %d\n", - merge_keys(oldkey, curkey)); - if (curkey->revocations == NULL && - curkey->uids == NULL && - curkey->subkeys == NULL) { - fprintf(stderr, "No new info.\n"); - if (prev == NULL) { - keys = curkey->next; - } else { - prev->next = curkey->next; - prev = curkey->next; - } - } else { - prev = curkey; - } - /* TODO: store_key(oldkey); */ - free_publickey(oldkey); - oldkey = NULL; - } else { - store_key(curkey); - newkeys++; - } + initdb(); + fprintf(stderr, "Got %d new keys.\n", + update_keys(&keys)); + cleanupdb(); + } else { + rc = 1; + fprintf(stderr, "No keys read.\n"); } - cleanupdb(); if (keys != NULL) { flatten_publickey(keys, &packets, &list_end); @@ -95,6 +67,7 @@ int main(int argc, char *argv[]) packets = NULL; } else { rc = 1; + fprintf(stderr, "No changes.\n"); } return rc;