From bd8c476f053258f68476b246c435ad09baae85ab Mon Sep 17 00:00:00 2001 From: jongfoster Date: Thu, 17 Jan 2002 20:56:22 +0000 Subject: [PATCH] Replacing hard references to the URL of the config interface with #defines from project.h --- cgi.c | 42 +++++++++++++++++++++++++++--------------- cgiedit.c | 30 ++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/cgi.c b/cgi.c index d6bc173b..356f0e0e 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.39 2001/11/16 00:48:13 jongfoster Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.40 2002/01/09 14:26:46 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -38,6 +38,9 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.39 2001/11/16 00:48:13 jongfoster Exp $"; * * Revisions : * $Log: cgi.c,v $ + * Revision 1.40 2002/01/09 14:26:46 oes + * Added support for thread-safe gmtime_r call. + * * Revision 1.39 2001/11/16 00:48:13 jongfoster * Fixing a compiler warning * @@ -398,8 +401,10 @@ static struct map *parse_cgi_parameters(char *argstring); * * Function : dispatch_cgi * - * Description : Checks if a request URL has either the magical hostname - * i.j.b or matches HOME_PAGE_URL/config/. If so, it passes + * Description : Checks if a request URL has either the magical + * hostname CGI_SITE_1_HOST (usully http://i.j.b/) or + * matches CGI_SITE_2_HOST CGI_SITE_2_PATH (usually + * http://ijbswa.sourceforge.net/config). If so, it passes * the (rest of the) path onto dispatch_known_cgi, which * calls the relevant CGI handler function. * @@ -418,27 +423,34 @@ struct http_response *dispatch_cgi(struct client_state *csp) * Should we intercept ? */ - /* Either the host matches CGI_PREFIX_HOST ..*/ - if ( (0 == strcmpic(host, CGI_PREFIX_HOST)) + /* Note: "example.com" and "example.com." are equivalent hostnames. */ + + /* Either the host matches CGI_SITE_1_HOST ..*/ + if ( ( (0 == strcmpic(host, CGI_SITE_1_HOST)) + || (0 == strcmpic(host, CGI_SITE_1_HOST "."))) && (path[0] == '/') ) { /* ..then the path will all be for us. Remove leading '/' */ path++; } - /* Or it's the host part HOME_PAGE_URL, and the path /config/ */ - else if ( (0 == strcmpic(host, HOME_PAGE_URL + 7 )) - && (0 == strncmpic(path,"/config", 7)) ) + /* Or it's the host part CGI_SITE_2_HOST, and the path CGI_SITE_2_PATH */ + else if ( ( (0 == strcmpic(host, CGI_SITE_2_HOST )) + || (0 == strcmpic(host, CGI_SITE_2_HOST ".")) ) + && (0 == strncmpic(path, CGI_SITE_2_PATH, strlen(CGI_SITE_2_PATH))) ) { - /* take everything following "/config" */ - path += 7; + /* take everything following CGI_SITE_2_PATH */ + path += strlen(CGI_SITE_2_PATH); if (*path == '/') { - /* skip the forward slash after "/config" */ + /* skip the forward slash after CGI_SITE_2_PATH */ path++; } else if (*path != '\0') { - /* wierdness: URL is /configXXX, where XXX is some string */ + /* + * wierdness: URL is /configXXX, where XXX is some string + * Do *NOT* intercept. + */ return NULL; } } @@ -1360,7 +1372,7 @@ struct map *default_exports(const struct client_state *csp, const char *caller) if (!err) err = map(exports, "my-ip-address", 1, csp->my_ip_addr_str ? csp->my_ip_addr_str : "unknown", 1); if (!err) err = map(exports, "my-hostname", 1, csp->my_hostname ? csp->my_hostname : "unknown", 1); if (!err) err = map(exports, "homepage", 1, HOME_PAGE_URL, 1); - if (!err) err = map(exports, "default-cgi", 1, HOME_PAGE_URL "/config", 1); + if (!err) err = map(exports, "default-cgi", 1, CGI_PREFIX, 1); if (!err) err = map(exports, "menu", 1, make_menu(caller), 0); if (!err) err = map(exports, "code-status", 1, CODE_STATUS, 1); if (!err) err = map_conditional(exports, "enabled-display", g_bToggleIJB); @@ -1517,8 +1529,8 @@ char *make_menu(const char *self) { if (d->description && strcmp(d->name, self)) { - snprintf(buf, BUFFER_SIZE, "
  • %s
  • \n", - HOME_PAGE_URL, d->name, d->description); + snprintf(buf, BUFFER_SIZE, "
  • %s
  • \n", + CGI_PREFIX, d->name, d->description); result = strsav(result, buf); } } diff --git a/cgiedit.c b/cgiedit.c index 5645bfd4..789bc3b1 100644 --- a/cgiedit.c +++ b/cgiedit.c @@ -1,4 +1,4 @@ -const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.7 2001/11/13 00:28:24 jongfoster Exp $"; +const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.8 2001/11/30 23:35:51 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ @@ -35,6 +35,9 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.7 2001/11/13 00:28:24 jongfoster * * Revisions : * $Log: cgiedit.c,v $ + * Revision 1.8 2001/11/30 23:35:51 jongfoster + * Renaming actionsfile to ijb.action + * * Revision 1.7 2001/11/13 00:28:24 jongfoster * - Renaming parameters from edit-actions-for-url so that they only * contain legal JavaScript characters. If we wanted to write @@ -124,6 +127,7 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.7 2001/11/13 00:28:24 jongfoster #include "errlog.h" #include "loadcfg.h" /* loadcfg.h is for g_bToggleIJB only */ +#include "urlmatch.h" const char cgiedit_h_rcs[] = CGIEDIT_H_VERSION; @@ -2599,7 +2603,8 @@ jb_err cgi_edit_actions(struct client_state *csp, { return JB_ERR_MEMORY; } - if (enlist_unique_header(rsp->headers, "Location", "http://ijbswa.sourceforge.net/config/edit-actions-list?filename=ijb")) + if (enlist_unique_header(rsp->headers, "Location", + CGI_PREFIX "edit-actions-list?filename=ijb")) { free(rsp->status); rsp->status = NULL; @@ -3140,7 +3145,7 @@ jb_err cgi_edit_actions_submit(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); @@ -3294,7 +3299,7 @@ jb_err cgi_edit_actions_url(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); @@ -3355,6 +3360,7 @@ jb_err cgi_edit_actions_add_url(struct client_state *csp, unsigned line_number; char * target; jb_err err; + struct url_spec compiled[1]; if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)) { @@ -3374,6 +3380,14 @@ jb_err cgi_edit_actions_add_url(struct client_state *csp, return JB_ERR_CGI_PARAMS; } + /* Check that regex is valid */ + err = create_url_spec(compiled, newval); + if (err) + { + return (err == JB_ERR_MEMORY) ? JB_ERR_MEMORY : JB_ERR_CGI_PARAMS; + } + free_url_spec(compiled); + err = edit_read_actions_file(csp, rsp, parameters, 1, &file); if (err) { @@ -3436,7 +3450,7 @@ jb_err cgi_edit_actions_add_url(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); @@ -3584,7 +3598,7 @@ jb_err cgi_edit_actions_remove_url(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); @@ -3717,7 +3731,7 @@ jb_err cgi_edit_actions_section_remove(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); @@ -3891,7 +3905,7 @@ jb_err cgi_edit_actions_section_add(struct client_state *csp, return err; } - target = strdup("http://ijbswa.sourceforge.net/config/edit-actions-list?filename="); + target = strdup(CGI_PREFIX "edit-actions-list?filename="); string_append(&target, file->identifier); edit_free_file(file); -- 2.39.2