From cc5b0a8e7e28a167ec9b593d918fb4e77e92a468 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 13 Jul 2008 18:29:53 +0100 Subject: [PATCH] ${PATH_INFO} rejection message now links to (hopefuly!) the right place. Fixes issue #21. Organization: Straylight/Edgeware From: Richard Kettlewell --- CHANGES.html | 18 ++++++++++++++++++ cgi/cgimain.c | 6 ++++-- lib/url.c | 10 +++++++--- lib/url.h | 2 +- libtests/t-url.c | 12 ++++++------ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CHANGES.html b/CHANGES.html index 6dd53be..d19afe7 100644 --- a/CHANGES.html +++ b/CHANGES.html @@ -83,6 +83,24 @@ span.command { disorder_preferences(5) man page.

+ +

Bugs fixed

+ +
+ + + + + + + + + + + +
IDDescription
#21CGI should use PATH_INFO more sensibly
+ +
diff --git a/cgi/cgimain.c b/cgi/cgimain.c index e96bbab..219f2b7 100644 --- a/cgi/cgimain.c +++ b/cgi/cgimain.c @@ -36,7 +36,9 @@ int main(int argc, char **argv) { printf("Content-Type: text/html; charset=UTF-8\n"); printf("Status: 404\n"); printf("\n"); - printf("

Sorry, PATH_INFO not supported.

\n"); + printf("

Sorry, is PATH_INFO not supported." + "Try here instead.

\n", + cgi_sgmlquote(infer_url(0/*!include_path_info*/))); exit(0); } /* Parse CGI arguments */ @@ -53,7 +55,7 @@ int main(int argc, char **argv) { /* Figure out our URL. This can still be overridden from the config file if * necessary but it shouldn't be necessary in ordinary installations. */ if(!config->url) - config->url = infer_url(); + config->url = infer_url(1/*include_path_info*/); /* Pick up the cookie, if there is one */ dcgi_get_cookie(); /* Register expansions */ diff --git a/lib/url.c b/lib/url.c index b777282..e05e6bf 100644 --- a/lib/url.c +++ b/lib/url.c @@ -32,12 +32,13 @@ #include "kvp.h" /** @brief Infer the for the web interface + * @param include_path_info 1 to include post-script path, else 0 * @return Inferred URL * * See RFC 3875. */ -char *infer_url(void) { - const char *scheme = "http", *server, *script, *e, *request_uri; +char *infer_url(int include_path_info) { + const char *scheme = "http", *server, *script, *e, *request_uri, *path_info; char *url; int port; @@ -58,7 +59,7 @@ char *infer_url(void) { port = 80; /* Figure out path to ourselves. */ - if((request_uri = getenv("REQUEST_URI"))) { + if(include_path_info && (request_uri = getenv("REQUEST_URI"))) { /* REQUEST_URI is an Apache extexnsion. If it's available it results in * more accurate self-referencing URLs. */ if((e = strchr(request_uri, '?'))) @@ -74,6 +75,9 @@ char *infer_url(void) { script = "/"; /* SCRIPT_NAME is not URL-encoded */ script = urlencodestring(script); + if(include_path_info && (path_info = getenv("PATH_INFO"))) + byte_xasprintf((char **)&script, "%s%s", + script, urlencodestring(path_info)); } if(script[0] != '/') fatal(0, "SCRIPT_NAME does not start with a '/'"); diff --git a/lib/url.h b/lib/url.h index 3331456..3546e77 100644 --- a/lib/url.h +++ b/lib/url.h @@ -68,7 +68,7 @@ struct url { char *query; }; -char *infer_url(void); +char *infer_url(int include_path_info); int parse_url(const char *url, struct url *parsed); #endif /* URL_H */ diff --git a/libtests/t-url.c b/libtests/t-url.c index dcff4bf..4bc7474 100644 --- a/libtests/t-url.c +++ b/libtests/t-url.c @@ -50,22 +50,22 @@ static void test_url(void) { setenv("SERVER_NAME", "www.anjou.terraraq.org.uk", 1); setenv("SERVER_PORT", "80", 1); setenv("SCRIPT_NAME", "/~richard/env.cgi", 1); - check_string(infer_url(), + check_string(infer_url(1), "http://www.anjou.terraraq.org.uk/~richard/env.cgi"); setenv("HTTPS", "on", 1); - check_string(infer_url(), + check_string(infer_url(1), "https://www.anjou.terraraq.org.uk/~richard/env.cgi"); setenv("QUERY_STRING", "foo", 1); - check_string(infer_url(), + check_string(infer_url(1), "https://www.anjou.terraraq.org.uk/~richard/env.cgi"); setenv("REQUEST_URI", "/~richard/env%2ecgi", 1); - check_string(infer_url(), + check_string(infer_url(1), "https://www.anjou.terraraq.org.uk/~richard/env%2ecgi"); setenv("REQUEST_URI", "/~richard/env%2ecgi?foo", 1); - check_string(infer_url(), + check_string(infer_url(1), "https://www.anjou.terraraq.org.uk/~richard/env%2ecgi"); setenv("SERVER_PORT", "8080", 1); - check_string(infer_url(), + check_string(infer_url(1), "https://www.anjou.terraraq.org.uk:8080/~richard/env%2ecgi"); } -- [mdw]