+ if (map(exports, "cgi-parameters", 1, "", 1))
+ {
+ return JB_ERR_MEMORY;
+ }
+ }
+
+ return template_fill_for_cgi(csp, "default", exports, rsp);
+}
+
+
+
+
+/*********************************************************************
+ *
+ * Function : cgi_error_404
+ *
+ * Description : CGI function that is called if an unknown action was
+ * given.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters : none
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err cgi_error_404(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ struct map *exports;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ if (NULL == (exports = default_exports(csp, NULL)))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ rsp->status = strdup("404 JunkBuster configuration page not found");
+ if (rsp->status == NULL)
+ {
+ free_map(exports);
+ return JB_ERR_MEMORY;
+ }
+
+ return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
+}
+
+
+/*********************************************************************
+ *
+ * Function : cgi_show_request
+ *
+ * Description : Show the client's request and what sed() would have
+ * made of it.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters : none
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err cgi_show_request(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ char *p;
+ struct map *exports;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ if (NULL == (exports = default_exports(csp, "show-request")))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ /*
+ * Repair the damage done to the IOB by get_header()
+ */
+ for (p = csp->iob->buf; p < csp->iob->eod; p++)
+ {
+ if (*p == '\0') *p = '\n';
+ }
+
+ /*
+ * Export the original client's request and the one we would
+ * be sending to the server if this wasn't a CGI call
+ */
+
+ if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
+ {
+ free_map(exports);
+ return JB_ERR_MEMORY;