X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/4b8483ae278577a3adc8d84da81d77019704466f..656bb5c3981ae175698ff8782c7ec39e1f6451d1:/add.c diff --git a/add.c b/add.c index 323373b..95f2189 100644 --- a/add.c +++ b/add.c @@ -16,6 +16,7 @@ #include "keydb.h" #include "keystructs.h" #include "parsekey.h" +#include "merge.h" struct cgi_get_ctx { char *buffer; @@ -23,13 +24,15 @@ struct cgi_get_ctx { }; -int cgi_getchar(void *ctx, unsigned char *c) +int cgi_getchar(void *ctx, size_t count, unsigned char *c) { struct cgi_get_ctx *buf = NULL; buf = (struct cgi_get_ctx *) ctx; - *c = buf->buffer[buf->offset++]; + while (count-- > 0 && *c != 0) { + *c = buf->buffer[buf->offset++]; + } return (*c == 0); } @@ -38,7 +41,6 @@ int main(int argc, char *argv[]) { struct openpgp_packet_list *packets = NULL; struct openpgp_publickey *keys = NULL; - struct openpgp_publickey *curkey = NULL; char **params = NULL; struct cgi_get_ctx ctx; int i; @@ -49,13 +51,19 @@ int main(int argc, char *argv[]) for (i = 0; params != NULL && params[i] != NULL; i += 2) { if (!strcmp(params[i], "keytext")) { ctx.buffer = params[i+1]; + } else { + free(params[i+1]); } + params[i+1] = NULL; + free(params[i]); + params[i] = NULL; + } + if (params != NULL) { + free(params); + params = NULL; } -// puts("HTTP/1.0 200 OK"); -// puts("Server: onak 0.0.1"); - puts("Content-Type: text/html\n"); - puts("onak : Add"); + start_html("onak : Add"); if (ctx.buffer == NULL) { puts("Error: No keytext to add supplied."); } else { @@ -64,22 +72,14 @@ int main(int argc, char *argv[]) &packets); if (packets != NULL) { parse_keys(packets, &keys); - curkey = keys; initdb(); - while (curkey != NULL) { - if (store_key(curkey)) { -// puts("Key added successfully."); - } else { - printf("Problem adding key '%s'.\n", strerror(errno)); - } - curkey = curkey->next; - } + printf("Got %d new keys.\n", + update_keys(&keys, false)); cleanupdb(); - puts("Keys added."); } else { puts("No OpenPGP packets found in input."); } } - puts(""); + end_html(); return (EXIT_SUCCESS); }