]> granicus.if.org Git - php/commitdiff
Replaced static server variables by function call and configurable list at the Pi3Web...
authorHolger Zimmermann <holger@php.net>
Sun, 5 Dec 2004 09:48:48 +0000 (09:48 +0000)
committerHolger Zimmermann <holger@php.net>
Sun, 5 Dec 2004 09:48:48 +0000 (09:48 +0000)
sapi/pi3web/php4pi3web.dsp
sapi/pi3web/pi3web_sapi.c
sapi/pi3web/pi3web_sapi.h

index 2e5bdda1529b17e2bb97aaafe7fb50c92155d69f..50eebadae3cf9b2493996d64a2a2afdca6ced5b9 100644 (file)
@@ -43,7 +43,7 @@ RSC=rc.exe
 # PROP Intermediate_Dir "Debug_TS"\r
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
-# 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\r
+# 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\r
 # 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\r
 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
@@ -69,7 +69,7 @@ LINK32=link.exe
 # PROP Intermediate_Dir "Release_TS"\r
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "php4pi3web_EXPORTS" /YX /FD /c\r
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4PI3WEB_EXPORTS" /YX /FD /c\r
 # 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\r
 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
index bc25266ac5e85c5fe042baf0e7e08a003e91017e..944403efa1cdb59b6b16c26373f7e604a7be3a40 100644 (file)
@@ -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"
 #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("<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");
@@ -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("<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>");
@@ -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 = {
index d1c38d744e7979d974567d2d098719826c3e865a..fc6e9fbe81c0691d1eb1cc2ec96fcc2cc5b8c01f 100644 (file)
@@ -3,7 +3,6 @@
 
 #ifdef PHP_WIN32
 #      include <windows.h>
-#      include <httpext.h>
 #      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 );