1999-04-08 05:05:13 +08:00
/*
2000-02-20 07:21:46 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 16:18:22 +08:00
| PHP Version 5 |
1999-04-08 05:05:13 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2005-08-03 22:08:58 +08:00
| Copyright ( c ) 1997 - 2005 The PHP Group |
1999-04-08 05:05:13 +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-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$ */
2001-06-06 21:06:12 +08:00
/* {{{ includes
*/
2003-02-17 21:29:59 +08:00
# define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
1999-04-08 05:05:13 +08:00
# include "php.h"
2003-03-02 18:19:15 +08:00
# include <stdio.h>
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
1999-04-08 05:05:13 +08:00
# include "win32/time.h"
# include "win32/signal.h"
# include <process.h>
2002-09-09 19:17:40 +08:00
# elif defined(NETWARE)
# include <sys/timeval.h>
# ifdef USE_WINSOCK
# include <novsock2.h>
# endif
1999-04-08 05:05:13 +08:00
# 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"
2000-10-03 22:43:04 +08:00
# include "zend_extensions.h"
1999-04-08 05:05:13 +08:00
# include "php_ini.h"
1999-04-10 03:09:29 +08:00
# include "php_globals.h"
2000-06-06 07:24:42 +08:00
# include "php_main.h"
2001-02-24 06:07:16 +08:00
# include "fopen_wrappers.h"
1999-12-05 03:19:57 +08:00
# include "ext/standard/php_standard.h"
2000-01-29 01:24:53 +08:00
# include "php_variables.h"
2000-11-21 06:31:38 +08:00
# include "ext/standard/credits.h"
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
1999-04-08 05:05:13 +08:00
# include <io.h>
# include <fcntl.h>
1999-04-18 23:58:27 +08:00
# include "win32/php_registry.h"
1999-04-08 05:05:13 +08:00
# endif
2000-05-29 00:22:28 +08:00
# include "php_syslog.h"
2004-02-12 18:43:27 +08:00
# include "Zend/zend_exceptions.h"
1999-04-08 05:05:13 +08:00
2000-05-19 18:48:05 +08:00
# if PHP_SIGCHILD
# include <sys/types.h>
# include <sys/wait.h>
# endif
1999-04-08 05:05:13 +08:00
# include "zend_compile.h"
# include "zend_execute.h"
# include "zend_highlight.h"
# include "zend_indent.h"
2000-10-18 02:12:31 +08:00
# include "zend_extensions.h"
2002-11-18 06:52:47 +08:00
# include "zend_ini.h"
1999-04-08 05:05:13 +08:00
1999-09-17 07:18:15 +08:00
# include "php_content_types.h"
2000-02-26 05:27:03 +08:00
# include "php_ticks.h"
2000-11-02 22:18:34 +08:00
# include "php_logos.h"
2002-03-16 05:03:08 +08:00
# include "php_streams.h"
1999-09-17 07:18:15 +08:00
1999-04-26 03:35:44 +08:00
# include "SAPI.h"
2002-07-12 09:49:58 +08:00
# include "rfc1867.h"
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-26 03:35:44 +08:00
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-10-09 00:24:31 +08:00
1999-06-26 20:27:49 +08:00
# define SAFE_FILENAME(f) ((f)?(f):"-")
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
1999-04-11 00:25:23 +08:00
static PHP_INI_MH ( OnSetPrecision )
1999-04-10 03:09:29 +08:00
{
EG ( precision ) = atoi ( new_value ) ;
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-10 03:09:29 +08:00
1999-12-16 01:41:19 +08:00
# if MEMORY_LIMIT
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
1999-04-11 00:25:23 +08:00
static PHP_INI_MH ( OnChangeMemoryLimit )
{
if ( new_value ) {
2003-08-23 04:01:53 +08:00
PG ( memory_limit ) = zend_atoi ( new_value , new_value_length ) ;
1999-04-11 00:25:23 +08:00
} else {
2003-08-23 04:01:53 +08:00
PG ( memory_limit ) = 1 < < 30 ; /* effectively, no limit */
1999-04-11 00:25:23 +08:00
}
2003-08-23 04:01:53 +08:00
return zend_set_memory_limit ( PG ( memory_limit ) ) ;
1999-04-11 00:25:23 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-12-16 01:41:19 +08:00
# endif
1999-04-11 00:25:23 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_disable_functions
*/
2001-07-31 12:53:54 +08:00
static void php_disable_functions ( TSRMLS_D )
2000-05-30 01:22:35 +08:00
{
2003-12-25 00:38:22 +08:00
char * s = NULL , * e ;
2002-12-16 23:43:52 +08:00
2003-12-25 00:38:22 +08:00
if ( ! * ( INI_STR ( " disable_functions " ) ) ) {
2002-12-16 23:43:52 +08:00
return ;
}
2003-12-25 00:38:22 +08:00
e = PG ( disable_functions ) = strdup ( INI_STR ( " disable_functions " ) ) ;
2002-12-16 23:43:52 +08:00
while ( * e ) {
switch ( * e ) {
case ' ' :
case ' , ' :
if ( s ) {
* e = ' \0 ' ;
zend_disable_function ( s , e - s TSRMLS_CC ) ;
s = NULL ;
}
break ;
default :
if ( ! s ) {
s = e ;
}
break ;
}
e + + ;
}
if ( s ) {
zend_disable_function ( s , e - s TSRMLS_CC ) ;
2000-05-30 01:22:35 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-05-30 01:22:35 +08:00
2003-03-03 09:27:22 +08:00
/* {{{ php_disable_classes
*/
static void php_disable_classes ( TSRMLS_D )
{
2003-12-25 00:38:22 +08:00
char * s = NULL , * e ;
2003-03-03 09:27:22 +08:00
2003-12-25 00:38:22 +08:00
if ( ! * ( INI_STR ( " disable_classes " ) ) ) {
2003-03-03 09:27:22 +08:00
return ;
}
2003-12-25 00:38:22 +08:00
e = PG ( disable_classes ) = strdup ( INI_STR ( " disable_classes " ) ) ;
2003-03-03 09:27:22 +08:00
while ( * e ) {
switch ( * e ) {
case ' ' :
case ' , ' :
if ( s ) {
* e = ' \0 ' ;
zend_disable_class ( s , e - s TSRMLS_CC ) ;
s = NULL ;
}
break ;
default :
if ( ! s ) {
s = e ;
}
break ;
}
e + + ;
}
if ( s ) {
zend_disable_class ( s , e - s TSRMLS_CC ) ;
}
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
2000-06-16 10:27:47 +08:00
static PHP_INI_MH ( OnUpdateTimeout )
{
EG ( timeout_seconds ) = atoi ( new_value ) ;
if ( stage = = PHP_INI_STAGE_STARTUP ) {
/* Don't set a timeout on startup, only per-request */
return SUCCESS ;
}
2001-07-30 16:24:42 +08:00
zend_unset_timeout ( TSRMLS_C ) ;
2000-06-16 10:27:47 +08:00
zend_set_timeout ( EG ( timeout_seconds ) ) ;
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-06-16 10:27:47 +08:00
1999-04-10 20:17:20 +08:00
/* Need to convert to strings and make use of:
* 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
2003-04-29 05:00:32 +08:00
# ifndef PHP_SAFE_MODE_EXEC_DIR
# define PHP_SAFE_MODE_EXEC_DIR ""
1999-04-10 20:17:20 +08:00
# endif
2005-07-16 20:21:34 +08:00
# if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)
2000-08-05 06:42:11 +08:00
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
1999-04-10 21:32:47 +08:00
# else
# define DEFAULT_SENDMAIL_PATH NULL
# endif
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI
*/
1999-04-10 03:09:29 +08:00
PHP_INI_BEGIN ( )
2000-02-25 06:00:47 +08:00
PHP_INI_ENTRY_EX ( " define_syslog_variables " , " 0 " , PHP_INI_ALL , NULL , php_ini_boolean_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.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.keyword " , HL_KEYWORD_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 )
2001-08-05 09:43:02 +08:00
STD_PHP_INI_BOOLEAN ( " allow_call_time_pass_reference " , " 1 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateBool , allow_call_time_pass_reference , zend_compiler_globals , compiler_globals )
2000-06-07 03:16:57 +08:00
STD_PHP_INI_BOOLEAN ( " asp_tags " , " 0 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateBool , asp_tags , zend_compiler_globals , compiler_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_BOOLEAN ( " display_errors " , " 1 " , PHP_INI_ALL , OnUpdateBool , display_errors , php_core_globals , core_globals )
2000-09-09 23:02:15 +08:00
STD_PHP_INI_BOOLEAN ( " display_startup_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , display_startup_errors , php_core_globals , core_globals )
2000-02-25 06:00:47 +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 )
2003-03-19 06:21:54 +08:00
STD_PHP_INI_ENTRY ( " docref_root " , " " , PHP_INI_ALL , OnUpdateString , docref_root , php_core_globals , core_globals )
2002-08-09 03:12:27 +08:00
STD_PHP_INI_ENTRY ( " docref_ext " , " " , PHP_INI_ALL , OnUpdateString , docref_ext , php_core_globals , core_globals )
2003-03-19 06:21:54 +08:00
STD_PHP_INI_BOOLEAN ( " html_errors " , " 1 " , PHP_INI_ALL , OnUpdateBool , html_errors , php_core_globals , core_globals )
2001-07-10 23:59:33 +08:00
STD_PHP_INI_BOOLEAN ( " xmlrpc_errors " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , xmlrpc_errors , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " xmlrpc_error_number " , " 0 " , PHP_INI_ALL , OnUpdateLong , xmlrpc_error_number , php_core_globals , core_globals )
STD_PHP_INI_ENTRY ( " max_input_time " , " -1 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateLong , max_input_time , php_core_globals , core_globals )
2000-05-31 22:02:36 +08:00
STD_PHP_INI_BOOLEAN ( " ignore_user_abort " , " 0 " , PHP_INI_ALL , OnUpdateBool , ignore_user_abort , php_core_globals , core_globals )
2002-10-23 17:31:33 +08:00
STD_PHP_INI_BOOLEAN ( " implicit_flush " , " 0 " , PHP_INI_ALL , OnUpdateBool , implicit_flush , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_BOOLEAN ( " log_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , log_errors , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " log_errors_max_len " , " 1024 " , PHP_INI_ALL , OnUpdateLong , log_errors_max_len , php_core_globals , core_globals )
2002-04-07 02:49:59 +08:00
STD_PHP_INI_BOOLEAN ( " ignore_repeated_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , ignore_repeated_errors , php_core_globals , core_globals )
STD_PHP_INI_BOOLEAN ( " ignore_repeated_source " , " 0 " , PHP_INI_ALL , OnUpdateBool , ignore_repeated_source , php_core_globals , core_globals )
2002-10-25 00:56:59 +08:00
STD_PHP_INI_BOOLEAN ( " report_memleaks " , " 1 " , PHP_INI_ALL , OnUpdateBool , report_memleaks , php_core_globals , core_globals )
2002-11-21 22:56:06 +08:00
STD_PHP_INI_BOOLEAN ( " report_zend_debug " , " 1 " , PHP_INI_ALL , OnUpdateBool , report_zend_debug , php_core_globals , core_globals )
2002-10-23 17:35:21 +08:00
STD_PHP_INI_BOOLEAN ( " magic_quotes_gpc " , " 1 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateBool , magic_quotes_gpc , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
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 )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " output_buffering " , " 0 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateLong , output_buffering , php_core_globals , core_globals )
2002-10-23 17:35:21 +08:00
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 )
2003-04-25 18:57:23 +08:00
STD_PHP_INI_BOOLEAN ( " register_long_arrays " , " 1 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateBool , register_long_arrays , php_core_globals , core_globals )
2004-03-17 03:49:19 +08:00
STD_PHP_INI_BOOLEAN ( " auto_globals_jit " , " 1 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateBool , auto_globals_jit , php_core_globals , core_globals )
2002-01-19 11:15:03 +08:00
# if PHP_SAFE_MODE
STD_PHP_INI_BOOLEAN ( " safe_mode " , " 1 " , PHP_INI_SYSTEM , OnUpdateBool , safe_mode , php_core_globals , core_globals )
# else
2000-02-25 06:00:47 +08:00
STD_PHP_INI_BOOLEAN ( " safe_mode " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , safe_mode , php_core_globals , core_globals )
2002-01-19 11:15:03 +08:00
# endif
2001-07-14 02:21:21 +08:00
STD_PHP_INI_ENTRY ( " safe_mode_include_dir " , NULL , PHP_INI_SYSTEM , OnUpdateString , safe_mode_include_dir , php_core_globals , core_globals )
2002-10-23 17:35:21 +08:00
STD_PHP_INI_BOOLEAN ( " safe_mode_gid " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , safe_mode_gid , php_core_globals , core_globals )
STD_PHP_INI_BOOLEAN ( " short_open_tag " , DEFAULT_SHORT_OPEN_TAG , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateBool , short_tags , zend_compiler_globals , compiler_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_BOOLEAN ( " sql.safe_mode " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , sql_safe_mode , php_core_globals , core_globals )
STD_PHP_INI_BOOLEAN ( " track_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , track_errors , php_core_globals , core_globals )
2002-09-26 00:11:31 +08:00
STD_PHP_INI_BOOLEAN ( " y2k_compliance " , " 1 " , PHP_INI_ALL , OnUpdateBool , y2k_compliance , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
2002-10-23 17:35:21 +08:00
STD_PHP_INI_ENTRY ( " unserialize_callback_func " , NULL , PHP_INI_ALL , OnUpdateString , unserialize_callback_func , php_core_globals , core_globals )
2003-05-08 09:23:21 +08:00
STD_PHP_INI_ENTRY ( " serialize_precision " , " 100 " , PHP_INI_ALL , OnUpdateLong , serialize_precision , php_core_globals , core_globals )
2001-04-05 04:46:26 +08:00
STD_PHP_INI_ENTRY ( " arg_separator.output " , " & " , PHP_INI_ALL , OnUpdateStringUnempty , arg_separator . output , php_core_globals , core_globals )
STD_PHP_INI_ENTRY ( " arg_separator.input " , " & " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateStringUnempty , arg_separator . input , php_core_globals , core_globals )
2002-07-12 03:38:08 +08:00
STD_PHP_INI_ENTRY ( " auto_append_file " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateString , auto_append_file , php_core_globals , core_globals )
STD_PHP_INI_ENTRY ( " auto_prepend_file " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateString , auto_prepend_file , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_ENTRY ( " doc_root " , NULL , PHP_INI_SYSTEM , OnUpdateStringUnempty , doc_root , php_core_globals , core_globals )
2002-10-23 17:35:21 +08:00
STD_PHP_INI_ENTRY ( " default_charset " , SAPI_DEFAULT_CHARSET , PHP_INI_ALL , OnUpdateString , default_charset , sapi_globals_struct , sapi_globals )
STD_PHP_INI_ENTRY ( " default_mimetype " , SAPI_DEFAULT_MIMETYPE , PHP_INI_ALL , OnUpdateString , default_mimetype , sapi_globals_struct , sapi_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_ENTRY ( " error_log " , NULL , PHP_INI_ALL , OnUpdateString , error_log , php_core_globals , core_globals )
2000-05-02 22:46:20 +08:00
STD_PHP_INI_ENTRY ( " extension_dir " , PHP_EXTENSION_DIR , PHP_INI_SYSTEM , OnUpdateStringUnempty , extension_dir , php_core_globals , core_globals )
2000-07-18 19:02:28 +08:00
STD_PHP_INI_ENTRY ( " include_path " , PHP_INCLUDE_PATH , PHP_INI_ALL , OnUpdateStringUnempty , include_path , php_core_globals , core_globals )
2000-06-16 10:27:47 +08:00
PHP_INI_ENTRY ( " max_execution_time " , " 30 " , PHP_INI_ALL , OnUpdateTimeout )
2003-02-16 04:22:19 +08:00
STD_PHP_INI_ENTRY ( " open_basedir " , NULL , PHP_INI_SYSTEM , OnUpdateString , open_basedir , php_core_globals , core_globals )
2003-04-29 05:00:32 +08:00
STD_PHP_INI_ENTRY ( " safe_mode_exec_dir " , PHP_SAFE_MODE_EXEC_DIR , PHP_INI_SYSTEM , OnUpdateString , safe_mode_exec_dir , php_core_globals , core_globals )
2002-07-26 01:31:34 +08:00
STD_PHP_INI_BOOLEAN ( " file_uploads " , " 1 " , PHP_INI_SYSTEM , OnUpdateBool , file_uploads , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " upload_max_filesize " , " 2M " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateLong , upload_max_filesize , php_core_globals , core_globals )
STD_PHP_INI_ENTRY ( " post_max_size " , " 8M " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateLong , post_max_size , sapi_globals_struct , sapi_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_ENTRY ( " upload_tmp_dir " , NULL , PHP_INI_SYSTEM , OnUpdateStringUnempty , upload_tmp_dir , php_core_globals , core_globals )
2002-07-26 01:31:34 +08:00
2003-02-16 04:22:19 +08:00
STD_PHP_INI_ENTRY ( " user_dir " , NULL , PHP_INI_SYSTEM , OnUpdateString , user_dir , php_core_globals , core_globals )
2005-08-06 05:44:26 +08:00
STD_PHP_INI_ENTRY ( " variables_order " , " EGPCS " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateStringUnempty , variables_order , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
2002-11-19 22:11:50 +08:00
STD_PHP_INI_ENTRY ( " error_append_string " , NULL , PHP_INI_ALL , OnUpdateString , error_append_string , php_core_globals , core_globals )
STD_PHP_INI_ENTRY ( " error_prepend_string " , NULL , PHP_INI_ALL , OnUpdateString , error_prepend_string , php_core_globals , core_globals )
2001-05-06 23:22:22 +08:00
2000-02-25 06:00:47 +08:00
PHP_INI_ENTRY ( " SMTP " , " localhost " , PHP_INI_ALL , NULL )
2002-06-03 01:13:48 +08:00
PHP_INI_ENTRY ( " smtp_port " , " 25 " , PHP_INI_ALL , NULL )
2000-02-25 06:00:47 +08:00
PHP_INI_ENTRY ( " browscap " , NULL , PHP_INI_SYSTEM , NULL )
1999-11-25 23:24:49 +08:00
# if MEMORY_LIMIT
2000-09-09 23:02:15 +08:00
PHP_INI_ENTRY ( " memory_limit " , " 8M " , PHP_INI_ALL , OnChangeMemoryLimit )
1999-11-25 23:24:49 +08:00
# endif
2000-02-25 06:00:47 +08:00
PHP_INI_ENTRY ( " precision " , " 14 " , PHP_INI_ALL , OnSetPrecision )
PHP_INI_ENTRY ( " sendmail_from " , NULL , PHP_INI_ALL , NULL )
PHP_INI_ENTRY ( " sendmail_path " , DEFAULT_SENDMAIL_PATH , PHP_INI_SYSTEM , NULL )
2004-05-20 18:24:39 +08:00
PHP_INI_ENTRY ( " mail.force_extra_parameters " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , NULL )
2000-07-14 01:52:00 +08:00
PHP_INI_ENTRY ( " disable_functions " , " " , PHP_INI_SYSTEM , NULL )
2003-03-03 09:27:22 +08:00
PHP_INI_ENTRY ( " disable_classes " , " " , PHP_INI_SYSTEM , NULL )
2000-10-13 08:09:31 +08:00
2004-01-29 08:08:21 +08:00
STD_PHP_INI_BOOLEAN ( " allow_url_fopen " , " 1 " , PHP_INI_SYSTEM , OnUpdateBool , allow_url_fopen , php_core_globals , core_globals )
2002-06-19 08:18:40 +08:00
STD_PHP_INI_BOOLEAN ( " always_populate_raw_post_data " , " 0 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateBool , always_populate_raw_post_data , php_core_globals , core_globals )
2004-10-05 08:42:25 +08:00
# ifdef REALPATH_CACHE
STD_PHP_INI_ENTRY ( " realpath_cache_size " , " 16K " , PHP_INI_SYSTEM , OnUpdateLong , realpath_cache_size_limit , virtual_cwd_globals , cwd_globals )
STD_PHP_INI_ENTRY ( " realpath_cache_ttl " , " 120 " , PHP_INI_SYSTEM , OnUpdateLong , realpath_cache_ttl , virtual_cwd_globals , cwd_globals )
# endif
1999-04-10 03:09:29 +08:00
PHP_INI_END ( )
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-10 03:09:29 +08:00
2003-09-02 20:12:05 +08:00
/* True globals (no need for thread safety */
/* But don't make them a single int bitfield */
1999-04-24 06:45:01 +08:00
static int module_initialized = 0 ;
2003-09-02 20:12:05 +08:00
static int module_startup = 1 ;
static int module_shutdown = 0 ;
1999-04-24 06:45:01 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_log_err
*/
2001-08-06 00:21:33 +08:00
PHPAPI void php_log_err ( char * log_message TSRMLS_DC )
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-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 ) {
2000-05-29 00:22:28 +08:00
# ifdef HAVE_SYSLOG_H
1999-07-30 21:17:29 +08:00
if ( ! strcmp ( PG ( error_log ) , " syslog " ) ) {
2000-09-08 20:07:21 +08:00
php_syslog ( LOG_NOTICE , " %.500s " , log_message ) ;
1999-04-08 05:05:13 +08:00
return ;
}
# endif
2005-08-17 15:54:07 +08:00
log_file = VCWD_FOPEN ( PG ( error_log ) , " ab " ) ;
2000-02-10 23:55:10 +08:00
if ( log_file ! = NULL ) {
time ( & error_time ) ;
2002-08-20 02:40:28 +08:00
strftime ( error_time_str , sizeof ( error_time_str ) , " %d-%b-%Y %H:%M:%S " , php_localtime_r ( & error_time , & tmbuf ) ) ;
2000-02-10 23:55:10 +08:00
fprintf ( log_file , " [%s] " , error_time_str ) ;
2000-10-01 00:13:48 +08:00
fprintf ( log_file , " %s " , log_message ) ;
2003-09-25 07:20:48 +08:00
fprintf ( log_file , " %s " , PHP_EOL ) ;
2000-02-10 23:55:10 +08:00
fclose ( log_file ) ;
return ;
}
1999-04-08 05:05:13 +08:00
}
2000-02-10 23:55:10 +08:00
/* Otherwise fall back to the default logging location, if we have one */
if ( sapi_module . log_message ) {
sapi_module . log_message ( log_message ) ;
1999-04-08 05:05:13 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_write
wrapper for modules to use PHPWRITE */
2001-08-06 00:21:33 +08:00
PHPAPI int php_write ( void * buf , uint size TSRMLS_DC )
1999-04-08 05:05:13 +08:00
{
return PHPWRITE ( buf , size ) ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_printf
*/
2000-02-19 21:11:02 +08:00
PHPAPI int php_printf ( const char * format , . . . )
1999-04-08 05:05:13 +08:00
{
va_list args ;
int ret ;
2002-06-23 08:57:01 +08:00
char * buffer ;
1999-04-08 05:05:13 +08:00
int size ;
2001-08-05 23:55:43 +08:00
TSRMLS_FETCH ( ) ;
1999-04-08 05:05:13 +08:00
va_start ( args , format ) ;
2002-06-23 08:57:01 +08:00
size = vspprintf ( & buffer , 0 , format , args ) ;
2004-05-28 22:14:26 +08:00
ret = PHPWRITE ( buffer , size ) ;
efree ( buffer ) ;
1999-04-08 05:05:13 +08:00
va_end ( args ) ;
return ret ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2003-09-02 20:12:05 +08:00
/* {{{ php_verror helpers */
/* {{{ php_during_module_startup */
static int php_during_module_startup ( )
{
return module_startup ;
}
/* }}} */
/* {{{ php_during_module_shutdown */
static int php_during_module_shutdown ( )
{
return module_shutdown ;
}
/* }}} */
/* }}} */
2003-08-26 04:51:40 +08:00
2002-08-08 02:29:36 +08:00
/* {{{ php_verror */
2002-08-20 02:40:28 +08:00
/* php_verror is called from php_error_docref<n> functions.
* Its purpose is to unify error messages and automatically generate clickable
* html error messages if correcponding ini setting ( html_errors ) is activated .
* See : CODING_STANDARDS for details .
*/
2002-08-09 03:12:27 +08:00
PHPAPI void php_verror ( const char * docref , const char * params , int type , const char * format , va_list args TSRMLS_DC )
2002-08-08 02:29:36 +08:00
{
2003-12-12 15:59:46 +08:00
char * buffer = NULL , * docref_buf = NULL , * target = NULL ;
2002-08-10 05:57:03 +08:00
char * docref_target = " " , * docref_root = " " ;
2003-09-02 06:55:40 +08:00
char * p ;
2002-11-10 10:48:22 +08:00
int buffer_len = 0 ;
2003-08-26 04:51:40 +08:00
char * space ;
char * class_name = get_active_class_name ( & space TSRMLS_CC ) ;
2003-09-02 20:12:05 +08:00
char * function ;
2003-09-02 07:32:28 +08:00
char * origin ;
char * message ;
2003-09-02 20:12:05 +08:00
int is_function = 0 ;
2003-09-02 06:55:40 +08:00
2003-09-02 20:12:05 +08:00
/* get error text into buffer and escape for html if necessary */
2002-11-10 10:09:26 +08:00
buffer_len = vspprintf ( & buffer , 0 , format , args ) ;
2003-09-02 20:12:05 +08:00
if ( PG ( html_errors ) ) {
2003-09-02 07:32:28 +08:00
int len ;
char * replace = php_escape_html_entities ( buffer , buffer_len , & len , 0 , ENT_COMPAT , NULL TSRMLS_CC ) ;
efree ( buffer ) ;
buffer = replace ;
buffer_len = len ;
}
2003-09-02 20:12:05 +08:00
/* which function caused the problem if any at all */
if ( php_during_module_startup ( ) ) {
function = " PHP Startup " ;
} else if ( php_during_module_shutdown ( ) ) {
function = " PHP Shutdown " ;
} else {
function = get_active_function_name ( TSRMLS_C ) ;
2003-09-02 07:32:28 +08:00
if ( ! function | | ! strlen ( function ) ) {
function = " Unknown " ;
} else {
2003-09-02 20:12:05 +08:00
is_function = 1 ;
2003-03-08 23:20:12 +08:00
}
2003-09-02 07:32:28 +08:00
}
2003-03-08 23:20:12 +08:00
2003-09-02 20:12:05 +08:00
/* if we still have memory then format the origin */
if ( is_function ) {
spprintf ( & origin , 0 , " %s%s%s(%s) " , class_name , space , function , params ) ;
} else {
spprintf ( & origin , 0 , " %s " , function ) ;
}
/* origin and buffer available, so lets come up with the error message */
if ( docref & & docref [ 0 ] = = ' # ' ) {
docref_target = strchr ( docref , ' # ' ) ;
docref = NULL ;
}
2003-12-12 15:59:46 +08:00
/* no docref given but function is known (the default) */
2003-09-02 20:12:05 +08:00
if ( ! docref & & is_function ) {
spprintf ( & docref_buf , 0 , " function.%s " , function ) ;
while ( ( p = strchr ( docref_buf , ' _ ' ) ) ! = NULL ) {
* p = ' - ' ;
2002-08-13 17:37:51 +08:00
}
2003-09-02 20:12:05 +08:00
docref = docref_buf ;
}
2003-12-12 15:59:46 +08:00
/* we have a docref for a function AND
* - we show erroes in html mode OR
* - the user wants to see the links anyway
*/
2003-09-02 20:12:05 +08:00
if ( docref & & is_function & & ( PG ( html_errors ) | | strlen ( PG ( docref_root ) ) ) ) {
if ( strncmp ( docref , " http:// " , 7 ) ) {
2003-12-12 15:59:46 +08:00
/* We don't have 'http://' so we use docref_root */
char * ref ; /* temp copy for duplicated docref */
2003-09-02 20:12:05 +08:00
docref_root = PG ( docref_root ) ;
2003-12-12 15:59:46 +08:00
2003-09-02 20:12:05 +08:00
ref = estrdup ( docref ) ;
if ( docref_buf ) {
efree ( docref_buf ) ;
2002-08-09 03:12:27 +08:00
}
2003-09-02 20:12:05 +08:00
docref_buf = ref ;
2003-12-12 15:59:46 +08:00
/* strip of the target if any */
2003-09-02 20:12:05 +08:00
p = strrchr ( ref , ' # ' ) ;
if ( p ) {
target = estrdup ( p ) ;
if ( target ) {
docref_target = target ;
* p = ' \0 ' ;
2002-08-10 05:57:03 +08:00
}
}
2003-12-12 15:59:46 +08:00
/* add the extension if it is set in ini */
if ( PG ( docref_ext ) & & strlen ( PG ( docref_ext ) ) ) {
2003-09-02 20:12:05 +08:00
spprintf ( & docref_buf , 0 , " %s%s " , ref , PG ( docref_ext ) ) ;
efree ( ref ) ;
2002-11-10 10:48:22 +08:00
}
2003-12-12 15:59:46 +08:00
docref = docref_buf ;
2003-09-02 07:32:28 +08:00
}
2003-12-12 15:59:46 +08:00
/* display html formatted or only show the additional links */
2003-09-02 20:12:05 +08:00
if ( PG ( html_errors ) ) {
spprintf ( & message , 0 , " %s [<a href='%s%s%s'>%s</a>]: %s " , origin , docref_root , docref , docref_target , docref , buffer ) ;
} else {
spprintf ( & message , 0 , " %s [%s%s%s]: %s " , origin , docref_root , docref , docref_target , buffer ) ;
2002-08-09 03:12:27 +08:00
}
2003-09-02 20:12:05 +08:00
if ( target ) {
efree ( target ) ;
2002-11-10 10:48:22 +08:00
}
2002-08-08 02:29:36 +08:00
} else {
2003-09-04 22:43:36 +08:00
spprintf ( & message , 0 , " %s: %s " , origin , buffer ) ;
2003-09-02 20:12:05 +08:00
}
efree ( origin ) ;
if ( docref_buf ) {
efree ( docref_buf ) ;
}
php_error ( type , " %s " , message ) ;
efree ( message ) ;
2003-12-12 16:25:22 +08:00
if ( PG ( track_errors ) & & module_initialized & & EG ( active_symbol_table ) ) {
2003-09-02 20:12:05 +08:00
zval * tmp ;
ALLOC_INIT_ZVAL ( tmp ) ;
ZVAL_STRINGL ( tmp , buffer , buffer_len , 1 ) ;
zend_hash_update ( EG ( active_symbol_table ) , " php_errormsg " , sizeof ( " php_errormsg " ) , ( void * * ) & tmp , sizeof ( pval * ) , NULL ) ;
2002-08-08 02:29:36 +08:00
}
2003-09-18 08:04:57 +08:00
efree ( buffer ) ;
2002-08-08 02:29:36 +08:00
}
/* }}} */
2005-03-09 05:42:10 +08:00
/* {{{ php_error_docref0 */
2002-08-20 02:40:28 +08:00
/* See: CODING_STANDARDS for details. */
2005-03-09 05:42:10 +08:00
PHPAPI void php_error_docref0 ( const char * docref TSRMLS_DC , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
va_list args ;
va_start ( args , format ) ;
2002-08-09 03:12:27 +08:00
php_verror ( docref , " " , type , format , args TSRMLS_CC ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
}
/* }}} */
2002-08-09 03:12:27 +08:00
/* {{{ php_error_docref1 */
2002-08-20 02:40:28 +08:00
/* See: CODING_STANDARDS for details. */
2002-08-09 03:12:27 +08:00
PHPAPI void php_error_docref1 ( const char * docref TSRMLS_DC , const char * param1 , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
va_list args ;
va_start ( args , format ) ;
2002-08-09 03:12:27 +08:00
php_verror ( docref , param1 , type , format , args TSRMLS_CC ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
}
/* }}} */
2002-08-09 03:12:27 +08:00
/* {{{ php_error_docref2 */
2002-08-20 02:40:28 +08:00
/* See: CODING_STANDARDS for details. */
2002-08-09 03:12:27 +08:00
PHPAPI void php_error_docref2 ( const char * docref TSRMLS_DC , const char * param1 , const char * param2 , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
2002-08-09 03:12:27 +08:00
char * params ;
2002-08-08 02:29:36 +08:00
va_list args ;
2002-08-09 03:12:27 +08:00
spprintf ( & params , 0 , " %s,%s " , param1 , param2 ) ;
2002-08-08 02:29:36 +08:00
va_start ( args , format ) ;
2002-08-09 03:12:27 +08:00
php_verror ( docref , params ? params : " ... " , type , format , args TSRMLS_CC ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
2003-09-02 06:55:40 +08:00
if ( params ) {
2002-08-09 03:12:27 +08:00
efree ( params ) ;
2003-09-02 06:55:40 +08:00
}
2002-08-08 02:29:36 +08:00
}
/* }}} */
2002-05-11 20:41:33 +08:00
/* {{{ php_html_puts */
2002-03-05 02:46:55 +08:00
PHPAPI void php_html_puts ( const char * str , uint size TSRMLS_DC )
{
2002-10-20 10:57:40 +08:00
zend_html_puts ( str , size TSRMLS_CC ) ;
2002-03-05 02:46:55 +08:00
}
/* }}} */
2003-05-07 09:02:23 +08:00
/* {{{ php_suppress_errors */
2005-02-27 20:50:22 +08:00
PHPAPI void php_set_error_handling ( error_handling_t error_handling , zend_class_entry * exception_class TSRMLS_DC )
{
2003-05-07 09:02:23 +08:00
PG ( error_handling ) = error_handling ;
PG ( exception_class ) = exception_class ;
if ( PG ( last_error_message ) ) {
free ( PG ( last_error_message ) ) ;
PG ( last_error_message ) = NULL ;
}
if ( PG ( last_error_file ) ) {
free ( PG ( last_error_file ) ) ;
PG ( last_error_file ) = NULL ;
}
PG ( last_error_lineno ) = 0 ;
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_error_cb
extended error handling function */
2000-09-01 20:06:52 +08:00
static void php_error_cb ( int type , const char * error_filename , const uint error_lineno , const char * format , va_list args )
1999-04-08 05:05:13 +08:00
{
2002-04-10 09:27:44 +08:00
char * buffer ;
2002-04-07 02:49:59 +08:00
int buffer_len , display ;
2001-07-27 18:16:41 +08:00
TSRMLS_FETCH ( ) ;
1999-04-08 05:05:13 +08:00
2002-04-10 09:27:44 +08:00
buffer_len = vspprintf ( & buffer , PG ( log_errors_max_len ) , format , args ) ;
2003-05-07 09:02:23 +08:00
/* check for repeated errors to be ignored */
if ( PG ( ignore_repeated_errors ) & & PG ( last_error_message ) ) {
/* no check for PG(last_error_file) is needed since it cannot
* be NULL if PG ( last_error_message ) is not NULL */
if ( strcmp ( PG ( last_error_message ) , buffer )
2002-04-07 02:49:59 +08:00
| | ( ! PG ( ignore_repeated_source )
2003-05-07 09:02:23 +08:00
& & ( ( PG ( last_error_lineno ) ! = error_lineno )
| | strcmp ( PG ( last_error_file ) , error_filename ) ) ) ) {
2002-04-07 02:49:59 +08:00
display = 1 ;
} else {
display = 0 ;
}
} else {
display = 1 ;
}
2003-05-07 09:02:23 +08:00
/* store the error if it has changed */
if ( display ) {
if ( PG ( last_error_message ) ) {
free ( PG ( last_error_message ) ) ;
}
if ( PG ( last_error_file ) ) {
free ( PG ( last_error_file ) ) ;
}
PG ( last_error_message ) = strdup ( buffer ) ;
PG ( last_error_file ) = strdup ( error_filename ) ;
PG ( last_error_lineno ) = error_lineno ;
}
/* according to error handling mode, suppress error, throw exception or show it */
2003-08-26 04:51:40 +08:00
if ( PG ( error_handling ) ! = EH_NORMAL ) {
2003-05-07 09:02:23 +08:00
switch ( type ) {
case E_CORE_ERROR :
case E_COMPILE_ERROR :
case E_PARSE :
/* fatal errors are real errors and cannot be made exceptions */
break ;
2005-08-17 02:10:34 +08:00
case E_STRICT :
/* for the sake of BC to old damaged code */
break ;
2005-03-23 15:54:22 +08:00
case E_NOTICE :
case E_USER_NOTICE :
2005-03-24 09:11:11 +08:00
/* notices are no errors and are not treated as such like E_WARNINGS */
2005-03-23 15:54:22 +08:00
break ;
2003-05-07 09:02:23 +08:00
default :
/* throw an exception if we are in EH_THROW mode
2005-03-24 09:11:11 +08:00
* but DO NOT overwrite a pending exception
2003-05-07 09:02:23 +08:00
*/
if ( PG ( error_handling ) = = EH_THROW & & ! EG ( exception ) ) {
2004-07-16 06:22:06 +08:00
zend_throw_error_exception ( PG ( exception_class ) , buffer , 0 , type TSRMLS_CC ) ;
2003-05-07 09:02:23 +08:00
}
2003-08-26 04:51:40 +08:00
efree ( buffer ) ;
2003-05-07 09:02:23 +08:00
return ;
}
}
2000-09-01 20:06:52 +08:00
/* display/log the error if necessary */
2002-04-07 02:49:59 +08:00
if ( display & & ( EG ( error_reporting ) & type | | ( type & E_CORE ) )
2000-09-01 20:06:52 +08:00
& & ( PG ( log_errors ) | | PG ( display_errors ) | | ( ! module_initialized ) ) ) {
1999-04-08 05:05:13 +08:00
char * error_type_str ;
switch ( type ) {
case E_ERROR :
case E_CORE_ERROR :
case E_COMPILE_ERROR :
2000-04-19 23:10:14 +08:00
case E_USER_ERROR :
1999-04-08 05:05:13 +08:00
error_type_str = " Fatal error " ;
break ;
case E_WARNING :
case E_CORE_WARNING :
case E_COMPILE_WARNING :
2000-04-19 23:10:14 +08:00
case E_USER_WARNING :
1999-04-08 05:05:13 +08:00
error_type_str = " Warning " ;
break ;
case E_PARSE :
error_type_str = " Parse error " ;
break ;
case E_NOTICE :
2000-04-19 23:10:14 +08:00
case E_USER_NOTICE :
error_type_str = " Notice " ;
break ;
2003-11-19 14:11:47 +08:00
case E_STRICT :
error_type_str = " Strict Standards " ;
break ;
1999-04-08 05:05:13 +08:00
default :
error_type_str = " Unknown error " ;
break ;
}
2000-09-01 20:06:52 +08:00
if ( ! module_initialized | | PG ( log_errors ) ) {
2002-04-10 09:27:44 +08:00
char * log_buffer ;
1999-04-08 05:05:13 +08:00
2000-06-13 04:22:17 +08:00
# ifdef PHP_WIN32
2000-09-01 20:06:52 +08:00
if ( type = = E_CORE_ERROR | | type = = E_CORE_WARNING ) {
MessageBox ( NULL , buffer , error_type_str , MB_OK | ZEND_SERVICE_MB_STYLE ) ;
}
2000-06-13 04:22:17 +08:00
# endif
2002-04-10 09:27:44 +08:00
spprintf ( & log_buffer , 0 , " PHP %s: %s in %s on line %d " , error_type_str , buffer , error_filename , error_lineno ) ;
2001-08-06 00:21:33 +08:00
php_log_err ( log_buffer TSRMLS_CC ) ;
2002-04-10 09:27:44 +08:00
efree ( log_buffer ) ;
2000-09-01 20:06:52 +08:00
}
2004-02-16 01:00:42 +08:00
if ( PG ( display_errors )
2004-03-15 07:56:07 +08:00
& & ( ( module_initialized & & ! PG ( during_request_startup ) )
| | ( PG ( display_startup_errors )
& & ( OG ( php_body_write ) = = php_default_output_func | | OG ( php_body_write ) = = php_ub_body_write_no_header | | OG ( php_body_write ) = = php_ub_body_write )
)
)
) {
2000-09-01 20:06:52 +08:00
2001-07-10 23:59:33 +08:00
if ( PG ( xmlrpc_errors ) ) {
2003-03-30 21:59:05 +08:00
php_printf ( " <?xml version= \" 1.0 \" ?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse> " , PG ( xmlrpc_error_number ) , error_type_str , buffer , error_filename , error_lineno ) ;
} else {
char * prepend_string = INI_STR ( " error_prepend_string " ) ;
char * append_string = INI_STR ( " error_append_string " ) ;
char * error_format = PG ( html_errors ) ?
" %s<br /> \n <b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br /> \n %s "
: " %s \n %s: %s in %s on line %d \n %s " ;
2003-04-01 03:14:18 +08:00
php_printf ( error_format , STR_PRINT ( prepend_string ) , error_type_str , buffer , error_filename , error_lineno , STR_PRINT ( append_string ) ) ;
1999-04-08 05:05:13 +08:00
}
2000-09-01 20:06:52 +08:00
}
2000-06-03 11:05:29 +08:00
# if ZEND_DEBUG
2002-11-21 22:56:06 +08:00
if ( PG ( report_zend_debug ) ) {
2000-09-01 20:06:52 +08:00
zend_bool trigger_break ;
switch ( type ) {
case E_ERROR :
case E_CORE_ERROR :
case E_COMPILE_ERROR :
case E_USER_ERROR :
trigger_break = 1 ;
break ;
default :
trigger_break = 0 ;
break ;
2000-06-03 11:05:29 +08:00
}
2000-09-01 20:06:52 +08:00
zend_output_debug_string ( trigger_break , " %s(%d) : %s - %s " , error_filename , error_lineno , error_type_str , buffer ) ;
1999-04-08 05:05:13 +08:00
}
2000-09-01 20:06:52 +08:00
# endif
1999-04-08 05:05:13 +08:00
}
2000-01-15 21:02:54 +08:00
2000-09-01 20:06:52 +08:00
/* Bail out if we can't recover */
2000-01-15 21:02:54 +08:00
switch ( type ) {
case E_CORE_ERROR :
2000-07-03 00:36:31 +08:00
if ( ! module_initialized ) {
/* bad error in module startup - no way we can live with this */
exit ( - 2 ) ;
}
/* no break - intentionally */
case E_ERROR :
2004-02-09 12:04:24 +08:00
/* case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
2000-01-15 21:02:54 +08:00
case E_COMPILE_ERROR :
2000-04-19 23:10:14 +08:00
case E_USER_ERROR :
2003-03-19 16:22:12 +08:00
EG ( exit_status ) = 255 ;
2000-01-15 21:02:54 +08:00
if ( module_initialized ) {
2003-08-23 04:01:53 +08:00
# if MEMORY_LIMIT
/* restore memory limit */
AG ( memory_limit ) = PG ( memory_limit ) ;
# endif
2002-04-10 09:27:44 +08:00
efree ( buffer ) ;
2005-06-21 03:58:51 +08:00
zend_bailout ( ) ;
2000-01-15 21:02:54 +08:00
return ;
}
break ;
}
2000-09-01 20:06:52 +08:00
/* Log if necessary */
2002-04-10 09:27:44 +08:00
if ( ! display ) {
efree ( buffer ) ;
return ;
}
2003-12-12 16:25:22 +08:00
if ( PG ( track_errors ) & & module_initialized & & EG ( active_symbol_table ) ) {
1999-07-21 23:10:04 +08:00
pval * tmp ;
1999-04-08 05:05:13 +08:00
1999-12-27 05:21:33 +08:00
ALLOC_ZVAL ( tmp ) ;
1999-07-21 23:10:04 +08:00
INIT_PZVAL ( tmp ) ;
2001-09-26 05:58:48 +08:00
Z_STRVAL_P ( tmp ) = ( char * ) estrndup ( buffer , buffer_len ) ;
Z_STRLEN_P ( tmp ) = buffer_len ;
Z_TYPE_P ( tmp ) = IS_STRING ;
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
}
2002-04-10 09:27:44 +08:00
efree ( buffer ) ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2002-07-17 16:06:43 +08:00
/* {{{ proto bool set_time_limit(int seconds)
2000-05-18 03:45:46 +08:00
Sets the maximum time a script can run */
1999-07-25 06:16:54 +08:00
PHP_FUNCTION ( set_time_limit )
1999-04-08 05:05:13 +08:00
{
2000-06-11 18:27:36 +08:00
zval * * new_timeout ;
1999-04-08 05:05:13 +08:00
1999-04-10 20:17:20 +08:00
if ( PG ( safe_mode ) ) {
2002-12-06 05:53:25 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot set time limit in safe mode " ) ;
1999-04-08 05:05:13 +08:00
RETURN_FALSE ;
}
2000-06-11 18:27:36 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & new_timeout ) = = FAILURE ) {
1999-04-08 05:05:13 +08:00
WRONG_PARAM_COUNT ;
}
2000-06-11 18:27:36 +08:00
2001-11-19 22:59:38 +08:00
convert_to_string_ex ( new_timeout ) ;
2002-07-17 16:06:43 +08:00
if ( zend_alter_ini_entry ( " max_execution_time " , sizeof ( " max_execution_time " ) , Z_STRVAL_PP ( new_timeout ) , Z_STRLEN_PP ( new_timeout ) , PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) = = SUCCESS ) {
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
1999-04-08 05:05:13 +08:00
}
2000-05-18 03:45:46 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_fopen_wrapper_for_zend
*/
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
{
2002-03-18 16:05:28 +08:00
TSRMLS_FETCH ( ) ;
2002-03-16 05:03:08 +08:00
2002-10-28 11:45:21 +08:00
return php_stream_open_wrapper_as_file ( ( char * ) filename , " rb " , ENFORCE_SAFE_MODE | USE_PATH | IGNORE_URL_WIN | REPORT_ERRORS | STREAM_OPEN_FOR_INCLUDE , opened_path ) ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2003-02-18 17:37:54 +08:00
static void stream_closer_for_zend ( void * handle TSRMLS_DC )
{
php_stream_close ( ( php_stream * ) handle ) ;
}
2005-06-05 00:16:53 +08:00
static long stream_fteller_for_zend ( void * handle TSRMLS_DC )
{
return ( long ) php_stream_tell ( ( php_stream * ) handle ) ;
}
2003-02-18 17:37:54 +08:00
static int php_stream_open_for_zend ( const char * filename , zend_file_handle * handle TSRMLS_DC )
{
php_stream * stream ;
stream = php_stream_open_wrapper ( ( char * ) filename , " rb " , ENFORCE_SAFE_MODE | USE_PATH | REPORT_ERRORS | STREAM_OPEN_FOR_INCLUDE , & handle - > opened_path ) ;
if ( stream ) {
handle - > type = ZEND_HANDLE_STREAM ;
handle - > filename = ( char * ) filename ;
handle - > free_filename = 0 ;
handle - > handle . stream . handle = stream ;
handle - > handle . stream . reader = ( zend_stream_reader_t ) _php_stream_read ;
2005-06-09 20:15:14 +08:00
handle - > handle . stream . closer = stream_closer_for_zend ;
2005-06-05 00:16:53 +08:00
handle - > handle . stream . fteller = stream_fteller_for_zend ;
2003-02-18 17:37:54 +08:00
handle - > handle . stream . interactive = 0 ;
2005-06-06 09:51:48 +08:00
/* suppress warning if this stream is not explicitly closed */
php_stream_auto_cleanup ( stream ) ;
2003-02-18 17:37:54 +08:00
return SUCCESS ;
}
return FAILURE ;
}
2001-06-06 21:06:12 +08:00
/* {{{ php_get_configuration_directive_for_zend
*/
2001-01-08 02:38:38 +08:00
static int php_get_configuration_directive_for_zend ( char * name , uint name_length , zval * contents )
1999-06-20 03:23:24 +08:00
{
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 ;
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-06-20 03:23:24 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_message_handler_for_zend
*/
1999-04-08 05:05:13 +08:00
static void php_message_handler_for_zend ( long message , void * data )
{
2003-08-19 11:25:00 +08:00
TSRMLS_FETCH ( ) ;
1999-04-08 05:05:13 +08:00
switch ( message ) {
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_INCLUDE_FOPEN :
php_error_docref ( " function.include " TSRMLS_CC , E_WARNING , " Failed opening '%s' for inclusion (include_path='%s') " , php_strip_url_passwd ( ( char * ) data ) , STR_PRINT ( PG ( include_path ) ) ) ;
1999-04-08 05:05:13 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_REQUIRE_FOPEN :
php_error_docref ( " function.require " TSRMLS_CC , E_COMPILE_ERROR , " Failed opening required '%s' (include_path='%s') " , php_strip_url_passwd ( ( char * ) data ) , STR_PRINT ( PG ( include_path ) ) ) ;
1999-04-08 05:05:13 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_HIGHLIGHT_FOPEN :
php_error_docref ( NULL TSRMLS_CC , 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 :
2003-08-21 07:00:08 +08:00
case ZMSG_MEMORY_LEAK_REPEATED :
2003-08-19 06:31:29 +08:00
# if ZEND_DEBUG
2004-02-11 02:46:53 +08:00
if ( EG ( error_reporting ) & E_WARNING ) {
2003-08-21 07:00:08 +08:00
char memory_leak_buf [ 512 ] ;
1999-04-08 05:05:13 +08:00
2003-08-21 07:00:08 +08:00
if ( message = = ZMSG_MEMORY_LEAK_DETECTED ) {
zend_mem_header * t = ( zend_mem_header * ) data ;
void * ptr = ( void * ) ( ( char * ) t + sizeof ( zend_mem_header ) + MEM_HEADER_PADDING ) ;
1999-05-22 18:56:36 +08:00
2003-08-21 07:00:08 +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 ) ) ;
if ( t - > orig_filename ) {
char relay_buf [ 512 ] ;
1999-08-28 19:17:28 +08:00
2003-08-21 07:00:08 +08:00
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
}
2003-08-21 07:00:08 +08:00
} else {
unsigned long leak_count = ( unsigned long ) data ;
snprintf ( memory_leak_buf , 512 , " Last leak repeated %ld time%s \n " , leak_count , ( leak_count > 1 ? " s " : " " ) ) ;
}
2000-02-11 23:59:30 +08:00
# if defined(PHP_WIN32)
2003-08-21 07:00:08 +08:00
OutputDebugString ( memory_leak_buf ) ;
1999-04-08 05:05:13 +08:00
# else
2003-08-21 07:00:08 +08:00
fprintf ( stderr , " %s " , memory_leak_buf ) ;
1999-04-08 05:05:13 +08:00
# endif
2003-08-19 11:25:00 +08:00
}
2003-08-21 07:00:08 +08:00
# endif
2003-08-19 06:31:29 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_MEMORY_LEAKS_GRAND_TOTAL :
2003-08-19 06:31:29 +08:00
# if ZEND_DEBUG
2004-02-11 02:46:53 +08:00
if ( EG ( error_reporting ) & E_WARNING ) {
2003-08-21 07:00:08 +08:00
char memory_leak_buf [ 512 ] ;
2003-08-19 06:31:29 +08:00
2003-08-21 07:00:08 +08:00
snprintf ( memory_leak_buf , 512 , " === Total %d memory leaks detected === \n " , * ( ( zend_uint * ) data ) ) ;
2003-08-19 06:31:29 +08:00
# if defined(PHP_WIN32)
2003-08-21 07:00:08 +08:00
OutputDebugString ( memory_leak_buf ) ;
2003-08-19 06:31:29 +08:00
# else
2003-08-21 07:00:08 +08:00
fprintf ( stderr , " %s " , memory_leak_buf ) ;
2003-08-19 06:31:29 +08:00
# endif
2003-08-19 11:25:00 +08:00
}
2003-08-21 07:00:08 +08:00
# endif
1999-04-08 05:05:13 +08:00
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
1999-08-27 12:31:53 +08:00
time ( & curtime ) ;
2000-05-04 18:38:17 +08:00
ta = php_localtime_r ( & curtime , & tmbuf ) ;
datetime_str = php_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
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-26 03:35:44 +08:00
2002-09-19 23:54:23 +08:00
void php_on_timeout ( int seconds TSRMLS_DC )
{
PG ( connection_status ) | = PHP_CONNECTION_TIMEOUT ;
2003-08-10 07:15:40 +08:00
zend_set_timeout ( EG ( timeout_seconds ) ) ;
2002-09-19 23:54:23 +08:00
}
2000-05-19 03:45:34 +08:00
# if PHP_SIGCHILD
2001-06-06 21:06:12 +08:00
/* {{{ sigchld_handler
*/
2000-05-19 18:48:05 +08:00
static void sigchld_handler ( int apar )
2000-05-19 03:45:34 +08:00
{
2002-05-10 03:58:39 +08:00
while ( waitpid ( - 1 , NULL , WNOHANG ) > 0 ) ;
signal ( SIGCHLD , sigchld_handler ) ;
2000-05-19 03:45:34 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-05-19 03:45:34 +08:00
# endif
2002-11-18 08:59:23 +08:00
/* {{{ php_start_sapi()
*/
2002-11-18 14:04:06 +08:00
static int php_start_sapi ( TSRMLS_D )
2002-11-18 08:59:23 +08:00
{
2003-03-04 22:12:39 +08:00
int retval = SUCCESS ;
if ( ! SG ( sapi_started ) ) {
zend_try {
PG ( during_request_startup ) = 1 ;
/* initialize global variables */
PG ( modules_activated ) = 0 ;
PG ( header_is_being_sent ) = 0 ;
PG ( connection_status ) = PHP_CONNECTION_NORMAL ;
zend_activate ( TSRMLS_C ) ;
zend_set_timeout ( EG ( timeout_seconds ) ) ;
zend_activate_modules ( TSRMLS_C ) ;
PG ( modules_activated ) = 1 ;
} zend_catch {
retval = FAILURE ;
} zend_end_try ( ) ;
SG ( sapi_started ) = 1 ;
}
return retval ;
2002-11-18 08:59:23 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_request_startup
*/
2005-06-20 15:04:07 +08:00
# ifndef APACHE_HOOKS
2001-07-28 19:36:37 +08:00
int php_request_startup ( TSRMLS_D )
1999-04-08 05:05:13 +08:00
{
2001-07-21 22:27:56 +08:00
int retval = SUCCESS ;
2003-01-29 08:49:09 +08:00
# ifdef PHP_WIN32
CoInitialize ( NULL ) ;
# endif
2000-05-19 03:45:34 +08:00
# if PHP_SIGCHILD
2001-08-05 09:43:02 +08:00
signal ( SIGCHLD , sigchld_handler ) ;
2000-05-19 03:45:34 +08:00
# endif
2001-07-21 22:27:56 +08:00
zend_try {
PG ( during_request_startup ) = 1 ;
2001-08-05 23:29:47 +08:00
php_output_activate ( TSRMLS_C ) ;
1999-04-21 12:02:11 +08:00
2001-07-21 22:27:56 +08:00
/* initialize global variables */
PG ( modules_activated ) = 0 ;
PG ( header_is_being_sent ) = 0 ;
PG ( connection_status ) = PHP_CONNECTION_NORMAL ;
2001-07-28 19:36:37 +08:00
zend_activate ( TSRMLS_C ) ;
sapi_activate ( TSRMLS_C ) ;
2000-04-11 01:39:11 +08:00
2002-11-12 22:40:00 +08:00
if ( PG ( max_input_time ) = = - 1 ) {
zend_set_timeout ( EG ( timeout_seconds ) ) ;
} else {
zend_set_timeout ( PG ( max_input_time ) ) ;
}
2000-06-16 10:27:47 +08:00
2001-07-21 22:27:56 +08:00
if ( PG ( expose_php ) ) {
sapi_add_header ( SAPI_PHP_VERSION_HEADER , sizeof ( SAPI_PHP_VERSION_HEADER ) - 1 , 1 ) ;
}
1999-12-03 13:03:16 +08:00
2001-07-21 22:27:56 +08:00
if ( PG ( output_handler ) & & PG ( output_handler ) [ 0 ] ) {
2002-08-10 06:29:58 +08:00
php_start_ob_buffer_named ( PG ( output_handler ) , 0 , 1 TSRMLS_CC ) ;
2002-10-03 19:18:39 +08:00
} else if ( PG ( output_buffering ) ) {
2002-09-01 19:33:19 +08:00
if ( PG ( output_buffering ) > 1 ) {
2003-03-16 00:39:35 +08:00
php_start_ob_buffer ( NULL , PG ( output_buffering ) , 1 TSRMLS_CC ) ;
2002-10-03 19:18:39 +08:00
} else {
2002-09-01 19:33:19 +08:00
php_start_ob_buffer ( NULL , 0 , 1 TSRMLS_CC ) ;
}
2002-10-03 19:18:39 +08:00
} else if ( PG ( implicit_flush ) ) {
2001-08-05 23:29:47 +08:00
php_start_implicit_flush ( TSRMLS_C ) ;
2001-07-21 22:27:56 +08:00
}
2000-09-09 23:02:15 +08:00
2001-07-21 22:27:56 +08:00
/* We turn this off in php_execute_script() */
/* PG(during_request_startup) = 0; */
2000-09-09 23:02:15 +08:00
2001-07-28 19:36:37 +08:00
php_hash_environment ( TSRMLS_C ) ;
2001-07-31 12:53:54 +08:00
zend_activate_modules ( TSRMLS_C ) ;
2001-07-21 22:27:56 +08:00
PG ( modules_activated ) = 1 ;
} zend_catch {
retval = FAILURE ;
} zend_end_try ( ) ;
2000-10-27 02:32:38 +08:00
2001-07-21 22:27:56 +08:00
return retval ;
1999-04-08 05:05:13 +08:00
}
2002-11-18 08:59:23 +08:00
# else
int php_request_startup ( TSRMLS_D )
{
2003-03-04 22:12:39 +08:00
int retval = SUCCESS ;
2002-11-18 08:59:23 +08:00
# if PHP_SIGCHILD
2003-03-04 22:12:39 +08:00
signal ( SIGCHLD , sigchld_handler ) ;
2002-11-18 08:59:23 +08:00
# endif
2003-03-04 22:12:39 +08:00
if ( php_start_sapi ( ) = = FAILURE ) {
return FAILURE ;
}
php_output_activate ( TSRMLS_C ) ;
sapi_activate ( TSRMLS_C ) ;
php_hash_environment ( TSRMLS_C ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
zend_try {
PG ( during_request_startup ) = 1 ;
php_output_activate ( TSRMLS_C ) ;
if ( PG ( expose_php ) ) {
sapi_add_header ( SAPI_PHP_VERSION_HEADER , sizeof ( SAPI_PHP_VERSION_HEADER ) - 1 , 1 ) ;
}
} zend_catch {
retval = FAILURE ;
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
return retval ;
2002-11-18 08:59:23 +08:00
}
# endif
/* }}} */
/* {{{ php_request_startup_for_hook
*/
int php_request_startup_for_hook ( TSRMLS_D )
{
2003-03-04 22:12:39 +08:00
int retval = SUCCESS ;
2002-11-18 08:59:23 +08:00
# if PHP_SIGCHLD
2003-03-04 22:12:39 +08:00
signal ( SIGCHLD , sigchld_handler ) ;
2002-11-18 08:59:23 +08:00
# endif
2003-03-04 22:12:39 +08:00
if ( php_start_sapi ( TSRMLS_C ) = = FAILURE ) {
return FAILURE ;
}
php_output_activate ( TSRMLS_C ) ;
sapi_activate_headers_only ( TSRMLS_C ) ;
php_hash_environment ( TSRMLS_C ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
return retval ;
2002-11-18 08:59:23 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_request_shutdown_for_exec
*/
2002-02-27 03:38:41 +08:00
void php_request_shutdown_for_exec ( void * dummy )
1999-04-08 05:05:13 +08:00
{
2002-02-27 03:38:41 +08:00
TSRMLS_FETCH ( ) ;
1999-04-08 05:05:13 +08:00
/* used to close fd's in the 3..255 range here, but it's problematic
*/
2002-02-27 02:59:27 +08:00
shutdown_memory_manager ( 1 , 1 TSRMLS_CC ) ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2002-11-18 08:59:23 +08:00
/* {{{ php_request_shutdown_for_hook
*/
void php_request_shutdown_for_hook ( void * dummy )
{
2003-03-04 22:12:39 +08:00
TSRMLS_FETCH ( ) ;
2005-04-28 15:50:53 +08:00
2003-03-04 22:12:39 +08:00
if ( PG ( modules_activated ) ) zend_try {
2005-01-10 00:30:09 +08:00
php_call_shutdown_functions ( TSRMLS_C ) ;
2003-03-04 22:12:39 +08:00
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
if ( PG ( modules_activated ) ) {
zend_deactivate_modules ( TSRMLS_C ) ;
2005-01-10 00:30:09 +08:00
php_free_shutdown_functions ( TSRMLS_C ) ;
2003-03-04 22:12:39 +08:00
}
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
zend_try {
int i ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
for ( i = 0 ; i < NUM_TRACK_VARS ; i + + ) {
2003-03-02 18:19:15 +08:00
if ( PG ( http_globals ) [ i ] ) {
2003-03-04 22:12:39 +08:00
zval_ptr_dtor ( & PG ( http_globals ) [ i ] ) ;
2003-03-02 18:19:15 +08:00
}
2003-03-04 22:12:39 +08:00
}
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
zend_deactivate ( TSRMLS_C ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
zend_try {
sapi_deactivate ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
2005-05-16 16:37:14 +08:00
zend_try {
php_shutdown_stream_hashes ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2003-03-04 22:12:39 +08:00
zend_try {
shutdown_memory_manager ( CG ( unclean_shutdown ) , 0 TSRMLS_CC ) ;
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
zend_try {
zend_unset_timeout ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2002-11-18 08:59:23 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_request_shutdown
*/
1999-04-26 22:00:49 +08:00
void php_request_shutdown ( void * dummy )
1999-04-08 05:05:13 +08:00
{
2004-02-11 01:55:32 +08:00
zend_bool report_memleaks ;
2001-07-27 18:16:41 +08:00
TSRMLS_FETCH ( ) ;
1999-04-08 05:05:13 +08:00
2004-02-11 01:55:32 +08:00
report_memleaks = PG ( report_memleaks ) ;
2005-04-28 15:50:53 +08:00
2003-02-20 00:17:15 +08:00
/* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
2003-07-31 00:15:03 +08:00
* inside zend_executor callback functions .
*/
2003-02-20 00:17:15 +08:00
EG ( opline_ptr ) = NULL ;
2005-07-05 22:13:46 +08:00
EG ( active_op_array ) = NULL ;
2003-02-20 00:17:15 +08:00
2005-09-15 04:08:31 +08:00
/* 1. Call all possible shutdown functions registered with register_shutdown_function() */
2005-04-28 15:50:53 +08:00
if ( PG ( modules_activated ) ) zend_try {
php_call_shutdown_functions ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2005-09-15 04:08:31 +08:00
/* 2. Call all possible __destruct() functions */
zend_try {
zend_call_destructors ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2005-04-28 15:50:53 +08:00
/* 3. Flush all output buffers */
2001-07-21 22:27:56 +08:00
zend_try {
2005-04-28 15:50:53 +08:00
php_end_ob_buffers ( ( zend_bool ) ( SG ( request_info ) . headers_only ? 0 : 1 ) TSRMLS_CC ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
1999-04-08 05:05:13 +08:00
2005-04-28 15:50:53 +08:00
/* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
2004-07-25 15:14:49 +08:00
zend_try {
2005-04-28 15:50:53 +08:00
sapi_send_headers ( TSRMLS_C ) ;
2004-07-25 15:14:49 +08:00
} zend_end_try ( ) ;
2005-04-28 15:50:53 +08:00
/* 5. Call all extensions RSHUTDOWN functions */
2000-05-30 02:45:06 +08:00
if ( PG ( modules_activated ) ) {
2001-07-30 09:56:43 +08:00
zend_deactivate_modules ( TSRMLS_C ) ;
2005-01-10 00:30:09 +08:00
php_free_shutdown_functions ( TSRMLS_C ) ;
2000-05-30 02:45:06 +08:00
}
2001-08-09 04:05:37 +08:00
2005-04-28 15:50:53 +08:00
/* 6. Destroy super-globals */
2001-08-09 04:05:37 +08:00
zend_try {
int i ;
for ( i = 0 ; i < NUM_TRACK_VARS ; i + + ) {
2002-07-25 17:33:26 +08:00
if ( PG ( http_globals ) [ i ] ) {
zval_ptr_dtor ( & PG ( http_globals ) [ i ] ) ;
}
2001-08-09 04:05:37 +08:00
}
} zend_end_try ( ) ;
2005-04-28 15:50:53 +08:00
/* 7. Shutdown scanner/executor/compiler and restore ini entries */
2001-07-28 19:36:37 +08:00
zend_deactivate ( TSRMLS_C ) ;
1999-05-06 05:29:26 +08:00
2005-04-28 15:50:53 +08:00
/* 8. Call all extensions post-RSHUTDOWN functions */
2004-03-17 06:27:57 +08:00
zend_try {
zend_post_deactivate_modules ( TSRMLS_C ) ;
} zend_end_try ( ) ;
2005-04-28 15:50:53 +08:00
/* 9. SAPI related shutdown (free stuff) */
2001-07-21 22:27:56 +08:00
zend_try {
2001-07-28 19:36:37 +08:00
sapi_deactivate ( TSRMLS_C ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
1999-04-08 05:05:13 +08:00
2005-05-16 16:37:14 +08:00
/* 10. Destroy stream hashes */
zend_try {
php_shutdown_stream_hashes ( TSRMLS_C ) ;
} zend_end_try ( ) ;
/* 11. Free Willy (here be crashes) */
2004-02-11 01:55:32 +08:00
zend_try {
shutdown_memory_manager ( CG ( unclean_shutdown ) | | ! report_memleaks , 0 TSRMLS_CC ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
2000-09-01 00:02:51 +08:00
2005-05-16 16:37:14 +08:00
/* 12. Reset max_execution_time */
2001-07-21 22:27:56 +08:00
zend_try {
2001-07-30 16:24:42 +08:00
zend_unset_timeout ( TSRMLS_C ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
2003-01-29 08:49:09 +08:00
# ifdef PHP_WIN32
CoUninitialize ( ) ;
# endif
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_body_write_wrapper
*/
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
{
2001-08-05 23:55:43 +08:00
TSRMLS_FETCH ( ) ;
return php_body_write ( str , str_length TSRMLS_CC ) ;
1999-04-26 03:35:44 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-05-07 05:58:49 +08:00
1999-08-26 00:24:14 +08:00
# ifdef ZTS
2001-06-06 21:06:12 +08:00
/* {{{ core_globals_ctor
*/
2001-07-27 18:16:41 +08:00
static void core_globals_ctor ( php_core_globals * core_globals TSRMLS_DC )
1999-08-26 00:24:14 +08:00
{
2001-08-05 09:43:02 +08:00
memset ( core_globals , 0 , sizeof ( * core_globals ) ) ;
1999-08-26 00:24:14 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-08-26 00:24:14 +08:00
# endif
2005-06-17 17:39:23 +08:00
/* {{{ php_register_extensions
2001-06-06 21:06:12 +08:00
*/
2005-06-17 17:39:23 +08:00
int php_register_extensions ( zend_module_entry * * ptr , int count TSRMLS_DC )
1999-12-08 04:49:01 +08:00
{
2005-06-17 17:39:23 +08:00
zend_module_entry * * end = ptr + count ;
1999-12-08 04:49:01 +08:00
while ( ptr < end ) {
if ( * ptr ) {
2005-07-19 00:20:08 +08:00
if ( zend_register_internal_module ( * ptr TSRMLS_CC ) = = NULL ) {
1999-12-08 04:49:01 +08:00
return FAILURE ;
}
}
ptr + + ;
}
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-12-08 04:49:01 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_module_startup
*/
2002-09-19 05:57:42 +08:00
int php_module_startup ( sapi_module_struct * sf , zend_module_entry * additional_modules , uint num_additional_modules )
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 ;
2001-07-27 18:16:41 +08:00
void * * * tsrm_ls ;
2001-07-28 19:36:37 +08:00
1999-04-21 12:02:11 +08:00
php_core_globals * core_globals ;
# endif
2002-09-09 19:17:40 +08:00
# if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
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
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
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
2002-05-10 03:58:39 +08:00
php_os = PHP_OS ;
1999-12-18 04:55:31 +08:00
# endif
1999-04-24 06:45:01 +08:00
2001-07-28 19:36:37 +08:00
# ifdef ZTS
tsrm_ls = ts_resource ( 0 ) ;
# endif
2004-03-24 21:31:34 +08:00
module_shutdown = 0 ;
2004-03-24 21:33:26 +08:00
module_startup = 1 ;
2001-07-28 19:36:37 +08:00
sapi_initialize_empty_request ( TSRMLS_C ) ;
sapi_activate ( TSRMLS_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
2000-04-28 02:37:02 +08:00
zuf . error_function = php_error_cb ;
1999-08-03 03:17:14 +08:00
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 ;
2000-02-11 02:44:33 +08:00
zuf . block_interruptions = sapi_module . block_interruptions ;
zuf . unblock_interruptions = sapi_module . unblock_interruptions ;
2001-01-08 02:38:38 +08:00
zuf . get_configuration_directive = php_get_configuration_directive_for_zend ;
2000-02-26 05:27:03 +08:00
zuf . ticks_function = php_run_ticks ;
2002-09-19 23:54:23 +08:00
zuf . on_timeout = php_on_timeout ;
2003-02-18 17:37:54 +08:00
zuf . stream_open_function = php_stream_open_for_zend ;
2003-08-31 17:35:54 +08:00
zuf . vspprintf_function = vspprintf ;
2004-09-06 06:40:35 +08:00
zuf . getenv_function = sapi_getenv ;
2000-03-22 03:04:34 +08:00
zend_startup ( & zuf , NULL , 1 ) ;
1999-04-08 05:05:13 +08:00
1999-04-21 12:02:11 +08:00
# ifdef ZTS
1999-08-20 00:52:53 +08:00
executor_globals = ts_resource ( executor_globals_id ) ;
2001-07-27 18:16:41 +08:00
ts_allocate_id ( & core_globals_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
2001-07-21 22:27:56 +08:00
EG ( bailout_set ) = 0 ;
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 ;
2000-02-11 04:03:17 +08:00
SG ( request_info ) . argv0 = NULL ;
2002-01-06 21:58:05 +08:00
SG ( request_info ) . argc = 0 ;
SG ( request_info ) . argv = ( char * * ) NULL ;
1999-09-07 06:40:27 +08:00
PG ( connection_status ) = PHP_CONNECTION_NORMAL ;
2000-09-09 23:02:15 +08:00
PG ( during_request_startup ) = 0 ;
2003-05-07 09:02:23 +08:00
PG ( last_error_message ) = NULL ;
PG ( last_error_file ) = NULL ;
PG ( last_error_lineno ) = 0 ;
PG ( error_handling ) = EH_NORMAL ;
2003-12-25 00:38:22 +08:00
PG ( disable_functions ) = NULL ;
PG ( disable_classes ) = NULL ;
1999-04-21 12:02:11 +08:00
1999-04-08 05:05:13 +08:00
# if HAVE_SETLOCALE
2000-06-05 23:34:11 +08:00
setlocale ( LC_CTYPE , " " ) ;
1999-04-08 05:05:13 +08:00
# endif
2004-02-09 12:04:24 +08:00
# if HAVE_TZSET
tzset ( ) ;
# endif
2002-09-09 19:17:40 +08:00
# if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1999-04-08 05:05:13 +08:00
/* start up winsock services */
if ( WSAStartup ( wVersionRequested , & wsaData ) ! = 0 ) {
1999-08-03 03:17:14 +08:00
php_printf ( " \n winsock.dll unusable. %d \n " , WSAGetLastError ( ) ) ;
1999-04-08 05:05:13 +08:00
return FAILURE ;
}
# endif
2000-10-21 02:25:16 +08:00
le_index_ptr = zend_register_list_destructors_ex ( NULL , NULL , " index pointer " , 0 ) ;
1999-04-08 05:05:13 +08:00
2001-02-21 09:43:15 +08:00
/* this will read in php.ini, set up the configuration parameters,
load zend extensions and register php function extensions
to be loaded later */
2005-09-01 22:44:15 +08:00
if ( php_init_config ( TSRMLS_C ) = = FAILURE ) {
1999-04-08 05:05:13 +08:00
return FAILURE ;
}
2005-09-02 22:05:46 +08:00
/* Register PHP core ini entries */
REGISTER_INI_ENTRIES ( ) ;
/* Register Zend ini entries */
zend_register_standard_ini_entries ( TSRMLS_C ) ;
2004-10-05 08:42:25 +08:00
/* Disable realpath cache if safe_mode or open_basedir are set */
if ( PG ( safe_mode ) | | ( PG ( open_basedir ) & & * PG ( open_basedir ) ) ) {
CWDG ( realpath_cache_size_limit ) = 0 ;
}
2002-03-16 05:03:08 +08:00
/* initialize stream wrappers registry
* ( this uses configuration parameters from php . ini )
2001-02-21 09:43:15 +08:00
*/
2002-09-25 23:25:12 +08:00
if ( php_init_stream_wrappers ( module_number TSRMLS_CC ) = = FAILURE ) {
2002-03-16 05:03:08 +08:00
php_printf ( " PHP: Unable to initialize stream url wrappers. \n " ) ;
2000-10-13 08:09:31 +08:00
return FAILURE ;
}
2002-03-16 05:03:08 +08:00
2001-02-21 09:43:15 +08:00
/* initialize registry for images to be used in phpinfo()
( this uses configuration parameters from php . ini )
*/
2000-11-01 01:21:52 +08:00
if ( php_init_info_logos ( ) = = FAILURE ) {
php_printf ( " PHP: Unable to initialize info phpinfo logos. \n " ) ;
return FAILURE ;
}
2003-04-16 20:44:08 +08:00
zuv . html_errors = 1 ;
1999-12-04 21:25:41 +08:00
zuv . import_use_extension = " .php " ;
2003-03-02 18:19:15 +08:00
php_startup_auto_globals ( TSRMLS_C ) ;
1999-04-10 19:22:18 +08:00
zend_set_utility_values ( & zuv ) ;
2005-02-21 23:14:02 +08:00
php_startup_sapi_content_types ( TSRMLS_C ) ;
1999-04-10 19:22:18 +08:00
2000-11-02 22:18:34 +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 ) ;
2002-03-02 03:29:35 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_SAPI " , sapi_module . name , strlen ( sapi_module . name ) , CONST_PERSISTENT | CONST_CS ) ;
2001-04-22 09:09:14 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " DEFAULT_INCLUDE_PATH " , PHP_INCLUDE_PATH , sizeof ( PHP_INCLUDE_PATH ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PEAR_INSTALL_DIR " , PEAR_INSTALLDIR , sizeof ( PEAR_INSTALLDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2001-04-26 05:46:40 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PEAR_EXTENSION_DIR " , PHP_EXTENSION_DIR , sizeof ( PHP_EXTENSION_DIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2001-04-22 09:09:14 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_EXTENSION_DIR " , PHP_EXTENSION_DIR , sizeof ( PHP_EXTENSION_DIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2002-06-07 20:19:26 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_PREFIX " , PHP_PREFIX , sizeof ( PHP_PREFIX ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2001-04-22 09:09:14 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_BINDIR " , PHP_BINDIR , sizeof ( PHP_BINDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_LIBDIR " , PHP_LIBDIR , sizeof ( PHP_LIBDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_DATADIR " , PHP_DATADIR , sizeof ( PHP_DATADIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_SYSCONFDIR " , PHP_SYSCONFDIR , sizeof ( PHP_SYSCONFDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_LOCALSTATEDIR " , PHP_LOCALSTATEDIR , sizeof ( PHP_LOCALSTATEDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_CONFIG_FILE_PATH " , PHP_CONFIG_FILE_PATH , sizeof ( PHP_CONFIG_FILE_PATH ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2002-10-04 12:47:35 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_CONFIG_FILE_SCAN_DIR " , PHP_CONFIG_FILE_SCAN_DIR , sizeof ( PHP_CONFIG_FILE_SCAN_DIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2002-06-07 20:19:26 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_SHLIB_SUFFIX " , PHP_SHLIB_SUFFIX , sizeof ( PHP_SHLIB_SUFFIX ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2004-08-13 15:02:50 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_EOL " , PHP_EOL , sizeof ( PHP_EOL ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2005-04-28 05:24:37 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_INT_MAX " , LONG_MAX , CONST_PERSISTENT | CONST_CS ) ;
REGISTER_MAIN_LONG_CONSTANT ( " PHP_INT_SIZE " , sizeof ( long ) , CONST_PERSISTENT | CONST_CS ) ;
2001-08-05 23:29:47 +08:00
php_output_register_constants ( TSRMLS_C ) ;
2002-07-12 09:49:58 +08:00
php_rfc1867_register_constants ( TSRMLS_C ) ;
1999-12-18 04:55:31 +08:00
2001-07-28 19:36:37 +08:00
if ( php_startup_ticks ( TSRMLS_C ) = = FAILURE ) {
2000-02-26 05:27:03 +08:00
php_printf ( " Unable to start PHP ticks \n " ) ;
return FAILURE ;
}
2004-02-25 18:58:06 +08:00
/* Register internal Zend classes */
zend_register_default_classes ( TSRMLS_C ) ;
2001-02-21 09:43:15 +08:00
/* startup extensions staticly compiled in */
2005-06-17 17:39:23 +08:00
if ( php_register_internal_extensions ( TSRMLS_C ) = = FAILURE ) {
1999-12-08 04:49:01 +08:00
php_printf ( " Unable to start builtin modules \n " ) ;
1999-04-08 05:05:13 +08:00
return FAILURE ;
}
2004-02-25 18:58:06 +08:00
2002-09-19 05:57:42 +08:00
/* start additional PHP extensions */
2005-06-17 17:39:23 +08:00
php_register_extensions ( & additional_modules , num_additional_modules TSRMLS_CC ) ;
2002-09-19 05:57:42 +08:00
2001-02-21 09:43:15 +08:00
/* load and startup extensions compiled as shared objects (aka DLLs)
as requested by php . ini entries
theese are loaded after initialization of internal extensions
as extensions * might * rely on things from ext / standard
which is always an internal extension and to be initialized
2002-05-10 03:58:39 +08:00
ahead of all other internals
2001-02-21 09:43:15 +08:00
*/
2005-06-17 17:39:23 +08:00
php_ini_register_extensions ( TSRMLS_C ) ;
zend_startup_modules ( TSRMLS_C ) ;
2001-02-21 09:43:15 +08:00
2003-03-03 09:27:22 +08:00
/* disable certain classes and functions as requested by php.ini */
2001-07-31 12:53:54 +08:00
php_disable_functions ( TSRMLS_C ) ;
2003-03-03 09:27:22 +08:00
php_disable_classes ( TSRMLS_C ) ;
2001-02-21 09:43:15 +08:00
2002-09-19 05:57:42 +08:00
/* start Zend extensions */
2000-09-28 03:46:47 +08:00
zend_startup_extensions ( ) ;
2001-02-21 09:43:15 +08:00
2002-09-17 17:07:10 +08:00
# ifdef ZTS
zend_post_startup ( TSRMLS_C ) ;
# endif
1999-04-24 06:45:01 +08:00
module_initialized = 1 ;
2001-07-28 19:36:37 +08:00
sapi_deactivate ( TSRMLS_C ) ;
2003-09-02 20:12:05 +08:00
module_startup = 0 ;
2001-02-21 09:43:15 +08:00
/* we're done */
1999-04-08 05:05:13 +08:00
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
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 */
}
2001-06-06 21:06:12 +08:00
/* {{{ php_module_shutdown_wrapper
*/
1999-05-03 02:07:41 +08:00
int php_module_shutdown_wrapper ( sapi_module_struct * sapi_globals )
{
2001-08-06 00:21:33 +08:00
TSRMLS_FETCH ( ) ;
php_module_shutdown ( TSRMLS_C ) ;
1999-05-03 02:07:41 +08:00
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-05-03 02:07:41 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_module_shutdown
*/
2001-08-06 00:21:33 +08:00
void php_module_shutdown ( TSRMLS_D )
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
2003-09-02 20:12:05 +08:00
module_shutdown = 1 ;
1999-04-24 08:12:00 +08:00
if ( ! module_initialized ) {
return ;
}
2000-02-11 00:52:07 +08:00
2002-09-09 19:17:40 +08:00
# if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1999-04-08 05:05:13 +08:00
/*close winsock */
1999-04-24 06:45:01 +08:00
WSACleanup ( ) ;
1999-04-08 05:05:13 +08:00
# endif
2001-07-28 19:36:37 +08:00
php_shutdown_ticks ( TSRMLS_C ) ;
2001-07-31 14:28:05 +08:00
sapi_flush ( TSRMLS_C ) ;
1999-04-08 05:05:13 +08:00
2001-07-31 12:53:54 +08:00
zend_shutdown ( TSRMLS_C ) ;
2002-03-16 05:03:08 +08:00
2002-09-25 23:25:12 +08:00
php_shutdown_stream_wrappers ( module_number TSRMLS_CC ) ;
2002-03-16 05:03:08 +08:00
2000-11-01 01:21:52 +08:00
php_shutdown_info_logos ( ) ;
1999-04-10 03:09:29 +08:00
UNREGISTER_INI_ENTRIES ( ) ;
2001-08-16 17:40:05 +08:00
/* close down the ini config */
php_shutdown_config ( ) ;
2001-12-17 06:45:57 +08:00
# ifndef ZTS
2001-07-27 18:16:41 +08:00
zend_ini_shutdown ( TSRMLS_C ) ;
2002-02-27 03:31:21 +08:00
shutdown_memory_manager ( CG ( unclean_shutdown ) , 1 TSRMLS_CC ) ;
2004-05-24 00:02:36 +08:00
# else
zend_ini_global_shutdown ( TSRMLS_C ) ;
2001-08-05 09:43:02 +08:00
# endif
2001-08-16 17:40:05 +08:00
1999-04-24 06:45:01 +08:00
module_initialized = 0 ;
2003-05-07 09:02:23 +08:00
if ( PG ( last_error_message ) ) {
free ( PG ( last_error_message ) ) ;
}
if ( PG ( last_error_file ) ) {
free ( PG ( last_error_file ) ) ;
}
2003-12-25 00:38:22 +08:00
if ( PG ( disable_functions ) ) {
free ( PG ( disable_functions ) ) ;
}
if ( PG ( disable_classes ) ) {
free ( PG ( disable_classes ) ) ;
}
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2000-01-29 02:29:37 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_execute_script
*/
2001-07-28 19:36:37 +08:00
PHPAPI int php_execute_script ( zend_file_handle * primary_file TSRMLS_DC )
2000-10-27 05:16:12 +08:00
{
zend_file_handle * prepend_file_p , * append_file_p ;
2003-12-01 18:47:08 +08:00
zend_file_handle prepend_file = { 0 } , append_file = { 0 } ;
2003-03-17 21:40:45 +08:00
# if HAVE_BROKEN_GETCWD
2003-05-13 10:26:42 +08:00
int old_cwd_fd = - 1 ;
2003-03-17 21:40:45 +08:00
# else
2000-10-27 05:16:12 +08:00
char * old_cwd ;
2003-03-17 21:40:45 +08:00
# endif
2002-10-17 00:52:08 +08:00
char * old_primary_file_path = NULL ;
2002-02-15 04:16:08 +08:00
int retval = 0 ;
2000-10-27 05:16:12 +08:00
2000-11-22 12:23:26 +08:00
EG ( exit_status ) = 0 ;
2001-07-28 19:36:37 +08:00
if ( php_handle_special_queries ( TSRMLS_C ) ) {
2004-08-16 20:24:52 +08:00
zend_file_handle_dtor ( primary_file ) ;
2000-11-22 12:23:26 +08:00
return 0 ;
2001-07-21 22:27:56 +08:00
}
2003-03-17 21:40:45 +08:00
# ifndef HAVE_BROKEN_GETCWD
# define OLD_CWD_SIZE 4096
2000-08-28 04:51:30 +08:00
old_cwd = do_alloca ( OLD_CWD_SIZE ) ;
2000-08-28 03:56:22 +08:00
old_cwd [ 0 ] = ' \0 ' ;
2003-03-17 21:40:45 +08:00
# endif
2000-05-29 01:19:49 +08:00
2001-07-21 22:27:56 +08:00
zend_try {
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
2001-08-05 09:43:02 +08:00
UpdateIniFromRegistry ( primary_file - > filename TSRMLS_CC ) ;
1999-04-18 23:09:46 +08:00
# endif
1999-04-08 05:05:13 +08:00
2001-07-21 22:27:56 +08:00
PG ( during_request_startup ) = 0 ;
2000-09-09 23:02:15 +08:00
2001-11-27 02:57:44 +08:00
if ( primary_file - > type = = ZEND_HANDLE_FILENAME
2001-07-21 22:27:56 +08:00
& & primary_file - > filename ) {
2003-03-17 21:40:45 +08:00
# if HAVE_BROKEN_GETCWD
/* this looks nasty to me */
old_cwd_fd = open ( " . " , 0 ) ;
# else
2001-07-21 22:27:56 +08:00
VCWD_GETCWD ( old_cwd , OLD_CWD_SIZE - 1 ) ;
2003-03-17 21:40:45 +08:00
# endif
2001-07-21 22:27:56 +08:00
VCWD_CHDIR_FILE ( primary_file - > filename ) ;
}
2000-08-20 22:29:00 +08:00
2002-09-30 03:22:39 +08:00
if ( primary_file - > filename ) {
2002-07-01 17:00:00 +08:00
char realfile [ MAXPATHLEN ] ;
2002-09-29 04:13:28 +08:00
int realfile_len ;
2002-06-30 21:38:16 +08:00
int dummy = 1 ;
2002-09-30 03:22:39 +08:00
if ( VCWD_REALPATH ( primary_file - > filename , realfile ) ) {
2002-09-29 04:13:28 +08:00
realfile_len = strlen ( realfile ) ;
zend_hash_add ( & EG ( included_files ) , realfile , realfile_len + 1 , ( void * ) & dummy , sizeof ( int ) , NULL ) ;
2002-10-17 00:52:08 +08:00
if ( strncmp ( realfile , primary_file - > filename , realfile_len ) ) {
old_primary_file_path = primary_file - > filename ;
primary_file - > filename = realfile ;
2002-09-30 06:16:29 +08:00
}
2002-06-30 21:38:16 +08:00
}
}
2001-07-21 22:27:56 +08:00
if ( PG ( auto_prepend_file ) & & PG ( auto_prepend_file ) [ 0 ] ) {
prepend_file . filename = PG ( auto_prepend_file ) ;
prepend_file . opened_path = NULL ;
prepend_file . free_filename = 0 ;
2001-11-27 02:57:44 +08:00
prepend_file . type = ZEND_HANDLE_FILENAME ;
2001-07-21 22:27:56 +08:00
prepend_file_p = & prepend_file ;
} else {
prepend_file_p = NULL ;
}
2002-09-30 03:22:39 +08:00
2001-07-21 22:27:56 +08:00
if ( PG ( auto_append_file ) & & PG ( auto_append_file ) [ 0 ] ) {
append_file . filename = PG ( auto_append_file ) ;
append_file . opened_path = NULL ;
append_file . free_filename = 0 ;
2001-11-27 02:57:44 +08:00
append_file . type = ZEND_HANDLE_FILENAME ;
2001-07-21 22:27:56 +08:00
append_file_p = & append_file ;
} else {
append_file_p = NULL ;
}
2003-02-27 06:19:01 +08:00
# ifdef PHP_WIN32
2002-10-21 21:09:29 +08:00
zend_unset_timeout ( TSRMLS_C ) ;
2003-02-27 06:19:01 +08:00
# endif
2002-11-18 06:52:47 +08:00
zend_set_timeout ( INI_INT ( " max_execution_time " ) ) ;
2002-02-15 04:16:08 +08:00
retval = ( zend_execute_scripts ( ZEND_REQUIRE TSRMLS_CC , NULL , 3 , prepend_file_p , primary_file , append_file_p ) = = SUCCESS ) ;
2002-10-17 00:52:08 +08:00
if ( old_primary_file_path ) {
primary_file - > filename = old_primary_file_path ;
}
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
2000-08-20 22:29:00 +08:00
2003-03-17 21:40:45 +08:00
# if HAVE_BROKEN_GETCWD
2003-05-13 10:26:42 +08:00
if ( old_cwd_fd ! = - 1 ) {
fchdir ( old_cwd_fd ) ;
close ( old_cwd_fd ) ;
}
2003-03-17 21:40:45 +08:00
# else
2001-07-21 22:27:56 +08:00
if ( old_cwd [ 0 ] ! = ' \0 ' ) {
2001-04-30 20:45:02 +08:00
VCWD_CHDIR ( old_cwd ) ;
2001-07-21 22:27:56 +08:00
}
2000-08-28 03:56:22 +08:00
free_alloca ( old_cwd ) ;
2003-03-17 21:40:45 +08:00
# endif
2002-02-15 04:16:08 +08:00
return retval ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2002-11-18 08:59:23 +08:00
/* {{{ php_execute_simple_script
*/
PHPAPI int php_execute_simple_script ( zend_file_handle * primary_file , zval * * ret TSRMLS_DC )
{
2003-03-04 22:12:39 +08:00
char * old_cwd ;
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
EG ( exit_status ) = 0 ;
2002-11-18 08:59:23 +08:00
# define OLD_CWD_SIZE 4096
2003-03-04 22:12:39 +08:00
old_cwd = do_alloca ( OLD_CWD_SIZE ) ;
old_cwd [ 0 ] = ' \0 ' ;
zend_try {
2002-11-18 08:59:23 +08:00
# ifdef PHP_WIN32
2003-03-04 22:12:39 +08:00
UpdateIniFromRegistry ( primary_file - > filename TSRMLS_CC ) ;
2002-11-18 08:59:23 +08:00
# endif
2003-03-04 22:12:39 +08:00
PG ( during_request_startup ) = 0 ;
if ( primary_file - > type = = ZEND_HANDLE_FILENAME & & primary_file - > filename ) {
VCWD_GETCWD ( old_cwd , OLD_CWD_SIZE - 1 ) ;
VCWD_CHDIR_FILE ( primary_file - > filename ) ;
}
zend_execute_scripts ( ZEND_REQUIRE TSRMLS_CC , ret , 1 , primary_file ) ;
} zend_end_try ( ) ;
if ( old_cwd [ 0 ] ! = ' \0 ' ) {
VCWD_CHDIR ( old_cwd ) ;
}
free_alloca ( old_cwd ) ;
return EG ( exit_status ) ;
2002-11-18 08:59:23 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_handle_aborted_connection
*/
2000-10-30 00:00:42 +08:00
PHPAPI void php_handle_aborted_connection ( void )
{
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-10-30 00:00:42 +08:00
PG ( connection_status ) = PHP_CONNECTION_ABORTED ;
2001-08-05 23:29:47 +08:00
php_output_set_status ( 0 TSRMLS_CC ) ;
2000-10-30 00:00:42 +08:00
if ( ! PG ( ignore_user_abort ) ) {
zend_bailout ( ) ;
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-10-30 00:00:42 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_handle_auth_data
*/
2001-07-28 19:36:37 +08:00
PHPAPI int php_handle_auth_data ( const char * auth TSRMLS_DC )
2000-10-27 18:16:54 +08:00
{
int ret = - 1 ;
2003-03-04 22:12:39 +08:00
if ( auth & & auth [ 0 ] ! = ' \0 ' & & strncmp ( auth , " Basic " , 6 ) = = 0 ) {
2000-10-27 18:16:54 +08:00
char * pass ;
char * user ;
user = php_base64_decode ( auth + 6 , strlen ( auth ) - 6 , NULL ) ;
if ( user ) {
pass = strchr ( user , ' : ' ) ;
if ( pass ) {
* pass + + = ' \0 ' ;
SG ( request_info ) . auth_user = user ;
SG ( request_info ) . auth_password = estrdup ( pass ) ;
ret = 0 ;
} else {
efree ( user ) ;
}
}
}
2000-10-27 18:28:57 +08:00
2003-03-04 22:12:39 +08:00
if ( ret = = - 1 ) {
2000-10-27 18:28:57 +08:00
SG ( request_info ) . auth_user = SG ( request_info ) . auth_password = NULL ;
2005-07-13 00:53:30 +08:00
} else {
SG ( request_info ) . auth_digest = NULL ;
2003-03-04 22:12:39 +08:00
}
2005-07-13 00:53:30 +08:00
if ( ret = = - 1 & & auth & & auth [ 0 ] ! = ' \0 ' & & strncmp ( auth , " Digest " , 7 ) = = 0 ) {
2005-04-04 23:06:36 +08:00
SG ( request_info ) . auth_digest = estrdup ( auth ) ;
ret = 0 ;
}
2005-07-13 00:53:30 +08:00
if ( ret = = - 1 ) {
SG ( request_info ) . auth_digest = NULL ;
}
2000-10-27 18:16:54 +08:00
return ret ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-10-27 18:16:54 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_lint_script
*/
2001-07-28 19:36:37 +08:00
PHPAPI int php_lint_script ( zend_file_handle * file TSRMLS_DC )
2000-07-28 23:21:20 +08:00
{
2000-08-10 03:23:53 +08:00
zend_op_array * op_array ;
2004-12-11 06:59:25 +08:00
zend_bool retval = FAILURE ;
2000-07-28 23:21:20 +08:00
2001-07-21 22:27:56 +08:00
zend_try {
2001-07-28 19:36:37 +08:00
op_array = zend_compile_file ( file , ZEND_INCLUDE TSRMLS_CC ) ;
zend_destroy_file_handle ( file TSRMLS_CC ) ;
2000-07-28 23:21:20 +08:00
2001-07-21 22:27:56 +08:00
if ( op_array ) {
2003-03-26 15:44:11 +08:00
destroy_op_array ( op_array TSRMLS_CC ) ;
2001-07-21 22:27:56 +08:00
efree ( op_array ) ;
2004-12-11 06:59:25 +08:00
retval = SUCCESS ;
2001-07-21 22:27:56 +08:00
}
} zend_end_try ( ) ;
2001-02-22 19:30:53 +08:00
2004-12-11 06:59:25 +08:00
return retval ;
2000-07-28 23:21:20 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-07-28 23:21:20 +08:00
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
2001-06-06 21:06:12 +08:00
/* {{{ dummy_indent
just so that this symbol gets exported . . . */
1999-04-26 22:00:49 +08:00
PHPAPI void dummy_indent ( )
{
zend_indent ( ) ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-26 22:00:49 +08:00
# endif
1999-04-08 05:05:13 +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-08 05:05:13 +08:00
*/