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 6dd53be..d19afe7 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 e96bbab..219f2b7 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 b777282..e05e6bf 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 3331456..3546e77 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 dcff4bf..4bc7474 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");
 }