httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject Fix for SCRIPT_NAME/PATH_INFO problem
Date Mon, 05 Aug 1996 22:45:15 GMT
Here's a patch that should fix, to everyone's satisfaction, the problem
we've had with SCRIPT_NAME and PATH_INFO, when r->path_info doesn't match
the end of r->uri. This patch should always generate a PATH_INFO where
possible (something Ralf's patch didn't do), so the user is guaranteed of
being able to mess with PATH_INFO at least by tacking something on to the
end of the URL. Also, it ensures that
http://$SERVER_NAME:$SERVER_PORT/$SCRIPT_NAME/$PATH_INFO?$QUERY_STRING
will call the script again, with the same arguments (which a lot of
scripts - at least the ones that I write - depend on).

PATH_TRANSLATED is still made directly from r->path_info, not from the
new, improved, PATH_INFO. This is so you can rewrite (using mod_rewrite,
or even just place ScriptAlias) into r->path_info and have it work as
expected.

+1, anyone?

Here's the patch:

Index: util_script.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.c,v
retrieving revision 1.16
diff -c -r1.16 util_script.c
*** util_script.c	1996/08/02 20:39:16	1.16
--- util_script.c	1996/08/05 22:41:14
***************
*** 192,197 ****
--- 192,214 ----
      }
  }
  
+ /* This "cute" little function comes about because the path info on
+  * filenames and URLs aren't always the same. So we take the two,
+  * and find as much of the two that match as possible.
+  */
+ 
+ static int find_path_info (char *uri, char *path_info)
+ {
+     int lu = strlen(uri);
+     int lp = strlen(path_info);
+ 
+     while (lu-- && lp-- && uri[lu] == path_info[lp]);
+ 
+     while (uri[lu] != '\0' && uri[lu] != '/')
+ 	lu++;
+ 
+     return lu;
+ }
  
  void add_cgi_vars(request_rec *r)
  {
***************
*** 211,221 ****
      if (!r->path_info || !*r->path_info || !strcmp (r->protocol, "INCLUDED")) {
          table_set (e, "SCRIPT_NAME", r->uri);
      } else {
!         int path_info_start = strlen (r->uri) - strlen (r->path_info);
! 	
! 	r->uri[path_info_start] = '\0';
! 	table_set (e, "SCRIPT_NAME", r->uri);
! 	r->uri[path_info_start] = '/';
      }
  	
      if (r->path_info && r->path_info[0]) {
--- 228,238 ----
      if (!r->path_info || !*r->path_info || !strcmp (r->protocol, "INCLUDED")) {
          table_set (e, "SCRIPT_NAME", r->uri);
      } else {
! 	int path_info_start = find_path_info (r->uri, r->path_info);
! 
! 	table_set (e, "SCRIPT_NAME", pstrndup(r->pool, r->uri,
! 					      path_info_start));
! 	table_set (e, "PATH_INFO", r->uri + path_info_start);
      }
  	
      if (r->path_info && r->path_info[0]) {
***************
*** 227,234 ****
  	request_rec *pa_req = sub_req_lookup_uri(
  				    escape_uri(r->pool, r->path_info), r);
        
-         table_set (e, "PATH_INFO", r->path_info);
- 
  	/* Don't bother destroying pa_req --- it's only created in
  	 * child processes which are about to jettison their address
  	 * space anyway.  BTW, we concatenate filename and path_info
--- 244,249 ----


-- Alexei Kosut <akosut@organic.com>            The Apache HTTP Server 
   http://www.nueva.pvt.k12.ca.us/~akosut/      http://www.apache.org/


Mime
View raw message