cscvs to tla changeset 4
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:46:55 +0000 (23:46 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:46:55 +0000 (23:46 +0000)
Author: noodles
Date: 2002/09/08 10:27:47
Pulled out HTML start/end code to getcgi.c and added DOCTYPE & charset.

add.c
getcgi.c
getcgi.h
lookup.c

diff --git a/add.c b/add.c
index 3af930903ce4d70e4f87b49b566c1122e0f6f7e6..95f218943b5dcaab6540201e116fe57bce2e5608 100644 (file)
--- a/add.c
+++ b/add.c
@@ -51,11 +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("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 {
@@ -72,6 +80,6 @@ int main(int argc, char *argv[])
                        puts("No OpenPGP packets found in input.");
                }
        }
-       puts("</body></html>");
+       end_html();
        return (EXIT_SUCCESS);
 }
index 47a94b294090c9a21da443247168aa706a72030a..26c3c50f5f52cf2b6bce08a0b962458640aa2f81 100644 (file)
--- a/getcgi.c
+++ b/getcgi.c
@@ -25,7 +25,7 @@ char *txt2html(const char *string)
        char *ptr = NULL;
        char *nextptr = NULL;
 
-       buf[0] = 0;
+       memset(buf, 0, 1024);
 
        ptr = strchr(string, '<');
        if (ptr != NULL) {
@@ -57,8 +57,42 @@ char *txt2html(const char *string)
        return buf;
 }
 
+/*
+ *     start_html - Start HTML output.
+ *     @title: The title for the HTML.
+ *
+ *     Takes a title string and starts HTML output, including the
+ *     Content-Type header all the way up to <BODY>.
+ */
+void start_html(const char *title)
+{
+       puts("Content-Type: text/html; charset=utf8\n");
+       puts("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'>");
+       puts("<HTML>");
+       puts("<HEAD>");
+       printf("<TITLE>%s</TITLE>\n", title);
+       puts("</HEAD>");
+       puts("<BODY>");
+
+       return;
+}
+
+/*
+ *     end_html - End HTML output.
+ *
+ *     Ends HTML output - closes the BODY and HTML tags.
+ */
+void end_html(void)
+{
+       puts("</BODY>");
+       puts("</HTML>");
+
+       return;
+}
+
+
 /* Convert a two-char hex string into the char it represents */
-char x2c(char *what) 
+char x2c(const char *what) 
 {
        register char digit;
 
index 58d009bd9afa302535d51c4be759043dd7cb2de1..5886996b3e07e052f12712f23485103f99ca7197 100644 (file)
--- a/getcgi.h
+++ b/getcgi.h
@@ -9,7 +9,23 @@
  */
 char *txt2html(const char *string);
 
-char x2c(char *what); 
+/*
+ *     start_html - Start HTML output.
+ *     @title: The title for the HTML.
+ *
+ *     Takes a title string and starts HTML output, including the
+ *     Content-Type header all the way up to <BODY>.
+ */
+void start_html(const char *title);
+
+/*
+ *     end_html - End HTML output.
+ *
+ *     Ends HTML output - closes the BODY and HTML tags.
+ */
+void end_html(void);
+
+char x2c(const char *what); 
 void unescape_url(char *url); 
 char **getcgivars(int argc, char *argv[]);
 
index 94f38c851fa44be2158700dd7c6cf079bfbdfd3c..e4ac9cefaecbe36fdbfbb7ba815d3de916e63940 100644 (file)
--- a/lookup.c
+++ b/lookup.c
@@ -28,7 +28,7 @@
 
 int putnextchar(void *ctx, size_t count, unsigned char *c)
 {
-       return printf("%.*s", count, c);
+       return printf("%.*s", (int) count, c);
 }
 
 void find_keys(char *search, uint64_t keyid, bool ishex,
@@ -82,6 +82,7 @@ int main(int argc, char *argv[])
                        }
                } else if (!strcmp(params[i], "search")) {
                        search = params[i+1];
+                       params[i+1] = NULL;
                        if (search != NULL) {
                                keyid = strtoul(search, &end, 16);
                                if (*search != 0 &&
@@ -99,13 +100,19 @@ int main(int argc, char *argv[])
                                exact = true;
                        }
                }
+               free(params[i]);
+               params[i] = NULL;
+               if (params[i+1] != NULL) {
+                       free(params[i+1]);
+                       params[i+1] = 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>\n<title>Lookup of key</title>");
-       puts("<body>");
+       start_html("Lookup of key");
 
        if (op == OP_UNKNOWN) {
                puts("Error: No operation supplied.");
@@ -143,6 +150,12 @@ int main(int argc, char *argv[])
        }
        puts("<hr>");
        puts("Produced by onak " VERSION " by Jonathan McDowell");
-       puts("</body>\n</html>");
+       end_html();
+
+       if (search != NULL) {
+               free(search);
+               search = NULL;
+       }
+       
        return (EXIT_SUCCESS);
 }