]> granicus.if.org Git - php/commitdiff
Tried to centralize global variable registration as much as possible:
authorZeev Suraski <zeev@php.net>
Fri, 28 Jan 2000 17:24:53 +0000 (17:24 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 28 Jan 2000 17:24:53 +0000 (17:24 +0000)
- Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly
  to $HTTP_GET_VARS[], contain environment and server variables.  Setting
  register_globals to Off will now also prevent registration of the
  environment and server variables into the global scope (Zeev)
- Renamed gpc_globals to register_globals (Zeev)
- Introduced variables_order that deprecates gpc_order, and allows control
  over the server and environment variables, in addition to GET/POST/Cookies
  (Zeev)

21 files changed:
Makefile.in
NEWS
ext/apache/apache.c
ext/standard/string.c
main/SAPI.h
main/main.c
main/php_globals.h
main/php_variables.c [moved from php_gpce.c with 91% similarity]
main/php_variables.h [moved from php_gpce.h with 87% similarity]
main/rfc1867.c
php.ini-dist
php4dll.dsp
php4dllts.dsp
sapi/aolserver/aolserver.c
sapi/apache/mod_php4.c
sapi/cgi/cgi_main.c
sapi/isapi/php4isapi.c
sapi/phttpd/phttpd.c
sapi/roxen/roxen.c
sapi/servlet/servlet.c
sapi/thttpd/thttpd.c

index 3dbcdcfe92b613429d58aa6db415df6367020504..bfa5dd17e3fc509b9029bef8be9a0e12a4bb5c6f 100644 (file)
@@ -14,7 +14,7 @@ LTLIBRARY_SOURCES = \
        configuration-parser.c configuration-scanner.c request_info.c \
        safe_mode.c fopen-wrappers.c php_realpath.c alloca.c \
        php_ini.c SAPI.c rfc1867.c dlist.c php_content_types.c strlcpy.c \
-       strlcat.c mergesort.c reentrancy.c php_gpce.c
+       strlcat.c mergesort.c reentrancy.c php_variables.c
 
 LTLIBRARY_DEPENDENCIES = \
                Zend/libZend.la \
diff --git a/NEWS b/NEWS
index d61ca3f6e67b6966ca574a3379df8cea6dab03c7..7c54d8f37c0cd8ec1de7cd8c668db5d9e129aa4d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,14 @@ PHP 4.0                                                                    NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 ?? ?? ????, Version 4.0 Beta 4
+- Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly
+  to $HTTP_GET_VARS[], contain environment and server variables.  Setting
+  register_globals to Off will now also prevent registration of the
+  environment and server variables into the global scope (Zeev)
+- Renamed gpc_globals to register_globals (Zeev)
+- Introduced variables_order that deprecates gpc_order, and allows control
+  over the server and environment variables, in addition to GET/POST/Cookies
+  (Zeev)
 - new function cpdf_set_document_limits() (Uwe)
 - Applied safe-mode patch to popen(). (Patch by Kristian Köhntopp)
 - str_repeat() now returns correct length. (Thies)
index f83257dfcd2e479ba33a5d4471edf66f2195ab79..ff0cb4da262edc11d03002bdf971332cd0d6ccd5 100644 (file)
@@ -416,6 +416,7 @@ PHP_FUNCTION(apache_lookup_uri)
 }
 /* }}} */
 
+
 #if 0
 This function is most likely a bad idea.  Just playing with it for now.
 
index 5b0a517eb06c41efc74749699375250619e2511a..a12a04a9a6778ae587176b840f5401a89318ce09 100644 (file)
@@ -26,7 +26,7 @@
 #include "php.h"
 #include "reg.h"
 #include "php_string.h"
-#include "php_gpce.h"
+#include "php_variables.h"
 #ifdef HAVE_LOCALE_H
 # include <locale.h>
 #endif
index d5ebcdc62fd1655d89c6fe7c40bdf3ac05ceddf9..7500b3ee201245b9f3e206dfad297e1ed38bebc6 100644 (file)
@@ -147,6 +147,8 @@ struct _sapi_module_struct {
        int (*read_post)(char *buffer, uint count_bytes SLS_DC);
        char *(*read_cookies)(SLS_D);
 
+       void (*register_server_variables)(zval *track_vars_array ELS_DC SLS_DC PLS_DC);
+
        void (*default_post_reader)(char *content_type_dup SLS_DC);
 };
 
