]> granicus.if.org Git - apache/commitdiff
mod_ext_filter: Set up environment variables for external programs.
authorJeff Trawick <trawick@apache.org>
Thu, 18 Jul 2002 12:25:24 +0000 (12:25 +0000)
committerJeff Trawick <trawick@apache.org>
Thu, 18 Jul 2002 12:25:24 +0000 (12:25 +0000)
Submitted by:              Craig Sebenik <craig@netapp.com>
Reviewed by:               Jeff Trawick

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96111 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/mod_ext_filter.html.en
docs/manual/mod/mod_ext_filter.xml
modules/experimental/mod_ext_filter.c

diff --git a/CHANGES b/CHANGES
index dcdb1ecad96b552450847e35819196ab0457a701..06cb6cb8fa6f6e5dd70783fbba618ac63c0a17bf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.40
 
+  *) mod_ext_filter: Set up environment variables for external programs.
+     [Craig Sebenik <craig@netapp.com>]
+
   *) Modified the HTTP_IN filter to immediately append the EOS (end of
      stream) bucket for C-L POST bodies, saving a roundtrip and allowing
      the caller to determine that no content remains without prefetching
index ebf0d1bb7eeeafe2ad2e09d019c913fc5bf7ca3d..3f6f552d78f534c6dd7bcd76dbf8ee1b267b56d4 100644 (file)
       program name, the command line should be surrounded in
       quotation marks (e.g., <em>cmd="/bin/mypgm arg1 arg2"</em>.
       Normal shell quoting is not necessary since the program is
-      run directly, bypassing the shell.</dd>
+      run directly, bypassing the shell.  In addition to the 
+      standard CGI environment variables, DOCUMENT_URI,
+      DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set
+      for the program.</dd>
 
       <dt>mode=<em>mode</em></dt>
 
index 0899a298133a6b3f79e636413955eeace272a620..de26a303199be3116fff9f573e9da14f6008c28f 100644 (file)
       program name, the command line should be surrounded in
       quotation marks (e.g., <em>cmd="/bin/mypgm arg1 arg2"</em>.
       Normal shell quoting is not necessary since the program is
-      run directly, bypassing the shell.</dd>
+      run directly, bypassing the shell.  In addition to the 
+      standard CGI environment variables, DOCUMENT_URI,
+      DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set
+      for the program.</dd>
 
       <dt>mode=<em>mode</em></dt>
 
index 37fa4137b1bfcf5d839e933ba5bc146dad1a1d2e..0ce3832c798a54288749c3d8d4e7371e9a2c4704 100644 (file)
@@ -68,6 +68,7 @@
 #include "http_core.h"
 #include "apr_buckets.h"
 #include "util_filter.h"
+#include "util_script.h"
 #include "apr_strings.h"
 #include "apr_hash.h"
 #include "apr_lib.h"
@@ -395,6 +396,7 @@ static apr_status_t init_ext_filter_process(ap_filter_t *f)
     ef_ctx_t *ctx = f->ctx;
     apr_status_t rc;
     ef_dir_t *dc = ctx->dc;
+    const char * const *env;
 
     ctx->proc = apr_pcalloc(ctx->p, sizeof(*ctx->proc));
 
@@ -416,11 +418,28 @@ static apr_status_t init_ext_filter_process(ap_filter_t *f)
                                       NULL);
         ap_assert(rc == APR_SUCCESS);
     }
-                                  
+
+    /* add standard CGI variables as well as DOCUMENT_URI, DOCUMENT_PATH_INFO,
+     * and QUERY_STRING_UNESCAPED
+     */
+    ap_add_cgi_vars(f->r);
+    apr_table_setn(f->r->subprocess_env, "DOCUMENT_URI", f->r->uri);
+    apr_table_setn(f->r->subprocess_env, "DOCUMENT_PATH_INFO", f->r->path_info);
+    if (f->r->args) {
+            /* QUERY_STRING is added by ap_add_cgi_vars */
+        char *arg_copy = apr_pstrdup(f->r->pool, f->r->args);
+        ap_unescape_url(arg_copy);
+        apr_table_setn(f->r->subprocess_env, "QUERY_STRING_UNESCAPED",
+                       ap_escape_shell_cmd(f->r->pool, arg_copy));
+    }
+
+    env = (const char * const *) ap_create_environment(ctx->p,
+                                                       f->r->subprocess_env);
+
     rc = apr_proc_create(ctx->proc, 
                             ctx->filter->command, 
                             (const char * const *)ctx->filter->args, 
-                            NULL, /* environment */
+                            env, /* environment */
                             ctx->procattr, 
                             ctx->p);
     if (rc != APR_SUCCESS) {