]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - add.c
cscvs to tla changeset 11
[onak.git] / add.c
diff --git a/add.c b/add.c
index 323373b36232e82de391a7e8782493e866caf1bf..95f218943b5dcaab6540201e116fe57bce2e5608 100644 (file)
--- 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("<html><title>onak : Add</title><body>");
+       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("</body></html>");
+       end_html();
        return (EXIT_SUCCESS);
 }