index 0bee1125467aea1c9c05c19e824ce5c901505616..d8568e973de3c43349a5a74f248484ab797af4bb 100644 (file)
@@ -50,7 +50,7 @@
 #include "fopen-wrappers.h"
 #include "ext/standard/php_standard.h"
 #include "snprintf.h"
-#include "php_gpce.h"
+#include "php_variables.h"
 #if WIN32|WINNT
 #include <io.h>
 #include <fcntl.h>
@@ -251,8 +251,9 @@ PHP_INI_BEGIN()
 #endif
 
        STD_PHP_INI_BOOLEAN("gpc_globals",                      "1",                    PHP_INI_ALL,            OnUpdateBool,                           gpc_globals,    php_core_globals,       core_globals)
-       STD_PHP_INI_ENTRY("gpc_order",                          "GPC",                  PHP_INI_ALL,            OnUpdateStringUnempty,  gpc_order,              php_core_globals,       core_globals)
-       STD_PHP_INI_ENTRY("arg_separator",                      "&",                    PHP_INI_ALL,            OnUpdateStringUnempty,  arg_separator,  php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("gpc_order",                          "GPC",                  PHP_INI_ALL,            OnUpdateStringUnempty,  gpc_order,                      php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("variables_order",            NULL,                   PHP_INI_ALL,            OnUpdateStringUnempty,  variables_order,        php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("arg_separator",                      "&",                    PHP_INI_ALL,            OnUpdateStringUnempty,  arg_separator,          php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("ignore_user_abort",        "1",                    PHP_INI_ALL,            OnUpdateBool,                   ignore_user_abort,              php_core_globals,       core_globals)
 PHP_INI_END()
 
@@ -702,24 +703,10 @@ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
        }
 
        if (SG(request_info).auth_user) {
-               zval *auth_user;
-
-               MAKE_STD_ZVAL(auth_user);
-               auth_user->type = IS_STRING;
-               auth_user->value.str.val = SG(request_info).auth_user;
-               auth_user->value.str.len = strlen(auth_user->value.str.val);
-
-               zend_hash_update(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), &auth_user, sizeof(zval *), NULL);
+               php_register_variable(SG(request_info).auth_user, "PHP_AUTH_USER", NULL ELS_CC PLS_CC);
        }
        if (SG(request_info).auth_password) {
-               zval *auth_password;
-
-               MAKE_STD_ZVAL(auth_password);
-               auth_password->type = IS_STRING;
-               auth_password->value.str.val = SG(request_info).auth_password;
-               auth_password->value.str.len = strlen(auth_password->value.str.val);
-
-               zend_hash_update(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), &auth_password, sizeof(zval *), NULL);
+               php_register_variable(SG(request_info).auth_password, "PHP_AUTH_PW", NULL ELS_CC PLS_CC);
        }
        
        return SUCCESS;
@@ -1009,14 +996,35 @@ void php_module_shutdown()
 }
 
 
