From: Sascha Schumann Date: Fri, 25 Aug 2000 08:46:32 +0000 (+0000) Subject: Make proper use of SAPI's register_environment functionality. X-Git-Tag: php-4.0.2~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a1db559b6f7b9be5a26ec22f595e0fb9995666d;p=php Make proper use of SAPI's register_environment functionality. --- diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c index fb1fdd3c7a..ebf7154687 100644 --- a/sapi/thttpd/thttpd.c +++ b/sapi/thttpd/thttpd.c @@ -21,6 +21,7 @@ #include "SAPI.h" #include "php_main.h" #include "php_thttpd.h" +#include "php_variables.h" #include "version.h" typedef struct { @@ -101,86 +102,40 @@ static char *sapi_thttpd_read_cookies(SLS_D) return TG(hc)->cookie; } -static sapi_module_struct sapi_module = { - "thttpd", - "thttpd", - - php_module_startup, - php_module_shutdown_wrapper, - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_thttpd_ub_write, - NULL, - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, - - NULL, - sapi_thttpd_send_headers, - sapi_thttpd_send_header, - sapi_thttpd_read_post, - sapi_thttpd_read_cookies, - - NULL, /* register server variables */ - NULL, /* Log message */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - #define BUF_SIZE 512 #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) - -static void thttpd_hash_environment(void) + php_register_variable(name, buf, track_vars_array ELS_C PLS_CC) + +static void sapi_thttpd_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC) { char buf[BUF_SIZE + 1]; - zval *pval; + TLS_FETCH(); + + php_register_variable("PHP_SELF", TG(hc)->decodedurl, track_vars_array ELS_CC PLS_CC); + php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array ELS_C PLS_CC); + php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array ELS_C PLS_CC); + php_register_variable("REQUEST_METHOD", SG(request_info).request_method, track_vars_array ELS_C PLS_CC); + php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array ELS_C PLS_CC); + php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array ELS_C PLS_CC); buf[BUF_SIZE] = '\0'; - strncpy(buf, SERVER_SOFTWARE, BUF_SIZE); - ADD_STRING("SERVER_SOFTWARE"); - - strncpy(buf, "CGI/1.1", BUF_SIZE); - ADD_STRING("GATEWAY_INTERFACE"); + strncpy(buf, inet_ntoa(TG(hc)->client_addr.sa_in.sin_addr), BUF_SIZE); + ADD_STRING("REMOTE_ADDR"); + ADD_STRING("REMOTE_HOST"); snprintf(buf, BUF_SIZE, "%d", TG(hc)->hs->port); ADD_STRING("SERVER_PORT"); - strncpy(buf, SG(request_info).request_method, BUF_SIZE); - ADD_STRING("REQUEST_METHOD"); - - strncpy(buf, SG(request_info).request_uri, BUF_SIZE); - ADD_STRING("REQUEST_URI"); - snprintf(buf, BUF_SIZE, "/%s", TG(hc)->pathinfo); ADD_STRING("PATH_INFO"); - - strncpy(buf, SG(request_info).path_translated, BUF_SIZE); - ADD_STRING("PATH_TRANSLATED"); snprintf(buf, BUF_SIZE, "/%s", TG(hc)->origfilename); ADD_STRING("SCRIPT_NAME"); - strncpy(buf, inet_ntoa(TG(hc)->client_addr.sa_in.sin_addr), BUF_SIZE); - ADD_STRING("REMOTE_ADDR"); - ADD_STRING("REMOTE_HOST"); - #define CONDADD(name, field) \ if (TG(hc)->field[0]) { \ - strncpy(buf, TG(hc)->field, BUF_SIZE); \ - ADD_STRING(#name); \ + php_register_variable(#name, TG(hc)->field, track_vars_array ELS_C PLS_C); \ } CONDADD(HTTP_REFERER, referer); @@ -197,12 +152,42 @@ static void thttpd_hash_environment(void) ADD_STRING("CONTENT_LENGTH"); } - if (TG(hc)->authorization[0]) { - strcpy(buf, "Basic"); - ADD_STRING("AUTH_TYPE"); - } + if (TG(hc)->authorization[0]) + php_register_variable("AUTH_TYPE", "Basic", track_vars_array ELS_C PLS_C); } +static sapi_module_struct sapi_module = { + "thttpd", + "thttpd", + + php_module_startup, + php_module_shutdown_wrapper, + + NULL, /* activate */ + NULL, /* deactivate */ + + sapi_thttpd_ub_write, + NULL, + NULL, /* get uid */ + NULL, /* getenv */ + + php_error, + + NULL, + sapi_thttpd_send_headers, + sapi_thttpd_send_header, + sapi_thttpd_read_post, + sapi_thttpd_read_cookies, + + sapi_thttpd_register_variables, + NULL, /* Log message */ + + NULL, /* Block interruptions */ + NULL, /* Unblock interruptions */ + + STANDARD_SAPI_MODULE_PROPERTIES +}; + static void thttpd_module_main(TLS_D SLS_DC) { zend_file_handle file_handle; @@ -219,7 +204,6 @@ static void thttpd_module_main(TLS_D SLS_DC) return; } - thttpd_hash_environment(); php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); php_request_shutdown(NULL); }