2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 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_0.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
+----------------------------------------------------------------------+
21
/* $Id: main.c,v 1.604.2.22 2005/08/16 18:11:34 helly Exp $ */
26
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
31
#include "win32/time.h"
32
#include "win32/signal.h"
34
#elif defined(NETWARE)
35
#include <sys/timeval.h>
53
#include "zend_extensions.h"
55
#include "php_globals.h"
57
#include "fopen_wrappers.h"
58
#include "ext/standard/php_standard.h"
59
#include "php_variables.h"
60
#include "ext/standard/credits.h"
64
#include "win32/php_registry.h"
66
#include "php_syslog.h"
67
#include "Zend/zend_exceptions.h"
70
#include <sys/types.h>
74
#include "zend_compile.h"
75
#include "zend_execute.h"
76
#include "zend_highlight.h"
77
#include "zend_indent.h"
78
#include "zend_extensions.h"
81
#include "php_content_types.h"
82
#include "php_ticks.h"
83
#include "php_logos.h"
84
#include "php_streams.h"
91
php_core_globals core_globals;
93
PHPAPI int core_globals_id;
96
#define SAFE_FILENAME(f) ((f)?(f):"-")
100
static PHP_INI_MH(OnSetPrecision)
102
EG(precision) = atoi(new_value);
110
static PHP_INI_MH(OnChangeMemoryLimit)
113
PG(memory_limit) = zend_atoi(new_value, new_value_length);
115
PG(memory_limit) = 1<<30; /* effectively, no limit */
117
return zend_set_memory_limit(PG(memory_limit));
123
/* {{{ php_disable_functions
125
static void php_disable_functions(TSRMLS_D)
129
if (!*(INI_STR("disable_functions"))) {
133
e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
141
zend_disable_function(s, e-s TSRMLS_CC);
154
zend_disable_function(s, e-s TSRMLS_CC);
159
/* {{{ php_disable_classes
161
static void php_disable_classes(TSRMLS_D)
165
if (!*(INI_STR("disable_classes"))) {
169
e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
177
zend_disable_class(s, e-s TSRMLS_CC);
190
zend_disable_class(s, e-s TSRMLS_CC);
197
static PHP_INI_MH(OnUpdateTimeout)
199
EG(timeout_seconds) = atoi(new_value);
200
if (stage==PHP_INI_STAGE_STARTUP) {
201
/* Don't set a timeout on startup, only per-request */
204
zend_unset_timeout(TSRMLS_C);
205
zend_set_timeout(EG(timeout_seconds));
210
/* Need to convert to strings and make use of:
213
* Need to be read from the environment (?):
214
* PHP_AUTO_PREPEND_FILE
215
* PHP_AUTO_APPEND_FILE
221
#ifndef PHP_SAFE_MODE_EXEC_DIR
222
# define PHP_SAFE_MODE_EXEC_DIR ""
225
#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)
226
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
228
# define DEFAULT_SENDMAIL_PATH NULL
233
PHP_INI_ENTRY_EX("define_syslog_variables", "0", PHP_INI_ALL, NULL, php_ini_boolean_displayer_cb)
234
PHP_INI_ENTRY_EX("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
235
PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
236
PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
237
PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
238
PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
239
PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
241
STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_call_time_pass_reference, zend_compiler_globals, compiler_globals)
242
STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals)
243
STD_PHP_INI_BOOLEAN("display_errors", "1", PHP_INI_ALL, OnUpdateBool, display_errors, php_core_globals, core_globals)
244
STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
245
STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
246
STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
247
STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
248
STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
249
STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
250
STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
251
STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
252
STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
253
STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
254
STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
255
STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
256
STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
257
STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
258
STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
259
STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
260
STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
261
STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals)
262
STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals)
263
STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals)
264
STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
265
STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
266
STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
267
STD_PHP_INI_BOOLEAN("register_globals", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_globals, php_core_globals, core_globals)
268
STD_PHP_INI_BOOLEAN("register_long_arrays", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays, php_core_globals, core_globals)
269
STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
271
STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
273
STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
275
STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals)
276
STD_PHP_INI_BOOLEAN("safe_mode_gid", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode_gid, php_core_globals, core_globals)
277
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)
278
STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
279
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
280
STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
282
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
283
STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLong, serialize_precision, php_core_globals, core_globals)
284
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
285
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
287
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
288
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
289
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
290
STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct,sapi_globals)
291
STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct,sapi_globals)
292
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateString, error_log, php_core_globals, core_globals)
293
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
294
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
295
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
296
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateString, open_basedir, php_core_globals, core_globals)
297
STD_PHP_INI_ENTRY("safe_mode_exec_dir", PHP_SAFE_MODE_EXEC_DIR, PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals)
299
STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
300
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
301
STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
302
STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
304
STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
305
STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_ALL, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
307
STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
308
STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
310
PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
311
PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
312
PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL)
314
PHP_INI_ENTRY("memory_limit", "8M", PHP_INI_ALL, OnChangeMemoryLimit)
316
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
317
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
318
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
319
PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
320
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
321
PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
323
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
324
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)
329
/* True globals (no need for thread safety */
330
/* But don't make them a single int bitfield */
331
static int module_initialized = 0;
332
static int module_startup = 1;
333
static int module_shutdown = 0;
337
PHPAPI void php_log_err(char *log_message TSRMLS_DC)
340
char error_time_str[128];
344
/* Try to use the specified logging location. */
345
if (PG(error_log) != NULL) {
347
if (!strcmp(PG(error_log), "syslog")) {
348
php_syslog(LOG_NOTICE, "%.500s", log_message);
352
log_file = VCWD_FOPEN(PG(error_log), "a");
353
if (log_file != NULL) {
355
strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
356
fprintf(log_file, "[%s] ", error_time_str);
357
fprintf(log_file, "%s", log_message);
358
fprintf(log_file, "%s", PHP_EOL);
364
/* Otherwise fall back to the default logging location, if we have one */
366
if (sapi_module.log_message) {
367
sapi_module.log_message(log_message);
373
wrapper for modules to use PHPWRITE */
374
PHPAPI int php_write(void *buf, uint size TSRMLS_DC)
376
return PHPWRITE(buf, size);
382
PHPAPI int php_printf(const char *format, ...)
390
va_start(args, format);
391
size = vspprintf(&buffer, 0, format, args);
392
ret = PHPWRITE(buffer, size);
400
/* {{{ php_verror helpers */
402
/* {{{ php_during_module_startup */
403
static int php_during_module_startup()
405
return module_startup;
409
/* {{{ php_during_module_shutdown */
410
static int php_during_module_shutdown()
412
return module_shutdown;
419
/* php_verror is called from php_error_docref<n> functions.
420
* Its purpose is to unify error messages and automatically generate clickable
421
* html error messages if correcponding ini setting (html_errors) is activated.
422
* See: CODING_STANDARDS for details.
424
PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
426
char *buffer = NULL, *docref_buf = NULL, *target = NULL;
427
char *docref_target = "", *docref_root = "";
431
char *class_name = get_active_class_name(&space TSRMLS_CC);
437
/* get error text into buffer and escape for html if necessary */
438
buffer_len = vspprintf(&buffer, 0, format, args);
439
if (PG(html_errors)) {
441
char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
447
/* which function caused the problem if any at all */
448
if (php_during_module_startup()) {
449
function = "PHP Startup";
450
} else if (php_during_module_shutdown()) {
451
function = "PHP Shutdown";
453
function = get_active_function_name(TSRMLS_C);
454
if (!function || !strlen(function)) {
455
function = "Unknown";
461
/* if we still have memory then format the origin */
463
spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
465
spprintf(&origin, 0, "%s", function);
468
/* origin and buffer available, so lets come up with the error message */
469
if (docref && docref[0] == '#') {
470
docref_target = strchr(docref, '#');
474
/* no docref given but function is known (the default) */
475
if (!docref && is_function) {
476
spprintf(&docref_buf, 0, "function.%s", function);
477
while((p = strchr(docref_buf, '_')) != NULL) {
483
/* we have a docref for a function AND
484
* - we show erroes in html mode OR
485
* - the user wants to see the links anyway
487
if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) {
488
if (strncmp(docref, "http://", 7)) {
489
/* We don't have 'http://' so we use docref_root */
491
char *ref; /* temp copy for duplicated docref */
493
docref_root = PG(docref_root);
495
ref = estrdup(docref);
500
/* strip of the target if any */
501
p = strrchr(ref, '#');
505
docref_target = target;
509
/* add the extension if it is set in ini */
510
if (PG(docref_ext) && strlen(PG(docref_ext))) {
511
spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
516
/* display html formatted or only show the additional links */
517
if (PG(html_errors)) {
518
spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
520
spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
526
spprintf(&message, 0, "%s: %s", origin, buffer);
532
php_error(type, "%s", message);
535
if (PG(track_errors) && module_initialized && EG(active_symbol_table)) {
537
ALLOC_INIT_ZVAL(tmp);
538
ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
539
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(pval *), NULL);
545
/* {{{ php_error_docref0 */
546
/* See: CODING_STANDARDS for details. */
547
PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
551
va_start(args, format);
552
php_verror(docref, "", type, format, args TSRMLS_CC);
557
/* {{{ php_error_docref1 */
558
/* See: CODING_STANDARDS for details. */
559
PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
563
va_start(args, format);
564
php_verror(docref, param1, type, format, args TSRMLS_CC);
569
/* {{{ php_error_docref2 */
570
/* See: CODING_STANDARDS for details. */
571
PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
576
spprintf(¶ms, 0, "%s,%s", param1, param2);
577
va_start(args, format);
578
php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC);
586
/* {{{ php_html_puts */
587
PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
589
zend_html_puts(str, size TSRMLS_CC);
593
/* {{{ php_suppress_errors */
594
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC) {
595
PG(error_handling) = error_handling;
596
PG(exception_class) = exception_class;
597
if (PG(last_error_message)) {
598
free(PG(last_error_message));
599
PG(last_error_message) = NULL;
601
if (PG(last_error_file)) {
602
free(PG(last_error_file));
603
PG(last_error_file) = NULL;
605
PG(last_error_lineno) = 0;
610
extended error handling function */
611
static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
614
int buffer_len, display;
617
buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
619
/* check for repeated errors to be ignored */
620
if (PG(ignore_repeated_errors) && PG(last_error_message)) {
621
/* no check for PG(last_error_file) is needed since it cannot
622
* be NULL if PG(last_error_message) is not NULL */
623
if (strcmp(PG(last_error_message), buffer)
624
|| (!PG(ignore_repeated_source)
625
&& ((PG(last_error_lineno) != error_lineno)
626
|| strcmp(PG(last_error_file), error_filename)))) {
635
/* store the error if it has changed */
637
if (PG(last_error_message)) {
638
free(PG(last_error_message));
640
if (PG(last_error_file)) {
641
free(PG(last_error_file));
643
PG(last_error_message) = strdup(buffer);
644
PG(last_error_file) = strdup(error_filename);
645
PG(last_error_lineno) = error_lineno;
648
/* according to error handling mode, suppress error, throw exception or show it */
649
if (PG(error_handling) != EH_NORMAL) {
652
case E_COMPILE_ERROR:
654
/* fatal errors are real errors and cannot be made exceptions */
657
/* for the sake of BC to old damaged code */
661
/* notices are no errors and are not treated as such like E_WARNINGS */
664
/* throw an exception if we are in EH_THROW mode
665
* but DO NOT overwrite a pending exception
667
if (PG(error_handling) == EH_THROW && !EG(exception)) {
668
zend_throw_exception(PG(exception_class), buffer, 0 TSRMLS_CC);
675
/* display/log the error if necessary */
676
if (display && (EG(error_reporting) & type || (type & E_CORE))
677
&& (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
678
char *error_type_str;
683
case E_COMPILE_ERROR:
685
error_type_str = "Fatal error";
689
case E_COMPILE_WARNING:
691
error_type_str = "Warning";
694
error_type_str = "Parse error";
698
error_type_str = "Notice";
701
error_type_str = "Strict Standards";
704
error_type_str = "Unknown error";
708
if (!module_initialized || PG(log_errors)) {
712
if (type==E_CORE_ERROR || type==E_CORE_WARNING) {
713
MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
716
spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
717
php_log_err(log_buffer TSRMLS_CC);
720
if (PG(display_errors)
721
&& ((module_initialized && !PG(during_request_startup))
722
|| (PG(display_startup_errors)
723
&& (OG(php_body_write)==php_default_output_func || OG(php_body_write)==php_ub_body_write_no_header || OG(php_body_write)==php_ub_body_write)
728
if (PG(xmlrpc_errors)) {
729
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);
731
char *prepend_string = INI_STR("error_prepend_string");
732
char *append_string = INI_STR("error_append_string");
733
char *error_format = PG(html_errors) ?
734
"%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s"
735
: "%s\n%s: %s in %s on line %d\n%s";
736
php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
740
if (PG(report_zend_debug)) {
741
zend_bool trigger_break;
746
case E_COMPILE_ERROR:
754
zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
759
/* Bail out if we can't recover */
762
if(!module_initialized) {
763
/* bad error in module startup - no way we can live with this */
766
/* no break - intentionally */
768
/* case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
769
case E_COMPILE_ERROR:
771
EG(exit_status) = 255;
772
if (module_initialized) {
774
/* restore memory limit */
775
AG(memory_limit) = PG(memory_limit);
784
/* Log if necessary */
789
if (PG(track_errors) && module_initialized && EG(active_symbol_table)) {
794
Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len);
795
Z_STRLEN_P(tmp) = buffer_len;
796
Z_TYPE_P(tmp) = IS_STRING;
797
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL);
803
/* {{{ proto bool set_time_limit(int seconds)
804
Sets the maximum time a script can run */
805
PHP_FUNCTION(set_time_limit)
810
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");
814
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_timeout) == FAILURE) {
818
convert_to_string_ex(new_timeout);
819
if (zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), Z_STRVAL_PP(new_timeout), Z_STRLEN_PP(new_timeout), PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) {
827
/* {{{ php_fopen_wrapper_for_zend
829
static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path)
833
return php_stream_open_wrapper_as_file((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
837
static void stream_closer_for_zend(void *handle TSRMLS_DC)
839
php_stream_close((php_stream*)handle);
842
static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC)
846
stream = php_stream_open_wrapper((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, &handle->opened_path);
849
handle->type = ZEND_HANDLE_STREAM;
850
handle->filename = (char*)filename;
851
handle->free_filename = 0;
852
handle->handle.stream.handle = stream;
853
handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
854
handle->handle.stream.closer = stream_closer_for_zend;
855
handle->handle.stream.interactive = 0;
863
/* {{{ php_get_configuration_directive_for_zend
865
static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents)
867
zval *retval = cfg_get_entry(name, name_length);
878
/* {{{ php_message_handler_for_zend
880
static void php_message_handler_for_zend(long message, void *data)
885
case ZMSG_FAILED_INCLUDE_FOPEN:
886
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)));
888
case ZMSG_FAILED_REQUIRE_FOPEN:
889
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)));
891
case ZMSG_FAILED_HIGHLIGHT_FOPEN:
892
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
894
case ZMSG_MEMORY_LEAK_DETECTED:
895
case ZMSG_MEMORY_LEAK_REPEATED:
897
if (EG(error_reporting) & E_WARNING) {
898
char memory_leak_buf[512];
900
if (message==ZMSG_MEMORY_LEAK_DETECTED) {
901
zend_mem_header *t = (zend_mem_header *) data;
902
void *ptr = (void *)((char *)t+sizeof(zend_mem_header)+MEM_HEADER_PADDING);
904
snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)ptr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
905
if (t->orig_filename) {
908
snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
909
strcat(memory_leak_buf, relay_buf);
912
unsigned long leak_count = (unsigned long) data;
914
snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
916
# if defined(PHP_WIN32)
917
OutputDebugString(memory_leak_buf);
919
fprintf(stderr, "%s", memory_leak_buf);
924
case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
926
if (EG(error_reporting) & E_WARNING) {
927
char memory_leak_buf[512];
929
snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data));
930
# if defined(PHP_WIN32)
931
OutputDebugString(memory_leak_buf);
933
fprintf(stderr, "%s", memory_leak_buf);
938
case ZMSG_LOG_SCRIPT_NAME: {
939
struct tm *ta, tmbuf;
941
char *datetime_str, asctimebuf[52];
944
ta = php_localtime_r(&curtime, &tmbuf);
945
datetime_str = php_asctime_r(ta, asctimebuf);
946
datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
947
fprintf(stderr, "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
955
void php_on_timeout(int seconds TSRMLS_DC)
957
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
958
zend_set_timeout(EG(timeout_seconds));
962
/* {{{ sigchld_handler
964
static void sigchld_handler(int apar)
966
while (waitpid(-1, NULL, WNOHANG) > 0);
967
signal(SIGCHLD, sigchld_handler);
972
/* {{{ php_start_sapi()
974
static int php_start_sapi(TSRMLS_D)
976
int retval = SUCCESS;
978
if(!SG(sapi_started)) {
980
PG(during_request_startup) = 1;
982
/* initialize global variables */
983
PG(modules_activated) = 0;
984
PG(header_is_being_sent) = 0;
985
PG(connection_status) = PHP_CONNECTION_NORMAL;
987
zend_activate(TSRMLS_C);
988
zend_set_timeout(EG(timeout_seconds));
989
zend_activate_modules(TSRMLS_C);
990
PG(modules_activated)=1;
995
SG(sapi_started) = 1;
1002
/* {{{ php_request_startup
1004
#ifndef APACHE_HOOKS
1005
int php_request_startup(TSRMLS_D)
1007
int retval = SUCCESS;
1014
signal(SIGCHLD, sigchld_handler);
1018
PG(during_request_startup) = 1;
1020
php_output_activate(TSRMLS_C);
1022
/* initialize global variables */
1023
PG(modules_activated) = 0;
1024
PG(header_is_being_sent) = 0;
1025
PG(connection_status) = PHP_CONNECTION_NORMAL;
1027
zend_activate(TSRMLS_C);
1028
sapi_activate(TSRMLS_C);
1030
if (PG(max_input_time) == -1) {
1031
zend_set_timeout(EG(timeout_seconds));
1033
zend_set_timeout(PG(max_input_time));
1036
if (PG(expose_php)) {
1037
sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1040
if (PG(output_handler) && PG(output_handler)[0]) {
1041
php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
1042
} else if (PG(output_buffering)) {
1043
if (PG(output_buffering)>1) {
1044
php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC);
1046
php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
1048
} else if (PG(implicit_flush)) {
1049
php_start_implicit_flush(TSRMLS_C);
1052
/* We turn this off in php_execute_script() */
1053
/* PG(during_request_startup) = 0; */
1055
php_hash_environment(TSRMLS_C);
1056
zend_activate_modules(TSRMLS_C);
1057
PG(modules_activated)=1;
1065
int php_request_startup(TSRMLS_D)
1067
int retval = SUCCESS;
1070
signal(SIGCHLD, sigchld_handler);
1073
if (php_start_sapi() == FAILURE) {
1077
php_output_activate(TSRMLS_C);
1078
sapi_activate(TSRMLS_C);
1079
php_hash_environment(TSRMLS_C);
1082
PG(during_request_startup) = 1;
1083
php_output_activate(TSRMLS_C);
1084
if (PG(expose_php)) {
1085
sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1096
/* {{{ php_request_startup_for_hook
1098
int php_request_startup_for_hook(TSRMLS_D)
1100
int retval = SUCCESS;
1103
signal(SIGCHLD, sigchld_handler);
1106
if (php_start_sapi(TSRMLS_C) == FAILURE) {
1110
php_output_activate(TSRMLS_C);
1111
sapi_activate_headers_only(TSRMLS_C);
1112
php_hash_environment(TSRMLS_C);
1118
/* {{{ php_request_shutdown_for_exec
1120
void php_request_shutdown_for_exec(void *dummy)
1124
/* used to close fd's in the 3..255 range here, but it's problematic
1126
shutdown_memory_manager(1, 1 TSRMLS_CC);
1130
/* {{{ php_request_shutdown_for_hook
1132
void php_request_shutdown_for_hook(void *dummy)
1135
if (PG(modules_activated)) zend_try {
1136
php_call_shutdown_functions(TSRMLS_C);
1139
if (PG(modules_activated)) {
1140
zend_deactivate_modules(TSRMLS_C);
1141
php_free_shutdown_functions(TSRMLS_C);
1147
for (i = 0; i < NUM_TRACK_VARS; i++) {
1148
if (PG(http_globals)[i]) {
1149
zval_ptr_dtor(&PG(http_globals)[i]);
1154
zend_deactivate(TSRMLS_C);
1157
sapi_deactivate(TSRMLS_C);
1161
php_shutdown_stream_hashes(TSRMLS_C);
1165
shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
1169
zend_unset_timeout(TSRMLS_C);
1175
/* {{{ php_request_shutdown
1177
void php_request_shutdown(void *dummy)
1179
zend_bool report_memleaks;
1182
report_memleaks = PG(report_memleaks);
1183
/* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
1184
* inside zend_executor callback functions.
1186
EG(opline_ptr) = NULL;
1187
EG(active_op_array) = NULL;
1190
php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC);
1194
sapi_send_headers(TSRMLS_C);
1198
zend_call_destructors(TSRMLS_C);
1201
if (PG(modules_activated)) zend_try {
1202
php_call_shutdown_functions(TSRMLS_C);
1205
if (PG(modules_activated)) {
1206
zend_deactivate_modules(TSRMLS_C);
1207
php_free_shutdown_functions(TSRMLS_C);
1213
for (i=0; i<NUM_TRACK_VARS; i++) {
1214
if (PG(http_globals)[i]) {
1215
zval_ptr_dtor(&PG(http_globals)[i]);
1221
zend_deactivate(TSRMLS_C);
1224
zend_post_deactivate_modules(TSRMLS_C);
1228
sapi_deactivate(TSRMLS_C);
1232
php_shutdown_stream_hashes(TSRMLS_C);
1236
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
1240
zend_unset_timeout(TSRMLS_C);
1250
/* {{{ php_body_write_wrapper
1252
static int php_body_write_wrapper(const char *str, uint str_length)
1255
return php_body_write(str, str_length TSRMLS_CC);
1260
/* {{{ core_globals_ctor
1262
static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
1264
memset(core_globals, 0, sizeof(*core_globals));
1269
/* {{{ php_startup_extensions
1271
int php_startup_extensions(zend_module_entry **ptr, int count)
1273
zend_module_entry **end = ptr+count;
1277
if (zend_startup_module(*ptr)==FAILURE) {
1288
/* {{{ php_module_startup
1290
int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
1292
zend_utility_functions zuf;
1293
zend_utility_values zuv;
1294
int module_number=0; /* for REGISTER_INI_ENTRIES() */
1297
zend_executor_globals *executor_globals;
1300
php_core_globals *core_globals;
1302
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1303
WORD wVersionRequested = MAKEWORD(2, 0);
1308
DWORD dwVersion = GetVersion();
1310
/* Get build numbers for Windows NT or Win95 */
1311
if (dwVersion < 0x80000000){
1322
tsrm_ls = ts_resource(0);
1325
module_shutdown = 0;
1327
sapi_initialize_empty_request(TSRMLS_C);
1328
sapi_activate(TSRMLS_C);
1330
if (module_initialized) {
1336
php_output_startup();
1338
zuf.error_function = php_error_cb;
1339
zuf.printf_function = php_printf;
1340
zuf.write_function = php_body_write_wrapper;
1341
zuf.fopen_function = php_fopen_wrapper_for_zend;
1342
zuf.message_handler = php_message_handler_for_zend;
1343
zuf.block_interruptions = sapi_module.block_interruptions;
1344
zuf.unblock_interruptions = sapi_module.unblock_interruptions;
1345
zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
1346
zuf.ticks_function = php_run_ticks;
1347
zuf.on_timeout = php_on_timeout;
1348
zuf.stream_open_function = php_stream_open_for_zend;
1349
zuf.vspprintf_function = vspprintf;
1350
zend_startup(&zuf, NULL, 1);
1353
executor_globals = ts_resource(executor_globals_id);
1354
ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL);
1355
core_globals = ts_resource(core_globals_id);
1357
EG(bailout_set) = 0;
1358
EG(error_reporting) = E_ALL & ~E_NOTICE;
1360
PG(header_is_being_sent) = 0;
1361
SG(request_info).headers_only = 0;
1362
SG(request_info).argv0 = NULL;
1363
SG(request_info).argc=0;
1364
SG(request_info).argv=(char **)NULL;
1365
PG(connection_status) = PHP_CONNECTION_NORMAL;
1366
PG(during_request_startup) = 0;
1367
PG(last_error_message) = NULL;
1368
PG(last_error_file) = NULL;
1369
PG(last_error_lineno) = 0;
1370
PG(error_handling) = EH_NORMAL;
1371
PG(disable_functions) = NULL;
1372
PG(disable_classes) = NULL;
1375
setlocale(LC_CTYPE, "");
1382
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1383
/* start up winsock services */
1384
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
1385
php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
1390
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
1393
/* this will read in php.ini, set up the configuration parameters,
1394
load zend extensions and register php function extensions
1395
to be loaded later */
1396
if (php_init_config() == FAILURE) {
1400
REGISTER_INI_ENTRIES();
1401
zend_register_standard_ini_entries(TSRMLS_C);
1403
/* initialize stream wrappers registry
1404
* (this uses configuration parameters from php.ini)
1406
if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE) {
1407
php_printf("PHP: Unable to initialize stream url wrappers.\n");
1411
/* initialize registry for images to be used in phpinfo()
1412
(this uses configuration parameters from php.ini)
1414
if (php_init_info_logos() == FAILURE) {
1415
php_printf("PHP: Unable to initialize info phpinfo logos.\n");
1419
zuv.html_errors = 1;
1420
zuv.import_use_extension = ".php";
1421
php_startup_auto_globals(TSRMLS_C);
1422
zend_set_utility_values(&zuv);
1423
php_startup_sapi_content_types();
1425
REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
1426
REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
1427
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
1428
REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
1429
REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
1430
REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
1431
REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
1432
REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
1433
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
1434
REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
1435
REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
1436
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
1437
REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
1438
REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, sizeof(PHP_CONFIG_FILE_PATH)-1, CONST_PERSISTENT | CONST_CS);
1439
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);
1440
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
1441
REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
1442
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
1443
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
1444
php_output_register_constants(TSRMLS_C);
1445
php_rfc1867_register_constants(TSRMLS_C);
1447
if (php_startup_ticks(TSRMLS_C) == FAILURE) {
1448
php_printf("Unable to start PHP ticks\n");
1452
/* Register internal Zend classes */
1453
zend_register_default_classes(TSRMLS_C);
1455
/* startup extensions staticly compiled in */
1456
if (php_startup_internal_extensions() == FAILURE) {
1457
php_printf("Unable to start builtin modules\n");
1461
/* start additional PHP extensions */
1462
php_startup_extensions(&additional_modules, num_additional_modules);
1465
/* load and startup extensions compiled as shared objects (aka DLLs)
1466
as requested by php.ini entries
1467
theese are loaded after initialization of internal extensions
1468
as extensions *might* rely on things from ext/standard
1469
which is always an internal extension and to be initialized
1470
ahead of all other internals
1472
php_ini_delayed_modules_startup(TSRMLS_C);
1474
/* disable certain classes and functions as requested by php.ini */
1475
php_disable_functions(TSRMLS_C);
1476
php_disable_classes(TSRMLS_C);
1478
/* start Zend extensions */
1479
zend_startup_extensions();
1482
zend_post_startup(TSRMLS_C);
1485
module_initialized = 1;
1486
sapi_deactivate(TSRMLS_C);
1494
void php_module_shutdown_for_exec()
1496
/* used to close fd's in the range 3.255 here, but it's problematic */
1499
/* {{{ php_module_shutdown_wrapper
1501
int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
1504
php_module_shutdown(TSRMLS_C);
1509
/* {{{ php_module_shutdown
1511
void php_module_shutdown(TSRMLS_D)
1513
int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
1515
module_shutdown = 1;
1517
if (!module_initialized) {
1521
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1526
php_shutdown_ticks(TSRMLS_C);
1527
sapi_flush(TSRMLS_C);
1529
zend_shutdown(TSRMLS_C);
1531
php_shutdown_stream_wrappers(module_number TSRMLS_CC);
1533
php_shutdown_info_logos();
1534
UNREGISTER_INI_ENTRIES();
1536
/* close down the ini config */
1537
php_shutdown_config();
1540
zend_ini_shutdown(TSRMLS_C);
1541
shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
1543
zend_ini_global_shutdown(TSRMLS_C);
1546
module_initialized = 0;
1547
if (PG(last_error_message)) {
1548
free(PG(last_error_message));
1550
if (PG(last_error_file)) {
1551
free(PG(last_error_file));
1553
if (PG(disable_functions)) {
1554
free(PG(disable_functions));
1556
if (PG(disable_classes)) {
1557
free(PG(disable_classes));
1563
/* {{{ php_execute_script
1565
PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
1567
zend_file_handle *prepend_file_p, *append_file_p;
1568
zend_file_handle prepend_file = {0}, append_file = {0};
1569
#if HAVE_BROKEN_GETCWD
1570
int old_cwd_fd = -1;
1574
char *old_primary_file_path = NULL;
1577
EG(exit_status) = 0;
1578
if (php_handle_special_queries(TSRMLS_C)) {
1579
zend_file_handle_dtor(primary_file);
1582
#ifndef HAVE_BROKEN_GETCWD
1583
# define OLD_CWD_SIZE 4096
1584
old_cwd = do_alloca(OLD_CWD_SIZE);
1590
UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
1593
PG(during_request_startup) = 0;
1595
if (primary_file->type == ZEND_HANDLE_FILENAME
1596
&& primary_file->filename) {
1597
#if HAVE_BROKEN_GETCWD
1598
/* this looks nasty to me */
1599
old_cwd_fd = open(".", 0);
1601
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
1603
VCWD_CHDIR_FILE(primary_file->filename);
1606
if (primary_file->filename) {
1607
char realfile[MAXPATHLEN];
1610
if (VCWD_REALPATH(primary_file->filename, realfile)) {
1611
realfile_len = strlen(realfile);
1612
zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL);
1613
if (strncmp(realfile, primary_file->filename, realfile_len)) {
1614
old_primary_file_path = primary_file->filename;
1615
primary_file->filename = realfile;
1620
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
1621
prepend_file.filename = PG(auto_prepend_file);
1622
prepend_file.opened_path = NULL;
1623
prepend_file.free_filename = 0;
1624
prepend_file.type = ZEND_HANDLE_FILENAME;
1625
prepend_file_p = &prepend_file;
1627
prepend_file_p = NULL;
1630
if (PG(auto_append_file) && PG(auto_append_file)[0]) {
1631
append_file.filename = PG(auto_append_file);
1632
append_file.opened_path = NULL;
1633
append_file.free_filename = 0;
1634
append_file.type = ZEND_HANDLE_FILENAME;
1635
append_file_p = &append_file;
1637
append_file_p = NULL;
1640
zend_unset_timeout(TSRMLS_C);
1642
zend_set_timeout(INI_INT("max_execution_time"));
1643
retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
1645
if (old_primary_file_path) {
1646
primary_file->filename = old_primary_file_path;
1651
#if HAVE_BROKEN_GETCWD
1652
if (old_cwd_fd != -1) {
1657
if (old_cwd[0] != '\0') {
1658
VCWD_CHDIR(old_cwd);
1660
free_alloca(old_cwd);
1666
/* {{{ php_execute_simple_script
1668
PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
1672
EG(exit_status) = 0;
1673
#define OLD_CWD_SIZE 4096
1674
old_cwd = do_alloca(OLD_CWD_SIZE);
1679
UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
1682
PG(during_request_startup) = 0;
1684
if (primary_file->type == ZEND_HANDLE_FILENAME && primary_file->filename) {
1685
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
1686
VCWD_CHDIR_FILE(primary_file->filename);
1688
zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
1691
if (old_cwd[0] != '\0') {
1692
VCWD_CHDIR(old_cwd);
1695
free_alloca(old_cwd);
1696
return EG(exit_status);
1700
/* {{{ php_handle_aborted_connection
1702
PHPAPI void php_handle_aborted_connection(void)
1706
PG(connection_status) = PHP_CONNECTION_ABORTED;
1707
php_output_set_status(0 TSRMLS_CC);
1709
if (!PG(ignore_user_abort)) {
1715
/* {{{ php_handle_auth_data
1717
PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
1721
if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
1725
user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL);
1727
pass = strchr(user, ':');
1730
SG(request_info).auth_user = user;
1731
SG(request_info).auth_password = estrdup(pass);
1740
SG(request_info).auth_user = SG(request_info).auth_password = NULL;
1747
/* {{{ php_lint_script
1749
PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
1751
zend_op_array *op_array;
1752
zend_bool retval = FAILURE;
1755
op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
1756
zend_destroy_file_handle(file TSRMLS_CC);
1759
destroy_op_array(op_array TSRMLS_CC);
1771
just so that this symbol gets exported... */
1772
PHPAPI void dummy_indent()
1784
* vim600: sw=4 ts=4 fdm=marker
1785
* vim<600: sw=4 ts=4