From: Holger Zimmermann Date: Sun, 5 Dec 2004 09:48:48 +0000 (+0000) Subject: Replaced static server variables by function call and configurable list at the Pi3Web... X-Git-Tag: php-4.3.10RC2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cd60dedad1f957c63dfb4a74166ee5756096547;p=php Replaced static server variables by function call and configurable list at the Pi3Web server side. --- diff --git a/sapi/pi3web/php4pi3web.dsp b/sapi/pi3web/php4pi3web.dsp index 2e5bdda152..50eebadae3 100644 --- a/sapi/pi3web/php4pi3web.dsp +++ b/sapi/pi3web/php4pi3web.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Debug_TS" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4pi3web_EXPORTS" /YX /FD /GZ /c +# ADD BASE CPP /nologo /MTd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4PI3WEB_EXPORTS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /D "PHP4PI3WEB_EXPORTS" /FR /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 @@ -69,7 +69,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Release_TS" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4pi3web_EXPORTS" /YX /FD /c +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4PI3WEB_EXPORTS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\main" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "_WINDOWS" /D "_USRDLL" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "_MBCS" /D "PHP4PI3WEB_EXPORTS" /FR /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c index bc25266ac5..944403efa1 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -25,7 +25,6 @@ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS -#include "pi3web_sapi.h" #include "php.h" #include "php_main.h" #include "php_variables.h" @@ -40,40 +39,20 @@ #include "PiAPI.h" #include "Pi3API.h" +#include "pi3web_sapi.h" + #define PI3WEB_SERVER_VAR_BUF_SIZE 1024 int IWasLoaded=0; -static char *pi3web_server_variables[] = { - "ALL_HTTP", - "AUTH_TYPE", - "CONTENT_LENGTH", - "CONTENT_TYPE", - "GATEWAY_INTERFACE", - "PATH_INFO", - "PATH_TRANSLATED", - "QUERY_STRING", - "REQUEST_METHOD", - "REMOTE_ADDR", - "REMOTE_HOST", - "REMOTE_USER", - "SCRIPT_NAME", - "SERVER_NAME", - "SERVER_PORT", - "SERVER_PROTOCOL", - "SERVER_SOFTWARE", - NULL -}; - static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) { - char **p = pi3web_server_variables; char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; DWORD variable_len; - LPCONTROL_BLOCK lpCB; - - lpCB = (LPCONTROL_BLOCK) SG(server_context); + LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); + PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); + PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); PUTS("\n"); PUTS("\n"); @@ -99,22 +78,28 @@ static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) php_info_print_table_row(2, "HTTP Request Line", lpCB->lpszReq); PUTS("\n"); php_info_print_table_header(2, "Server Variable", "Value"); - while (*p) { + + /* --- loop over all registered server variables --- */ + for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) + { + PCHAR pKey; + PIDBIterator_current( pIter, &pKey ); + if ( !pKey ) { /* sanity */ continue; }; + variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, *p, variable_buf, &variable_len) + if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len) && variable_buf[0]) { - php_info_print_table_row(2, *p, variable_buf); + php_info_print_table_row(2, pKey, variable_buf); } else if (PIPlatform_getLastError() == PIAPI_EINVAL) { char *tmp_variable_buf; tmp_variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, *p, tmp_variable_buf, &variable_len) + if (lpCB->GetServerVariable(lpCB->ConnID, pKey, tmp_variable_buf, &variable_len) && variable_buf[0]) { - php_info_print_table_row(2, *p, tmp_variable_buf); + php_info_print_table_row(2, pKey, tmp_variable_buf); } efree(tmp_variable_buf); } - p++; } PUTS("
Pi3Web Server Information
HTTP Headers
"); @@ -297,26 +282,29 @@ static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC) char static_variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; char *variable_buf; DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - char *variable; - char *strtok_buf = NULL; LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - char **p = pi3web_server_variables; - p++; // Jump over ALL_HTTP; + PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); + PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); + + /* --- loop over all registered server variables --- */ + for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) + { + PCHAR pKey; + PIDBIterator_current( pIter, &pKey ); + if ( !pKey ) { /* sanity */ continue; }; - /* Register the standard server variables */ - while (*p) { variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, *p, static_variable_buf, &variable_len) + if (lpCB->GetServerVariable(lpCB->ConnID, pKey, static_variable_buf, &variable_len) && (variable_len > 1)) { - php_register_variable(*p, static_variable_buf, track_vars_array TSRMLS_CC); + php_register_variable(pKey, static_variable_buf, track_vars_array TSRMLS_CC); } else if (PIPlatform_getLastError()==PIAPI_EINVAL) { variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, *p, variable_buf, &variable_len)) { - php_register_variable(*p, variable_buf, track_vars_array TSRMLS_CC); + if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len)) { + php_register_variable(pKey, variable_buf, track_vars_array TSRMLS_CC); } efree(variable_buf); } - p++; + } /* PHP_SELF support */ @@ -325,40 +313,6 @@ static void sapi_pi3web_register_variables(zval *track_vars_array TSRMLS_DC) && (variable_len > 1)) { php_register_variable("PHP_SELF", static_variable_buf, track_vars_array TSRMLS_CC); } - - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len) - && (variable_len > 1)) { - variable_buf = static_variable_buf; - } else { - if (PIPlatform_getLastError()==PIAPI_EINVAL) { - variable_buf = (char *) emalloc(variable_len); - if (!lpCB->GetServerVariable(lpCB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) { - efree(variable_buf); - return; - } - } else { - return; - } - } - variable = php_strtok_r(variable_buf, "\r\n", &strtok_buf); - while (variable) { - char *colon = strchr(variable, ':'); - - if (colon) { - char *value = colon+1; - while (*value==' ') { - value++; - } - *colon = 0; - php_register_variable(variable, value, track_vars_array TSRMLS_CC); - *colon = ':'; - } - variable = php_strtok_r(NULL, "\r\n", &strtok_buf); - } - if (variable_buf!=static_variable_buf) { - efree(variable_buf); - } } static sapi_module_struct pi3web_sapi_module = { diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h index d1c38d744e..fc6e9fbe81 100644 --- a/sapi/pi3web/pi3web_sapi.h +++ b/sapi/pi3web/pi3web_sapi.h @@ -3,7 +3,6 @@ #ifdef PHP_WIN32 # include -# include # ifdef PHP4PI3WEB_EXPORTS # define MODULE_API __declspec(dllexport) # else @@ -15,7 +14,6 @@ typedef int BOOL; typedef void far *LPVOID; - typedef LPVOID HCONN; typedef unsigned long DWORD; typedef DWORD far *LPDWORD; typedef char CHAR; @@ -24,6 +22,8 @@ typedef BYTE far *LPBYTE; #endif + typedef LPVOID HCONN; + #ifdef __cplusplus extern "C" { #endif @@ -59,17 +59,19 @@ typedef struct _CONTROL_BLOCK { LPSTR lpszContentType; // Content type of client data DWORD dwBehavior; // PHP behavior (standard, highlight, intend + LPVOID (* GetVariableNames) (HCONN hConn); + BOOL (* GetServerVariable) ( HCONN hConn, LPSTR lpszVariableName, LPVOID lpvBuffer, LPDWORD lpdwSize ); - BOOL (* WriteClient) ( HCONN ConnID, - LPVOID Buffer, + BOOL (* WriteClient) ( HCONN hConn, + LPVOID lpvBuffer, LPDWORD lpdwBytes, DWORD dwReserved ); - BOOL (* ReadClient) ( HCONN ConnID, + BOOL (* ReadClient) ( HCONN hConn, LPVOID lpvBuffer, LPDWORD lpdwSize );