-/* in 3.1 some of this should move into sapi */
-static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
+static inline void php_register_server_variables(ELS_D SLS_DC PLS_DC)
+{
+       zval *array_ptr=NULL;
+
+       if (PG(track_vars)) {
+               ALLOC_ZVAL(array_ptr);
+               array_init(array_ptr);
+               INIT_PZVAL(array_ptr);
+               zend_hash_add(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_ENV_VARS"), &array_ptr, sizeof(pval *),NULL);
+       }
+       sapi_module.register_server_variables(array_ptr ELS_CC SLS_CC PLS_CC);
+}
+
+
+static int zend_hash_environment(ELS_D SLS_DC PLS_DC)
 {
-       char **env, *p, *t;
+       char *p;
        unsigned char _gpc_flags[3] = {0,0,0};
-       pval *tmp;
-       
-       p = PG(gpc_order);
+       zend_bool have_variables_order;
+
+       if (PG(variables_order)) {
+               p = PG(variables_order);
+               have_variables_order=1;
+       } else {
+               p = PG(gpc_order);
+               have_variables_order=0;
+               php_import_environment_variables(ELS_C PLS_CC);
+       }
+
        while(*p) {
                switch(*p++) {
                        case 'p':
@@ -1040,94 +1048,27 @@ static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
                                        _gpc_flags[2]=1;
                                }
                                break;
+                       case 'e':
+                       case 'E':
+                               if (have_variables_order) {
+                                       php_import_environment_variables(ELS_C PLS_CC);
+                               } else {
+                                       php_error(E_CORE_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead");
+                               }
+                               break;
+                       case 's':
+                       case 'S':
+                               if (sapi_module.register_server_variables) {
+                                       php_register_server_variables(ELS_C SLS_CC PLS_CC);
+                               }
+                               break;
                }
        }
 
-       
-       for (env = environ; env != NULL && *env != NULL; env++) {
-               p = strchr(*env, '=');
-               if (!p) {                               /* malformed entry? */
-                       continue;
-               }
-               t = estrndup(*env, p - *env);
-               ALLOC_ZVAL(tmp);
-               tmp->value.str.len = strlen(p + 1);
-               tmp->value.str.val = estrndup(p + 1, tmp->value.str.len);
-               tmp->type = IS_STRING;
-               INIT_PZVAL(tmp);
-               /* environmental variables never take precedence over get/post/cookie variables */
-               zend_hash_add(&EG(symbol_table), t, p - *env + 1, &tmp, sizeof(pval *), NULL);
-               efree(t);
-       }
 
-#if APACHE
-       {
-               pval **tmp_ptr;
-               register int i;
-               array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
-               table_entry *elts = (table_entry *) arr->elts;
-               int len;
-
-               for (i = 0; i < arr->nelts; i++) {
-                       len = strlen(elts[i].key);
-                       t = elts[i].key;
-                       ALLOC_ZVAL(tmp);
-                       if (elts[i].val) {
-                               tmp->value.str.len = strlen(elts[i].val);
-                               tmp->value.str.val = estrndup(elts[i].val, tmp->value.str.len);
-                       } else {
-                               tmp->value.str.len = 0;
-                               tmp->value.str.val = empty_string;
-                       }
-                       INIT_PZVAL(tmp);
-                       tmp->type = IS_STRING;
-                       zend_hash_update(&EG(symbol_table), t, strlen(t)+1, &tmp, sizeof(pval *), NULL);
-               }
-               /* insert special variables */
-               if (zend_hash_find(&EG(symbol_table), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &tmp_ptr) == SUCCESS) {
-                       (*tmp_ptr)->refcount++;
-                       zend_hash_update(&EG(symbol_table), "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), tmp_ptr, sizeof(pval *), NULL);
-               }
-               ALLOC_ZVAL(tmp);
-               tmp->value.str.len = strlen(((request_rec *) SG(server_context))->uri);
-               tmp->value.str.val = estrndup(((request_rec *) SG(server_context))->uri, tmp->value.str.len);
-               INIT_PZVAL(tmp);
-               tmp->type = IS_STRING;
-               zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) &tmp, sizeof(pval *), NULL);
+       if (!have_variables_order) {
+               php_register_server_variables(ELS_C SLS_CC PLS_CC);
        }
-#else
-       {
-               /* Build the special-case PHP_SELF variable for the CGI version */
-               char *pi;
-#if FORCE_CGI_REDIRECT
-               pi = SG(request_info).request_uri;
-               ALLOC_ZVAL(tmp);
-               tmp->value.str.val = emalloc(((pi)?strlen(pi):0) + 1);
-               tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s", (pi ? pi : ""));     /* SAFE */
-               tmp->type = IS_STRING;
-               INIT_PZVAL(tmp);
-#else
-               int l = 0;
-               char *sn;
-               sn = request_info.script_name;
-               pi = SG(request_info).request_uri;
-               if (sn)
-                       l += strlen(sn);
-               if (pi)
-                       l += strlen(pi);
-               if (pi && sn && !strcmp(pi, sn)) {
-                       l -= strlen(pi);
-                       pi = NULL;
-               }
-               ALLOC_ZVAL(tmp);
-               tmp->value.str.val = emalloc(l + 1);
-               tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s%s", (sn ? sn : ""), (pi ? pi : ""));   /* SAFE */
-               tmp->type = IS_STRING;
-               INIT_PZVAL(tmp);
-#endif
-               zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval *), NULL);
-       }
-#endif
 
 
        /* need argc/argv support as well */
@@ -1136,6 +1077,7 @@ static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
        return SUCCESS;
 }
 
