cvs: php4 /ext/standard basic_functions.c basic_functions.h /main main.c

From: Date: Wed, 08 Aug 2001 20:05:37 +0000
Subject: cvs: php4 /ext/standard basic_functions.c basic_functions.h /main main.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6664@lists.php.net to get a copy of this message
zeev Wed Aug 8 16:05:37 2001 EDT Modified files: /php4/ext/standard basic_functions.c basic_functions.h /php4/main main.c Log: Implement import_request_variables() Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.380 php4/ext/standard/basic_functions.c:1.381 --- php4/ext/standard/basic_functions.c:1.380 Tue Aug 7 15:44:44 2001 +++ php4/ext/standard/basic_functions.c Wed Aug 8 16:05:34 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.380 2001/08/07 19:44:44 andrei Exp $ */ +/* $Id: basic_functions.c,v 1.381 2001/08/08 20:05:34 zeev Exp $ */ #include "php.h" #include "php_main.h" @@ -371,6 +371,7 @@ PHP_FE(is_object, NULL) PHP_FE(is_scalar, NULL) PHP_FE(is_callable, third_arg_force_ref) + PHP_FE(import_request_variables, NULL) PHP_FE(error_log, NULL) PHP_FE(call_user_func, NULL) @@ -2610,6 +2611,90 @@ RETURN_BOOL(retval); } /* }}} */ + + +static int copy_request_variable(void *pDest, int num_args, va_list args, zend_hash_key *hash_key) +{ + char *prefix, *new_key; + uint prefix_len, new_key_len; + zval **var = (zval **) pDest; + TSRMLS_FETCH(); + + if (num_args!=2) { + return 0; + } + + prefix = va_arg(args, char *); + prefix_len = va_arg(args, uint); + + new_key_len = prefix_len + hash_key->nKeyLength; + new_key = (char *) emalloc(new_key_len); + + memcpy(new_key, prefix, prefix_len); + memcpy(new_key+prefix_len, hash_key->arKey, hash_key->nKeyLength); + + ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), new_key, new_key_len, *var, 0, 1); + + efree(new_key); + + return 0; +} + + +/* {{{ proto bool import_request_variables(string types, string prefix) + Import GET/POST/Cookie variables into the global scope */ +PHP_FUNCTION(import_request_variables) +{ + zval **z_types, **z_prefix; + char *types, *prefix; + uint prefix_len; + char *p; + + switch (ZEND_NUM_ARGS()) { + case 1: + if (zend_get_parameters_ex(1, &z_types)==FAILURE) { + RETURN_FALSE; + } + prefix = ""; + prefix_len = 0; + break; + case 2: + if (zend_get_parameters_ex(2, &z_types, &z_prefix)==FAILURE) { + RETURN_FALSE; + } + convert_to_string_ex(z_prefix); + prefix = Z_STRVAL_PP(z_prefix); + prefix_len = Z_STRLEN_PP(z_prefix); + break; + default: + ZEND_WRONG_PARAM_COUNT(); + } + + if (prefix_len==0) { + zend_error(E_NOTICE, "No prefix specified in %s() - possible security hazard", get_active_function_name(TSRMLS_C)); + } + + convert_to_string_ex(z_types); + types = Z_STRVAL_PP(z_types); + + for (p=types; p && *p; p++) { + switch (*p) { + case 'g': + case 'G': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + case 'p': + case 'P': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + case 'c': + case 'C': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + } + } +} /* Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.87 php4/ext/standard/basic_functions.h:1.88 --- php4/ext/standard/basic_functions.h:1.87 Sat Aug 4 12:53:57 2001 +++ php4/ext/standard/basic_functions.h Wed Aug 8 16:05:36 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.h,v 1.87 2001/08/04 16:53:57 thies Exp $ */ +/* $Id: basic_functions.h,v 1.88 2001/08/08 20:05:36 zeev Exp $ */ #ifndef BASIC_FUNCTIONS_H #define BASIC_FUNCTIONS_H @@ -77,6 +77,7 @@ PHP_FUNCTION(is_object); PHP_FUNCTION(is_scalar); PHP_FUNCTION(is_callable); +PHP_FUNCTION(import_request_variables); PHP_FUNCTION(error_log); Index: php4/main/main.c diff -u php4/main/main.c:1.402 php4/main/main.c:1.403 --- php4/main/main.c:1.402 Wed Aug 8 15:15:38 2001 +++ php4/main/main.c Wed Aug 8 16:05:37 2001 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.402 2001/08/08 19:15:38 zeev Exp $ */ +/* $Id: main.c,v 1.403 2001/08/08 20:05:37 zeev Exp $ */ /* {{{ includes */ @@ -105,6 +105,7 @@ sizeof("_FILES") }; +#define NUM_TRACK_VARS (sizeof(short_track_vars_names_length)/sizeof(int)) #define SAFE_FILENAME(f) ((f)?(f):"-") @@ -718,6 +719,15 @@ if (PG(modules_activated)) { zend_deactivate_modules(TSRMLS_C); } + + zend_try { + int i; + + for (i=0; i<NUM_TRACK_VARS; i++) { + zval_ptr_dtor(&PG(http_globals)[i]); + } + } zend_end_try(); + zend_deactivate(TSRMLS_C); @@ -891,7 +901,7 @@ } zuv.import_use_extension = ".php"; - for (i=0; i<6; i++) { + for (i=0; i<NUM_TRACK_VARS; i++) { zend_register_auto_global(short_track_vars_names[i], short_track_vars_names_length[i]-1 TSRMLS_CC); } zend_register_auto_global("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC); @@ -1057,7 +1067,7 @@ }; - for (i=0; i<6; i++) { + for (i=0; i<NUM_TRACK_VARS; i++) { PG(http_globals)[i] = NULL; } @@ -1118,7 +1128,7 @@ php_register_server_variables(TSRMLS_C); } - for (i=0; i<6; i++) { + for (i=0; i<NUM_TRACK_VARS; i++) { if (!PG(http_globals)[i]) { if (!initialized_dummy_track_vars_array) { ALLOC_ZVAL(dummy_track_vars_array); @@ -1133,6 +1143,7 @@ zend_hash_update(&EG(symbol_table), track_vars_names[i], track_vars_names_length[i], &PG(http_globals)[i], sizeof(zval *), NULL); PG(http_globals)[i]->refcount++; zend_hash_update(&EG(symbol_table), short_track_vars_names[i], short_track_vars_names_length[i], &PG(http_globals)[i], sizeof(zval *), NULL); + PG(http_globals)[i]->refcount++; } {

« previous php.cvs (#6664) next »