1999-04-08 05:05:13 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-08 05:05:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 09:32:05 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-08 05:05:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| This source file is subject to version 2.0 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_0.txt. |
|
|
|
|
| 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-08 05:05:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
1999-07-16 21:13:16 +08:00
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
1999-04-08 05:05:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
*/
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "php.h"
|
|
|
|
#ifdef MSVC5
|
|
|
|
#include "win32/time.h"
|
|
|
|
#include "win32/signal.h"
|
|
|
|
#include <process.h>
|
|
|
|
#else
|
|
|
|
#include "build-defs.h"
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SETLOCALE
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
#include "zend.h"
|
|
|
|
#include "php_ini.h"
|
1999-04-10 03:09:29 +08:00
|
|
|
#include "php_globals.h"
|
1999-04-08 05:05:13 +08:00
|
|
|
#include "main.h"
|
|
|
|
#include "fopen-wrappers.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "ext/standard/php_standard.h"
|
1999-04-08 05:05:13 +08:00
|
|
|
#include "snprintf.h"
|
|
|
|
#if WIN32|WINNT
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "win32/syslog.h"
|
1999-04-18 23:58:27 +08:00
|
|
|
#include "win32/php_registry.h"
|
1999-04-08 05:05:13 +08:00
|
|
|
#else
|
|
|
|
#include <syslog.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "zend_compile.h"
|
|
|
|
#include "zend_execute.h"
|
|
|
|
#include "zend_highlight.h"
|
|
|
|
#include "zend_indent.h"
|
|
|
|
|
1999-09-17 07:18:15 +08:00
|
|
|
#include "php_content_types.h"
|
|
|
|
|
1999-04-26 03:35:44 +08:00
|
|
|
#include "SAPI.h"
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
#if MSVC5 || !defined(HAVE_GETOPT)
|
1999-05-29 21:53:59 +08:00
|
|
|
#include "php_getopt.h"
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-04-10 03:09:29 +08:00
|
|
|
#ifndef ZTS
|
|
|
|
php_core_globals core_globals;
|
1999-04-21 12:02:11 +08:00
|
|
|
#else
|
1999-04-26 22:00:49 +08:00
|
|
|
PHPAPI int core_globals_id;
|
1999-04-10 03:09:29 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-12 18:49:03 +08:00
|
|
|
#define NO_GLOBAL_LOCK
|
|
|
|
|
1999-12-20 05:02:54 +08:00
|
|
|
/* temporary workaround for thread-safety issues in Zend */
|
1999-10-09 00:24:31 +08:00
|
|
|
#if defined(ZTS) && !defined(NO_GLOBAL_LOCK)
|
1999-10-09 00:29:33 +08:00
|
|
|
static MUTEX_T global_lock;
|
1999-10-09 00:24:31 +08:00
|
|
|
#define global_lock() tsrm_mutex_lock(global_lock)
|
|
|
|
#define global_unlock() tsrm_mutex_unlock(global_lock);
|
|
|
|
#define global_lock_init() global_lock = tsrm_mutex_alloc()
|
|
|
|
#define global_lock_destroy() tsrm_mutex_free(global_lock)
|
|
|
|
#else
|
|
|
|
#define global_lock()
|
|
|
|
#define global_unlock()
|
|
|
|
#define global_lock_init()
|
|
|
|
#define global_lock_destroy()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-12-03 04:00:16 +08:00
|
|
|
void _php_build_argv(char * ELS_DC);
|
|
|
|
static void php_timeout(int dummy);
|
|
|
|
static void php_set_timeout(long seconds);
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
void *gLock; /*mutex variable */
|
|
|
|
|
|
|
|
|
|
|
|
/* True globals (no need for thread safety) */
|
|
|
|
HashTable configuration_hash;
|
1999-12-18 03:51:39 +08:00
|
|
|
PHPAPI char *php_ini_path = NULL;
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-06-26 20:27:49 +08:00
|
|
|
#define SAFE_FILENAME(f) ((f)?(f):"-")
|
|
|
|
|
1999-04-11 00:25:23 +08:00
|
|
|
static PHP_INI_MH(OnSetPrecision)
|
1999-04-10 03:09:29 +08:00
|
|
|
{
|
|
|
|
ELS_FETCH();
|
|
|
|
|
|
|
|
EG(precision) = atoi(new_value);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-11 00:25:23 +08:00
|
|
|
static PHP_INI_MH(OnChangeMaxExecutionTime)
|
|
|
|
{
|
|
|
|
int new_timeout;
|
1999-12-03 13:03:16 +08:00
|
|
|
PLS_FETCH();
|
1999-04-11 00:25:23 +08:00
|
|
|
|
|
|
|
if (new_value) {
|
|
|
|
new_timeout = atoi(new_value);
|
|
|
|
} else {
|
|
|
|
new_timeout = 0;
|
|
|
|
}
|
1999-12-03 13:03:16 +08:00
|
|
|
PG(max_execution_time) = new_timeout;
|
1999-12-03 04:00:16 +08:00
|
|
|
php_set_timeout(new_timeout);
|
1999-04-11 00:25:23 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-16 01:41:19 +08:00
|
|
|
#if MEMORY_LIMIT
|
1999-04-11 00:25:23 +08:00
|
|
|
static PHP_INI_MH(OnChangeMemoryLimit)
|
|
|
|
{
|
|
|
|
int new_limit;
|
|
|
|
|
|
|
|
if (new_value) {
|
|
|
|
new_limit = atoi(new_value);
|
|
|
|
} else {
|
1999-12-03 23:16:32 +08:00
|
|
|
new_limit = 1<<30; /* effectively, no limit */
|
1999-04-11 00:25:23 +08:00
|
|
|
}
|
|
|
|
return zend_set_memory_limit(new_limit);
|
|
|
|
}
|
1999-12-16 01:41:19 +08:00
|
|
|
#endif
|
1999-04-11 00:25:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
static PHP_INI_MH(OnUpdateErrorReporting)
|
|
|
|
{
|
|
|
|
ELS_FETCH();
|
|
|
|
|
|
|
|
if (!new_value) {
|
|
|
|
EG(error_reporting) = E_ALL & ~E_NOTICE;
|
|
|
|
} else {
|
|
|
|
EG(error_reporting) = atoi(new_value);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-10 20:17:20 +08:00
|
|
|
/* Need to convert to strings and make use of:
|
|
|
|
* DEFAULT_SHORT_OPEN_TAG
|
|
|
|
* PHP_SAFE_MODE
|
1999-04-10 21:32:47 +08:00
|
|
|
*
|
|
|
|
* Need to be read from the environment (?):
|
|
|
|
* PHP_AUTO_PREPEND_FILE
|
|
|
|
* PHP_AUTO_APPEND_FILE
|
1999-04-11 00:25:23 +08:00
|
|
|
* PHP_DOCUMENT_ROOT
|
|
|
|
* PHP_USER_DIR
|
|
|
|
* PHP_INCLUDE_PATH
|
1999-04-10 20:17:20 +08:00
|
|
|
*/
|
1999-04-10 21:32:47 +08:00
|
|
|
|
1999-04-10 20:17:20 +08:00
|
|
|
#ifndef SAFE_MODE_EXEC_DIR
|
|
|
|
# define SAFE_MODE_EXEC_DIR "/"
|
|
|
|
#endif
|
|
|
|
|
1999-04-10 21:32:47 +08:00
|
|
|
#ifdef PHP_PROG_SENDMAIL
|
|
|
|
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t"
|
|
|
|
#else
|
|
|
|
# define DEFAULT_SENDMAIL_PATH NULL
|
|
|
|
#endif
|
1999-04-10 03:09:29 +08:00
|
|
|
PHP_INI_BEGIN()
|
1999-09-06 03:49:54 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("short_open_tag", "1", PHP_INI_ALL, OnUpdateBool, short_tags, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_ALL, OnUpdateBool, asp_tags, php_core_globals, core_globals)
|
1999-12-16 05:20:34 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_ALL, OnUpdateBool, allow_call_time_pass_reference, php_core_globals, core_globals)
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
|
1999-09-06 03:49:54 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, output_buffering, php_core_globals, core_globals)
|
1999-04-10 03:09:29 +08:00
|
|
|
|
1999-05-09 16:48:05 +08:00
|
|
|
PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
|
|
|
PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
|
|
|
PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
|
|
|
PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
|
|
|
PHP_INI_ENTRY_EX("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
|
|
|
PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
|
1999-04-10 03:09:29 +08:00
|
|
|
|
1999-09-06 03:49:54 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_ALL, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals)
|
1999-04-10 20:17:20 +08:00
|
|
|
|
1999-09-13 04:36:48 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("safe_mode_exec_dir", "1", PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals)
|
1999-09-13 04:36:48 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
|
1999-04-10 21:32:47 +08:00
|
|
|
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("SMTP", "localhost", PHP_INI_ALL, NULL)
|
|
|
|
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
|
|
|
|
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
|
1999-04-10 21:32:47 +08:00
|
|
|
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("error_reporting", NULL, PHP_INI_ALL, OnUpdateErrorReporting)
|
1999-09-06 03:49:54 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("display_errors", "1", PHP_INI_ALL, OnUpdateBool, display_errors, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateString, error_log, php_core_globals, core_globals)
|
|
|
|
|
1999-04-10 21:32:47 +08:00
|
|
|
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_ALL, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_ALL, OnUpdateString, auto_append_file, php_core_globals, core_globals)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-09-06 03:49:54 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("y2k_compliance", "0", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, user_dir, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("include_path", NULL, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, open_basedir, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("extension_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("upload_max_filesize", "2097152", PHP_INI_ALL, OnUpdateInt, upload_max_filesize, php_core_globals, core_globals)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-05-09 16:48:05 +08:00
|
|
|
PHP_INI_ENTRY_EX("define_syslog_variables", "0", PHP_INI_ALL, NULL, php_ini_boolean_displayer_cb)
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnChangeMaxExecutionTime)
|
1999-11-25 23:24:49 +08:00
|
|
|
#if MEMORY_LIMIT
|
1999-04-29 05:29:31 +08:00
|
|
|
PHP_INI_ENTRY("memory_limit", "8388608", PHP_INI_ALL, OnChangeMemoryLimit)
|
1999-11-25 23:24:49 +08:00
|
|
|
#endif
|
1999-04-11 00:25:23 +08:00
|
|
|
|
1999-10-04 17:56:52 +08:00
|
|
|
#if PHP_TRACK_VARS /* "cc -32" on IRIX 6.4 does not like (PHP_TRACK_VARS?"1":"0") - thies 991004 */
|
|
|
|
STD_PHP_INI_BOOLEAN("track_vars", "1", PHP_INI_ALL, OnUpdateBool, track_vars, php_core_globals, core_globals)
|
1999-10-04 18:39:32 +08:00
|
|
|
#else
|
1999-10-04 17:56:52 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("track_vars", "0", PHP_INI_ALL, OnUpdateBool, track_vars, php_core_globals, core_globals)
|
|
|
|
#endif
|
|
|
|
|
1999-12-05 01:02:04 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("gpc_globals", "1", PHP_INI_ALL, OnUpdateBool, gpc_globals, php_core_globals, core_globals)
|
1999-04-29 05:14:47 +08:00
|
|
|
STD_PHP_INI_ENTRY("gpc_order", "GPC", PHP_INI_ALL, OnUpdateStringUnempty, gpc_order, php_core_globals, core_globals)
|
|
|
|
STD_PHP_INI_ENTRY("arg_separator", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator, php_core_globals, core_globals)
|
1999-09-12 04:36:47 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("ignore_user_abort", "1", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
|
1999-04-10 03:09:29 +08:00
|
|
|
PHP_INI_END()
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-04-24 06:45:01 +08:00
|
|
|
/* True global (no need for thread safety */
|
|
|
|
static int module_initialized = 0;
|
|
|
|
|
1999-12-18 03:16:50 +08:00
|
|
|
void php_log_err(char *log_message)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
FILE *log_file;
|
1999-12-16 01:37:05 +08:00
|
|
|
char error_time_str[128];
|
|
|
|
struct tm tmbuf;
|
|
|
|
time_t error_time;
|
1999-04-11 05:39:23 +08:00
|
|
|
PLS_FETCH();
|
1999-11-25 01:56:31 +08:00
|
|
|
#if APACHE
|
1999-04-27 01:26:37 +08:00
|
|
|
SLS_FETCH();
|
1999-11-25 01:56:31 +08:00
|
|
|
#endif
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
/* Try to use the specified logging location. */
|
1999-04-11 00:25:23 +08:00
|
|
|
if (PG(error_log) != NULL) {
|
1999-04-08 05:05:13 +08:00
|
|
|
#if HAVE_SYSLOG_H
|
1999-07-30 21:17:29 +08:00
|
|
|
if (!strcmp(PG(error_log), "syslog")) {
|
1999-04-08 05:05:13 +08:00
|
|
|
syslog(LOG_NOTICE, log_message);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
#endif
|
1999-04-11 00:25:23 +08:00
|
|
|
log_file = fopen(PG(error_log), "a");
|
1999-04-08 05:05:13 +08:00
|
|
|
if (log_file != NULL) {
|
1999-12-16 01:37:05 +08:00
|
|
|
time(&error_time);
|
|
|
|
strftime(error_time_str, 128, "%d-%b-%Y %H:%M:%S", localtime_r(&error_time, &tmbuf));
|
|
|
|
fprintf(log_file, "[%s] ", error_time_str);
|
1999-04-08 05:05:13 +08:00
|
|
|
fprintf(log_file, log_message);
|
|
|
|
fprintf(log_file, "\n");
|
|
|
|
fclose(log_file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if HAVE_SYSLOG_H
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* Otherwise fall back to the default logging location. */
|
|
|
|
#if APACHE
|
1999-04-27 01:26:37 +08:00
|
|
|
if (SG(server_context)) {
|
1999-04-08 05:05:13 +08:00
|
|
|
#if MODULE_MAGIC_NUMBER >= 19970831
|
1999-04-27 01:26:37 +08:00
|
|
|
aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, log_message);
|
1999-04-08 05:05:13 +08:00
|
|
|
#else
|
1999-04-27 01:26:37 +08:00
|
|
|
log_error(log_message, ((requset_rec *) SG(server_context))->server);
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, log_message);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif /*APACHE */
|
|
|
|
|
|
|
|
#if CGI_BINARY
|
1999-12-18 03:51:39 +08:00
|
|
|
if (php_header()) {
|
1999-04-08 05:05:13 +08:00
|
|
|
fprintf(stderr, log_message);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* is 4K big enough? */
|
|
|
|
#define PRINTF_BUFFER_SIZE 1024*4
|
|
|
|
|
|
|
|
/* wrapper for modules to use PHPWRITE */
|
1999-12-18 03:16:50 +08:00
|
|
|
PHPAPI int php_write(void *buf, int size)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
return PHPWRITE(buf, size);
|
|
|
|
}
|
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
PHPAPI int php_printf(const char *format,...)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
char buffer[PRINTF_BUFFER_SIZE];
|
|
|
|
int size;
|
|
|
|
|
|
|
|
va_start(args, format);
|
1999-09-04 01:46:39 +08:00
|
|
|
size = vsnprintf(buffer, sizeof(buffer), format, args);
|
1999-04-08 05:05:13 +08:00
|
|
|
ret = PHPWRITE(buffer, size);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* extended error handling function */
|
1999-08-03 03:17:14 +08:00
|
|
|
PHPAPI void php_error(int type, const char *format,...)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *error_filename = NULL;
|
|
|
|
uint error_lineno;
|
|
|
|
char buffer[1024];
|
|
|
|
int size = 0;
|
|
|
|
ELS_FETCH();
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-25 00:51:15 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
switch (type) {
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
case E_CORE_WARNING:
|
|
|
|
error_filename = NULL;
|
|
|
|
error_lineno = 0;
|
|
|
|
break;
|
|
|
|
case E_PARSE:
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
case E_COMPILE_WARNING: {
|
|
|
|
CLS_FETCH();
|
|
|
|
|
|
|
|
error_filename = zend_get_compiled_filename();
|
|
|
|
error_lineno = CG(zend_lineno);
|
1999-07-25 04:36:31 +08:00
|
|
|
if (!error_filename) {
|
|
|
|
error_filename = zend_get_executed_filename(ELS_C);
|
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_ERROR:
|
|
|
|
case E_NOTICE:
|
|
|
|
case E_WARNING:
|
|
|
|
error_filename = zend_get_executed_filename(ELS_C);
|
|
|
|
error_lineno = zend_get_executed_lineno(ELS_C);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_filename = NULL;
|
|
|
|
error_lineno = 0;
|
|
|
|
break;
|
|
|
|
}
|
1999-07-25 04:36:31 +08:00
|
|
|
|
|
|
|
if (!error_filename) {
|
|
|
|
error_filename = "Unknown";
|
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
if (EG(error_reporting) & type || (type & E_CORE)) {
|
|
|
|
char *error_type_str;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case E_ERROR:
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
error_type_str = "Fatal error";
|
|
|
|
break;
|
|
|
|
case E_WARNING:
|
|
|
|
case E_CORE_WARNING:
|
|
|
|
case E_COMPILE_WARNING:
|
|
|
|
error_type_str = "Warning";
|
|
|
|
break;
|
|
|
|
case E_PARSE:
|
|
|
|
error_type_str = "Parse error";
|
|
|
|
break;
|
|
|
|
case E_NOTICE:
|
|
|
|
error_type_str = "Warning";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_type_str = "Unknown error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get include file name */
|
1999-11-23 11:10:46 +08:00
|
|
|
if (PG(log_errors) || PG(display_errors) || (!module_initialized)) {
|
1999-04-08 05:05:13 +08:00
|
|
|
va_start(args, format);
|
|
|
|
size = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
|
|
|
va_end(args);
|
|
|
|
buffer[sizeof(buffer) - 1] = 0;
|
|
|
|
|
1999-11-23 11:10:46 +08:00
|
|
|
if (PG(log_errors) || (!module_initialized)) {
|
1999-04-08 05:05:13 +08:00
|
|
|
char log_buffer[1024];
|
|
|
|
|
1999-10-20 03:11:02 +08:00
|
|
|
snprintf(log_buffer, 1024, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
|
1999-12-18 03:16:50 +08:00
|
|
|
php_log_err(log_buffer);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
1999-04-10 21:32:47 +08:00
|
|
|
if (PG(display_errors)) {
|
1999-04-11 00:25:23 +08:00
|
|
|
char *prepend_string = INI_STR("error_prepend_string");
|
|
|
|
char *append_string = INI_STR("error_append_string");
|
|
|
|
|
|
|
|
if (prepend_string) {
|
|
|
|
PUTS(prepend_string);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
1999-10-20 03:11:02 +08:00
|
|
|
php_printf("<br>\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br>\n", error_type_str, buffer, error_filename, error_lineno);
|
1999-04-11 00:25:23 +08:00
|
|
|
if (append_string) {
|
|
|
|
PUTS(append_string);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-10 21:32:47 +08:00
|
|
|
if (PG(track_errors)) {
|
1999-07-21 23:10:04 +08:00
|
|
|
pval *tmp;
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
size = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
|
|
|
va_end(args);
|
|
|
|
buffer[sizeof(buffer) - 1] = 0;
|
|
|
|
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-07-21 23:10:04 +08:00
|
|
|
INIT_PZVAL(tmp);
|
|
|
|
tmp->value.str.val = (char *) estrndup(buffer, size);
|
|
|
|
tmp->value.str.len = size;
|
|
|
|
tmp->type = IS_STRING;
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case E_ERROR:
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
/*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
|
|
|
|
case E_COMPILE_ERROR:
|
1999-11-06 01:52:00 +08:00
|
|
|
if (module_initialized) {
|
|
|
|
zend_bailout();
|
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-31 23:39:13 +08:00
|
|
|
static long php_timeout_seconds;
|
1999-04-08 05:05:13 +08:00
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#ifdef HAVE_SETITIMER
|
1999-12-03 04:00:16 +08:00
|
|
|
static void php_timeout(int dummy)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
1999-04-11 05:34:53 +08:00
|
|
|
PLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-09-05 13:15:42 +08:00
|
|
|
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
|
1999-08-31 23:39:13 +08:00
|
|
|
php_error(E_ERROR, "Maximum execution time of %d second%s exceeded",
|
|
|
|
php_timeout_seconds, php_timeout_seconds == 1 ? "" : "s");
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This one doesn't exists on QNX */
|
|
|
|
#ifndef SIGPROF
|
|
|
|
#define SIGPROF 27
|
|
|
|
#endif
|
|
|
|
|
1999-12-03 04:00:16 +08:00
|
|
|
static void php_set_timeout(long seconds)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
#if WIN32|WINNT
|
|
|
|
#else
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
# ifdef HAVE_SETITIMER
|
1999-04-08 05:05:13 +08:00
|
|
|
struct itimerval t_r; /* timeout requested */
|
|
|
|
|
|
|
|
t_r.it_value.tv_sec = seconds;
|
|
|
|
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
|
|
|
|
|
1999-08-31 23:39:13 +08:00
|
|
|
php_timeout_seconds = seconds;
|
1999-04-08 05:05:13 +08:00
|
|
|
setitimer(ITIMER_PROF, &t_r, NULL);
|
1999-12-03 04:00:16 +08:00
|
|
|
signal(SIGPROF, php_timeout);
|
1999-04-25 00:17:04 +08:00
|
|
|
# endif
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-06 00:25:32 +08:00
|
|
|
static void php_unset_timeout(void)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
#if WIN32|WINNT
|
|
|
|
#else
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
# ifdef HAVE_SETITIMER
|
1999-04-08 05:05:13 +08:00
|
|
|
struct itimerval no_timeout;
|
|
|
|
|
|
|
|
no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;
|
|
|
|
|
|
|
|
setitimer(ITIMER_PROF, &no_timeout, NULL);
|
1999-04-25 00:17:04 +08:00
|
|
|
# endif
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-25 06:16:54 +08:00
|
|
|
PHP_FUNCTION(set_time_limit)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
pval *new_timeout;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-10 20:17:20 +08:00
|
|
|
if (PG(safe_mode)) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Cannot set time limit in safe mode");
|
1999-04-08 05:05:13 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &new_timeout) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(new_timeout);
|
|
|
|
/* FIXME ** This is BAD...in a threaded situation, any user
|
|
|
|
can set the timeout for php on a server wide basis.
|
|
|
|
INI variables should not be reset via a user script
|
|
|
|
|
|
|
|
Fix what? At least on Unix, timers like these are
|
|
|
|
per-thread timers. Well, with a little work they will
|
|
|
|
be. If we use a bound thread and proper masking it
|
|
|
|
should work fine. Is this FIXME a WIN32 problem? Is
|
|
|
|
there no way to do per-thread timers on WIN32?
|
|
|
|
*/
|
1999-12-03 04:00:16 +08:00
|
|
|
php_unset_timeout();
|
|
|
|
php_set_timeout(new_timeout->value.lval);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-01 04:18:11 +08:00
|
|
|
static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
int issock=0, socketd=0;
|
1999-08-01 02:57:41 +08:00
|
|
|
int old_chunk_size;
|
|
|
|
FILE *retval;
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
old_chunk_size = php_sock_set_def_chunk_size(1);
|
1999-12-18 03:16:50 +08:00
|
|
|
retval=php_fopen_wrapper((char *) filename, "r", USE_PATH|IGNORE_URL_WIN, &issock, &socketd, opened_path);
|
1999-12-18 03:51:39 +08:00
|
|
|
php_sock_set_def_chunk_size(old_chunk_size);
|
1999-08-01 02:57:41 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
if (issock) {
|
|
|
|
retval = fdopen(socketd, "r");
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-20 03:23:24 +08:00
|
|
|
static int php_get_ini_entry_for_zend(char *name, uint name_length, zval *contents)
|
|
|
|
{
|
1999-06-20 06:56:34 +08:00
|
|
|
zval *retval = cfg_get_entry(name, name_length);
|
1999-06-20 03:23:24 +08:00
|
|
|
|
1999-06-20 06:56:34 +08:00
|
|
|
if (retval) {
|
|
|
|
*contents = *retval;
|
1999-06-20 03:23:24 +08:00
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
static void php_message_handler_for_zend(long message, void *data)
|
|
|
|
{
|
|
|
|
switch (message) {
|
1999-04-21 12:02:11 +08:00
|
|
|
case ZMSG_ENABLE_TRACK_VARS: {
|
|
|
|
PLS_FETCH();
|
1999-08-28 22:00:44 +08:00
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
PG(track_vars) = 1;
|
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
break;
|
1999-06-11 19:59:35 +08:00
|
|
|
case ZMSG_FAILED_INCLUDE_FOPEN: {
|
|
|
|
PLS_FETCH();
|
|
|
|
|
1999-12-18 03:16:50 +08:00
|
|
|
php_error(E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
|
1999-06-11 19:59:35 +08:00
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
break;
|
1999-06-11 19:59:35 +08:00
|
|
|
case ZMSG_FAILED_REQUIRE_FOPEN: {
|
|
|
|
PLS_FETCH();
|
|
|
|
|
1999-12-18 03:16:50 +08:00
|
|
|
php_error(E_COMPILE_ERROR, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
|
1999-06-11 19:59:35 +08:00
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
break;
|
|
|
|
case ZMSG_FAILED_HIGHLIGHT_FOPEN:
|
1999-12-18 03:16:50 +08:00
|
|
|
php_error(E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
|
1999-04-08 05:05:13 +08:00
|
|
|
break;
|
1999-05-22 18:56:36 +08:00
|
|
|
case ZMSG_MEMORY_LEAK_DETECTED:
|
|
|
|
case ZMSG_MEMORY_LEAK_REPEATED: {
|
1999-04-08 05:05:13 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
|
|
|
|
if (EG(error_reporting)&E_WARNING) {
|
|
|
|
#if ZEND_DEBUG
|
|
|
|
char memory_leak_buf[512];
|
1999-05-22 18:56:36 +08:00
|
|
|
SLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-05-22 18:56:36 +08:00
|
|
|
if (message==ZMSG_MEMORY_LEAK_DETECTED) {
|
1999-12-27 04:45:42 +08:00
|
|
|
zend_mem_header *t = (zend_mem_header *) data;
|
|
|
|
void *ptr = (void *)((char *)t+sizeof(zend_mem_header)+PLATFORM_PADDING);
|
1999-05-22 18:56:36 +08:00
|
|
|
|
1999-09-17 09:16:54 +08:00
|
|
|
snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)ptr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
|
1999-08-28 19:17:28 +08:00
|
|
|
if (t->orig_filename) {
|
|
|
|
char relay_buf[512];
|
|
|
|
|
|
|
|
snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
|
|
|
|
strcat(memory_leak_buf, relay_buf);
|
|
|
|
}
|
1999-05-22 18:56:36 +08:00
|
|
|
} else {
|
1999-05-30 20:00:06 +08:00
|
|
|
unsigned long leak_count = (unsigned long) data;
|
1999-05-22 18:56:36 +08:00
|
|
|
|
1999-05-30 20:00:06 +08:00
|
|
|
snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
|
1999-05-22 18:56:36 +08:00
|
|
|
}
|
1999-05-21 03:06:28 +08:00
|
|
|
# if WIN32||WINNT
|
|
|
|
OutputDebugString(memory_leak_buf);
|
1999-04-08 05:05:13 +08:00
|
|
|
# else
|
1999-05-21 03:06:28 +08:00
|
|
|
fprintf(stderr, memory_leak_buf);
|
1999-04-08 05:05:13 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-06-01 03:58:20 +08:00
|
|
|
case ZMSG_LOG_SCRIPT_NAME: {
|
1999-11-27 00:32:02 +08:00
|
|
|
struct tm *ta, tmbuf;
|
1999-08-27 12:31:53 +08:00
|
|
|
time_t curtime;
|
1999-11-27 00:32:02 +08:00
|
|
|
char *datetime_str, asctimebuf[52];
|
1999-06-01 03:58:20 +08:00
|
|
|
SLS_FETCH();
|
|
|
|
|
1999-08-27 12:31:53 +08:00
|
|
|
time(&curtime);
|
1999-11-27 00:32:02 +08:00
|
|
|
ta = localtime_r(&curtime, &tmbuf);
|
|
|
|
datetime_str = asctime_r(ta, asctimebuf);
|
1999-09-02 03:28:07 +08:00
|
|
|
datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
|
1999-08-27 12:51:49 +08:00
|
|
|
fprintf(stderr, "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
|
1999-06-01 03:58:20 +08:00
|
|
|
}
|
1999-06-01 01:40:15 +08:00
|
|
|
break;
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-18 07:01:27 +08:00
|
|
|
static void php_start_post_request_startup(void *data)
|
|
|
|
{
|
|
|
|
php_post_request_startup *ptr = (php_post_request_startup *) data;
|
|
|
|
|
|
|
|
ptr->func(ptr->userdata);
|
|
|
|
}
|
|
|
|
|
1999-12-14 08:01:08 +08:00
|
|
|
static void php_execute_post_request_startup(PLS_D)
|
1999-11-18 07:01:27 +08:00
|
|
|
{
|
|
|
|
zend_llist_apply(&PG(ll_post_request_startup), php_start_post_request_startup);
|
1999-12-14 08:01:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void php_destroy_post_request_startup(void)
|
|
|
|
{
|
|
|
|
PLS_FETCH();
|
|
|
|
|
1999-11-18 07:01:27 +08:00
|
|
|
zend_llist_destroy(&PG(ll_post_request_startup));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void php_init_post_request_startup(PLS_D)
|
|
|
|
{
|
|
|
|
zend_llist_init(&PG(ll_post_request_startup), sizeof(php_post_request_startup), NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void php_register_post_request_startup(void (*func)(void *), void *userdata)
|
|
|
|
{
|
|
|
|
php_post_request_startup ptr;
|
|
|
|
PLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-11-18 07:01:27 +08:00
|
|
|
ptr.func = func;
|
|
|
|
ptr.userdata = userdata;
|
|
|
|
|
|
|
|
zend_llist_add_element(&PG(ll_post_request_startup), &ptr);
|
|
|
|
}
|
1999-04-26 03:35:44 +08:00
|
|
|
|
1999-05-06 05:05:44 +08:00
|
|
|
int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
1999-10-09 00:24:31 +08:00
|
|
|
global_lock();
|
|
|
|
|
1999-09-12 11:25:02 +08:00
|
|
|
php_output_startup();
|
1999-11-18 07:01:27 +08:00
|
|
|
php_init_post_request_startup(PLS_C);
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
#if APACHE
|
|
|
|
/*
|
|
|
|
* For the Apache module version, this bit of code registers a cleanup
|
|
|
|
* function that gets triggered when our request pool is destroyed.
|
|
|
|
* We need this because at any point in our code we can be interrupted
|
|
|
|
* and that may happen before we have had time to free our memory.
|
1999-12-18 03:51:39 +08:00
|
|
|
* The php_request_shutdown function needs to free all outstanding allocated
|
1999-04-08 05:05:13 +08:00
|
|
|
* memory.
|
|
|
|
*/
|
|
|
|
block_alarms();
|
1999-04-27 01:26:37 +08:00
|
|
|
register_cleanup(((request_rec *) SG(server_context))->pool, NULL, php_request_shutdown, php_request_shutdown_for_exec);
|
1999-04-08 05:05:13 +08:00
|
|
|
unblock_alarms();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* initialize global variables */
|
|
|
|
{
|
1999-04-24 04:20:30 +08:00
|
|
|
PG(header_is_being_sent)=0;
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
1999-12-22 03:43:38 +08:00
|
|
|
if (php_init_request_info(NULL)) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_printf("Unable to initialize request info.\n");
|
1999-04-08 05:05:13 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
1999-06-06 03:00:56 +08:00
|
|
|
|
|
|
|
zend_activate(CLS_C ELS_CC);
|
1999-05-06 05:05:44 +08:00
|
|
|
sapi_activate(SLS_C);
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-12-03 13:03:16 +08:00
|
|
|
php_set_timeout(PG(max_execution_time));
|
1999-12-03 20:21:57 +08:00
|
|
|
|
|
|
|
if (PG(expose_php)) {
|
|
|
|
sapi_add_header(estrdup(SAPI_PHP_VERSION_HEADER), sizeof(SAPI_PHP_VERSION_HEADER) - 1);
|
|
|
|
}
|
1999-12-03 13:03:16 +08:00
|
|
|
|
1999-11-23 04:58:56 +08:00
|
|
|
if (PG(output_buffering)) {
|
|
|
|
php_start_ob_buffering();
|
|
|
|
}
|
|
|
|
|
1999-05-13 05:35:16 +08:00
|
|
|
if (SG(request_info).auth_user) {
|
|
|
|
zval *auth_user;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(auth_user);
|
|
|
|
auth_user->type = IS_STRING;
|
|
|
|
auth_user->value.str.val = SG(request_info).auth_user;
|
|
|
|
auth_user->value.str.len = strlen(auth_user->value.str.val);
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), &auth_user, sizeof(zval *), NULL);
|
|
|
|
}
|
1999-05-13 23:54:49 +08:00
|
|
|
if (SG(request_info).auth_password) {
|
1999-05-13 05:35:16 +08:00
|
|
|
zval *auth_password;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(auth_password);
|
|
|
|
auth_password->type = IS_STRING;
|
|
|
|
auth_password->value.str.val = SG(request_info).auth_password;
|
|
|
|
auth_password->value.str.len = strlen(auth_password->value.str.val);
|
|
|
|
|
|
|
|
zend_hash_update(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), &auth_password, sizeof(zval *), NULL);
|
|
|
|
}
|
1999-11-18 07:01:27 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
void php_request_shutdown_for_exec(void *dummy)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
/* used to close fd's in the 3..255 range here, but it's problematic
|
|
|
|
*/
|
|
|
|
shutdown_memory_manager(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
void php_request_shutdown(void *dummy)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
CLS_FETCH();
|
|
|
|
ELS_FETCH();
|
1999-05-06 05:05:44 +08:00
|
|
|
SLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-12-14 08:01:08 +08:00
|
|
|
php_destroy_post_request_startup();
|
1999-05-09 21:55:15 +08:00
|
|
|
sapi_send_headers();
|
1999-09-12 11:25:02 +08:00
|
|
|
php_end_ob_buffering(SG(request_info).headers_only?0:1);
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-12-05 22:16:37 +08:00
|
|
|
php_call_shutdown_functions();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-09 05:32:57 +08:00
|
|
|
php_ini_rshutdown();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-06-06 03:00:56 +08:00
|
|
|
zend_deactivate(CLS_C ELS_CC);
|
1999-05-06 05:29:26 +08:00
|
|
|
sapi_deactivate(SLS_C);
|
|
|
|
|
1999-12-22 03:43:38 +08:00
|
|
|
php_destroy_request_info(NULL);
|
1999-05-12 00:52:58 +08:00
|
|
|
shutdown_memory_manager(CG(unclean_shutdown), 0);
|
1999-12-03 04:00:16 +08:00
|
|
|
php_unset_timeout();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if CGI_BINARY
|
|
|
|
fflush(stdout);
|
1999-04-24 08:12:00 +08:00
|
|
|
if(request_info.php_argv0) {
|
|
|
|
free(request_info.php_argv0);
|
|
|
|
request_info.php_argv0 = NULL;
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
1999-10-09 00:24:31 +08:00
|
|
|
|
|
|
|
global_unlock();
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
static int php_config_ini_startup(void)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
1999-12-18 03:16:50 +08:00
|
|
|
if (php_init_config() == FAILURE) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_printf("PHP: Unable to parse configuration file.\n");
|
1999-04-08 05:05:13 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
static void php_config_ini_shutdown(void)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
1999-12-18 03:16:50 +08:00
|
|
|
php_shutdown_config();
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-09-12 11:25:02 +08:00
|
|
|
static int php_body_write_wrapper(const char *str, uint str_length)
|
1999-04-26 03:35:44 +08:00
|
|
|
{
|
1999-09-12 11:25:02 +08:00
|
|
|
return php_body_write(str, str_length);
|
1999-04-26 03:35:44 +08:00
|
|
|
}
|
|
|
|
|
1999-08-14 05:03:27 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
static void php_new_thread_end_handler(THREAD_T thread_id)
|
1999-05-07 05:58:49 +08:00
|
|
|
{
|
1999-08-14 05:03:27 +08:00
|
|
|
php_ini_refresh_caches();
|
1999-05-07 05:58:49 +08:00
|
|
|
}
|
1999-08-14 05:03:27 +08:00
|
|
|
#endif
|
1999-05-07 05:58:49 +08:00
|
|
|
|
|
|
|
|
1999-08-26 00:24:14 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
static void core_globals_ctor(php_core_globals *core_globals)
|
|
|
|
{
|
1999-11-23 11:10:46 +08:00
|
|
|
memset(core_globals,0,sizeof(*core_globals));
|
1999-08-26 00:24:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-12-08 04:49:01 +08:00
|
|
|
int php_startup_extensions(zend_module_entry **ptr, int count)
|
|
|
|
{
|
|
|
|
zend_module_entry **end = ptr+count;
|
|
|
|
|
|
|
|
while (ptr < end) {
|
|
|
|
if (*ptr) {
|
|
|
|
if (zend_startup_module(*ptr)==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int php_global_startup_extensions(zend_module_entry **ptr, int count)
|
|
|
|
{
|
|
|
|
zend_module_entry **end = ptr+count;
|
|
|
|
|
|
|
|
while (ptr < end) {
|
|
|
|
if (*ptr) {
|
|
|
|
if ((*ptr)->global_startup_func &&
|
|
|
|
(*ptr)->global_startup_func()==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int php_global_shutdown_extensions(zend_module_entry **ptr, int count)
|
|
|
|
{
|
|
|
|
zend_module_entry **end = ptr+count;
|
|
|
|
|
|
|
|
while (ptr < end) {
|
|
|
|
if (*ptr) {
|
|
|
|
if ((*ptr)->global_shutdown_func &&
|
|
|
|
(*ptr)->global_shutdown_func()==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-03 02:07:41 +08:00
|
|
|
int php_module_startup(sapi_module_struct *sf)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
zend_utility_functions zuf;
|
|
|
|
zend_utility_values zuv;
|
1999-04-10 03:09:29 +08:00
|
|
|
int module_number=0; /* for REGISTER_INI_ENTRIES() */
|
1999-12-18 04:55:31 +08:00
|
|
|
char *php_os;
|
1999-04-21 12:02:11 +08:00
|
|
|
#ifdef ZTS
|
1999-08-20 00:52:53 +08:00
|
|
|
zend_executor_globals *executor_globals;
|
1999-04-21 12:02:11 +08:00
|
|
|
php_core_globals *core_globals;
|
1999-05-09 16:48:05 +08:00
|
|
|
sapi_globals_struct *sapi_globals = ts_resource(sapi_globals_id);
|
1999-04-21 12:02:11 +08:00
|
|
|
#endif
|
1999-04-08 05:05:13 +08:00
|
|
|
#if (WIN32|WINNT) && !(USE_SAPI)
|
1999-07-25 00:52:00 +08:00
|
|
|
WORD wVersionRequested = MAKEWORD(2, 0);
|
1999-04-08 05:05:13 +08:00
|
|
|
WSADATA wsaData;
|
1999-04-24 06:45:01 +08:00
|
|
|
#endif
|
1999-12-18 04:55:31 +08:00
|
|
|
#if WIN32|WINNT
|
1999-12-19 01:44:56 +08:00
|
|
|
{
|
|
|
|
DWORD dwVersion = GetVersion();
|
|
|
|
|
|
|
|
/* Get build numbers for Windows NT or Win95 */
|
|
|
|
if (dwVersion < 0x80000000){
|
|
|
|
php_os="WINNT";
|
|
|
|
} else {
|
|
|
|
php_os="WIN32";
|
|
|
|
}
|
|
|
|
}
|
1999-12-18 04:55:31 +08:00
|
|
|
#else
|
|
|
|
php_os=PHP_OS;
|
|
|
|
#endif
|
1999-04-24 06:45:01 +08:00
|
|
|
|
1999-10-09 00:24:31 +08:00
|
|
|
global_lock_init();
|
1999-05-09 16:48:05 +08:00
|
|
|
SG(server_context) = NULL;
|
1999-05-22 09:15:25 +08:00
|
|
|
SG(request_info).request_method = NULL;
|
1999-05-09 16:48:05 +08:00
|
|
|
sapi_activate(SLS_C);
|
1999-04-24 06:45:01 +08:00
|
|
|
|
|
|
|
if (module_initialized) {
|
1999-04-08 05:05:13 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-05-03 02:07:41 +08:00
|
|
|
sapi_module = *sf;
|
1999-04-27 04:20:12 +08:00
|
|
|
|
1999-09-12 11:25:02 +08:00
|
|
|
php_output_startup();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
zuf.error_function = php_error;
|
|
|
|
zuf.printf_function = php_printf;
|
1999-09-12 11:25:02 +08:00
|
|
|
zuf.write_function = php_body_write_wrapper;
|
1999-04-08 05:05:13 +08:00
|
|
|
zuf.fopen_function = php_fopen_wrapper_for_zend;
|
|
|
|
zuf.message_handler = php_message_handler_for_zend;
|
|
|
|
zuf.block_interruptions = BLOCK_INTERRUPTIONS;
|
|
|
|
zuf.unblock_interruptions = UNBLOCK_INTERRUPTIONS;
|
1999-06-20 03:23:24 +08:00
|
|
|
zuf.get_ini_entry = php_get_ini_entry_for_zend;
|
1999-04-10 19:22:18 +08:00
|
|
|
zend_startup(&zuf, NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
#ifdef ZTS
|
1999-08-14 17:55:43 +08:00
|
|
|
tsrm_set_new_thread_end_handler(php_new_thread_end_handler);
|
1999-08-20 00:52:53 +08:00
|
|
|
executor_globals = ts_resource(executor_globals_id);
|
1999-12-06 00:25:32 +08:00
|
|
|
core_globals_id = ts_allocate_id(sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL);
|
1999-04-21 12:02:11 +08:00
|
|
|
core_globals = ts_resource(core_globals_id);
|
1999-04-26 03:35:44 +08:00
|
|
|
#endif
|
1999-08-20 00:52:53 +08:00
|
|
|
EG(error_reporting) = E_ALL & ~E_NOTICE;
|
|
|
|
|
1999-04-29 01:38:24 +08:00
|
|
|
PG(header_is_being_sent) = 0;
|
1999-05-09 16:48:05 +08:00
|
|
|
SG(request_info).headers_only = 0;
|
1999-09-07 06:40:27 +08:00
|
|
|
PG(connection_status) = PHP_CONNECTION_NORMAL;
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
#if HAVE_SETLOCALE
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (WIN32|WINNT) && !(USE_SAPI)
|
|
|
|
/* start up winsock services */
|
|
|
|
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
|
1999-04-08 05:05:13 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SET_MUTEX(gLock);
|
|
|
|
le_index_ptr = _register_list_destructors(NULL, NULL, 0);
|
|
|
|
FREE_MUTEX(gLock);
|
|
|
|
|
1999-08-14 05:03:27 +08:00
|
|
|
php_ini_mstartup();
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
if (php_config_ini_startup() == FAILURE) {
|
1999-04-08 05:05:13 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-04-10 03:09:29 +08:00
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
|
1999-12-16 05:20:34 +08:00
|
|
|
zuv.short_tags = (zend_bool) PG(short_tags);
|
|
|
|
zuv.asp_tags = (zend_bool) PG(asp_tags);
|
|
|
|
zuv.allow_call_time_pass_reference = PG(allow_call_time_pass_reference);
|
1999-12-04 21:25:41 +08:00
|
|
|
zuv.import_use_extension = ".php";
|
1999-04-10 19:22:18 +08:00
|
|
|
zend_set_utility_values(&zuv);
|
1999-09-17 07:18:15 +08:00
|
|
|
php_startup_SAPI_content_types();
|
1999-04-10 19:22:18 +08:00
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
|
|
|
|
|
1999-12-08 04:49:01 +08:00
|
|
|
if (php_startup_internal_extensions() == FAILURE) {
|
|
|
|
php_printf("Unable to start builtin modules\n");
|
1999-04-08 05:05:13 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
1999-04-24 06:45:01 +08:00
|
|
|
module_initialized = 1;
|
1999-05-09 16:48:05 +08:00
|
|
|
sapi_deactivate(SLS_C);
|
1999-04-08 05:05:13 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-05-28 11:54:15 +08:00
|
|
|
void php_module_shutdown_for_exec()
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
/* used to close fd's in the range 3.255 here, but it's problematic */
|
|
|
|
}
|
|
|
|
|
1999-05-03 02:07:41 +08:00
|
|
|
|
|
|
|
int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
|
|
|
|
{
|
|
|
|
php_module_shutdown();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
void php_module_shutdown()
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
1999-04-10 03:09:29 +08:00
|
|
|
int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-24 08:12:00 +08:00
|
|
|
if (!module_initialized) {
|
|
|
|
return;
|
|
|
|
}
|
1999-04-08 05:05:13 +08:00
|
|
|
#if !USE_SAPI
|
|
|
|
/* close down the ini config */
|
1999-12-18 03:51:39 +08:00
|
|
|
php_config_ini_shutdown();
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (WIN32|WINNT) && !(USE_SAPI)
|
|
|
|
/*close winsock */
|
1999-04-24 06:45:01 +08:00
|
|
|
WSACleanup();
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CGI_BINARY
|
|
|
|
fflush(stdout);
|
|
|
|
#endif
|
|
|
|
#if 0 /* SAPI */
|
1999-04-24 08:12:00 +08:00
|
|
|
sapi_rqst->flush(sapi_rqst->scid);
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
|
|
|
|
1999-10-09 00:24:31 +08:00
|
|
|
global_lock_destroy();
|
1999-04-08 05:05:13 +08:00
|
|
|
zend_shutdown();
|
1999-04-10 03:09:29 +08:00
|
|
|
UNREGISTER_INI_ENTRIES();
|
1999-04-09 05:32:57 +08:00
|
|
|
php_ini_mshutdown();
|
1999-04-08 05:05:13 +08:00
|
|
|
shutdown_memory_manager(0, 1);
|
1999-04-24 06:45:01 +08:00
|
|
|
module_initialized = 0;
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* in 3.1 some of this should move into sapi */
|
1999-09-11 22:09:29 +08:00
|
|
|
static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
char **env, *p, *t;
|
|
|
|
unsigned char _gpc_flags[3] = {0,0,0};
|
|
|
|
pval *tmp;
|
|
|
|
|
1999-04-11 00:25:23 +08:00
|
|
|
p = PG(gpc_order);
|
1999-04-08 05:05:13 +08:00
|
|
|
while(*p) {
|
|
|
|
switch(*p++) {
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
1999-05-09 16:48:05 +08:00
|
|
|
if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
|
1999-09-11 22:09:29 +08:00
|
|
|
php_treat_data(PARSE_POST, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */
|
1999-04-08 05:05:13 +08:00
|
|
|
_gpc_flags[0]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
if (!_gpc_flags[1]) {
|
1999-09-11 22:09:29 +08:00
|
|
|
php_treat_data(PARSE_COOKIE, NULL ELS_CC PLS_CC SLS_CC); /* Cookie Data */
|
1999-04-08 05:05:13 +08:00
|
|
|
_gpc_flags[1]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
if (!_gpc_flags[2]) {
|
1999-09-11 22:09:29 +08:00
|
|
|
php_treat_data(PARSE_GET, NULL ELS_CC PLS_CC SLS_CC); /* GET Data */
|
1999-04-08 05:05:13 +08:00
|
|
|
_gpc_flags[2]=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (env = environ; env != NULL && *env != NULL; env++) {
|
|
|
|
p = strchr(*env, '=');
|
|
|
|
if (!p) { /* malformed entry? */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
t = estrndup(*env, p - *env);
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->value.str.len = strlen(p + 1);
|
|
|
|
tmp->value.str.val = estrndup(p + 1, tmp->value.str.len);
|
|
|
|
tmp->type = IS_STRING;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
/* environmental variables never take precedence over get/post/cookie variables */
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&EG(symbol_table), t, p - *env + 1, &tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
efree(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if APACHE
|
|
|
|
{
|
|
|
|
pval **tmp_ptr;
|
|
|
|
register int i;
|
1999-04-27 01:26:37 +08:00
|
|
|
array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
|
1999-04-08 05:05:13 +08:00
|
|
|
table_entry *elts = (table_entry *) arr->elts;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
for (i = 0; i < arr->nelts; i++) {
|
|
|
|
len = strlen(elts[i].key);
|
|
|
|
t = elts[i].key;
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
if (elts[i].val) {
|
|
|
|
tmp->value.str.len = strlen(elts[i].val);
|
|
|
|
tmp->value.str.val = estrndup(elts[i].val, tmp->value.str.len);
|
|
|
|
} else {
|
|
|
|
tmp->value.str.len = 0;
|
|
|
|
tmp->value.str.val = empty_string;
|
|
|
|
}
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->type = IS_STRING;
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), t, strlen(t)+1, &tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
/* insert special variables */
|
1999-08-03 03:17:14 +08:00
|
|
|
if (zend_hash_find(&EG(symbol_table), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &tmp_ptr) == SUCCESS) {
|
1999-04-08 05:05:13 +08:00
|
|
|
(*tmp_ptr)->refcount++;
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), tmp_ptr, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-27 01:26:37 +08:00
|
|
|
tmp->value.str.len = strlen(((request_rec *) SG(server_context))->uri);
|
|
|
|
tmp->value.str.val = estrndup(((request_rec *) SG(server_context))->uri, tmp->value.str.len);
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->type = IS_STRING;
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) &tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
/* Build the special-case PHP_SELF variable for the CGI version */
|
|
|
|
char *pi;
|
|
|
|
#if FORCE_CGI_REDIRECT
|
1999-05-03 03:54:02 +08:00
|
|
|
pi = SG(request_info).request_uri;
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->value.str.val = emalloc(((pi)?strlen(pi):0) + 1);
|
1999-08-03 03:17:14 +08:00
|
|
|
tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s", (pi ? pi : "")); /* SAFE */
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->type = IS_STRING;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
#else
|
|
|
|
int l = 0;
|
|
|
|
char *sn;
|
1999-04-24 08:12:00 +08:00
|
|
|
sn = request_info.script_name;
|
1999-05-03 03:54:02 +08:00
|
|
|
pi = SG(request_info).request_uri;
|
1999-04-08 05:05:13 +08:00
|
|
|
if (sn)
|
|
|
|
l += strlen(sn);
|
|
|
|
if (pi)
|
|
|
|
l += strlen(pi);
|
|
|
|
if (pi && sn && !strcmp(pi, sn)) {
|
|
|
|
l -= strlen(pi);
|
|
|
|
pi = NULL;
|
|
|
|
}
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->value.str.val = emalloc(l + 1);
|
1999-08-03 03:17:14 +08:00
|
|
|
tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s%s", (sn ? sn : ""), (pi ? pi : "")); /* SAFE */
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->type = IS_STRING;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
#endif
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* need argc/argv support as well */
|
1999-12-03 04:00:16 +08:00
|
|
|
_php_build_argv(SG(request_info).query_string ELS_CC);
|
1999-04-08 05:05:13 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-12-03 04:00:16 +08:00
|
|
|
void _php_build_argv(char *s ELS_DC)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
pval *arr, *tmp;
|
|
|
|
int count = 0;
|
|
|
|
char *ss, *space;
|
|
|
|
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(arr);
|
1999-04-08 05:05:13 +08:00
|
|
|
arr->value.ht = (HashTable *) emalloc(sizeof(HashTable));
|
1999-12-22 01:14:31 +08:00
|
|
|
if (zend_hash_init(arr->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0) == FAILURE) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Unable to create argv array");
|
1999-04-08 05:05:13 +08:00
|
|
|
} else {
|
|
|
|
arr->type = IS_ARRAY;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(arr);
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
/* now pick out individual entries */
|
|
|
|
ss = s;
|
|
|
|
while (ss) {
|
|
|
|
space = strchr(ss, '+');
|
|
|
|
if (space) {
|
|
|
|
*space = '\0';
|
|
|
|
}
|
|
|
|
/* auto-type */
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->type = IS_STRING;
|
|
|
|
tmp->value.str.len = strlen(ss);
|
|
|
|
tmp->value.str.val = estrndup(ss, tmp->value.str.len);
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
count++;
|
1999-08-03 03:17:14 +08:00
|
|
|
if (zend_hash_next_index_insert(arr->value.ht, &tmp, sizeof(pval *), NULL)==FAILURE) {
|
1999-04-08 05:05:13 +08:00
|
|
|
if (tmp->type == IS_STRING) {
|
|
|
|
efree(tmp->value.str.val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (space) {
|
|
|
|
*space = '+';
|
|
|
|
ss = space + 1;
|
|
|
|
} else {
|
|
|
|
ss = space;
|
|
|
|
}
|
|
|
|
}
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(tmp);
|
1999-04-08 05:05:13 +08:00
|
|
|
tmp->value.lval = count;
|
|
|
|
tmp->type = IS_LONG;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(tmp);
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &tmp, sizeof(pval *), NULL);
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "logos.h"
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC)
|
1999-04-08 05:05:13 +08:00
|
|
|
{
|
|
|
|
zend_file_handle *prepend_file_p, *append_file_p;
|
|
|
|
zend_file_handle prepend_file, append_file;
|
1999-05-03 02:07:41 +08:00
|
|
|
SLS_FETCH();
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-08-08 02:21:35 +08:00
|
|
|
if (SG(request_info).query_string && SG(request_info).query_string[0]=='='
|
1999-09-13 04:36:48 +08:00
|
|
|
&& PG(expose_php)) {
|
1999-12-22 04:35:43 +08:00
|
|
|
if (!strcmp(SG(request_info).query_string+1, PHP_LOGO_GUID)) {
|
1999-05-06 02:25:20 +08:00
|
|
|
char *header_line = estrndup(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF));
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-05-06 03:53:15 +08:00
|
|
|
php4i_add_header_information(header_line, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1);
|
1999-04-08 05:05:13 +08:00
|
|
|
PHPWRITE(php4_logo, sizeof(php4_logo));
|
|
|
|
return;
|
1999-12-22 04:35:43 +08:00
|
|
|
} else if (!strcmp(SG(request_info).query_string+1, ZEND_LOGO_GUID)) {
|
1999-05-06 02:25:20 +08:00
|
|
|
char *header_line = estrndup(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF));
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-05-06 03:53:15 +08:00
|
|
|
php4i_add_header_information(header_line, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1);
|
1999-07-15 07:33:00 +08:00
|
|
|
PHPWRITE(zend_logo, sizeof(zend_logo));
|
1999-04-08 05:05:13 +08:00
|
|
|
return;
|
1999-07-18 03:17:42 +08:00
|
|
|
} else if (!strcmp(SG(request_info).query_string+1, "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000")) {
|
|
|
|
php_print_credits(PHP_CREDITS_ALL);
|
|
|
|
return;
|
1999-04-08 05:05:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(EG(bailout))!=0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-04-18 23:09:46 +08:00
|
|
|
#if WIN32||WINNT
|
|
|
|
UpdateIniFromRegistry(primary_file->filename);
|
|
|
|
#endif
|
1999-04-08 05:05:13 +08:00
|
|
|
|
1999-04-10 21:32:47 +08:00
|
|
|
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
|
|
|
|
prepend_file.filename = PG(auto_prepend_file);
|
1999-12-04 21:25:41 +08:00
|
|
|
prepend_file.free_filename = 0;
|
1999-04-08 05:05:13 +08:00
|
|
|
prepend_file.type = ZEND_HANDLE_FILENAME;
|
|
|
|
prepend_file_p = &prepend_file;
|
|
|
|
} else {
|
|
|
|
prepend_file_p = NULL;
|
|
|
|
}
|
1999-04-10 21:32:47 +08:00
|
|
|
if (PG(auto_append_file) && PG(auto_append_file)[0]) {
|
|
|
|
append_file.filename = PG(auto_append_file);
|
1999-12-04 21:25:41 +08:00
|
|
|
append_file.free_filename = 0;
|
1999-04-08 05:05:13 +08:00
|
|
|
append_file.type = ZEND_HANDLE_FILENAME;
|
|
|
|
append_file_p = &append_file;
|
|
|
|
} else {
|
|
|
|
append_file_p = NULL;
|
|
|
|
}
|
|
|
|
EG(main_op_array) = zend_compile_files(0 CLS_CC, 3, prepend_file_p, primary_file, append_file_p);
|
|
|
|
if (EG(main_op_array)) {
|
1999-09-12 00:16:16 +08:00
|
|
|
zend_hash_environment(PLS_C ELS_CC SLS_CC);
|
1999-04-08 05:05:13 +08:00
|
|
|
EG(active_op_array) = EG(main_op_array);
|
1999-12-14 08:01:08 +08:00
|
|
|
php_execute_post_request_startup(PLS_C);
|
1999-04-08 05:05:13 +08:00
|
|
|
zend_execute(EG(main_op_array) ELS_CC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
#if WIN32||WINNT
|
|
|
|
/* just so that this symbol gets exported... */
|
|
|
|
PHPAPI void dummy_indent()
|
|
|
|
{
|
|
|
|
zend_indent();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|