+
 void _php_build_argv(char *s ELS_DC)
 {
        pval *arr, *tmp;
@@ -1193,6 +1135,7 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
        zend_file_handle prepend_file, append_file;
        SLS_FETCH();
 
+       zend_hash_environment(ELS_C SLS_CC PLS_CC);
        zend_activate_modules();
        if (SG(request_info).query_string && SG(request_info).query_string[0]=='=' 
                && PG(expose_php)) {
@@ -1240,7 +1183,6 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
        }       
        EG(main_op_array) = zend_compile_files(0 CLS_CC, 3, prepend_file_p, primary_file, append_file_p);
        if (EG(main_op_array)) {
-               zend_hash_environment(PLS_C ELS_CC SLS_CC);
                EG(active_op_array) = EG(main_op_array);
                zend_execute(EG(main_op_array) ELS_CC);
        }
index 809b36ae53b30b06d833705fab5d00c8fa331229..8bb5792c825dfee6fb27caab2a845e79997d2fa7 100644 (file)
@@ -81,6 +81,7 @@ struct _php_core_globals {
 
        char *arg_separator;
        char *gpc_order;
+       char *variables_order;
 
        zend_bool expose_php;
 
similarity index 91%
rename from php_gpce.c
rename to main/php_variables.c
index d481c40858e7601548918c75950196e439180ecf..b4355b4ee8560bf22de7c9c077f46aafffdc2231 100644 (file)
 #include <stdio.h>
 #include "php.h"
 #include "ext/standard/php_standard.h"
-#include "php_gpce.h"
+#include "php_variables.h"
 #include "php_globals.h"
 #include "SAPI.h"
 
 #include "zend_globals.h"
 
 
-void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC)
+PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC)
 {
        char *p = NULL;
        char *ip;               /* index pointer */
@@ -265,7 +265,7 @@ void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
                                /* FIXME: XXX: not binary safe, discards returned length */
                                php_url_decode(var, strlen(var));
                                php_url_decode(val, strlen(val));
-                               php_register_variable(val,var,array_ptr ELS_CC PLS_CC);
+                               php_register_variable(val, var, array_ptr ELS_CC PLS_CC);
                        }
                        if (arg == PARSE_COOKIE) {
                                var = strtok_r(NULL, ";", &strtok_buf);
@@ -284,6 +284,31 @@ void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
 }
 
 
+
+void php_import_environment_variables(ELS_D PLS_DC)
+{
+       char **env, *p, *t;
+       zval *array_ptr=NULL;
+
+       if (PG(track_vars)) {
+               ALLOC_ZVAL(array_ptr);
+               array_init(array_ptr);
+               INIT_PZVAL(array_ptr);
+               zend_hash_add(&EG(symbol_table), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), &array_ptr, sizeof(pval *),NULL);
+       }
+
+       for (env = environ; env != NULL && *env != NULL; env++) {
+               p = strchr(*env, '=');
+               if (!p) {                               /* malformed entry? */
+                       continue;
+               }
+               t = estrndup(*env, p - *env);
+               php_register_variable(p+1, t, array_ptr ELS_CC PLS_CC);
+               efree(t);
+       }
+}
+
+
 /*
  * Local variables:
  * tab-width: 4
similarity index 87%
rename from php_gpce.h
rename to main/php_variables.h
index b8dca449ab22d9c42238b8deca680a2393beeeca..826f77dc7600c247735f36e347f32b05979cdec6 100644 (file)
    | contact core@php.net.                                                |
    +----------------------------------------------------------------------+
    | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
+   |          Zeev Suraski <zeev@zend.com>                                |
    +----------------------------------------------------------------------+
  */
 /* $Id$ */
 
-#ifndef _POST_H
-#define _POST_H
+#ifndef _PHP_VARIABLES_H
+#define _PHP_VARIABLES_H
 
+#include "php.h"
 #include "SAPI.h"
 
 #define PARSE_POST 0
@@ -39,6 +41,7 @@
 #define PARSE_STRING 3
 
 void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC);
-void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC);
+void php_import_environment_variables(ELS_D PLS_DC);
+PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC);
 
-#endif
+#endif /* _PHP_VARIABLES_H */
index f4337c3f8ba2a9a7a4107ca92c493cb1647f9727..e418fe0606007993f59a5bcbe9555b6b2bd88f0c 100644 (file)
@@ -23,7 +23,7 @@
 #include "ext/standard/file.h" /* for php_file_le_uploads() */
 #include "zend_globals.h"
 #include "php_globals.h"
