chiark / gitweb /
${PATH_INFO} rejection message now links to (hopefuly!) the right
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 13 Jul 2008 17:29:53 +0000 (18:29 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 13 Jul 2008 17:29:53 +0000 (18:29 +0100)
place.  Fixes issue #21.

CHANGES.html
cgi/cgimain.c
lib/url.c
lib/url.h
libtests/t-url.c

index 6dd53be4e4a5b8a49f259109cbfe6e1faaaf467d..d19afe7cc861f74876a24f1f79edc639c001c97c 100644 (file)
@@ -83,6 +83,24 @@ span.command {
       <b>disorder_preferences</b>(5) man page.</p>
       
     </div>
+
+  <h3>Bugs fixed</h3>
+  
+    <div class=section>
+
+      <table class=bugs>
+        <tr>
+          <th>ID</th>
+          <th>Description</th>
+        </tr>
+        
+        <tr>
+          <td><a href="http://code.google.com/p/disorder/issues/detail?id=21">#21</a></td>
+          <td>CGI should use PATH_INFO more sensibly</td>
+        </tr>
+      </table>
+      
+    </div>
 </div>
 
 
index e96bbab77b2235ea61593496e0aa783e916f8cda..219f2b77d937495fcec5252e6323388c8360e842 100644 (file)
@@ -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("<p>Sorry, PATH_INFO not supported.</p>\n");
+    printf("<p>Sorry, is PATH_INFO not supported."
+           "<a href=\"%s\">Try here instead.</a></p>\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 */
index b7772829e64a293a30ec21ba8fc25ce9004527f2..e05e6bf580fd6d841314167ea84292f6649f7391 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
 #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 <a href="http://tools.ietf.org/html/rfc3875">RFC 3875</a>.
  */
-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 '/'");
index 3331456912294af9bc39299066bd06d06c7e787b..3546e77d37eabeb7b52318e77046716c85782b49 100644 (file)
--- 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 */
index dcff4bf642b86927f37b481c530edf1c90b284c9..4bc7474dfed145b82178e102cecf0c428db4f45c 100644 (file)
@@ -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");
 }