summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>1999-09-11 15:04:45 +0000
committerZeev Suraski <zeev@php.net>1999-09-11 15:04:45 +0000
commit15fee4d3a618ccdabc0d41da0ac5cb536b929f6f (patch)
tree069c7e8d30a1554c51bc5a42395b5ef63dca89c9
parent1b6ccfe86c3664a667ec03973970045f137e6e7d (diff)
downloadphp-git-15fee4d3a618ccdabc0d41da0ac5cb536b929f6f.tar.gz
- Seriously optimize and clean php_parse_gpc_data()
- Added gpc_globals directive to turn global definitions of GPC variables on/off (untested)
-rw-r--r--ChangeLog5
-rw-r--r--ext/standard/post.c142
-rw-r--r--main/main.c1
-rw-r--r--main/php_globals.h1
-rw-r--r--php.ini-dist18
5 files changed, 83 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index bb97ab5f56..7235587dd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,10 @@ PHP 4.0 CHANGE LOG ChangeLog
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? 1999, Version 4.0 Beta 3
-- Add versioning support for shared library (Sascha)
+- Added gpc_globals variable directive to php.ini. By default it is On, but
+ if it is set to Off, GET, POST and Cookie variables will not be inserted
+ to the global scope. Mostly makes sense when coupled with track_vars (Zeev)
+- Added versioning support for shared library (Sascha)
- Added second parameter to array_keys which specifies search value
for which the key should be returned (Andrey)
- Resourcified Informix driver (Danny)
diff --git a/ext/standard/post.c b/ext/standard/post.c
index ea119f08de..3baf66dfb8 100644
--- a/ext/standard/post.c
+++ b/ext/standard/post.c
@@ -13,6 +13,7 @@
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ | Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id: */
@@ -36,17 +37,23 @@
void php_parse_gpc_data(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC)
{
int var_type;
- char *ind, *tmp = NULL, *ret = NULL;
+ char *ind, *tmp = NULL, *array_index = NULL;
int var_len, val_len;
- pval *entry;
+ pval *gpc_element;
+ zend_bool do_insert;
+ if (!PG(gpc_globals) && !track_vars_array) {
+ /* we don't need track_vars, and we're not setting GPC globals either. */
+ return;
+ }
+
var_type = php3_check_ident_type(var);
if (var_type == GPC_INDEXED_ARRAY) {
ind = php3_get_ident_index(var);
if (PG(magic_quotes_gpc)) {
- ret = php_addslashes(ind, 0, NULL, 1);
+ array_index = php_addslashes(ind, 0, NULL, 1);
} else {
- ret = ind;
+ array_index = ind;
}
}
if (var_type & GPC_ARRAY) { /* array (indexed or not) */
@@ -82,93 +89,68 @@ void php_parse_gpc_data(char *val, char *var, pval *track_vars_array ELS_DC PLS_
}
if (var_type & GPC_ARRAY) {
- pval *arr1, *arr2;
- pval **arr_ptr;
+ pval *gpc_element;
+ pval **arr_ptr_ptr;
+ pval *array_element;
- /* If the array doesn't exist, create it */
- if (zend_hash_find(EG(active_symbol_table), var, var_len+1, (void **) &arr_ptr) == FAILURE) {
- arr1 = (pval *) emalloc(sizeof(pval));
- INIT_PZVAL(arr1);
- if (array_init(arr1)==FAILURE) {
- return;
- }
- zend_hash_update(EG(active_symbol_table), var, var_len+1, &arr1, sizeof(pval *), NULL);
- if (track_vars_array) {
- arr2 = (pval *) emalloc(sizeof(pval));
- INIT_PZVAL(arr2);
- if (array_init(arr2)==FAILURE) {
- return;
- }
- zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
- }
+ if (zend_hash_find(EG(active_symbol_table), var, var_len+1, (void **) &arr_ptr_ptr) == FAILURE) {
+ /* If the array doesn't exist, create it */
+ MAKE_STD_ZVAL(gpc_element);
+ array_init(gpc_element);
+ do_insert=1;
} else {
- if ((*arr_ptr)->type!=IS_ARRAY) {
- if (--(*arr_ptr) > 0) {
- *arr_ptr = (pval *) emalloc(sizeof(pval));
- INIT_PZVAL(*arr_ptr);
+ if ((*arr_ptr_ptr)->type!=IS_ARRAY) {
+ if (--(*arr_ptr_ptr)->refcount > 0) {
+ MAKE_STD_ZVAL(*arr_ptr_ptr);
} else {
- pval_destructor(*arr_ptr);
- }
- if (array_init(*arr_ptr)==FAILURE) {
- return;
+ zval_dtor(*arr_ptr_ptr);
}
- if (track_vars_array) {
- arr2 = (pval *) emalloc(sizeof(pval));
- INIT_PZVAL(arr2);
- if (array_init(arr2)==FAILURE) {
- return;
- }
- zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
- }
- }
- arr1 = *arr_ptr;
- if (track_vars_array && zend_hash_find(track_vars_array->value.ht, var, var_len+1, (void **) &arr_ptr) == FAILURE) {
- return;
+ array_init(*arr_ptr_ptr);
}
- arr2 = *arr_ptr;
+ gpc_element = *arr_ptr_ptr;
+ do_insert=0;
}
- /* Now create the element */
- entry = (pval *) emalloc(sizeof(pval));
- INIT_PZVAL(entry);
- entry->value.str.val = val;
- entry->value.str.len = val_len;
- entry->type = IS_STRING;
- /* And then insert it */
- if (ret) { /* array */
- if (php3_check_type(ret) == IS_LONG) { /* numeric index */
- zend_hash_index_update(arr1->value.ht, atol(ret), &entry, sizeof(pval *),NULL); /* s[ret]=tmp */
- if (track_vars_array) {
- zend_hash_index_update(arr2->value.ht, atol(ret), &entry, sizeof(pval *),NULL);
- entry->refcount++;
- }
- } else { /* associative index */
- zend_hash_update(arr1->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL); /* s["ret"]=tmp */
- if (track_vars_array) {
- zend_hash_update(arr2->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL);
- entry->refcount++;
- }
- }
- efree(ret);
- ret = NULL;
- } else { /* non-indexed array */
- zend_hash_next_index_insert(arr1->value.ht, &entry, sizeof(pval *),NULL);
- if (track_vars_array) {
- zend_hash_next_index_insert(arr2->value.ht, &entry, sizeof(pval *),NULL);
- entry->refcount++;
+ /* Create the element */
+ array_element = (pval *) emalloc(sizeof(pval));
+ INIT_PZVAL(array_element);
+ array_element->value.str.val = val;
+ array_element->value.str.len = val_len;
+ array_element->type = IS_STRING;
+
+ /* Insert it */
+ if (array_index) {
+ /* indexed array */
+ if (php3_check_type(array_index) == IS_LONG) {
+ /* numeric index */
+ zend_hash_index_update(gpc_element->value.ht, atol(array_index), &array_element, sizeof(pval *), NULL); /* s[array_index]=tmp */
+ } else {
+ /* associative index */
+ zend_hash_update(gpc_element->value.ht, array_index, strlen(array_index)+1, &array_element, sizeof(pval *), NULL); /* s["ret"]=tmp */
}
+ efree(array_index);
+ } else {
+ /* non-indexed array */
+ zend_hash_next_index_insert(gpc_element->value.ht, &array_element, sizeof(pval *), NULL);
}
} else { /* we have a normal variable */
- pval *entry = (pval *) emalloc(sizeof(pval));
-
- entry->type = IS_STRING;
- INIT_PZVAL(entry);
- entry->value.str.val = val;
- entry->value.str.len = val_len;
- zend_hash_update(EG(active_symbol_table), var, var_len+1, (void *) &entry, sizeof(pval *),NULL);
+ MAKE_STD_ZVAL(gpc_element);
+ gpc_element->type = IS_STRING;
+ gpc_element->refcount = 0;
+ gpc_element->value.str.val = val;
+ gpc_element->value.str.len = val_len;
+ do_insert=1;
+ }
+
+ if (do_insert) {
+ gpc_element->refcount = 0;
+ if (PG(gpc_globals)) {
+ zend_hash_update(EG(active_symbol_table), var, var_len+1, &gpc_element, sizeof(pval *), NULL);
+ gpc_element->refcount++;
+ }
if (track_vars_array) {
- entry->refcount++;
- zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &entry, sizeof(pval *), NULL);
+ zend_hash_update(EG(active_symbol_table), var, var_len+1, &gpc_element, sizeof(pval *), NULL);
+ gpc_element->refcount++;
}
}
}
diff --git a/main/main.c b/main/main.c
index 472e030087..d618205253 100644
--- a/main/main.c
+++ b/main/main.c
@@ -226,6 +226,7 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("memory_limit", "8388608", PHP_INI_ALL, OnChangeMemoryLimit)
STD_PHP_INI_BOOLEAN("track_vars", (PHP_TRACK_VARS?"1":"0"), PHP_INI_ALL, OnUpdateBool, track_vars, php_core_globals, core_globals)
+ STD_PHP_INI_BOOLEAN("gpc_globals", "1", PHP_INI_ALL, OnUpdateBool, gpc_globals, 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("arg_separator", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("ignore_user_abort", "1", PHP_INI_ALL, OnUpdateInt, ignore_user_abort, php_core_globals, core_globals)
diff --git a/main/php_globals.h b/main/php_globals.h
index 2ac448adeb..4086bcac1b 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -80,6 +80,7 @@ struct _php_core_globals {
char *gpc_order;
zend_bool track_vars;
+ zend_bool gpc_globals;
zend_bool y2k_compliance;
diff --git a/php.ini-dist b/php.ini-dist
index 2342219ad5..d125ef05fd 100644
--- a/php.ini-dist
+++ b/php.ini-dist
@@ -94,11 +94,23 @@ warn_plus_overloading = Off ; warn if the + operator is used with strings
;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
+gpc_order = "GPC" ; Order of evaluation of GET/POST/Cookie data. Later values override
+ ; earlier values (e.g., by default, POST variables override GET variables,
+ ; and Cookie variables override both POST and GET variables).
+gpc_globals = On ; Whether or not to define GET/POST/Cookie variables in the global
+ ; scope. You may want to turn this off if you don't want
+ ; to clutter your scripts' global scope with user data. This makes
+ ; most sense when coupled with track_vars - in which case you can
+ ; access all of the GPC variables through the $HTTP_GET_VARS[],
+ ; $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] variables.
+track_vars = On ; enable $HTTP_GET_VARS[], $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] arrays
+
+; Magic quotes
magic_quotes_gpc = On ; magic quotes for incoming GET/POST/Cookie data
magic_quotes_runtime= Off ; magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_sybase = Off ; Use Sybase-style magic quotes (escape ' with '' instead of \')
-track_vars = On ; enable $HTTP_GET_VARS[], $HTTP_POST_VARS[] and $HTTP_COOKIE_VARS[] arrays
-; automatically add files before or after any PHP 3.0 document
+
+; automatically add files before or after any PHP document
auto_prepend_file =
auto_append_file =
@@ -220,7 +232,7 @@ sybase.max_links = -1 ; maximum number of links (persistent+non persistent). -
;sybase.interface_file = "/usr/sybase/interfaces"
sybase.min_error_severity = 10 ; minimum error severity to display
sybase.min_message_severity = 10 ; minimum message severity to display
-sybase.compatability_mode = Off ; compatability mode with earlier versions of PHP 3.0.
+sybase.compatability_mode = Off ; compatability mode with old versions of PHP 3.0.
; If on, this will cause PHP to automatically assign types to results
; according to their Sybase type, instead of treating them all as
; strings. This compatability mode will probably not stay around