]> granicus.if.org Git - php/commitdiff
Use SAPI' register_server_variables hook.
authorSascha Schumann <sas@php.net>
Fri, 25 Aug 2000 09:59:38 +0000 (09:59 +0000)
committerSascha Schumann <sas@php.net>
Fri, 25 Aug 2000 09:59:38 +0000 (09:59 +0000)
Defines PHP_SELF now.

sapi/aolserver/aolserver.c

index 90a2719ac47b47656a879dc7f8ce5552d7f4faad..765b46b7fa5b9712e447aee59f728f6c4a563679 100644 (file)
@@ -44,6 +44,7 @@
 #include "php_globals.h"
 #include "SAPI.h"
 #include "php_main.h"
+#include "php_variables.h"
 
 #include "ns.h"
 
@@ -287,62 +288,25 @@ php_ns_startup(sapi_module_struct *sapi_module)
 }
 
 
-/* this structure is static (as in "it does not change") */
-
-static sapi_module_struct sapi_module = {
-       "aolserver",
-       "AOLserver",
-
-       php_ns_startup,                                                 /* startup */
-       php_module_shutdown_wrapper,                    /* shutdown */
-
-       NULL,                                                                   /* activate */
-       NULL,                                                                   /* deactivate */
-
-       php_ns_sapi_ub_write,                                   /* unbuffered write */
-       NULL,                                                                   /* flush */
-       NULL,                                                                   /* get uid */
-       NULL,                                                                   /* getenv */
-
-       php_error,                                                              /* error handler */
-
-       php_ns_sapi_header_handler,                             /* header handler */
-       php_ns_sapi_send_headers,                               /* send headers handler */
-       NULL,                                                                   /* send header handler */
-
-       php_ns_sapi_read_post,                                  /* read POST data */
-       php_ns_sapi_read_cookies,                               /* read Cookies */
-
-       NULL,                                                                   /* register server variables */
-       NULL,                                                                   /* Log message */
-
-       NULL,                                                                   /* Block interruptions */
-       NULL,                                                                   /* Unblock interruptions */
-
-       STANDARD_SAPI_MODULE_PROPERTIES
-};
-
 /*
- * php_ns_hash_environment() populates the php script environment
+ * php_ns_sapi_register_variables() populates the php script environment
  * with a number of variables. HTTP_* variables are created for
  * the HTTP header data, so that a script can access these.
  */
 
+#define ADD_STRINGX(name,buf)                                                                          \
+       php_register_variable(name, buf, track_vars_array ELS_CC PLS_CC)
+
 #define ADD_STRING(name)                                                                               \
-       MAKE_STD_ZVAL(pval);                                                                            \
-       pval->type = IS_STRING;                                                                         \
-       pval->value.str.len = strlen(buf);                                                      \
-       pval->value.str.val = estrndup(buf, pval->value.str.len);       \
-       zend_hash_update(&EG(symbol_table), name, sizeof(name),         \
-                       &pval, sizeof(zval *), NULL)
+       ADD_STRINGX(name, buf)
 
 static void
-php_ns_hash_environment(NSLS_D CLS_DC ELS_DC PLS_DC SLS_DC)
+php_ns_sapi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
 {
        int i;
        char buf[NS_BUF_SIZE + 1];
-       zval *pval;
        char *tmp;
+       NSLS_FETCH();
 
        for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) {
                char *key = Ns_SetKey(NSG(conn->headers), i);
@@ -352,20 +316,15 @@ php_ns_hash_environment(NSLS_D CLS_DC ELS_DC PLS_DC SLS_DC)
                int buf_len;
 
                buf_len = snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key);
-               for(p = buf; (c = *p); p++) {
+               for(p = buf + 5; (c = *p); p++) {
                        c = toupper(c);
                        if(c < 'A' || c > 'Z') {
                                c = '_';
                        }
                        *p = c;
                }
-               
-               MAKE_STD_ZVAL(pval);
-               pval->type = IS_STRING;
-               pval->value.str.len = strlen(value);
-               pval->value.str.val = estrndup(value, pval->value.str.len);
 
-               zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &pval, sizeof(zval *), NULL);
+               ADD_STRINGX(buf, value);
        }
        
        snprintf(buf, NS_BUF_SIZE, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
@@ -373,21 +332,14 @@ php_ns_hash_environment(NSLS_D CLS_DC ELS_DC PLS_DC SLS_DC)
        snprintf(buf, NS_BUF_SIZE, "HTTP/%1.1f", NSG(conn)->request->version);
        ADD_STRING("SERVER_PROTOCOL");
 
-       strncpy(buf, NSG(conn)->request->method, NS_BUF_SIZE);
-       ADD_STRING("REQUEST_METHOD");
+       ADD_STRINGX("REQUEST_METHOD", NSG(conn)->request->method);
 
-       if(NSG(conn)->request->query) {
-               strncpy(buf, NSG(conn)->request->query, NS_BUF_SIZE);
-       } else {
-               buf[0] = '\0';
-       }
-       ADD_STRING("QUERY_STRING");
+       if(NSG(conn)->request->query)
+               ADD_STRINGX("QUERY_STRING", NSG(conn)->request->query);
        
-       strncpy(buf, Ns_InfoBuildDate(), NS_BUF_SIZE);
-       ADD_STRING("SERVER_BUILDDATE");
+       ADD_STRINGX("SERVER_BUILDDATE", Ns_InfoBuildDate());
 
-       strncpy(buf, Ns_ConnPeer(NSG(conn)), NS_BUF_SIZE);
-       ADD_STRING("REMOTE_ADDR");
+       ADD_STRINGX("REMOTE_ADDR", Ns_ConnPeer(NSG(conn)));
 
        snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPeerPort(NSG(conn)));
        ADD_STRING("REMOTE_PORT");
