2 * add.c - CGI to add keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "keystructs.h"
26 int cgi_getchar(void *ctx, unsigned char *c)
28 struct cgi_get_ctx *buf = NULL;
30 buf = (struct cgi_get_ctx *) ctx;
32 *c = buf->buffer[buf->offset++];
37 int main(int argc, char *argv[])
39 struct openpgp_packet_list *packets = NULL;
40 struct openpgp_publickey *keys = NULL;
41 struct openpgp_publickey *curkey = NULL;
43 struct cgi_get_ctx ctx;
46 memset(&ctx, 0, sizeof(ctx));
48 params = getcgivars(argc, argv);
49 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
50 if (!strcmp(params[i], "keytext")) {
51 ctx.buffer = params[i+1];
55 // puts("HTTP/1.0 200 OK");
56 // puts("Server: onak 0.0.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);
69 while (curkey != NULL) {
70 if (store_key(curkey)) {
71 // puts("Key added successfully.");
73 printf("Problem adding key '%s'.\n", strerror(errno));
75 curkey = curkey->next;
80 puts("No OpenPGP packets found in input.");
83 puts("</body></html>");
84 return (EXIT_SUCCESS);