Back to index

php5  5.3.10
main.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Andi Gutmans <andi@zend.com>                                |
00016    |          Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
00017    |          Zeev Suraski <zeev@zend.com>                                |
00018    +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: main.c 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 /* {{{ includes
00024  */
00025 
00026 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
00027 
00028 #include "php.h"
00029 #include <stdio.h>
00030 #include <fcntl.h>
00031 #ifdef PHP_WIN32
00032 #include "win32/time.h"
00033 #include "win32/signal.h"
00034 #include "win32/php_win32_globals.h"
00035 #include "win32/winutil.h"
00036 #include <process.h>
00037 #elif defined(NETWARE)
00038 #include <sys/timeval.h>
00039 #ifdef USE_WINSOCK
00040 #include <novsock2.h>
00041 #endif
00042 #endif
00043 #if HAVE_SYS_TIME_H
00044 #include <sys/time.h>
00045 #endif
00046 #if HAVE_UNISTD_H
00047 #include <unistd.h>
00048 #endif
00049 #if HAVE_SIGNAL_H
00050 #include <signal.h>
00051 #endif
00052 #if HAVE_SETLOCALE
00053 #include <locale.h>
00054 #endif
00055 #include "zend.h"
00056 #include "zend_extensions.h"
00057 #include "php_ini.h"
00058 #include "php_globals.h"
00059 #include "php_main.h"
00060 #include "fopen_wrappers.h"
00061 #include "ext/standard/php_standard.h"
00062 #include "ext/standard/php_string.h"
00063 #include "ext/date/php_date.h"
00064 #include "php_variables.h"
00065 #include "ext/standard/credits.h"
00066 #ifdef PHP_WIN32
00067 #include <io.h>
00068 #include "win32/php_registry.h"
00069 #include "ext/standard/flock_compat.h"
00070 #endif
00071 #include "php_syslog.h"
00072 #include "Zend/zend_exceptions.h"
00073 
00074 #if PHP_SIGCHILD
00075 #include <sys/types.h>
00076 #include <sys/wait.h>
00077 #endif
00078 
00079 #include "zend_compile.h"
00080 #include "zend_execute.h"
00081 #include "zend_highlight.h"
00082 #include "zend_indent.h"
00083 #include "zend_extensions.h"
00084 #include "zend_ini.h"
00085 
00086 #include "php_content_types.h"
00087 #include "php_ticks.h"
00088 #include "php_logos.h"
00089 #include "php_streams.h"
00090 #include "php_open_temporary_file.h"
00091 
00092 #include "SAPI.h"
00093 #include "rfc1867.h"
00094 
00095 #if HAVE_MMAP
00096 # if HAVE_UNISTD_H
00097 #  include <unistd.h>
00098 #  if defined(_SC_PAGESIZE)
00099 #    define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
00100 #  elif defined(_SC_PAGE_SIZE)
00101 #    define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);
00102 #  endif
00103 # endif
00104 # if HAVE_SYS_MMAN_H
00105 #  include <sys/mman.h>
00106 # endif
00107 # ifndef REAL_PAGE_SIZE
00108 #  ifdef PAGE_SIZE
00109 #   define REAL_PAGE_SIZE PAGE_SIZE
00110 #  else
00111 #   define REAL_PAGE_SIZE 4096
00112 #  endif
00113 # endif
00114 #endif
00115 /* }}} */
00116 
00117 PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
00118 
00119 #ifndef ZTS
00120 php_core_globals core_globals;
00121 #else
00122 PHPAPI int core_globals_id;
00123 #endif
00124 
00125 #ifdef PHP_WIN32
00126 #include "win32_internal_function_disabled.h"
00127 
00128 static php_win32_disable_functions() {
00129        int i;
00130        TSRMLS_FETCH();
00131 
00132        if (EG(windows_version_info).dwMajorVersion < 5) {
00133               for (i = 0; i < function_name_cnt_5; i++) {
00134                      if (zend_hash_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]) + 1)==FAILURE) {
00135                             php_printf("Unable to disable function '%s'\n", function_name_5[i]);
00136                             return FAILURE;
00137                      }
00138               }
00139        }
00140 
00141        if (EG(windows_version_info).dwMajorVersion < 6) {
00142               for (i = 0; i < function_name_cnt_6; i++) {
00143                      if (zend_hash_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]) + 1)==FAILURE) {
00144                             php_printf("Unable to disable function '%s'\n", function_name_6[i]);
00145                             return FAILURE;
00146                      }
00147               }
00148        }
00149        return SUCCESS;
00150 }
00151 #endif
00152 
00153 #define SAFE_FILENAME(f) ((f)?(f):"-")
00154 
00155 /* {{{ PHP_INI_MH
00156  */
00157 static PHP_INI_MH(OnSetPrecision)
00158 {
00159        int i = atoi(new_value);
00160        if (i >= 0) {
00161               EG(precision) = i;
00162               return SUCCESS;
00163        } else {
00164               return FAILURE;
00165        }
00166 }
00167 /* }}} */
00168 
00169 /* {{{ PHP_INI_MH
00170  */
00171 static PHP_INI_MH(OnChangeMemoryLimit)
00172 {
00173        if (new_value) {
00174               PG(memory_limit) = zend_atol(new_value, new_value_length);
00175        } else {
00176               PG(memory_limit) = 1<<30;          /* effectively, no limit */
00177        }
00178        return zend_set_memory_limit(PG(memory_limit));
00179 }
00180 /* }}} */
00181 
00182 
00183 /* {{{ php_disable_functions
00184  */
00185 static void php_disable_functions(TSRMLS_D)
00186 {
00187        char *s = NULL, *e;
00188 
00189        if (!*(INI_STR("disable_functions"))) {
00190               return;
00191        }
00192 
00193        e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
00194        if (e == NULL) {
00195               return;
00196        }
00197        while (*e) {
00198               switch (*e) {
00199                      case ' ':
00200                      case ',':
00201                             if (s) {
00202                                    *e = '\0';
00203                                    zend_disable_function(s, e-s TSRMLS_CC);
00204                                    s = NULL;
00205                             }
00206                             break;
00207                      default:
00208                             if (!s) {
00209                                    s = e;
00210                             }
00211                             break;
00212               }
00213               e++;
00214        }
00215        if (s) {
00216               zend_disable_function(s, e-s TSRMLS_CC);
00217        }
00218 }
00219 /* }}} */
00220 
00221 /* {{{ php_disable_classes
00222  */
00223 static void php_disable_classes(TSRMLS_D)
00224 {
00225        char *s = NULL, *e;
00226 
00227        if (!*(INI_STR("disable_classes"))) {
00228               return;
00229        }
00230 
00231        e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
00232 
00233        while (*e) {
00234               switch (*e) {
00235                      case ' ':
00236                      case ',':
00237                             if (s) {
00238                                    *e = '\0';
00239                                    zend_disable_class(s, e-s TSRMLS_CC);
00240                                    s = NULL;
00241                             }
00242                             break;
00243                      default:
00244                             if (!s) {
00245                                    s = e;
00246                             }
00247                             break;
00248               }
00249               e++;
00250        }
00251        if (s) {
00252               zend_disable_class(s, e-s TSRMLS_CC);
00253        }
00254 }
00255 /* }}} */
00256 
00257 /* {{{ PHP_INI_MH
00258  */
00259 static PHP_INI_MH(OnUpdateTimeout)
00260 {
00261        if (stage==PHP_INI_STAGE_STARTUP) {
00262               /* Don't set a timeout on startup, only per-request */
00263               EG(timeout_seconds) = atoi(new_value);
00264               return SUCCESS;
00265        }
00266        zend_unset_timeout(TSRMLS_C);
00267        EG(timeout_seconds) = atoi(new_value);
00268        zend_set_timeout(EG(timeout_seconds), 0);
00269        return SUCCESS;
00270 }
00271 /* }}} */
00272 
00273 /* {{{ php_get_display_errors_mode() helper function
00274  */
00275 static int php_get_display_errors_mode(char *value, int value_length)
00276 {
00277        int mode;
00278 
00279        if (!value) {
00280               return PHP_DISPLAY_ERRORS_STDOUT;
00281        }
00282 
00283        if (value_length == 2 && !strcasecmp("on", value)) {
00284               mode = PHP_DISPLAY_ERRORS_STDOUT;
00285        } else if (value_length == 3 && !strcasecmp("yes", value)) {
00286               mode = PHP_DISPLAY_ERRORS_STDOUT;
00287        } else if (value_length == 4 && !strcasecmp("true", value)) {
00288               mode = PHP_DISPLAY_ERRORS_STDOUT;
00289        } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
00290               mode = PHP_DISPLAY_ERRORS_STDERR;
00291        } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
00292               mode = PHP_DISPLAY_ERRORS_STDOUT;
00293        } else {
00294               mode = atoi(value);
00295               if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
00296                      mode = PHP_DISPLAY_ERRORS_STDOUT;
00297               }
00298        }
00299 
00300        return mode;
00301 }
00302 /* }}} */
00303 
00304 /* {{{ PHP_INI_MH
00305  */
00306 static PHP_INI_MH(OnUpdateDisplayErrors)
00307 {
00308        PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);
00309 
00310        return SUCCESS;
00311 }
00312 /* }}} */
00313 
00314 /* {{{ PHP_INI_DISP
00315  */
00316 static PHP_INI_DISP(display_errors_mode)
00317 {
00318        int mode, tmp_value_length, cgi_or_cli;
00319        char *tmp_value;
00320        TSRMLS_FETCH();
00321 
00322        if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
00323               tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
00324               tmp_value_length = ini_entry->orig_value_length;
00325        } else if (ini_entry->value) {
00326               tmp_value = ini_entry->value;
00327               tmp_value_length = ini_entry->value_length;
00328        } else {
00329               tmp_value = NULL;
00330               tmp_value_length = 0;
00331        }
00332 
00333        mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
00334 
00335        /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
00336        cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi"));
00337 
00338        switch (mode) {
00339               case PHP_DISPLAY_ERRORS_STDERR:
00340                      if (cgi_or_cli ) {
00341                             PUTS("STDERR");
00342                      } else {
00343                             PUTS("On");
00344                      }
00345                      break;
00346 
00347               case PHP_DISPLAY_ERRORS_STDOUT:
00348                      if (cgi_or_cli ) {
00349                             PUTS("STDOUT");
00350                      } else {
00351                             PUTS("On");
00352                      }
00353                      break;
00354 
00355               default:
00356                      PUTS("Off");
00357                      break;
00358        }
00359 }
00360 /* }}} */
00361 
00362 /* {{{ PHP_INI_MH
00363  */
00364 static PHP_INI_MH(OnUpdateErrorLog)
00365 {
00366        /* Only do the safemode/open_basedir check at runtime */
00367        if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {
00368               if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
00369                      return FAILURE;
00370               }
00371 
00372               if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
00373                      return FAILURE;
00374               }
00375 
00376        }
00377        OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
00378        return SUCCESS;
00379 }
00380 /* }}} */
00381 
00382 /* {{{ PHP_INI_MH
00383  */
00384 static PHP_INI_MH(OnUpdateMailLog)
00385 {
00386        /* Only do the safemode/open_basedir check at runtime */
00387        if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
00388               if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
00389                      return FAILURE;
00390               }
00391 
00392               if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
00393                      return FAILURE;
00394               }
00395 
00396        }
00397        OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
00398        return SUCCESS;
00399 }
00400 /* }}} */
00401 
00402 /* {{{ PHP_INI_MH
00403  */
00404 static PHP_INI_MH(OnChangeMailForceExtra)
00405 {
00406        /* Don't allow changing it in htaccess */
00407        if (stage == PHP_INI_STAGE_HTACCESS) {
00408                      return FAILURE;
00409        }
00410        return SUCCESS;
00411 }
00412 /* }}} */
00413 
00414 /* defined in browscap.c */
00415 PHP_INI_MH(OnChangeBrowscap);
00416 
00417 /* Need to convert to strings and make use of:
00418  * PHP_SAFE_MODE
00419  *
00420  * Need to be read from the environment (?):
00421  * PHP_AUTO_PREPEND_FILE
00422  * PHP_AUTO_APPEND_FILE
00423  * PHP_DOCUMENT_ROOT
00424  * PHP_USER_DIR
00425  * PHP_INCLUDE_PATH
00426  */
00427 
00428 #ifndef PHP_SAFE_MODE_EXEC_DIR
00429 #      define PHP_SAFE_MODE_EXEC_DIR ""
00430 #endif
00431 
00432  /* Windows and Netware use the internal mail */
00433 #if defined(PHP_WIN32) || defined(NETWARE)
00434 # define DEFAULT_SENDMAIL_PATH NULL
00435 #elif defined(PHP_PROG_SENDMAIL)
00436 # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
00437 #else
00438 # define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"
00439 #endif
00440 
00441 /* {{{ PHP_INI
00442  */
00443 PHP_INI_BEGIN()
00444        PHP_INI_ENTRY_EX("define_syslog_variables",      "0",                        PHP_INI_ALL,  NULL,                php_ini_boolean_displayer_cb)
00445        PHP_INI_ENTRY_EX("highlight.bg",                 HL_BG_COLOR,         PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00446        PHP_INI_ENTRY_EX("highlight.comment",            HL_COMMENT_COLOR,    PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00447        PHP_INI_ENTRY_EX("highlight.default",            HL_DEFAULT_COLOR,    PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00448        PHP_INI_ENTRY_EX("highlight.html",               HL_HTML_COLOR,              PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00449        PHP_INI_ENTRY_EX("highlight.keyword",            HL_KEYWORD_COLOR,    PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00450        PHP_INI_ENTRY_EX("highlight.string",             HL_STRING_COLOR,     PHP_INI_ALL,  NULL,                php_ini_color_displayer_cb)
00451 
00452        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)
00453        STD_PHP_INI_BOOLEAN("asp_tags",                         "0",          PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateBool,               asp_tags,                          zend_compiler_globals,      compiler_globals)
00454        STD_PHP_INI_ENTRY_EX("display_errors",           "1",          PHP_INI_ALL,         OnUpdateDisplayErrors,      display_errors,                    php_core_globals,    core_globals, display_errors_mode)
00455        STD_PHP_INI_BOOLEAN("display_startup_errors",    "0",   PHP_INI_ALL,         OnUpdateBool,               display_startup_errors,     php_core_globals,    core_globals)
00456        STD_PHP_INI_BOOLEAN("enable_dl",                 "1",          PHP_INI_SYSTEM,             OnUpdateBool,               enable_dl,                         php_core_globals,    core_globals)
00457        STD_PHP_INI_BOOLEAN("expose_php",                "1",          PHP_INI_SYSTEM,             OnUpdateBool,               expose_php,                        php_core_globals,    core_globals)
00458        STD_PHP_INI_ENTRY("docref_root",                 "",           PHP_INI_ALL,         OnUpdateString,                    docref_root,                php_core_globals,    core_globals)
00459        STD_PHP_INI_ENTRY("docref_ext",                         "",                  PHP_INI_ALL,         OnUpdateString,                    docref_ext,                        php_core_globals,    core_globals)
00460        STD_PHP_INI_BOOLEAN("html_errors",               "1",          PHP_INI_ALL,         OnUpdateBool,               html_errors,                php_core_globals,    core_globals)
00461        STD_PHP_INI_BOOLEAN("xmlrpc_errors",             "0",          PHP_INI_SYSTEM,             OnUpdateBool,               xmlrpc_errors,                     php_core_globals,    core_globals)
00462        STD_PHP_INI_ENTRY("xmlrpc_error_number",  "0",          PHP_INI_ALL,         OnUpdateLong,               xmlrpc_error_number, php_core_globals,    core_globals)
00463        STD_PHP_INI_ENTRY("max_input_time",                     "-1",  PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateLong,               max_input_time,      php_core_globals,    core_globals)
00464        STD_PHP_INI_BOOLEAN("ignore_user_abort",  "0",          PHP_INI_ALL,         OnUpdateBool,               ignore_user_abort,          php_core_globals,    core_globals)
00465        STD_PHP_INI_BOOLEAN("implicit_flush",            "0",          PHP_INI_ALL,         OnUpdateBool,               implicit_flush,                    php_core_globals,    core_globals)
00466        STD_PHP_INI_BOOLEAN("log_errors",                "0",          PHP_INI_ALL,         OnUpdateBool,               log_errors,                        php_core_globals,    core_globals)
00467        STD_PHP_INI_ENTRY("log_errors_max_len",    "1024",             PHP_INI_ALL,         OnUpdateLong,               log_errors_max_len,         php_core_globals,    core_globals)
00468        STD_PHP_INI_BOOLEAN("ignore_repeated_errors",    "0",   PHP_INI_ALL,         OnUpdateBool,               ignore_repeated_errors,     php_core_globals,    core_globals)
00469        STD_PHP_INI_BOOLEAN("ignore_repeated_source",    "0",   PHP_INI_ALL,         OnUpdateBool,               ignore_repeated_source,     php_core_globals,    core_globals)
00470        STD_PHP_INI_BOOLEAN("report_memleaks",           "1",          PHP_INI_ALL,         OnUpdateBool,               report_memleaks,            php_core_globals,    core_globals)
00471        STD_PHP_INI_BOOLEAN("report_zend_debug",  "1",          PHP_INI_ALL,         OnUpdateBool,               report_zend_debug,          php_core_globals,    core_globals)
00472        STD_PHP_INI_BOOLEAN("magic_quotes_gpc",          "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateBool, magic_quotes_gpc,           php_core_globals,    core_globals)
00473        STD_PHP_INI_BOOLEAN("magic_quotes_runtime",      "0",          PHP_INI_ALL,         OnUpdateBool,               magic_quotes_runtime,       php_core_globals,    core_globals)
00474        STD_PHP_INI_BOOLEAN("magic_quotes_sybase",       "0",          PHP_INI_ALL,         OnUpdateBool,               magic_quotes_sybase, php_core_globals,    core_globals)
00475        STD_PHP_INI_ENTRY("output_buffering",            "0",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateLong, output_buffering,           php_core_globals,    core_globals)
00476        STD_PHP_INI_ENTRY("output_handler",                     NULL,         PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateString,      output_handler,             php_core_globals,    core_globals)
00477        STD_PHP_INI_BOOLEAN("register_argc_argv", "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateBool, register_argc_argv,         php_core_globals,    core_globals)
00478        STD_PHP_INI_BOOLEAN("register_globals",          "0",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateBool, register_globals,           php_core_globals,    core_globals)
00479        STD_PHP_INI_BOOLEAN("register_long_arrays",      "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateBool, register_long_arrays,       php_core_globals,    core_globals)
00480        STD_PHP_INI_BOOLEAN("auto_globals_jit",          "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,     OnUpdateBool, auto_globals_jit,    php_core_globals,    core_globals)
00481 #if PHP_SAFE_MODE
00482        STD_PHP_INI_BOOLEAN("safe_mode",                 "1",          PHP_INI_SYSTEM,             OnUpdateBool,               safe_mode,                         php_core_globals,    core_globals)
00483 #else
00484        STD_PHP_INI_BOOLEAN("safe_mode",                 "0",          PHP_INI_SYSTEM,             OnUpdateBool,               safe_mode,                         php_core_globals,    core_globals)
00485 #endif
00486        STD_PHP_INI_ENTRY("safe_mode_include_dir",       NULL,         PHP_INI_SYSTEM,             OnUpdateString,                    safe_mode_include_dir,      php_core_globals,    core_globals)
00487        STD_PHP_INI_BOOLEAN("safe_mode_gid",             "0",          PHP_INI_SYSTEM,             OnUpdateBool,               safe_mode_gid,                     php_core_globals,    core_globals)
00488        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)
00489        STD_PHP_INI_BOOLEAN("sql.safe_mode",             "0",          PHP_INI_SYSTEM,             OnUpdateBool,               sql_safe_mode,                     php_core_globals,    core_globals)
00490        STD_PHP_INI_BOOLEAN("track_errors",                     "0",          PHP_INI_ALL,         OnUpdateBool,               track_errors,               php_core_globals,    core_globals)
00491        STD_PHP_INI_BOOLEAN("y2k_compliance",            "1",          PHP_INI_ALL,         OnUpdateBool,               y2k_compliance,                    php_core_globals,    core_globals)
00492 
00493        STD_PHP_INI_ENTRY("unserialize_callback_func",   NULL,  PHP_INI_ALL,         OnUpdateString,                    unserialize_callback_func,  php_core_globals,    core_globals)
00494        STD_PHP_INI_ENTRY("serialize_precision",  "17",  PHP_INI_ALL,         OnUpdateLongGEZero,                serialize_precision, php_core_globals,    core_globals)
00495        STD_PHP_INI_ENTRY("arg_separator.output", "&",          PHP_INI_ALL,         OnUpdateStringUnempty,      arg_separator.output,       php_core_globals,    core_globals)
00496        STD_PHP_INI_ENTRY("arg_separator.input",  "&",          PHP_INI_SYSTEM|PHP_INI_PERDIR,     OnUpdateStringUnempty,      arg_separator.input, php_core_globals,    core_globals)
00497 
00498        STD_PHP_INI_ENTRY("auto_append_file",            NULL,         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateString,                    auto_append_file,           php_core_globals,    core_globals)
00499        STD_PHP_INI_ENTRY("auto_prepend_file",           NULL,         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateString,                    auto_prepend_file,          php_core_globals,    core_globals)
00500        STD_PHP_INI_ENTRY("doc_root",                           NULL,         PHP_INI_SYSTEM,             OnUpdateStringUnempty,      doc_root,                          php_core_globals,    core_globals)
00501        STD_PHP_INI_ENTRY("default_charset",             SAPI_DEFAULT_CHARSET,       PHP_INI_ALL,  OnUpdateString,                    default_charset,            sapi_globals_struct,sapi_globals)
00502        STD_PHP_INI_ENTRY("default_mimetype",            SAPI_DEFAULT_MIMETYPE,      PHP_INI_ALL,  OnUpdateString,                    default_mimetype,           sapi_globals_struct,sapi_globals)
00503        STD_PHP_INI_ENTRY("error_log",                          NULL,         PHP_INI_ALL,         OnUpdateErrorLog,                  error_log,                         php_core_globals,    core_globals)
00504        STD_PHP_INI_ENTRY("extension_dir",               PHP_EXTENSION_DIR,          PHP_INI_SYSTEM,             OnUpdateStringUnempty,      extension_dir,                     php_core_globals,    core_globals)
00505        STD_PHP_INI_ENTRY("include_path",                PHP_INCLUDE_PATH,           PHP_INI_ALL,         OnUpdateStringUnempty,      include_path,               php_core_globals,    core_globals)
00506        PHP_INI_ENTRY("max_execution_time",                     "30",         PHP_INI_ALL,                OnUpdateTimeout)
00507        STD_PHP_INI_ENTRY("open_basedir",                NULL,         PHP_INI_ALL,         OnUpdateBaseDir,                   open_basedir,               php_core_globals,    core_globals)
00508        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)
00509 
00510        STD_PHP_INI_BOOLEAN("file_uploads",                     "1",          PHP_INI_SYSTEM,             OnUpdateBool,               file_uploads,               php_core_globals,    core_globals)
00511        STD_PHP_INI_ENTRY("upload_max_filesize",  "2M",         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateLong,               upload_max_filesize, php_core_globals,    core_globals)
00512        STD_PHP_INI_ENTRY("post_max_size",               "8M",         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateLong,               post_max_size,                     sapi_globals_struct,sapi_globals)
00513        STD_PHP_INI_ENTRY("upload_tmp_dir",                     NULL,         PHP_INI_SYSTEM,             OnUpdateStringUnempty,      upload_tmp_dir,                    php_core_globals,    core_globals)
00514        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)
00515        STD_PHP_INI_ENTRY("max_input_vars",                     "1000",              PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateLongGEZero,  max_input_vars,                                         php_core_globals,    core_globals)
00516 
00517        STD_PHP_INI_ENTRY("user_dir",                           NULL,         PHP_INI_SYSTEM,             OnUpdateString,                    user_dir,                          php_core_globals,    core_globals)
00518        STD_PHP_INI_ENTRY("variables_order",             "EGPCS",      PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateStringUnempty,      variables_order,            php_core_globals,    core_globals)
00519        STD_PHP_INI_ENTRY("request_order",               NULL,         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateString,      request_order,              php_core_globals,    core_globals)
00520 
00521        STD_PHP_INI_ENTRY("error_append_string",  NULL,         PHP_INI_ALL,         OnUpdateString,                    error_append_string, php_core_globals,    core_globals)
00522        STD_PHP_INI_ENTRY("error_prepend_string", NULL,         PHP_INI_ALL,         OnUpdateString,                    error_prepend_string,       php_core_globals,    core_globals)
00523 
00524        PHP_INI_ENTRY("SMTP",                                          "localhost",PHP_INI_ALL,           NULL)
00525        PHP_INI_ENTRY("smtp_port",                              "25",         PHP_INI_ALL,         NULL)
00526        STD_PHP_INI_BOOLEAN("mail.add_x_header",                "0",          PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateBool,               mail_x_header,                     php_core_globals,    core_globals)
00527        STD_PHP_INI_ENTRY("mail.log",                                  NULL,         PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnUpdateMailLog,                   mail_log,                   php_core_globals,    core_globals)
00528        PHP_INI_ENTRY("browscap",                               NULL,         PHP_INI_SYSTEM,             OnChangeBrowscap)
00529        PHP_INI_ENTRY("memory_limit",                           "128M",              PHP_INI_ALL,         OnChangeMemoryLimit)
00530        PHP_INI_ENTRY("precision",                              "14",         PHP_INI_ALL,         OnSetPrecision)
00531        PHP_INI_ENTRY("sendmail_from",                          NULL,         PHP_INI_ALL,         NULL)
00532        PHP_INI_ENTRY("sendmail_path",     DEFAULT_SENDMAIL_PATH,      PHP_INI_SYSTEM,             NULL)
00533        PHP_INI_ENTRY("mail.force_extra_parameters",NULL,              PHP_INI_SYSTEM|PHP_INI_PERDIR,            OnChangeMailForceExtra)
00534        PHP_INI_ENTRY("disable_functions",               "",                  PHP_INI_SYSTEM,             NULL)
00535        PHP_INI_ENTRY("disable_classes",                 "",                  PHP_INI_SYSTEM,             NULL)
00536        PHP_INI_ENTRY("max_file_uploads",                "20",                PHP_INI_SYSTEM,             NULL)
00537 
00538        STD_PHP_INI_BOOLEAN("allow_url_fopen",           "1",          PHP_INI_SYSTEM,             OnUpdateBool,        allow_url_fopen,            php_core_globals,           core_globals)
00539        STD_PHP_INI_BOOLEAN("allow_url_include",  "0",          PHP_INI_SYSTEM,             OnUpdateBool,        allow_url_include,          php_core_globals,           core_globals)
00540        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)
00541 
00542        STD_PHP_INI_ENTRY("realpath_cache_size",  "16K",        PHP_INI_SYSTEM,             OnUpdateLong, realpath_cache_size_limit,  virtual_cwd_globals, cwd_globals)
00543        STD_PHP_INI_ENTRY("realpath_cache_ttl",          "120",        PHP_INI_SYSTEM,             OnUpdateLong, realpath_cache_ttl,                virtual_cwd_globals, cwd_globals)
00544 
00545        STD_PHP_INI_ENTRY("user_ini.filename",           ".user.ini",  PHP_INI_SYSTEM,             OnUpdateString,             user_ini_filename,   php_core_globals,           core_globals)
00546        STD_PHP_INI_ENTRY("user_ini.cache_ttl",          "300",               PHP_INI_SYSTEM,             OnUpdateLong,        user_ini_cache_ttl,  php_core_globals,           core_globals)
00547        STD_PHP_INI_BOOLEAN("exit_on_timeout",           "0",          PHP_INI_ALL,         OnUpdateBool,               exit_on_timeout,                   php_core_globals,    core_globals)
00548 #ifdef PHP_WIN32
00549        STD_PHP_INI_BOOLEAN("windows.show_crt_warning",         "0",          PHP_INI_ALL,         OnUpdateBool,               windows_show_crt_warning,                 php_core_globals,    core_globals)
00550 #endif
00551 PHP_INI_END()
00552 /* }}} */
00553 
00554 /* True globals (no need for thread safety */
00555 /* But don't make them a single int bitfield */
00556 static int module_initialized = 0;
00557 static int module_startup = 1;
00558 static int module_shutdown = 0;
00559 
00560 /* {{{ php_during_module_startup */
00561 static int php_during_module_startup(void)
00562 {
00563        return module_startup;
00564 }
00565 /* }}} */
00566 
00567 /* {{{ php_during_module_shutdown */
00568 static int php_during_module_shutdown(void)
00569 {
00570        return module_shutdown;
00571 }
00572 /* }}} */
00573 
00574 /* {{{ php_log_err
00575  */
00576 PHPAPI void php_log_err(char *log_message TSRMLS_DC)
00577 {
00578        int fd = -1;
00579        time_t error_time;
00580 
00581        if (PG(in_error_log)) {
00582               /* prevent recursive invocation */
00583               return;
00584        }
00585        PG(in_error_log) = 1;
00586 
00587        /* Try to use the specified logging location. */
00588        if (PG(error_log) != NULL) {
00589 #ifdef HAVE_SYSLOG_H
00590               if (!strcmp(PG(error_log), "syslog")) {
00591                      php_syslog(LOG_NOTICE, "%s", log_message);
00592                      PG(in_error_log) = 0;
00593                      return;
00594               }
00595 #endif
00596               fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
00597               if (fd != -1) {
00598                      char *tmp;
00599                      int len;
00600                      char *error_time_str;
00601 
00602                      time(&error_time);
00603                      error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0 TSRMLS_CC);
00604                      len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
00605 #ifdef PHP_WIN32
00606                      php_flock(fd, 2);
00607 #endif
00608                      write(fd, tmp, len);
00609                      efree(tmp);
00610                      efree(error_time_str);
00611                      close(fd);
00612                      PG(in_error_log) = 0;
00613                      return;
00614               }
00615        }
00616 
00617        /* Otherwise fall back to the default logging location, if we have one */
00618 
00619        if (sapi_module.log_message) {
00620               sapi_module.log_message(log_message);
00621        }
00622        PG(in_error_log) = 0;
00623 }
00624 /* }}} */
00625 
00626 /* {{{ php_write
00627    wrapper for modules to use PHPWRITE */
00628 PHPAPI int php_write(void *buf, uint size TSRMLS_DC)
00629 {
00630        return PHPWRITE(buf, size);
00631 }
00632 /* }}} */
00633 
00634 /* {{{ php_printf
00635  */
00636 PHPAPI int php_printf(const char *format, ...)
00637 {
00638        va_list args;
00639        int ret;
00640        char *buffer;
00641        int size;
00642        TSRMLS_FETCH();
00643 
00644        va_start(args, format);
00645        size = vspprintf(&buffer, 0, format, args);
00646        ret = PHPWRITE(buffer, size);
00647        efree(buffer);
00648        va_end(args);
00649 
00650        return ret;
00651 }
00652 /* }}} */
00653 
00654 /* {{{ php_verror */
00655 /* php_verror is called from php_error_docref<n> functions.
00656  * Its purpose is to unify error messages and automatically generate clickable
00657  * html error messages if correcponding ini setting (html_errors) is activated.
00658  * See: CODING_STANDARDS for details.
00659  */
00660 PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
00661 {
00662        char *buffer = NULL, *docref_buf = NULL, *target = NULL;
00663        char *docref_target = "", *docref_root = "";
00664        char *p;
00665        int buffer_len = 0;
00666        char *space = "";
00667        char *class_name = "";
00668        char *function;
00669        int origin_len;
00670        char *origin;
00671        char *message;
00672        int is_function = 0;
00673 
00674        /* get error text into buffer and escape for html if necessary */
00675        buffer_len = vspprintf(&buffer, 0, format, args);
00676        if (PG(html_errors)) {
00677               int len;
00678               char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
00679               efree(buffer);
00680               buffer = replace;
00681               buffer_len = len;
00682        }
00683 
00684        /* which function caused the problem if any at all */
00685        if (php_during_module_startup()) {
00686               function = "PHP Startup";
00687        } else if (php_during_module_shutdown()) {
00688               function = "PHP Shutdown";
00689        } else if (EG(current_execute_data) &&
00690                             EG(current_execute_data)->opline &&
00691                             EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
00692        ) {
00693               switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) {
00694                      case ZEND_EVAL:
00695                             function = "eval";
00696                             is_function = 1;
00697                             break;
00698                      case ZEND_INCLUDE:
00699                             function = "include";
00700                             is_function = 1;
00701                             break;
00702                      case ZEND_INCLUDE_ONCE:
00703                             function = "include_once";
00704                             is_function = 1;
00705                             break;
00706                      case ZEND_REQUIRE:
00707                             function = "require";
00708                             is_function = 1;
00709                             break;
00710                      case ZEND_REQUIRE_ONCE:
00711                             function = "require_once";
00712                             is_function = 1;
00713                             break;
00714                      default:
00715                             function = "Unknown";
00716               }
00717        } else {
00718               function = get_active_function_name(TSRMLS_C);
00719               if (!function || !strlen(function)) {
00720                      function = "Unknown";
00721               } else {
00722                      is_function = 1;
00723                      class_name = get_active_class_name(&space TSRMLS_CC);
00724               }
00725        }
00726 
00727        /* if we still have memory then format the origin */
00728        if (is_function) {
00729               origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
00730        } else {
00731               origin_len = spprintf(&origin, 0, "%s", function);
00732        }
00733 
00734        if (PG(html_errors)) {
00735               int len;
00736               char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
00737               efree(origin);
00738               origin = replace;
00739        }
00740 
00741        /* origin and buffer available, so lets come up with the error message */
00742        if (docref && docref[0] == '#') {
00743               docref_target = strchr(docref, '#');
00744               docref = NULL;
00745        }
00746 
00747        /* no docref given but function is known (the default) */
00748        if (!docref && is_function) {
00749               int doclen;
00750               if (space[0] == '\0') {
00751                      doclen = spprintf(&docref_buf, 0, "function.%s", function);
00752               } else {
00753                      doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function);
00754               }
00755               while((p = strchr(docref_buf, '_')) != NULL) {
00756                      *p = '-';
00757               }
00758               docref = php_strtolower(docref_buf, doclen);
00759        }
00760 
00761        /* we have a docref for a function AND
00762         * - we show erroes in html mode OR
00763         * - the user wants to see the links anyway
00764         */
00765        if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) {
00766               if (strncmp(docref, "http://", 7)) {
00767                      /* We don't have 'http://' so we use docref_root */
00768 
00769                      char *ref;  /* temp copy for duplicated docref */
00770 
00771                      docref_root = PG(docref_root);
00772 
00773                      ref = estrdup(docref);
00774                      if (docref_buf) {
00775                             efree(docref_buf);
00776                      }
00777                      docref_buf = ref;
00778                      /* strip of the target if any */
00779                      p = strrchr(ref, '#');
00780                      if (p) {
00781                             target = estrdup(p);
00782                             if (target) {
00783                                    docref_target = target;
00784                                    *p = '\0';
00785                             }
00786                      }
00787                      /* add the extension if it is set in ini */
00788                      if (PG(docref_ext) && strlen(PG(docref_ext))) {
00789                             spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
00790                             efree(ref);
00791                      }
00792                      docref = docref_buf;
00793               }
00794               /* display html formatted or only show the additional links */
00795               if (PG(html_errors)) {
00796                      spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
00797               } else {
00798                      spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
00799               }
00800               if (target) {
00801                      efree(target);
00802               }
00803        } else {
00804               spprintf(&message, 0, "%s: %s", origin, buffer);
00805        }
00806        efree(origin);
00807        if (docref_buf) {
00808               efree(docref_buf);
00809        }
00810 
00811        if (PG(track_errors) && module_initialized && 
00812                      (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) {
00813               if (!EG(active_symbol_table)) {
00814                      zend_rebuild_symbol_table(TSRMLS_C);
00815               }
00816               if (EG(active_symbol_table)) {
00817                      zval *tmp;
00818                      ALLOC_INIT_ZVAL(tmp);
00819                      ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
00820                      zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
00821               }
00822        }
00823        efree(buffer);
00824 
00825        php_error(type, "%s", message);
00826        efree(message);
00827 }
00828 /* }}} */
00829 
00830 /* {{{ php_error_docref0 */
00831 /* See: CODING_STANDARDS for details. */
00832 PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
00833 {
00834        va_list args;
00835 
00836        va_start(args, format);
00837        php_verror(docref, "", type, format, args TSRMLS_CC);
00838        va_end(args);
00839 }
00840 /* }}} */
00841 
00842 /* {{{ php_error_docref1 */
00843 /* See: CODING_STANDARDS for details. */
00844 PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
00845 {
00846        va_list args;
00847 
00848        va_start(args, format);
00849        php_verror(docref, param1, type, format, args TSRMLS_CC);
00850        va_end(args);
00851 }
00852 /* }}} */
00853 
00854 /* {{{ php_error_docref2 */
00855 /* See: CODING_STANDARDS for details. */
00856 PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
00857 {
00858        char *params;
00859        va_list args;
00860 
00861        spprintf(&params, 0, "%s,%s", param1, param2);
00862        va_start(args, format);
00863        php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC);
00864        va_end(args);
00865        if (params) {
00866               efree(params);
00867        }
00868 }
00869 /* }}} */
00870 
00871 #ifdef PHP_WIN32
00872 #define PHP_WIN32_ERROR_MSG_BUFFER_SIZE 512
00873 PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC) {
00874        if (error == 0) {
00875               php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s", strerror(errno));
00876        } else {
00877               char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1];
00878               int buf_len;
00879 
00880               FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
00881               buf_len = strlen(buf);
00882               if (buf_len >= 2) {
00883                      buf[buf_len - 1] = '\0';
00884                      buf[buf_len - 2] = '\0';
00885               }
00886               php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s (code: %lu)", (char *)buf, error);
00887        }
00888 }
00889 #undef PHP_WIN32_ERROR_MSG_BUFFER_SIZE
00890 #endif
00891 
00892 /* {{{ php_html_puts */
00893 PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
00894 {
00895        zend_html_puts(str, size TSRMLS_CC);
00896 }
00897 /* }}} */
00898 
00899 /* {{{ php_error_cb
00900  extended error handling function */
00901 static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
00902 {
00903        char *buffer;
00904        int buffer_len, display;
00905        TSRMLS_FETCH();
00906 
00907        buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
00908 
00909        /* check for repeated errors to be ignored */
00910        if (PG(ignore_repeated_errors) && PG(last_error_message)) {
00911               /* no check for PG(last_error_file) is needed since it cannot
00912                * be NULL if PG(last_error_message) is not NULL */
00913               if (strcmp(PG(last_error_message), buffer)
00914                      || (!PG(ignore_repeated_source)
00915                             && ((PG(last_error_lineno) != (int)error_lineno)
00916                                    || strcmp(PG(last_error_file), error_filename)))) {
00917                      display = 1;
00918               } else {
00919                      display = 0;
00920               }
00921        } else {
00922               display = 1;
00923        }
00924 
00925        /* store the error if it has changed */
00926        if (display) {
00927               if (PG(last_error_message)) {
00928                      free(PG(last_error_message));
00929                      PG(last_error_message) = NULL;
00930               }
00931               if (PG(last_error_file)) {
00932                      free(PG(last_error_file));
00933                      PG(last_error_file) = NULL;
00934               }
00935               if (!error_filename) {
00936                      error_filename = "Unknown";
00937               }
00938               PG(last_error_type) = type;
00939               PG(last_error_message) = strdup(buffer);
00940               PG(last_error_file) = strdup(error_filename);
00941               PG(last_error_lineno) = error_lineno;
00942        }
00943 
00944        /* according to error handling mode, suppress error, throw exception or show it */
00945        if (EG(error_handling) != EH_NORMAL) {
00946               switch (type) {
00947                      case E_ERROR:
00948                      case E_CORE_ERROR:
00949                      case E_COMPILE_ERROR:
00950                      case E_USER_ERROR:
00951                      case E_PARSE:
00952                             /* fatal errors are real errors and cannot be made exceptions */
00953                             break;
00954                      case E_STRICT:
00955                      case E_DEPRECATED:
00956                      case E_USER_DEPRECATED:
00957                             /* for the sake of BC to old damaged code */
00958                             break;
00959                      case E_NOTICE:
00960                      case E_USER_NOTICE:
00961                             /* notices are no errors and are not treated as such like E_WARNINGS */
00962                             break;
00963                      default:
00964                             /* throw an exception if we are in EH_THROW mode
00965                              * but DO NOT overwrite a pending exception
00966                              */
00967                             if (EG(error_handling) == EH_THROW && !EG(exception)) {
00968                                    zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
00969                             }
00970                             efree(buffer);
00971                             return;
00972               }
00973        }
00974 
00975        /* display/log the error if necessary */
00976        if (display && (EG(error_reporting) & type || (type & E_CORE))
00977               && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
00978               char *error_type_str;
00979 
00980               switch (type) {
00981                      case E_ERROR:
00982                      case E_CORE_ERROR:
00983                      case E_COMPILE_ERROR:
00984                      case E_USER_ERROR:
00985                             error_type_str = "Fatal error";
00986                             break;
00987                      case E_RECOVERABLE_ERROR:
00988                             error_type_str = "Catchable fatal error";
00989                             break;
00990                      case E_WARNING:
00991                      case E_CORE_WARNING:
00992                      case E_COMPILE_WARNING:
00993                      case E_USER_WARNING:
00994                             error_type_str = "Warning";
00995                             break;
00996                      case E_PARSE:
00997                             error_type_str = "Parse error";
00998                             break;
00999                      case E_NOTICE:
01000                      case E_USER_NOTICE:
01001                             error_type_str = "Notice";
01002                             break;
01003                      case E_STRICT:
01004                             error_type_str = "Strict Standards";
01005                             break;
01006                      case E_DEPRECATED:
01007                      case E_USER_DEPRECATED:
01008                             error_type_str = "Deprecated";
01009                             break;
01010                      default:
01011                             error_type_str = "Unknown error";
01012                             break;
01013               }
01014 
01015               if (!module_initialized || PG(log_errors)) {
01016                      char *log_buffer;
01017 #ifdef PHP_WIN32
01018                      if ((type == E_CORE_ERROR || type == E_CORE_WARNING) && PG(display_startup_errors)) {
01019                             MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
01020                      }
01021 #endif
01022                      spprintf(&log_buffer, 0, "PHP %s:  %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
01023                      php_log_err(log_buffer TSRMLS_CC);
01024                      efree(log_buffer);
01025               }
01026 
01027               if (PG(display_errors)
01028                      && ((module_initialized && !PG(during_request_startup))
01029                             || (PG(display_startup_errors) 
01030                                    && (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)
01031                                    )
01032                             )
01033                      ) {
01034 
01035                      if (PG(xmlrpc_errors)) {
01036                             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);
01037                      } else {
01038                             char *prepend_string = INI_STR("error_prepend_string");
01039                             char *append_string = INI_STR("error_append_string");
01040 
01041                             if (PG(html_errors)) {
01042                                    if (type == E_ERROR) {
01043                                           int len;
01044                                           char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
01045                                           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));
01046                                           efree(buf);
01047                                    } else {
01048                                           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));
01049                                    }
01050                             } else {
01051                                    /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
01052                                    if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) &&
01053                                           PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
01054                                    ) {
01055 #ifdef PHP_WIN32
01056                                           fprintf(stderr, "%s: %s in %s on line%d\n", error_type_str, buffer, error_filename, error_lineno);
01057                                           fflush(stderr);
01058 #else
01059                                           fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno);
01060 #endif
01061                                    } else {
01062                                           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));
01063                                    }
01064                             }
01065                      }
01066               }
01067 #if ZEND_DEBUG
01068               if (PG(report_zend_debug)) {
01069                      zend_bool trigger_break;
01070 
01071                      switch (type) {
01072                             case E_ERROR:
01073                             case E_CORE_ERROR:
01074                             case E_COMPILE_ERROR:
01075                             case E_USER_ERROR:
01076                                    trigger_break=1;
01077                                    break;
01078                             default:
01079                                    trigger_break=0;
01080                                    break;
01081                      }
01082                      zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
01083               }
01084 #endif
01085        }
01086 
01087        /* Bail out if we can't recover */
01088        switch (type) {
01089               case E_CORE_ERROR:
01090                      if(!module_initialized) {
01091                             /* bad error in module startup - no way we can live with this */
01092                             exit(-2);
01093                      }
01094               /* no break - intentionally */
01095               case E_ERROR:
01096               case E_RECOVERABLE_ERROR:
01097               case E_PARSE:
01098               case E_COMPILE_ERROR:
01099               case E_USER_ERROR:
01100                      EG(exit_status) = 255;
01101                      if (module_initialized) {
01102                             if (!PG(display_errors) &&
01103                                 !SG(headers_sent) &&
01104                                    SG(sapi_headers).http_response_code == 200
01105                             ) {
01106                                    sapi_header_line ctr = {0};
01107 
01108                                    ctr.line = "HTTP/1.0 500 Internal Server Error";
01109                                    ctr.line_len = strlen(ctr.line);
01110                                    sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
01111                             }
01112                             /* the parser would return 1 (failure), we can bail out nicely */
01113                             if (type != E_PARSE) {
01114                                    /* restore memory limit */
01115                                    zend_set_memory_limit(PG(memory_limit));
01116                                    efree(buffer);
01117                                    zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
01118                                    zend_bailout();
01119                                    return;
01120                             }
01121                      }
01122                      break;
01123        }
01124 
01125        /* Log if necessary */
01126        if (!display) {
01127               efree(buffer);
01128               return;
01129        }
01130 
01131        if (PG(track_errors) && module_initialized) {
01132               if (!EG(active_symbol_table)) {
01133                      zend_rebuild_symbol_table(TSRMLS_C);
01134               }
01135               if (EG(active_symbol_table)) {
01136                      zval *tmp;
01137                      ALLOC_INIT_ZVAL(tmp);
01138                      ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
01139                      zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
01140               }
01141        }
01142 
01143        efree(buffer);
01144 }
01145 /* }}} */
01146 
01147 /* {{{ proto bool set_time_limit(int seconds)
01148    Sets the maximum time a script can run */
01149 PHP_FUNCTION(set_time_limit)
01150 {
01151        long new_timeout;
01152        char *new_timeout_str;
01153        int new_timeout_strlen;
01154 
01155        if (PG(safe_mode)) {
01156               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");
01157               RETURN_FALSE;
01158        }
01159 
01160        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) {
01161               return;
01162        }
01163        
01164        new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, "%ld", new_timeout);
01165 
01166        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) {
01167               RETVAL_TRUE;
01168        } else {
01169               RETVAL_FALSE;
01170        }
01171        efree(new_timeout_str);
01172 }
01173 /* }}} */
01174 
01175 /* {{{ php_fopen_wrapper_for_zend
01176  */
01177 static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path TSRMLS_DC)
01178 {
01179        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);
01180 }
01181 /* }}} */
01182 
01183 static void php_zend_stream_closer(void *handle TSRMLS_DC) /* {{{ */
01184 {
01185        php_stream_close((php_stream*)handle);
01186 }
01187 /* }}} */
01188 
01189 static void php_zend_stream_mmap_closer(void *handle TSRMLS_DC) /* {{{ */
01190 {
01191        php_stream_mmap_unmap((php_stream*)handle);
01192        php_zend_stream_closer(handle TSRMLS_CC);
01193 }
01194 /* }}} */
01195 
01196 static size_t php_zend_stream_fsizer(void *handle TSRMLS_DC) /* {{{ */
01197 {
01198        php_stream_statbuf  ssb;
01199        if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
01200               return ssb.sb.st_size;
01201        }
01202        return 0;
01203 }
01204 /* }}} */
01205 
01206 static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
01207 {
01208        return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
01209 }
01210 /* }}} */
01211 
01212 PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC) /* {{{ */
01213 {
01214        char *p;
01215        size_t len, mapped_len;
01216        php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
01217 
01218        if (stream) {
01219 #if HAVE_MMAP
01220               size_t page_size = REAL_PAGE_SIZE;
01221 #endif
01222 
01223               handle->filename = (char*)filename;
01224               handle->free_filename = 0;
01225               handle->handle.stream.handle  = stream;
01226               handle->handle.stream.reader  = (zend_stream_reader_t)_php_stream_read;
01227               handle->handle.stream.fsizer  = php_zend_stream_fsizer;
01228               handle->handle.stream.isatty  = 0;
01229               /* can we mmap immeadiately? */
01230               memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
01231               len = php_zend_stream_fsizer(stream TSRMLS_CC);
01232               if (len != 0
01233 #if HAVE_MMAP
01234               && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD
01235 #endif
01236               && php_stream_mmap_possible(stream)
01237               && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
01238                      handle->handle.stream.closer   = php_zend_stream_mmap_closer;
01239                      handle->handle.stream.mmap.buf = p;
01240                      handle->handle.stream.mmap.len = mapped_len;
01241                      handle->type = ZEND_HANDLE_MAPPED;
01242               } else {
01243                      handle->handle.stream.closer = php_zend_stream_closer;
01244                      handle->type = ZEND_HANDLE_STREAM;
01245               }
01246               /* suppress warning if this stream is not explicitly closed */
01247               php_stream_auto_cleanup(stream);
01248 
01249               return SUCCESS;
01250        }
01251        return FAILURE;
01252 }
01253 /* }}} */
01254 
01255 static char *php_resolve_path_for_zend(const char *filename, int filename_len TSRMLS_DC) /* {{{ */
01256 {
01257        return php_resolve_path(filename, filename_len, PG(include_path) TSRMLS_CC);
01258 }
01259 /* }}} */
01260 
01261 /* {{{ php_get_configuration_directive_for_zend
01262  */
01263 static int php_get_configuration_directive_for_zend(const char *name, uint name_length, zval *contents)
01264 {
01265        zval *retval = cfg_get_entry(name, name_length);
01266 
01267        if (retval) {
01268               *contents = *retval;
01269               return SUCCESS;
01270        } else {
01271               return FAILURE;
01272        }
01273 }
01274 /* }}} */
01275 
01276 /* {{{ php_message_handler_for_zend
01277  */
01278 static void php_message_handler_for_zend(long message, void *data TSRMLS_DC)
01279 {
01280        switch (message) {
01281               case ZMSG_FAILED_INCLUDE_FOPEN:
01282                      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)));
01283                      break;
01284               case ZMSG_FAILED_REQUIRE_FOPEN:
01285                      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)));
01286                      break;
01287               case ZMSG_FAILED_HIGHLIGHT_FOPEN:
01288                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
01289                      break;
01290               case ZMSG_MEMORY_LEAK_DETECTED:
01291               case ZMSG_MEMORY_LEAK_REPEATED:
01292 #if ZEND_DEBUG
01293                      if (EG(error_reporting) & E_WARNING) {
01294                             char memory_leak_buf[1024];
01295 
01296                             if (message==ZMSG_MEMORY_LEAK_DETECTED) {
01297                                    zend_leak_info *t = (zend_leak_info *) data;
01298 
01299                                    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));
01300                                    if (t->orig_filename) {
01301                                           char relay_buf[512];
01302 
01303                                           snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
01304                                           strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
01305                                    }
01306                             } else {
01307                                    unsigned long leak_count = (zend_uintptr_t) data;
01308 
01309                                    snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
01310                             }
01311 #      if defined(PHP_WIN32)
01312                             OutputDebugString(memory_leak_buf);
01313 #      else
01314                             fprintf(stderr, "%s", memory_leak_buf);
01315 #      endif
01316                      }
01317 #endif
01318                      break;
01319               case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
01320 #if ZEND_DEBUG
01321                      if (EG(error_reporting) & E_WARNING) {
01322                             char memory_leak_buf[512];
01323 
01324                             snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data));
01325 #      if defined(PHP_WIN32)
01326                             OutputDebugString(memory_leak_buf);
01327 #      else
01328                             fprintf(stderr, "%s", memory_leak_buf);
01329 #      endif
01330                      }
01331 #endif
01332                      break;
01333               case ZMSG_LOG_SCRIPT_NAME: {
01334                             struct tm *ta, tmbuf;
01335                             time_t curtime;
01336                             char *datetime_str, asctimebuf[52];
01337                             char memory_leak_buf[4096];
01338 
01339                             time(&curtime);
01340                             ta = php_localtime_r(&curtime, &tmbuf);
01341                             datetime_str = php_asctime_r(ta, asctimebuf);
01342                             if (datetime_str) {
01343                                    datetime_str[strlen(datetime_str)-1]=0;   /* get rid of the trailing newline */
01344                                    snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s]  Script:  '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
01345                             } else {
01346                                    snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null]  Script:  '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
01347                             }
01348 #      if defined(PHP_WIN32)
01349                             OutputDebugString(memory_leak_buf);
01350 #      else
01351                             fprintf(stderr, "%s", memory_leak_buf);
01352 #      endif
01353                      }
01354                      break;
01355        }
01356 }
01357 /* }}} */
01358 
01359 
01360 void php_on_timeout(int seconds TSRMLS_DC)
01361 {
01362        PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
01363        zend_set_timeout(EG(timeout_seconds), 1);
01364        if(PG(exit_on_timeout)) sapi_terminate_process(TSRMLS_C);
01365 }
01366 
01367 #if PHP_SIGCHILD
01368 /* {{{ sigchld_handler
01369  */
01370 static void sigchld_handler(int apar)
01371 {
01372        while (waitpid(-1, NULL, WNOHANG) > 0);
01373        signal(SIGCHLD, sigchld_handler);
01374 }
01375 /* }}} */
01376 #endif
01377 
01378 /* {{{ php_start_sapi()
01379  */
01380 static int php_start_sapi(TSRMLS_D)
01381 {
01382        int retval = SUCCESS;
01383 
01384        if(!SG(sapi_started)) {
01385               zend_try {
01386                      PG(during_request_startup) = 1;
01387 
01388                      /* initialize global variables */
01389                      PG(modules_activated) = 0;
01390                      PG(header_is_being_sent) = 0;
01391                      PG(connection_status) = PHP_CONNECTION_NORMAL;
01392 
01393                      zend_activate(TSRMLS_C);
01394                      zend_set_timeout(EG(timeout_seconds), 1);
01395                      zend_activate_modules(TSRMLS_C);
01396                      PG(modules_activated)=1;
01397               } zend_catch {
01398                      retval = FAILURE;
01399               } zend_end_try();
01400 
01401               SG(sapi_started) = 1;
01402        }
01403        return retval;
01404 }
01405 
01406 /* }}} */
01407 
01408 /* {{{ php_request_startup
01409  */
01410 #ifndef APACHE_HOOKS
01411 int php_request_startup(TSRMLS_D)
01412 {
01413        int retval = SUCCESS;
01414 
01415 #ifdef PHP_WIN32
01416        PG(com_initialized) = 0;
01417 #endif
01418 
01419 #if PHP_SIGCHILD
01420        signal(SIGCHLD, sigchld_handler);
01421 #endif
01422 
01423        zend_try {
01424               PG(in_error_log) = 0;
01425               PG(during_request_startup) = 1;
01426 
01427               php_output_activate(TSRMLS_C);
01428 
01429               /* initialize global variables */
01430               PG(modules_activated) = 0;
01431               PG(header_is_being_sent) = 0;
01432               PG(connection_status) = PHP_CONNECTION_NORMAL;
01433               PG(in_user_include) = 0;
01434 
01435               zend_activate(TSRMLS_C);
01436               sapi_activate(TSRMLS_C);
01437 
01438               if (PG(max_input_time) == -1) {
01439                      zend_set_timeout(EG(timeout_seconds), 1);
01440               } else {
01441                      zend_set_timeout(PG(max_input_time), 1);
01442               }
01443 
01444               /* Disable realpath cache if safe_mode or open_basedir are set */
01445               if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
01446                      CWDG(realpath_cache_size_limit) = 0;
01447               }
01448 
01449               if (PG(expose_php)) {
01450                      sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
01451               }
01452 
01453               if (PG(output_handler) && PG(output_handler)[0]) {
01454                      php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
01455               } else if (PG(output_buffering)) {
01456                      if (PG(output_buffering)>1) {
01457                             php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC);
01458                      } else {
01459                             php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
01460                      }
01461               } else if (PG(implicit_flush)) {
01462                      php_start_implicit_flush(TSRMLS_C);
01463               }
01464 
01465               /* We turn this off in php_execute_script() */
01466               /* PG(during_request_startup) = 0; */
01467 
01468               php_hash_environment(TSRMLS_C);
01469               zend_activate_modules(TSRMLS_C);
01470               PG(modules_activated)=1;
01471        } zend_catch {
01472               retval = FAILURE;
01473        } zend_end_try();
01474 
01475        SG(sapi_started) = 1;
01476 
01477        return retval;
01478 }
01479 # else
01480 int php_request_startup(TSRMLS_D)
01481 {
01482        int retval = SUCCESS;
01483 
01484 #if PHP_SIGCHILD
01485        signal(SIGCHLD, sigchld_handler);
01486 #endif
01487 
01488        if (php_start_sapi() == FAILURE) {
01489               return FAILURE;
01490        }
01491 
01492        php_output_activate(TSRMLS_C);
01493        sapi_activate(TSRMLS_C);
01494        php_hash_environment(TSRMLS_C);
01495 
01496        zend_try {
01497               PG(during_request_startup) = 1;
01498               php_output_activate(TSRMLS_C);
01499               if (PG(expose_php)) {
01500                      sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
01501               }
01502        } zend_catch {
01503               retval = FAILURE;
01504        } zend_end_try();
01505 
01506        return retval;
01507 }
01508 # endif
01509 /* }}} */
01510 
01511 /* {{{ php_request_startup_for_hook
01512  */
01513 int php_request_startup_for_hook(TSRMLS_D)
01514 {
01515        int retval = SUCCESS;
01516 
01517 #if PHP_SIGCHLD
01518        signal(SIGCHLD, sigchld_handler);
01519 #endif
01520 
01521        if (php_start_sapi(TSRMLS_C) == FAILURE) {
01522               return FAILURE;
01523        }
01524 
01525        php_output_activate(TSRMLS_C);
01526        sapi_activate_headers_only(TSRMLS_C);
01527        php_hash_environment(TSRMLS_C);
01528 
01529        return retval;
01530 }
01531 /* }}} */
01532 
01533 /* {{{ php_request_shutdown_for_exec
01534  */
01535 void php_request_shutdown_for_exec(void *dummy)
01536 {
01537        TSRMLS_FETCH();
01538 
01539        /* used to close fd's in the 3..255 range here, but it's problematic
01540         */
01541        shutdown_memory_manager(1, 1 TSRMLS_CC);
01542 }
01543 /* }}} */
01544 
01545 /* {{{ php_request_shutdown_for_hook
01546  */
01547 void php_request_shutdown_for_hook(void *dummy)
01548 {
01549        TSRMLS_FETCH();
01550 
01551        if (PG(modules_activated)) zend_try {
01552               php_call_shutdown_functions(TSRMLS_C);
01553        } zend_end_try();
01554 
01555        if (PG(modules_activated)) {
01556               zend_deactivate_modules(TSRMLS_C);
01557               php_free_shutdown_functions(TSRMLS_C);
01558        }
01559 
01560        zend_try {
01561               int i;
01562 
01563               for (i = 0; i < NUM_TRACK_VARS; i++) {
01564                      if (PG(http_globals)[i]) {
01565                             zval_ptr_dtor(&PG(http_globals)[i]);
01566                      }
01567               }
01568        } zend_end_try();
01569 
01570        zend_deactivate(TSRMLS_C);
01571 
01572        zend_try {
01573               sapi_deactivate(TSRMLS_C);
01574        } zend_end_try();
01575 
01576        zend_try {
01577               php_shutdown_stream_hashes(TSRMLS_C);
01578        } zend_end_try();
01579 
01580        zend_try {
01581               shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
01582        } zend_end_try();
01583 
01584        zend_try {
01585               zend_unset_timeout(TSRMLS_C);
01586        } zend_end_try();
01587 }
01588 
01589 /* }}} */
01590 
01591 /* {{{ php_request_shutdown
01592  */
01593 void php_request_shutdown(void *dummy)
01594 {
01595        zend_bool report_memleaks;
01596        TSRMLS_FETCH();
01597 
01598        report_memleaks = PG(report_memleaks);
01599 
01600        /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
01601         * inside zend_executor callback functions.
01602         */
01603        EG(opline_ptr) = NULL;
01604        EG(active_op_array) = NULL;
01605 
01606        php_deactivate_ticks(TSRMLS_C);
01607 
01608        /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
01609        if (PG(modules_activated)) zend_try {
01610               php_call_shutdown_functions(TSRMLS_C);
01611        } zend_end_try();
01612 
01613        /* 2. Call all possible __destruct() functions */
01614        zend_try {
01615               zend_call_destructors(TSRMLS_C);
01616        } zend_end_try();
01617 
01618        /* 3. Flush all output buffers */
01619        zend_try {
01620               zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
01621               if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
01622                             OG(ob_nesting_level) && !OG(active_ob_buffer).chunk_size && PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)) {
01623                      send_buffer = 0;
01624               }
01625               php_end_ob_buffers(send_buffer TSRMLS_CC);
01626        } zend_end_try();
01627 
01628        /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
01629        zend_try {
01630               sapi_send_headers(TSRMLS_C);
01631        } zend_end_try();
01632 
01633        /* 5. Call all extensions RSHUTDOWN functions */
01634        if (PG(modules_activated)) {
01635               zend_deactivate_modules(TSRMLS_C);
01636               php_free_shutdown_functions(TSRMLS_C);
01637        }
01638 
01639        /* 6. Destroy super-globals */
01640        zend_try {
01641               int i;
01642 
01643               for (i=0; i<NUM_TRACK_VARS; i++) {
01644                      if (PG(http_globals)[i]) {
01645                             zval_ptr_dtor(&PG(http_globals)[i]);
01646                      }
01647               }
01648        } zend_end_try();
01649 
01650        /* 6.5 free last error information */
01651        if (PG(last_error_message)) {
01652               free(PG(last_error_message));
01653               PG(last_error_message) = NULL;
01654        }
01655        if (PG(last_error_file)) {
01656               free(PG(last_error_file));
01657               PG(last_error_file) = NULL;
01658        }
01659 
01660        /* 7. Shutdown scanner/executor/compiler and restore ini entries */
01661        zend_deactivate(TSRMLS_C);
01662 
01663        /* 8. Call all extensions post-RSHUTDOWN functions */
01664        zend_try {
01665               zend_post_deactivate_modules(TSRMLS_C);
01666        } zend_end_try();
01667 
01668        /* 9. SAPI related shutdown (free stuff) */
01669        zend_try {
01670               sapi_deactivate(TSRMLS_C);
01671        } zend_end_try();
01672 
01673        /* 10. Destroy stream hashes */
01674        zend_try {
01675               php_shutdown_stream_hashes(TSRMLS_C);
01676        } zend_end_try();
01677 
01678        /* 11. Free Willy (here be crashes) */
01679        zend_try {
01680               shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
01681        } zend_end_try();
01682 
01683        /* 12. Reset max_execution_time */
01684        zend_try {
01685               zend_unset_timeout(TSRMLS_C);
01686        } zend_end_try();
01687 
01688 #ifdef PHP_WIN32
01689        if (PG(com_initialized)) {
01690               CoUninitialize();
01691               PG(com_initialized) = 0;
01692        }
01693 #endif
01694 }
01695 /* }}} */
01696 
01697 /* {{{ php_com_initialize
01698  */
01699 PHPAPI void php_com_initialize(TSRMLS_D)
01700 {
01701 #ifdef PHP_WIN32
01702        if (!PG(com_initialized)) {
01703               if (CoInitialize(NULL) == S_OK) {
01704                      PG(com_initialized) = 1;
01705               }
01706        }
01707 #endif
01708 }
01709 /* }}} */
01710 
01711 /* {{{ php_body_write_wrapper
01712  */
01713 static int php_body_write_wrapper(const char *str, uint str_length)
01714 {
01715        TSRMLS_FETCH();
01716        return php_body_write(str, str_length TSRMLS_CC);
01717 }
01718 /* }}} */
01719 
01720 #ifdef ZTS
01721 /* {{{ core_globals_ctor
01722  */
01723 static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
01724 {
01725        memset(core_globals, 0, sizeof(*core_globals));
01726 
01727        php_startup_ticks(TSRMLS_C);
01728 }
01729 /* }}} */
01730 #endif
01731 
01732 /* {{{ core_globals_dtor
01733  */
01734 static void core_globals_dtor(php_core_globals *core_globals TSRMLS_DC)
01735 {
01736        if (core_globals->last_error_message) {
01737               free(core_globals->last_error_message);
01738        }
01739        if (core_globals->last_error_file) {
01740               free(core_globals->last_error_file);
01741        }
01742        if (core_globals->disable_functions) {
01743               free(core_globals->disable_functions);
01744        }
01745        if (core_globals->disable_classes) {
01746               free(core_globals->disable_classes);
01747        }
01748 
01749        php_shutdown_ticks(TSRMLS_C);
01750 }
01751 /* }}} */
01752 
01753 PHP_MINFO_FUNCTION(php_core) { /* {{{ */
01754        php_info_print_table_start();
01755        php_info_print_table_row(2, "PHP Version", PHP_VERSION);
01756        php_info_print_table_end(); 
01757        DISPLAY_INI_ENTRIES();
01758 }
01759 /* }}} */
01760 
01761 /* {{{ php_register_extensions
01762  */
01763 int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
01764 {
01765        zend_module_entry **end = ptr + count;
01766 
01767        while (ptr < end) {
01768               if (*ptr) {
01769                      if (zend_register_internal_module(*ptr TSRMLS_CC)==NULL) {
01770                             return FAILURE;
01771                      }
01772               }
01773               ptr++;
01774        }
01775        return SUCCESS;
01776 }
01777 /* }}} */
01778 
01779 #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
01780 static _invalid_parameter_handler old_invalid_parameter_handler;
01781 
01782 void dummy_invalid_parameter_handler(
01783               const wchar_t *expression,
01784               const wchar_t *function,
01785               const wchar_t *file,
01786               unsigned int   line,
01787               uintptr_t      pEwserved)
01788 {
01789        static int called = 0;
01790        char buf[1024];
01791        int len;
01792 
01793        if (!called) {
01794               TSRMLS_FETCH();
01795               if(PG(windows_show_crt_warning)) {
01796                      called = 1;
01797                      if (function) {
01798                             if (file) {
01799                                    len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line);
01800                             } else {
01801                                    len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
01802                             }
01803                      } else {
01804                             len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameter detected (function not known)");
01805                      }
01806                      zend_error(E_WARNING, "%s", buf);
01807                      called = 0;
01808               }
01809        }
01810 }
01811 #endif
01812 
01813 /* {{{ php_module_startup
01814  */
01815 int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
01816 {
01817        zend_utility_functions zuf;
01818        zend_utility_values zuv;
01819        int module_number=0; /* for REGISTER_INI_ENTRIES() */
01820        char *php_os;
01821        zend_module_entry *module;
01822 #ifdef ZTS
01823        zend_executor_globals *executor_globals;
01824        void ***tsrm_ls;
01825        php_core_globals *core_globals;
01826 #endif
01827 #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
01828        WORD wVersionRequested = MAKEWORD(2, 0);
01829        WSADATA wsaData;
01830 #endif
01831 #ifdef PHP_WIN32
01832        DWORD dwVersion = GetVersion();
01833        /* Get build numbers for Windows NT or Win95 */
01834        if (dwVersion < 0x80000000){
01835               php_os="WINNT";
01836        } else {
01837               php_os="WIN32";
01838        }
01839 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
01840        old_invalid_parameter_handler =
01841               _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
01842        if (old_invalid_parameter_handler != NULL) {
01843               _set_invalid_parameter_handler(old_invalid_parameter_handler);
01844        }
01845 
01846        /* Disable the message box for assertions.*/
01847        _CrtSetReportMode(_CRT_ASSERT, 0);
01848 #endif
01849 #else
01850        php_os=PHP_OS;
01851 #endif
01852 
01853 #ifdef ZTS
01854        tsrm_ls = ts_resource(0);
01855 #endif
01856 
01857 #ifdef PHP_WIN32
01858        php_win32_init_rng_lock();
01859 #endif
01860 
01861        module_shutdown = 0;
01862        module_startup = 1;
01863        sapi_initialize_empty_request(TSRMLS_C);
01864        sapi_activate(TSRMLS_C);
01865 
01866        if (module_initialized) {
01867               return SUCCESS;
01868        }
01869 
01870        sapi_module = *sf;
01871 
01872        php_output_startup();
01873 
01874        zuf.error_function = php_error_cb;
01875        zuf.printf_function = php_printf;
01876        zuf.write_function = php_body_write_wrapper;
01877        zuf.fopen_function = php_fopen_wrapper_for_zend;
01878        zuf.message_handler = php_message_handler_for_zend;
01879        zuf.block_interruptions = sapi_module.block_interruptions;
01880        zuf.unblock_interruptions = sapi_module.unblock_interruptions;
01881        zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
01882        zuf.ticks_function = php_run_ticks;
01883        zuf.on_timeout = php_on_timeout;
01884        zuf.stream_open_function = php_stream_open_for_zend;
01885        zuf.vspprintf_function = vspprintf;
01886        zuf.getenv_function = sapi_getenv;
01887        zuf.resolve_path_function = php_resolve_path_for_zend;
01888        zend_startup(&zuf, NULL TSRMLS_CC);
01889 
01890 #ifdef ZTS
01891        executor_globals = ts_resource(executor_globals_id);
01892        ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
01893        core_globals = ts_resource(core_globals_id);
01894 #ifdef PHP_WIN32
01895        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);
01896 #endif
01897 #else
01898        php_startup_ticks(TSRMLS_C);
01899 #endif
01900        gc_globals_ctor(TSRMLS_C);
01901 
01902 #ifdef PHP_WIN32
01903        {
01904               OSVERSIONINFOEX *osvi = &EG(windows_version_info);
01905 
01906               ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
01907               osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
01908               if( !GetVersionEx((OSVERSIONINFO *) osvi)) {
01909                      php_printf("\nGetVersionEx unusable. %d\n", GetLastError());
01910                      return FAILURE;
01911               }
01912        }
01913 #endif
01914        EG(bailout) = NULL;
01915        EG(error_reporting) = E_ALL & ~E_NOTICE;
01916        EG(active_symbol_table) = NULL;
01917        PG(header_is_being_sent) = 0;
01918        SG(request_info).headers_only = 0;
01919        SG(request_info).argv0 = NULL;
01920        SG(request_info).argc=0;
01921        SG(request_info).argv=(char **)NULL;
01922        PG(connection_status) = PHP_CONNECTION_NORMAL;
01923        PG(during_request_startup) = 0;
01924        PG(last_error_message) = NULL;
01925        PG(last_error_file) = NULL;
01926        PG(last_error_lineno) = 0;
01927        EG(error_handling)  = EH_NORMAL;
01928        EG(exception_class) = NULL;
01929        PG(disable_functions) = NULL;
01930        PG(disable_classes) = NULL;
01931 
01932 #if HAVE_SETLOCALE
01933        setlocale(LC_CTYPE, "");
01934        zend_update_current_locale();
01935 #endif
01936 
01937 #if HAVE_TZSET
01938        tzset();
01939 #endif
01940 
01941 #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
01942        /* start up winsock services */
01943        if (WSAStartup(wVersionRequested, &wsaData) != 0) {
01944               php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
01945               return FAILURE;
01946        }
01947 #endif
01948 
01949        le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
01950 
01951        /* Register constants */
01952        REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
01953        REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
01954        REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
01955        REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
01956        REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
01957        REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
01958 #ifdef ZTS
01959        REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
01960 #else
01961        REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
01962 #endif
01963        REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
01964        REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
01965        REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
01966        REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
01967        REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
01968        REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
01969        REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
01970        REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
01971        REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
01972 #ifndef PHP_WIN32
01973        REGISTER_MAIN_STRINGL_CONSTANT("PHP_MANDIR", PHP_MANDIR, sizeof(PHP_MANDIR)-1, CONST_PERSISTENT | CONST_CS);
01974 #endif
01975        REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
01976        REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
01977        REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
01978        REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
01979        REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
01980        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);
01981        REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
01982        REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
01983        REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
01984        REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
01985        REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
01986 #ifdef ZEND_MULTIBYTE
01987        REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 1, CONST_PERSISTENT | CONST_CS);
01988 #else
01989        REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 0, CONST_PERSISTENT | CONST_CS);
01990 #endif
01991 
01992 #ifdef PHP_WIN32
01993        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR",      EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
01994        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR",      EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
01995        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD",      EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
01996        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM",   EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
01997        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR",   EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
01998        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR",   EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
01999        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK",  EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
02000        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
02001        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
02002        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
02003        REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
02004 #endif
02005 
02006        php_output_register_constants(TSRMLS_C);
02007        php_rfc1867_register_constants(TSRMLS_C);
02008 
02009        /* this will read in php.ini, set up the configuration parameters,
02010           load zend extensions and register php function extensions
02011           to be loaded later */
02012        if (php_init_config(TSRMLS_C) == FAILURE) {
02013               return FAILURE;
02014        }
02015 
02016        /* Register PHP core ini entries */
02017        REGISTER_INI_ENTRIES();
02018 
02019        /* Register Zend ini entries */
02020        zend_register_standard_ini_entries(TSRMLS_C);
02021 
02022        /* Disable realpath cache if safe_mode or open_basedir are set */
02023        if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
02024               CWDG(realpath_cache_size_limit) = 0;
02025        }
02026 
02027        /* initialize stream wrappers registry
02028         * (this uses configuration parameters from php.ini)
02029         */
02030        if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE)     {
02031               php_printf("PHP:  Unable to initialize stream url wrappers.\n");
02032               return FAILURE;
02033        }
02034 
02035        /* initialize registry for images to be used in phpinfo() 
02036           (this uses configuration parameters from php.ini)
02037         */
02038        if (php_init_info_logos() == FAILURE) {
02039               php_printf("PHP:  Unable to initialize info phpinfo logos.\n");
02040               return FAILURE;
02041        }
02042 
02043        zuv.html_errors = 1;
02044        zuv.import_use_extension = ".php";
02045        php_startup_auto_globals(TSRMLS_C);
02046        zend_set_utility_values(&zuv);
02047        php_startup_sapi_content_types(TSRMLS_C);
02048 
02049        /* startup extensions staticly compiled in */
02050        if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) {
02051               php_printf("Unable to start builtin modules\n");
02052               return FAILURE;
02053        }
02054 
02055        /* start additional PHP extensions */
02056        php_register_extensions(&additional_modules, num_additional_modules TSRMLS_CC);
02057 
02058        /* load and startup extensions compiled as shared objects (aka DLLs)
02059           as requested by php.ini entries
02060           theese are loaded after initialization of internal extensions
02061           as extensions *might* rely on things from ext/standard
02062           which is always an internal extension and to be initialized
02063           ahead of all other internals
02064         */
02065        php_ini_register_extensions(TSRMLS_C);
02066        zend_startup_modules(TSRMLS_C);
02067 
02068        /* start Zend extensions */
02069        zend_startup_extensions();
02070 
02071        /* register additional functions */
02072        if (sapi_module.additional_functions) {
02073               if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {
02074                      EG(current_module) = module;
02075                      zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT TSRMLS_CC);
02076                      EG(current_module) = NULL;
02077               }
02078        }
02079        
02080        /* disable certain classes and functions as requested by php.ini */
02081        php_disable_functions(TSRMLS_C);
02082        php_disable_classes(TSRMLS_C);
02083 
02084        /* make core report what it should */
02085        if (zend_hash_find(&module_registry, "core", sizeof("core"), (void**)&module)==SUCCESS) {
02086               module->version = PHP_VERSION;
02087               module->info_func = PHP_MINFO(php_core);
02088        }
02089 
02090 
02091 #ifdef PHP_WIN32
02092        /* Disable incompatible functions for the running platform */
02093        if (php_win32_disable_functions() == FAILURE) {
02094               php_printf("Unable to disable unsupported functions\n");
02095               return FAILURE;
02096        }
02097 #endif
02098 
02099 #ifdef ZTS
02100        zend_post_startup(TSRMLS_C);
02101 #endif
02102 
02103        module_initialized = 1;
02104 
02105        /* Check for deprecated directives */
02106        /* NOTE: If you add anything here, remember to add it also in Makefile.global! */
02107        {
02108               static const char *directives[] = {
02109                      "define_syslog_variables", 
02110                      "register_globals", 
02111                      "register_long_arrays", 
02112                      "safe_mode", 
02113                      "magic_quotes_gpc", 
02114                      "magic_quotes_runtime", 
02115                      "magic_quotes_sybase", 
02116                      NULL
02117               };
02118               const char **p = directives;
02119               long val;
02120 
02121               while (*p) {
02122                      if (cfg_get_long((char*)*p, &val) == SUCCESS && val) {
02123                             zend_error(E_DEPRECATED, "Directive '%s' is deprecated in PHP 5.3 and greater", *p);
02124                      }
02125                      ++p;
02126               }
02127 
02128               /* This is not too nice, but since its the only one theres no need for extra stuff here */
02129               if (cfg_get_long("zend.ze1_compatibility_mode", &val) == SUCCESS && val) {
02130                      zend_error(E_CORE_ERROR, "zend.ze1_compatibility_mode is no longer supported in PHP 5.3 and greater");
02131               }
02132        }
02133        
02134        sapi_deactivate(TSRMLS_C);
02135        module_startup = 0;
02136 
02137        shutdown_memory_manager(1, 0 TSRMLS_CC);
02138 
02139        /* we're done */
02140        return SUCCESS;
02141 }
02142 /* }}} */
02143 
02144 void php_module_shutdown_for_exec(void)
02145 {
02146        /* used to close fd's in the range 3.255 here, but it's problematic */
02147 }
02148 
02149 /* {{{ php_module_shutdown_wrapper
02150  */
02151 int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
02152 {
02153        TSRMLS_FETCH();
02154        php_module_shutdown(TSRMLS_C);
02155        return SUCCESS;
02156 }
02157 /* }}} */
02158 
02159 /* {{{ php_module_shutdown
02160  */
02161 void php_module_shutdown(TSRMLS_D)
02162 {
02163        int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
02164 
02165        module_shutdown = 1;
02166 
02167        if (!module_initialized) {
02168               return;
02169        }
02170 
02171 #ifdef ZTS
02172        ts_free_worker_threads();
02173 #endif
02174 
02175 #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
02176        /*close winsock */
02177        WSACleanup();
02178 #endif
02179 
02180 #ifdef PHP_WIN32
02181        php_win32_free_rng_lock();
02182 #endif
02183 
02184        sapi_flush(TSRMLS_C);
02185 
02186        zend_shutdown(TSRMLS_C);
02187        
02188        /* Destroys filter & transport registries too */
02189        php_shutdown_stream_wrappers(module_number TSRMLS_CC);
02190 
02191        php_shutdown_info_logos();
02192        UNREGISTER_INI_ENTRIES();
02193 
02194        /* close down the ini config */
02195        php_shutdown_config();
02196 
02197 #ifndef ZTS
02198        zend_ini_shutdown(TSRMLS_C);
02199        shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
02200        core_globals_dtor(&core_globals TSRMLS_CC);
02201        gc_globals_dtor(TSRMLS_C);
02202 #else
02203        zend_ini_global_shutdown(TSRMLS_C);
02204        ts_free_id(core_globals_id);
02205 #endif
02206 
02207        php_shutdown_temporary_directory();
02208 
02209        module_initialized = 0;
02210 
02211 #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
02212        if (old_invalid_parameter_handler == NULL) {
02213               _set_invalid_parameter_handler(old_invalid_parameter_handler);
02214        }
02215 #endif
02216 }
02217 /* }}} */
02218 
02219 /* {{{ php_execute_script
02220  */
02221 PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
02222 {
02223        zend_file_handle *prepend_file_p, *append_file_p;
02224        zend_file_handle prepend_file = {0}, append_file = {0};
02225 #if HAVE_BROKEN_GETCWD 
02226        int old_cwd_fd = -1;
02227 #else
02228        char *old_cwd;
02229        ALLOCA_FLAG(use_heap)
02230 #endif
02231        int retval = 0;
02232 
02233        EG(exit_status) = 0;
02234        if (php_handle_special_queries(TSRMLS_C)) {
02235               zend_file_handle_dtor(primary_file TSRMLS_CC);
02236               return 0;
02237        }
02238 #ifndef HAVE_BROKEN_GETCWD
02239 # define OLD_CWD_SIZE 4096
02240        old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
02241        old_cwd[0] = '\0';
02242 #endif
02243 
02244        zend_try {
02245               char realfile[MAXPATHLEN];
02246 
02247 #ifdef PHP_WIN32
02248               if(primary_file->filename) {
02249                      UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
02250               }
02251 #endif
02252 
02253               PG(during_request_startup) = 0;
02254 
02255               if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
02256 #if HAVE_BROKEN_GETCWD
02257                      /* this looks nasty to me */
02258                      old_cwd_fd = open(".", 0);
02259 #else
02260                      VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
02261 #endif
02262                      VCWD_CHDIR_FILE(primary_file->filename);
02263               }
02264 
02265               /* Only lookup the real file path and add it to the included_files list if already opened
02266                *   otherwise it will get opened and added to the included_files list in zend_execute_scripts
02267                */
02268               if (primary_file->filename &&
02269                   (primary_file->filename[0] != '-' || primary_file->filename[1] != 0) &&
02270                      primary_file->opened_path == NULL &&
02271                      primary_file->type != ZEND_HANDLE_FILENAME
02272               ) {
02273                      int realfile_len;
02274                      int dummy = 1;
02275 
02276                      if (expand_filepath(primary_file->filename, realfile TSRMLS_CC)) {
02277                             realfile_len =  strlen(realfile);
02278                             zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL);
02279                             primary_file->opened_path = estrndup(realfile, realfile_len);
02280                      }
02281               }
02282 
02283               if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
02284                      prepend_file.filename = PG(auto_prepend_file);
02285                      prepend_file.opened_path = NULL;
02286                      prepend_file.free_filename = 0;
02287                      prepend_file.type = ZEND_HANDLE_FILENAME;
02288                      prepend_file_p = &prepend_file;
02289               } else {
02290                      prepend_file_p = NULL;
02291               }
02292 
02293               if (PG(auto_append_file) && PG(auto_append_file)[0]) {
02294                      append_file.filename = PG(auto_append_file);
02295                      append_file.opened_path = NULL;
02296                      append_file.free_filename = 0;
02297                      append_file.type = ZEND_HANDLE_FILENAME;
02298                      append_file_p = &append_file;
02299               } else {
02300                      append_file_p = NULL;
02301               }
02302               if (PG(max_input_time) != -1) {
02303 #ifdef PHP_WIN32
02304                      zend_unset_timeout(TSRMLS_C);
02305 #endif
02306                      zend_set_timeout(INI_INT("max_execution_time"), 0);
02307               }
02308               retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
02309 
02310        } zend_end_try();
02311 
02312 #if HAVE_BROKEN_GETCWD
02313        if (old_cwd_fd != -1) {
02314               fchdir(old_cwd_fd);
02315               close(old_cwd_fd);
02316        }
02317 #else
02318        if (old_cwd[0] != '\0') {
02319               VCWD_CHDIR(old_cwd);
02320        }
02321        free_alloca(old_cwd, use_heap);
02322 #endif
02323        return retval;
02324 }
02325 /* }}} */
02326 
02327 /* {{{ php_execute_simple_script
02328  */
02329 PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
02330 {
02331        char *old_cwd;
02332        ALLOCA_FLAG(use_heap)
02333 
02334        EG(exit_status) = 0;
02335 #define OLD_CWD_SIZE 4096
02336        old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
02337        old_cwd[0] = '\0';
02338 
02339        zend_try {
02340 #ifdef PHP_WIN32
02341               if(primary_file->filename) {
02342                      UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
02343               }
02344 #endif
02345 
02346               PG(during_request_startup) = 0;
02347 
02348               if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
02349                      VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
02350                      VCWD_CHDIR_FILE(primary_file->filename);
02351               }
02352               zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
02353        } zend_end_try();
02354 
02355        if (old_cwd[0] != '\0') {
02356               VCWD_CHDIR(old_cwd);
02357        }
02358 
02359        free_alloca(old_cwd, use_heap);
02360        return EG(exit_status);
02361 }
02362 /* }}} */
02363 
02364 /* {{{ php_handle_aborted_connection
02365  */
02366 PHPAPI void php_handle_aborted_connection(void)
02367 {
02368        TSRMLS_FETCH();
02369 
02370        PG(connection_status) = PHP_CONNECTION_ABORTED;
02371        php_output_set_status(0 TSRMLS_CC);
02372 
02373        if (!PG(ignore_user_abort)) {
02374               zend_bailout();
02375        }
02376 }
02377 /* }}} */
02378 
02379 /* {{{ php_handle_auth_data
02380  */
02381 PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
02382 {
02383        int ret = -1;
02384 
02385        if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
02386               char *pass;
02387               char *user;
02388 
02389               user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL);
02390               if (user) {
02391                      pass = strchr(user, ':');
02392                      if (pass) {
02393                             *pass++ = '\0';
02394                             SG(request_info).auth_user = user;
02395                             SG(request_info).auth_password = estrdup(pass);
02396                             ret = 0;
02397                      } else {
02398                             efree(user);
02399                      }
02400               }
02401        }
02402 
02403        if (ret == -1) {
02404               SG(request_info).auth_user = SG(request_info).auth_password = NULL;
02405        } else {
02406               SG(request_info).auth_digest = NULL;
02407        }
02408 
02409        if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
02410               SG(request_info).auth_digest = estrdup(auth + 7);
02411               ret = 0;
02412        }
02413 
02414        if (ret == -1) {
02415               SG(request_info).auth_digest = NULL;
02416        }
02417 
02418        return ret;
02419 }
02420 /* }}} */
02421 
02422 /* {{{ php_lint_script
02423  */
02424 PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
02425 {
02426        zend_op_array *op_array;
02427        int retval = FAILURE;
02428 
02429        zend_try {
02430               op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
02431               zend_destroy_file_handle(file TSRMLS_CC);
02432 
02433               if (op_array) {
02434                      destroy_op_array(op_array TSRMLS_CC);
02435                      efree(op_array);
02436                      retval = SUCCESS;
02437               }
02438        } zend_end_try();
02439 
02440        return retval;
02441 }
02442 /* }}} */
02443 
02444 #ifdef PHP_WIN32
02445 /* {{{ dummy_indent
02446    just so that this symbol gets exported... */
02447 PHPAPI void dummy_indent(void)
02448 {
02449        zend_indent();
02450 }
02451 /* }}} */
02452 #endif
02453 
02454 /*
02455  * Local variables:
02456  * tab-width: 4
02457  * c-basic-offset: 4
02458  * End:
02459  * vim600: sw=4 ts=4 fdm=marker
02460  * vim<600: sw=4 ts=4
02461  */