-#include "php_gpce.h"
+#include "php_variables.h"
 #include "rfc1867.h"
 
 
index d3d4aae294bbad87321eb9122c623ac8ed445473..4714a1bb917ad8d79320b39f34160ef77fd7eeac 100644 (file)
@@ -135,16 +135,20 @@ warn_plus_overloading     =       Off             ; warn if the + operator is used with strings
 ;;;;;;;;;;;;;;;;;
 ; Data Handling ;
 ;;;;;;;;;;;;;;;;;
-gpc_order                      =       "GPC"   ; Order of evaluation of GET/POST/Cookie data.  Later values override
-                                                               ; earlier values (e.g., by default, POST variables override GET variables,
-                                                               ; and Cookie variables override both POST and GET variables).
-gpc_globals                    =       On              ; Whether or not to define GET/POST/Cookie variables in the global
-                                                               ; scope.  You may want to turn this off if you don't want
+variables_order                =       "EGPCB" ; This directive describes the order in which PHP registers
+                                                               ; GET, POST, Cookie, Environment and Built-in variables (G, P,
+                                                               ; C, E & B respectively, often referred to as EGPCB or GPC).
+                                                               ; Registration is done from left to right, newer values override
+                                                               ; older values.
+register_globals       =       On              ; Whether or not to register the EGPCB variables as global
+                                                               ; variables.  You may want to turn this off if you don't want
                                                                ; to clutter your scripts' global scope with user data.  This makes
                                                                ; most sense when coupled with track_vars - in which case you can
-                                                               ; access all of the GPC variables through the $HTTP_GET_VARS[],
-                                                               ; $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] variables.
-track_vars                     =       On              ; enable $HTTP_GET_VARS[], $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] arrays
+                                                               ; access all of the GPC variables through the $HTTP_*_VARS[],
+                                                               ; variables.
+track_vars                     =       On              ; enable the $HTTP_*_VARS[] arrays, where * is one of
+                                                               ; ENV, POST, GET, COOKIE or SERVER.
+gpc_order                      =       "GPC"   ; This directive is deprecated.  Use variables_order instead.
 
 ; Magic quotes
 magic_quotes_gpc       =       On              ; magic quotes for incoming GET/POST/Cookie data
index 1e4a084a993ec6aa030dc6c83e6470d7708aee08..81fd417b9a5c3bf93a4a587698205b9543b491e3 100644 (file)
@@ -164,7 +164,7 @@ SOURCE=.\php_content_types.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_gpce.c\r
+SOURCE=.\php_variables.c\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -264,7 +264,7 @@ SOURCE=.\php_globals.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_gpce.h\r
+SOURCE=.\php_variables.h\r
 # End Source File\r
 # Begin Source File\r
 \r
index f527312a3c4712e730ba0a2bb0cdd5b1a49a4f62..dca871e0320184bfc89c3b99d01b56699a7eb88f 100644 (file)
@@ -160,15 +160,15 @@ SOURCE=.\php_content_types.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_gpce.c\r
+SOURCE=.\php_ini.c\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_ini.c\r
+SOURCE=.\php_realpath.c\r
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_realpath.c\r
+SOURCE=.\php_variables.c\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -260,10 +260,6 @@ SOURCE=.\php_globals.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\php_gpce.h\r
-# End Source File\r
-# Begin Source File\r
-\r
 SOURCE=.\php_ini.h\r
 # End Source File\r
 # Begin Source File\r
@@ -276,6 +272,10 @@ SOURCE=.\php_regex.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\php_variables.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\ext\standard\quot_print.h\r
 # End Source File\r
 # Begin Source File\r
index 2491c31f2d778e996b64a5fda3a3fe333c415a73..5b1af17ec75e1d639186f747f8b77e33c3d6669c 100644 (file)
@@ -308,6 +308,8 @@ static sapi_module_struct sapi_module = {
        php_ns_sapi_read_post,                                  /* read POST data */
        php_ns_sapi_read_cookies,                               /* read Cookies */
 
+       NULL,                                                                   /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index 0f89fb241f3e5fe531b6629d66630c1d6a0ea5c1..6303d7dd831424cbd388e055def2ec22c1579594 100644 (file)
@@ -222,6 +222,39 @@ int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
 }
 
 
