diff options
| author | Zeev Suraski <zeev@php.net> | 2000-01-28 17:24:53 +0000 |
|---|---|---|
| committer | Zeev Suraski <zeev@php.net> | 2000-01-28 17:24:53 +0000 |
| commit | 9ab35ae39367bcd30037c6bfc73ae0c77c35d872 (patch) | |
| tree | 0159d87ae935d13e9b82961442d741ce9360b439 /sapi | |
| parent | 270eff1dfee55220c009cd1a546901339f657b94 (diff) | |
| download | php-git-9ab35ae39367bcd30037c6bfc73ae0c77c35d872.tar.gz | |
Tried to centralize global variable registration as much as possible:
- 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)
Diffstat (limited to 'sapi')
| -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 |
8 files changed, 131 insertions, 53 deletions
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 }; |
