File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / main / main.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:35 2012 UTC (12 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_17p0, HEAD
php 5.4.3+patches

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>