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 - SAPI.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 414 532 77.8 %
Date: 2016-05-22 Functions: 35 43 81.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2016 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             :    | Original design:  Shane Caraveo <shane@caraveo.com>                  |
      16             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      17             :    |          Zeev Suraski <zeev@zend.com>                                |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include <ctype.h>
      24             : #include <sys/stat.h>
      25             : 
      26             : #include "php.h"
      27             : #include "SAPI.h"
      28             : #include "php_variables.h"
      29             : #include "php_ini.h"
      30             : #include "ext/standard/php_string.h"
      31             : #include "ext/standard/pageinfo.h"
      32             : #if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
      33             : #include "ext/pcre/php_pcre.h"
      34             : #endif
      35             : #ifdef ZTS
      36             : #include "TSRM.h"
      37             : #endif
      38             : #ifdef HAVE_SYS_TIME_H
      39             : #include <sys/time.h>
      40             : #elif defined(PHP_WIN32)
      41             : #include "win32/time.h"
      42             : #endif
      43             : 
      44             : #include "rfc1867.h"
      45             : 
      46             : #include "php_content_types.h"
      47             : 
      48             : #ifdef ZTS
      49             : SAPI_API int sapi_globals_id;
      50             : #else
      51             : sapi_globals_struct sapi_globals;
      52             : #endif
      53             : 
      54       67837 : static void _type_dtor(zval *zv)
      55             : {
      56       67837 :         free(Z_PTR_P(zv));
      57       67837 : }
      58             : 
      59       22587 : static void sapi_globals_ctor(sapi_globals_struct *sapi_globals)
      60             : {
      61             : #ifdef ZTS
      62             :         ZEND_TSRMLS_CACHE_UPDATE();
      63             : #endif
      64       22587 :         memset(sapi_globals, 0, sizeof(*sapi_globals));
      65       22587 :         zend_hash_init_ex(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1, 0);
      66       22587 :         php_setup_sapi_content_types();
      67       22587 : }
      68             : 
      69       22625 : static void sapi_globals_dtor(sapi_globals_struct *sapi_globals)
      70             : {
      71       22625 :         zend_hash_destroy(&sapi_globals->known_post_content_types);
      72       22625 : }
      73             : 
      74             : /* True globals (no need for thread safety) */
      75             : SAPI_API sapi_module_struct sapi_module;
      76             : 
      77             : 
      78       22587 : SAPI_API void sapi_startup(sapi_module_struct *sf)
      79             : {
      80       22587 :         sf->ini_entries = NULL;
      81       22587 :         sapi_module = *sf;
      82             : 
      83             : #ifdef ZTS
      84             :         ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
      85             : # ifdef PHP_WIN32
      86             :         _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
      87             : # endif
      88             : #else
      89       22587 :         sapi_globals_ctor(&sapi_globals);
      90             : #endif
      91             : 
      92             : #ifdef PHP_WIN32
      93             :         tsrm_win32_startup();
      94             : #endif
      95             : 
      96             :         reentrancy_startup();
      97       22587 : }
      98             : 
      99       22625 : SAPI_API void sapi_shutdown(void)
     100             : {
     101             : #ifdef ZTS
     102             :         ts_free_id(sapi_globals_id);
     103             : #else
     104       22625 :         sapi_globals_dtor(&sapi_globals);
     105             : #endif
     106             : 
     107             :         reentrancy_shutdown();
     108             : 
     109             : #ifdef PHP_WIN32
     110             :         tsrm_win32_shutdown();
     111             : #endif
     112       22625 : }
     113             : 
     114             : 
     115       46614 : SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
     116             : {
     117       46614 :         efree(sapi_header->header);
     118       46614 : }
     119             : 
     120             : /* {{{ proto bool header_register_callback(mixed callback)
     121             :    call a header function */
     122           1 : PHP_FUNCTION(header_register_callback)
     123             : {
     124             :         zval *callback_func;
     125             : 
     126           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback_func) == FAILURE) {
     127           0 :                 return;
     128             :         }
     129             : 
     130           1 :         if (!zend_is_callable(callback_func, 0, NULL)) {
     131           0 :                 RETURN_FALSE;
     132             :         }
     133             : 
     134           1 :         if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
     135           0 :                 zval_ptr_dtor(&SG(callback_func));
     136           0 :                 SG(fci_cache) = empty_fcall_info_cache;
     137             :         }
     138             : 
     139           1 :         ZVAL_COPY(&SG(callback_func), callback_func);
     140             : 
     141           1 :         RETURN_TRUE;
     142             : }
     143             : /* }}} */
     144             : 
     145           1 : static void sapi_run_header_callback(zval *callback)
     146             : {
     147             :         int   error;
     148             :         zend_fcall_info fci;
     149           1 :         char *callback_error = NULL;
     150             :         zval retval;
     151             : 
     152           1 :         if (zend_fcall_info_init(callback, 0, &fci, &SG(fci_cache), NULL, &callback_error) == SUCCESS) {
     153           1 :                 fci.retval = &retval;
     154             : 
     155           1 :                 error = zend_call_function(&fci, &SG(fci_cache));
     156           1 :                 if (error == FAILURE) {
     157           0 :                         goto callback_failed;
     158             :                 } else {
     159           1 :                         zval_ptr_dtor(&retval);
     160             :                 }
     161             :         } else {
     162             : callback_failed:
     163           0 :                 php_error_docref(NULL, E_WARNING, "Could not call the sapi_header_callback");
     164             :         }
     165             : 
     166           1 :         if (callback_error) {
     167           0 :                 efree(callback_error);
     168             :         }
     169           1 : }
     170             : 
     171          80 : SAPI_API void sapi_handle_post(void *arg)
     172             : {
     173          80 :         if (SG(request_info).post_entry && SG(request_info).content_type_dup) {
     174          74 :                 SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg);
     175          74 :                 efree(SG(request_info).content_type_dup);
     176          74 :                 SG(request_info).content_type_dup = NULL;
     177             :         }
     178          80 : }
     179             : 
     180          76 : static void sapi_read_post_data(void)
     181             : {
     182             :         sapi_post_entry *post_entry;
     183          76 :         uint content_type_length = (uint)strlen(SG(request_info).content_type);
     184          76 :         char *content_type = estrndup(SG(request_info).content_type, content_type_length);
     185             :         char *p;
     186          76 :         char oldchar=0;
     187          76 :         void (*post_reader_func)(void) = NULL;
     188             : 
     189             : 
     190             :         /* dedicated implementation for increased performance:
     191             :          * - Make the content type lowercase
     192             :          * - Trim descriptive data, stay with the content-type only
     193             :          */
     194        2089 :         for (p=content_type; p<content_type+content_type_length; p++) {
     195        2013 :                 switch (*p) {
     196             :                         case ';':
     197             :                         case ',':
     198             :                         case ' ':
     199          37 :                                 content_type_length = p-content_type;
     200          37 :                                 oldchar = *p;
     201          37 :                                 *p = 0;
     202          37 :                                 break;
     203             :                         default:
     204        1976 :                                 *p = tolower(*p);
     205             :                                 break;
     206             :                 }
     207             :         }
     208             : 
     209             :         /* now try to find an appropriate POST content handler */
     210         152 :         if ((post_entry = zend_hash_str_find_ptr(&SG(known_post_content_types), content_type,
     211             :                         content_type_length)) != NULL) {
     212             :                 /* found one, register it for use */
     213          76 :                 SG(request_info).post_entry = post_entry;
     214          76 :                 post_reader_func = post_entry->post_reader;
     215             :         } else {
     216             :                 /* fallback */
     217           0 :                 SG(request_info).post_entry = NULL;
     218           0 :                 if (!sapi_module.default_post_reader) {
     219             :                         /* no default reader ? */
     220           0 :                         SG(request_info).content_type_dup = NULL;
     221           0 :                         sapi_module.sapi_error(E_WARNING, "Unsupported content type:  '%s'", content_type);
     222           0 :                         return;
     223             :                 }
     224             :         }
     225          76 :         if (oldchar) {
     226          37 :                 *(p-1) = oldchar;
     227             :         }
     228             : 
     229          76 :         SG(request_info).content_type_dup = content_type;
     230             : 
     231          76 :         if(post_reader_func) {
     232          38 :                 post_reader_func();
     233             :         }
     234             : 
     235          76 :         if(sapi_module.default_post_reader) {
     236          76 :                 sapi_module.default_post_reader();
     237             :         }
     238             : }
     239             : 
     240         409 : SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen)
     241             : {
     242             :         size_t read_bytes;
     243             : 
     244         409 :         if (!sapi_module.read_post) {
     245           0 :                 return 0;
     246             :         }
     247             : 
     248         409 :         read_bytes = sapi_module.read_post(buffer, buflen);
     249             : 
     250         409 :         if (read_bytes > 0) {
     251             :                 /* gogo */
     252          48 :                 SG(read_post_bytes) += read_bytes;
     253             :         }
     254         409 :         if (read_bytes < buflen) {
     255             :                 /* done */
     256         407 :                 SG(post_read) = 1;
     257             :         }
     258             : 
     259         409 :         return read_bytes;
     260             : }
     261             : 
     262          38 : SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
     263             : {
     264          38 :         if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) {
     265           1 :                 php_error_docref(NULL, E_WARNING, "POST Content-Length of %pd bytes exceeds the limit of %pd bytes",
     266             :                                         SG(request_info).content_length, SG(post_max_size));
     267           1 :                 return;
     268             :         }
     269             : 
     270             : 
     271          37 :         SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir));
     272             : 
     273          37 :         if (sapi_module.read_post) {
     274             :                 size_t read_bytes;
     275             : 
     276             :                 for (;;) {
     277             :                         char buffer[SAPI_POST_BLOCK_SIZE];
     278             : 
     279          37 :                         read_bytes = sapi_read_post_block(buffer, SAPI_POST_BLOCK_SIZE);
     280             : 
     281          37 :                         if (read_bytes > 0) {
     282          37 :                                 if (php_stream_write(SG(request_info).request_body, buffer, read_bytes) != read_bytes) {
     283             :                                         /* if parts of the stream can't be written, purge it completely */
     284           1 :                                         php_stream_truncate_set_size(SG(request_info).request_body, 0);
     285           1 :                                         php_error_docref(NULL, E_WARNING, "POST data can't be buffered; all data discarded");
     286           1 :                                         break;
     287             :                                 }
     288             :                         }
     289             : 
     290          36 :                         if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) {
     291           0 :                                 php_error_docref(NULL, E_WARNING, "Actual POST length does not match Content-Length, and exceeds " ZEND_LONG_FMT " bytes", SG(post_max_size));
     292           0 :                                 break;
     293             :                         }
     294             : 
     295          36 :                         if (read_bytes < SAPI_POST_BLOCK_SIZE) {
     296             :                                 /* done */
     297          36 :                                 break;
     298             :                         }
     299           0 :                 }
     300          37 :                 php_stream_rewind(SG(request_info).request_body);
     301             :         }
     302             : }
     303             : 
     304             : 
     305       22282 : static inline char *get_default_content_type(uint prefix_len, uint *len)
     306             : {
     307             :         char *mimetype, *charset, *content_type;
     308             :         uint mimetype_len, charset_len;
     309             : 
     310       22282 :         if (SG(default_mimetype)) {
     311       22282 :                 mimetype = SG(default_mimetype);
     312       22282 :                 mimetype_len = (uint)strlen(SG(default_mimetype));
     313             :         } else {
     314           0 :                 mimetype = SAPI_DEFAULT_MIMETYPE;
     315           0 :                 mimetype_len = sizeof(SAPI_DEFAULT_MIMETYPE) - 1;
     316             :         }
     317       22282 :         if (SG(default_charset)) {
     318       22282 :                 charset = SG(default_charset);
     319       22282 :                 charset_len = (uint)strlen(SG(default_charset));
     320             :         } else {
     321           0 :                 charset = SAPI_DEFAULT_CHARSET;
     322           0 :                 charset_len = sizeof(SAPI_DEFAULT_CHARSET) - 1;
     323             :         }
     324             : 
     325       44554 :         if (*charset && strncasecmp(mimetype, "text/", 5) == 0) {
     326             :                 char *p;
     327             : 
     328       22272 :                 *len = prefix_len + mimetype_len + sizeof("; charset=") - 1 + charset_len;
     329       22272 :                 content_type = (char*)emalloc(*len + 1);
     330       22272 :                 p = content_type + prefix_len;
     331       22272 :                 memcpy(p, mimetype, mimetype_len);
     332       22272 :                 p += mimetype_len;
     333       22272 :                 memcpy(p, "; charset=", sizeof("; charset=") - 1);
     334       22272 :                 p += sizeof("; charset=") - 1;
     335       22272 :                 memcpy(p, charset, charset_len + 1);
     336             :         } else {
     337          10 :                 *len = prefix_len + mimetype_len;
     338          10 :                 content_type = (char*)emalloc(*len + 1);
     339          10 :                 memcpy(content_type + prefix_len, mimetype, mimetype_len + 1);
     340             :         }
     341       22282 :         return content_type;
     342             : }
     343             : 
     344             : 
     345           0 : SAPI_API char *sapi_get_default_content_type(void)
     346             : {
     347             :         uint len;
     348             : 
     349           0 :         return get_default_content_type(0, &len);
     350             : }
     351             : 
     352             : 
     353           0 : SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header)
     354             : {
     355             :     uint len;
     356             : 
     357           0 :         default_header->header = get_default_content_type(sizeof("Content-type: ")-1, &len);
     358           0 :         default_header->header_len = len;
     359           0 :         memcpy(default_header->header, "Content-type: ", sizeof("Content-type: ") - 1);
     360           0 : }
     361             : 
     362             : /*
     363             :  * Add charset on content-type header if the MIME type starts with
     364             :  * "text/", the default_charset directive is not empty and
     365             :  * there is not already a charset option in there.
     366             :  *
     367             :  * If "mimetype" is non-NULL, it should point to a pointer allocated
     368             :  * with emalloc().  If a charset is added, the string will be
     369             :  * re-allocated and the new length is returned.  If mimetype is
     370             :  * unchanged, 0 is returned.
     371             :  *
     372             :  */
     373         194 : SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len)
     374             : {
     375             :         char *charset, *newtype;
     376             :         size_t newlen;
     377         194 :         charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
     378             : 
     379         194 :         if (*mimetype != NULL) {
     380         194 :                 if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) {
     381          12 :                         newlen = len + (sizeof(";charset=")-1) + strlen(charset);
     382          12 :                         newtype = emalloc(newlen + 1);
     383          12 :                         PHP_STRLCPY(newtype, *mimetype, newlen + 1, len);
     384          12 :                         strlcat(newtype, ";charset=", newlen + 1);
     385          12 :                         strlcat(newtype, charset, newlen + 1);
     386          12 :                         efree(*mimetype);
     387          12 :                         *mimetype = newtype;
     388          12 :                         return newlen;
     389             :                 }
     390             :         }
     391         182 :         return 0;
     392             : }
     393             : 
     394           0 : SAPI_API void sapi_activate_headers_only(void)
     395             : {
     396           0 :         if (SG(request_info).headers_read == 1)
     397           0 :                 return;
     398           0 :         SG(request_info).headers_read = 1;
     399           0 :         zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct),
     400             :                         (void (*)(void *)) sapi_free_header, 0);
     401           0 :         SG(sapi_headers).send_default_content_type = 1;
     402             : 
     403             :         /* SG(sapi_headers).http_response_code = 200; */
     404           0 :         SG(sapi_headers).http_status_line = NULL;
     405           0 :         SG(sapi_headers).mimetype = NULL;
     406           0 :         SG(read_post_bytes) = 0;
     407           0 :         SG(request_info).request_body = NULL;
     408           0 :         SG(request_info).current_user = NULL;
     409           0 :         SG(request_info).current_user_length = 0;
     410           0 :         SG(request_info).no_headers = 0;
     411           0 :         SG(request_info).post_entry = NULL;
     412           0 :         SG(global_request_time) = 0;
     413             : 
     414             :         /*
     415             :          * It's possible to override this general case in the activate() callback,
     416             :          * if necessary.
     417             :          */
     418           0 :         if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
     419           0 :                 SG(request_info).headers_only = 1;
     420             :         } else {
     421           0 :                 SG(request_info).headers_only = 0;
     422             :         }
     423           0 :         if (SG(server_context)) {
     424           0 :                 SG(request_info).cookie_data = sapi_module.read_cookies();
     425           0 :                 if (sapi_module.activate) {
     426           0 :                         sapi_module.activate();
     427             :                 }
     428             :         }
     429           0 :         if (sapi_module.input_filter_init ) {
     430           0 :                 sapi_module.input_filter_init();
     431             :         }
     432             : }
     433             : 
     434             : /*
     435             :  * Called from php_request_startup() for every request.
     436             :  */
     437             : 
     438       45128 : SAPI_API void sapi_activate(void)
     439             : {
     440       45128 :         zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
     441       45128 :         SG(sapi_headers).send_default_content_type = 1;
     442             : 
     443             :         /*
     444             :         SG(sapi_headers).http_response_code = 200;
     445             :         */
     446       45128 :         SG(sapi_headers).http_status_line = NULL;
     447       45128 :         SG(sapi_headers).mimetype = NULL;
     448       45128 :         SG(headers_sent) = 0;
     449       45128 :         ZVAL_UNDEF(&SG(callback_func));
     450       45128 :         SG(read_post_bytes) = 0;
     451       45128 :         SG(request_info).request_body = NULL;
     452       45128 :         SG(request_info).current_user = NULL;
     453       45128 :         SG(request_info).current_user_length = 0;
     454       45128 :         SG(request_info).no_headers = 0;
     455       45128 :         SG(request_info).post_entry = NULL;
     456       45128 :         SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
     457       45128 :         SG(global_request_time) = 0;
     458       45128 :         SG(post_read) = 0;
     459             :         /* It's possible to override this general case in the activate() callback, if necessary. */
     460       45128 :         if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
     461           0 :                 SG(request_info).headers_only = 1;
     462             :         } else {
     463       45128 :                 SG(request_info).headers_only = 0;
     464             :         }
     465       45128 :         SG(rfc1867_uploaded_files) = NULL;
     466             : 
     467             :         /* Handle request method */
     468       45128 :         if (SG(server_context)) {
     469        1322 :                 if (PG(enable_post_data_reading)
     470             :                 &&      SG(request_info).content_type
     471         405 :                 &&  SG(request_info).request_method
     472         430 :                 && !strcmp(SG(request_info).request_method, "POST")) {
     473             :                         /* HTTP POST may contain form data to be processed into variables
     474             :                          * depending on given content type */
     475          76 :                         sapi_read_post_data();
     476             :                 } else {
     477         335 :                         SG(request_info).content_type_dup = NULL;
     478             :                 }
     479             : 
     480             :                 /* Cookies */
     481         411 :                 SG(request_info).cookie_data = sapi_module.read_cookies();
     482             : 
     483         411 :                 if (sapi_module.activate) {
     484         411 :                         sapi_module.activate();
     485             :                 }
     486             :         }
     487       45128 :         if (sapi_module.input_filter_init) {
     488       22541 :                 sapi_module.input_filter_init();
     489             :         }
     490       45128 : }
     491             : 
     492             : 
     493       67676 : static void sapi_send_headers_free(void)
     494             : {
     495       67676 :         if (SG(sapi_headers).http_status_line) {
     496         157 :                 efree(SG(sapi_headers).http_status_line);
     497         157 :                 SG(sapi_headers).http_status_line = NULL;
     498             :         }
     499       67676 : }
     500             : 
     501       45210 : SAPI_API void sapi_deactivate(void)
     502             : {
     503       45210 :         zend_llist_destroy(&SG(sapi_headers).headers);
     504       45210 :         if (SG(request_info).request_body) {
     505          44 :                 SG(request_info).request_body = NULL;
     506       45166 :         } else if (SG(server_context)) {
     507         365 :                 if (!SG(post_read)) {
     508             :                         /* make sure we've consumed all request input data */
     509             :                         char dummy[SAPI_POST_BLOCK_SIZE];
     510             :                         size_t read_bytes;
     511             : 
     512             :                         do {
     513         365 :                                 read_bytes = sapi_read_post_block(dummy, SAPI_POST_BLOCK_SIZE);
     514         365 :                         } while (SAPI_POST_BLOCK_SIZE == read_bytes);
     515             :                 }
     516             :         }
     517       45210 :         if (SG(request_info).auth_user) {
     518           0 :                 efree(SG(request_info).auth_user);
     519             :         }
     520       45210 :         if (SG(request_info).auth_password) {
     521           0 :                 efree(SG(request_info).auth_password);
     522             :         }
     523       45210 :         if (SG(request_info).auth_digest) {
     524           0 :                 efree(SG(request_info).auth_digest);
     525             :         }
     526       45210 :         if (SG(request_info).content_type_dup) {
     527           2 :                 efree(SG(request_info).content_type_dup);
     528             :         }
     529       45210 :         if (SG(request_info).current_user) {
     530           9 :                 efree(SG(request_info).current_user);
     531             :         }
     532       45210 :         if (sapi_module.deactivate) {
     533       45210 :                 sapi_module.deactivate();
     534             :         }
     535       45210 :         if (SG(rfc1867_uploaded_files)) {
     536          35 :                 destroy_uploaded_files_hash();
     537             :         }
     538       45210 :         if (SG(sapi_headers).mimetype) {
     539       22413 :                 efree(SG(sapi_headers).mimetype);
     540       22413 :                 SG(sapi_headers).mimetype = NULL;
     541             :         }
     542       45210 :         sapi_send_headers_free();
     543       45210 :         SG(sapi_started) = 0;
     544       45210 :         SG(headers_sent) = 0;
     545       45210 :         SG(request_info).headers_read = 0;
     546       45210 :         SG(global_request_time) = 0;
     547       45210 : }
     548             : 
     549             : 
     550       22587 : SAPI_API void sapi_initialize_empty_request(void)
     551             : {
     552       22587 :         SG(server_context) = NULL;
     553       22587 :         SG(request_info).request_method = NULL;
     554       22587 :         SG(request_info).auth_digest = SG(request_info).auth_user = SG(request_info).auth_password = NULL;
     555       22587 :         SG(request_info).content_type_dup = NULL;
     556       22587 : }
     557             : 
     558             : 
     559         158 : static int sapi_extract_response_code(const char *header_line)
     560             : {
     561         158 :         int code = 200;
     562             :         const char *ptr;
     563             : 
     564        1422 :         for (ptr = header_line; *ptr; ptr++) {
     565        1422 :                 if (*ptr == ' ' && *(ptr + 1) != ' ') {
     566         158 :                         code = atoi(ptr + 1);
     567         158 :                         break;
     568             :                 }
     569             :         }
     570             : 
     571         158 :         return code;
     572             : }
     573             : 
     574             : 
     575         165 : static void sapi_update_response_code(int ncode)
     576             : {
     577             :         /* if the status code did not change, we do not want
     578             :            to change the status line, and no need to change the code */
     579         165 :         if (SG(sapi_headers).http_response_code == ncode) {
     580           2 :                 return;
     581             :         }
     582             : 
     583         163 :         if (SG(sapi_headers).http_status_line) {
     584           1 :                 efree(SG(sapi_headers).http_status_line);
     585           1 :                 SG(sapi_headers).http_status_line = NULL;
     586             :         }
     587         163 :         SG(sapi_headers).http_response_code = ncode;
     588             : }
     589             : 
     590             : /*
     591             :  * since zend_llist_del_element only remove one matched item once,
     592             :  * we should remove them by ourself
     593             :  */
     594         539 : static void sapi_remove_header(zend_llist *l, char *name, size_t len) {
     595             :         sapi_header_struct *header;
     596             :         zend_llist_element *next;
     597         539 :         zend_llist_element *current=l->head;
     598             : 
     599        1290 :         while (current) {
     600         212 :                 header = (sapi_header_struct *)(current->data);
     601         212 :                 next = current->next;
     602         246 :                 if (header->header_len > len && header->header[len] == ':'
     603          34 :                                 && !strncasecmp(header->header, name, len)) {
     604           4 :                         if (current->prev) {
     605           4 :                                 current->prev->next = next;
     606             :                         } else {
     607           0 :                                 l->head = next;
     608             :                         }
     609           4 :                         if (next) {
     610           2 :                                 next->prev = current->prev;
     611             :                         } else {
     612           2 :                                 l->tail = current->prev;
     613             :                         }
     614           4 :                         sapi_free_header(header);
     615           4 :                         efree(current);
     616           4 :                         --l->count;
     617             :                 }
     618         212 :                 current = next;
     619             :         }
     620         539 : }
     621             : 
     622       24905 : SAPI_API int sapi_add_header_ex(char *header_line, size_t header_line_len, zend_bool duplicate, zend_bool replace)
     623             : {
     624       24905 :         sapi_header_line ctr = {0};
     625             :         int r;
     626             : 
     627       24905 :         ctr.line = header_line;
     628       24905 :         ctr.line_len = header_line_len;
     629             : 
     630       24905 :         r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD,
     631             :                         &ctr);
     632             : 
     633       24905 :         if (!duplicate)
     634         344 :                 efree(header_line);
     635             : 
     636       24905 :         return r;
     637             : }
     638             : 
     639       46620 : static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_header)
     640             : {
     641       93240 :         if (!sapi_module.header_handler ||
     642       45839 :                 (SAPI_HEADER_ADD & sapi_module.header_handler(sapi_header, op, &SG(sapi_headers)))) {
     643         781 :                 if (op == SAPI_HEADER_REPLACE) {
     644         536 :                         char *colon_offset = strchr(sapi_header->header, ':');
     645             : 
     646         536 :                         if (colon_offset) {
     647         536 :                                 char sav = *colon_offset;
     648             : 
     649         536 :                                 *colon_offset = 0;
     650         536 :                         sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, (int)strlen(sapi_header->header));
     651         536 :                                 *colon_offset = sav;
     652             :                         }
     653             :                 }
     654         781 :                 zend_llist_add_element(&SG(sapi_headers).headers, (void *) sapi_header);
     655             :         } else {
     656       45839 :                 sapi_free_header(sapi_header);
     657             :         }
     658       46620 : }
     659             : 
     660       25067 : SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
     661             : {
     662             :         sapi_header_struct sapi_header;
     663             :         char *colon_offset;
     664             :         char *header_line;
     665             :         size_t header_line_len;
     666             :         int http_response_code;
     667             : 
     668       25067 :         if (SG(headers_sent) && !SG(request_info).no_headers) {
     669         558 :                 const char *output_start_filename = php_output_get_start_filename();
     670         558 :                 int output_start_lineno = php_output_get_start_lineno();
     671             : 
     672         558 :                 if (output_start_filename) {
     673         556 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)",
     674             :                                 output_start_filename, output_start_lineno);
     675             :                 } else {
     676           2 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent");
     677             :                 }
     678         558 :                 return FAILURE;
     679             :         }
     680             : 
     681       24509 :         switch (op) {
     682             :                 case SAPI_HEADER_SET_STATUS:
     683           0 :                         sapi_update_response_code((int)(zend_intptr_t) arg);
     684           0 :                         return SUCCESS;
     685             : 
     686             :                 case SAPI_HEADER_ADD:
     687             :                 case SAPI_HEADER_REPLACE:
     688             :                 case SAPI_HEADER_DELETE: {
     689       24507 :                                 sapi_header_line *p = arg;
     690             : 
     691       24507 :                                 if (!p->line || !p->line_len) {
     692           1 :                                         return FAILURE;
     693             :                                 }
     694       24506 :                                 header_line = p->line;
     695       24506 :                                 header_line_len = p->line_len;
     696       24506 :                                 http_response_code = p->response_code;
     697       24506 :                                 break;
     698             :                         }
     699             : 
     700             :                 case SAPI_HEADER_DELETE_ALL:
     701           2 :                         if (sapi_module.header_handler) {
     702           0 :                                 sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers));
     703             :                         }
     704           2 :                         zend_llist_clean(&SG(sapi_headers).headers);
     705           2 :                         return SUCCESS;
     706             : 
     707             :                 default:
     708           0 :                         return FAILURE;
     709             :         }
     710             : 
     711       24506 :         header_line = estrndup(header_line, header_line_len);
     712             : 
     713             :         /* cut off trailing spaces, linefeeds and carriage-returns */
     714       24506 :         if (header_line_len && isspace(header_line[header_line_len-1])) {
     715             :                 do {
     716           7 :                         header_line_len--;
     717           7 :                 } while(header_line_len && isspace(header_line[header_line_len-1]));
     718           3 :                 header_line[header_line_len]='\0';
     719             :         }
     720             : 
     721       24506 :         if (op == SAPI_HEADER_DELETE) {
     722           6 :                 if (strchr(header_line, ':')) {
     723           3 :                         efree(header_line);
     724           3 :                         sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon.");
     725           3 :                         return FAILURE;
     726             :                 }
     727           3 :                 if (sapi_module.header_handler) {
     728           0 :                         sapi_header.header = header_line;
     729           0 :                         sapi_header.header_len = header_line_len;
     730           0 :                         sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers));
     731             :                 }
     732           3 :                 sapi_remove_header(&SG(sapi_headers).headers, header_line, header_line_len);
     733           3 :                 efree(header_line);
     734           3 :                 return SUCCESS;
     735             :         } else {
     736             :                 /* new line/NUL character safety check */
     737             :                 uint i;
     738      704921 :                 for (i = 0; i < header_line_len; i++) {
     739             :                         /* RFC 7230 ch. 3.2.4 deprecates folding support */
     740      680425 :                         if (header_line[i] == '\n' || header_line[i] == '\r') {
     741           3 :                                 efree(header_line);
     742           3 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain "
     743             :                                                 "more than a single header, new line detected");
     744           3 :                                 return FAILURE;
     745             :                         }
     746      680422 :                         if (header_line[i] == '\0') {
     747           1 :                                 efree(header_line);
     748           1 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain NUL bytes");
     749           1 :                                 return FAILURE;
     750             :                         }
     751             :                 }
     752             :         }
     753             : 
     754       24496 :         sapi_header.header = header_line;
     755       24496 :         sapi_header.header_len = header_line_len;
     756             : 
     757             :         /* Check the header for a few cases that we have special support for in SAPI */
     758       48992 :         if (header_line_len>=5
     759       24496 :                 && !strncasecmp(header_line, "HTTP/", 5)) {
     760             :                 /* filter out the response code */
     761         158 :                 sapi_update_response_code(sapi_extract_response_code(header_line));
     762             :                 /* sapi_update_response_code doesn't free the status line if the code didn't change */
     763         158 :                 if (SG(sapi_headers).http_status_line) {
     764           0 :                         efree(SG(sapi_headers).http_status_line);
     765             :                 }
     766         158 :                 SG(sapi_headers).http_status_line = header_line;
     767         158 :                 return SUCCESS;
     768             :         } else {
     769       24338 :                 colon_offset = strchr(header_line, ':');
     770       24338 :                 if (colon_offset) {
     771       24337 :                         *colon_offset = 0;
     772       24337 :                         if (!strcasecmp(header_line, "Content-Type")) {
     773         194 :                                 char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
     774         194 :                                 size_t len = header_line_len - (ptr - header_line), newlen;
     775         580 :                                 while (*ptr == ' ') {
     776         192 :                                         ptr++;
     777         192 :                                         len--;
     778             :                                 }
     779             : 
     780             :                                 /* Disable possible output compression for images */
     781         194 :                                 if (!strncmp(ptr, "image/", sizeof("image/")-1)) {
     782           4 :                                         zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
     783           4 :                                         zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
     784             :                                         zend_string_release(key);
     785             :                                 }
     786             : 
     787         194 :                                 mimetype = estrdup(ptr);
     788         194 :                                 newlen = sapi_apply_default_charset(&mimetype, len);
     789         194 :                                 if (!SG(sapi_headers).mimetype){
     790         183 :                                         SG(sapi_headers).mimetype = estrdup(mimetype);
     791             :                                 }
     792             : 
     793         194 :                                 if (newlen != 0) {
     794          12 :                                         newlen += sizeof("Content-type: ");
     795          12 :                                         newheader = emalloc(newlen);
     796          12 :                                         PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1);
     797          12 :                                         strlcat(newheader, mimetype, newlen);
     798          12 :                                         sapi_header.header = newheader;
     799          12 :                                         sapi_header.header_len = (uint)(newlen - 1);
     800          12 :                                         efree(header_line);
     801             :                                 }
     802         194 :                                 efree(mimetype);
     803         194 :                                 SG(sapi_headers).send_default_content_type = 0;
     804       24143 :                         } else if (!strcasecmp(header_line, "Content-Length")) {
     805             :                                 /* Script is setting Content-length. The script cannot reasonably
     806             :                                  * know the size of the message body after compression, so it's best
     807             :                                  * do disable compression altogether. This contributes to making scripts
     808             :                                  * portable between setups that have and don't have zlib compression
     809             :                                  * enabled globally. See req #44164 */
     810         246 :                                 zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
     811         246 :                                 zend_alter_ini_entry_chars(key,
     812             :                                         "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
     813             :                                 zend_string_release(key);
     814       23897 :                         } else if (!strcasecmp(header_line, "Location")) {
     815          53 :                                 if ((SG(sapi_headers).http_response_code < 300 ||
     816          22 :                                         SG(sapi_headers).http_response_code > 399) &&
     817           5 :                                         SG(sapi_headers).http_response_code != 201) {
     818             :                                         /* Return a Found Redirect if one is not already specified */
     819           4 :                                         if (http_response_code) { /* user specified redirect code */
     820           2 :                                                 sapi_update_response_code(http_response_code);
     821           2 :                                         } else if (SG(request_info).proto_num > 1000 &&
     822           0 :                                            SG(request_info).request_method &&
     823           0 :                                            strcmp(SG(request_info).request_method, "HEAD") &&
     824           0 :                                            strcmp(SG(request_info).request_method, "GET")) {
     825           0 :                                                 sapi_update_response_code(303);
     826             :                                         } else {
     827           2 :                                                 sapi_update_response_code(302);
     828             :                                         }
     829             :                                 }
     830       23871 :                         } else if (!strcasecmp(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
     831           0 :                                 sapi_update_response_code(401); /* authentication-required */
     832             :                         }
     833       24337 :                         if (sapi_header.header==header_line) {
     834       24325 :                                 *colon_offset = ':';
     835             :                         }
     836             :                 }
     837             :         }
     838       24338 :         if (http_response_code) {
     839           3 :                 sapi_update_response_code(http_response_code);
     840             :         }
     841       24338 :         sapi_header_add_op(op, &sapi_header);
     842       24338 :         return SUCCESS;
     843             : }
     844             : 
     845             : 
     846       22466 : SAPI_API int sapi_send_headers(void)
     847             : {
     848             :         int retval;
     849       22466 :         int ret = FAILURE;
     850             : 
     851       22466 :         if (SG(headers_sent) || SG(request_info).no_headers) {
     852           0 :                 return SUCCESS;
     853             :         }
     854             : 
     855             :         /* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
     856             :          * in case of an error situation.
     857             :          */
     858       22466 :         if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) {
     859             :                 sapi_header_struct default_header;
     860             :             uint len;
     861             : 
     862       22282 :                 SG(sapi_headers).mimetype = get_default_content_type(0, &len);
     863       22282 :                 default_header.header_len = sizeof("Content-type: ") - 1 + len;
     864       22282 :                 default_header.header = emalloc(default_header.header_len + 1);
     865       22282 :                 memcpy(default_header.header, "Content-type: ", sizeof("Content-type: ") - 1);
     866       22282 :                 memcpy(default_header.header + sizeof("Content-type: ") - 1, SG(sapi_headers).mimetype, len + 1);
     867       22282 :                 sapi_header_add_op(SAPI_HEADER_ADD, &default_header);
     868       22282 :                 SG(sapi_headers).send_default_content_type = 0;
     869             :         }
     870             : 
     871       22466 :         if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
     872             :                 zval cb;
     873           1 :                 ZVAL_COPY_VALUE(&cb, &SG(callback_func));
     874           1 :                 ZVAL_UNDEF(&SG(callback_func));
     875           1 :                 sapi_run_header_callback(&cb);
     876           1 :                 zval_ptr_dtor(&cb);
     877             :         }
     878             : 
     879       22466 :         SG(headers_sent) = 1;
     880             : 
     881       22466 :         if (sapi_module.send_headers) {
     882       22466 :                 retval = sapi_module.send_headers(&SG(sapi_headers));
     883             :         } else {
     884           0 :                 retval = SAPI_HEADER_DO_SEND;
     885             :         }
     886             : 
     887       22466 :         switch (retval) {
     888             :                 case SAPI_HEADER_SENT_SUCCESSFULLY:
     889       22466 :                         ret = SUCCESS;
     890       22466 :                         break;
     891             :                 case SAPI_HEADER_DO_SEND: {
     892             :                                 sapi_header_struct http_status_line;
     893             :                                 char buf[255];
     894             : 
     895           0 :                                 if (SG(sapi_headers).http_status_line) {
     896           0 :                                         http_status_line.header = SG(sapi_headers).http_status_line;
     897           0 :                                         http_status_line.header_len = (uint)strlen(SG(sapi_headers).http_status_line);
     898             :                                 } else {
     899           0 :                                         http_status_line.header = buf;
     900           0 :                                         http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
     901             :                                 }
     902           0 :                                 sapi_module.send_header(&http_status_line, SG(server_context));
     903             :                         }
     904           0 :                         zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context));
     905           0 :                         if(SG(sapi_headers).send_default_content_type) {
     906             :                                 sapi_header_struct default_header;
     907             : 
     908           0 :                                 sapi_get_default_content_type_header(&default_header);
     909           0 :                                 sapi_module.send_header(&default_header, SG(server_context));
     910           0 :                                 sapi_free_header(&default_header);
     911             :                         }
     912           0 :                         sapi_module.send_header(NULL, SG(server_context));
     913           0 :                         ret = SUCCESS;
     914           0 :                         break;
     915             :                 case SAPI_HEADER_SEND_FAILED:
     916           0 :                         SG(headers_sent) = 0;
     917           0 :                         ret = FAILURE;
     918             :                         break;
     919             :         }
     920             : 
     921       22466 :         sapi_send_headers_free();
     922             : 
     923       22466 :         return ret;
     924             : }
     925             : 
     926             : 
     927       45188 : SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries)
     928             : {
     929       45188 :         sapi_post_entry *p=post_entries;
     930             : 
     931      158137 :         while (p->content_type) {
     932       90362 :                 if (sapi_register_post_entry(p) == FAILURE) {
     933       22601 :                         return FAILURE;
     934             :                 }
     935       67761 :                 p++;
     936             :         }
     937       22587 :         return SUCCESS;
     938             : }
     939             : 
     940             : 
     941       90362 : SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry)
     942             : {
     943       90362 :         if (SG(sapi_started) && EG(current_execute_data)) {
     944           0 :                 return FAILURE;
     945             :         }
     946      180724 :         return zend_hash_str_add_mem(&SG(known_post_content_types),
     947      180724 :                         post_entry->content_type, post_entry->content_type_len,
     948             :                         (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE;
     949             : }
     950             : 
     951       22587 : SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry)
     952             : {
     953       22587 :         if (SG(sapi_started) && EG(current_execute_data)) {
     954           0 :                 return;
     955             :         }
     956       22587 :         zend_hash_str_del(&SG(known_post_content_types), post_entry->content_type,
     957       22587 :                         post_entry->content_type_len);
     958             : }
     959             : 
     960             : 
     961       22587 : SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void))
     962             : {
     963       22587 :         if (SG(sapi_started) && EG(current_execute_data)) {
     964           0 :                 return FAILURE;
     965             :         }
     966       22587 :         sapi_module.default_post_reader = default_post_reader;
     967       22587 :         return SUCCESS;
     968             : }
     969             : 
     970             : 
     971       45174 : SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray))
     972             : {
     973       45174 :         if (SG(sapi_started) && EG(current_execute_data)) {
     974           0 :                 return FAILURE;
     975             :         }
     976       45174 :         sapi_module.treat_data = treat_data;
     977       45174 :         return SUCCESS;
     978             : }
     979             : 
     980       45174 : SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void))
     981             : {
     982       45174 :         if (SG(sapi_started) && EG(current_execute_data)) {
     983           0 :                 return FAILURE;
     984             :         }
     985       45174 :         sapi_module.input_filter = input_filter;
     986       45174 :         sapi_module.input_filter_init = input_filter_init;
     987       45174 :         return SUCCESS;
     988             : }
     989             : 
     990      983304 : SAPI_API int sapi_flush(void)
     991             : {
     992      983304 :         if (sapi_module.flush) {
     993      983304 :                 sapi_module.flush(SG(server_context));
     994      983304 :                 return SUCCESS;
     995             :         } else {
     996           0 :                 return FAILURE;
     997             :         }
     998             : }
     999             : 
    1000          19 : SAPI_API zend_stat_t *sapi_get_stat(void)
    1001             : {
    1002          19 :         if (sapi_module.get_stat) {
    1003           0 :                 return sapi_module.get_stat();
    1004             :         } else {
    1005          19 :                 if (!SG(request_info).path_translated || (VCWD_STAT(SG(request_info).path_translated, &SG(global_stat)) == -1)) {
    1006           0 :                         return NULL;
    1007             :                 }
    1008          19 :                 return &SG(global_stat);
    1009             :         }
    1010             : }
    1011             : 
    1012       28899 : SAPI_API char *sapi_getenv(char *name, size_t name_len)
    1013             : {
    1014       28899 :         if (sapi_module.getenv) {
    1015           8 :                 char *value, *tmp = sapi_module.getenv(name, name_len);
    1016           8 :                 if (tmp) {
    1017           8 :                         value = estrdup(tmp);
    1018             :                 } else {
    1019           0 :                         return NULL;
    1020             :                 }
    1021           8 :                 if (sapi_module.input_filter) {
    1022           8 :                         sapi_module.input_filter(PARSE_STRING, name, &value, strlen(value), NULL);
    1023             :                 }
    1024           8 :                 return value;
    1025             :         }
    1026       28891 :         return NULL;
    1027             : }
    1028             : 
    1029           0 : SAPI_API int sapi_get_fd(int *fd)
    1030             : {
    1031           0 :         if (sapi_module.get_fd) {
    1032           0 :                 return sapi_module.get_fd(fd);
    1033             :         } else {
    1034           0 :                 return FAILURE;
    1035             :         }
    1036             : }
    1037             : 
    1038           0 : SAPI_API int sapi_force_http_10(void)
    1039             : {
    1040           0 :         if (sapi_module.force_http_10) {
    1041           0 :                 return sapi_module.force_http_10();
    1042             :         } else {
    1043           0 :                 return FAILURE;
    1044             :         }
    1045             : }
    1046             : 
    1047             : 
    1048           0 : SAPI_API int sapi_get_target_uid(uid_t *obj)
    1049             : {
    1050           0 :         if (sapi_module.get_target_uid) {
    1051           0 :                 return sapi_module.get_target_uid(obj);
    1052             :         } else {
    1053           0 :                 return FAILURE;
    1054             :         }
    1055             : }
    1056             : 
    1057           0 : SAPI_API int sapi_get_target_gid(gid_t *obj)
    1058             : {
    1059           0 :         if (sapi_module.get_target_gid) {
    1060           0 :                 return sapi_module.get_target_gid(obj);
    1061             :         } else {
    1062           0 :                 return FAILURE;
    1063             :         }
    1064             : }
    1065             : 
    1066       22574 : SAPI_API double sapi_get_request_time(void)
    1067             : {
    1068       22574 :         if(SG(global_request_time)) return SG(global_request_time);
    1069             : 
    1070       22574 :         if (sapi_module.get_request_time && SG(server_context)) {
    1071           0 :                 SG(global_request_time) = sapi_module.get_request_time();
    1072             :         } else {
    1073       22574 :                 struct timeval tp = {0};
    1074       22574 :                 if (!gettimeofday(&tp, NULL)) {
    1075       22574 :                         SG(global_request_time) = (double)(tp.tv_sec + tp.tv_usec / 1000000.00);
    1076             :                 } else {
    1077           0 :                         SG(global_request_time) = (double)time(0);
    1078             :                 }
    1079             :         }
    1080       22574 :         return SG(global_request_time);
    1081             : }
    1082             : 
    1083           0 : SAPI_API void sapi_terminate_process(void) {
    1084           0 :         if (sapi_module.terminate_process) {
    1085           0 :                 sapi_module.terminate_process();
    1086             :         }
    1087           0 : }
    1088             : 
    1089             : /*
    1090             :  * Local variables:
    1091             :  * tab-width: 4
    1092             :  * c-basic-offset: 4
    1093             :  * End:
    1094             :  * vim600: sw=4 ts=4 fdm=marker
    1095             :  * vim<600: sw=4 ts=4
    1096             :  */

Generated by: LCOV version 1.10

Generated at Sun, 22 May 2016 10:53:09 +0000 (3 days ago)

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