diff options
author | Zeev Suraski <zeev@php.net> | 2001-01-02 22:49:31 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 2001-01-02 22:49:31 +0000 |
commit | bd0ac7fe14b6f2eb82a2e13a38c3eca5d4fe2e4f (patch) | |
tree | ff521b5242f3800f3495220bfdf51f9cf35bbe20 /sapi/isapi/php4isapi.c | |
parent | 348f6c609c148c2c1f17669dad521fe04cd50a2a (diff) | |
download | php-git-bd0ac7fe14b6f2eb82a2e13a38c3eca5d4fe2e4f.tar.gz |
Many patches. I hope I remember them all:
- Make sapi_module available to external modules (PHPAPI)
- Make the php.ini path reported in phpinfo() always point to
real full path of the php.ini file
- Optimized the ISAPI module not to read unnecessary server
variables and read necessary variables at most once.
Diffstat (limited to 'sapi/isapi/php4isapi.c')
-rw-r--r-- | sapi/isapi/php4isapi.c | 258 |
1 files changed, 154 insertions, 104 deletions
diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index c2acf57310..03748e24ed 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -50,28 +50,30 @@ static zend_bool bFilterLoaded=0; static zend_bool bTerminateThreadsOnError=0; -static char *isapi_server_variables[] = { +static char *isapi_special_server_variable_names[] = { "ALL_HTTP", + "HTTPS", +#ifndef WITH_ZEUS + "SCRIPT_NAME", +#else + "PATH_INFO", +#endif + NULL +}; + +#define NUM_SPECIAL_VARS (sizeof(isapi_special_server_variable_names)/sizeof(char *)) +#define SPECIAL_VAR_ALL_HTTP 0 +#define SPECIAL_VAR_HTTPS 1 +#define SPECIAL_VAR_PHP_SELF 2 + +static char *isapi_special_server_variables[NUM_SPECIAL_VARS]; + +static char *isapi_server_variable_names[] = { "AUTH_PASSWORD", "AUTH_TYPE", "AUTH_USER", - "CERT_COOKIE", - "CERT_FLAGS", - "CERT_ISSUER", - "CERT_KEYSIZE", - "CERT_SECRETKEYSIZE", - "CERT_SERIALNUMBER", - "CERT_SERVER_ISSUER", - "CERT_SERVER_SUBJECT", - "CERT_SUBJECT", "CONTENT_LENGTH", "CONTENT_TYPE", - "HTTP_COOKIE", - "HTTPS_KEYSIZE", - "HTTPS_SECRETKEYSIZE", - "HTTPS_SERVER_ISSUER", - "HTTPS_SERVER_SUBJECT", - "HTTPS", "PATH_TRANSLATED", "QUERY_STRING", "REMOTE_ADDR", @@ -80,7 +82,6 @@ static char *isapi_server_variables[] = { "REQUEST_METHOD", "SERVER_NAME", "SERVER_PORT", - "SERVER_PORT_SECURE", "SERVER_PROTOCOL", "SERVER_SOFTWARE", #ifndef WITH_ZEUS @@ -89,9 +90,7 @@ static char *isapi_server_variables[] = { "INSTANCE_ID", "INSTANCE_META_PATH", "LOGON_USER", - "PATH_INFO", "REQUEST_URI", - "SCRIPT_NAME", "URL", #else "DOCUMENT_ROOT", @@ -100,11 +99,37 @@ static char *isapi_server_variables[] = { }; +static char *isapi_secure_server_variable_names[] = { + "CERT_COOKIE", + "CERT_FLAGS", + "CERT_ISSUER", + "CERT_KEYSIZE", + "CERT_SECRETKEYSIZE", + "CERT_SERIALNUMBER", + "CERT_SERVER_ISSUER", + "CERT_SERVER_SUBJECT", + "CERT_SUBJECT", + "HTTPS_KEYSIZE", + "HTTPS_SECRETKEYSIZE", + "HTTPS_SERVER_ISSUER", + "HTTPS_SERVER_SUBJECT", + "SERVER_PORT_SECURE", + NULL +}; + + static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS) { - char **p = isapi_server_variables; + char **p; char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; DWORD variable_len; + char **all_variables[] = { + isapi_server_variable_names, + isapi_special_server_variable_names, + isapi_secure_server_variable_names, + NULL + }; + char ***server_variable_names; LPEXTENSION_CONTROL_BLOCK lpECB; SLS_FETCH(); @@ -112,22 +137,27 @@ static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS) php_info_print_table_start(); php_info_print_table_header(2, "Server Variable", "Value"); - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, *p, variable_buf); - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - char *tmp_variable_buf; - - tmp_variable_buf = (char *) emalloc(variable_len); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) + server_variable_names = all_variables; + while (*server_variable_names) { + p = *server_variable_names; + while (*p) { + variable_len = ISAPI_SERVER_VAR_BUF_SIZE; + if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) && variable_buf[0]) { - php_info_print_table_row(2, *p, tmp_variable_buf); + php_info_print_table_row(2, *p, variable_buf); + } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + char *tmp_variable_buf; + + tmp_variable_buf = (char *) emalloc(variable_len); + if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) + && variable_buf[0]) { + php_info_print_table_row(2, *p, tmp_variable_buf); + } + efree(tmp_variable_buf); } - efree(tmp_variable_buf); + p++; } - p++; + server_variable_names++; } php_info_print_table_end(); } @@ -304,38 +334,15 @@ 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) +#ifdef WITH_ZEUS +static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array ELS_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; - char **p = isapi_server_variables; - - lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - /* Register the standard ISAPI variables */ - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len) - && static_variable_buf[0]) { - php_register_variable(*p, static_variable_buf, track_vars_array ELS_CC PLS_CC); - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - variable_buf = (char *) emalloc(variable_len); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_register_variable(*p, variable_buf, track_vars_array ELS_CC PLS_CC); - } - efree(variable_buf); - } - p++; - } - -#ifdef WITH_ZEUS /* - * Zeus' map module translates the given URL onto the PHP ISAPI libray; + * Zeus' map module translates the given URL onto the PHP ISAPI library; * from an internal point of view, SCRIPT_NAME and URL are correct, * but from the end-users point of view, it is not... We need to * reconstruct the SCRIPT_NAME and URL from PATH_INFO, and then @@ -359,51 +366,98 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array ELS_DC S if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { php_register_variable( "SCRIPT_FILENAME", static_variable_buf, track_vars_array ELS_CC PLS_CC ); } +} #endif - /* PHP_SELF support */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; -#ifdef WITH_ZEUS - if (lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) -#else - if (lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len) -#endif - && static_variable_buf[0]) { - php_register_variable("PHP_SELF", static_variable_buf, track_vars_array ELS_CC PLS_CC); - } - - /* Register the internal bits of ALL_HTTP */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; +static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values ELS_DC PLS_DC) +{ + char **p=server_variables; + DWORD variable_len; + char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; + char *variable_buf; - if (lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len)) { - variable_buf = static_variable_buf; - } else { - if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { + while (*p) { + variable_len = ISAPI_SERVER_VAR_BUF_SIZE; + if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len) + && static_variable_buf[0]) { + php_register_variable(*p, static_variable_buf, track_vars_array ELS_CC PLS_CC); + if (recorded_values) { + recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len); + } + } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { variable_buf = (char *) emalloc(variable_len); - if (!lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) { + if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) + && variable_buf[0]) { + php_register_variable(*p, variable_buf, track_vars_array ELS_CC PLS_CC); + } + if (recorded_values) { + recorded_values[p-server_variables] = variable_buf; + } else { efree(variable_buf); - return; } - } else { - return; } + p++; + } +} + + +static void sapi_isapi_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC) +{ + 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); + + /* Register the special ISAPI variables */ + memset(isapi_special_server_variables, 0, sizeof(isapi_special_server_variables)); + sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables ELS_CC PLS_CC); + if (SG(request_info).cookie_data) { + php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array ELS_CC PLS_CC); + } + + /* Register the standard ISAPI variables */ + sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL ELS_CC PLS_CC); + + if (isapi_special_server_variables[SPECIAL_VAR_HTTPS] + && atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS])) { + /* Register SSL ISAPI variables */ + sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL ELS_CC PLS_CC); + } + efree(isapi_special_server_variables[SPECIAL_VAR_HTTPS]); + + +#ifdef WITH_ZEUS + sapi_isapi_register_zeus_variables(lpECB, track_vars_array ELS_CC PLS_CC); +#endif + + /* PHP_SELF support */ + if (isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]) { + php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array ELS_CC PLS_CC); + efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]); } - variable = php_strtok_r(variable_buf, "\r\n", &strtok_buf); - while (variable) { - char *colon = strchr(variable, ':'); - if (colon) { - char *value = colon+1; + if (isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]) { + /* Register the internal bits of ALL_HTTP */ + variable = php_strtok_r(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP], "\r\n", &strtok_buf); + while (variable) { + char *colon = strchr(variable, ':'); - while (*value==' ') { - value++; + if (colon) { + char *value = colon+1; + + while (*value==' ') { + value++; + } + *colon = 0; + php_register_variable(variable, value, track_vars_array ELS_CC PLS_CC); + *colon = ':'; } - *colon = 0; - php_register_variable(variable, value, track_vars_array ELS_CC PLS_CC); - *colon = ':'; + variable = php_strtok_r(NULL, "\r\n", &strtok_buf); } - variable = php_strtok_r(NULL, "\r\n", &strtok_buf); + efree(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]); } #ifdef PHP_WIN32 @@ -421,14 +475,10 @@ static void sapi_isapi_register_server_variables(zval *track_vars_array ELS_DC S } } #endif - - if (variable_buf!=static_variable_buf) { - efree(variable_buf); - } } -static sapi_module_struct sapi_module = { +static sapi_module_struct isapi_sapi_module = { "isapi", /* name */ "ISAPI", /* pretty name */ @@ -466,7 +516,7 @@ BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion) { bFilterLoaded = 1; pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION; - strcpy(pFilterVersion->lpszFilterDesc, sapi_module.pretty_name); + strcpy(pFilterVersion->lpszFilterDesc, isapi_sapi_module.pretty_name); pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS); return TRUE; } @@ -537,9 +587,9 @@ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) { pVer->dwExtensionVersion = HSE_VERSION; #ifdef WITH_ZEUS - strncpy( pVer->lpszExtensionDesc, sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); + strncpy( pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); #else - lstrcpyn(pVer->lpszExtensionDesc, sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); + lstrcpyn(pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); #endif return TRUE; } @@ -661,9 +711,9 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, L switch (fdwReason) { case DLL_PROCESS_ATTACH: tsrm_startup(1, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log"); - sapi_startup(&sapi_module); - if (sapi_module.startup) { - sapi_module.startup(&sapi_module); + sapi_startup(&isapi_sapi_module); + if (isapi_sapi_module.startup) { + isapi_sapi_module.startup(&sapi_module); } break; case DLL_THREAD_ATTACH: @@ -672,8 +722,8 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, L ts_free_thread(); break; case DLL_PROCESS_DETACH: - if (sapi_module.shutdown) { - sapi_module.shutdown(&sapi_module); + if (isapi_sapi_module.shutdown) { + isapi_sapi_module.shutdown(&sapi_module); } tsrm_shutdown(); break; |