From: Zeev Suraski Date: Fri, 28 Jan 2000 18:29:37 +0000 (+0000) Subject: - A few fixes X-Git-Tag: BEFORE_SAPIFICATION_FEB_10_2000~164 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99f079a3495f8b909d2f79c3c67b88f89e316f49;p=php - A few fixes - Added register_argv_argc directive to allow disabling of argv/argc --- diff --git a/NEWS b/NEWS index 7c54d8f37c..26c07b9d68 100644 --- a/NEWS +++ b/NEWS @@ -2,11 +2,14 @@ PHP 4.0 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? ????, Version 4.0 Beta 4 +- Added register_argc_argv INI directive, to allow to selectively disable + the declaration of the $argv and $argc variables for increased + performance (Zeev) - Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly to $HTTP_GET_VARS[], contain environment and server variables. Setting register_globals to Off will now also prevent registration of the environment and server variables into the global scope (Zeev) -- Renamed gpc_globals to register_globals (Zeev) +- Renamed gpc_globals INI directive to register_globals (Zeev) - Introduced variables_order that deprecates gpc_order, and allows control over the server and environment variables, in addition to GET/POST/Cookies (Zeev) diff --git a/ext/session/session.c b/ext/session/session.c index a4e99225ca..ed359e9737 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -181,10 +181,10 @@ static void php_set_session_var(char *name, size_t namelen, zval_copy_ctor(state_val_copy); state_val_copy->refcount = 0; - if (PG(gpc_globals) && PG(track_vars)) { + if (PG(register_globals) && PG(track_vars)) { zend_set_hash_symbol(state_val_copy, name, namelen, 1, 2, PS(http_state_vars)->value.ht, &EG(symbol_table)); } else { - if (PG(gpc_globals)) { + if (PG(register_globals)) { zend_set_hash_symbol(state_val_copy, name, namelen, 0, 1, &EG(symbol_table)); } @@ -639,7 +639,7 @@ static void _php_session_start(PSLS_D) char *p; int send_cookie = 1; int define_sid = 1; - zend_bool gpc_globals; + zend_bool register_globals; zend_bool track_vars; int module_number = PS(module_number); int nrand; @@ -650,11 +650,11 @@ static void _php_session_start(PSLS_D) lensess = strlen(PS(session_name)); - gpc_globals = INI_BOOL("gpc_globals"); + register_globals = INI_BOOL("register_globals"); track_vars = INI_BOOL("track_vars"); - if (!gpc_globals && !track_vars) { - php_error(E_ERROR, "The sessions module will not work, if you have disabled track_vars and gpc_globals. Enable at least one of them."); + if (!register_globals && !track_vars) { + php_error(E_ERROR, "The sessions module will not work, if you have disabled track_vars and register_globals. Enable at least one of them."); return; } @@ -669,7 +669,7 @@ static void _php_session_start(PSLS_D) * cookie. */ - if (gpc_globals && + if (register_globals && !track_vars && !PS(id) && zend_hash_find(&EG(symbol_table), PS(session_name), diff --git a/main/main.c b/main/main.c index 2c1789c385..5fb79f0702 100644 --- a/main/main.c +++ b/main/main.c @@ -97,7 +97,7 @@ static MUTEX_T global_lock; #endif -void _php_build_argv(char * ELS_DC); +static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC); static void php_timeout(int dummy); static void php_set_timeout(long seconds); @@ -250,7 +250,8 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("track_vars", "0", PHP_INI_ALL, OnUpdateBool, track_vars, php_core_globals, core_globals) #endif - STD_PHP_INI_BOOLEAN("register_globals", "1", PHP_INI_ALL, OnUpdateBool, gpc_globals, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("register_globals", "1", PHP_INI_ALL, OnUpdateBool, register_globals, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_ALL, OnUpdateBool, register_argc_argv, php_core_globals, core_globals) STD_PHP_INI_ENTRY("gpc_order", "GPC", PHP_INI_ALL, OnUpdateStringUnempty, gpc_order, php_core_globals, core_globals) STD_PHP_INI_ENTRY("variables_order", NULL, PHP_INI_ALL, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals) STD_PHP_INI_ENTRY("arg_separator", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator, php_core_globals, core_globals) @@ -1007,6 +1008,10 @@ static inline void php_register_server_variables(ELS_D SLS_DC PLS_DC) zend_hash_add(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), &array_ptr, sizeof(pval *),NULL); } sapi_module.register_server_variables(array_ptr ELS_CC SLS_CC PLS_CC); + + if (PG(register_argc_argv)) { + php_build_argv(SG(request_info).query_string, array_ptr ELS_CC PLS_CC); + } } @@ -1070,30 +1075,21 @@ static int php_hash_environment(ELS_D SLS_DC PLS_DC) php_register_server_variables(ELS_C SLS_CC PLS_CC); } - - /* need argc/argv support as well */ - _php_build_argv(SG(request_info).query_string ELS_CC); - return SUCCESS; } -void _php_build_argv(char *s ELS_DC) +static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC) { - pval *arr, *tmp; + pval *arr, *argc, *tmp; int count = 0; char *ss, *space; ALLOC_ZVAL(arr); - arr->value.ht = (HashTable *) emalloc(sizeof(HashTable)); - if (zend_hash_init(arr->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0) == FAILURE) { - php_error(E_WARNING, "Unable to create argv array"); - } else { - arr->type = IS_ARRAY; - INIT_PZVAL(arr); - zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); - } - /* now pick out individual entries */ + array_init(arr); + INIT_PZVAL(arr); + + /* Prepare argv */ ss = s; while (ss) { space = strchr(ss, '+'); @@ -1119,11 +1115,27 @@ void _php_build_argv(char *s ELS_DC) ss = space; } } - ALLOC_ZVAL(tmp); - tmp->value.lval = count; - tmp->type = IS_LONG; - INIT_PZVAL(tmp); - zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &tmp, sizeof(pval *), NULL); + + /* prepare argc */ + ALLOC_ZVAL(argc); + argc->value.lval = count; + argc->type = IS_LONG; + INIT_PZVAL(argc); + + if (PG(register_globals)) { + zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); + zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL); + } + + if (PG(track_vars)) { + if (!PG(register_globals)) { + arr->refcount++; + argc->refcount++; + } + zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); + zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL); + } + } diff --git a/main/php_globals.h b/main/php_globals.h index 8bb5792c82..b6e086ced3 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -86,7 +86,8 @@ struct _php_core_globals { zend_bool expose_php; zend_bool track_vars; - zend_bool gpc_globals; + zend_bool register_globals; + zend_bool register_argc_argv; zend_bool y2k_compliance; diff --git a/main/php_variables.c b/main/php_variables.c index b4355b4ee8..383442ab66 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -40,7 +40,7 @@ PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array E HashTable *symtable1=NULL; HashTable *symtable2=NULL; - if (PG(gpc_globals)) { + if (PG(register_globals)) { symtable1 = EG(active_symbol_table); } if (track_vars_array) { diff --git a/php.ini-dist b/php.ini-dist index 4714a1bb91..583f5df0bd 100644 --- a/php.ini-dist +++ b/php.ini-dist @@ -146,6 +146,10 @@ register_globals = On ; Whether or not to register the EGPCB variables as globa ; most sense when coupled with track_vars - in which case you can ; access all of the GPC variables through the $HTTP_*_VARS[], ; variables. +register_argv_argc = On ; This directive tells PHP whether to declare the argv&argc + ; variables (that would contain the GET information). If you + ; don't use these variables, you should turn it off for + ; increased performance track_vars = On ; enable the $HTTP_*_VARS[] arrays, where * is one of ; ENV, POST, GET, COOKIE or SERVER. gpc_order = "GPC" ; This directive is deprecated. Use variables_order instead. diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 4ed0442c43..2f35878086 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -153,6 +153,7 @@ static void sapi_cgi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS val = emalloc(l + 1); php_sprintf(val, "%s%s", (sn ? sn : ""), (pi ? pi : "")); /* SAFE */ php_register_variable(val, "PHP_SELF", track_vars_array ELS_CC PLS_CC); + efree(val); } #endif }