cvs: php4(apache_hooks) /main SAPI.c SAPI.h main.c

From: Date: Mon, 26 Aug 2002 20:02:19 +0000
Subject: cvs: php4(apache_hooks) /main SAPI.c SAPI.h main.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-13682@lists.php.net to get a copy of this message
gschlossnagle Mon Aug 26 16:02:19 2002 EDT Added files: (Branch: apache_hooks) /php4/main SAPI.c SAPI.h Modified files: /php4/main main.c Log: new full apache-1.3.x hooks interface support initial import

Index: php4/main/main.c diff -u php4/main/main.c:1.407.2.1 php4/main/main.c:1.407.2.2 --- php4/main/main.c:1.407.2.1 Thu Sep 6 05:53:33 2001 +++ php4/main/main.c Mon Aug 26 16:02:18 2002 @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.407.2.1 2001/09/06 09:53:33 rasmus Exp $ */ +/* $Id: main.c,v 1.407.2.2 2002/08/26 20:02:18 gschlossnagle Exp $ */ /* {{{ includes */ @@ -73,8 +73,14 @@ #include "php_content_types.h" #include "php_ticks.h" #include "php_logos.h" +#include "php_streams.h" + +#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) +#include "ext/mbstring/mbstring.h" +#endif /* defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) */ #include "SAPI.h" +#include "rfc1867.h" /* }}} */ #ifndef ZTS @@ -83,6 +89,16 @@ PHPAPI int core_globals_id; #endif +#define ERROR_BUF_LEN 1024 + +typedef struct { + char buf[ERROR_BUF_LEN]; + char filename[ERROR_BUF_LEN]; + uint lineno; +} last_error_type; + +static last_error_type last_error; + static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC); @@ -181,6 +197,24 @@ } /* }}} */ +/* {{{ OnUpdateOutputBuffering + */ +static PHP_INI_MH(OnUpdateOutputBuffering) +{ + if(!strncasecmp(new_value, "off", sizeof("off"))) { + new_value = "0"; + new_value_length = sizeof("0"); + } else if(!strncasecmp(new_value, "on", sizeof("on"))) { + new_value = "1"; + new_value_length = sizeof("1"); + } + OnUpdateInt(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + /* Need to convert to strings and make use of: * PHP_SAFE_MODE * @@ -218,20 +252,31 @@ STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals) 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) - STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_SYSTEM, OnUpdateBool, html_errors, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("docref_root", "http://www.php.net/", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals) STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateInt, xmlrpc_error_number, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateBool, implicit_flush, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateInt, log_errors_max_len, php_core_globals, core_globals) + 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) + STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_SYSTEM, OnUpdateBool, report_memleaks, php_core_globals, core_globals) 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) - STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateInt, output_buffering, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateOutputBuffering, output_buffering, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("double_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateOutputBuffering, double_buffering, php_core_globals, core_globals) 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_ALL, OnUpdateBool, register_argc_argv, php_core_globals, core_globals) - STD_PHP_INI_BOOLEAN("register_globals", "1", PHP_INI_ALL, OnUpdateBool, register_globals, 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) +#if PHP_SAFE_MODE + STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals) +#else STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals) +#endif STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals) 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) @@ -239,11 +284,12 @@ STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("y2k_compliance", "0", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals) 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) - STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_ALL, OnUpdateString, auto_append_file, php_core_globals, core_globals) - 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_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) STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals) 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) @@ -254,10 +300,12 @@ PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout) STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, open_basedir, php_core_globals, core_globals) STD_PHP_INI_ENTRY("safe_mode_exec_dir", "1", PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_ALL, OnUpdateInt, upload_max_filesize, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("file_uploads", "1", PHP_INI_ALL, OnUpdateBool, file_uploads, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM, OnUpdateInt, post_max_size, sapi_globals_struct,sapi_globals) + + STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateInt, upload_max_filesize, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateInt, post_max_size, sapi_globals_struct,sapi_globals) STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, 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("variables_order", NULL, PHP_INI_ALL, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals) @@ -265,6 +313,7 @@ STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateStringUnempty, error_prepend_string, php_core_globals, core_globals) PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL) + PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL) PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL) PHP_INI_ENTRY("error_reporting", NULL, PHP_INI_ALL, OnUpdateErrorReporting) #if MEMORY_LIMIT @@ -275,8 +324,9 @@ PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL) PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL) - STD_PHP_INI_ENTRY("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) - STD_PHP_INI_ENTRY("always_populate_raw_post_data", "0", PHP_INI_ALL, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) + 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) + STD_PHP_INI_BOOLEAN("allow_webdav_methods", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_webdav_methods, php_core_globals, core_globals) PHP_INI_END() /* }}} */ @@ -304,7 +354,7 @@ log_file = VCWD_FOPEN(PG(error_log), "a"); if (log_file != NULL) { time(&error_time); - strftime(error_time_str, 128, "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf)); + strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf)); fprintf(log_file, "[%s] ", error_time_str); fprintf(log_file, "%s", log_message); fprintf(log_file, "\n"); @@ -321,9 +371,6 @@ } /* }}} */ -/* is 4K big enough? */ -#define PRINTF_BUFFER_SIZE 1024*4 - /* {{{ php_write wrapper for modules to use PHPWRITE */ PHPAPI int php_write(void *buf, uint size TSRMLS_DC) @@ -338,38 +385,177 @@ { va_list args; int ret; - char buffer[PRINTF_BUFFER_SIZE]; + char *buffer; int size; TSRMLS_FETCH(); va_start(args, format); - size = vsnprintf(buffer, sizeof(buffer), format, args); - if(size > sizeof(buffer) - 1) { - size = sizeof(buffer) - 1; + size = vspprintf(&buffer, 0, format, args); + if (buffer) { + ret = PHPWRITE(buffer, size); + efree(buffer); + } else { + php_error(E_ERROR, "Out of memory"); + ret = 0; } - ret = PHPWRITE(buffer, size); va_end(args); return ret; } /* }}} */ +/* {{{ php_verror */ +/* 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. + */ +PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) +{ + char *buffer = NULL, *docref_buf = NULL, *ref = NULL, *target = NULL; + char *docref_target = "", *docref_root = ""; + char *function, *p; + + vspprintf(&buffer, 0, format, args); + if (buffer) { + if (docref && docref[0] == '#') { + docref_target = strchr(docref, '#'); + docref = NULL; + } + if (!docref) { + function = get_active_function_name(TSRMLS_C); + if (function) { + spprintf(&docref_buf, 0, "function.%s", function); + if (docref_buf) { + while((p=strchr(docref_buf, '_'))!=NULL) *p = '-'; + docref = docref_buf; + } + } + } + if (docref) { + if (strncmp(docref, "http://", 7)) { + docref_root = PG(docref_root); + /* now check copy of extension */ + ref = estrdup(docref); + if (ref) { + if (docref_buf) { + efree(docref_buf); + } + docref_buf = ref; + docref = docref_buf; + p = strrchr(ref, '#'); + if (p) { + target = estrdup(p); + if (target) { + docref_target = target; + *p = '\0'; + } + } + if ((!p || target) && PG(docref_ext) && strlen(PG(docref_ext))) { + spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext)); + if (docref_buf) { + efree(ref); + docref = docref_buf; + } + } + } + } + if (PG(html_errors)) { + php_error(type, "%s(%s) [<a href='%s%s%s'>%s</a>]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, docref, buffer); + } else { + php_error(type, "%s(%s) [%s%s%s]: %s", get_active_function_name(TSRMLS_C), params, docref_root, docref, docref_target, buffer); + } + if (target) + efree(target); + } else { + docref = get_active_function_name(TSRMLS_C); + if (!docref) + docref = "Unknown"; + php_error(type, "%s(%s): %s", docref, params, buffer); + } + efree(buffer); + if (docref_buf) + efree(docref_buf); + } else { + php_error(E_ERROR, "%s(%s): Out of memory", get_active_function_name(TSRMLS_C), params); + } +} +/* }}} */ + +/* {{{ php_error_docref */ +/* See: CODING_STANDARDS for details. */ +PHPAPI void php_error_docref(const char *docref TSRMLS_DC, int type, const char *format, ...) +{ + va_list args; + + va_start(args, format); + php_verror(docref, "", type, format, args TSRMLS_CC); + va_end(args); +} +/* }}} */ + +/* {{{ php_error_docref1 */ +/* See: CODING_STANDARDS for details. */ +PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...) +{ + va_list args; + + va_start(args, format); + php_verror(docref, param1, type, format, args TSRMLS_CC); + va_end(args); +} +/* }}} */ + +/* {{{ php_error_docref2 */ +/* See: CODING_STANDARDS for details. */ +PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...) +{ + char *params; + va_list args; + + spprintf(&params, 0, "%s,%s", param1, param2); + va_start(args, format); + php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC); + va_end(args); + if (params) + efree(params); +} +/* }}} */ + +/* {{{ php_html_puts */ +PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) +{ + zend_html_puts(str, size); +} +/* }}} */ + /* {{{ php_error_cb extended error handling function */ static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) { - char buffer[1024]; - int buffer_len; + char *buffer; + int buffer_len, display; TSRMLS_FETCH(); - buffer_len = vsnprintf(buffer, sizeof(buffer)-1, format, args); - buffer[sizeof(buffer)-1]=0; - if(buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { - buffer_len = sizeof(buffer) - 1; + buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args); + if (PG(ignore_repeated_errors)) { + if (strncmp(last_error.buf, buffer, sizeof(last_error.buf)) + || (!PG(ignore_repeated_source) + && ((last_error.lineno != error_lineno) + || strncmp(last_error.filename, error_filename, sizeof(last_error.filename))))) { + display = 1; + } else { + display = 0; + } + } else { + display = 1; } + strlcpy(last_error.buf, buffer, sizeof(last_error.buf)); + strlcpy(last_error.filename, error_filename, sizeof(last_error.filename)); + last_error.lineno = error_lineno; /* display/log the error if necessary */ - if ((EG(error_reporting) & type || (type & E_CORE)) + if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { char *error_type_str; @@ -390,8 +576,6 @@ error_type_str = "Parse error"; break; case E_NOTICE: - error_type_str = "Warning"; - break; case E_USER_NOTICE: error_type_str = "Notice"; break; @@ -401,15 +585,16 @@ } if (!module_initialized || PG(log_errors)) { - char log_buffer[1024]; + char *log_buffer; #ifdef PHP_WIN32 if (type==E_CORE_ERROR || type==E_CORE_WARNING) { MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE); } #endif - snprintf(log_buffer, 1024, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); + spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); php_log_err(log_buffer TSRMLS_CC); + efree(log_buffer); } if (module_initialized && PG(display_errors) && (!PG(during_request_startup) || PG(display_startup_errors))) { @@ -418,18 +603,17 @@ char *error_format; error_format = PG(html_errors) ? - "<br>\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br>\n" + "<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n" : "\n%s: %s in %s on line %d\n"; if (PG(xmlrpc_errors)) { - error_format = do_alloca(1024); - snprintf(error_format, 1023, "<?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_format = do_alloca(ERROR_BUF_LEN); + snprintf(error_format, ERROR_BUF_LEN-1, "<?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)); } if (prepend_string) { PUTS(prepend_string); } - php_printf(error_format, error_type_str, buffer, - error_filename, error_lineno); + php_printf(error_format, error_type_str, buffer, error_filename, error_lineno); if (PG(xmlrpc_errors)) { free_alloca(error_format); } @@ -472,26 +656,32 @@ case E_USER_ERROR: if (module_initialized) { zend_bailout(); + efree(buffer); return; } break; } /* Log if necessary */ + if (!display) { + efree(buffer); + return; + } if (PG(track_errors) && EG(active_symbol_table)) { pval *tmp; ALLOC_ZVAL(tmp); INIT_PZVAL(tmp); - tmp->value.str.val = (char *) estrndup(buffer, buffer_len); - tmp->value.str.len = buffer_len; - tmp->type = IS_STRING; + Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len); + Z_STRLEN_P(tmp) = buffer_len; + Z_TYPE_P(tmp) = IS_STRING; zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL); } + efree(buffer); } /* }}} */ -/* {{{ proto void set_time_limit(int seconds) +/* {{{ proto bool set_time_limit(int seconds) Sets the maximum time a script can run */ PHP_FUNCTION(set_time_limit) { @@ -506,9 +696,12 @@ WRONG_PARAM_COUNT; } - convert_to_long_ex(new_timeout); - zend_unset_timeout(TSRMLS_C); - zend_set_timeout(Z_LVAL_PP(new_timeout)); + convert_to_string_ex(new_timeout); + 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; + } } /* }}} */ @@ -516,19 +709,9 @@ */ static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path) { - int issock=0, socketd=0; - int old_chunk_size; - FILE *retval; TSRMLS_FETCH(); - - old_chunk_size = php_sock_set_def_chunk_size(1); - retval=php_fopen_wrapper((char *) filename, "rb", USE_PATH|IGNORE_URL_WIN, &issock, &socketd, opened_path TSRMLS_CC); - php_sock_set_def_chunk_size(old_chunk_size); - - if (issock) { - retval = fdopen(socketd, "rb"); - } - return retval; + + return php_stream_open_wrapper_as_file((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, opened_path); } /* }}} */ @@ -571,7 +754,7 @@ case ZMSG_MEMORY_LEAK_REPEATED: { TSRMLS_FETCH(); - if (EG(error_reporting)&E_WARNING) { + if ((EG(error_reporting)&E_WARNING) && PG(report_memleaks)) { #if ZEND_DEBUG char memory_leak_buf[512]; @@ -622,9 +805,8 @@ */ static void sigchld_handler(int apar) { - while (waitpid(-1, NULL, WNOHANG) > 0) - ; - signal(SIGCHLD, sigchld_handler); + while (waitpid(-1, NULL, WNOHANG) > 0); + signal(SIGCHLD, sigchld_handler); } /* }}} */ #endif @@ -634,62 +816,52 @@ /* {{{ php_request_startup */ int php_request_startup(TSRMLS_D) -{ - int retval = SUCCESS; - +{ + int retval = SUCCESS; #if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - - zend_try { - PG(during_request_startup) = 1; - - php_output_activate(TSRMLS_C); - - /* initialize global variables */ - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - - zend_activate(TSRMLS_C); - sapi_activate(TSRMLS_C); + signal(SIGCHLD, sigchld_handler); +#endif + 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; + } + php_output_activate(TSRMLS_C); + sapi_activate(TSRMLS_C); + php_hash_environment(TSRMLS_C); + zend_try { + if (PG(expose_php)) { + sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); + } + if (PG(output_handler) && PG(output_handler)[0]) { + php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC); + } + else if (PG(output_buffering)) { + php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); + } + else if (PG(implicit_flush)) { + php_start_implicit_flush(TSRMLS_C); + } + } zend_catch { + retval = FAILURE; + } zend_end_try(); - zend_set_timeout(EG(timeout_seconds)); - - if (PG(expose_php)) { - sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); - } - - if (PG(output_handler) && PG(output_handler)[0]) { - zval *output_handler; - - ALLOC_INIT_ZVAL(output_handler); - Z_STRLEN_P(output_handler) = strlen(PG(output_handler)); /* this can be optimized */ - Z_STRVAL_P(output_handler) = estrndup(PG(output_handler), Z_STRLEN_P(output_handler)); - Z_TYPE_P(output_handler) = IS_STRING; - php_start_ob_buffer(output_handler, 0 TSRMLS_CC); - } else if (PG(output_buffering)) { - if (PG(output_buffering)>1) { - php_start_ob_buffer(NULL, PG(output_buffering) TSRMLS_CC); - } else { - php_start_ob_buffer(NULL, 0 TSRMLS_CC); - } - } else if (PG(implicit_flush)) { - php_start_implicit_flush(TSRMLS_C); - } - - /* We turn this off in php_execute_script() */ - /* PG(during_request_startup) = 0; */ - - php_hash_environment(TSRMLS_C); - zend_activate_modules(TSRMLS_C); - PG(modules_activated)=1; - } zend_catch { - retval = FAILURE; - } zend_end_try(); - - return retval; + return retval; } + /* }}} */ /* {{{ php_request_startup_for_hook @@ -697,25 +869,26 @@ int php_request_startup_for_hook(TSRMLS_D) { int retval = SUCCESS; - -#if PHP_SIGCHILD +#if PHP_SIGCHLD signal(SIGCHLD, sigchld_handler); #endif - - zend_try { - PG(during_request_startup) = 1; - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - zend_activate(TSRMLS_C); - sapi_activate(TSRMLS_C); - zend_set_timeout(EG(timeout_seconds)); - php_hash_environment(TSRMLS_C); - zend_activate_modules(TSRMLS_C); - PG(modules_activated)=1; - } zend_catch { - retval = FAILURE; - } zend_end_try(); + if(!SG(sapi_started)) { + zend_try { + PG(during_request_startup) = 1; + PG(modules_activated) = 0; + PG(header_is_being_sent) = 0; + PG(connection_status) = PHP_CONNECTION_NORMAL; + zend_activate(TSRMLS_C); + zend_activate_modules(TSRMLS_C); + PG(modules_activated) = 1; + } zend_catch { + retval = FAILURE; + } zend_end_try(); + SG(sapi_started) = 1; + } + sapi_activate(TSRMLS_C); + zend_set_timeout(EG(timeout_seconds)); + php_hash_environment(TSRMLS_C); return retval; } @@ -725,9 +898,11 @@ */ void php_request_shutdown_for_exec(void *dummy) { + TSRMLS_FETCH(); + /* used to close fd's in the 3..255 range here, but it's problematic */ - shutdown_memory_manager(1, 1); + shutdown_memory_manager(1, 1 TSRMLS_CC); } /* }}} */ @@ -736,11 +911,10 @@ void php_request_shutdown_for_hook(void *dummy) { TSRMLS_FETCH(); - if (PG(modules_activated)) zend_try { php_call_shutdown_functions(); } zend_end_try(); - + if (PG(modules_activated)) { zend_deactivate_modules(TSRMLS_C); } @@ -748,7 +922,7 @@ zend_try { int i; - for (i=0; i<NUM_TRACK_VARS; i++) { + for (i = 0; i < NUM_TRACK_VARS; i++) { zval_ptr_dtor(&PG(http_globals)[i]); } } zend_end_try(); @@ -759,14 +933,15 @@ sapi_deactivate(TSRMLS_C); } zend_end_try(); - zend_try { + zend_try { shutdown_memory_manager(CG(unclean_shutdown), 0); } zend_end_try(); - zend_try { + zend_try { zend_unset_timeout(TSRMLS_C); } zend_end_try(); } + /* }}} */ /* {{{ php_request_shutdown @@ -795,7 +970,9 @@ int i; for (i=0; i<NUM_TRACK_VARS; i++) { - zval_ptr_dtor(&PG(http_globals)[i]); + if (PG(http_globals)[i]) { + zval_ptr_dtor(&PG(http_globals)[i]); + } } } zend_end_try(); @@ -807,7 +984,7 @@ } zend_end_try(); zend_try { - shutdown_memory_manager(CG(unclean_shutdown), 0); + shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC); } zend_end_try(); zend_try { @@ -887,7 +1064,7 @@ } } #else - php_os=PHP_OS; + php_os=PHP_OS; #endif #ifdef ZTS @@ -928,6 +1105,8 @@ PG(header_is_being_sent) = 0; SG(request_info).headers_only = 0; SG(request_info).argv0 = NULL; + SG(request_info).argc=0; + SG(request_info).argv=(char **)NULL; PG(connection_status) = PHP_CONNECTION_NORMAL; PG(during_request_startup) = 0; @@ -949,20 +1128,20 @@ /* this will read in php.ini, set up the configuration parameters, load zend extensions and register php function extensions to be loaded later */ - if (php_init_config(sf->php_ini_path_override) == FAILURE) { + if (php_init_config() == FAILURE) { return FAILURE; } REGISTER_INI_ENTRIES(); - /* initialize fopen wrappers registry - (this uses configuration parameters from php.ini) + /* initialize stream wrappers registry + * (this uses configuration parameters from php.ini) */ - if (php_init_fopen_wrappers(TSRMLS_C) == FAILURE) { - php_printf("PHP: Unable to initialize fopen url wrappers.\n"); + if (php_init_stream_wrappers(TSRMLS_C) == FAILURE) { + php_printf("PHP: Unable to initialize stream url wrappers.\n"); return FAILURE; } - + /* initialize registry for images to be used in phpinfo() (this uses configuration parameters from php.ini) */ @@ -981,17 +1160,21 @@ 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); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS); 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); REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS); 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); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS); php_output_register_constants(TSRMLS_C); + php_rfc1867_register_constants(TSRMLS_C); if (php_startup_ticks(TSRMLS_C) == FAILURE) { php_printf("Unable to start PHP ticks\n"); @@ -1009,7 +1192,7 @@ 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 - ahead of all other internals + ahead of all other internals */ php_ini_delayed_modules_startup(TSRMLS_C); @@ -1061,18 +1244,18 @@ sapi_flush(TSRMLS_C); zend_shutdown(TSRMLS_C); - php_shutdown_fopen_wrappers(TSRMLS_C); + + php_shutdown_stream_wrappers(TSRMLS_C); + php_shutdown_info_logos(); UNREGISTER_INI_ENTRIES(); /* close down the ini config */ php_shutdown_config(); -#ifdef ZTS - ts_free_thread(); -#else +#ifndef ZTS zend_ini_shutdown(TSRMLS_C); - shutdown_memory_manager(CG(unclean_shutdown), 1); + shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC); #endif module_initialized = 0; @@ -1117,7 +1300,7 @@ char *p; unsigned char _gpc_flags[3] = {0, 0, 0}; zend_bool have_variables_order; - zval *dummy_track_vars_array; + zval *dummy_track_vars_array = NULL; zend_bool initialized_dummy_track_vars_array=0; int i; char *variables_order; @@ -1161,21 +1344,21 @@ case 'p': case 'P': if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) { - php_treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */ + sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */ _gpc_flags[0]=1; } break; case 'c': case 'C': if (!_gpc_flags[1]) { - php_treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */ + sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */ _gpc_flags[1]=1; } break; case 'g': case 'G': if (!_gpc_flags[2]) { - php_treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */ + sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */ _gpc_flags[2]=1; } break; @@ -1264,7 +1447,21 @@ INIT_PZVAL(arr); /* Prepare argv */ - if (s && *s) { + if (SG(request_info).argc) { /* are we in cli sapi? */ + int i; + for (i=0; i<SG(request_info).argc; i++) { + ALLOC_ZVAL(tmp); + Z_TYPE_P(tmp) = IS_STRING; + Z_STRLEN_P(tmp) = strlen(SG(request_info).argv[i]); + Z_STRVAL_P(tmp) = estrndup(SG(request_info).argv[i], Z_STRLEN_P(tmp)); + INIT_PZVAL(tmp); + if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) { + if (Z_TYPE_P(tmp) == IS_STRING) { + efree(Z_STRVAL_P(tmp)); + } + } + } + } else if (s && *s) { ss = s; while (ss) { space = strchr(ss, '+'); @@ -1273,14 +1470,14 @@ } /* auto-type */ ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(ss); - tmp->value.str.val = estrndup(ss, tmp->value.str.len); + Z_TYPE_P(tmp) = IS_STRING; + Z_STRLEN_P(tmp) = strlen(ss); + Z_STRVAL_P(tmp) = estrndup(ss, Z_STRLEN_P(tmp)); INIT_PZVAL(tmp); count++; - if (zend_hash_next_index_insert(arr->value.ht, &tmp, sizeof(pval *), NULL)==FAILURE) { - if (tmp->type == IS_STRING) { - efree(tmp->value.str.val); + if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(pval *), NULL)==FAILURE) { + if (Z_TYPE_P(tmp) == IS_STRING) { + efree(Z_STRVAL_P(tmp)); } } if (space) { @@ -1294,19 +1491,23 @@ /* prepare argc */ ALLOC_ZVAL(argc); - argc->value.lval = count; - argc->type = IS_LONG; + if (SG(request_info).argc) { + Z_LVAL_P(argc) = SG(request_info).argc; + } else { + Z_LVAL_P(argc) = count; + } + Z_TYPE_P(argc) = IS_LONG; INIT_PZVAL(argc); - if (PG(register_globals)) { + if (PG(register_globals) || SG(request_info).argc) { arr->refcount++; argc->refcount++; zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL); zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL); } - zend_hash_update(track_vars_array->value.ht, "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); - zend_hash_update(track_vars_array->value.ht, "argc", sizeof("argc"), &argc, sizeof(pval *), NULL); + zend_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL); + zend_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL); } /* }}} */ @@ -1334,6 +1535,7 @@ zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; char *old_cwd; + int retval = 0; EG(exit_status) = 0; if (php_handle_special_queries(TSRMLS_C)) { @@ -1356,6 +1558,14 @@ VCWD_CHDIR_FILE(primary_file->filename); } + if(primary_file->filename) { + char realfile[MAXPATHLEN]; + int dummy = 1; + if(VCWD_REALPATH(primary_file->filename, realfile)) { + zend_hash_add(&EG(included_files), realfile, strlen(realfile)+1, (void *)&dummy, sizeof(int), NULL); + } + } + if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { prepend_file.filename = PG(auto_prepend_file); prepend_file.opened_path = NULL; @@ -1374,14 +1584,17 @@ } else { append_file_p = NULL; } - zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p); +#if defined(ZEND_MULTIBYTE) && defined(HAVE_MBSTRING) + php_mbstring_set_zend_encoding(TSRMLS_C); +#endif /* ZEND_MULTIBYTE && HAVE_MBSTRING */ + retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS); } zend_end_try(); if (old_cwd[0] != '\0') { VCWD_CHDIR(old_cwd); } free_alloca(old_cwd); - return EG(exit_status); + return retval; } /* }}} */ @@ -1403,7 +1616,7 @@ PG(during_request_startup) = 0; - if (primary_file->type == ZEND_HANDLE_FILENAME + if (primary_file->type == ZEND_HANDLE_FILENAME && primary_file->filename) { VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); VCWD_CHDIR_FILE(primary_file->filename); @@ -1414,6 +1627,7 @@ if (old_cwd[0] != '\0') { VCWD_CHDIR(old_cwd); } + free_alloca(old_cwd); return EG(exit_status); } @@ -1504,6 +1718,6 @@ * tab-width: 4 * c-basic-offset: 4 * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ Index: php4/main/SAPI.c +++ php4/main/SAPI.c #include "SAPI.h" #include "TSRM.h" #ifdef ZTS int sapi_globals_id; #endif void sapi_startup() { #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL); #endif } Index: php4/main/SAPI.h +++ php4/main/SAPI.h #ifndef _NEW_SAPI_H #define _NEW_SAPI_H typedef struct { int (*ub_write)(const char *str, unsigned int str_length); } sapi_functions_struct; extern sapi_functions_struct sapi_functions; /* true global */ typedef struct { void *server_context; } sapi_globals_struct; void sapi_startup(); #ifdef ZTS # define SLS_D sapi_globals_struct *sapi_globals # define SLS_DC , SLS_D # define SLS_C sapi_globals # define SLS_CC , SLS_C # define SG(v) (sapi_globals->v) # define SLS_FETCH() sapi_globals_struct *sapi_globals = ts_resource(sapi_globals_id) extern int sapi_globals_id; #else # define SLS_D # define SLS_DC # define SLS_C # define SLS_CC # define SG(v) (sapi_globals.v) # define SLS_FETCH() extern ZEND_API sapi_globals_struct sapi_globals; #endif #endif /* _NEW_SAPI_H */
« previous php.cvs (#13682) next »