Annotation of embedaddon/php/main/main.c, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | Copyright (c) 1997-2012 The PHP Group |
! 6: +----------------------------------------------------------------------+
! 7: | This source file is subject to version 3.01 of the PHP license, |
! 8: | that is bundled with this package in the file LICENSE, and is |
! 9: | available through the world-wide-web at the following url: |
! 10: | http://www.php.net/license/3_01.txt |
! 11: | If you did not receive a copy of the PHP license and are unable to |
! 12: | obtain it through the world-wide-web, please send a note to |
! 13: | license@php.net so we can mail you a copy immediately. |
! 14: +----------------------------------------------------------------------+
! 15: | Authors: Andi Gutmans <andi@zend.com> |
! 16: | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
! 17: | Zeev Suraski <zeev@zend.com> |
! 18: +----------------------------------------------------------------------+
! 19: */
! 20:
! 21: /* $Id: main.c 321634 2012-01-01 13:15:04Z felipe $ */
! 22:
! 23: /* {{{ includes
! 24: */
! 25:
! 26: #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
! 27:
! 28: #include "php.h"
! 29: #include <stdio.h>
! 30: #include <fcntl.h>
! 31: #ifdef PHP_WIN32
! 32: #include "win32/time.h"
! 33: #include "win32/signal.h"
! 34: #include "win32/php_win32_globals.h"
! 35: #include "win32/winutil.h"
! 36: #include <process.h>
! 37: #elif defined(NETWARE)
! 38: #include <sys/timeval.h>
! 39: #ifdef USE_WINSOCK
! 40: #include <novsock2.h>
! 41: #endif
! 42: #endif
! 43: #if HAVE_SYS_TIME_H
! 44: #include <sys/time.h>
! 45: #endif
! 46: #if HAVE_UNISTD_H
! 47: #include <unistd.h>
! 48: #endif
! 49: #if HAVE_SIGNAL_H
! 50: #include <signal.h>
! 51: #endif
! 52: #if HAVE_SETLOCALE
! 53: #include <locale.h>
! 54: #endif
! 55: #include "zend.h"
! 56: #include "zend_extensions.h"
! 57: #include "php_ini.h"
! 58: #include "php_globals.h"
! 59: #include "php_main.h"
! 60: #include "fopen_wrappers.h"
! 61: #include "ext/standard/php_standard.h"
! 62: #include "ext/standard/php_string.h"
! 63: #include "ext/date/php_date.h"
! 64: #include "php_variables.h"
! 65: #include "ext/standard/credits.h"
! 66: #ifdef PHP_WIN32
! 67: #include <io.h>
! 68: #include "win32/php_registry.h"
! 69: #include "ext/standard/flock_compat.h"
! 70: #endif
! 71: #include "php_syslog.h"
! 72: #include "Zend/zend_exceptions.h"
! 73:
! 74: #if PHP_SIGCHILD
! 75: #include <sys/types.h>
! 76: #include <sys/wait.h>
! 77: #endif
! 78:
! 79: #include "zend_compile.h"
! 80: #include "zend_execute.h"
! 81: #include "zend_highlight.h"
! 82: #include "zend_indent.h"
! 83: #include "zend_extensions.h"
! 84: #include "zend_ini.h"
! 85:
! 86: #include "php_content_types.h"
! 87: #include "php_ticks.h"
! 88: #include "php_logos.h"
! 89: #include "php_streams.h"
! 90: #include "php_open_temporary_file.h"
! 91:
! 92: #include "SAPI.h"
! 93: #include "rfc1867.h"
! 94: #if SUHOSIN_PATCH
! 95: #include "suhosin_globals.h"
! 96: #endif
! 97:
! 98: #if HAVE_MMAP
! 99: # if HAVE_UNISTD_H
! 100: # include <unistd.h>
! 101: # if defined(_SC_PAGESIZE)
! 102: # define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
! 103: # elif defined(_SC_PAGE_SIZE)
! 104: # define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);
! 105: # endif
! 106: # endif
! 107: # if HAVE_SYS_MMAN_H
! 108: # include <sys/mman.h>
! 109: # endif
! 110: # ifndef REAL_PAGE_SIZE
! 111: # ifdef PAGE_SIZE
! 112: # define REAL_PAGE_SIZE PAGE_SIZE
! 113: # else
! 114: # define REAL_PAGE_SIZE 4096
! 115: # endif
! 116: # endif
! 117: #endif
! 118: /* }}} */
! 119:
! 120: PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
! 121:
! 122: #ifndef ZTS
! 123: php_core_globals core_globals;
! 124: #else
! 125: PHPAPI int core_globals_id;
! 126: #endif
! 127:
! 128: #ifdef PHP_WIN32
! 129: #include "win32_internal_function_disabled.h"
! 130:
! 131: static php_win32_disable_functions() {
! 132: int i;
! 133: TSRMLS_FETCH();
! 134:
! 135: if (EG(windows_version_info).dwMajorVersion < 5) {
! 136: for (i = 0; i < function_name_cnt_5; i++) {
! 137: if (zend_hash_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]) + 1)==FAILURE) {
! 138: php_printf("Unable to disable function '%s'\n", function_name_5[i]);
! 139: return FAILURE;
! 140: }
! 141: }
! 142: }
! 143:
! 144: if (EG(windows_version_info).dwMajorVersion < 6) {
! 145: for (i = 0; i < function_name_cnt_6; i++) {
! 146: if (zend_hash_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]) + 1)==FAILURE) {
! 147: php_printf("Unable to disable function '%s'\n", function_name_6[i]);
! 148: return FAILURE;
! 149: }
! 150: }
! 151: }
! 152: return SUCCESS;
! 153: }
! 154: #endif
! 155:
! 156: #define SAFE_FILENAME(f) ((f)?(f):"-")
! 157:
! 158: /* {{{ PHP_INI_MH
! 159: */
! 160: static PHP_INI_MH(OnSetPrecision)
! 161: {
! 162: int i = atoi(new_value);
! 163: if (i >= 0) {
! 164: EG(precision) = i;
! 165: return SUCCESS;
! 166: } else {
! 167: return FAILURE;
! 168: }
! 169: }
! 170: /* }}} */
! 171:
! 172: /* {{{ PHP_INI_MH
! 173: */
! 174: static PHP_INI_MH(OnChangeMemoryLimit)
! 175: {
! 176: if (new_value) {
! 177: PG(memory_limit) = zend_atol(new_value, new_value_length);
! 178: } else {
! 179: PG(memory_limit) = 1<<30; /* effectively, no limit */
! 180: }
! 181: return zend_set_memory_limit(PG(memory_limit));
! 182: }
! 183: /* }}} */
! 184:
! 185:
! 186: /* {{{ php_disable_functions
! 187: */
! 188: static void php_disable_functions(TSRMLS_D)
! 189: {
! 190: char *s = NULL, *e;
! 191:
! 192: if (!*(INI_STR("disable_functions"))) {
! 193: return;
! 194: }
! 195:
! 196: e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
! 197: if (e == NULL) {
! 198: return;
! 199: }
! 200: while (*e) {
! 201: switch (*e) {
! 202: case ' ':
! 203: case ',':
! 204: if (s) {
! 205: *e = '\0';
! 206: zend_disable_function(s, e-s TSRMLS_CC);
! 207: s = NULL;
! 208: }
! 209: break;
! 210: default:
! 211: if (!s) {
! 212: s = e;
! 213: }
! 214: break;
! 215: }
! 216: e++;
! 217: }
! 218: if (s) {
! 219: zend_disable_function(s, e-s TSRMLS_CC);
! 220: }
! 221: }
! 222: /* }}} */
! 223:
! 224: /* {{{ php_disable_classes
! 225: */
! 226: static void php_disable_classes(TSRMLS_D)
! 227: {
! 228: char *s = NULL, *e;
! 229:
! 230: if (!*(INI_STR("disable_classes"))) {
! 231: return;
! 232: }
! 233:
! 234: e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
! 235:
! 236: while (*e) {
! 237: switch (*e) {
! 238: case ' ':
! 239: case ',':
! 240: if (s) {
! 241: *e = '\0';
! 242: zend_disable_class(s, e-s TSRMLS_CC);
! 243: s = NULL;
! 244: }
! 245: break;
! 246: default:
! 247: if (!s) {
! 248: s = e;
! 249: }
! 250: break;
! 251: }
! 252: e++;
! 253: }
! 254: if (s) {
! 255: zend_disable_class(s, e-s TSRMLS_CC);
! 256: }
! 257: }
! 258: /* }}} */
! 259:
! 260: /* {{{ PHP_INI_MH
! 261: */
! 262: static PHP_INI_MH(OnUpdateTimeout)
! 263: {
! 264: if (stage==PHP_INI_STAGE_STARTUP) {
! 265: /* Don't set a timeout on startup, only per-request */
! 266: EG(timeout_seconds) = atoi(new_value);
! 267: return SUCCESS;
! 268: }
! 269: zend_unset_timeout(TSRMLS_C);
! 270: EG(timeout_seconds) = atoi(new_value);
! 271: zend_set_timeout(EG(timeout_seconds), 0);
! 272: return SUCCESS;
! 273: }
! 274: /* }}} */
! 275:
! 276: /* {{{ php_get_display_errors_mode() helper function
! 277: */
! 278: static int php_get_display_errors_mode(char *value, int value_length)
! 279: {
! 280: int mode;
! 281:
! 282: if (!value) {
! 283: return PHP_DISPLAY_ERRORS_STDOUT;
! 284: }
! 285:
! 286: if (value_length == 2 && !strcasecmp("on", value)) {
! 287: mode = PHP_DISPLAY_ERRORS_STDOUT;
! 288: } else if (value_length == 3 && !strcasecmp("yes", value)) {
! 289: mode = PHP_DISPLAY_ERRORS_STDOUT;
! 290: } else if (value_length == 4 && !strcasecmp("true", value)) {
! 291: mode = PHP_DISPLAY_ERRORS_STDOUT;
! 292: } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
! 293: mode = PHP_DISPLAY_ERRORS_STDERR;
! 294: } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
! 295: mode = PHP_DISPLAY_ERRORS_STDOUT;
! 296: } else {
! 297: mode = atoi(value);
! 298: if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
! 299: mode = PHP_DISPLAY_ERRORS_STDOUT;
! 300: }
! 301: }
! 302:
! 303: return mode;
! 304: }
! 305: /* }}} */
! 306:
! 307: /* {{{ PHP_INI_MH
! 308: */
! 309: static PHP_INI_MH(OnUpdateDisplayErrors)
! 310: {
! 311: PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);
! 312:
! 313: return SUCCESS;
! 314: }
! 315: /* }}} */
! 316:
! 317: /* {{{ PHP_INI_DISP
! 318: */
! 319: static PHP_INI_DISP(display_errors_mode)
! 320: {
! 321: int mode, tmp_value_length, cgi_or_cli;
! 322: char *tmp_value;
! 323: TSRMLS_FETCH();
! 324:
! 325: if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
! 326: tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
! 327: tmp_value_length = ini_entry->orig_value_length;
! 328: } else if (ini_entry->value) {
! 329: tmp_value = ini_entry->value;
! 330: tmp_value_length = ini_entry->value_length;
! 331: } else {
! 332: tmp_value = NULL;
! 333: tmp_value_length = 0;
! 334: }
! 335:
! 336: mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
! 337:
! 338: /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
! 339: cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi"));
! 340:
! 341: switch (mode) {
! 342: case PHP_DISPLAY_ERRORS_STDERR:
! 343: if (cgi_or_cli ) {
! 344: PUTS("STDERR");
! 345: } else {
! 346: PUTS("On");
! 347: }
! 348: break;
! 349:
! 350: case PHP_DISPLAY_ERRORS_STDOUT:
! 351: if (cgi_or_cli ) {
! 352: PUTS("STDOUT");
! 353: } else {
! 354: PUTS("On");
! 355: }
! 356: break;
! 357:
! 358: default:
! 359: PUTS("Off");
! 360: break;
! 361: }
! 362: }
! 363: /* }}} */
! 364:
! 365: /* {{{ PHP_INI_MH
! 366: */
! 367: static PHP_INI_MH(OnUpdateErrorLog)
! 368: {
! 369: /* Only do the safemode/open_basedir check at runtime */
! 370: if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {
! 371: if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
! 372: return FAILURE;
! 373: }
! 374:
! 375: if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
! 376: return FAILURE;
! 377: }
! 378:
! 379: }
! 380: OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
! 381: return SUCCESS;
! 382: }
! 383: /* }}} */
! 384:
! 385: /* {{{ PHP_INI_MH
! 386: */
! 387: static PHP_INI_MH(OnUpdateMailLog)
! 388: {
! 389: /* Only do the safemode/open_basedir check at runtime */
! 390: if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
! 391: if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
! 392: return FAILURE;
! 393: }
! 394:
! 395: if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
! 396: return FAILURE;
! 397: }
! 398:
! 399: }
! 400: OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
! 401: return SUCCESS;
! 402: }
! 403: /* }}} */
! 404:
! 405: /* {{{ PHP_INI_MH
! 406: */
! 407: static PHP_INI_MH(OnChangeMailForceExtra)
! 408: {
! 409: /* Don't allow changing it in htaccess */
! 410: if (stage == PHP_INI_STAGE_HTACCESS) {
! 411: return FAILURE;
! 412: }
! 413: return SUCCESS;
! 414: }
! 415: /* }}} */
! 416:
! 417: /* defined in browscap.c */
! 418: PHP_INI_MH(OnChangeBrowscap);
! 419:
! 420: /* Need to convert to strings and make use of:
! 421: * PHP_SAFE_MODE
! 422: *
! 423: * Need to be read from the environment (?):
! 424: * PHP_AUTO_PREPEND_FILE
! 425: * PHP_AUTO_APPEND_FILE
! 426: * PHP_DOCUMENT_ROOT
! 427: * PHP_USER_DIR
! 428: * PHP_INCLUDE_PATH
! 429: */
! 430:
! 431: #ifndef PHP_SAFE_MODE_EXEC_DIR
! 432: # define PHP_SAFE_MODE_EXEC_DIR ""
! 433: #endif
! 434:
! 435: /* Windows and Netware use the internal mail */
! 436: #if defined(PHP_WIN32) || defined(NETWARE)
! 437: # define DEFAULT_SENDMAIL_PATH NULL
! 438: #elif defined(PHP_PROG_SENDMAIL)
! 439: # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
! 440: #else
! 441: # define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"
! 442: #endif
! 443:
! 444: /* {{{ PHP_INI
! 445: */
! 446: PHP_INI_BEGIN()
! 447: PHP_INI_ENTRY_EX("define_syslog_variables", "0", PHP_INI_ALL, NULL, php_ini_boolean_displayer_cb)
! 448: PHP_INI_ENTRY_EX("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 449: PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 450: PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 451: PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 452: PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 453: PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
! 454:
! 455: 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)
! 456: STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals)
! 457: STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
! 458: STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
! 459: STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
! 460: STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
! 461: STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
! 462: STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
! 463: STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
! 464: STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
! 465: STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
! 466: STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
! 467: STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
! 468: STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
! 469: STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
! 470: STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
! 471: STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
! 472: STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
! 473: STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
! 474: STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
! 475: STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals)
! 476: STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals)
! 477: STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals)
! 478: STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
! 479: STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
! 480: STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
! 481: STD_PHP_INI_BOOLEAN("register_globals", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_globals, php_core_globals, core_globals)
! 482: STD_PHP_INI_BOOLEAN("register_long_arrays", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays, php_core_globals, core_globals)
! 483: STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
! 484: #if PHP_SAFE_MODE
! 485: STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
! 486: #else
! 487: STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
! 488: #endif
! 489: STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals)
! 490: STD_PHP_INI_BOOLEAN("safe_mode_gid", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode_gid, php_core_globals, core_globals)
! 491: 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)
! 492: STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
! 493: STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
! 494: STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
! 495:
! 496: STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
! 497: STD_PHP_INI_ENTRY("serialize_precision", "17", PHP_INI_ALL, OnUpdateLongGEZero, serialize_precision, php_core_globals, core_globals)
! 498: STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
! 499: STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
! 500:
! 501: STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
! 502: STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
! 503: STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
! 504: STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct,sapi_globals)
! 505: STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct,sapi_globals)
! 506: STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
! 507: STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
! 508: STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
! 509: PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
! 510: PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir)
! 511: 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)
! 512:
! 513: STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
! 514: STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
! 515: STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
! 516: STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
! 517: STD_PHP_INI_ENTRY("max_input_nesting_level", "64", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_nesting_level, php_core_globals, core_globals)
! 518: STD_PHP_INI_ENTRY("max_input_vars", "1000", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_vars, php_core_globals, core_globals)
! 519:
! 520: STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
! 521: STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
! 522: STD_PHP_INI_ENTRY("request_order", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, request_order, php_core_globals, core_globals)
! 523:
! 524: STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
! 525: STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
! 526:
! 527: PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
! 528: PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
! 529: STD_PHP_INI_BOOLEAN("mail.add_x_header", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, mail_x_header, php_core_globals, core_globals)
! 530: STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateMailLog, mail_log, php_core_globals, core_globals)
! 531: PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, OnChangeBrowscap)
! 532: PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
! 533: PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
! 534: PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
! 535: PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
! 536: PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
! 537: PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
! 538: PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
! 539: PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM, NULL)
! 540:
! 541: STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
! 542: STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
! 543: 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)
! 544:
! 545: STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
! 546: STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
! 547:
! 548: STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
! 549: STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
! 550: STD_PHP_INI_BOOLEAN("exit_on_timeout", "0", PHP_INI_ALL, OnUpdateBool, exit_on_timeout, php_core_globals, core_globals)
! 551: #ifdef PHP_WIN32
! 552: STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals)
! 553: #endif
! 554: PHP_INI_END()
! 555: /* }}} */
! 556:
! 557: /* True globals (no need for thread safety */
! 558: /* But don't make them a single int bitfield */
! 559: static int module_initialized = 0;
! 560: static int module_startup = 1;
! 561: static int module_shutdown = 0;
! 562:
! 563: /* {{{ php_during_module_startup */
! 564: static int php_during_module_startup(void)
! 565: {
! 566: return module_startup;
! 567: }
! 568: /* }}} */
! 569:
! 570: /* {{{ php_during_module_shutdown */
! 571: static int php_during_module_shutdown(void)
! 572: {
! 573: return module_shutdown;
! 574: }
! 575: /* }}} */
! 576:
! 577: /* {{{ php_log_err
! 578: */
! 579: PHPAPI void php_log_err(char *log_message TSRMLS_DC)
! 580: {
! 581: int fd = -1;
! 582: time_t error_time;
! 583:
! 584: if (PG(in_error_log)) {
! 585: /* prevent recursive invocation */
! 586: return;
! 587: }
! 588: PG(in_error_log) = 1;
! 589:
! 590: /* Try to use the specified logging location. */
! 591: if (PG(error_log) != NULL) {
! 592: #ifdef HAVE_SYSLOG_H
! 593: if (!strcmp(PG(error_log), "syslog")) {
! 594: php_syslog(LOG_NOTICE, "%s", log_message);
! 595: PG(in_error_log) = 0;
! 596: return;
! 597: }
! 598: #endif
! 599: fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
! 600: if (fd != -1) {
! 601: char *tmp;
! 602: int len;
! 603: char *error_time_str;
! 604:
! 605: time(&error_time);
! 606: error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0 TSRMLS_CC);
! 607: len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
! 608: #ifdef PHP_WIN32
! 609: php_flock(fd, 2);
! 610: #endif
! 611: write(fd, tmp, len);
! 612: efree(tmp);
! 613: efree(error_time_str);
! 614: close(fd);
! 615: PG(in_error_log) = 0;
! 616: return;
! 617: }
! 618: }
! 619:
! 620: /* Otherwise fall back to the default logging location, if we have one */
! 621:
! 622: if (sapi_module.log_message) {
! 623: sapi_module.log_message(log_message);
! 624: }
! 625: PG(in_error_log) = 0;
! 626: }
! 627: /* }}} */
! 628:
! 629: /* {{{ php_write
! 630: wrapper for modules to use PHPWRITE */
! 631: PHPAPI int php_write(void *buf, uint size TSRMLS_DC)
! 632: {
! 633: return PHPWRITE(buf, size);
! 634: }
! 635: /* }}} */
! 636:
! 637: /* {{{ php_printf
! 638: */
! 639: PHPAPI int php_printf(const char *format, ...)
! 640: {
! 641: va_list args;
! 642: int ret;
! 643: char *buffer;
! 644: int size;
! 645: TSRMLS_FETCH();
! 646:
! 647: va_start(args, format);
! 648: size = vspprintf(&buffer, 0, format, args);
! 649: ret = PHPWRITE(buffer, size);
! 650: efree(buffer);
! 651: va_end(args);
! 652:
! 653: return ret;
! 654: }
! 655: /* }}} */
! 656:
! 657: /* {{{ php_verror */
! 658: /* php_verror is called from php_error_docref<n> functions.
! 659: * Its purpose is to unify error messages and automatically generate clickable
! 660: * html error messages if correcponding ini setting (html_errors) is activated.
! 661: * See: CODING_STANDARDS for details.
! 662: */
! 663: PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
! 664: {
! 665: char *buffer = NULL, *docref_buf = NULL, *target = NULL;
! 666: char *docref_target = "", *docref_root = "";
! 667: char *p;
! 668: int buffer_len = 0;
! 669: char *space = "";
! 670: char *class_name = "";
! 671: char *function;
! 672: int origin_len;
! 673: char *origin;
! 674: char *message;
! 675: int is_function = 0;
! 676:
! 677: /* get error text into buffer and escape for html if necessary */
! 678: buffer_len = vspprintf(&buffer, 0, format, args);
! 679: if (PG(html_errors)) {
! 680: int len;
! 681: char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
! 682: efree(buffer);
! 683: buffer = replace;
! 684: buffer_len = len;
! 685: }
! 686:
! 687: /* which function caused the problem if any at all */
! 688: if (php_during_module_startup()) {
! 689: function = "PHP Startup";
! 690: } else if (php_during_module_shutdown()) {
! 691: function = "PHP Shutdown";
! 692: } else if (EG(current_execute_data) &&
! 693: EG(current_execute_data)->opline &&
! 694: EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
! 695: ) {
! 696: switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) {
! 697: case ZEND_EVAL:
! 698: function = "eval";
! 699: is_function = 1;
! 700: break;
! 701: case ZEND_INCLUDE:
! 702: function = "include";
! 703: is_function = 1;
! 704: break;
! 705: case ZEND_INCLUDE_ONCE:
! 706: function = "include_once";
! 707: is_function = 1;
! 708: break;
! 709: case ZEND_REQUIRE:
! 710: function = "require";
! 711: is_function = 1;
! 712: break;
! 713: case ZEND_REQUIRE_ONCE:
! 714: function = "require_once";
! 715: is_function = 1;
! 716: break;
! 717: default:
! 718: function = "Unknown";
! 719: }
! 720: } else {
! 721: function = get_active_function_name(TSRMLS_C);
! 722: if (!function || !strlen(function)) {
! 723: function = "Unknown";
! 724: } else {
! 725: is_function = 1;
! 726: class_name = get_active_class_name(&space TSRMLS_CC);
! 727: }
! 728: }
! 729:
! 730: /* if we still have memory then format the origin */
! 731: if (is_function) {
! 732: origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
! 733: } else {
! 734: origin_len = spprintf(&origin, 0, "%s", function);
! 735: }
! 736:
! 737: if (PG(html_errors)) {
! 738: int len;
! 739: char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
! 740: efree(origin);
! 741: origin = replace;
! 742: }
! 743:
! 744: /* origin and buffer available, so lets come up with the error message */
! 745: if (docref && docref[0] == '#') {
! 746: docref_target = strchr(docref, '#');
! 747: docref = NULL;
! 748: }
! 749:
! 750: /* no docref given but function is known (the default) */
! 751: if (!docref && is_function) {
! 752: int doclen;
! 753: if (space[0] == '\0') {
! 754: doclen = spprintf(&docref_buf, 0, "function.%s", function);
! 755: } else {
! 756: doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function);
! 757: }
! 758: while((p = strchr(docref_buf, '_')) != NULL) {
! 759: *p = '-';
! 760: }
! 761: docref = php_strtolower(docref_buf, doclen);
! 762: }
! 763:
! 764: /* we have a docref for a function AND
! 765: * - we show erroes in html mode OR
! 766: * - the user wants to see the links anyway
! 767: */
! 768: if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) {
! 769: if (strncmp(docref, "http://", 7)) {
! 770: /* We don't have 'http://' so we use docref_root */
! 771:
! 772: char *ref; /* temp copy for duplicated docref */
! 773:
! 774: docref_root = PG(docref_root);
! 775:
! 776: ref = estrdup(docref);
! 777: if (docref_buf) {
! 778: efree(docref_buf);
! 779: }
! 780: docref_buf = ref;
! 781: /* strip of the target if any */
! 782: p = strrchr(ref, '#');
! 783: if (p) {
! 784: target = estrdup(p);
! 785: if (target) {
! 786: docref_target = target;
! 787: *p = '\0';
! 788: }
! 789: }
! 790: /* add the extension if it is set in ini */
! 791: if (PG(docref_ext) && strlen(PG(docref_ext))) {
! 792: spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
! 793: efree(ref);
! 794: }
! 795: docref = docref_buf;
! 796: }
! 797: /* display html formatted or only show the additional links */
! 798: if (PG(html_errors)) {
! 799: spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
! 800: } else {
! 801: spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
! 802: }
! 803: if (target) {
! 804: efree(target);
! 805: }
! 806: } else {
! 807: spprintf(&message, 0, "%s: %s", origin, buffer);
! 808: }
! 809: efree(origin);
! 810: if (docref_buf) {
! 811: efree(docref_buf);
! 812: }
! 813:
! 814: if (PG(track_errors) && module_initialized &&
! 815: (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) {
! 816: if (!EG(active_symbol_table)) {
! 817: zend_rebuild_symbol_table(TSRMLS_C);
! 818: }
! 819: if (EG(active_symbol_table)) {
! 820: zval *tmp;
! 821: ALLOC_INIT_ZVAL(tmp);
! 822: ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
! 823: zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
! 824: }
! 825: }
! 826: efree(buffer);
! 827:
! 828: php_error(type, "%s", message);
! 829: efree(message);
! 830: }
! 831: /* }}} */
! 832:
! 833: /* {{{ php_error_docref0 */
! 834: /* See: CODING_STANDARDS for details. */
! 835: PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
! 836: {
! 837: va_list args;
! 838:
! 839: va_start(args, format);
! 840: php_verror(docref, "", type, format, args TSRMLS_CC);
! 841: va_end(args);
! 842: }
! 843: /* }}} */
! 844:
! 845: /* {{{ php_error_docref1 */
! 846: /* See: CODING_STANDARDS for details. */
! 847: PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
! 848: {
! 849: va_list args;
! 850:
! 851: va_start(args, format);
! 852: php_verror(docref, param1, type, format, args TSRMLS_CC);
! 853: va_end(args);
! 854: }
! 855: /* }}} */
! 856:
! 857: /* {{{ php_error_docref2 */
! 858: /* See: CODING_STANDARDS for details. */
! 859: PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
! 860: {
! 861: char *params;
! 862: va_list args;
! 863:
! 864: spprintf(¶ms, 0, "%s,%s", param1, param2);
! 865: va_start(args, format);
! 866: php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC);
! 867: va_end(args);
! 868: if (params) {
! 869: efree(params);
! 870: }
! 871: }
! 872: /* }}} */
! 873:
! 874: #ifdef PHP_WIN32
! 875: #define PHP_WIN32_ERROR_MSG_BUFFER_SIZE 512
! 876: PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC) {
! 877: if (error == 0) {
! 878: php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s", strerror(errno));
! 879: } else {
! 880: char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1];
! 881: int buf_len;
! 882:
! 883: FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
! 884: buf_len = strlen(buf);
! 885: if (buf_len >= 2) {
! 886: buf[buf_len - 1] = '\0';
! 887: buf[buf_len - 2] = '\0';
! 888: }
! 889: php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s (code: %lu)", (char *)buf, error);
! 890: }
! 891: }
! 892: #undef PHP_WIN32_ERROR_MSG_BUFFER_SIZE
! 893: #endif
! 894:
! 895: /* {{{ php_html_puts */
! 896: PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
! 897: {
! 898: zend_html_puts(str, size TSRMLS_CC);
! 899: }
! 900: /* }}} */
! 901:
! 902: /* {{{ php_error_cb
! 903: extended error handling function */
! 904: static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
! 905: {
! 906: char *buffer;
! 907: int buffer_len, display;
! 908: TSRMLS_FETCH();
! 909:
! 910: buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
! 911:
! 912: /* check for repeated errors to be ignored */
! 913: if (PG(ignore_repeated_errors) && PG(last_error_message)) {
! 914: /* no check for PG(last_error_file) is needed since it cannot
! 915: * be NULL if PG(last_error_message) is not NULL */
! 916: if (strcmp(PG(last_error_message), buffer)
! 917: || (!PG(ignore_repeated_source)
! 918: && ((PG(last_error_lineno) != (int)error_lineno)
! 919: || strcmp(PG(last_error_file), error_filename)))) {
! 920: display = 1;
! 921: } else {
! 922: display = 0;
! 923: }
! 924: } else {
! 925: display = 1;
! 926: }
! 927:
! 928: /* store the error if it has changed */
! 929: if (display) {
! 930: if (PG(last_error_message)) {
! 931: free(PG(last_error_message));
! 932: PG(last_error_message) = NULL;
! 933: }
! 934: if (PG(last_error_file)) {
! 935: free(PG(last_error_file));
! 936: PG(last_error_file) = NULL;
! 937: }
! 938: if (!error_filename) {
! 939: error_filename = "Unknown";
! 940: }
! 941: PG(last_error_type) = type;
! 942: PG(last_error_message) = strdup(buffer);
! 943: PG(last_error_file) = strdup(error_filename);
! 944: PG(last_error_lineno) = error_lineno;
! 945: }
! 946:
! 947: /* according to error handling mode, suppress error, throw exception or show it */
! 948: if (EG(error_handling) != EH_NORMAL) {
! 949: switch (type) {
! 950: case E_ERROR:
! 951: case E_CORE_ERROR:
! 952: case E_COMPILE_ERROR:
! 953: case E_USER_ERROR:
! 954: case E_PARSE:
! 955: /* fatal errors are real errors and cannot be made exceptions */
! 956: break;
! 957: case E_STRICT:
! 958: case E_DEPRECATED:
! 959: case E_USER_DEPRECATED:
! 960: /* for the sake of BC to old damaged code */
! 961: break;
! 962: case E_NOTICE:
! 963: case E_USER_NOTICE:
! 964: /* notices are no errors and are not treated as such like E_WARNINGS */
! 965: break;
! 966: default:
! 967: /* throw an exception if we are in EH_THROW mode
! 968: * but DO NOT overwrite a pending exception
! 969: */
! 970: if (EG(error_handling) == EH_THROW && !EG(exception)) {
! 971: zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
! 972: }
! 973: efree(buffer);
! 974: return;
! 975: }
! 976: }
! 977:
! 978: /* display/log the error if necessary */
! 979: if (display && (EG(error_reporting) & type || (type & E_CORE))
! 980: && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
! 981: char *error_type_str;
! 982:
! 983: switch (type) {
! 984: case E_ERROR:
! 985: case E_CORE_ERROR:
! 986: case E_COMPILE_ERROR:
! 987: case E_USER_ERROR:
! 988: error_type_str = "Fatal error";
! 989: break;
! 990: case E_RECOVERABLE_ERROR:
! 991: error_type_str = "Catchable fatal error";
! 992: break;
! 993: case E_WARNING:
! 994: case E_CORE_WARNING:
! 995: case E_COMPILE_WARNING:
! 996: case E_USER_WARNING:
! 997: error_type_str = "Warning";
! 998: break;
! 999: case E_PARSE:
! 1000: error_type_str = "Parse error";
! 1001: break;
! 1002: case E_NOTICE:
! 1003: case E_USER_NOTICE:
! 1004: error_type_str = "Notice";
! 1005: break;
! 1006: case E_STRICT:
! 1007: error_type_str = "Strict Standards";
! 1008: break;
! 1009: case E_DEPRECATED:
! 1010: case E_USER_DEPRECATED:
! 1011: error_type_str = "Deprecated";
! 1012: break;
! 1013: default:
! 1014: error_type_str = "Unknown error";
! 1015: break;
! 1016: }
! 1017:
! 1018: if (!module_initialized || PG(log_errors)) {
! 1019: char *log_buffer;
! 1020: #ifdef PHP_WIN32
! 1021: if ((type == E_CORE_ERROR || type == E_CORE_WARNING) && PG(display_startup_errors)) {
! 1022: MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
! 1023: }
! 1024: #endif
! 1025: spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
! 1026: php_log_err(log_buffer TSRMLS_CC);
! 1027: efree(log_buffer);
! 1028: }
! 1029:
! 1030: if (PG(display_errors)
! 1031: && ((module_initialized && !PG(during_request_startup))
! 1032: || (PG(display_startup_errors)
! 1033: && (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)
! 1034: )
! 1035: )
! 1036: ) {
! 1037:
! 1038: if (PG(xmlrpc_errors)) {
! 1039: 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);
! 1040: } else {
! 1041: char *prepend_string = INI_STR("error_prepend_string");
! 1042: char *append_string = INI_STR("error_append_string");
! 1043:
! 1044: if (PG(html_errors)) {
! 1045: if (type == E_ERROR) {
! 1046: int len;
! 1047: char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
! 1048: php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buf, error_filename, error_lineno, STR_PRINT(append_string));
! 1049: efree(buf);
! 1050: } else {
! 1051: php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
! 1052: }
! 1053: } else {
! 1054: /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
! 1055: if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) &&
! 1056: PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
! 1057: ) {
! 1058: #ifdef PHP_WIN32
! 1059: fprintf(stderr, "%s: %s in %s on line%d\n", error_type_str, buffer, error_filename, error_lineno);
! 1060: fflush(stderr);
! 1061: #else
! 1062: fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno);
! 1063: #endif
! 1064: } else {
! 1065: php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
! 1066: }
! 1067: }
! 1068: }
! 1069: }
! 1070: #if ZEND_DEBUG
! 1071: if (PG(report_zend_debug)) {
! 1072: zend_bool trigger_break;
! 1073:
! 1074: switch (type) {
! 1075: case E_ERROR:
! 1076: case E_CORE_ERROR:
! 1077: case E_COMPILE_ERROR:
! 1078: case E_USER_ERROR:
! 1079: trigger_break=1;
! 1080: break;
! 1081: default:
! 1082: trigger_break=0;
! 1083: break;
! 1084: }
! 1085: zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
! 1086: }
! 1087: #endif
! 1088: }
! 1089:
! 1090: /* Bail out if we can't recover */
! 1091: switch (type) {
! 1092: case E_CORE_ERROR:
! 1093: if(!module_initialized) {
! 1094: /* bad error in module startup - no way we can live with this */
! 1095: exit(-2);
! 1096: }
! 1097: /* no break - intentionally */
! 1098: case E_ERROR:
! 1099: case E_RECOVERABLE_ERROR:
! 1100: case E_PARSE:
! 1101: case E_COMPILE_ERROR:
! 1102: case E_USER_ERROR:
! 1103: EG(exit_status) = 255;
! 1104: if (module_initialized) {
! 1105: if (!PG(display_errors) &&
! 1106: !SG(headers_sent) &&
! 1107: SG(sapi_headers).http_response_code == 200
! 1108: ) {
! 1109: sapi_header_line ctr = {0};
! 1110:
! 1111: ctr.line = "HTTP/1.0 500 Internal Server Error";
! 1112: ctr.line_len = strlen(ctr.line);
! 1113: sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
! 1114: }
! 1115: /* the parser would return 1 (failure), we can bail out nicely */
! 1116: if (type != E_PARSE) {
! 1117: /* restore memory limit */
! 1118: zend_set_memory_limit(PG(memory_limit));
! 1119: efree(buffer);
! 1120: zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
! 1121: zend_bailout();
! 1122: return;
! 1123: }
! 1124: }
! 1125: break;
! 1126: }
! 1127:
! 1128: /* Log if necessary */
! 1129: if (!display) {
! 1130: efree(buffer);
! 1131: return;
! 1132: }
! 1133:
! 1134: if (PG(track_errors) && module_initialized) {
! 1135: if (!EG(active_symbol_table)) {
! 1136: zend_rebuild_symbol_table(TSRMLS_C);
! 1137: }
! 1138: if (EG(active_symbol_table)) {
! 1139: zval *tmp;
! 1140: ALLOC_INIT_ZVAL(tmp);
! 1141: ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
! 1142: zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
! 1143: }
! 1144: }
! 1145:
! 1146: efree(buffer);
! 1147: }
! 1148: /* }}} */
! 1149:
! 1150: /* {{{ proto bool set_time_limit(int seconds)
! 1151: Sets the maximum time a script can run */
! 1152: PHP_FUNCTION(set_time_limit)
! 1153: {
! 1154: long new_timeout;
! 1155: char *new_timeout_str;
! 1156: int new_timeout_strlen;
! 1157:
! 1158: if (PG(safe_mode)) {
! 1159: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");
! 1160: RETURN_FALSE;
! 1161: }
! 1162:
! 1163: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) {
! 1164: return;
! 1165: }
! 1166:
! 1167: new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, "%ld", new_timeout);
! 1168:
! 1169: if (zend_alter_ini_entry_ex("max_execution_time", sizeof("max_execution_time"), new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) {
! 1170: RETVAL_TRUE;
! 1171: } else {
! 1172: RETVAL_FALSE;
! 1173: }
! 1174: efree(new_timeout_str);
! 1175: }
! 1176: /* }}} */
! 1177:
! 1178: /* {{{ php_fopen_wrapper_for_zend
! 1179: */
! 1180: static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path TSRMLS_DC)
! 1181: {
! 1182: 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);
! 1183: }
! 1184: /* }}} */
! 1185:
! 1186: static void php_zend_stream_closer(void *handle TSRMLS_DC) /* {{{ */
! 1187: {
! 1188: php_stream_close((php_stream*)handle);
! 1189: }
! 1190: /* }}} */
! 1191:
! 1192: static void php_zend_stream_mmap_closer(void *handle TSRMLS_DC) /* {{{ */
! 1193: {
! 1194: php_stream_mmap_unmap((php_stream*)handle);
! 1195: php_zend_stream_closer(handle TSRMLS_CC);
! 1196: }
! 1197: /* }}} */
! 1198:
! 1199: static size_t php_zend_stream_fsizer(void *handle TSRMLS_DC) /* {{{ */
! 1200: {
! 1201: php_stream_statbuf ssb;
! 1202: if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
! 1203: return ssb.sb.st_size;
! 1204: }
! 1205: return 0;
! 1206: }
! 1207: /* }}} */
! 1208:
! 1209: static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
! 1210: {
! 1211: return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
! 1212: }
! 1213: /* }}} */
! 1214:
! 1215: PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC) /* {{{ */
! 1216: {
! 1217: char *p;
! 1218: size_t len, mapped_len;
! 1219: php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
! 1220:
! 1221: if (stream) {
! 1222: #if HAVE_MMAP
! 1223: size_t page_size = REAL_PAGE_SIZE;
! 1224: #endif
! 1225:
! 1226: handle->filename = (char*)filename;
! 1227: handle->free_filename = 0;
! 1228: handle->handle.stream.handle = stream;
! 1229: handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
! 1230: handle->handle.stream.fsizer = php_zend_stream_fsizer;
! 1231: handle->handle.stream.isatty = 0;
! 1232: /* can we mmap immeadiately? */
! 1233: memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
! 1234: len = php_zend_stream_fsizer(stream TSRMLS_CC);
! 1235: if (len != 0
! 1236: #if HAVE_MMAP
! 1237: && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD
! 1238: #endif
! 1239: && php_stream_mmap_possible(stream)
! 1240: && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
! 1241: handle->handle.stream.closer = php_zend_stream_mmap_closer;
! 1242: handle->handle.stream.mmap.buf = p;
! 1243: handle->handle.stream.mmap.len = mapped_len;
! 1244: handle->type = ZEND_HANDLE_MAPPED;
! 1245: } else {
! 1246: handle->handle.stream.closer = php_zend_stream_closer;
! 1247: handle->type = ZEND_HANDLE_STREAM;
! 1248: }
! 1249: /* suppress warning if this stream is not explicitly closed */
! 1250: php_stream_auto_cleanup(stream);
! 1251:
! 1252: return SUCCESS;
! 1253: }
! 1254: return FAILURE;
! 1255: }
! 1256: /* }}} */
! 1257:
! 1258: static char *php_resolve_path_for_zend(const char *filename, int filename_len TSRMLS_DC) /* {{{ */
! 1259: {
! 1260: return php_resolve_path(filename, filename_len, PG(include_path) TSRMLS_CC);
! 1261: }
! 1262: /* }}} */
! 1263:
! 1264: /* {{{ php_get_configuration_directive_for_zend
! 1265: */
! 1266: static int php_get_configuration_directive_for_zend(const char *name, uint name_length, zval *contents)
! 1267: {
! 1268: zval *retval = cfg_get_entry(name, name_length);
! 1269:
! 1270: if (retval) {
! 1271: *contents = *retval;
! 1272: return SUCCESS;
! 1273: } else {
! 1274: return FAILURE;
! 1275: }
! 1276: }
! 1277: /* }}} */
! 1278:
! 1279: /* {{{ php_message_handler_for_zend
! 1280: */
! 1281: static void php_message_handler_for_zend(long message, void *data TSRMLS_DC)
! 1282: {
! 1283: switch (message) {
! 1284: case ZMSG_FAILED_INCLUDE_FOPEN:
! 1285: 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)));
! 1286: break;
! 1287: case ZMSG_FAILED_REQUIRE_FOPEN:
! 1288: 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)));
! 1289: break;
! 1290: case ZMSG_FAILED_HIGHLIGHT_FOPEN:
! 1291: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
! 1292: break;
! 1293: case ZMSG_MEMORY_LEAK_DETECTED:
! 1294: case ZMSG_MEMORY_LEAK_REPEATED:
! 1295: #if ZEND_DEBUG
! 1296: if (EG(error_reporting) & E_WARNING) {
! 1297: char memory_leak_buf[1024];
! 1298:
! 1299: if (message==ZMSG_MEMORY_LEAK_DETECTED) {
! 1300: zend_leak_info *t = (zend_leak_info *) data;
! 1301:
! 1302: snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", t->filename, t->lineno, (zend_uintptr_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
! 1303: if (t->orig_filename) {
! 1304: char relay_buf[512];
! 1305:
! 1306: snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
! 1307: strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
! 1308: }
! 1309: } else {
! 1310: unsigned long leak_count = (zend_uintptr_t) data;
! 1311:
! 1312: snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
! 1313: }
! 1314: # if defined(PHP_WIN32)
! 1315: OutputDebugString(memory_leak_buf);
! 1316: # else
! 1317: fprintf(stderr, "%s", memory_leak_buf);
! 1318: # endif
! 1319: }
! 1320: #endif
! 1321: break;
! 1322: case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
! 1323: #if ZEND_DEBUG
! 1324: if (EG(error_reporting) & E_WARNING) {
! 1325: char memory_leak_buf[512];
! 1326:
! 1327: snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data));
! 1328: # if defined(PHP_WIN32)
! 1329: OutputDebugString(memory_leak_buf);
! 1330: # else
! 1331: fprintf(stderr, "%s", memory_leak_buf);
! 1332: # endif
! 1333: }
! 1334: #endif
! 1335: break;
! 1336: case ZMSG_LOG_SCRIPT_NAME: {
! 1337: struct tm *ta, tmbuf;
! 1338: time_t curtime;
! 1339: char *datetime_str, asctimebuf[52];
! 1340: char memory_leak_buf[4096];
! 1341:
! 1342: time(&curtime);
! 1343: ta = php_localtime_r(&curtime, &tmbuf);
! 1344: datetime_str = php_asctime_r(ta, asctimebuf);
! 1345: if (datetime_str) {
! 1346: datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
! 1347: snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
! 1348: } else {
! 1349: snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null] Script: '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
! 1350: }
! 1351: # if defined(PHP_WIN32)
! 1352: OutputDebugString(memory_leak_buf);
! 1353: # else
! 1354: fprintf(stderr, "%s", memory_leak_buf);
! 1355: # endif
! 1356: }
! 1357: break;
! 1358: }
! 1359: }
! 1360: /* }}} */
! 1361:
! 1362:
! 1363: void php_on_timeout(int seconds TSRMLS_DC)
! 1364: {
! 1365: PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
! 1366: zend_set_timeout(EG(timeout_seconds), 1);
! 1367: if(PG(exit_on_timeout)) sapi_terminate_process(TSRMLS_C);
! 1368: }
! 1369:
! 1370: #if PHP_SIGCHILD
! 1371: /* {{{ sigchld_handler
! 1372: */
! 1373: static void sigchld_handler(int apar)
! 1374: {
! 1375: while (waitpid(-1, NULL, WNOHANG) > 0);
! 1376: signal(SIGCHLD, sigchld_handler);
! 1377: }
! 1378: /* }}} */
! 1379: #endif
! 1380:
! 1381: /* {{{ php_start_sapi()
! 1382: */
! 1383: static int php_start_sapi(TSRMLS_D)
! 1384: {
! 1385: int retval = SUCCESS;
! 1386:
! 1387: if(!SG(sapi_started)) {
! 1388: zend_try {
! 1389: PG(during_request_startup) = 1;
! 1390:
! 1391: /* initialize global variables */
! 1392: PG(modules_activated) = 0;
! 1393: PG(header_is_being_sent) = 0;
! 1394: PG(connection_status) = PHP_CONNECTION_NORMAL;
! 1395:
! 1396: zend_activate(TSRMLS_C);
! 1397: zend_set_timeout(EG(timeout_seconds), 1);
! 1398: zend_activate_modules(TSRMLS_C);
! 1399: PG(modules_activated)=1;
! 1400: } zend_catch {
! 1401: retval = FAILURE;
! 1402: } zend_end_try();
! 1403:
! 1404: SG(sapi_started) = 1;
! 1405: }
! 1406: return retval;
! 1407: }
! 1408:
! 1409: /* }}} */
! 1410:
! 1411: /* {{{ php_request_startup
! 1412: */
! 1413: #ifndef APACHE_HOOKS
! 1414: int php_request_startup(TSRMLS_D)
! 1415: {
! 1416: int retval = SUCCESS;
! 1417:
! 1418: #ifdef PHP_WIN32
! 1419: PG(com_initialized) = 0;
! 1420: #endif
! 1421:
! 1422: #if PHP_SIGCHILD
! 1423: signal(SIGCHLD, sigchld_handler);
! 1424: #endif
! 1425:
! 1426: zend_try {
! 1427: PG(in_error_log) = 0;
! 1428: PG(during_request_startup) = 1;
! 1429:
! 1430: php_output_activate(TSRMLS_C);
! 1431:
! 1432: /* initialize global variables */
! 1433: PG(modules_activated) = 0;
! 1434: PG(header_is_being_sent) = 0;
! 1435: PG(connection_status) = PHP_CONNECTION_NORMAL;
! 1436: PG(in_user_include) = 0;
! 1437:
! 1438: zend_activate(TSRMLS_C);
! 1439: sapi_activate(TSRMLS_C);
! 1440:
! 1441: if (PG(max_input_time) == -1) {
! 1442: zend_set_timeout(EG(timeout_seconds), 1);
! 1443: } else {
! 1444: zend_set_timeout(PG(max_input_time), 1);
! 1445: }
! 1446:
! 1447: /* Disable realpath cache if safe_mode or open_basedir are set */
! 1448: if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
! 1449: CWDG(realpath_cache_size_limit) = 0;
! 1450: }
! 1451:
! 1452: if (PG(expose_php)) {
! 1453: sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
! 1454: }
! 1455:
! 1456: if (PG(output_handler) && PG(output_handler)[0]) {
! 1457: php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
! 1458: } else if (PG(output_buffering)) {
! 1459: if (PG(output_buffering)>1) {
! 1460: php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC);
! 1461: } else {
! 1462: php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
! 1463: }
! 1464: } else if (PG(implicit_flush)) {
! 1465: php_start_implicit_flush(TSRMLS_C);
! 1466: }
! 1467:
! 1468: /* We turn this off in php_execute_script() */
! 1469: /* PG(during_request_startup) = 0; */
! 1470:
! 1471: php_hash_environment(TSRMLS_C);
! 1472: zend_activate_modules(TSRMLS_C);
! 1473: PG(modules_activated)=1;
! 1474: } zend_catch {
! 1475: retval = FAILURE;
! 1476: } zend_end_try();
! 1477:
! 1478: SG(sapi_started) = 1;
! 1479:
! 1480: return retval;
! 1481: }
! 1482: # else
! 1483: int php_request_startup(TSRMLS_D)
! 1484: {
! 1485: int retval = SUCCESS;
! 1486:
! 1487: #if PHP_SIGCHILD
! 1488: signal(SIGCHLD, sigchld_handler);
! 1489: #endif
! 1490:
! 1491: if (php_start_sapi() == FAILURE) {
! 1492: return FAILURE;
! 1493: }
! 1494:
! 1495: php_output_activate(TSRMLS_C);
! 1496: sapi_activate(TSRMLS_C);
! 1497: php_hash_environment(TSRMLS_C);
! 1498:
! 1499: zend_try {
! 1500: PG(during_request_startup) = 1;
! 1501: php_output_activate(TSRMLS_C);
! 1502: if (PG(expose_php)) {
! 1503: sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
! 1504: }
! 1505: } zend_catch {
! 1506: retval = FAILURE;
! 1507: } zend_end_try();
! 1508:
! 1509: return retval;
! 1510: }
! 1511: # endif
! 1512: /* }}} */
! 1513:
! 1514: /* {{{ php_request_startup_for_hook
! 1515: */
! 1516: int php_request_startup_for_hook(TSRMLS_D)
! 1517: {
! 1518: int retval = SUCCESS;
! 1519:
! 1520: #if PHP_SIGCHLD
! 1521: signal(SIGCHLD, sigchld_handler);
! 1522: #endif
! 1523:
! 1524: if (php_start_sapi(TSRMLS_C) == FAILURE) {
! 1525: return FAILURE;
! 1526: }
! 1527:
! 1528: php_output_activate(TSRMLS_C);
! 1529: sapi_activate_headers_only(TSRMLS_C);
! 1530: php_hash_environment(TSRMLS_C);
! 1531:
! 1532: return retval;
! 1533: }
! 1534: /* }}} */
! 1535:
! 1536: /* {{{ php_request_shutdown_for_exec
! 1537: */
! 1538: void php_request_shutdown_for_exec(void *dummy)
! 1539: {
! 1540: TSRMLS_FETCH();
! 1541:
! 1542: /* used to close fd's in the 3..255 range here, but it's problematic
! 1543: */
! 1544: shutdown_memory_manager(1, 1 TSRMLS_CC);
! 1545: }
! 1546: /* }}} */
! 1547:
! 1548: /* {{{ php_request_shutdown_for_hook
! 1549: */
! 1550: void php_request_shutdown_for_hook(void *dummy)
! 1551: {
! 1552: TSRMLS_FETCH();
! 1553:
! 1554: if (PG(modules_activated)) zend_try {
! 1555: php_call_shutdown_functions(TSRMLS_C);
! 1556: } zend_end_try();
! 1557:
! 1558: if (PG(modules_activated)) {
! 1559: zend_deactivate_modules(TSRMLS_C);
! 1560: php_free_shutdown_functions(TSRMLS_C);
! 1561: }
! 1562:
! 1563: zend_try {
! 1564: int i;
! 1565:
! 1566: for (i = 0; i < NUM_TRACK_VARS; i++) {
! 1567: if (PG(http_globals)[i]) {
! 1568: zval_ptr_dtor(&PG(http_globals)[i]);
! 1569: }
! 1570: }
! 1571: } zend_end_try();
! 1572:
! 1573: zend_deactivate(TSRMLS_C);
! 1574:
! 1575: zend_try {
! 1576: sapi_deactivate(TSRMLS_C);
! 1577: } zend_end_try();
! 1578:
! 1579: zend_try {
! 1580: php_shutdown_stream_hashes(TSRMLS_C);
! 1581: } zend_end_try();
! 1582:
! 1583: zend_try {
! 1584: shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
! 1585: } zend_end_try();
! 1586:
! 1587: zend_try {
! 1588: zend_unset_timeout(TSRMLS_C);
! 1589: } zend_end_try();
! 1590: }
! 1591:
! 1592: /* }}} */
! 1593:
! 1594: /* {{{ php_request_shutdown
! 1595: */
! 1596: void php_request_shutdown(void *dummy)
! 1597: {
! 1598: zend_bool report_memleaks;
! 1599: TSRMLS_FETCH();
! 1600:
! 1601: report_memleaks = PG(report_memleaks);
! 1602:
! 1603: /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
! 1604: * inside zend_executor callback functions.
! 1605: */
! 1606: EG(opline_ptr) = NULL;
! 1607: EG(active_op_array) = NULL;
! 1608:
! 1609: php_deactivate_ticks(TSRMLS_C);
! 1610:
! 1611: /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
! 1612: if (PG(modules_activated)) zend_try {
! 1613: php_call_shutdown_functions(TSRMLS_C);
! 1614: } zend_end_try();
! 1615:
! 1616: /* 2. Call all possible __destruct() functions */
! 1617: zend_try {
! 1618: zend_call_destructors(TSRMLS_C);
! 1619: } zend_end_try();
! 1620:
! 1621: /* 3. Flush all output buffers */
! 1622: zend_try {
! 1623: zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
! 1624: if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
! 1625: OG(ob_nesting_level) && !OG(active_ob_buffer).chunk_size && PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)) {
! 1626: send_buffer = 0;
! 1627: }
! 1628: php_end_ob_buffers(send_buffer TSRMLS_CC);
! 1629: } zend_end_try();
! 1630:
! 1631: /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
! 1632: zend_try {
! 1633: sapi_send_headers(TSRMLS_C);
! 1634: } zend_end_try();
! 1635:
! 1636: /* 5. Call all extensions RSHUTDOWN functions */
! 1637: if (PG(modules_activated)) {
! 1638: zend_deactivate_modules(TSRMLS_C);
! 1639: php_free_shutdown_functions(TSRMLS_C);
! 1640: }
! 1641:
! 1642: /* 6. Destroy super-globals */
! 1643: zend_try {
! 1644: int i;
! 1645:
! 1646: for (i=0; i<NUM_TRACK_VARS; i++) {
! 1647: if (PG(http_globals)[i]) {
! 1648: zval_ptr_dtor(&PG(http_globals)[i]);
! 1649: }
! 1650: }
! 1651: } zend_end_try();
! 1652:
! 1653: /* 6.5 free last error information */
! 1654: if (PG(last_error_message)) {
! 1655: free(PG(last_error_message));
! 1656: PG(last_error_message) = NULL;
! 1657: }
! 1658: if (PG(last_error_file)) {
! 1659: free(PG(last_error_file));
! 1660: PG(last_error_file) = NULL;
! 1661: }
! 1662:
! 1663: /* 7. Shutdown scanner/executor/compiler and restore ini entries */
! 1664: zend_deactivate(TSRMLS_C);
! 1665:
! 1666: /* 8. Call all extensions post-RSHUTDOWN functions */
! 1667: zend_try {
! 1668: zend_post_deactivate_modules(TSRMLS_C);
! 1669: } zend_end_try();
! 1670:
! 1671: /* 9. SAPI related shutdown (free stuff) */
! 1672: zend_try {
! 1673: sapi_deactivate(TSRMLS_C);
! 1674: } zend_end_try();
! 1675:
! 1676: /* 10. Destroy stream hashes */
! 1677: zend_try {
! 1678: php_shutdown_stream_hashes(TSRMLS_C);
! 1679: } zend_end_try();
! 1680:
! 1681: /* 11. Free Willy (here be crashes) */
! 1682: zend_try {
! 1683: shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
! 1684: } zend_end_try();
! 1685:
! 1686: /* 12. Reset max_execution_time */
! 1687: zend_try {
! 1688: zend_unset_timeout(TSRMLS_C);
! 1689: } zend_end_try();
! 1690:
! 1691: #ifdef PHP_WIN32
! 1692: if (PG(com_initialized)) {
! 1693: CoUninitialize();
! 1694: PG(com_initialized) = 0;
! 1695: }
! 1696: #endif
! 1697: }
! 1698: /* }}} */
! 1699:
! 1700: /* {{{ php_com_initialize
! 1701: */
! 1702: PHPAPI void php_com_initialize(TSRMLS_D)
! 1703: {
! 1704: #ifdef PHP_WIN32
! 1705: if (!PG(com_initialized)) {
! 1706: if (CoInitialize(NULL) == S_OK) {
! 1707: PG(com_initialized) = 1;
! 1708: }
! 1709: }
! 1710: #endif
! 1711: }
! 1712: /* }}} */
! 1713:
! 1714: /* {{{ php_body_write_wrapper
! 1715: */
! 1716: static int php_body_write_wrapper(const char *str, uint str_length)
! 1717: {
! 1718: TSRMLS_FETCH();
! 1719: return php_body_write(str, str_length TSRMLS_CC);
! 1720: }
! 1721: /* }}} */
! 1722:
! 1723: #ifdef ZTS
! 1724: /* {{{ core_globals_ctor
! 1725: */
! 1726: static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
! 1727: {
! 1728: memset(core_globals, 0, sizeof(*core_globals));
! 1729:
! 1730: php_startup_ticks(TSRMLS_C);
! 1731: }
! 1732: /* }}} */
! 1733: #endif
! 1734:
! 1735: /* {{{ core_globals_dtor
! 1736: */
! 1737: static void core_globals_dtor(php_core_globals *core_globals TSRMLS_DC)
! 1738: {
! 1739: if (core_globals->last_error_message) {
! 1740: free(core_globals->last_error_message);
! 1741: }
! 1742: if (core_globals->last_error_file) {
! 1743: free(core_globals->last_error_file);
! 1744: }
! 1745: if (core_globals->disable_functions) {
! 1746: free(core_globals->disable_functions);
! 1747: }
! 1748: if (core_globals->disable_classes) {
! 1749: free(core_globals->disable_classes);
! 1750: }
! 1751:
! 1752: php_shutdown_ticks(TSRMLS_C);
! 1753: }
! 1754: /* }}} */
! 1755:
! 1756: PHP_MINFO_FUNCTION(php_core) { /* {{{ */
! 1757: php_info_print_table_start();
! 1758: php_info_print_table_row(2, "PHP Version", PHP_VERSION);
! 1759: php_info_print_table_end();
! 1760: DISPLAY_INI_ENTRIES();
! 1761: }
! 1762: /* }}} */
! 1763:
! 1764: /* {{{ php_register_extensions
! 1765: */
! 1766: int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
! 1767: {
! 1768: zend_module_entry **end = ptr + count;
! 1769:
! 1770: while (ptr < end) {
! 1771: if (*ptr) {
! 1772: if (zend_register_internal_module(*ptr TSRMLS_CC)==NULL) {
! 1773: return FAILURE;
! 1774: }
! 1775: }
! 1776: ptr++;
! 1777: }
! 1778: return SUCCESS;
! 1779: }
! 1780: /* }}} */
! 1781:
! 1782: #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
! 1783: static _invalid_parameter_handler old_invalid_parameter_handler;
! 1784:
! 1785: void dummy_invalid_parameter_handler(
! 1786: const wchar_t *expression,
! 1787: const wchar_t *function,
! 1788: const wchar_t *file,
! 1789: unsigned int line,
! 1790: uintptr_t pEwserved)
! 1791: {
! 1792: static int called = 0;
! 1793: char buf[1024];
! 1794: int len;
! 1795:
! 1796: if (!called) {
! 1797: TSRMLS_FETCH();
! 1798: if(PG(windows_show_crt_warning)) {
! 1799: called = 1;
! 1800: if (function) {
! 1801: if (file) {
! 1802: len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line);
! 1803: } else {
! 1804: len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
! 1805: }
! 1806: } else {
! 1807: len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameter detected (function not known)");
! 1808: }
! 1809: zend_error(E_WARNING, "%s", buf);
! 1810: called = 0;
! 1811: }
! 1812: }
! 1813: }
! 1814: #endif
! 1815:
! 1816: #if SUHOSIN_PATCH
! 1817: PHPAPI void suhosin_startup();
! 1818: #endif
! 1819:
! 1820: /* {{{ php_module_startup
! 1821: */
! 1822: int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
! 1823: {
! 1824: zend_utility_functions zuf;
! 1825: zend_utility_values zuv;
! 1826: int module_number=0; /* for REGISTER_INI_ENTRIES() */
! 1827: char *php_os;
! 1828: zend_module_entry *module;
! 1829: #ifdef ZTS
! 1830: zend_executor_globals *executor_globals;
! 1831: void ***tsrm_ls;
! 1832: php_core_globals *core_globals;
! 1833: #endif
! 1834: #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
! 1835: WORD wVersionRequested = MAKEWORD(2, 0);
! 1836: WSADATA wsaData;
! 1837: #endif
! 1838: #ifdef PHP_WIN32
! 1839: DWORD dwVersion = GetVersion();
! 1840: /* Get build numbers for Windows NT or Win95 */
! 1841: if (dwVersion < 0x80000000){
! 1842: php_os="WINNT";
! 1843: } else {
! 1844: php_os="WIN32";
! 1845: }
! 1846: #if defined(_MSC_VER) && (_MSC_VER >= 1400)
! 1847: old_invalid_parameter_handler =
! 1848: _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
! 1849: if (old_invalid_parameter_handler != NULL) {
! 1850: _set_invalid_parameter_handler(old_invalid_parameter_handler);
! 1851: }
! 1852:
! 1853: /* Disable the message box for assertions.*/
! 1854: _CrtSetReportMode(_CRT_ASSERT, 0);
! 1855: #endif
! 1856: #else
! 1857: php_os=PHP_OS;
! 1858: #endif
! 1859:
! 1860: #ifdef ZTS
! 1861: tsrm_ls = ts_resource(0);
! 1862: #endif
! 1863:
! 1864: #ifdef PHP_WIN32
! 1865: php_win32_init_rng_lock();
! 1866: #endif
! 1867:
! 1868: #if SUHOSIN_PATCH
! 1869: suhosin_startup();
! 1870: #endif
! 1871:
! 1872: module_shutdown = 0;
! 1873: module_startup = 1;
! 1874: sapi_initialize_empty_request(TSRMLS_C);
! 1875: sapi_activate(TSRMLS_C);
! 1876:
! 1877: if (module_initialized) {
! 1878: return SUCCESS;
! 1879: }
! 1880:
! 1881: sapi_module = *sf;
! 1882:
! 1883: php_output_startup();
! 1884:
! 1885: zuf.error_function = php_error_cb;
! 1886: zuf.printf_function = php_printf;
! 1887: zuf.write_function = php_body_write_wrapper;
! 1888: zuf.fopen_function = php_fopen_wrapper_for_zend;
! 1889: zuf.message_handler = php_message_handler_for_zend;
! 1890: zuf.block_interruptions = sapi_module.block_interruptions;
! 1891: zuf.unblock_interruptions = sapi_module.unblock_interruptions;
! 1892: zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
! 1893: zuf.ticks_function = php_run_ticks;
! 1894: zuf.on_timeout = php_on_timeout;
! 1895: zuf.stream_open_function = php_stream_open_for_zend;
! 1896: zuf.vspprintf_function = vspprintf;
! 1897: zuf.getenv_function = sapi_getenv;
! 1898: zuf.resolve_path_function = php_resolve_path_for_zend;
! 1899: zend_startup(&zuf, NULL TSRMLS_CC);
! 1900:
! 1901: #ifdef ZTS
! 1902: executor_globals = ts_resource(executor_globals_id);
! 1903: ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
! 1904: core_globals = ts_resource(core_globals_id);
! 1905: #ifdef PHP_WIN32
! 1906: ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
! 1907: #endif
! 1908: #else
! 1909: php_startup_ticks(TSRMLS_C);
! 1910: #endif
! 1911: gc_globals_ctor(TSRMLS_C);
! 1912:
! 1913: #ifdef PHP_WIN32
! 1914: {
! 1915: OSVERSIONINFOEX *osvi = &EG(windows_version_info);
! 1916:
! 1917: ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
! 1918: osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
! 1919: if( !GetVersionEx((OSVERSIONINFO *) osvi)) {
! 1920: php_printf("\nGetVersionEx unusable. %d\n", GetLastError());
! 1921: return FAILURE;
! 1922: }
! 1923: }
! 1924: #endif
! 1925: EG(bailout) = NULL;
! 1926: EG(error_reporting) = E_ALL & ~E_NOTICE;
! 1927: EG(active_symbol_table) = NULL;
! 1928: PG(header_is_being_sent) = 0;
! 1929: SG(request_info).headers_only = 0;
! 1930: SG(request_info).argv0 = NULL;
! 1931: SG(request_info).argc=0;
! 1932: SG(request_info).argv=(char **)NULL;
! 1933: PG(connection_status) = PHP_CONNECTION_NORMAL;
! 1934: PG(during_request_startup) = 0;
! 1935: PG(last_error_message) = NULL;
! 1936: PG(last_error_file) = NULL;
! 1937: PG(last_error_lineno) = 0;
! 1938: EG(error_handling) = EH_NORMAL;
! 1939: EG(exception_class) = NULL;
! 1940: PG(disable_functions) = NULL;
! 1941: PG(disable_classes) = NULL;
! 1942:
! 1943: #if HAVE_SETLOCALE
! 1944: setlocale(LC_CTYPE, "");
! 1945: zend_update_current_locale();
! 1946: #endif
! 1947:
! 1948: #if HAVE_TZSET
! 1949: tzset();
! 1950: #endif
! 1951:
! 1952: #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
! 1953: /* start up winsock services */
! 1954: if (WSAStartup(wVersionRequested, &wsaData) != 0) {
! 1955: php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
! 1956: return FAILURE;
! 1957: }
! 1958: #endif
! 1959:
! 1960: le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
! 1961:
! 1962: /* Register constants */
! 1963: REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
! 1964: REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
! 1965: REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
! 1966: REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
! 1967: REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
! 1968: REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
! 1969: #ifdef ZTS
! 1970: REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
! 1971: #else
! 1972: REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
! 1973: #endif
! 1974: REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
! 1975: REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
! 1976: REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
! 1977: REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
! 1978: REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1979: REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
! 1980: REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
! 1981: REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
! 1982: REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1983: #ifndef PHP_WIN32
! 1984: REGISTER_MAIN_STRINGL_CONSTANT("PHP_MANDIR", PHP_MANDIR, sizeof(PHP_MANDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1985: #endif
! 1986: REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1987: REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
! 1988: REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1989: REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
! 1990: REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
! 1991: 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);
! 1992: REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
! 1993: REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
! 1994: #if SUHOSIN_PATCH
! 1995: REGISTER_MAIN_LONG_CONSTANT("SUHOSIN_PATCH", 1, CONST_PERSISTENT | CONST_CS);
! 1996: REGISTER_MAIN_STRINGL_CONSTANT("SUHOSIN_PATCH_VERSION", SUHOSIN_PATCH_VERSION, sizeof(SUHOSIN_PATCH_VERSION)-1, CONST_PERSISTENT | CONST_CS);
! 1997: #endif
! 1998: REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
! 1999: REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
! 2000: REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
! 2001: #ifdef ZEND_MULTIBYTE
! 2002: REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 1, CONST_PERSISTENT | CONST_CS);
! 2003: #else
! 2004: REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 0, CONST_PERSISTENT | CONST_CS);
! 2005: #endif
! 2006:
! 2007: #ifdef PHP_WIN32
! 2008: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
! 2009: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR", EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
! 2010: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD", EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
! 2011: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM", EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
! 2012: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR", EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
! 2013: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR", EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
! 2014: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK", EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
! 2015: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
! 2016: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
! 2017: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
! 2018: REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
! 2019: #endif
! 2020:
! 2021: php_output_register_constants(TSRMLS_C);
! 2022: php_rfc1867_register_constants(TSRMLS_C);
! 2023:
! 2024: /* this will read in php.ini, set up the configuration parameters,
! 2025: load zend extensions and register php function extensions
! 2026: to be loaded later */
! 2027: if (php_init_config(TSRMLS_C) == FAILURE) {
! 2028: return FAILURE;
! 2029: }
! 2030:
! 2031: /* Register PHP core ini entries */
! 2032: REGISTER_INI_ENTRIES();
! 2033:
! 2034: /* Register Zend ini entries */
! 2035: zend_register_standard_ini_entries(TSRMLS_C);
! 2036:
! 2037: /* Disable realpath cache if safe_mode or open_basedir are set */
! 2038: if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
! 2039: CWDG(realpath_cache_size_limit) = 0;
! 2040: }
! 2041:
! 2042: /* initialize stream wrappers registry
! 2043: * (this uses configuration parameters from php.ini)
! 2044: */
! 2045: if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE) {
! 2046: php_printf("PHP: Unable to initialize stream url wrappers.\n");
! 2047: return FAILURE;
! 2048: }
! 2049:
! 2050: /* initialize registry for images to be used in phpinfo()
! 2051: (this uses configuration parameters from php.ini)
! 2052: */
! 2053: if (php_init_info_logos() == FAILURE) {
! 2054: php_printf("PHP: Unable to initialize info phpinfo logos.\n");
! 2055: return FAILURE;
! 2056: }
! 2057:
! 2058: zuv.html_errors = 1;
! 2059: zuv.import_use_extension = ".php";
! 2060: php_startup_auto_globals(TSRMLS_C);
! 2061: zend_set_utility_values(&zuv);
! 2062: php_startup_sapi_content_types(TSRMLS_C);
! 2063:
! 2064: /* startup extensions staticly compiled in */
! 2065: if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) {
! 2066: php_printf("Unable to start builtin modules\n");
! 2067: return FAILURE;
! 2068: }
! 2069:
! 2070: /* start additional PHP extensions */
! 2071: php_register_extensions(&additional_modules, num_additional_modules TSRMLS_CC);
! 2072:
! 2073: /* load and startup extensions compiled as shared objects (aka DLLs)
! 2074: as requested by php.ini entries
! 2075: theese are loaded after initialization of internal extensions
! 2076: as extensions *might* rely on things from ext/standard
! 2077: which is always an internal extension and to be initialized
! 2078: ahead of all other internals
! 2079: */
! 2080: php_ini_register_extensions(TSRMLS_C);
! 2081: zend_startup_modules(TSRMLS_C);
! 2082:
! 2083: /* start Zend extensions */
! 2084: zend_startup_extensions();
! 2085:
! 2086: /* register additional functions */
! 2087: if (sapi_module.additional_functions) {
! 2088: if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {
! 2089: EG(current_module) = module;
! 2090: zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT TSRMLS_CC);
! 2091: EG(current_module) = NULL;
! 2092: }
! 2093: }
! 2094:
! 2095: /* disable certain classes and functions as requested by php.ini */
! 2096: php_disable_functions(TSRMLS_C);
! 2097: php_disable_classes(TSRMLS_C);
! 2098:
! 2099: /* make core report what it should */
! 2100: if (zend_hash_find(&module_registry, "core", sizeof("core"), (void**)&module)==SUCCESS) {
! 2101: module->version = PHP_VERSION;
! 2102: module->info_func = PHP_MINFO(php_core);
! 2103: }
! 2104:
! 2105:
! 2106: #ifdef PHP_WIN32
! 2107: /* Disable incompatible functions for the running platform */
! 2108: if (php_win32_disable_functions() == FAILURE) {
! 2109: php_printf("Unable to disable unsupported functions\n");
! 2110: return FAILURE;
! 2111: }
! 2112: #endif
! 2113:
! 2114: #ifdef ZTS
! 2115: zend_post_startup(TSRMLS_C);
! 2116: #endif
! 2117:
! 2118: module_initialized = 1;
! 2119:
! 2120: /* Check for deprecated directives */
! 2121: /* NOTE: If you add anything here, remember to add it also in Makefile.global! */
! 2122: {
! 2123: static const char *directives[] = {
! 2124: "define_syslog_variables",
! 2125: "register_globals",
! 2126: "register_long_arrays",
! 2127: "safe_mode",
! 2128: "magic_quotes_gpc",
! 2129: "magic_quotes_runtime",
! 2130: "magic_quotes_sybase",
! 2131: NULL
! 2132: };
! 2133: const char **p = directives;
! 2134: long val;
! 2135:
! 2136: while (*p) {
! 2137: if (cfg_get_long((char*)*p, &val) == SUCCESS && val) {
! 2138: zend_error(E_DEPRECATED, "Directive '%s' is deprecated in PHP 5.3 and greater", *p);
! 2139: }
! 2140: ++p;
! 2141: }
! 2142:
! 2143: /* This is not too nice, but since its the only one theres no need for extra stuff here */
! 2144: if (cfg_get_long("zend.ze1_compatibility_mode", &val) == SUCCESS && val) {
! 2145: zend_error(E_CORE_ERROR, "zend.ze1_compatibility_mode is no longer supported in PHP 5.3 and greater");
! 2146: }
! 2147: }
! 2148:
! 2149: sapi_deactivate(TSRMLS_C);
! 2150: module_startup = 0;
! 2151:
! 2152: shutdown_memory_manager(1, 0 TSRMLS_CC);
! 2153:
! 2154: /* we're done */
! 2155: return SUCCESS;
! 2156: }
! 2157: /* }}} */
! 2158:
! 2159: void php_module_shutdown_for_exec(void)
! 2160: {
! 2161: /* used to close fd's in the range 3.255 here, but it's problematic */
! 2162: }
! 2163:
! 2164: /* {{{ php_module_shutdown_wrapper
! 2165: */
! 2166: int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
! 2167: {
! 2168: TSRMLS_FETCH();
! 2169: php_module_shutdown(TSRMLS_C);
! 2170: return SUCCESS;
! 2171: }
! 2172: /* }}} */
! 2173:
! 2174: /* {{{ php_module_shutdown
! 2175: */
! 2176: void php_module_shutdown(TSRMLS_D)
! 2177: {
! 2178: int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
! 2179:
! 2180: module_shutdown = 1;
! 2181:
! 2182: if (!module_initialized) {
! 2183: return;
! 2184: }
! 2185:
! 2186: #ifdef ZTS
! 2187: ts_free_worker_threads();
! 2188: #endif
! 2189:
! 2190: #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
! 2191: /*close winsock */
! 2192: WSACleanup();
! 2193: #endif
! 2194:
! 2195: #ifdef PHP_WIN32
! 2196: php_win32_free_rng_lock();
! 2197: #endif
! 2198:
! 2199: sapi_flush(TSRMLS_C);
! 2200:
! 2201: zend_shutdown(TSRMLS_C);
! 2202:
! 2203: /* Destroys filter & transport registries too */
! 2204: php_shutdown_stream_wrappers(module_number TSRMLS_CC);
! 2205:
! 2206: php_shutdown_info_logos();
! 2207: UNREGISTER_INI_ENTRIES();
! 2208:
! 2209: /* close down the ini config */
! 2210: php_shutdown_config();
! 2211:
! 2212: #ifndef ZTS
! 2213: zend_ini_shutdown(TSRMLS_C);
! 2214: shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
! 2215: core_globals_dtor(&core_globals TSRMLS_CC);
! 2216: gc_globals_dtor(TSRMLS_C);
! 2217: #else
! 2218: zend_ini_global_shutdown(TSRMLS_C);
! 2219: ts_free_id(core_globals_id);
! 2220: #endif
! 2221:
! 2222: php_shutdown_temporary_directory();
! 2223:
! 2224: module_initialized = 0;
! 2225:
! 2226: #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
! 2227: if (old_invalid_parameter_handler == NULL) {
! 2228: _set_invalid_parameter_handler(old_invalid_parameter_handler);
! 2229: }
! 2230: #endif
! 2231: }
! 2232: /* }}} */
! 2233:
! 2234: /* {{{ php_execute_script
! 2235: */
! 2236: PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
! 2237: {
! 2238: zend_file_handle *prepend_file_p, *append_file_p;
! 2239: zend_file_handle prepend_file = {0}, append_file = {0};
! 2240: #if HAVE_BROKEN_GETCWD
! 2241: int old_cwd_fd = -1;
! 2242: #else
! 2243: char *old_cwd;
! 2244: ALLOCA_FLAG(use_heap)
! 2245: #endif
! 2246: int retval = 0;
! 2247:
! 2248: EG(exit_status) = 0;
! 2249: if (php_handle_special_queries(TSRMLS_C)) {
! 2250: zend_file_handle_dtor(primary_file TSRMLS_CC);
! 2251: return 0;
! 2252: }
! 2253: #ifndef HAVE_BROKEN_GETCWD
! 2254: # define OLD_CWD_SIZE 4096
! 2255: old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
! 2256: old_cwd[0] = '\0';
! 2257: #endif
! 2258:
! 2259: zend_try {
! 2260: char realfile[MAXPATHLEN];
! 2261:
! 2262: #ifdef PHP_WIN32
! 2263: if(primary_file->filename) {
! 2264: UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
! 2265: }
! 2266: #endif
! 2267:
! 2268: PG(during_request_startup) = 0;
! 2269:
! 2270: if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
! 2271: #if HAVE_BROKEN_GETCWD
! 2272: /* this looks nasty to me */
! 2273: old_cwd_fd = open(".", 0);
! 2274: #else
! 2275: VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
! 2276: #endif
! 2277: VCWD_CHDIR_FILE(primary_file->filename);
! 2278: }
! 2279:
! 2280: /* Only lookup the real file path and add it to the included_files list if already opened
! 2281: * otherwise it will get opened and added to the included_files list in zend_execute_scripts
! 2282: */
! 2283: if (primary_file->filename &&
! 2284: (primary_file->filename[0] != '-' || primary_file->filename[1] != 0) &&
! 2285: primary_file->opened_path == NULL &&
! 2286: primary_file->type != ZEND_HANDLE_FILENAME
! 2287: ) {
! 2288: int realfile_len;
! 2289: int dummy = 1;
! 2290:
! 2291: if (expand_filepath(primary_file->filename, realfile TSRMLS_CC)) {
! 2292: realfile_len = strlen(realfile);
! 2293: zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL);
! 2294: primary_file->opened_path = estrndup(realfile, realfile_len);
! 2295: }
! 2296: }
! 2297:
! 2298: if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
! 2299: prepend_file.filename = PG(auto_prepend_file);
! 2300: prepend_file.opened_path = NULL;
! 2301: prepend_file.free_filename = 0;
! 2302: prepend_file.type = ZEND_HANDLE_FILENAME;
! 2303: prepend_file_p = &prepend_file;
! 2304: } else {
! 2305: prepend_file_p = NULL;
! 2306: }
! 2307:
! 2308: if (PG(auto_append_file) && PG(auto_append_file)[0]) {
! 2309: append_file.filename = PG(auto_append_file);
! 2310: append_file.opened_path = NULL;
! 2311: append_file.free_filename = 0;
! 2312: append_file.type = ZEND_HANDLE_FILENAME;
! 2313: append_file_p = &append_file;
! 2314: } else {
! 2315: append_file_p = NULL;
! 2316: }
! 2317: if (PG(max_input_time) != -1) {
! 2318: #ifdef PHP_WIN32
! 2319: zend_unset_timeout(TSRMLS_C);
! 2320: #endif
! 2321: zend_set_timeout(INI_INT("max_execution_time"), 0);
! 2322: }
! 2323: retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
! 2324:
! 2325: } zend_end_try();
! 2326:
! 2327: #if HAVE_BROKEN_GETCWD
! 2328: if (old_cwd_fd != -1) {
! 2329: fchdir(old_cwd_fd);
! 2330: close(old_cwd_fd);
! 2331: }
! 2332: #else
! 2333: if (old_cwd[0] != '\0') {
! 2334: VCWD_CHDIR(old_cwd);
! 2335: }
! 2336: free_alloca(old_cwd, use_heap);
! 2337: #endif
! 2338: return retval;
! 2339: }
! 2340: /* }}} */
! 2341:
! 2342: /* {{{ php_execute_simple_script
! 2343: */
! 2344: PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
! 2345: {
! 2346: char *old_cwd;
! 2347: ALLOCA_FLAG(use_heap)
! 2348:
! 2349: EG(exit_status) = 0;
! 2350: #define OLD_CWD_SIZE 4096
! 2351: old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
! 2352: old_cwd[0] = '\0';
! 2353:
! 2354: zend_try {
! 2355: #ifdef PHP_WIN32
! 2356: if(primary_file->filename) {
! 2357: UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
! 2358: }
! 2359: #endif
! 2360:
! 2361: PG(during_request_startup) = 0;
! 2362:
! 2363: if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
! 2364: VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
! 2365: VCWD_CHDIR_FILE(primary_file->filename);
! 2366: }
! 2367: zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
! 2368: } zend_end_try();
! 2369:
! 2370: if (old_cwd[0] != '\0') {
! 2371: VCWD_CHDIR(old_cwd);
! 2372: }
! 2373:
! 2374: free_alloca(old_cwd, use_heap);
! 2375: return EG(exit_status);
! 2376: }
! 2377: /* }}} */
! 2378:
! 2379: /* {{{ php_handle_aborted_connection
! 2380: */
! 2381: PHPAPI void php_handle_aborted_connection(void)
! 2382: {
! 2383: TSRMLS_FETCH();
! 2384:
! 2385: PG(connection_status) = PHP_CONNECTION_ABORTED;
! 2386: php_output_set_status(0 TSRMLS_CC);
! 2387:
! 2388: if (!PG(ignore_user_abort)) {
! 2389: zend_bailout();
! 2390: }
! 2391: }
! 2392: /* }}} */
! 2393:
! 2394: /* {{{ php_handle_auth_data
! 2395: */
! 2396: PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
! 2397: {
! 2398: int ret = -1;
! 2399:
! 2400: if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
! 2401: char *pass;
! 2402: char *user;
! 2403:
! 2404: user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL);
! 2405: if (user) {
! 2406: pass = strchr(user, ':');
! 2407: if (pass) {
! 2408: *pass++ = '\0';
! 2409: SG(request_info).auth_user = user;
! 2410: SG(request_info).auth_password = estrdup(pass);
! 2411: ret = 0;
! 2412: } else {
! 2413: efree(user);
! 2414: }
! 2415: }
! 2416: }
! 2417:
! 2418: if (ret == -1) {
! 2419: SG(request_info).auth_user = SG(request_info).auth_password = NULL;
! 2420: } else {
! 2421: SG(request_info).auth_digest = NULL;
! 2422: }
! 2423:
! 2424: if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
! 2425: SG(request_info).auth_digest = estrdup(auth + 7);
! 2426: ret = 0;
! 2427: }
! 2428:
! 2429: if (ret == -1) {
! 2430: SG(request_info).auth_digest = NULL;
! 2431: }
! 2432:
! 2433: return ret;
! 2434: }
! 2435: /* }}} */
! 2436:
! 2437: /* {{{ php_lint_script
! 2438: */
! 2439: PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
! 2440: {
! 2441: zend_op_array *op_array;
! 2442: int retval = FAILURE;
! 2443:
! 2444: zend_try {
! 2445: op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
! 2446: zend_destroy_file_handle(file TSRMLS_CC);
! 2447:
! 2448: if (op_array) {
! 2449: destroy_op_array(op_array TSRMLS_CC);
! 2450: efree(op_array);
! 2451: retval = SUCCESS;
! 2452: }
! 2453: } zend_end_try();
! 2454:
! 2455: return retval;
! 2456: }
! 2457: /* }}} */
! 2458:
! 2459: #ifdef PHP_WIN32
! 2460: /* {{{ dummy_indent
! 2461: just so that this symbol gets exported... */
! 2462: PHPAPI void dummy_indent(void)
! 2463: {
! 2464: zend_indent();
! 2465: }
! 2466: /* }}} */
! 2467: #endif
! 2468:
! 2469: /*
! 2470: * Local variables:
! 2471: * tab-width: 4
! 2472: * c-basic-offset: 4
! 2473: * End:
! 2474: * vim600: sw=4 ts=4 fdm=marker
! 2475: * vim<600: sw=4 ts=4
! 2476: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>