PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_5_3/main - main.c
Test: PHP Code Coverage
Date: 2009-11-21 Instrumented lines: 842
Code covered: 74.1 % Executed lines: 624
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Sat, 21 Nov 2009 12:27:16 +0000 (3 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.