From 1f641e69a8cb9402126c1031f71424527d669dff Mon Sep 17 00:00:00 2001 From: jongfoster Date: Sat, 9 Jun 2001 10:51:58 +0000 Subject: [PATCH] Changing "show URL info" handler to new style. Changing BUFSIZ ==> BUFFER_SIZE --- cgi.c | 139 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 77 insertions(+), 62 deletions(-) diff --git a/cgi.c b/cgi.c index b101b2cd..c8aa4027 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.5 2001/06/05 19:59:16 jongfoster Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.6 2001/06/07 23:05:19 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -36,6 +36,9 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.5 2001/06/05 19:59:16 jongfoster Exp $"; * * Revisions : * $Log: cgi.c,v $ + * Revision 1.6 2001/06/07 23:05:19 jongfoster + * Removing code related to old forward and ACL files. + * * Revision 1.5 2001/06/05 19:59:16 jongfoster * Fixing multiline character string (a GCC-only "feature"), and snprintf (it's _snprintf under VC++). * @@ -135,9 +138,9 @@ const struct cgi_dispatcher cgi_dispatchers[] = { { "show-status", 11, cgi_show_status, "Show information about the version and configuration" }, -/* { "show-url-info", + { "show-url-info", 13, cgi_show_url_info, - "Show which actions apply to a URL and why" },*/ + "Show which actions apply to a URL and why" }, { "send-banner", 11, cgi_send_banner, "HIDE Send the transparent or \"Junkbuster\" gif" }, @@ -257,7 +260,7 @@ struct http_response *cgi_dispatch(struct client_state *csp) struct map *parse_cgi(char *argstring) { char *tmp, *p; - char *vector[BUFSIZ]; + char *vector[BUFFER_SIZE]; int pairs, i; struct map *cgi_params = NULL; @@ -296,7 +299,7 @@ struct map *parse_cgi(char *argstring) *********************************************************************/ int make_http_response(struct http_response *rsp) { - char buf[BUFSIZ]; + char buf[BUFFER_SIZE]; /* Fill in the HTTP Status */ sprintf(buf, "HTTP/1.0 %s", rsp->status ? rsp->status : "200 OK"); @@ -378,7 +381,7 @@ char *fill_template(struct client_state *csp, char *template, struct map *answer { struct map *m; pcrs_job *job, *joblist = NULL; - char buf[BUFSIZ]; + char buf[BUFFER_SIZE]; char *new, *old = NULL; int size; FILE *fp; @@ -386,7 +389,7 @@ char *fill_template(struct client_state *csp, char *template, struct map *answer /* * Open template file or fail */ - snprintf(buf, BUFSIZ, "%s/templates/%s", csp->config->confdir, template); + snprintf(buf, BUFFER_SIZE, "%s/templates/%s", csp->config->confdir, template); if(NULL == (fp = fopen(buf, "r"))) { @@ -401,7 +404,7 @@ char *fill_template(struct client_state *csp, char *template, struct map *answer { int error; - snprintf(buf, BUFSIZ, "s°@%s@°%s°ig", m->name, m->value); + snprintf(buf, BUFFER_SIZE, "s°@%s@°%s°ig", m->name, m->value); if(NULL == (job = pcrs_make_job(buf, &error))) { @@ -420,7 +423,7 @@ char *fill_template(struct client_state *csp, char *template, struct map *answer /* * Read the file, ignoring comments */ - while (fgets(buf, BUFSIZ, fp)) + while (fgets(buf, BUFFER_SIZE, fp)) { /* skip lines starting with '#' */ if(*buf == '#') continue; @@ -505,7 +508,7 @@ int cgi_default(struct client_state *csp, struct http_response *rsp, struct map *parameters) { char *p, *tmp = NULL; - char buf[BUFSIZ]; + char buf[BUFFER_SIZE]; const struct cgi_dispatcher *d; struct map *exports = NULL; @@ -514,7 +517,7 @@ int cgi_default(struct client_state *csp, struct http_response *rsp, { if (strncmp(d->description, "HIDE", 4)) { - snprintf(buf, BUFSIZ, "
  • %s
  • ", + snprintf(buf, BUFFER_SIZE, "
  • %s
  • ", HOME_PAGE_URL, d->name, d->description); tmp = strsav(tmp, buf); } @@ -656,7 +659,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, #ifdef SPLIT_PROXY_ARGS FILE * fp; - char buf[BUFSIZ]; + char buf[BUFFER_SIZE]; char * p; const char * filename = NULL; char * file_description = NULL; @@ -717,10 +720,10 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, } fclose(fp); exports = map(exports, "contents", 1, s, 0); - } - rsp->body = fill_template(csp, "show-status-file", exports);; - free_map(exports); - return(0); + } + rsp->body = fill_template(csp, "show-status-file", exports);; + free_map(exports); + return(0); } @@ -824,23 +827,19 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp, * Returns : ???FIXME * *********************************************************************/ -char *cgi_show_url_info(struct http_request *http, struct client_state *csp) +int cgi_show_url_info(struct client_state *csp, struct http_response *rsp, + struct map *parameters) { - char * query_string = strchr(http->path, '?'); - char * host = NULL; - - if (query_string != NULL) + const char * host_param = lookup(parameters, "url"); + char * host = NULL; + + if (*host_param != '\0') { - query_string = url_decode(query_string + 1); - if (strncmpic(query_string, "url=", 4) == 0) - { - host = strdup(query_string + 4); - } - freez(query_string); + host = strdup(host_param); } if (host != NULL) { - char * result; + char * matches = NULL; char * path; char * s; int port = 80; @@ -848,18 +847,29 @@ char *cgi_show_url_info(struct http_request *http, struct client_state *csp) struct url_actions *b; struct url_spec url[1]; struct current_action_spec action[1]; + struct map *exports = NULL; + exports = map(exports, "url", 1, html_encode(host), 0); + init_current_action(action); - result = (char *)malloc(sizeof(C_URL_INFO_HEADER) + 2 * strlen(host)); - sprintf(result, C_URL_INFO_HEADER, host, host); - s = current_action_to_text(action); - result = strsav(result, "

    Defaults:

    \n

    {"); - result = strsav(result, s); - result = strsav(result, " }

    \n

    Patterns affecting the URL:

    \n

    \n"); - freez(s); - + exports = map(exports, "default", 1, s , 0); + + if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL)) + { + exports = map(exports, "matches", 1, "" , 1); + exports = map(exports, "final", 1, lookup(exports, "default"), 1); + + freez(host); + free_current_action(action); + + rsp->body = fill_template(csp, "show-url-info", exports); + free_map(exports); + + return 0; + } + s = strchr(host, '/'); if (s != NULL) { @@ -875,14 +885,7 @@ char *cgi_show_url_info(struct http_request *http, struct client_state *csp) { *s++ = '\0'; port = atoi(s); - } - - if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL)) - { - freez(host); - freez(path); - result = strsav(result, C_URL_INFO_FOOTER); - return result; + s = NULL; } *url = dsplit(host); @@ -890,10 +893,17 @@ char *cgi_show_url_info(struct http_request *http, struct client_state *csp) /* if splitting the domain fails, punt */ if (url->dbuf == NULL) { - freez(host); - freez(path); - result = strsav(result, C_URL_INFO_FOOTER); - return result; + exports = map(exports, "matches", 1, "" , 1); + exports = map(exports, "final", 1, lookup(exports, "default"), 1); + + freez(host); + 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) @@ -911,11 +921,11 @@ char *cgi_show_url_info(struct http_request *http, struct client_state *csp) ) { s = actions_to_text(b->action); - result = strsav(result, "{"); - result = strsav(result, s); - result = strsav(result, " }
    \n"); - result = strsav(result, b->url->spec); - result = strsav(result, "
    \n
    \n"); + matches = strsav(matches, "{"); + matches = strsav(matches, s); + matches = strsav(matches, " }
    \n"); + matches = strsav(matches, b->url->spec); + matches = strsav(matches, "
    \n
    \n"); freez(s); merge_current_action(action, b->action); @@ -924,26 +934,31 @@ char *cgi_show_url_info(struct http_request *http, struct client_state *csp) } } + exports = map(exports, "matches", 1, matches , 0); + matches = NULL; + freez(url->dbuf); freez(url->dvec); freez(host); freez(path); - + s = current_action_to_text(action); - result = strsav(result, "

    \n

    Final Results:

    \n

    {"); - result = strsav(result, s); - result = strsav(result, " }
    \n
    \n"); - freez(s); + exports = map(exports, "final", 1, s, 0); + s = NULL; free_current_action(action); - result = strsav(result, C_URL_INFO_FOOTER); - return result; + rsp->body = fill_template(csp, "show-url-info", exports); + free_map(exports); + + return 0; } else { - return strdup(C_URL_INFO_FORM); + rsp->body = fill_template(csp, "show-url-info-form", NULL); + + return 0; } } @@ -968,7 +983,7 @@ char *ij_untrusted_url(struct http_request *http, struct client_state *csp) { int n; char *hostport, *path, *refer, *p, *v[9]; - char buf[BUFSIZ]; + char buf[BUFFER_SIZE]; struct url_spec **tl, *t; -- 2.39.2