From: Jonathan McDowell Date: Mon, 31 May 2004 23:46:55 +0000 (+0000) Subject: cscvs to tla changeset 4 X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/200b89a2c66c58c41a27883f021850445698b337?ds=sidebyside;hp=e02c731dfbb288c736f2cd09a9b6df0507c59ddd cscvs to tla changeset 4 Author: noodles Date: 2002/09/08 10:27:47 Pulled out HTML start/end code to getcgi.c and added DOCTYPE & charset. --- diff --git a/add.c b/add.c index 3af9309..95f2189 100644 --- 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("onak : Add"); + 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(""); + end_html(); return (EXIT_SUCCESS); } diff --git a/getcgi.c b/getcgi.c index 47a94b2..26c3c50 100644 --- 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 . + */ +void start_html(const char *title) +{ + puts("Content-Type: text/html; charset=utf8\n"); + puts(""); + puts(""); + puts(""); + printf("%s\n", title); + puts(""); + puts(""); + + return; +} + +/* + * end_html - End HTML output. + * + * Ends HTML output - closes the BODY and HTML tags. + */ +void end_html(void) +{ + puts(""); + puts(""); + + return; +} + + /* Convert a two-char hex string into the char it represents */ -char x2c(char *what) +char x2c(const char *what) { register char digit; diff --git a/getcgi.h b/getcgi.h index 58d009b..5886996 100644 --- 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 . + */ +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[]); diff --git a/lookup.c b/lookup.c index 94f38c8..e4ac9ce 100644 --- 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("\nLookup of key"); - puts(""); + 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("
"); puts("Produced by onak " VERSION " by Jonathan McDowell"); - puts("\n"); + end_html(); + + if (search != NULL) { + free(search); + search = NULL; + } + return (EXIT_SUCCESS); }