2 * add.c - CGI to add keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "keystructs.h"
27 int cgi_getchar(void *ctx, size_t count, unsigned char *c)
29 struct cgi_get_ctx *buf = NULL;
31 buf = (struct cgi_get_ctx *) ctx;
33 while (count-- > 0 && *c != 0) {
34 *c = buf->buffer[buf->offset++];
40 int main(int argc, char *argv[])
42 struct openpgp_packet_list *packets = NULL;
43 struct openpgp_publickey *keys = NULL;
45 struct cgi_get_ctx ctx;
48 memset(&ctx, 0, sizeof(ctx));
50 params = getcgivars(argc, argv);
51 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
52 if (!strcmp(params[i], "keytext")) {
53 ctx.buffer = params[i+1];
57 puts("Content-Type: text/html\n");
58 puts("<html><title>onak : Add</title><body>");
59 if (ctx.buffer == NULL) {
60 puts("Error: No keytext to add supplied.");
62 dearmor_openpgp_stream(cgi_getchar,
65 if (packets != NULL) {
66 parse_keys(packets, &keys);
68 printf("Got %d new keys.\n",
69 update_keys(&keys, false));
72 puts("No OpenPGP packets found in input.");
75 puts("</body></html>");
76 return (EXIT_SUCCESS);