1999-04-22 10:48:28 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-12-31 23:59:15 +08:00
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
1999-07-16 21:13:16 +08: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 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
1999-09-11 23:04:45 +08:00
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
2003-02-19 16:40:19 +08:00
|
|
|
|
2001-04-06 09:50:40 +08:00
|
|
|
/* $Id$ */
|
1999-04-24 04:06:01 +08:00
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "php.h"
|
2000-01-28 21:31:12 +08:00
|
|
|
#include "ext/standard/php_standard.h"
|
2003-03-04 03:37:09 +08:00
|
|
|
#include "ext/standard/credits.h"
|
2000-01-29 01:24:53 +08:00
|
|
|
#include "php_variables.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
#include "php_globals.h"
|
2000-08-21 17:50:53 +08:00
|
|
|
#include "php_content_types.h"
|
1999-04-27 01:26:37 +08:00
|
|
|
#include "SAPI.h"
|
2003-03-04 03:37:09 +08:00
|
|
|
#include "php_logos.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
2003-03-02 18:19:15 +08:00
|
|
|
|
2002-10-13 16:38:09 +08:00
|
|
|
/* for systems that need to override reading of environment variables */
|
|
|
|
void _php_import_environment_variables(zval *array_ptr TSRMLS_DC);
|
|
|
|
PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC) = _php_import_environment_variables;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
PHPAPI void php_register_variable(char *var, char *strval, zval *track_vars_array TSRMLS_DC)
|
2001-07-27 18:16:41 +08:00
|
|
|
{
|
2001-07-28 19:36:37 +08:00
|
|
|
php_register_variable_safe(var, strval, strlen(strval), track_vars_array TSRMLS_CC);
|
2000-12-12 18:47:47 +08:00
|
|
|
}
|
|
|
|
|
2001-11-25 00:05:22 +08:00
|
|
|
|
2000-12-12 18:47:47 +08:00
|
|
|
/* binary-safe version */
|
2001-07-28 19:36:37 +08:00
|
|
|
PHPAPI void php_register_variable_safe(char *var, char *strval, int str_len, zval *track_vars_array TSRMLS_DC)
|
2000-02-20 04:12:26 +08:00
|
|
|
{
|
|
|
|
zval new_entry;
|
2002-08-08 11:08:54 +08:00
|
|
|
assert(strval != NULL);
|
|
|
|
|
2000-02-20 04:12:26 +08:00
|
|
|
/* Prepare value */
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_STRLEN(new_entry) = str_len;
|
2000-02-20 04:12:26 +08:00
|
|
|
if (PG(magic_quotes_gpc)) {
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_STRVAL(new_entry) = php_addslashes(strval, Z_STRLEN(new_entry), &Z_STRLEN(new_entry), 0 TSRMLS_CC);
|
2000-02-20 04:12:26 +08:00
|
|
|
} else {
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_STRVAL(new_entry) = estrndup(strval, Z_STRLEN(new_entry));
|
2000-02-20 04:12:26 +08:00
|
|
|
}
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_TYPE(new_entry) = IS_STRING;
|
2000-02-20 04:12:26 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
php_register_variable_ex(var, &new_entry, track_vars_array TSRMLS_CC);
|
2000-02-20 04:12:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array TSRMLS_DC)
|
1999-09-13 07:51:12 +08:00
|
|
|
{
|
|
|
|
char *p = NULL;
|
|
|
|
char *ip; /* index pointer */
|
|
|
|
char *index;
|
2000-02-20 04:12:26 +08:00
|
|
|
int var_len, index_len;
|
2003-06-14 23:08:27 +08:00
|
|
|
zval *gpc_element, **gpc_element_p;
|
1999-09-13 07:51:12 +08:00
|
|
|
zend_bool is_array;
|
|
|
|
HashTable *symtable1=NULL;
|
2000-09-06 03:06:29 +08:00
|
|
|
|
2002-08-08 11:08:54 +08:00
|
|
|
assert(var != NULL);
|
|
|
|
|
1999-09-13 07:51:12 +08:00
|
|
|
if (track_vars_array) {
|
2002-12-08 00:05:27 +08:00
|
|
|
symtable1 = Z_ARRVAL_P(track_vars_array);
|
|
|
|
}
|
1999-09-13 07:51:12 +08:00
|
|
|
if (!symtable1) {
|
2000-09-06 03:06:29 +08:00
|
|
|
/* Nothing to do */
|
2000-02-20 04:12:26 +08:00
|
|
|
zval_dtor(val);
|
1999-09-13 07:51:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare variable name
|
|
|
|
*/
|
|
|
|
ip = strchr(var, '[');
|
|
|
|
if (ip) {
|
|
|
|
is_array = 1;
|
|
|
|
*ip = 0;
|
|
|
|
} else {
|
|
|
|
is_array = 0;
|
|
|
|
}
|
|
|
|
/* ignore leading spaces in the variable name */
|
|
|
|
while (*var && *var==' ') {
|
|
|
|
var++;
|
|
|
|
}
|
|
|
|
var_len = strlen(var);
|
|
|
|
if (var_len==0) { /* empty variable name, or variable name with a space in it */
|
2000-02-20 04:12:26 +08:00
|
|
|
zval_dtor(val);
|
1999-09-13 07:51:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* ensure that we don't have spaces or dots in the variable name (not binary safe) */
|
|
|
|
for (p=var; *p; p++) {
|
|
|
|
switch(*p) {
|
|
|
|
case ' ':
|
|
|
|
case '.':
|
|
|
|
*p='_';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
index = var;
|
|
|
|
index_len = var_len;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (is_array) {
|
2002-12-30 05:02:17 +08:00
|
|
|
char *escaped_index = NULL, *index_s;
|
|
|
|
int new_idx_len = 0;
|
|
|
|
|
|
|
|
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) = '_';
|
|
|
|
index_len = var_len = strlen(var);
|
|
|
|
goto plain_var;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ip = 0;
|
|
|
|
new_idx_len = strlen(index_s);
|
|
|
|
}
|
1999-09-13 07:51:12 +08:00
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
MAKE_STD_ZVAL(gpc_element);
|
|
|
|
array_init(gpc_element);
|
|
|
|
zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
|
|
|
|
} else {
|
|
|
|
if (PG(magic_quotes_gpc) && (index!=var)) {
|
|
|
|
/* no need to addslashes() the index if it's the main variable name */
|
2001-08-06 11:50:52 +08:00
|
|
|
escaped_index = php_addslashes(index, index_len, &index_len, 0 TSRMLS_CC);
|
1999-09-13 07:51:12 +08:00
|
|
|
} else {
|
|
|
|
escaped_index = index;
|
|
|
|
}
|
|
|
|
if (zend_hash_find(symtable1, escaped_index, index_len+1, (void **) &gpc_element_p)==FAILURE
|
2001-09-26 05:58:48 +08:00
|
|
|
|| Z_TYPE_PP(gpc_element_p) != IS_ARRAY) {
|
1999-09-13 07:51:12 +08:00
|
|
|
MAKE_STD_ZVAL(gpc_element);
|
|
|
|
array_init(gpc_element);
|
|
|
|
zend_hash_update(symtable1, escaped_index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
|
|
|
|
}
|
|
|
|
if (index!=escaped_index) {
|
|
|
|
efree(escaped_index);
|
|
|
|
}
|
|
|
|
}
|
2001-09-26 05:58:48 +08:00
|
|
|
symtable1 = Z_ARRVAL_PP(gpc_element_p);
|
1999-09-13 07:51:12 +08:00
|
|
|
/* ip pointed to the '[' character, now obtain the key */
|
2002-12-30 05:02:17 +08:00
|
|
|
index = index_s;
|
|
|
|
index_len = new_idx_len;
|
|
|
|
|
1999-09-13 07:51:12 +08:00
|
|
|
ip++;
|
|
|
|
if (*ip=='[') {
|
|
|
|
is_array = 1;
|
|
|
|
*ip = 0;
|
|
|
|
} else {
|
|
|
|
is_array = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2002-12-30 05:02:17 +08:00
|
|
|
plain_var:
|
1999-09-13 07:51:12 +08:00
|
|
|
MAKE_STD_ZVAL(gpc_element);
|
2000-02-20 04:12:26 +08:00
|
|
|
gpc_element->value = val->value;
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_TYPE_P(gpc_element) = Z_TYPE_P(val);
|
1999-09-13 07:51:12 +08:00
|
|
|
if (!index) {
|
|
|
|
zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
|
|
|
|
} else {
|
2000-03-24 19:16:24 +08:00
|
|
|
zend_hash_update(symtable1, index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
|
1999-09-13 07:51:12 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-16 02:01:48 +08:00
|
|
|
SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
|
2000-02-18 04:23:59 +08:00
|
|
|
{
|
|
|
|
char *var, *val;
|
|
|
|
char *strtok_buf = NULL;
|
|
|
|
zval *array_ptr = (zval *) arg;
|
|
|
|
|
2002-07-24 19:25:36 +08:00
|
|
|
if (SG(request_info).post_data==NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-05-04 18:38:17 +08:00
|
|
|
var = php_strtok_r(SG(request_info).post_data, "&", &strtok_buf);
|
2000-02-18 04:23:59 +08:00
|
|
|
|
|
|
|
while (var) {
|
|
|
|
val = strchr(var, '=');
|
|
|
|
if (val) { /* have a value */
|
2000-12-12 18:47:47 +08:00
|
|
|
int val_len;
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
*val++ = '\0';
|
|
|
|
php_url_decode(var, strlen(var));
|
2000-12-12 18:47:47 +08:00
|
|
|
val_len = php_url_decode(val, strlen(val));
|
2003-02-21 06:21:49 +08:00
|
|
|
val_len = sapi_module.input_filter(PARSE_POST, var, &val, val_len TSRMLS_CC);
|
2001-07-28 19:36:37 +08:00
|
|
|
php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
|
2000-02-18 04:23:59 +08:00
|
|
|
}
|
2000-05-04 18:38:17 +08:00
|
|
|
var = php_strtok_r(NULL, "&", &strtok_buf);
|
2000-02-18 04:23:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-20 03:41:09 +08:00
|
|
|
SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter)
|
|
|
|
{
|
|
|
|
/* TODO: check .ini setting here and apply user-defined input filter */
|
|
|
|
return val_len;
|
|
|
|
}
|
|
|
|
|
2002-08-02 14:53:48 +08:00
|
|
|
SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
2001-04-05 04:46:26 +08:00
|
|
|
char *res = NULL, *var, *val, *separator=NULL;
|
2000-11-02 23:47:02 +08:00
|
|
|
const char *c_var;
|
1999-04-22 10:48:28 +08:00
|
|
|
pval *array_ptr;
|
1999-05-11 08:01:47 +08:00
|
|
|
int free_buffer=0;
|
1999-11-26 21:34:31 +08:00
|
|
|
char *strtok_buf = NULL;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
switch (arg) {
|
|
|
|
case PARSE_POST:
|
|
|
|
case PARSE_GET:
|
|
|
|
case PARSE_COOKIE:
|
2000-09-06 03:06:29 +08:00
|
|
|
ALLOC_ZVAL(array_ptr);
|
|
|
|
array_init(array_ptr);
|
|
|
|
INIT_PZVAL(array_ptr);
|
|
|
|
switch (arg) {
|
|
|
|
case PARSE_POST:
|
|
|
|
PG(http_globals)[TRACK_VARS_POST] = array_ptr;
|
|
|
|
break;
|
|
|
|
case PARSE_GET:
|
|
|
|
PG(http_globals)[TRACK_VARS_GET] = array_ptr;
|
|
|
|
break;
|
|
|
|
case PARSE_COOKIE:
|
|
|
|
PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
|
|
|
|
break;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2000-09-11 22:50:26 +08:00
|
|
|
array_ptr=destArray;
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
if (arg==PARSE_POST) {
|
2001-07-28 19:36:37 +08:00
|
|
|
sapi_handle_post(array_ptr TSRMLS_CC);
|
2000-02-18 04:23:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg == PARSE_GET) { /* GET data */
|
2000-11-02 23:47:02 +08:00
|
|
|
c_var = SG(request_info).query_string;
|
|
|
|
if (c_var && *c_var) {
|
|
|
|
res = (char *) estrdup(c_var);
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
|
|
|
} else {
|
|
|
|
free_buffer = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
} else if (arg == PARSE_COOKIE) { /* Cookie data */
|
2000-11-02 23:47:02 +08:00
|
|
|
c_var = SG(request_info).cookie_data;
|
|
|
|
if (c_var && *c_var) {
|
|
|
|
res = (char *) estrdup(c_var);
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
|
|
|
} else {
|
|
|
|
free_buffer = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
} else if (arg == PARSE_STRING) { /* String data */
|
|
|
|
res = str;
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2000-02-18 04:23:59 +08:00
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
if (!res) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-05 04:46:26 +08:00
|
|
|
switch (arg) {
|
|
|
|
case PARSE_GET:
|
|
|
|
case PARSE_STRING:
|
|
|
|
separator = (char *) estrdup(PG(arg_separator).input);
|
|
|
|
break;
|
|
|
|
case PARSE_COOKIE:
|
|
|
|
separator = ";\0";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-04-04 08:37:06 +08:00
|
|
|
var = php_strtok_r(res, separator, &strtok_buf);
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
while (var) {
|
|
|
|
val = strchr(var, '=');
|
|
|
|
if (val) { /* have a value */
|
2000-12-12 18:47:47 +08:00
|
|
|
int val_len;
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
*val++ = '\0';
|
|
|
|
php_url_decode(var, strlen(var));
|
2002-09-08 08:27:05 +08:00
|
|
|
val_len = php_url_decode(val, strlen(val));
|
2003-02-21 06:21:49 +08:00
|
|
|
val_len = sapi_module.input_filter(arg, var, &val, val_len TSRMLS_CC);
|
2001-07-28 19:36:37 +08:00
|
|
|
php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
|
2002-08-01 00:25:12 +08:00
|
|
|
} else {
|
2002-09-08 05:04:14 +08:00
|
|
|
php_url_decode(var, strlen(var));
|
2002-08-01 00:25:12 +08:00
|
|
|
php_register_variable_safe(var, "", 0, array_ptr TSRMLS_CC);
|
2002-07-28 12:18:40 +08:00
|
|
|
}
|
2001-04-04 08:37:06 +08:00
|
|
|
var = php_strtok_r(NULL, separator, &strtok_buf);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2001-04-05 04:46:26 +08:00
|
|
|
|
|
|
|
if(arg != PARSE_COOKIE) {
|
|
|
|
efree(separator);
|
|
|
|
}
|
|
|
|
|
1999-05-10 02:40:59 +08:00
|
|
|
if (free_buffer) {
|
|
|
|
efree(res);
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
2002-10-13 16:38:09 +08:00
|
|
|
void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
|
2000-01-29 01:24:53 +08:00
|
|
|
{
|
2003-03-28 05:13:47 +08:00
|
|
|
char buf[128];
|
|
|
|
char **env, *p, *t = buf;
|
|
|
|
size_t alloc_size = sizeof(buf);
|
2003-03-29 01:09:04 +08:00
|
|
|
unsigned long nlen; /* ptrdiff_t is not portable */
|
2003-03-28 05:13:47 +08:00
|
|
|
|
2003-03-24 03:30:31 +08:00
|
|
|
/* turn off magic_quotes while importing environment variables */
|
|
|
|
int magic_quotes_gpc = PG(magic_quotes_gpc);
|
|
|
|
PG(magic_quotes_gpc) = 0;
|
2000-01-29 01:24:53 +08:00
|
|
|
|
|
|
|
for (env = environ; env != NULL && *env != NULL; env++) {
|
|
|
|
p = strchr(*env, '=');
|
|
|
|
if (!p) { /* malformed entry? */
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-28 05:13:47 +08: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';
|
2001-07-28 19:36:37 +08:00
|
|
|
php_register_variable(t, p+1, array_ptr TSRMLS_CC);
|
2003-03-28 05:13:47 +08:00
|
|
|
}
|
|
|
|
if (t != buf && t != NULL) {
|
2000-01-29 01:24:53 +08:00
|
|
|
efree(t);
|
|
|
|
}
|
2003-03-24 03:30:31 +08:00
|
|
|
PG(magic_quotes_gpc) = magic_quotes_gpc;
|
2000-01-29 01:24:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-02 18:19:15 +08:00
|
|
|
zend_bool php_std_auto_global_callback(char *name, uint name_len TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_printf("%s\n", name);
|
|
|
|
return 0; /* don't rearm */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* {{{ php_build_argv
|
|
|
|
*/
|
|
|
|
static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC)
|
|
|
|
{
|
|
|
|
pval *arr, *argc, *tmp;
|
|
|
|
int count = 0;
|
|
|
|
char *ss, *space;
|
|
|
|
|
|
|
|
ALLOC_ZVAL(arr);
|
|
|
|
array_init(arr);
|
|
|
|
INIT_PZVAL(arr);
|
|
|
|
|
|
|
|
/* Prepare argv */
|
|
|
|
if (SG(request_info).argc) { /* are we in cli sapi? */
|
|
|
|
int i;
|
|
|
|
for (i=0; i<SG(request_info).argc; i++) {
|
|
|
|
ALLOC_ZVAL(tmp);
|
|
|
|
Z_TYPE_P(tmp) = IS_STRING;
|
|
|
|
Z_STRLEN_P(tmp) = strlen(SG(request_info).argv[i]);
|
|
|
|
Z_STRVAL_P(tmp) = estrndup(SG(request_info).argv[i], Z_STRLEN_P(tmp));
|
|
|
|
INIT_PZVAL(tmp);
|
|
|
|
if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) {
|
|
|
|
if (Z_TYPE_P(tmp) == IS_STRING) {
|
|
|
|
efree(Z_STRVAL_P(tmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (s && *s) {
|
|
|
|
ss = s;
|
|
|
|
while (ss) {
|
|
|
|
space = strchr(ss, '+');
|
|
|
|
if (space) {
|
|
|
|
*space = '\0';
|
|
|
|
}
|
|
|
|
/* auto-type */
|
|
|
|
ALLOC_ZVAL(tmp);
|
|
|
|
Z_TYPE_P(tmp) = IS_STRING;
|
|
|
|
Z_STRLEN_P(tmp) = strlen(ss);
|
|
|
|
Z_STRVAL_P(tmp) = estrndup(ss, Z_STRLEN_P(tmp));
|
|
|
|
INIT_PZVAL(tmp);
|
|
|
|
count++;
|
|
|
|
if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) {
|
|
|
|
if (Z_TYPE_P(tmp) == IS_STRING) {
|
|
|
|
efree(Z_STRVAL_P(tmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (space) {
|
|
|
|
*space = '+';
|
|
|
|
ss = space + 1;
|
|
|
|
} else {
|
|
|
|
ss = space;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prepare argc */
|
|
|
|
ALLOC_ZVAL(argc);
|
|
|
|
if (SG(request_info).argc) {
|
|
|
|
Z_LVAL_P(argc) = SG(request_info).argc;
|
|
|
|
} else {
|
|
|
|
Z_LVAL_P(argc) = count;
|
|
|
|
}
|
|
|
|
Z_TYPE_P(argc) = IS_LONG;
|
|
|
|
INIT_PZVAL(argc);
|
|
|
|
|
|
|
|
if (PG(register_globals) || SG(request_info).argc) {
|
|
|
|
arr->refcount++;
|
|
|
|
argc->refcount++;
|
|
|
|
zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL);
|
|
|
|
zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL);
|
|
|
|
zend_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ php_handle_special_queries
|
|
|
|
*/
|
|
|
|
PHPAPI int php_handle_special_queries(TSRMLS_D)
|
|
|
|
{
|
|
|
|
if (SG(request_info).query_string && SG(request_info).query_string[0]=='='
|
|
|
|
&& PG(expose_php)) {
|
|
|
|
if (php_info_logos(SG(request_info).query_string+1 TSRMLS_CC)) {
|
|
|
|
return 1;
|
|
|
|
} else if (!strcmp(SG(request_info).query_string+1, PHP_CREDITS_GUID)) {
|
2003-03-25 16:07:13 +08:00
|
|
|
php_print_credits(PHP_CREDITS_ALL TSRMLS_CC);
|
2003-03-02 18:19:15 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ php_register_server_variables
|
|
|
|
*/
|
|
|
|
static inline void php_register_server_variables(TSRMLS_D)
|
|
|
|
{
|
|
|
|
zval *array_ptr=NULL;
|
2003-03-30 09:06:54 +08:00
|
|
|
/* turn off magic_quotes while importing server variables */
|
|
|
|
int magic_quotes_gpc = PG(magic_quotes_gpc);
|
2003-03-02 18:19:15 +08:00
|
|
|
|
|
|
|
ALLOC_ZVAL(array_ptr);
|
|
|
|
array_init(array_ptr);
|
|
|
|
INIT_PZVAL(array_ptr);
|
|
|
|
PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
|
2003-03-30 09:06:54 +08:00
|
|
|
PG(magic_quotes_gpc) = 0;
|
2003-03-02 18:19:15 +08:00
|
|
|
|
|
|
|
/* Server variables */
|
|
|
|
if (sapi_module.register_server_variables) {
|
|
|
|
sapi_module.register_server_variables(array_ptr TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* argv/argc support */
|
|
|
|
if (PG(register_argc_argv)) {
|
|
|
|
php_build_argv(SG(request_info).query_string, array_ptr TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PHP Authentication support */
|
|
|
|
if (SG(request_info).auth_user) {
|
|
|
|
php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (SG(request_info).auth_password) {
|
|
|
|
php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, array_ptr TSRMLS_CC);
|
|
|
|
}
|
2003-03-30 09:06:54 +08:00
|
|
|
PG(magic_quotes_gpc) = magic_quotes_gpc;
|
2003-03-02 18:19:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC);
|
|
|
|
static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC);
|
2003-03-02 21:35:01 +08:00
|
|
|
static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC);
|
2003-03-02 18:19:15 +08:00
|
|
|
|
|
|
|
/* {{{ php_hash_environment
|
|
|
|
*/
|
|
|
|
int php_hash_environment(TSRMLS_D)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
unsigned char _gpc_flags[3] = {0, 0, 0};
|
|
|
|
zend_bool have_variables_order;
|
|
|
|
zval *dummy_track_vars_array = NULL;
|
|
|
|
zend_bool initialized_dummy_track_vars_array=0;
|
|
|
|
zend_bool jit_initialization = (!PG(register_globals) && !PG(register_long_arrays));
|
|
|
|
char *variables_order;
|
|
|
|
struct auto_global_record {
|
|
|
|
char *name;
|
|
|
|
uint name_len;
|
|
|
|
char *long_name;
|
|
|
|
uint long_name_len;
|
|
|
|
zend_bool jit_initialization;
|
|
|
|
} auto_global_records[] = {
|
2003-03-02 23:41:12 +08:00
|
|
|
{ "_POST", sizeof("_POST"), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), 0 },
|
|
|
|
{ "_GET", sizeof("_GET"), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), 0 },
|
|
|
|
{ "_COOKIE", sizeof("_COOKIE"), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), 0 },
|
|
|
|
{ "_SERVER", sizeof("_SERVER"), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), 1 },
|
|
|
|
{ "_ENV", sizeof("_ENV"), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), 1 },
|
|
|
|
{ "_FILES", sizeof("_FILES"), "HTTP_POST_FILES", sizeof("HTTP_POST_FILES"), 0 },
|
2003-03-02 18:19:15 +08:00
|
|
|
};
|
|
|
|
size_t num_track_vars = sizeof(auto_global_records)/sizeof(struct auto_global_record);
|
2003-03-02 21:35:01 +08:00
|
|
|
size_t i;
|
2003-03-02 18:19:15 +08:00
|
|
|
|
2003-03-02 21:35:01 +08:00
|
|
|
/* jit_initialization = 0; */
|
2003-03-02 18:19:15 +08:00
|
|
|
for (i=0; i<num_track_vars; i++) {
|
|
|
|
PG(http_globals)[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PG(variables_order)) {
|
|
|
|
variables_order = PG(variables_order);
|
|
|
|
have_variables_order=1;
|
|
|
|
} else {
|
|
|
|
variables_order = PG(gpc_order);
|
|
|
|
have_variables_order=0;
|
|
|
|
ALLOC_ZVAL(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
array_init(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
INIT_PZVAL(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p=variables_order; p && *p; p++) {
|
|
|
|
switch(*p) {
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
|
|
|
|
sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */
|
|
|
|
_gpc_flags[0]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
if (!_gpc_flags[1]) {
|
|
|
|
sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */
|
|
|
|
_gpc_flags[1]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
if (!_gpc_flags[2]) {
|
|
|
|
sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */
|
|
|
|
_gpc_flags[2]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
if (!jit_initialization) {
|
|
|
|
if (have_variables_order) {
|
|
|
|
php_auto_globals_create_env("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
|
|
|
|
} else {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
if (!jit_initialization) {
|
|
|
|
php_register_server_variables(TSRMLS_C);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-30 09:06:54 +08:00
|
|
|
if (!jit_initialization && !have_variables_order) {
|
|
|
|
php_register_server_variables(TSRMLS_C);
|
2003-03-02 18:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<num_track_vars; i++) {
|
|
|
|
if (jit_initialization && auto_global_records[i].jit_initialization) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!PG(http_globals)[i]) {
|
|
|
|
if (!initialized_dummy_track_vars_array) {
|
|
|
|
ALLOC_ZVAL(dummy_track_vars_array);
|
|
|
|
array_init(dummy_track_vars_array);
|
|
|
|
INIT_PZVAL(dummy_track_vars_array);
|
|
|
|
initialized_dummy_track_vars_array = 1;
|
|
|
|
} else {
|
|
|
|
dummy_track_vars_array->refcount++;
|
|
|
|
}
|
|
|
|
PG(http_globals)[i] = dummy_track_vars_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), auto_global_records[i].name, auto_global_records[i].name_len, &PG(http_globals)[i], sizeof(zval *), NULL);
|
|
|
|
PG(http_globals)[i]->refcount++;
|
|
|
|
if (PG(register_long_arrays)) {
|
|
|
|
zend_hash_update(&EG(symbol_table), auto_global_records[i].long_name, auto_global_records[i].long_name_len, &PG(http_globals)[i], sizeof(zval *), NULL);
|
|
|
|
PG(http_globals)[i]->refcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create _REQUEST */
|
2003-03-02 21:35:01 +08:00
|
|
|
if (!jit_initialization) {
|
|
|
|
php_auto_globals_create_request("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC);
|
2003-03-02 18:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC)
|
|
|
|
{
|
|
|
|
php_register_server_variables(TSRMLS_C);
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), name, name_len+1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL);
|
|
|
|
PG(http_globals)[TRACK_VARS_SERVER]->refcount++;
|
|
|
|
|
|
|
|
if (PG(register_long_arrays)) {
|
2003-03-02 23:41:12 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL);
|
2003-03-02 18:19:15 +08:00
|
|
|
PG(http_globals)[TRACK_VARS_SERVER]->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; /* don't rearm */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC)
|
|
|
|
{
|
|
|
|
ALLOC_ZVAL(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
array_init(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
INIT_PZVAL(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
|
php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC);
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), name, name_len+1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
|
|
|
|
PG(http_globals)[TRACK_VARS_ENV]->refcount++;
|
|
|
|
|
|
|
|
if (PG(register_long_arrays)) {
|
2003-03-02 23:41:12 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
|
2003-03-02 18:19:15 +08:00
|
|
|
PG(http_globals)[TRACK_VARS_ENV]->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; /* don't rearm */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-02 21:35:01 +08:00
|
|
|
static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zval *form_variables;
|
|
|
|
char *variables_order;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (PG(variables_order)) {
|
|
|
|
variables_order = PG(variables_order);
|
|
|
|
} else {
|
|
|
|
variables_order = PG(gpc_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(form_variables);
|
|
|
|
array_init(form_variables);
|
|
|
|
INIT_PZVAL(form_variables);
|
|
|
|
|
|
|
|
for (p=variables_order; p && *p; p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
|
|
|
zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST"), &form_variables, sizeof(zval *), NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-02 18:19:15 +08:00
|
|
|
void php_startup_auto_globals(TSRMLS_D)
|
|
|
|
{
|
|
|
|
zend_bool cb = (!PG(register_globals) && !PG(register_long_arrays));
|
|
|
|
|
2003-03-02 21:35:01 +08:00
|
|
|
/*cb = 0;*/
|
2003-03-02 18:19:15 +08:00
|
|
|
zend_register_auto_global("_GET", sizeof("_GET")-1, NULL TSRMLS_CC);
|
|
|
|
zend_register_auto_global("_POST", sizeof("_POST")-1, NULL TSRMLS_CC);
|
|
|
|
zend_register_auto_global("_COOKIE", sizeof("_COOKIE")-1, NULL TSRMLS_CC);
|
|
|
|
zend_register_auto_global("_SERVER", sizeof("_SERVER")-1, cb?php_auto_globals_create_server:NULL TSRMLS_CC);
|
|
|
|
zend_register_auto_global("_ENV", sizeof("_ENV")-1, cb?php_auto_globals_create_env:NULL TSRMLS_CC);
|
2003-03-02 21:35:01 +08:00
|
|
|
zend_register_auto_global("_REQUEST", sizeof("_REQUEST")-1, cb?php_auto_globals_create_request:NULL TSRMLS_CC);
|
2003-06-08 23:30:33 +08:00
|
|
|
zend_register_auto_global("_FILES", sizeof("_FILES")-1, NULL TSRMLS_CC);
|
2003-03-02 18:19:15 +08:00
|
|
|
}
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
1999-04-22 10:48:28 +08:00
|
|
|
*/
|