@@ -396,23 +348,56 @@ php_ns_hash_environment(NSLS_D CLS_DC ELS_DC PLS_DC SLS_DC)
        ADD_STRING("SERVER_PORT");
 
        tmp = Ns_ConnHost(NSG(conn));
-       if (tmp) {
-               strncpy(buf, tmp, NS_BUF_SIZE);
-               ADD_STRING("SERVER_NAME");
-       }       
+       if (tmp)
+               ADD_STRINGX("SERVER_NAME", tmp);
 
-       strncpy(buf, SG(request_info).path_translated, NS_BUF_SIZE);
-       ADD_STRING("PATH_TRANSLATED");
+       ADD_STRINGX("PATH_TRANSLATED", SG(request_info).path_translated);
+       ADD_STRINGX("REQUEST_URI", SG(request_info).request_uri);
+       ADD_STRINGX("PHP_SELF", SG(request_info).request_uri);
 
-       strncpy(buf, "CGI/1.1", NS_BUF_SIZE);
-       ADD_STRING("GATEWAY_INTERFACE");
+       ADD_STRINGX("GATEWAY_INTERFACE", "CGI/1.1");
 
-       MAKE_STD_ZVAL(pval);
-       pval->type = IS_LONG;
-       pval->value.lval = Ns_InfoBootTime();
-       zend_hash_update(&EG(symbol_table), "SERVER_BOOTTIME", sizeof("SERVER_BOOTTIME"), &pval, sizeof(zval *), NULL);
+       snprintf(buf, NS_BUF_SIZE, "%d", Ns_InfoBootTime());
+       ADD_STRING("SERVER_BOOTTIME");
 }
 
+
+
+/* this structure is static (as in "it does not change") */
+
+static sapi_module_struct sapi_module = {
+       "aolserver",
+       "AOLserver",
+
+       php_ns_startup,                                                 /* startup */
+       php_module_shutdown_wrapper,                    /* shutdown */
+
+       NULL,                                                                   /* activate */
+       NULL,                                                                   /* deactivate */
+
+       php_ns_sapi_ub_write,                                   /* unbuffered write */
+       NULL,                                                                   /* flush */
+       NULL,                                                                   /* get uid */
+       NULL,                                                                   /* getenv */
+
+       php_error,                                                              /* error handler */
+
+       php_ns_sapi_header_handler,                             /* header handler */
+       php_ns_sapi_send_headers,                               /* send headers handler */
+       NULL,                                                                   /* send header handler */
+
+       php_ns_sapi_read_post,                                  /* read POST data */
+       php_ns_sapi_read_cookies,                               /* read Cookies */
+
+       php_ns_sapi_register_variables,
+       NULL,                                                                   /* Log message */
+
+       NULL,                                                                   /* Block interruptions */
+       NULL,                                                                   /* Unblock interruptions */
+
+       STANDARD_SAPI_MODULE_PROPERTIES
+};
+
 /*
  * php_ns_module_main() is called by the per-request handler and
  * "executes" the script
@@ -436,7 +421,6 @@ php_ns_module_main(NSLS_D SLS_DC)
                return NS_ERROR;
        }
        
-       php_ns_hash_environment(NSLS_C CLS_CC ELS_CC PLS_CC SLS_CC);
        php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
        php_request_shutdown(NULL);
 
@@ -564,8 +548,9 @@ php_ns_config(php_ns_context *ctx, char global)
         * known_directives) 
         */
 
-#if 0
                } else if (!global && !strcasecmp(key, "php_value")) {
+                       Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks.");
+#if 0
                        char *val;
 
                        val = strchr(value, ' ');
@@ -583,8 +568,8 @@ php_ns_config(php_ns_context *ctx, char global)
                                                strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME);
                                
                                efree(new_key);
-#endif
                        }
+#endif
                }
                
        }