+static void sapi_apache_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+       pval **tmp_ptr;
+       register int i;
+       array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
+       table_entry *elts = (table_entry *) arr->elts;
+       int len;
+       char *script_filename=NULL;
+       ELS_FETCH();
+       PLS_FETCH();
+
+       for (i = 0; i < arr->nelts; i++) {
+               char *val;
+
+               if (elts[i].val) {
+                       val = elts[i].val;
+                       if (!strcmp(val, "SCRIPT_FILENAME")) {
+                               script_filename = val;
+                       }
+               } else {
+                       val = empty_string;
+               }
+               php_register_variable(val, elts[i].key, NULL ELS_CC PLS_CC);
+       }
+
+       /* insert special variables */
+       if (script_filename) {
+               php_register_variable(script_filename, "PATH_TRANSLATED", NULL ELS_CC PLS_CC);
+       }
+       php_register_variable(SG(server_context)->uri, "PHP_SELF", NULL ELS_CC PLS_CC);
+}
+*
+
 static sapi_module_struct sapi_module = {
        "Apache",                                               /* name */
                                                                        
@@ -241,6 +274,8 @@ static sapi_module_struct sapi_module = {
        sapi_apache_read_post,                  /* read POST data */
        sapi_apache_read_cookies,               /* read Cookies */
 
+       sapi_apache_register_server_variables,          /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index 538861faabeadc989d9de30ea6f530e479ef97e0..4ed0442c43fadbd82bd33ff2b1e8db810f60cdbf 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "php.h"
 #include "php_globals.h"
+#include "php_variables.h"
 
 #include "SAPI.h"
 
@@ -126,6 +127,37 @@ static char *sapi_cgi_read_cookies(SLS_D)
 }
 
 
+static void sapi_cgi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+       char *pi;
+
+       /* Build the special-case PHP_SELF variable for the CGI version */
+#if FORCE_CGI_REDIRECT
+       php_register_variable((SG(request_info).request_uri ? SG(request_info).request_uri, "PHP_SELF", track_vars_array ELS_CC PLS_CC);
+#else
+       {
+               char *sn;
+               char *val;
+               int l=0;
+
+               sn = request_info.script_name;
+               pi = SG(request_info).request_uri;
+               if (sn)
+                       l += strlen(sn);
+               if (pi)
+                       l += strlen(pi);
+               if (pi && sn && !strcmp(pi, sn)) {
+                       l -= strlen(pi);
+                       pi = NULL;
+               }
+               val = emalloc(l + 1);
+               php_sprintf(val, "%s%s", (sn ? sn : ""), (pi ? pi : ""));       /* SAFE */
+               php_register_variable(val, "PHP_SELF", track_vars_array ELS_CC PLS_CC);
+       }
+#endif
+}
+
+
 static sapi_module_struct sapi_module = {
        "CGI",                                                  /* name */
                                                                        
@@ -144,6 +176,8 @@ static sapi_module_struct sapi_module = {
        sapi_cgi_read_post,                             /* read POST data */
        sapi_cgi_read_cookies,                  /* read Cookies */
 
+       sapi_cgi_register_variables,    /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index f85b181d485718916ad43b8c8faae41b6d9ecbf3..151a331601256d744b40e3feb10da9fb00148b4f 100644 (file)
@@ -28,6 +28,7 @@
 #include "SAPI.h"
 #include "php_globals.h"
 #include "ext/standard/info.h"
+#include "php_variables.h"
 
 #ifdef WITH_ZEUS
 #include "zeus.h"
@@ -290,6 +291,54 @@ static char *sapi_isapi_read_cookies(SLS_D)
 }
 
 
+static void sapi_isapi_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+       char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
+       char *variable_buf;
+       DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
+       char *variable;
+       char *strtok_buf = NULL;
+       LPEXTENSION_CONTROL_BLOCK lpECB;
+
+       lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
+
+       if (lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len)) {
+               variable_buf = static_variable_buf;
+       } else {
+               if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
+                       variable_buf = (char *) emalloc(variable_len);
+                       if (!lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) {
+                               efree(variable_buf);
+                               return;
+                       }
+               } else {
+                       return;
+               }
+       }
+       variable = strtok_r(variable_buf, "\r\n", &strtok_buf);
+       while (variable) {
+               char *colon = strchr(variable, ':');
+
+               if (colon) {
+                       char *value = colon+1;
+                       zval *entry;
+
+                       ALLOC_ZVAL(entry);
+                       while (*value==' ') {
+                               value++;
+                       }
+                       *colon = 0;
+                       php_register_variable(value, variable, track_vars_array ELS_CC PLS_CC);
+                       *colon = ':';
+               }
+               variable = strtok_r(NULL, "\r\n", &strtok_buf);
+       }
+       if (variable_buf!=static_variable_buf) {
+               efree(variable_buf);
+       }
+}
+
+
 static sapi_module_struct sapi_module = {
        "ISAPI",                                                /* name */
                                                                        
@@ -308,6 +357,8 @@ static sapi_module_struct sapi_module = {
        sapi_isapi_read_post,                   /* read POST data */
        sapi_isapi_read_cookies,                /* read Cookies */
 
+       sapi_isapi_register_server_variables,   /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
@@ -378,58 +429,6 @@ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
 }
 
 
-static void hash_isapi_variables(ELS_D SLS_DC)
-{
-       char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
-       char *variable_buf;
-       DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
-       char *variable;
-       char *strtok_buf = NULL;
-       LPEXTENSION_CONTROL_BLOCK lpECB;
-
-       lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
-
-       if (lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len)) {
-               variable_buf = static_variable_buf;
-       } else {
-               if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
-                       variable_buf = (char *) emalloc(variable_len);
-                       if (!lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) {
-                               efree(variable_buf);
-                               return;
-                       }
-               } else {
-                       return;
-               }
-       }
-       variable = strtok_r(variable_buf, "\r\n", &strtok_buf);
-       while (variable) {
-               char *colon = strchr(variable, ':');
-
-               if (colon) {
-                       char *value = colon+1;
-                       zval *entry;
-
-                       ALLOC_ZVAL(entry);
-                       while (*value==' ') {
-                               value++;
-                       }
-                       *colon = 0;
-                       INIT_PZVAL(entry);
-                       entry->value.str.len = strlen(value);
-                       entry->value.str.val = estrndup(value, entry->value.str.len);
-                       entry->type = IS_STRING;
-                       zend_hash_add(&EG(symbol_table), variable, strlen(variable)+1, &entry, sizeof(zval *), NULL);
-                       *colon = ':';
-               }
-               variable = strtok_r(NULL, "\r\n", &strtok_buf);
-       }
-       if (variable_buf!=static_variable_buf) {
-               efree(variable_buf);
-       }
-}
-
-
 DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
 {
        zend_file_handle file_handle;
@@ -450,7 +449,6 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
        file_handle.type = ZEND_HANDLE_FILENAME;
 
        php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC);
