cvs: php4 /sapi/thttpd thttpd.c

From: Date: Fri, 25 Aug 2000 08:46:32 +0000
Subject: cvs: php4 /sapi/thttpd thttpd.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1383@lists.php.net to get a copy of this message
sas Fri Aug 25 01:46:32 2000 EDT Modified files: /php4/sapi/thttpd thttpd.c Log: Make proper use of SAPI's register_environment functionality. Index: php4/sapi/thttpd/thttpd.c diff -u php4/sapi/thttpd/thttpd.c:1.17 php4/sapi/thttpd/thttpd.c:1.18 --- php4/sapi/thttpd/thttpd.c:1.17 Sun Aug 13 11:00:39 2000 +++ php4/sapi/thttpd/thttpd.c Fri Aug 25 01:46:32 2000 @@ -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 @@ 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) + php_register_variable(name, buf, track_vars_array ELS_C PLS_CC) -static void thttpd_hash_environment(void) +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 @@ 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 @@ return; } - thttpd_hash_environment(); php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); php_request_shutdown(NULL); }

« previous php.cvs (#1383) next »