You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Nathan Schrenk <ns...@neog.com> on 1996/02/19 23:24:27 UTC

Here's a patch fixing some SSI variable problems

From: nschrenk@neog.com (Nathan Schrenk)
Subject: Server side include variables fix
Affects: mod_include.c, mod_cgi.c, util_script.h, util_script.c
ChangeLog: CGI variables are now available to server side include directives
           as well as the QUERY_STRING_UNESCAPED variable, as required by
           the NCSA server side include documentation.  Without this patch,
           Apache does not put any of the CGI variables in the SSI 
           environment.
Comments: This patch moves add_cgi_vars() from mod_cgi.c into util_script.c
          so that it becomes available to mod_include.c 

*** mod_include.c.orig	Mon Feb 19 14:24:59 1996
--- mod_include.c	Mon Feb 19 15:19:23 1996
***************
*** 97,102 ****
--- 97,107 ----
          table_set (e, "DOCUMENT_NAME", ++t);
      else
          table_set (e, "DOCUMENT_NAME", r->uri);
+     if (r->args) {
+         unescape_url (r->args);
+ 	  table_set (e, "QUERY_STRING_UNESCAPED",
+ 		   escape_shell_cmd (r->pool, r->args));
+     }
  }
  
  #define GET_CHAR(f,c,r) \
***************
*** 818,823 ****
--- 823,829 ----
  	r->finfo.st_mtime= r->main->finfo.st_mtime;
      } else { 
  	add_common_vars (r);
+ 	add_cgi_vars(r);
  	add_include_vars (r, DEFAULT_TIME_FORMAT);
      }
      
*** mod_cgi.c.orig	Mon Feb 19 14:25:55 1996
--- mod_cgi.c	Mon Feb 19 14:55:59 1996
***************
*** 91,145 ****
   * Actual CGI handling...
   */
  
- void add_cgi_vars(request_rec *r)
- {
-     table *e = r->subprocess_env;
- 
-     table_set (e, "GATEWAY_INTERFACE","CGI/1.1");
-     table_set (e, "SERVER_PROTOCOL", r->protocol);
-     table_set (e, "REQUEST_METHOD", r->method);
-     table_set (e, "QUERY_STRING", r->args ? r->args : "");
-     
-     /* Note that the code below special-cases scripts run from includes,
-      * because it "knows" that the sub_request has been hacked to have the
-      * args and path_info of the original request, and not any that may have
-      * come with the script URI in the include command.  Ugh.
-      */
-     
-     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]) {
- 	/*
-  	 * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
- 	 * Need to re-escape it for this, since the entire URI was
- 	 * un-escaped before we determined where the PATH_INFO began.
-  	 */
- 	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
- 	 * from the sub_request to be compatible in case the PATH_INFO
- 	 * is pointing to an object which doesn't exist.
- 	 */
- 	
- 	if (pa_req->filename)
- 	    table_set (e, "PATH_TRANSLATED",
- 		       pstrcat (r->pool, pa_req->filename, pa_req->path_info,
- 				NULL));
-     }
- }
  
  struct cgi_child_stuff {
      request_rec *r;
--- 91,96 ----
*** util_script.h.orig	Mon Feb 19 14:25:32 1996
--- util_script.h	Mon Feb 19 14:57:34 1996
***************
*** 54,59 ****
--- 54,60 ----
  
  char **create_argv(pool *p, char *av0, char *args);
  char **create_environment(pool *p, table *t);
+ void add_cgi_vars(request_rec *r);
  void add_common_vars(request_rec *r);
  int scan_script_header(request_rec *r, FILE *f);
  void send_size(size_t size, request_rec *r);
*** util_script.c.orig	Mon Feb 19 14:25:15 1996
--- util_script.c	Mon Feb 19 15:20:55 1996
***************
*** 58,63 ****
--- 58,64 ----
  #include "http_log.h"
  #include "http_protocol.h"
  #include "http_core.h"		/* For document_root.  Sigh... */
+ #include "http_request.h"       /* for sub_req_lookup_uri() */
  #include "util_script.h"
  
  /*
***************
*** 178,183 ****
--- 179,235 ----
      if (r->prev) {
          if (r->prev->args) table_set(e,"REDIRECT_QUERY_STRING", r->prev->args);
  	if (r->prev->uri) table_set (e, "REDIRECT_URL", r->prev->uri);
+     }
+ }
+ 
+ 
+ void add_cgi_vars(request_rec *r)
+ {
+     table *e = r->subprocess_env;
+ 
+     table_set (e, "GATEWAY_INTERFACE","CGI/1.1");
+     table_set (e, "SERVER_PROTOCOL", r->protocol);
+     table_set (e, "REQUEST_METHOD", r->method);
+     table_set (e, "QUERY_STRING", r->args ? r->args : "");
+     
+     /* Note that the code below special-cases scripts run from includes,
+      * because it "knows" that the sub_request has been hacked to have the
+      * args and path_info of the original request, and not any that may have
+      * come with the script URI in the include command.  Ugh.
+      */
+     
+     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]) {
+ 	/*
+  	 * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
+ 	 * Need to re-escape it for this, since the entire URI was
+ 	 * un-escaped before we determined where the PATH_INFO began.
+  	 */
+ 	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
+ 	 * from the sub_request to be compatible in case the PATH_INFO
+ 	 * is pointing to an object which doesn't exist.
+ 	 */
+ 	
+ 	if (pa_req->filename)
+ 	    table_set (e, "PATH_TRANSLATED",
+ 		       pstrcat (r->pool, pa_req->filename, pa_req->path_info,
+ 				NULL));
      }
  }