X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=cgi.c;h=d2d6d93357a96084036133b07464edf378d34a45;hb=dcccd4b171466114662ad4d5b1d2e017bb579430;hp=00cbc3bcfc306872c737fd1d97cf52422e10f731;hpb=c36f4d5f3bbeef7ee4fd42c9a9b85e7e656b1658;p=privoxy.git diff --git a/cgi.c b/cgi.c index 00cbc3bc..d2d6d933 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -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 $ @@ -36,6 +36,72 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.7 2001/06/09 10:51:58 jongfoster Exp $"; * * 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 @@ -72,7 +138,6 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.7 2001/06/09 10:51:58 jongfoster Exp $"; #include "project.h" #include "cgi.h" #include "list.h" -#include "pcrs.h" #include "encode.h" #include "ssplit.h" #include "jcc.h" @@ -81,6 +146,7 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.7 2001/06/09 10:51:58 jongfoster Exp $"; #include "errlog.h" #include "miscutil.h" #include "showargs.h" +#include "loadcfg.h" const char cgi_h_rcs[] = CGI_H_VERSION; @@ -175,12 +241,12 @@ struct http_response *dispatch_cgi(struct client_state *csp) { 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)); } } @@ -297,18 +363,19 @@ int cgi_send_banner(struct client_state *csp, struct 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); + } @@ -338,7 +405,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, int i; struct map *exports = default_exports(csp, "show-status"); -#ifdef SPLIT_PROXY_ARGS FILE * fp; char buf[BUFFER_SIZE]; char * p; @@ -357,7 +423,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, } break; -#ifdef PCRS case 'r': if (csp->rlist) { @@ -365,9 +430,8 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, file_description = "Regex Filter List"; } break; -#endif /* def PCRS */ -#ifdef TRUST_FILES +#ifdef FEATURE_TRUST case 't': if (csp->tlist) { @@ -375,7 +439,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, file_description = "Trust List"; } break; -#endif /* def TRUST_FILES */ +#endif /* def FEATURE_TRUST */ } if (NULL != filename) @@ -408,8 +472,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, } -#endif /* def SPLIT_PROXY_ARGS */ - exports = map(exports, "redirect-url", 1, REDIRECT_URL, 1); s = NULL; @@ -426,13 +488,11 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, 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"); @@ -445,7 +505,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, 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); @@ -454,46 +513,19 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, { 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); @@ -524,8 +556,8 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, * Returns : 0 * *********************************************************************/ -int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, - struct map *parameters) +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; @@ -550,28 +582,28 @@ int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, host = url_param; host += (strncmp(url_param, "http://", 7)) ? 0 : 7; - exports = map(exports, "url", 1, host, 1); - exports = map(exports, "url-html", 1, html_encode(host), 0); + 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); - - 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; - } - + 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) { @@ -587,7 +619,7 @@ int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, { *s++ = '\0'; port = atoi(s); - s = NULL; + s = NULL; } *url = dsplit(host); @@ -595,17 +627,17 @@ int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, /* if splitting the domain fails, punt */ if (url->dbuf == NULL) { - 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; + 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) @@ -645,23 +677,23 @@ int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, { exports = map(exports, "matches", 1, "none", 1); } - matches = NULL; - + matches = NULL; + freez(url->dbuf); freez(url->dvec); freez(url_param); freez(path); - + s = current_action_to_text(action); - exports = map(exports, "final", 1, s, 0); - s = NULL; + exports = map(exports, "final", 1, s, 0); + s = NULL; free_current_action(action); } - rsp->body = fill_template(csp, "show-url-info", exports); - free_map(exports); + rsp->body = fill_template(csp, "show-url-info", exports); + free_map(exports); return 0; } @@ -731,44 +763,44 @@ struct http_response *error_response(struct client_state *csp, const char *templ *********************************************************************/ 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); } @@ -837,7 +869,7 @@ char *fill_template(struct client_state *csp, const char *template, struct map * log_error(LOG_LEVEL_ERROR, "error loading template %s: %E", buf); return NULL; } - + /* * Assemble pcrs joblist from exports map @@ -849,8 +881,8 @@ char *fill_template(struct client_state *csp, const char *template, struct 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); } @@ -869,7 +901,7 @@ char *fill_template(struct client_state *csp, const char *template, struct map * { /* skip lines starting with '#' */ if(*buf == '#') continue; - + old = strsav(old, buf); } fclose(fp); @@ -1002,7 +1034,7 @@ char *make_menu(const char *self) if (strncmp(d->description, "HIDE", 4) && strcmp(d->name, self)) { snprintf(buf, BUFFER_SIZE, "
  • %s
  • \n", - HOME_PAGE_URL, d->name, d->description); + HOME_PAGE_URL, d->name, d->description); tmp = strsav(tmp, buf); } } @@ -1028,7 +1060,6 @@ char *dump_map(struct map *map) struct map *p = map; char *ret = NULL; - ret = strsav(ret, "\n"); while (p) @@ -1047,7 +1078,7 @@ char *dump_map(struct map *map) } -#ifdef STATISTICS +#ifdef FEATURE_STATISTICS /********************************************************************* * * Function : add_stats @@ -1101,7 +1132,7 @@ struct map *add_stats(struct map *exports) return(exports); } -#endif /* def STATISTICS */ +#endif /* def FEATURE_STATISTICS */ /* Local Variables: