cscvs to tla changeset 2
[onak.git] / onak.c
1 /*
2  * onak.c - An OpenPGP keyserver.
3  *
4  * This is the main swiss army knife binary.
5  *
6  * Jonathan McDowell <noodles@earth.li>
7  * 
8  * Copyright 2002 Project Purple
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "armor.h"
15 #include "keydb.h"
16 #include "keyid.h"
17 #include "keystructs.h"
18 #include "mem.h"
19 #include "merge.h"
20 #include "parsekey.h"
21
22 int stdin_getchar(void *ctx, size_t count, unsigned char *c)
23 {
24         int ic;
25
26         do {
27                 ic = getchar();
28                 *c = ic;
29                 c++;
30         } while ((ic != EOF) && (--count > 0));
31         return (ic == EOF);
32 }
33
34 int stdout_putchar(void *ctx, unsigned char c)
35 {
36         return (putchar(c));
37 }
38
39
40 int main(int argc, char *argv[])
41 {
42         struct openpgp_packet_list      *packets = NULL;
43         struct openpgp_packet_list      *list_end = NULL;
44         struct openpgp_publickey        *keys = NULL;
45         int                              rc = EXIT_SUCCESS;
46
47         read_openpgp_stream(stdin_getchar, NULL, &packets);
48         if (packets != NULL) {
49                 parse_keys(packets, &keys);
50                 free_packet_list(packets);
51                 packets = NULL;
52
53                 initdb();
54                 fprintf(stderr, "Got %d new keys.\n",
55                                 update_keys(&keys));
56                 cleanupdb();
57         } else {
58                 rc = 1;
59                 fprintf(stderr, "No keys read.\n");
60         }
61
62         if (keys != NULL) {
63                 free_publickey(keys);
64                 keys = NULL;
65         } else {
66                 rc = 1;
67                 fprintf(stderr, "No changes.\n");
68         }
69
70         return rc;
71 }