#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);
}
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);
packets = NULL;
} else {
rc = 1;
+ fprintf(stderr, "No changes.\n");
}
return rc;