diff options
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | ext/apache/apache.c | 1 | ||||
-rw-r--r-- | ext/standard/string.c | 2 | ||||
-rw-r--r-- | main/SAPI.h | 2 | ||||
-rw-r--r-- | main/main.c | 160 | ||||
-rw-r--r-- | main/php_globals.h | 1 | ||||
-rw-r--r-- | main/php_variables.c (renamed from php_gpce.c) | 31 | ||||
-rw-r--r-- | main/php_variables.h (renamed from php_gpce.h) | 11 | ||||
-rw-r--r-- | main/rfc1867.c | 2 | ||||
-rw-r--r-- | php.ini-dist | 20 | ||||
-rw-r--r-- | php4dll.dsp | 4 | ||||
-rw-r--r-- | php4dllts.dsp | 14 | ||||
-rw-r--r-- | sapi/aolserver/aolserver.c | 2 | ||||
-rw-r--r-- | sapi/apache/mod_php4.c | 35 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 34 | ||||
-rw-r--r-- | sapi/isapi/php4isapi.c | 104 | ||||
-rw-r--r-- | sapi/phttpd/phttpd.c | 2 | ||||
-rw-r--r-- | sapi/roxen/roxen.c | 3 | ||||
-rw-r--r-- | sapi/servlet/servlet.c | 2 | ||||
-rw-r--r-- | sapi/thttpd/thttpd.c | 2 |
21 files changed, 253 insertions, 189 deletions
diff --git a/Makefile.in b/Makefile.in index 3dbcdcfe92..bfa5dd17e3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ @@ -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) diff --git a/ext/apache/apache.c b/ext/apache/apache.c index f83257dfcd..ff0cb4da26 100644 --- a/ext/apache/apache.c +++ b/ext/apache/apache.c @@ -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. diff --git a/ext/standard/string.c b/ext/standard/string.c index 5b0a517eb0..a12a04a9a6 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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 diff --git a/main/SAPI.h b/main/SAPI.h index d5ebcdc62f..7500b3ee20 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -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); }; diff --git a/main/main.c b/main/main.c index 0bee112546..d8568e973d 100644 --- a/main/main.c +++ b/main/main.c @@ -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); } diff --git a/main/php_globals.h b/main/php_globals.h index 809b36ae53..8bb5792c82 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -81,6 +81,7 @@ struct _php_core_globals { char *arg_separator; char *gpc_order; + char *variables_order; zend_bool expose_php; diff --git a/php_gpce.c b/main/php_variables.c index d481c40858..b4355b4ee8 100644 --- a/php_gpce.c +++ b/main/php_variables.c @@ -21,14 +21,14 @@ #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 diff --git a/php_gpce.h b/main/php_variables.h index b8dca449ab..826f77dc76 100644 --- a/php_gpce.h +++ b/main/php_variables.h @@ -24,13 +24,15 @@ | 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 */ diff --git a/main/rfc1867.c b/main/rfc1867.c index f4337c3f8b..e418fe0606 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -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" diff --git a/php.ini-dist b/php.ini-dist index d3d4aae294..4714a1bb91 100644 --- a/php.ini-dist +++ b/php.ini-dist @@ -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 diff --git a/php4dll.dsp b/php4dll.dsp index 1e4a084a99..81fd417b9a 100644 --- a/php4dll.dsp +++ b/php4dll.dsp @@ -164,7 +164,7 @@ SOURCE=.\php_content_types.c # End Source File
# Begin Source File
-SOURCE=.\php_gpce.c
+SOURCE=.\php_variables.c
# End Source File
# Begin Source File
@@ -264,7 +264,7 @@ SOURCE=.\php_globals.h # End Source File
# Begin Source File
-SOURCE=.\php_gpce.h
+SOURCE=.\php_variables.h
# End Source File
# Begin Source File
diff --git a/php4dllts.dsp b/php4dllts.dsp index f527312a3c..dca871e032 100644 --- a/php4dllts.dsp +++ b/php4dllts.dsp @@ -160,15 +160,15 @@ SOURCE=.\php_content_types.c # End Source File
# Begin Source File
-SOURCE=.\php_gpce.c
+SOURCE=.\php_ini.c
# End Source File
# Begin Source File
-SOURCE=.\php_ini.c
+SOURCE=.\php_realpath.c
# End Source File
# Begin Source File
-SOURCE=.\php_realpath.c
+SOURCE=.\php_variables.c
# End Source File
# Begin Source File
@@ -260,10 +260,6 @@ SOURCE=.\php_globals.h # End Source File
# Begin Source File
-SOURCE=.\php_gpce.h
-# End Source File
-# Begin Source File
-
SOURCE=.\php_ini.h
# End Source File
# Begin Source File
@@ -276,6 +272,10 @@ SOURCE=.\php_regex.h # End Source File
# Begin Source File
+SOURCE=.\php_variables.h
+# End Source File
+# Begin Source File
+
SOURCE=.\ext\standard\quot_print.h
# End Source File
# Begin Source File
diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c index 2491c31f2d..5b1af17ec7 100644 --- a/sapi/aolserver/aolserver.c +++ b/sapi/aolserver/aolserver.c @@ -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 }; diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c index 0f89fb241f..6303d7dd83 100644 --- a/sapi/apache/mod_php4.c +++ b/sapi/apache/mod_php4.c @@ -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 }; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 538861faab..4ed0442c43 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -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 }; diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index f85b181d48..151a331601 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -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); diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c index 5906e16faf..62e3edc0c8 100644 --- a/sapi/phttpd/phttpd.c +++ b/sapi/phttpd/phttpd.c @@ -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 }; diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c index d9c588fa96..a17cf5a3e6 100644 --- a/sapi/roxen/roxen.c +++ b/sapi/roxen/roxen.c @@ -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 }; diff --git a/sapi/servlet/servlet.c b/sapi/servlet/servlet.c index 0682dc0578..d16e3f8ab1 100644 --- a/sapi/servlet/servlet.c +++ b/sapi/servlet/servlet.c @@ -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 }; diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c index fed6c578bd..81726c2205 100644 --- a/sapi/thttpd/thttpd.c +++ b/sapi/thttpd/thttpd.c @@ -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 }; |