diff options
author | Holger Zimmermann <holger@php.net> | 2004-12-05 09:52:25 +0000 |
---|---|---|
committer | Holger Zimmermann <holger@php.net> | 2004-12-05 09:52:25 +0000 |
commit | b36a4c57cac7d3f810e4c4a35266b00b91243db6 (patch) | |
tree | 8ca7295e8a1acbd2c8c722d3e17a63c9ac80c3c4 /sapi/pi3web/pi3web_sapi.c | |
parent | 4026a3ce7ed822418c35d49e4ea51319ad7d2311 (diff) | |
download | php-git-b36a4c57cac7d3f810e4c4a35266b00b91243db6.tar.gz |
Replaced static server variables by function call and configurable list at the Pi3Web server side.
Diffstat (limited to 'sapi/pi3web/pi3web_sapi.c')
-rw-r--r-- | sapi/pi3web/pi3web_sapi.c | 108 |
1 files changed, 31 insertions, 77 deletions
diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c index 1a6d36fdc7..ac7f3a93da 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -45,36 +45,14 @@ 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("<table border=0 cellpadding=3 cellspacing=1 width=600 align=center>\n"); PUTS("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">Pi3Web Server Information</th></tr>\n"); @@ -100,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("<tr><th colspan=2 bgcolor=\"" PHP_HEADER_COLOR "\">HTTP Headers</th></tr>\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("</table>"); @@ -298,68 +282,38 @@ 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 */ variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; if (lpCB->GetServerVariable(lpCB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len) && (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 = { @@ -388,7 +342,7 @@ static sapi_module_struct pi3web_sapi_module = { MODULE_API DWORD PHP5_wrapper(LPCONTROL_BLOCK lpCB) { - zend_file_handle file_handle; + zend_file_handle file_handle = {0}; int iRet = PIAPI_COMPLETED; TSRMLS_FETCH(); |