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 {
puts("No OpenPGP packets found in input.");
}
}
- puts("</body></html>");
+ end_html();
return (EXIT_SUCCESS);
}
char *ptr = NULL;
char *nextptr = NULL;
- buf[0] = 0;
+ memset(buf, 0, 1024);
ptr = strchr(string, '<');
if (ptr != NULL) {
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;
*/
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[]);
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,
}
} 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 &&
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.");
}
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);
}