1999-04-22 02:48:28 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
1999-04-22 02:48:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2016-01-01 17:19:27 +00:00
| Copyright ( c ) 1997 - 2016 The PHP Group |
1999-04-22 02:48:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 12:51:34 +00:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 13:13:16 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-04-22 02:48:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Rasmus Lerdorf < rasmus @ lerdorf . on . ca > |
1999-09-11 15:04:45 +00:00
| Zeev Suraski < zeev @ zend . com > |
1999-04-22 02:48:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2003-02-19 08:40:19 +00:00
2001-04-06 01:50:40 +00:00
/* $Id$ */
1999-04-23 20:06:01 +00:00
1999-04-22 02:48:28 +00:00
# include <stdio.h>
# include "php.h"
2000-01-28 13:31:12 +00:00
# include "ext/standard/php_standard.h"
2003-03-03 19:37:09 +00:00
# include "ext/standard/credits.h"
2014-09-20 20:42:02 +00:00
# include "zend_smart_str.h"
2000-01-28 17:24:53 +00:00
# include "php_variables.h"
1999-04-22 02:48:28 +00:00
# include "php_globals.h"
2000-08-21 09:50:53 +00:00
# include "php_content_types.h"
1999-04-26 17:26:37 +00:00
# include "SAPI.h"
1999-04-22 02:48:28 +00:00
# include "zend_globals.h"
2013-09-18 13:14:36 +00:00
# ifdef PHP_WIN32
# include "win32 / php_inttypes.h"
# endif
1999-04-22 02:48:28 +00:00
2002-10-13 08:38:09 +00:00
/* for systems that need to override reading of environment variables */
2014-12-13 22:06:14 +00:00
void _php_import_environment_variables ( zval * array_ptr ) ;
PHPAPI void ( * php_import_environment_variables ) ( zval * array_ptr ) = _php_import_environment_variables ;
1999-04-22 02:48:28 +00:00
2014-12-13 22:06:14 +00:00
PHPAPI void php_register_variable ( char * var , char * strval , zval * track_vars_array )
2001-07-27 10:16:41 +00:00
{
2014-12-13 22:06:14 +00:00
php_register_variable_safe ( var , strval , strlen ( strval ) , track_vars_array ) ;
2000-12-12 10:47:47 +00:00
}
/* binary-safe version */
2014-12-13 22:06:14 +00:00
PHPAPI void php_register_variable_safe ( char * var , char * strval , size_t str_len , zval * track_vars_array )
2000-02-19 20:12:26 +00:00
{
zval new_entry ;
2002-08-08 03:08:54 +00:00
assert ( strval ! = NULL ) ;
2015-01-03 09:22:58 +00:00
2000-02-19 20:12:26 +00:00
/* Prepare value */
2014-08-25 17:24:55 +00:00
ZVAL_NEW_STR ( & new_entry , zend_string_init ( strval , str_len , 0 ) ) ;
2014-12-13 22:06:14 +00:00
php_register_variable_ex ( var , & new_entry , track_vars_array ) ;
2000-02-19 20:12:26 +00:00
}
2014-12-13 22:06:14 +00:00
PHPAPI void php_register_variable_ex ( char * var_name , zval * val , zval * track_vars_array )
1999-09-12 23:51:12 +00:00
{
char * p = NULL ;
2013-08-15 03:36:50 +00:00
char * ip = NULL ; /* index pointer */
2012-02-02 10:26:53 +00:00
char * index ;
2008-08-30 16:47:46 +00:00
char * var , * var_orig ;
2014-10-27 12:20:16 +00:00
size_t var_len , index_len ;
2014-02-10 06:04:30 +00:00
zval gpc_element , * gpc_element_p ;
2006-04-07 13:57:27 +00:00
zend_bool is_array = 0 ;
2005-04-23 19:30:29 +00:00
HashTable * symtable1 = NULL ;
2010-08-26 12:20:35 +00:00
ALLOCA_FLAG ( use_heap )
2000-09-05 19:06:29 +00:00
2008-08-30 18:27:29 +00:00
assert ( var_name ! = NULL ) ;
2008-08-30 22:26:09 +00:00
2014-03-17 19:15:22 +00:00
if ( track_vars_array & & Z_TYPE_P ( track_vars_array ) = = IS_ARRAY ) {
2002-12-07 16:05:27 +00:00
symtable1 = Z_ARRVAL_P ( track_vars_array ) ;
}
2010-04-21 01:27:22 +00:00
1999-09-12 23:51:12 +00:00
if ( ! symtable1 ) {
2000-09-05 19:06:29 +00:00
/* Nothing to do */
2000-02-19 20:12:26 +00:00
zval_dtor ( val ) ;
1999-09-12 23:51:12 +00:00
return ;
}
2006-04-07 13:57:27 +00:00
1999-09-12 23:51:12 +00:00
/* ignore leading spaces in the variable name */
2010-08-26 12:20:35 +00:00
while ( * var_name & & * var_name = = ' ' ) {
var_name + + ;
1999-09-12 23:51:12 +00:00
}
2015-01-03 09:22:58 +00:00
2010-08-26 12:20:35 +00:00
/*
* Prepare variable name
*/
var_len = strlen ( var_name ) ;
var = var_orig = do_alloca ( var_len + 1 , use_heap ) ;
memcpy ( var_orig , var_name , var_len + 1 ) ;
2006-04-07 13:57:27 +00:00
/* ensure that we don't have spaces or dots in the variable name (not binary safe) */
for ( p = var ; * p ; p + + ) {
if ( * p = = ' ' | | * p = = ' . ' ) {
* p = ' _ ' ;
} else if ( * p = = ' [ ' ) {
is_array = 1 ;
ip = p ;
* p = 0 ;
break ;
}
}
var_len = p - var ;
1999-09-12 23:51:12 +00:00
if ( var_len = = 0 ) { /* empty variable name, or variable name with a space in it */
2000-02-19 20:12:26 +00:00
zval_dtor ( val ) ;
2010-08-26 12:20:35 +00:00
free_alloca ( var_orig , use_heap ) ;
1999-09-12 23:51:12 +00:00
return ;
}
2005-09-28 22:39:52 +00:00
/* GLOBALS hijack attempt, reject parameter */
2015-02-13 19:20:39 +00:00
if ( symtable1 = = & EG ( symbol_table ) & &
2006-04-07 13:57:27 +00:00
var_len = = sizeof ( " GLOBALS " ) - 1 & &
! memcmp ( var , " GLOBALS " , sizeof ( " GLOBALS " ) - 1 ) ) {
2005-09-28 22:39:52 +00:00
zval_dtor ( val ) ;
2010-08-26 12:20:35 +00:00
free_alloca ( var_orig , use_heap ) ;
2005-09-28 22:39:52 +00:00
return ;
}
1999-09-12 23:51:12 +00:00
index = var ;
index_len = var_len ;
2006-04-07 13:57:27 +00:00
if ( is_array ) {
2007-03-02 21:58:05 +00:00
int nest_level = 0 ;
2006-04-07 13:57:27 +00:00
while ( 1 ) {
2005-08-10 23:33:10 +00:00
char * index_s ;
2014-10-27 12:20:16 +00:00
size_t new_idx_len = 0 ;
2002-12-29 21:02:17 +00:00
2007-03-02 22:03:05 +00:00
if ( + + nest_level > PG ( max_input_nesting_level ) ) {
2007-06-03 16:19:14 +00:00
HashTable * ht ;
2007-03-02 21:58:05 +00:00
/* too many levels of nesting */
2007-06-03 16:19:14 +00:00
if ( track_vars_array ) {
ht = Z_ARRVAL_P ( track_vars_array ) ;
2014-02-10 06:04:30 +00:00
zend_symtable_str_del ( ht , var , var_len ) ;
2007-06-03 16:19:14 +00:00
}
zval_dtor ( val ) ;
2007-07-18 11:46:50 +00:00
/* do not output the error message to the screen,
this helps us to to avoid " information disclosure " */
2007-06-03 16:19:14 +00:00
if ( ! PG ( display_errors ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Input variable nesting level exceeded " ZEND_LONG_FMT " . To increase the limit change max_input_nesting_level in php.ini. " , PG ( max_input_nesting_level ) ) ;
2007-06-03 16:19:14 +00:00
}
2010-08-26 12:20:35 +00:00
free_alloca ( var_orig , use_heap ) ;
2007-06-03 16:19:14 +00:00
return ;
2007-03-02 21:58:05 +00:00
}
2002-12-29 21:02:17 +00:00
ip + + ;
index_s = ip ;
if ( isspace ( * ip ) ) {
ip + + ;
}
if ( * ip = = ' ] ' ) {
index_s = NULL ;
} else {
ip = strchr ( ip , ' ] ' ) ;
if ( ! ip ) {
/* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
* ( index_s - 1 ) = ' _ ' ;
2004-10-18 15:05:06 +00:00
2007-06-03 16:19:14 +00:00
index_len = 0 ;
2004-10-18 15:05:06 +00:00
if ( index ) {
2007-06-03 16:19:14 +00:00
index_len = strlen ( index ) ;
2004-10-18 15:05:06 +00:00
}
2002-12-29 21:02:17 +00:00
goto plain_var ;
return ;
}
* ip = 0 ;
2015-01-03 09:22:58 +00:00
new_idx_len = strlen ( index_s ) ;
2002-12-29 21:02:17 +00:00
}
1999-09-12 23:51:12 +00:00
if ( ! index ) {
2014-02-10 06:04:30 +00:00
array_init ( & gpc_element ) ;
if ( ( gpc_element_p = zend_hash_next_index_insert ( symtable1 , & gpc_element ) ) = = NULL ) {
2012-02-02 10:26:53 +00:00
zval_ptr_dtor ( & gpc_element ) ;
zval_dtor ( val ) ;
free_alloca ( var_orig , use_heap ) ;
return ;
}
1999-09-12 23:51:12 +00:00
} else {
2014-03-26 14:07:31 +00:00
gpc_element_p = zend_symtable_str_find ( symtable1 , index , index_len ) ;
if ( ! gpc_element_p ) {
zval tmp ;
array_init ( & tmp ) ;
gpc_element_p = zend_symtable_str_update_ind ( symtable1 , index , index_len , & tmp ) ;
} else {
if ( Z_TYPE_P ( gpc_element_p ) = = IS_INDIRECT ) {
gpc_element_p = Z_INDIRECT_P ( gpc_element_p ) ;
}
if ( Z_TYPE_P ( gpc_element_p ) ! = IS_ARRAY ) {
zval_ptr_dtor ( gpc_element_p ) ;
array_init ( gpc_element_p ) ;
}
1999-09-12 23:51:12 +00:00
}
}
2014-02-10 06:04:30 +00:00
symtable1 = Z_ARRVAL_P ( gpc_element_p ) ;
1999-09-12 23:51:12 +00:00
/* ip pointed to the '[' character, now obtain the key */
2002-12-29 21:02:17 +00:00
index = index_s ;
index_len = new_idx_len ;
1999-09-12 23:51:12 +00:00
ip + + ;
2005-04-23 19:30:29 +00:00
if ( * ip = = ' [ ' ) {
1999-09-12 23:51:12 +00:00
is_array = 1 ;
* ip = 0 ;
} else {
2006-05-03 11:24:29 +00:00
goto plain_var ;
1999-09-12 23:51:12 +00:00
}
2006-04-07 13:57:27 +00:00
}
} else {
2002-12-29 21:02:17 +00:00
plain_var :
2014-02-10 06:04:30 +00:00
ZVAL_COPY_VALUE ( & gpc_element , val ) ;
2006-04-07 13:57:27 +00:00
if ( ! index ) {
2014-02-10 06:04:30 +00:00
if ( ( gpc_element_p = zend_hash_next_index_insert ( symtable1 , & gpc_element ) ) = = NULL ) {
2012-02-02 10:26:53 +00:00
zval_ptr_dtor ( & gpc_element ) ;
}
2006-04-07 13:57:27 +00:00
} else {
2015-01-03 09:22:58 +00:00
/*
2006-04-07 13:57:27 +00:00
* According to rfc2965 , more specific paths are listed above the less specific ones .
* If we encounter a duplicate cookie name , we should skip it , since it is not possible
* to have the same ( plain text ) cookie name for the same path and we should not overwrite
* more specific cookies with the less specific ones .
*/
2014-02-10 06:04:30 +00:00
if ( Z_TYPE ( PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ! = IS_UNDEF & &
symtable1 = = Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) & &
zend_symtable_str_exists ( symtable1 , index , index_len ) ) {
2006-04-07 13:57:27 +00:00
zval_ptr_dtor ( & gpc_element ) ;
1999-09-12 23:51:12 +00:00
} else {
2014-03-26 14:07:31 +00:00
gpc_element_p = zend_symtable_str_update_ind ( symtable1 , index , index_len , & gpc_element ) ;
1999-09-12 23:51:12 +00:00
}
}
}
2010-08-26 12:20:35 +00:00
free_alloca ( var_orig , use_heap ) ;
1999-09-12 23:51:12 +00:00
}
2013-08-14 12:42:36 +00:00
typedef struct post_var_data {
smart_str str ;
char * ptr ;
char * end ;
uint64_t cnt ;
} post_var_data_t ;
2014-12-13 22:06:14 +00:00
static zend_bool add_post_var ( zval * arr , post_var_data_t * var , zend_bool eof )
2013-08-14 12:42:36 +00:00
{
2014-09-09 04:54:23 +00:00
char * ksep , * vsep , * val ;
2013-08-14 12:42:36 +00:00
size_t klen , vlen ;
2014-08-25 18:22:49 +00:00
size_t new_vlen ;
2013-08-14 12:42:36 +00:00
if ( var - > ptr > = var - > end ) {
return 0 ;
}
vsep = memchr ( var - > ptr , ' & ' , var - > end - var - > ptr ) ;
if ( ! vsep ) {
if ( ! eof ) {
return 0 ;
} else {
vsep = var - > end ;
}
}
ksep = memchr ( var - > ptr , ' = ' , vsep - var - > ptr ) ;
if ( ksep ) {
* ksep = ' \0 ' ;
/* "foo=bar&" or "foo=&" */
klen = ksep - var - > ptr ;
vlen = vsep - + + ksep ;
} else {
ksep = " " ;
/* "foo&" */
klen = vsep - var - > ptr ;
vlen = 0 ;
}
php_url_decode ( var - > ptr , klen ) ;
2014-09-09 04:54:23 +00:00
val = estrndup ( ksep , vlen ) ;
2013-08-14 12:42:36 +00:00
if ( vlen ) {
2014-09-09 04:54:23 +00:00
vlen = php_url_decode ( val , vlen ) ;
2013-08-14 12:42:36 +00:00
}
2014-12-13 22:06:14 +00:00
if ( sapi_module . input_filter ( PARSE_POST , var - > ptr , & val , vlen , & new_vlen ) ) {
php_register_variable_safe ( var - > ptr , val , new_vlen , arr ) ;
2013-08-14 12:42:36 +00:00
}
2014-09-09 04:54:23 +00:00
efree ( val ) ;
2013-08-14 12:42:36 +00:00
var - > ptr = vsep + ( vsep ! = var - > end ) ;
return 1 ;
}
2014-12-13 22:06:14 +00:00
static inline int add_post_vars ( zval * arr , post_var_data_t * vars , zend_bool eof )
2013-08-14 12:42:36 +00:00
{
uint64_t max_vars = PG ( max_input_vars ) ;
2015-06-30 10:59:27 +00:00
vars - > ptr = ZSTR_VAL ( vars - > str . s ) ;
vars - > end = ZSTR_VAL ( vars - > str . s ) + ZSTR_LEN ( vars - > str . s ) ;
2014-12-13 22:06:14 +00:00
while ( add_post_var ( arr , vars , eof ) ) {
2013-08-14 12:42:36 +00:00
if ( + + vars - > cnt > max_vars ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING ,
2013-08-14 12:42:36 +00:00
" Input variables exceeded % " PRIu64 " . "
" To increase the limit change max_input_vars in php.ini. " ,
max_vars ) ;
return FAILURE ;
}
}
if ( ! eof ) {
2015-06-30 10:59:27 +00:00
memmove ( ZSTR_VAL ( vars - > str . s ) , vars - > ptr , ZSTR_LEN ( vars - > str . s ) = vars - > end - vars - > ptr ) ;
2013-08-14 12:42:36 +00:00
}
return SUCCESS ;
}
2015-05-23 16:44:39 +00:00
# ifdef PHP_WIN32
# define SAPI_POST_HANDLER_BUFSIZ 16384
# else
# define SAPI_POST_HANDLER_BUFSIZ BUFSIZ
# endif
2001-08-15 18:01:48 +00:00
SAPI_API SAPI_POST_HANDLER_FUNC ( php_std_post_handler )
2000-02-17 20:23:59 +00:00
{
2013-08-14 12:42:36 +00:00
zval * arr = ( zval * ) arg ;
php_stream * s = SG ( request_info ) . request_body ;
post_var_data_t post_data ;
2000-02-17 20:23:59 +00:00
2013-08-14 12:42:36 +00:00
if ( s & & SUCCESS = = php_stream_rewind ( s ) ) {
memset ( & post_data , 0 , sizeof ( post_data ) ) ;
2002-07-24 11:25:36 +00:00
2013-08-14 12:42:36 +00:00
while ( ! php_stream_eof ( s ) ) {
2015-05-23 16:44:39 +00:00
char buf [ SAPI_POST_HANDLER_BUFSIZ ] = { 0 } ;
size_t len = php_stream_read ( s , buf , SAPI_POST_HANDLER_BUFSIZ ) ;
2000-02-17 20:23:59 +00:00
2013-08-14 12:42:36 +00:00
if ( len & & len ! = ( size_t ) - 1 ) {
smart_str_appendl ( & post_data . str , buf , len ) ;
2000-12-12 10:47:47 +00:00
2014-12-13 22:06:14 +00:00
if ( SUCCESS ! = add_post_vars ( arr , & post_data , 0 ) ) {
2014-07-03 15:58:21 +00:00
smart_str_free ( & post_data . str ) ;
2013-08-14 12:42:36 +00:00
return ;
}
2012-02-14 08:58:52 +00:00
}
2013-08-14 12:42:36 +00:00
2015-05-23 16:44:39 +00:00
if ( len ! = SAPI_POST_HANDLER_BUFSIZ ) {
2013-08-14 12:42:36 +00:00
break ;
2003-11-26 09:53:22 +00:00
}
2000-02-17 20:23:59 +00:00
}
2013-08-14 12:42:36 +00:00
2014-02-18 09:42:46 +00:00
if ( post_data . str . s ) {
2014-12-13 22:06:14 +00:00
add_post_vars ( arr , & post_data , 1 ) ;
2014-02-18 09:42:46 +00:00
smart_str_free ( & post_data . str ) ;
2013-08-14 12:42:36 +00:00
}
2000-02-17 20:23:59 +00:00
}
}
2015-05-23 16:44:39 +00:00
# undef SAPI_POST_HANDLER_BUFSIZ
2000-02-17 20:23:59 +00:00
2003-02-19 19:41:09 +00:00
SAPI_API SAPI_INPUT_FILTER_FUNC ( php_default_input_filter )
{
/* TODO: check .ini setting here and apply user-defined input filter */
2005-07-25 22:37:35 +00:00
if ( new_val_len ) * new_val_len = val_len ;
2003-12-01 19:25:07 +00:00
return 1 ;
2003-02-19 19:41:09 +00:00
}
2002-08-02 06:53:48 +00:00
SAPI_API SAPI_TREAT_DATA_FUNC ( php_default_treat_data )
1999-04-22 02:48:28 +00:00
{
2005-04-23 19:30:29 +00:00
char * res = NULL , * var , * val , * separator = NULL ;
2000-11-02 15:47:02 +00:00
const char * c_var ;
2014-02-10 06:04:30 +00:00
zval array ;
2005-04-23 19:30:29 +00:00
int free_buffer = 0 ;
1999-11-26 13:34:31 +00:00
char * strtok_buf = NULL ;
2014-08-25 17:24:55 +00:00
zend_long count = 0 ;
2015-01-03 09:22:58 +00:00
2014-03-17 19:15:22 +00:00
ZVAL_UNDEF ( & array ) ;
1999-04-22 02:48:28 +00:00
switch ( arg ) {
case PARSE_POST :
case PARSE_GET :
case PARSE_COOKIE :
2014-02-10 06:04:30 +00:00
array_init ( & array ) ;
2000-09-05 19:06:29 +00:00
switch ( arg ) {
case PARSE_POST :
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_POST ] ) ;
ZVAL_COPY_VALUE ( & PG ( http_globals ) [ TRACK_VARS_POST ] , & array ) ;
2000-09-05 19:06:29 +00:00
break ;
case PARSE_GET :
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_GET ] ) ;
ZVAL_COPY_VALUE ( & PG ( http_globals ) [ TRACK_VARS_GET ] , & array ) ;
2000-09-05 19:06:29 +00:00
break ;
case PARSE_COOKIE :
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ;
ZVAL_COPY_VALUE ( & PG ( http_globals ) [ TRACK_VARS_COOKIE ] , & array ) ;
2000-09-05 19:06:29 +00:00
break ;
1999-04-22 02:48:28 +00:00
}
break ;
default :
2014-02-10 06:04:30 +00:00
ZVAL_COPY_VALUE ( & array , destArray ) ;
1999-04-22 02:48:28 +00:00
break ;
}
2005-04-23 19:30:29 +00:00
if ( arg = = PARSE_POST ) {
2014-12-13 22:06:14 +00:00
sapi_handle_post ( & array ) ;
2000-02-17 20:23:59 +00:00
return ;
}
if ( arg = = PARSE_GET ) { /* GET data */
2000-11-02 15:47:02 +00:00
c_var = SG ( request_info ) . query_string ;
if ( c_var & & * c_var ) {
res = ( char * ) estrdup ( c_var ) ;
1999-05-09 18:40:59 +00:00
free_buffer = 1 ;
} else {
free_buffer = 0 ;
1999-04-22 02:48:28 +00:00
}
} else if ( arg = = PARSE_COOKIE ) { /* Cookie data */
2000-11-02 15:47:02 +00:00
c_var = SG ( request_info ) . cookie_data ;
if ( c_var & & * c_var ) {
res = ( char * ) estrdup ( c_var ) ;
1999-05-09 18:40:59 +00:00
free_buffer = 1 ;
} else {
free_buffer = 0 ;
1999-04-22 02:48:28 +00:00
}
} else if ( arg = = PARSE_STRING ) { /* String data */
res = str ;
1999-05-09 18:40:59 +00:00
free_buffer = 1 ;
1999-04-22 02:48:28 +00:00
}
2000-02-17 20:23:59 +00:00
1999-04-22 02:48:28 +00:00
if ( ! res ) {
return ;
}
2001-04-04 20:46:26 +00:00
switch ( arg ) {
case PARSE_GET :
case PARSE_STRING :
separator = ( char * ) estrdup ( PG ( arg_separator ) . input ) ;
break ;
case PARSE_COOKIE :
2005-07-18 19:18:03 +00:00
separator = " ; \0 " ;
2001-04-04 20:46:26 +00:00
break ;
}
2015-01-03 09:22:58 +00:00
2001-04-04 00:37:06 +00:00
var = php_strtok_r ( res , separator , & strtok_buf ) ;
2015-01-03 09:22:58 +00:00
2000-02-17 20:23:59 +00:00
while ( var ) {
val = strchr ( var , ' = ' ) ;
2006-12-09 13:01:23 +00:00
if ( arg = = PARSE_COOKIE ) {
/* Remove leading spaces from cookie names, needed for multi-cookie header where ; can be followed by a space */
while ( isspace ( * var ) ) {
var + + ;
}
if ( var = = val | | * var = = ' \0 ' ) {
goto next_cookie ;
}
}
2012-02-14 08:58:52 +00:00
if ( + + count > PG ( max_input_vars ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Input variables exceeded " ZEND_LONG_FMT " . To increase the limit change max_input_vars in php.ini. " , PG ( max_input_vars ) ) ;
2012-02-14 08:58:52 +00:00
break ;
}
2000-02-17 20:23:59 +00:00
if ( val ) { /* have a value */
2014-08-25 18:22:49 +00:00
size_t val_len ;
size_t new_val_len ;
2000-12-12 10:47:47 +00:00
2000-02-17 20:23:59 +00:00
* val + + = ' \0 ' ;
php_url_decode ( var , strlen ( var ) ) ;
2002-09-08 00:27:05 +00:00
val_len = php_url_decode ( val , strlen ( val ) ) ;
2004-06-26 08:09:28 +00:00
val = estrndup ( val , val_len ) ;
2014-12-13 22:06:14 +00:00
if ( sapi_module . input_filter ( arg , var , & val , val_len , & new_val_len ) ) {
php_register_variable_safe ( var , val , new_val_len , & array ) ;
2003-11-26 09:53:22 +00:00
}
2004-06-26 08:09:28 +00:00
efree ( val ) ;
2002-07-31 16:25:12 +00:00
} else {
2014-08-25 18:22:49 +00:00
size_t val_len ;
size_t new_val_len ;
2004-07-11 21:14:50 +00:00
2002-09-07 21:04:14 +00:00
php_url_decode ( var , strlen ( var ) ) ;
2004-07-11 20:13:39 +00:00
val_len = 0 ;
val = estrndup ( " " , val_len ) ;
2014-12-13 22:06:14 +00:00
if ( sapi_module . input_filter ( arg , var , & val , val_len , & new_val_len ) ) {
php_register_variable_safe ( var , val , new_val_len , & array ) ;
2004-07-11 20:13:39 +00:00
}
efree ( val ) ;
2002-07-28 04:18:40 +00:00
}
2006-12-09 13:01:23 +00:00
next_cookie :
2001-04-04 00:37:06 +00:00
var = php_strtok_r ( NULL , separator , & strtok_buf ) ;
1999-04-22 02:48:28 +00:00
}
2001-04-04 20:46:26 +00:00
2005-04-23 19:30:29 +00:00
if ( arg ! = PARSE_COOKIE ) {
2001-04-04 20:46:26 +00:00
efree ( separator ) ;
}
1999-05-09 18:40:59 +00:00
if ( free_buffer ) {
efree ( res ) ;
}
1999-04-22 02:48:28 +00:00
}
2014-12-13 22:06:14 +00:00
void _php_import_environment_variables ( zval * array_ptr )
2000-01-28 17:24:53 +00:00
{
2003-03-27 21:13:47 +00:00
char buf [ 128 ] ;
char * * env , * p , * t = buf ;
size_t alloc_size = sizeof ( buf ) ;
2003-03-28 17:09:04 +00:00
unsigned long nlen ; /* ptrdiff_t is not portable */
2003-03-27 21:13:47 +00:00
2000-01-28 17:24:53 +00:00
for ( env = environ ; env ! = NULL & & * env ! = NULL ; env + + ) {
p = strchr ( * env , ' = ' ) ;
if ( ! p ) { /* malformed entry? */
continue ;
}
2003-03-27 21:13:47 +00:00
nlen = p - * env ;
if ( nlen > = alloc_size ) {
alloc_size = nlen + 64 ;
t = ( t = = buf ? emalloc ( alloc_size ) : erealloc ( t , alloc_size ) ) ;
}
memcpy ( t , * env , nlen ) ;
t [ nlen ] = ' \0 ' ;
2014-12-13 22:06:14 +00:00
php_register_variable ( t , p + 1 , array_ptr ) ;
2003-03-27 21:13:47 +00:00
}
if ( t ! = buf & & t ! = NULL ) {
2000-01-28 17:24:53 +00:00
efree ( t ) ;
}
}
2014-12-13 22:06:14 +00:00
zend_bool php_std_auto_global_callback ( char * name , uint name_len )
2003-03-02 10:19:15 +00:00
{
zend_printf ( " %s \n " , name ) ;
return 0 ; /* don't rearm */
}
/* {{{ php_build_argv
*/
2015-07-24 15:17:09 +00:00
PHPAPI void php_build_argv ( char * s , zval * track_vars_array )
2003-03-02 10:19:15 +00:00
{
2014-02-10 06:04:30 +00:00
zval arr , argc , tmp ;
2003-03-02 10:19:15 +00:00
int count = 0 ;
char * ss , * space ;
2015-01-03 09:22:58 +00:00
2010-04-21 01:27:22 +00:00
if ( ! ( SG ( request_info ) . argc | | track_vars_array ) ) {
2003-10-01 23:11:59 +00:00
return ;
}
2015-01-03 09:22:58 +00:00
2014-02-10 06:04:30 +00:00
array_init ( & arr ) ;
2003-03-02 10:19:15 +00:00
/* Prepare argv */
if ( SG ( request_info ) . argc ) { /* are we in cli sapi? */
int i ;
2005-04-23 19:30:29 +00:00
for ( i = 0 ; i < SG ( request_info ) . argc ; i + + ) {
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & tmp , SG ( request_info ) . argv [ i ] ) ;
2015-01-03 09:22:58 +00:00
if ( zend_hash_next_index_insert ( Z_ARRVAL ( arr ) , & tmp ) = = NULL ) {
2014-08-25 17:24:55 +00:00
zend_string_free ( Z_STR ( tmp ) ) ;
2003-03-02 10:19:15 +00:00
}
}
} else if ( s & & * s ) {
ss = s ;
while ( ss ) {
space = strchr ( ss , ' + ' ) ;
if ( space ) {
* space = ' \0 ' ;
}
/* auto-type */
2014-02-10 06:04:30 +00:00
ZVAL_STRING ( & tmp , ss ) ;
2003-03-02 10:19:15 +00:00
count + + ;
2014-02-10 06:04:30 +00:00
if ( zend_hash_next_index_insert ( Z_ARRVAL ( arr ) , & tmp ) = = NULL ) {
2014-08-25 17:24:55 +00:00
zend_string_free ( Z_STR ( tmp ) ) ;
2003-03-02 10:19:15 +00:00
}
if ( space ) {
* space = ' + ' ;
ss = space + 1 ;
} else {
ss = space ;
}
}
}
/* prepare argc */
if ( SG ( request_info ) . argc ) {
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & argc , SG ( request_info ) . argc ) ;
2003-03-02 10:19:15 +00:00
} else {
2014-08-25 17:24:55 +00:00
ZVAL_LONG ( & argc , count ) ;
2003-03-02 10:19:15 +00:00
}
2010-04-21 01:27:22 +00:00
if ( SG ( request_info ) . argc ) {
2014-02-10 06:04:30 +00:00
Z_ADDREF ( arr ) ;
2015-02-13 19:20:39 +00:00
zend_hash_str_update ( & EG ( symbol_table ) , " argv " , sizeof ( " argv " ) - 1 , & arr ) ;
zend_hash_str_add ( & EG ( symbol_table ) , " argc " , sizeof ( " argc " ) - 1 , & argc ) ;
2015-01-03 09:22:58 +00:00
}
2014-02-17 13:59:18 +00:00
if ( track_vars_array & & Z_TYPE_P ( track_vars_array ) = = IS_ARRAY ) {
2014-02-10 06:04:30 +00:00
Z_ADDREF ( arr ) ;
2014-02-17 13:59:18 +00:00
zend_hash_str_update ( Z_ARRVAL_P ( track_vars_array ) , " argv " , sizeof ( " argv " ) - 1 , & arr ) ;
zend_hash_str_update ( Z_ARRVAL_P ( track_vars_array ) , " argc " , sizeof ( " argc " ) - 1 , & argc ) ;
2003-03-02 10:19:15 +00:00
}
2006-04-18 06:58:43 +00:00
zval_ptr_dtor ( & arr ) ;
2003-03-02 10:19:15 +00:00
}
/* }}} */
/* {{{ php_register_server_variables
*/
2014-12-13 22:06:14 +00:00
static inline void php_register_server_variables ( void )
2003-03-02 10:19:15 +00:00
{
2015-07-31 12:02:03 +00:00
zval request_time_float , request_time_long ;
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-03-02 10:19:15 +00:00
/* Server variables */
if ( sapi_module . register_server_variables ) {
2014-12-13 22:06:14 +00:00
sapi_module . register_server_variables ( & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-03-02 10:19:15 +00:00
}
/* PHP Authentication support */
if ( SG ( request_info ) . auth_user ) {
2014-12-13 22:06:14 +00:00
php_register_variable ( " PHP_AUTH_USER " , SG ( request_info ) . auth_user , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-03-02 10:19:15 +00:00
}
if ( SG ( request_info ) . auth_password ) {
2014-12-13 22:06:14 +00:00
php_register_variable ( " PHP_AUTH_PW " , SG ( request_info ) . auth_password , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-03-02 10:19:15 +00:00
}
2005-04-04 15:06:36 +00:00
if ( SG ( request_info ) . auth_digest ) {
2014-12-13 22:06:14 +00:00
php_register_variable ( " PHP_AUTH_DIGEST " , SG ( request_info ) . auth_digest , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2005-04-04 15:06:36 +00:00
}
2004-10-24 17:41:13 +00:00
2015-07-31 12:02:03 +00:00
/* store request init time */
ZVAL_DOUBLE ( & request_time_float , sapi_get_request_time ( ) ) ;
php_register_variable_ex ( " REQUEST_TIME_FLOAT " , & request_time_float , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
ZVAL_LONG ( & request_time_long , zend_dval_to_lval ( Z_DVAL ( request_time_float ) ) ) ;
php_register_variable_ex ( " REQUEST_TIME " , & request_time_long , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-03-02 10:19:15 +00:00
}
/* }}} */
2003-07-21 17:42:24 +00:00
/* {{{ php_autoglobal_merge
*/
2014-12-13 22:06:14 +00:00
static void php_autoglobal_merge ( HashTable * dest , HashTable * src )
2003-07-21 17:42:24 +00:00
{
2014-02-10 06:04:30 +00:00
zval * src_entry , * dest_entry ;
zend_string * string_key ;
2014-08-25 17:24:55 +00:00
zend_ulong num_key ;
2015-02-13 19:20:39 +00:00
int globals_check = ( dest = = ( & EG ( symbol_table ) ) ) ;
2003-07-21 17:42:24 +00:00
2014-05-07 09:06:27 +00:00
ZEND_HASH_FOREACH_KEY_VAL ( src , num_key , string_key , src_entry ) {
2014-02-10 06:04:30 +00:00
if ( Z_TYPE_P ( src_entry ) ! = IS_ARRAY
2014-05-07 09:06:27 +00:00
| | ( string_key & & ( dest_entry = zend_hash_find ( dest , string_key ) ) = = NULL )
| | ( string_key = = NULL & & ( dest_entry = zend_hash_index_find ( dest , num_key ) ) = = NULL )
2014-05-07 08:52:58 +00:00
| | Z_TYPE_P ( dest_entry ) ! = IS_ARRAY ) {
if ( Z_REFCOUNTED_P ( src_entry ) ) {
Z_ADDREF_P ( src_entry ) ;
}
2014-05-07 09:06:27 +00:00
if ( string_key ) {
2015-06-30 10:59:27 +00:00
if ( ! globals_check | | ZSTR_LEN ( string_key ) ! = sizeof ( " GLOBALS " ) - 1
| | memcmp ( ZSTR_VAL ( string_key ) , " GLOBALS " , sizeof ( " GLOBALS " ) - 1 ) ) {
2014-02-10 06:04:30 +00:00
zend_hash_update ( dest , string_key , src_entry ) ;
2014-05-07 08:52:58 +00:00
} else if ( Z_REFCOUNTED_P ( src_entry ) ) {
2014-02-10 06:04:30 +00:00
Z_DELREF_P ( src_entry ) ;
2005-02-17 04:44:11 +00:00
}
2003-07-21 17:42:24 +00:00
} else {
2014-02-10 06:04:30 +00:00
zend_hash_index_update ( dest , num_key , src_entry ) ;
2003-07-21 17:42:24 +00:00
}
} else {
2015-09-29 08:17:43 +00:00
SEPARATE_ARRAY ( dest_entry ) ;
2014-12-13 22:06:14 +00:00
php_autoglobal_merge ( Z_ARRVAL_P ( dest_entry ) , Z_ARRVAL_P ( src_entry ) ) ;
2003-07-21 17:42:24 +00:00
}
2014-05-07 09:06:27 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2003-07-21 17:42:24 +00:00
}
/* }}} */
2003-03-02 10:19:15 +00:00
/* {{{ php_hash_environment
*/
2014-12-13 22:06:14 +00:00
PHPAPI int php_hash_environment ( void )
2003-03-02 10:19:15 +00:00
{
2010-07-08 14:05:11 +00:00
memset ( PG ( http_globals ) , 0 , sizeof ( PG ( http_globals ) ) ) ;
2014-12-13 22:06:14 +00:00
zend_activate_auto_globals ( ) ;
2003-10-01 23:11:59 +00:00
if ( PG ( register_argc_argv ) ) {
2014-12-13 22:06:14 +00:00
php_build_argv ( SG ( request_info ) . query_string , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2003-10-01 23:11:59 +00:00
}
2010-07-08 14:05:11 +00:00
return SUCCESS ;
}
/* }}} */
2003-10-01 23:11:59 +00:00
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_get ( zend_string * name )
2010-07-08 14:05:11 +00:00
{
if ( PG ( variables_order ) & & ( strchr ( PG ( variables_order ) , ' G ' ) | | strchr ( PG ( variables_order ) , ' g ' ) ) ) {
2014-12-13 22:06:14 +00:00
sapi_module . treat_data ( PARSE_GET , NULL , NULL ) ;
2010-07-08 14:05:11 +00:00
} else {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_GET ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_GET ] ) ;
2010-07-08 14:05:11 +00:00
}
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_GET ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_GET ] ) ;
2015-01-03 09:22:58 +00:00
2010-07-08 14:05:11 +00:00
return 0 ; /* don't rearm */
}
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_post ( zend_string * name )
2010-07-08 14:05:11 +00:00
{
if ( PG ( variables_order ) & &
2011-08-23 18:32:53 +00:00
( strchr ( PG ( variables_order ) , ' P ' ) | | strchr ( PG ( variables_order ) , ' p ' ) ) & &
2010-07-08 14:05:11 +00:00
! SG ( headers_sent ) & &
SG ( request_info ) . request_method & &
! strcasecmp ( SG ( request_info ) . request_method , " POST " ) ) {
2014-12-13 22:06:14 +00:00
sapi_module . treat_data ( PARSE_POST , NULL , NULL ) ;
2010-07-08 14:05:11 +00:00
} else {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_POST ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_POST ] ) ;
2010-07-08 14:05:11 +00:00
}
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_POST ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_POST ] ) ;
2015-01-03 09:22:58 +00:00
2010-07-08 14:05:11 +00:00
return 0 ; /* don't rearm */
}
2003-03-02 10:19:15 +00:00
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_cookie ( zend_string * name )
2010-07-08 14:05:11 +00:00
{
if ( PG ( variables_order ) & & ( strchr ( PG ( variables_order ) , ' C ' ) | | strchr ( PG ( variables_order ) , ' c ' ) ) ) {
2014-12-13 22:06:14 +00:00
sapi_module . treat_data ( PARSE_COOKIE , NULL , NULL ) ;
2010-07-08 14:05:11 +00:00
} else {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ;
2003-03-02 10:19:15 +00:00
}
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ;
2015-01-03 09:22:58 +00:00
2010-07-08 14:05:11 +00:00
return 0 ; /* don't rearm */
}
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_files ( zend_string * name )
2010-07-08 14:05:11 +00:00
{
2014-02-10 06:04:30 +00:00
if ( Z_TYPE ( PG ( http_globals ) [ TRACK_VARS_FILES ] ) = = IS_UNDEF ) {
array_init ( & PG ( http_globals ) [ TRACK_VARS_FILES ] ) ;
2003-03-02 10:19:15 +00:00
}
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_FILES ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_FILES ] ) ;
2015-01-03 09:22:58 +00:00
2010-07-08 14:05:11 +00:00
return 0 ; /* don't rearm */
2003-03-02 10:19:15 +00:00
}
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_server ( zend_string * name )
2003-03-02 10:19:15 +00:00
{
2005-09-01 19:15:19 +00:00
if ( PG ( variables_order ) & & ( strchr ( PG ( variables_order ) , ' S ' ) | | strchr ( PG ( variables_order ) , ' s ' ) ) ) {
2014-12-13 22:06:14 +00:00
php_register_server_variables ( ) ;
2006-03-20 10:15:02 +00:00
if ( PG ( register_argc_argv ) ) {
if ( SG ( request_info ) . argc ) {
2014-02-10 06:04:30 +00:00
zval * argc , * argv ;
2015-01-03 09:22:58 +00:00
2015-07-21 22:22:39 +00:00
if ( ( argc = zend_hash_str_find_ind ( & EG ( symbol_table ) , " argc " , sizeof ( " argc " ) - 1 ) ) ! = NULL & &
( argv = zend_hash_str_find_ind ( & EG ( symbol_table ) , " argv " , sizeof ( " argv " ) - 1 ) ) ! = NULL ) {
2014-02-10 06:04:30 +00:00
Z_ADDREF_P ( argv ) ;
zend_hash_str_update ( Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) , " argv " , sizeof ( " argv " ) - 1 , argv ) ;
zend_hash_str_update ( Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) , " argc " , sizeof ( " argc " ) - 1 , argc ) ;
2006-03-20 10:15:02 +00:00
}
} else {
2014-12-13 22:06:14 +00:00
php_build_argv ( SG ( request_info ) . query_string , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2006-03-20 10:15:02 +00:00
}
}
2015-01-03 09:22:58 +00:00
2005-05-25 17:41:50 +00:00
} else {
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2005-05-25 17:41:50 +00:00
}
2003-03-02 10:19:15 +00:00
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_SERVER ] ) ;
2015-01-03 09:22:58 +00:00
2003-03-02 10:19:15 +00:00
return 0 ; /* don't rearm */
}
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_env ( zend_string * name )
2003-03-02 10:19:15 +00:00
{
2014-02-10 06:04:30 +00:00
zval_ptr_dtor ( & PG ( http_globals ) [ TRACK_VARS_ENV ] ) ;
array_init ( & PG ( http_globals ) [ TRACK_VARS_ENV ] ) ;
2015-01-03 09:22:58 +00:00
2005-09-01 19:15:19 +00:00
if ( PG ( variables_order ) & & ( strchr ( PG ( variables_order ) , ' E ' ) | | strchr ( PG ( variables_order ) , ' e ' ) ) ) {
2014-12-13 22:06:14 +00:00
php_import_environment_variables ( & PG ( http_globals ) [ TRACK_VARS_ENV ] ) ;
2005-05-25 17:41:50 +00:00
}
2003-03-02 10:19:15 +00:00
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & PG ( http_globals ) [ TRACK_VARS_ENV ] ) ;
2014-02-10 06:04:30 +00:00
Z_ADDREF ( PG ( http_globals ) [ TRACK_VARS_ENV ] ) ;
2003-03-02 10:19:15 +00:00
return 0 ; /* don't rearm */
}
2014-12-13 22:06:14 +00:00
static zend_bool php_auto_globals_create_request ( zend_string * name )
2003-03-02 13:35:01 +00:00
{
2014-02-10 06:04:30 +00:00
zval form_variables ;
2003-07-31 22:29:32 +00:00
unsigned char _gpc_flags [ 3 ] = { 0 , 0 , 0 } ;
2003-03-02 13:35:01 +00:00
char * p ;
2014-02-10 06:04:30 +00:00
array_init ( & form_variables ) ;
2003-03-02 13:35:01 +00:00
2010-11-17 11:55:37 +00:00
if ( PG ( request_order ) ! = NULL ) {
2008-03-12 20:24:45 +00:00
p = PG ( request_order ) ;
} else {
p = PG ( variables_order ) ;
}
for ( ; p & & * p ; p + + ) {
2003-03-02 13:35:01 +00:00
switch ( * p ) {
case ' g ' :
case ' G ' :
2003-07-31 22:29:32 +00:00
if ( ! _gpc_flags [ 0 ] ) {
2014-12-13 22:06:14 +00:00
php_autoglobal_merge ( Z_ARRVAL ( form_variables ) , Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_GET ] ) ) ;
2003-07-31 22:29:32 +00:00
_gpc_flags [ 0 ] = 1 ;
}
2003-03-02 13:35:01 +00:00
break ;
case ' p ' :
case ' P ' :
2003-07-31 22:29:32 +00:00
if ( ! _gpc_flags [ 1 ] ) {
2014-12-13 22:06:14 +00:00
php_autoglobal_merge ( Z_ARRVAL ( form_variables ) , Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_POST ] ) ) ;
2003-07-31 22:29:32 +00:00
_gpc_flags [ 1 ] = 1 ;
}
2003-03-02 13:35:01 +00:00
break ;
case ' c ' :
case ' C ' :
2003-07-31 22:29:32 +00:00
if ( ! _gpc_flags [ 2 ] ) {
2014-12-13 22:06:14 +00:00
php_autoglobal_merge ( Z_ARRVAL ( form_variables ) , Z_ARRVAL ( PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) ) ;
2003-07-31 22:29:32 +00:00
_gpc_flags [ 2 ] = 1 ;
}
2003-03-02 13:35:01 +00:00
break ;
}
}
2015-02-13 19:20:39 +00:00
zend_hash_update ( & EG ( symbol_table ) , name , & form_variables ) ;
2003-03-02 13:35:01 +00:00
return 0 ;
}
2014-12-13 22:06:14 +00:00
void php_startup_auto_globals ( void )
2003-03-02 10:19:15 +00:00
{
2014-12-13 22:06:14 +00:00
zend_register_auto_global ( zend_string_init ( " _GET " , sizeof ( " _GET " ) - 1 , 1 ) , 0 , php_auto_globals_create_get ) ;
zend_register_auto_global ( zend_string_init ( " _POST " , sizeof ( " _POST " ) - 1 , 1 ) , 0 , php_auto_globals_create_post ) ;
zend_register_auto_global ( zend_string_init ( " _COOKIE " , sizeof ( " _COOKIE " ) - 1 , 1 ) , 0 , php_auto_globals_create_cookie ) ;
zend_register_auto_global ( zend_string_init ( " _SERVER " , sizeof ( " _SERVER " ) - 1 , 1 ) , PG ( auto_globals_jit ) , php_auto_globals_create_server ) ;
zend_register_auto_global ( zend_string_init ( " _ENV " , sizeof ( " _ENV " ) - 1 , 1 ) , PG ( auto_globals_jit ) , php_auto_globals_create_env ) ;
zend_register_auto_global ( zend_string_init ( " _REQUEST " , sizeof ( " _REQUEST " ) - 1 , 1 ) , PG ( auto_globals_jit ) , php_auto_globals_create_request ) ;
zend_register_auto_global ( zend_string_init ( " _FILES " , sizeof ( " _FILES " ) - 1 , 1 ) , 0 , php_auto_globals_create_files ) ;
2003-03-02 10:19:15 +00:00
}
1999-04-22 02:48:28 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 13:29:31 +00:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-22 02:48:28 +00:00
*/