zeev Sun Mar 2 05:19:17 2003 EDT
Modified files:
/php4 php.ini-dist php.ini-recommended
/php4/ext/filepro filepro.c
/php4/ext/session session.c
/php4/main main.c php_globals.h php_variables.c php_variables.h
Log:
Add JIT initialization for _SERVER and _ENV
(it's less important for the others, even though it should be fairly
easy now too)
Index: php4/php.ini-dist
diff -u php4/php.ini-dist:1.180 php4/php.ini-dist:1.181
--- php4/php.ini-dist:1.180 Mon Feb 10 19:50:00 2003
+++ php4/php.ini-dist Sun Mar 2 05:19:11 2003
@@ -354,6 +354,11 @@
; to possible security problems, if the code is not very well thought of.
register_globals = Off
+; Whether or not to register the old-style input arrays, HTTP_GET_GLOBALS
+; and friends. If you're not using them, it's recommended to turn them off,
+; for performance reasons.
+register_long_arrays = Off
+
; 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.
Index: php4/php.ini-recommended
diff -u php4/php.ini-recommended:1.126 php4/php.ini-recommended:1.127
--- php4/php.ini-recommended:1.126 Mon Feb 10 19:50:00 2003
+++ php4/php.ini-recommended Sun Mar 2 05:19:12 2003
@@ -369,6 +369,11 @@
; to possible security problems, if the code is not very well thought of.
register_globals = Off
+; Whether or not to register the old-style input arrays, HTTP_GET_GLOBALS
+; and friends. If you're not using them, it's recommended to turn them off,
+; for performance reasons.
+register_long_arrays = Off
+
; 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.
Index: php4/ext/filepro/filepro.c
diff -u php4/ext/filepro/filepro.c:1.49 php4/ext/filepro/filepro.c:1.50
--- php4/ext/filepro/filepro.c:1.49 Tue Jan 14 21:49:38 2003
+++ php4/ext/filepro/filepro.c Sun Mar 2 05:19:13 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: filepro.c,v 1.49 2003/01/15 02:49:38 iliaa Exp $ */
+/* $Id: filepro.c,v 1.50 2003/03/02 10:19:13 zeev Exp $ */
/*
filePro 4.x support developed by Chad Robinson, [EMAIL PROTECTED]
@@ -34,11 +34,7 @@
#include "safe_mode.h"
#include "fopen_wrappers.h"
#include <string.h>
-#ifdef PHP_WIN32
-#include <windows.h>
-#else
#include <sys/param.h>
-#endif
#include <errno.h>
#include "php_globals.h"
Index: php4/ext/session/session.c
diff -u php4/ext/session/session.c:1.355 php4/ext/session/session.c:1.356
--- php4/ext/session/session.c:1.355 Thu Feb 20 01:18:16 2003
+++ php4/ext/session/session.c Sun Mar 2 05:19:13 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: session.c,v 1.355 2003/02/20 06:18:16 sas Exp $ */
+/* $Id: session.c,v 1.356 2003/03/02 10:19:13 zeev Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -1714,7 +1714,7 @@
ps_globals = ts_resource(ps_globals_id);
#endif
- zend_register_auto_global("_SESSION", sizeof("_SESSION")-1 TSRMLS_CC);
+ zend_register_auto_global("_SESSION", sizeof("_SESSION")-1, NULL TSRMLS_CC);
PS(module_number) = module_number; /* if we really need this var we need to
init it in zts mode as well! */
Index: php4/main/main.c
diff -u php4/main/main.c:1.530 php4/main/main.c:1.531
--- php4/main/main.c:1.530 Wed Feb 26 17:19:01 2003
+++ php4/main/main.c Sun Mar 2 05:19:14 2003
@@ -18,15 +18,15 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.530 2003/02/26 22:19:01 rasmus Exp $ */
+/* $Id: main.c,v 1.531 2003/03/02 10:19:14 zeev Exp $ */
/* {{{ includes
*/
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-#include <stdio.h>
#include "php.h"
+#include <stdio.h>
#ifdef PHP_WIN32
#include "win32/time.h"
#include "win32/signal.h"
@@ -116,28 +116,6 @@
static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC);
-static char *short_track_vars_names[] = {
- "_POST",
- "_GET",
- "_COOKIE",
- "_SERVER",
- "_ENV",
- "_FILES",
- NULL
-};
-
-static int short_track_vars_names_length[] = {
- sizeof("_POST"),
- sizeof("_GET"),
- sizeof("_COOKIE"),
- sizeof("_SERVER"),
- sizeof("_ENV"),
- sizeof("_FILES")
-};
-
-#define NUM_TRACK_VARS (sizeof(short_track_vars_names_length)/sizeof(int))
-
-
#define SAFE_FILENAME(f) ((f)?(f):"-")
/* {{{ PHP_INI_MH
@@ -278,6 +256,7 @@
STD_PHP_INI_ENTRY("output_handler", NULL,
PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler,
php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("register_argc_argv", "1",
PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv,
php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("register_globals", "0",
PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_globals,
php_core_globals, core_globals)
+ STD_PHP_INI_BOOLEAN("register_long_arrays", "0",
PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays,
php_core_globals, core_globals)
#if PHP_SAFE_MODE
STD_PHP_INI_BOOLEAN("safe_mode", "1",
PHP_INI_SYSTEM, OnUpdateBool, safe_mode,
php_core_globals, core_globals)
#else
@@ -864,8 +843,6 @@
/* }}} */
#endif
-static int php_hash_environment(TSRMLS_D);
-
/* {{{ php_start_sapi()
*/
static int php_start_sapi(TSRMLS_D)
@@ -1039,7 +1016,9 @@
int i;
for (i = 0; i < NUM_TRACK_VARS; i++) {
- zval_ptr_dtor(&PG(http_globals)[i]);
+ if (PG(http_globals)[i]) {
+ zval_ptr_dtor(&PG(http_globals)[i]);
+ }
}
} zend_end_try();
@@ -1164,7 +1143,6 @@
zend_utility_values zuv;
int module_number=0; /* for REGISTER_INI_ENTRIES() */
char *php_os;
- int i;
#ifdef ZTS
zend_executor_globals *executor_globals;
void ***tsrm_ls;
@@ -1277,10 +1255,7 @@
}
zuv.import_use_extension = ".php";
- 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);
+ php_startup_auto_globals(TSRMLS_C);
zend_set_utility_values(&zuv);
php_startup_sapi_content_types();
@@ -1397,270 +1372,84 @@
}
/* }}} */
-/* {{{ php_register_server_variables
- */
-static inline void php_register_server_variables(TSRMLS_D)
-{
- zval *array_ptr=NULL;
-
- ALLOC_ZVAL(array_ptr);
- array_init(array_ptr);
- INIT_PZVAL(array_ptr);
- PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
- /* Server variables */
- if (sapi_module.register_server_variables) {
- sapi_module.register_server_variables(array_ptr TSRMLS_CC);
+/* Only _ENV and _SERVER are JIT'd for now */
+#if 0
+static zend_bool php_auto_globals_create_get(TSRMLS_D)
+{
+ if (PG(activated_auto_globals)[TRACK_VARS_GET]) {
+ return 0;
}
- /* argv/argc support */
- if (PG(register_argc_argv)) {
- php_build_argv(SG(request_info).query_string, array_ptr TSRMLS_CC);
- }
+ return 0;
+}
- /* PHP Authentication support */
- if (SG(request_info).auth_user) {
- php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user,
array_ptr TSRMLS_CC);
+
+static zend_bool php_auto_globals_create_post(TSRMLS_D)
+{
+ if (PG(activated_auto_globals)[TRACK_VARS_POST]) {
+ return 0;
}
- if (SG(request_info).auth_password) {
- php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password,
array_ptr TSRMLS_CC);
+ if (!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;
}
+
+ PG(activated_auto_globals)[TRACK_VARS_POST] = 1;
+
+ return 0;
}
-/* }}} */
-/* {{{ php_hash_environment
- */
-static int php_hash_environment(TSRMLS_D)
+
+static zend_bool php_auto_globals_create_cookie(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;
- int i;
- char *variables_order;
- char *track_vars_names[] = {
- "HTTP_POST_VARS",
- "HTTP_GET_VARS",
- "HTTP_COOKIE_VARS",
- "HTTP_SERVER_VARS",
- "HTTP_ENV_VARS",
- "HTTP_POST_FILES",
- NULL
- };
- int track_vars_names_length[] = {
- sizeof("HTTP_POST_VARS"),
- sizeof("HTTP_GET_VARS"),
- sizeof("HTTP_COOKIE_VARS"),
- sizeof("HTTP_SERVER_VARS"),
- sizeof("HTTP_ENV_VARS"),
- sizeof("HTTP_POST_FILES")
- };
+ if (PG(activated_auto_globals)[TRACK_VARS_COOKIE]) {
+ return 0;
+ }
+ return 0;
+}
- 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);
+static zend_bool php_auto_globals_create_request(TSRMLS_D)
+{
+ zval *form_variables;
+
+ if (PG(activated_auto_globals)[TRACK_VARS_REQUEST]) {
+ return 0;
}
+ php_auto_globals_create_get(TSRMLS_C);
+ php_auto_globals_create_post(TSRMLS_C);
+ php_auto_globals_create_cookie(TSRMLS_C);
+
+ ALLOC_ZVAL(form_variables);
+ array_init(form_variables);
+ INIT_PZVAL(form_variables);
+
for (p=variables_order; p && *p; p++) {
- switch(*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':
- 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;
- }
+ 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':
- if (!_gpc_flags[1]) {
- sapi_module.treat_data(PARSE_COOKIE, NULL,
NULL TSRMLS_CC); /* Cookie Data */
- _gpc_flags[1]=1;
- }
+ 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;
- 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 (have_variables_order) {
- 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);
- } 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':
- php_register_server_variables(TSRMLS_C);
- break;
- }
- }
-
- if (!have_variables_order) {
- php_register_server_variables(TSRMLS_C);
- }
-
- 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);
- 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), 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++;
}
- {
- zval *form_variables;
-
- 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 SUCCESS;
+ zend_hash_update(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST"),
&form_variables, sizeof(zval *), NULL);
}
-/* }}} */
-
-/* {{{ 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);
+#endif
- 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))
{
- php_print_credits(PHP_CREDITS_ALL);
- return 1;
- }
- }
- return 0;
-}
-/* }}} */
/* {{{ php_execute_script
*/
Index: php4/main/php_globals.h
diff -u php4/main/php_globals.h:1.88 php4/main/php_globals.h:1.89
--- php4/main/php_globals.h:1.88 Wed Feb 19 03:40:18 2003
+++ php4/main/php_globals.h Sun Mar 2 05:19:15 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_globals.h,v 1.88 2003/02/19 08:40:18 sniper Exp $ */
+/* $Id: php_globals.h,v 1.89 2003/03/02 10:19:15 zeev Exp $ */
#ifndef PHP_GLOBALS_H
#define PHP_GLOBALS_H
@@ -40,6 +40,7 @@
#define TRACK_VARS_SERVER 3
#define TRACK_VARS_ENV 4
#define TRACK_VARS_FILES 5
+#define TRACK_VARS_REQUEST 6
struct _php_tick_function_entry;
@@ -118,6 +119,7 @@
zend_bool expose_php;
zend_bool register_globals;
+ zend_bool register_long_arrays;
zend_bool register_argc_argv;
zend_bool y2k_compliance;
@@ -130,17 +132,13 @@
long xmlrpc_error_number;
+ zend_bool activated_auto_globals[8];
zend_bool modules_activated;
-
zend_bool file_uploads;
-
zend_bool during_request_startup;
-
zend_bool allow_url_fopen;
-
zend_bool always_populate_raw_post_data;
-
zend_bool report_zend_debug;
};
Index: php4/main/php_variables.c
diff -u php4/main/php_variables.c:1.51 php4/main/php_variables.c:1.52
--- php4/main/php_variables.c:1.51 Thu Feb 20 17:21:48 2003
+++ php4/main/php_variables.c Sun Mar 2 05:19:15 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.c,v 1.51 2003/02/20 22:21:48 rasmus Exp $ */
+/* $Id: php_variables.c,v 1.52 2003/03/02 10:19:15 zeev Exp $ */
#include <stdio.h>
#include "php.h"
@@ -29,6 +29,7 @@
#include "zend_globals.h"
+
/* 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;
@@ -354,6 +355,343 @@
}
}
+
+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))
{
+ php_print_credits(PHP_CREDITS_ALL);
+ return 1;
+ }
+ }
+ return 0;
+}
+/* }}} */
+
+
+
+/* {{{ php_register_server_variables
+ */
+static inline void php_register_server_variables(TSRMLS_D)
+{
+ zval *array_ptr=NULL;
+
+ ALLOC_ZVAL(array_ptr);
+ array_init(array_ptr);
+ INIT_PZVAL(array_ptr);
+ PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
+
+ /* 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);
+ }
+}
+/* }}} */
+
+
+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);
+
+
+/* {{{ 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;
+ int i;
+ 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[] = {
+ { "_POST", sizeof("_POST"), "HTTP_POST_GLOBALS",
sizeof("HTTP_POST_GLOBALS"), 0 },
+ { "_GET", sizeof("_GET"), "HTTP_GET_GLOBALS",
sizeof("HTTP_GET_GLOBALS"), 0 },
+ { "_COOKIE", sizeof("_COOKIE"), "HTTP_COOKIE_GLOBALS",
sizeof("HTTP_COOKIE_GLOBALS"), 0 },
+ { "_SERVER", sizeof("_SERVER"), "HTTP_SERVER_GLOBALS",
sizeof("HTTP_SERVER_GLOBALS"), 1 },
+ { "_ENV", sizeof("_ENV"), "HTTP_ENV_GLOBALS",
sizeof("HTTP_ENV_GLOBALS"), 1 },
+ { "_FILES", sizeof("_FILES"), "HTTP_FILES_GLOBALS",
sizeof("HTTP_FILES_GLOBALS"), 0 },
+ };
+ size_t num_track_vars = sizeof(auto_global_records)/sizeof(struct
auto_global_record);
+
+ 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;
+ }
+ }
+
+ if (!jit_initialization) {
+ if (!have_variables_order) {
+ php_register_server_variables(TSRMLS_C);
+ }
+ if (!PG(http_globals)[TRACK_VARS_ENV]) {
+
+ }
+ }
+
+ 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 */
+ {
+ zval *form_variables;
+
+ 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 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)) {
+ zend_hash_update(&EG(symbol_table), "HTTP_SERVER_GLOBALS",
sizeof("HTTP_SERVER_GLOBALS"), &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *),
NULL);
+ 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)) {
+ zend_hash_update(&EG(symbol_table), "HTTP_ENV_GLOBALS",
sizeof("HTTP_ENV_GLOBALS"), &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
+ PG(http_globals)[TRACK_VARS_ENV]->refcount++;
+ }
+
+ return 0; /* don't rearm */
+}
+
+
+void php_startup_auto_globals(TSRMLS_D)
+{
+ zend_bool cb = (!PG(register_globals) && !PG(register_long_arrays));
+
+ 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);
+ zend_register_auto_global("_REQUEST", sizeof("_REQUEST")-1, NULL TSRMLS_CC);
+}
/*
* Local variables:
Index: php4/main/php_variables.h
diff -u php4/main/php_variables.h:1.15 php4/main/php_variables.h:1.16
--- php4/main/php_variables.h:1.15 Tue Dec 31 10:58:54 2002
+++ php4/main/php_variables.h Sun Mar 2 05:19:15 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.h,v 1.15 2002/12/31 15:58:54 sebastian Exp $ */
+/* $Id: php_variables.h,v 1.16 2003/03/02 10:19:15 zeev Exp $ */
#ifndef PHP_VARIABLES_H
#define PHP_VARIABLES_H
@@ -37,5 +37,9 @@
PHPAPI void php_register_variable_safe(char *var, char *val, int val_len, pval
*track_vars_array TSRMLS_DC);
PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array
TSRMLS_DC);
+int php_hash_environment(TSRMLS_D);
+
+
+#define NUM_TRACK_VARS 6
#endif /* PHP_VARIABLES_H */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php