-       hash_isapi_variables(ELS_C SLS_CC);
        php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
        if (SG(request_info).cookie_data) {
                efree(SG(request_info).cookie_data);
index 5906e16fafd9291ebcc09bfa30964198e3ea102b..62e3edc0c86281b88e8e9c1e8933de5282a02b77 100644 (file)
@@ -179,6 +179,8 @@ static sapi_module_struct sapi_module = {
     php_phttpd_sapi_read_post,              /* read POST data */
     php_phttpd_sapi_read_cookies,           /* read Cookies */
  
+       NULL,                                                                   /* register server variables */
+
     STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index d9c588fa966deb22994f32d703de406d79c9c7d2..a17cf5a3e66d541970f6643c3460ee96ed759dca 100644 (file)
@@ -533,6 +533,9 @@ static sapi_module_struct sapi_module = {
   php_roxen_sapi_read_post,                                    /* read POST data */
   php_roxen_sapi_read_cookies,                         /* read Cookies */
 
+  NULL,                                                                                /* register server variables */
+
+
   STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index 0682dc0578878ce9918da1c1fb4041c74ca75d64..d16e3f8ab13e1cdb2e9e17baadc06158ceae17eb 100644 (file)
@@ -227,6 +227,8 @@ static sapi_module_struct sapi_module = {
        sapi_servlet_read_post,                 /* read POST data */
        sapi_servlet_read_cookies,              /* read Cookies */
 
+       NULL,                                                   /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
index fed6c578bd2fc7707b37bba17f387d2469203b8e..81726c2205937562bb9b7e682e362a9159bcf0a1 100644 (file)
@@ -118,6 +118,8 @@ static sapi_module_struct sapi_module = {
        sapi_thttpd_read_post,
        sapi_thttpd_read_cookies,
 
+       NULL,                                                   /* register server variables */
+
        STANDARD_SAPI_MODULE_PROPERTIES
 };