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

LCOV - code coverage report
Current view: top level - main - main.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 729 943 77.3 %
Date: 2014-10-30 Functions: 50 60 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Thu, 30 Oct 2014 07:41:45 +0000 (8 hours ago)

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