-const char cgi_rcs[] = "$Id: cgi.c,v 1.7 2001/06/09 10:51:58 jongfoster Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.12 2001/07/29 18:47:05 jongfoster Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
*
* Revisions :
* $Log: cgi.c,v $
+ * Revision 1.12 2001/07/29 18:47:05 jongfoster
+ * Adding missing #include "loadcfg.h"
+ *
+ * Revision 1.11 2001/07/18 17:24:37 oes
+ * Changed to conform to new pcrs interface
+ *
+ * Revision 1.10 2001/07/13 13:53:13 oes
+ * Removed all #ifdef PCRS and related code
+ *
+ * Revision 1.9 2001/06/29 21:45:41 oes
+ * Indentation, CRLF->LF, Tab-> Space
+ *
+ * Revision 1.8 2001/06/29 13:21:46 oes
+ * - Cosmetics: renamed and reordered functions, variables,
+ * texts, improved comments etc
+ *
+ * - Removed ij_untrusted_url() The relevant
+ * info is now part of the "untrusted" page,
+ * which is generated by filters.c:trust_url()
+ *
+ * - Generators of content now call finish_http_response()
+ * themselves, making jcc.c:chat() a little less
+ * cluttered
+ *
+ * - Removed obsolete "Pragma: no-cache" from our headers
+ *
+ * - http_responses now know their head length
+ *
+ * - fill_template now uses the new interface to pcrs, so that
+ * - long jobs (like whole files) no longer have to be assembled
+ * in a fixed size buffer
+ * - the new T (trivial) option is used, and the replacement may
+ * contain Perl syntax backrefs without confusing pcrs
+ *
+ * - Introduced default_exports() which generates a set of exports
+ * common to all CGIs and other content generators
+ *
+ * - Introduced convenience function map_block_killer()
+ *
+ * - Introduced convenience function make_menu()
+ *
+ * - Introduced CGI-like function error_response() which generates
+ * the "No such domain" and "Connect failed" messages using the
+ * CGI platform
+ *
+ * - cgi_show_url_info:
+ * - adapted to new CGI features
+ * - form and answers now generated from same template
+ * - http:// prefix in URL now OK
+ *
+ * - cgi_show_status:
+ * - adapted to new CGI features
+ * - no longer uses csp->init_proxy_args
+ *
+ * - cgi_default:
+ * - moved menu generation to make_menu()
+ *
+ * - add_stats now writes single export map entries instead
+ * of a fixed string
+ *
+ * - Moved redirect_url() to filters.c
+ *
+ * - Fixed mem leak in free_http_response(), map_block_killer(),
+ *
+ * - Removed logentry from cancelled commit
+ *
* Revision 1.7 2001/06/09 10:51:58 jongfoster
* Changing "show URL info" handler to new style.
* Changing BUFSIZ ==> BUFFER_SIZE
#include "project.h"
#include "cgi.h"
#include "list.h"
-#include "pcrs.h"
#include "encode.h"
#include "ssplit.h"
#include "jcc.h"
#include "errlog.h"
#include "miscutil.h"
#include "showargs.h"
+#include "loadcfg.h"
const char cgi_h_rcs[] = CGI_H_VERSION;
{
param_list = parse_cgi_parameters(argstring + d->name_length);
if ((d->handler)(csp, rsp, param_list))
- {
- freez(rsp);
- }
+ {
+ freez(rsp);
+ }
- free_map(param_list);
- return(finish_http_response(rsp));
+ free_map(param_list);
+ return(finish_http_response(rsp));
}
}
{
if(strcmp(lookup(parameters, "type"), "trans"))
{
- rsp->body = bindup(JBGIF, sizeof(JBGIF));
- rsp->content_length = sizeof(JBGIF);
+ rsp->body = bindup(JBGIF, sizeof(JBGIF));
+ rsp->content_length = sizeof(JBGIF);
}
else
{
- rsp->body = bindup(BLANKGIF, sizeof(BLANKGIF));
- rsp->content_length = sizeof(BLANKGIF);
+ rsp->body = bindup(BLANKGIF, sizeof(BLANKGIF));
+ rsp->content_length = sizeof(BLANKGIF);
}
enlist(rsp->headers, "Content-Type: image/gif");
return(0);
+
}
int i;
struct map *exports = default_exports(csp, "show-status");
-#ifdef SPLIT_PROXY_ARGS
FILE * fp;
char buf[BUFFER_SIZE];
char * p;
}
break;
-#ifdef PCRS
case 'r':
if (csp->rlist)
{
file_description = "Regex Filter List";
}
break;
-#endif /* def PCRS */
-#ifdef TRUST_FILES
+#ifdef FEATURE_TRUST
case 't':
if (csp->tlist)
{
file_description = "Trust List";
}
break;
-#endif /* def TRUST_FILES */
+#endif /* def FEATURE_TRUST */
}
if (NULL != filename)
}
-#endif /* def SPLIT_PROXY_ARGS */
-
exports = map(exports, "redirect-url", 1, REDIRECT_URL, 1);
s = NULL;
s = show_defines();
exports = map(exports, "defines", 1, s, 0);
-#ifdef STATISTICS
+#ifdef FEATURE_STATISTICS
exports = add_stats(exports);
-#else
+#else /* ndef FEATURE_STATISTICS */
exports = map_block_killer(exports, "statistics");
-#endif /* ndef STATISTICS */
-
-#ifdef SPLIT_PROXY_ARGS
+#endif /* ndef FEATURE_STATISTICS */
exports = map_block_killer(exports, "no-split-args");
exports = map(exports, "actions-filename", 1, "None specified", 1);
}
-#ifdef PCRS
if (csp->rlist)
{
exports = map(exports, "re-filter-filename", 1, csp->rlist->filename, 1);
{
exports = map(exports, "re-filter-filename", 1, "None specified", 1);
}
-#else
- exports = map_block_killer(exports, "pcrs-support");
-#endif /* ndef PCRS */
-#ifdef TRUST_FILES
+#ifdef FEATURE_TRUST
if (csp->tlist)
{
exports = map(exports, "trust-filename", 1, csp->tlist->filename, 1);
- }
- else
- {
- exports = map(exports, "trust-filename", 1, "None specified", 1);
- }
-#else
- exports = map_block_killer(exports, "trust-support");
-#endif /* ndef TRUST_FILES */
-
-#else /* ifndef SPLIT_PROXY_ARGS */
- exports = map_block_killer(exports, "split-args");
-
- if (csp->clist)
- {
- map(exports, "clist", 1, csp->clist->proxy_args , 1);
- }
-
-#ifdef PCRS
- if (csp->rlist)
- {
- map(exports, "rlist", 1, csp->rlist->proxy_args , 1);
}
-#endif /* def PCRS */
-
-#ifdef TRUST_FILES
- if (csp->tlist)
+ else
{
- map(exports, "tlist", 1, csp->tlist->proxy_args , 1);
+ exports = map(exports, "trust-filename", 1, "None specified", 1);
}
-#endif /* def TRUST_FILES */
-
-#endif /* ndef SPLIT_PROXY_ARGS */
+#else
+ exports = map_block_killer(exports, "trust-support");
+#endif /* ndef FEATURE_TRUST */
rsp->body = fill_template(csp, "show-status", exports);
free_map(exports);
* Returns : 0
*
*********************************************************************/
-int cgi_show_url_info(struct client_state *csp, struct http_response *rsp,\r
- struct map *parameters)\r
+int cgi_show_url_info(struct client_state *csp, struct http_response *rsp,
+ struct map *parameters)
{
struct map *exports = default_exports(csp, "show-url-info");
char *url_param, *host = NULL;
host = url_param;
host += (strncmp(url_param, "http://", 7)) ? 0 : 7;
- exports = map(exports, "url", 1, host, 1);\r
- exports = map(exports, "url-html", 1, html_encode(host), 0);\r\r
+ exports = map(exports, "url", 1, host, 1);
+ exports = map(exports, "url-html", 1, html_encode(host), 0);
init_current_action(action);
s = current_action_to_text(action);
- exports = map(exports, "default", 1, s , 0);\r
-
- if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))\r
- {\r
- exports = map(exports, "matches", 1, "none" , 1);\r
- exports = map(exports, "final", 1, lookup(exports, "default"), 1);\r
-\r
- freez(url_param);\r
- free_current_action(action);\r
-\r
- rsp->body = fill_template(csp, "show-url-info", exports);\r
- free_map(exports);\r
-\r
- return 0;\r
- }\r
-\r
+ exports = map(exports, "default", 1, s , 0);
+
+ if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
+ {
+ exports = map(exports, "matches", 1, "none" , 1);
+ exports = map(exports, "final", 1, lookup(exports, "default"), 1);
+
+ freez(url_param);
+ free_current_action(action);
+
+ rsp->body = fill_template(csp, "show-url-info", exports);
+ free_map(exports);
+
+ return 0;
+ }
+
s = strchr(host, '/');
if (s != NULL)
{
{
*s++ = '\0';
port = atoi(s);
- s = NULL;\r
+ s = NULL;
}
*url = dsplit(host);
/* if splitting the domain fails, punt */
if (url->dbuf == NULL)
{
- exports = map(exports, "matches", 1, "none" , 1);\r
- exports = map(exports, "final", 1, lookup(exports, "default"), 1);\r
-\r
- freez(url_param);\r
- freez(path);\r
- free_current_action(action);\r
-\r
- rsp->body = fill_template(csp, "show-url-info", exports);\r
- free_map(exports);\r
-\r
- return 0;\r
+ exports = map(exports, "matches", 1, "none" , 1);
+ exports = map(exports, "final", 1, lookup(exports, "default"), 1);
+
+ freez(url_param);
+ freez(path);
+ free_current_action(action);
+
+ rsp->body = fill_template(csp, "show-url-info", exports);
+ free_map(exports);
+
+ return 0;
}
for (b = b->next; NULL != b; b = b->next)
{
exports = map(exports, "matches", 1, "none", 1);
}
- matches = NULL;\r
-\r
+ matches = NULL;
+
freez(url->dbuf);
freez(url->dvec);
freez(url_param);
freez(path);
-\r
+
s = current_action_to_text(action);
- exports = map(exports, "final", 1, s, 0);\r
- s = NULL;\r
+ exports = map(exports, "final", 1, s, 0);
+ s = NULL;
free_current_action(action);
}
- rsp->body = fill_template(csp, "show-url-info", exports);\r
- free_map(exports);\r
+ rsp->body = fill_template(csp, "show-url-info", exports);
+ free_map(exports);
return 0;
}
*********************************************************************/
struct http_response *finish_http_response(struct http_response *rsp)
{
- char buf[BUFFER_SIZE];
-
- /*
- * Fill in the HTTP Status
- */
- sprintf(buf, "HTTP/1.0 %s", rsp->status ? rsp->status : "200 OK");
- enlist_first(rsp->headers, buf);
-
- /*
- * Set the Content-Length
- */
- if (rsp->content_length == 0)
- {
- rsp->content_length = rsp->body ? strlen(rsp->body) : 0;
- }
- sprintf(buf, "Content-Length: %d", rsp->content_length);
- enlist(rsp->headers, buf);
-
- /*
- * Fill in the default headers FIXME: Are these correct? sequence OK? check rfc!
- */
- enlist_unique(rsp->headers, "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT", 14);
- enlist_unique(rsp->headers, "Expires: Thu Jul 31, 1997 07:42:22 pm GMT", 8);
- enlist_unique(rsp->headers, "Content-Type: text/html", 13);
- enlist(rsp->headers, "");
+ char buf[BUFFER_SIZE];
+
+ /*
+ * Fill in the HTTP Status
+ */
+ sprintf(buf, "HTTP/1.0 %s", rsp->status ? rsp->status : "200 OK");
+ enlist_first(rsp->headers, buf);
+
+ /*
+ * Set the Content-Length
+ */
+ if (rsp->content_length == 0)
+ {
+ rsp->content_length = rsp->body ? strlen(rsp->body) : 0;
+ }
+ sprintf(buf, "Content-Length: %d", rsp->content_length);
+ enlist(rsp->headers, buf);
+
+ /*
+ * Fill in the default headers FIXME: Are these correct? sequence OK? check rfc!
+ */
+ enlist_unique(rsp->headers, "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT", 14);
+ enlist_unique(rsp->headers, "Expires: Thu Jul 31, 1997 07:42:22 pm GMT", 8);
+ enlist_unique(rsp->headers, "Content-Type: text/html", 13);
+ enlist(rsp->headers, "");
- /*
- * Write the head
- */
- if (NULL == (rsp->head = list_to_text(rsp->headers)))
- {
- free_http_response(rsp);
- return(NULL);
- }
- rsp->head_length = strlen(rsp->head);
+ /*
+ * Write the head
+ */
+ if (NULL == (rsp->head = list_to_text(rsp->headers)))
+ {
+ free_http_response(rsp);
+ return(NULL);
+ }
+ rsp->head_length = strlen(rsp->head);
- return(rsp);
+ return(rsp);
}
log_error(LOG_LEVEL_ERROR, "error loading template %s: %E", buf);
return NULL;
}
-
+
/*
* Assemble pcrs joblist from exports map
/* Enclose name in @@ */
snprintf(buf, BUFFER_SIZE, "@%s@", m->name);
- /* Make and chain in job */
- if ( NULL == (job = (pcrs_make_job(buf, m->value, "sigTU", &error))) )
+ /* Make and chain job */
+ if ( NULL == (job = (pcrs_compile(buf, m->value, "sigTU", &error))) )
{
log_error(LOG_LEVEL_ERROR, "Error compiling template fill job %s: %d", m->name, error);
}
{
/* skip lines starting with '#' */
if(*buf == '#') continue;
-
+
old = strsav(old, buf);
}
fclose(fp);
if (strncmp(d->description, "HIDE", 4) && strcmp(d->name, self))
{
snprintf(buf, BUFFER_SIZE, "<li><a href=%s/config/%s>%s</a></li>\n",
- HOME_PAGE_URL, d->name, d->description);
+ HOME_PAGE_URL, d->name, d->description);
tmp = strsav(tmp, buf);
}
}
struct map *p = map;
char *ret = NULL;
-
ret = strsav(ret, "<table>\n");
while (p)
}
-#ifdef STATISTICS
+#ifdef FEATURE_STATISTICS
/*********************************************************************
*
* Function : add_stats
return(exports);
}
-#endif /* def STATISTICS */
+#endif /* def FEATURE_STATISTICS */
/*
Local Variables: