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: 418 538 77.7 %
Date: 2016-09-27 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       71892 : static void _type_dtor(zval *zv)
      55             : {
      56       71892 :         free(Z_PTR_P(zv));
      57       71892 : }
      58             : 
      59       23950 : static void sapi_globals_ctor(sapi_globals_struct *sapi_globals)
      60             : {
      61             : #ifdef ZTS
      62             :         ZEND_TSRMLS_CACHE_UPDATE();
      63             : #endif
      64       23950 :         memset(sapi_globals, 0, sizeof(*sapi_globals));
      65       23950 :         zend_hash_init_ex(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1, 0);
      66       23950 :         php_setup_sapi_content_types();
      67       23950 : }
      68             : 
      69       23971 : static void sapi_globals_dtor(sapi_globals_struct *sapi_globals)
      70             : {
      71       23971 :         zend_hash_destroy(&sapi_globals->known_post_content_types);
      72       23971 : }
      73             : 
      74             : /* True globals (no need for thread safety) */
      75             : SAPI_API sapi_module_struct sapi_module;
      76             : 
      77             : 
      78       23950 : SAPI_API void sapi_startup(sapi_module_struct *sf)
      79             : {
      80       23950 :         sf->ini_entries = NULL;
      81       23950 :         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       23950 :         sapi_globals_ctor(&sapi_globals);
      90             : #endif
      91             : 
      92             : #ifdef PHP_WIN32
      93             :         tsrm_win32_startup();
      94             : #endif
      95             : 
      96             :         reentrancy_startup();
      97       23950 : }
      98             : 
      99       23971 : SAPI_API void sapi_shutdown(void)
     100             : {
     101             : #ifdef ZTS
     102             :         ts_free_id(sapi_globals_id);
     103             : #else
     104       23971 :         sapi_globals_dtor(&sapi_globals);
     105             : #endif
     106             : 
     107             :         reentrancy_shutdown();
     108             : 
     109             : #ifdef PHP_WIN32
     110             :         tsrm_win32_shutdown();
     111             : #endif
     112       23971 : }
     113             : 
     114             : 
     115       49414 : SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
     116             : {
     117       49414 :         efree(sapi_header->header);
     118       49414 : }
     119             : 
     120             : /* {{{ proto bool header_register_callback(mixed callback)
     121             :    call a header function */
     122           2 : PHP_FUNCTION(header_register_callback)
     123             : {
     124             :         zval *callback_func;
     125             : 
     126           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback_func) == FAILURE) {
     127           0 :                 return;
     128             :         }
     129             : 
     130           2 :         if (!zend_is_callable(callback_func, 0, NULL)) {
     131           0 :                 RETURN_FALSE;
     132             :         }
     133             : 
     134           2 :         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           2 :         ZVAL_COPY(&SG(callback_func), callback_func);
     140             : 
     141           2 :         RETURN_TRUE;
     142             : }
     143             : /* }}} */
     144             : 
     145           2 : static void sapi_run_header_callback(zval *callback)
     146             : {
     147             :         int   error;
     148             :         zend_fcall_info fci;
     149           2 :         char *callback_error = NULL;
     150             :         zval retval;
     151             : 
     152           2 :         if (zend_fcall_info_init(callback, 0, &fci, &SG(fci_cache), NULL, &callback_error) == SUCCESS) {
     153           2 :                 fci.retval = &retval;
     154             : 
     155           2 :                 error = zend_call_function(&fci, &SG(fci_cache));
     156           2 :                 if (error == FAILURE) {
     157           0 :                         goto callback_failed;
     158             :                 } else {
     159           2 :                         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           2 :         if (callback_error) {
     167           0 :                 efree(callback_error);
     168             :         }
     169           2 : }
     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         411 : SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen)
     241             : {
     242             :         size_t read_bytes;
     243             : 
     244         411 :         if (!sapi_module.read_post) {
     245           0 :                 return 0;
     246             :         }
     247             : 
     248         411 :         read_bytes = sapi_module.read_post(buffer, buflen);
     249             : 
     250         411 :         if (read_bytes > 0) {
     251             :                 /* gogo */
     252          48 :                 SG(read_post_bytes) += read_bytes;
     253             :         }
     254         411 :         if (read_bytes < buflen) {
     255             :                 /* done */
     256         409 :                 SG(post_read) = 1;
     257             :         }
     258             : 
     259         411 :         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 " ZEND_LONG_FMT " bytes exceeds the limit of " ZEND_LONG_FMT " 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       23651 : 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       23651 :         if (SG(default_mimetype)) {
     311       23651 :                 mimetype = SG(default_mimetype);
     312       23651 :                 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       23651 :         if (SG(default_charset)) {
     318       23651 :                 charset = SG(default_charset);
     319       23651 :                 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       47292 :         if (*charset && strncasecmp(mimetype, "text/", 5) == 0) {
     326             :                 char *p;
     327             : 
     328       23641 :                 *len = prefix_len + mimetype_len + sizeof("; charset=") - 1 + charset_len;
     329       23641 :                 content_type = (char*)emalloc(*len + 1);
     330       23641 :                 p = content_type + prefix_len;
     331       23641 :                 memcpy(p, mimetype, mimetype_len);
     332       23641 :                 p += mimetype_len;
     333       23641 :                 memcpy(p, "; charset=", sizeof("; charset=") - 1);
     334       23641 :                 p += sizeof("; charset=") - 1;
     335       23641 :                 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       23651 :         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       47854 : SAPI_API void sapi_activate(void)
     439             : {
     440       47854 :         zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
     441       47854 :         SG(sapi_headers).send_default_content_type = 1;
     442             : 
     443             :         /*
     444             :         SG(sapi_headers).http_response_code = 200;
     445             :         */
     446       47854 :         SG(sapi_headers).http_status_line = NULL;
     447       47854 :         SG(sapi_headers).mimetype = NULL;
     448       47854 :         SG(headers_sent) = 0;
     449       47854 :         ZVAL_UNDEF(&SG(callback_func));
     450       47854 :         SG(read_post_bytes) = 0;
     451       47854 :         SG(request_info).request_body = NULL;
     452       47854 :         SG(request_info).current_user = NULL;
     453       47854 :         SG(request_info).current_user_length = 0;
     454       47854 :         SG(request_info).no_headers = 0;
     455       47854 :         SG(request_info).post_entry = NULL;
     456       47854 :         SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
     457       47854 :         SG(global_request_time) = 0;
     458       47854 :         SG(post_read) = 0;
     459             :         /* It's possible to override this general case in the activate() callback, if necessary. */
     460       47854 :         if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
     461           0 :                 SG(request_info).headers_only = 1;
     462             :         } else {
     463       47854 :                 SG(request_info).headers_only = 0;
     464             :         }
     465       47854 :         SG(rfc1867_uploaded_files) = NULL;
     466             : 
     467             :         /* Handle request method */
     468       47854 :         if (SG(server_context)) {
     469        1330 :                 if (PG(enable_post_data_reading)
     470             :                 &&      SG(request_info).content_type
     471         407 :                 &&  SG(request_info).request_method
     472         434 :                 && !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         337 :                         SG(request_info).content_type_dup = NULL;
     478             :                 }
     479             : 
     480             :                 /* Cookies */
     481         413 :                 SG(request_info).cookie_data = sapi_module.read_cookies();
     482             :         }
     483       47854 :         if (sapi_module.activate) {
     484         952 :                 sapi_module.activate();
     485             :         }
     486       47854 :         if (sapi_module.input_filter_init) {
     487       23904 :                 sapi_module.input_filter_init();
     488             :         }
     489       47854 : }
     490             : 
     491             : 
     492       71755 : static void sapi_send_headers_free(void)
     493             : {
     494       71755 :         if (SG(sapi_headers).http_status_line) {
     495         157 :                 efree(SG(sapi_headers).http_status_line);
     496         157 :                 SG(sapi_headers).http_status_line = NULL;
     497             :         }
     498       71755 : }
     499             : 
     500       47919 : SAPI_API void sapi_deactivate(void)
     501             : {
     502       47919 :         zend_llist_destroy(&SG(sapi_headers).headers);
     503       47919 :         if (SG(request_info).request_body) {
     504          44 :                 SG(request_info).request_body = NULL;
     505       47875 :         } else if (SG(server_context)) {
     506         367 :                 if (!SG(post_read)) {
     507             :                         /* make sure we've consumed all request input data */
     508             :                         char dummy[SAPI_POST_BLOCK_SIZE];
     509             :                         size_t read_bytes;
     510             : 
     511             :                         do {
     512         367 :                                 read_bytes = sapi_read_post_block(dummy, SAPI_POST_BLOCK_SIZE);
     513         367 :                         } while (SAPI_POST_BLOCK_SIZE == read_bytes);
     514             :                 }
     515             :         }
     516       47919 :         if (SG(request_info).auth_user) {
     517           0 :                 efree(SG(request_info).auth_user);
     518             :         }
     519       47919 :         if (SG(request_info).auth_password) {
     520           0 :                 efree(SG(request_info).auth_password);
     521             :         }
     522       47919 :         if (SG(request_info).auth_digest) {
     523           0 :                 efree(SG(request_info).auth_digest);
     524             :         }
     525       47919 :         if (SG(request_info).content_type_dup) {
     526           2 :                 efree(SG(request_info).content_type_dup);
     527             :         }
     528       47919 :         if (SG(request_info).current_user) {
     529           9 :                 efree(SG(request_info).current_user);
     530             :         }
     531       47919 :         if (sapi_module.deactivate) {
     532       47919 :                 sapi_module.deactivate();
     533             :         }
     534       47919 :         if (SG(rfc1867_uploaded_files)) {
     535          35 :                 destroy_uploaded_files_hash();
     536             :         }
     537       47919 :         if (SG(sapi_headers).mimetype) {
     538       23759 :                 efree(SG(sapi_headers).mimetype);
     539       23759 :                 SG(sapi_headers).mimetype = NULL;
     540             :         }
     541       47919 :         sapi_send_headers_free();
     542       47919 :         SG(sapi_started) = 0;
     543       47919 :         SG(headers_sent) = 0;
     544       47919 :         SG(request_info).headers_read = 0;
     545       47919 :         SG(global_request_time) = 0;
     546       47919 : }
     547             : 
     548             : 
     549       23950 : SAPI_API void sapi_initialize_empty_request(void)
     550             : {
     551       23950 :         SG(server_context) = NULL;
     552       23950 :         SG(request_info).request_method = NULL;
     553       23950 :         SG(request_info).auth_digest = SG(request_info).auth_user = SG(request_info).auth_password = NULL;
     554       23950 :         SG(request_info).content_type_dup = NULL;
     555       23950 : }
     556             : 
     557             : 
     558         158 : static int sapi_extract_response_code(const char *header_line)
     559             : {
     560         158 :         int code = 200;
     561             :         const char *ptr;
     562             : 
     563        1422 :         for (ptr = header_line; *ptr; ptr++) {
     564        1422 :                 if (*ptr == ' ' && *(ptr + 1) != ' ') {
     565         158 :                         code = atoi(ptr + 1);
     566         158 :                         break;
     567             :                 }
     568             :         }
     569             : 
     570         158 :         return code;
     571             : }
     572             : 
     573             : 
     574         165 : static void sapi_update_response_code(int ncode)
     575             : {
     576             :         /* if the status code did not change, we do not want
     577             :            to change the status line, and no need to change the code */
     578         165 :         if (SG(sapi_headers).http_response_code == ncode) {
     579           2 :                 return;
     580             :         }
     581             : 
     582         163 :         if (SG(sapi_headers).http_status_line) {
     583           1 :                 efree(SG(sapi_headers).http_status_line);
     584           1 :                 SG(sapi_headers).http_status_line = NULL;
     585             :         }
     586         163 :         SG(sapi_headers).http_response_code = ncode;
     587             : }
     588             : 
     589             : /*
     590             :  * since zend_llist_del_element only remove one matched item once,
     591             :  * we should remove them by ourself
     592             :  */
     593         550 : static void sapi_remove_header(zend_llist *l, char *name, size_t len) {
     594             :         sapi_header_struct *header;
     595             :         zend_llist_element *next;
     596         550 :         zend_llist_element *current=l->head;
     597             : 
     598        1336 :         while (current) {
     599         236 :                 header = (sapi_header_struct *)(current->data);
     600         236 :                 next = current->next;
     601         273 :                 if (header->header_len > len && header->header[len] == ':'
     602          37 :                                 && !strncasecmp(header->header, name, len)) {
     603           7 :                         if (current->prev) {
     604           7 :                                 current->prev->next = next;
     605             :                         } else {
     606           0 :                                 l->head = next;
     607             :                         }
     608           7 :                         if (next) {
     609           5 :                                 next->prev = current->prev;
     610             :                         } else {
     611           2 :                                 l->tail = current->prev;
     612             :                         }
     613           7 :                         sapi_free_header(header);
     614           7 :                         efree(current);
     615           7 :                         --l->count;
     616             :                 }
     617         236 :                 current = next;
     618             :         }
     619         550 : }
     620             : 
     621       26336 : SAPI_API int sapi_add_header_ex(char *header_line, size_t header_line_len, zend_bool duplicate, zend_bool replace)
     622             : {
     623       26336 :         sapi_header_line ctr = {0};
     624             :         int r;
     625             : 
     626       26336 :         ctr.line = header_line;
     627       26336 :         ctr.line_len = header_line_len;
     628             : 
     629       26336 :         r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD,
     630             :                         &ctr);
     631             : 
     632       26336 :         if (!duplicate)
     633         355 :                 efree(header_line);
     634             : 
     635       26336 :         return r;
     636             : }
     637             : 
     638       49420 : static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_header)
     639             : {
     640       98840 :         if (!sapi_module.header_handler ||
     641       48626 :                 (SAPI_HEADER_ADD & sapi_module.header_handler(sapi_header, op, &SG(sapi_headers)))) {
     642         794 :                 if (op == SAPI_HEADER_REPLACE) {
     643         547 :                         char *colon_offset = strchr(sapi_header->header, ':');
     644             : 
     645         547 :                         if (colon_offset) {
     646         547 :                                 char sav = *colon_offset;
     647             : 
     648         547 :                                 *colon_offset = 0;
     649         547 :                         sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, (int)strlen(sapi_header->header));
     650         547 :                                 *colon_offset = sav;
     651             :                         }
     652             :                 }
     653         794 :                 zend_llist_add_element(&SG(sapi_headers).headers, (void *) sapi_header);
     654             :         } else {
     655       48626 :                 sapi_free_header(sapi_header);
     656             :         }
     657       49420 : }
     658             : 
     659       26498 : SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
     660             : {
     661             :         sapi_header_struct sapi_header;
     662             :         char *colon_offset;
     663             :         char *header_line;
     664             :         size_t header_line_len;
     665             :         int http_response_code;
     666             : 
     667       26498 :         if (SG(headers_sent) && !SG(request_info).no_headers) {
     668         558 :                 const char *output_start_filename = php_output_get_start_filename();
     669         558 :                 int output_start_lineno = php_output_get_start_lineno();
     670             : 
     671         558 :                 if (output_start_filename) {
     672         556 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)",
     673             :                                 output_start_filename, output_start_lineno);
     674             :                 } else {
     675           2 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent");
     676             :                 }
     677         558 :                 return FAILURE;
     678             :         }
     679             : 
     680       25940 :         switch (op) {
     681             :                 case SAPI_HEADER_SET_STATUS:
     682           0 :                         sapi_update_response_code((int)(zend_intptr_t) arg);
     683           0 :                         return SUCCESS;
     684             : 
     685             :                 case SAPI_HEADER_ADD:
     686             :                 case SAPI_HEADER_REPLACE:
     687             :                 case SAPI_HEADER_DELETE: {
     688       25938 :                                 sapi_header_line *p = arg;
     689             : 
     690       25938 :                                 if (!p->line || !p->line_len) {
     691           1 :                                         return FAILURE;
     692             :                                 }
     693       25937 :                                 header_line = p->line;
     694       25937 :                                 header_line_len = p->line_len;
     695       25937 :                                 http_response_code = p->response_code;
     696       25937 :                                 break;
     697             :                         }
     698             : 
     699             :                 case SAPI_HEADER_DELETE_ALL:
     700           2 :                         if (sapi_module.header_handler) {
     701           0 :                                 sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers));
     702             :                         }
     703           2 :                         zend_llist_clean(&SG(sapi_headers).headers);
     704           2 :                         return SUCCESS;
     705             : 
     706             :                 default:
     707           0 :                         return FAILURE;
     708             :         }
     709             : 
     710       25937 :         header_line = estrndup(header_line, header_line_len);
     711             : 
     712             :         /* cut off trailing spaces, linefeeds and carriage-returns */
     713       25937 :         if (header_line_len && isspace(header_line[header_line_len-1])) {
     714             :                 do {
     715           7 :                         header_line_len--;
     716           7 :                 } while(header_line_len && isspace(header_line[header_line_len-1]));
     717           3 :                 header_line[header_line_len]='\0';
     718             :         }
     719             : 
     720       25937 :         if (op == SAPI_HEADER_DELETE) {
     721           6 :                 if (strchr(header_line, ':')) {
     722           3 :                         efree(header_line);
     723           3 :                         sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon.");
     724           3 :                         return FAILURE;
     725             :                 }
     726           3 :                 if (sapi_module.header_handler) {
     727           0 :                         sapi_header.header = header_line;
     728           0 :                         sapi_header.header_len = header_line_len;
     729           0 :                         sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers));
     730             :                 }
     731           3 :                 sapi_remove_header(&SG(sapi_headers).headers, header_line, header_line_len);
     732           3 :                 efree(header_line);
     733           3 :                 return SUCCESS;
     734             :         } else {
     735             :                 /* new line/NUL character safety check */
     736             :                 uint i;
     737      745522 :                 for (i = 0; i < header_line_len; i++) {
     738             :                         /* RFC 7230 ch. 3.2.4 deprecates folding support */
     739      719595 :                         if (header_line[i] == '\n' || header_line[i] == '\r') {
     740           3 :                                 efree(header_line);
     741           3 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain "
     742             :                                                 "more than a single header, new line detected");
     743           3 :                                 return FAILURE;
     744             :                         }
     745      719592 :                         if (header_line[i] == '\0') {
     746           1 :                                 efree(header_line);
     747           1 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain NUL bytes");
     748           1 :                                 return FAILURE;
     749             :                         }
     750             :                 }
     751             :         }
     752             : 
     753       25927 :         sapi_header.header = header_line;
     754       25927 :         sapi_header.header_len = header_line_len;
     755             : 
     756             :         /* Check the header for a few cases that we have special support for in SAPI */
     757       51854 :         if (header_line_len>=5
     758       25927 :                 && !strncasecmp(header_line, "HTTP/", 5)) {
     759             :                 /* filter out the response code */
     760         158 :                 sapi_update_response_code(sapi_extract_response_code(header_line));
     761             :                 /* sapi_update_response_code doesn't free the status line if the code didn't change */
     762         158 :                 if (SG(sapi_headers).http_status_line) {
     763           0 :                         efree(SG(sapi_headers).http_status_line);
     764             :                 }
     765         158 :                 SG(sapi_headers).http_status_line = header_line;
     766         158 :                 return SUCCESS;
     767             :         } else {
     768       25769 :                 colon_offset = strchr(header_line, ':');
     769       25769 :                 if (colon_offset) {
     770       25768 :                         *colon_offset = 0;
     771       25768 :                         if (!strcasecmp(header_line, "Content-Type")) {
     772         194 :                                 char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
     773         194 :                                 size_t len = header_line_len - (ptr - header_line), newlen;
     774         580 :                                 while (*ptr == ' ') {
     775         192 :                                         ptr++;
     776         192 :                                         len--;
     777             :                                 }
     778             : 
     779             :                                 /* Disable possible output compression for images */
     780         194 :                                 if (!strncmp(ptr, "image/", sizeof("image/")-1)) {
     781           4 :                                         zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
     782           4 :                                         zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
     783             :                                         zend_string_release(key);
     784             :                                 }
     785             : 
     786         194 :                                 mimetype = estrdup(ptr);
     787         194 :                                 newlen = sapi_apply_default_charset(&mimetype, len);
     788         194 :                                 if (!SG(sapi_headers).mimetype){
     789         183 :                                         SG(sapi_headers).mimetype = estrdup(mimetype);
     790             :                                 }
     791             : 
     792         194 :                                 if (newlen != 0) {
     793          12 :                                         newlen += sizeof("Content-type: ");
     794          12 :                                         newheader = emalloc(newlen);
     795          12 :                                         PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1);
     796          12 :                                         strlcat(newheader, mimetype, newlen);
     797          12 :                                         sapi_header.header = newheader;
     798          12 :                                         sapi_header.header_len = (uint)(newlen - 1);
     799          12 :                                         efree(header_line);
     800             :                                 }
     801         194 :                                 efree(mimetype);
     802         194 :                                 SG(sapi_headers).send_default_content_type = 0;
     803       25574 :                         } else if (!strcasecmp(header_line, "Content-Length")) {
     804             :                                 /* Script is setting Content-length. The script cannot reasonably
     805             :                                  * know the size of the message body after compression, so it's best
     806             :                                  * do disable compression altogether. This contributes to making scripts
     807             :                                  * portable between setups that have and don't have zlib compression
     808             :                                  * enabled globally. See req #44164 */
     809         246 :                                 zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
     810         246 :                                 zend_alter_ini_entry_chars(key,
     811             :                                         "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
     812             :                                 zend_string_release(key);
     813       25328 :                         } else if (!strcasecmp(header_line, "Location")) {
     814          53 :                                 if ((SG(sapi_headers).http_response_code < 300 ||
     815          22 :                                         SG(sapi_headers).http_response_code > 399) &&
     816           5 :                                         SG(sapi_headers).http_response_code != 201) {
     817             :                                         /* Return a Found Redirect if one is not already specified */
     818           4 :                                         if (http_response_code) { /* user specified redirect code */
     819           2 :                                                 sapi_update_response_code(http_response_code);
     820           2 :                                         } else if (SG(request_info).proto_num > 1000 &&
     821           0 :                                            SG(request_info).request_method &&
     822           0 :                                            strcmp(SG(request_info).request_method, "HEAD") &&
     823           0 :                                            strcmp(SG(request_info).request_method, "GET")) {
     824           0 :                                                 sapi_update_response_code(303);
     825             :                                         } else {
     826           2 :                                                 sapi_update_response_code(302);
     827             :                                         }
     828             :                                 }
     829       25302 :                         } else if (!strcasecmp(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
     830           0 :                                 sapi_update_response_code(401); /* authentication-required */
     831             :                         }
     832       25768 :                         if (sapi_header.header==header_line) {
     833       25756 :                                 *colon_offset = ':';
     834             :                         }
     835             :                 }
     836             :         }
     837       25769 :         if (http_response_code) {
     838           3 :                 sapi_update_response_code(http_response_code);
     839             :         }
     840       25769 :         sapi_header_add_op(op, &sapi_header);
     841       25769 :         return SUCCESS;
     842             : }
     843             : 
     844             : 
     845       23836 : SAPI_API int sapi_send_headers(void)
     846             : {
     847             :         int retval;
     848       23836 :         int ret = FAILURE;
     849             : 
     850       23836 :         if (SG(headers_sent) || SG(request_info).no_headers) {
     851           0 :                 return SUCCESS;
     852             :         }
     853             : 
     854             :         /* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
     855             :          * in case of an error situation.
     856             :          */
     857       23836 :         if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) {
     858       23651 :             uint len = 0;
     859       23651 :                 char *default_mimetype = get_default_content_type(0, &len);
     860             : 
     861       47302 :                 if (default_mimetype && len) {
     862             :                         sapi_header_struct default_header;
     863             : 
     864       23651 :                         SG(sapi_headers).mimetype = default_mimetype;
     865             : 
     866       23651 :                         default_header.header_len = sizeof("Content-type: ") - 1 + len;
     867       23651 :                         default_header.header = emalloc(default_header.header_len + 1);
     868             : 
     869       23651 :                         memcpy(default_header.header, "Content-type: ", sizeof("Content-type: ") - 1);
     870       23651 :                         memcpy(default_header.header + sizeof("Content-type: ") - 1, SG(sapi_headers).mimetype, len + 1);
     871             :                         
     872       23651 :                         sapi_header_add_op(SAPI_HEADER_ADD, &default_header);
     873             :                 } else {
     874           0 :                         efree(default_mimetype);
     875             :                 }
     876       23651 :                 SG(sapi_headers).send_default_content_type = 0;
     877             :         }
     878             : 
     879       23836 :         if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
     880             :                 zval cb;
     881           2 :                 ZVAL_COPY_VALUE(&cb, &SG(callback_func));
     882           2 :                 ZVAL_UNDEF(&SG(callback_func));
     883           2 :                 sapi_run_header_callback(&cb);
     884           2 :                 zval_ptr_dtor(&cb);
     885             :         }
     886             : 
     887       23836 :         SG(headers_sent) = 1;
     888             : 
     889       23836 :         if (sapi_module.send_headers) {
     890       23836 :                 retval = sapi_module.send_headers(&SG(sapi_headers));
     891             :         } else {
     892           0 :                 retval = SAPI_HEADER_DO_SEND;
     893             :         }
     894             : 
     895       23836 :         switch (retval) {
     896             :                 case SAPI_HEADER_SENT_SUCCESSFULLY:
     897       23836 :                         ret = SUCCESS;
     898       23836 :                         break;
     899             :                 case SAPI_HEADER_DO_SEND: {
     900             :                                 sapi_header_struct http_status_line;
     901             :                                 char buf[255];
     902             : 
     903           0 :                                 if (SG(sapi_headers).http_status_line) {
     904           0 :                                         http_status_line.header = SG(sapi_headers).http_status_line;
     905           0 :                                         http_status_line.header_len = (uint)strlen(SG(sapi_headers).http_status_line);
     906             :                                 } else {
     907           0 :                                         http_status_line.header = buf;
     908           0 :                                         http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
     909             :                                 }
     910           0 :                                 sapi_module.send_header(&http_status_line, SG(server_context));
     911             :                         }
     912           0 :                         zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context));
     913           0 :                         if(SG(sapi_headers).send_default_content_type) {
     914             :                                 sapi_header_struct default_header;
     915             : 
     916           0 :                                 sapi_get_default_content_type_header(&default_header);
     917           0 :                                 sapi_module.send_header(&default_header, SG(server_context));
     918           0 :                                 sapi_free_header(&default_header);
     919             :                         }
     920           0 :                         sapi_module.send_header(NULL, SG(server_context));
     921           0 :                         ret = SUCCESS;
     922           0 :                         break;
     923             :                 case SAPI_HEADER_SEND_FAILED:
     924           0 :                         SG(headers_sent) = 0;
     925           0 :                         ret = FAILURE;
     926             :                         break;
     927             :         }
     928             : 
     929       23836 :         sapi_send_headers_free();
     930             : 
     931       23836 :         return ret;
     932             : }
     933             : 
     934             : 
     935       47914 : SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries)
     936             : {
     937       47914 :         sapi_post_entry *p=post_entries;
     938             : 
     939      167678 :         while (p->content_type) {
     940       95814 :                 if (sapi_register_post_entry(p) == FAILURE) {
     941       23964 :                         return FAILURE;
     942             :                 }
     943       71850 :                 p++;
     944             :         }
     945       23950 :         return SUCCESS;
     946             : }
     947             : 
     948             : 
     949       95814 : SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry)
     950             : {
     951       95814 :         if (SG(sapi_started) && EG(current_execute_data)) {
     952           0 :                 return FAILURE;
     953             :         }
     954      191628 :         return zend_hash_str_add_mem(&SG(known_post_content_types),
     955      191628 :                         post_entry->content_type, post_entry->content_type_len,
     956             :                         (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE;
     957             : }
     958             : 
     959       23950 : SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry)
     960             : {
     961       23950 :         if (SG(sapi_started) && EG(current_execute_data)) {
     962           0 :                 return;
     963             :         }
     964       23950 :         zend_hash_str_del(&SG(known_post_content_types), post_entry->content_type,
     965       23950 :                         post_entry->content_type_len);
     966             : }
     967             : 
     968             : 
     969       23950 : SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void))
     970             : {
     971       23950 :         if (SG(sapi_started) && EG(current_execute_data)) {
     972           0 :                 return FAILURE;
     973             :         }
     974       23950 :         sapi_module.default_post_reader = default_post_reader;
     975       23950 :         return SUCCESS;
     976             : }
     977             : 
     978             : 
     979       47900 : SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray))
     980             : {
     981       47900 :         if (SG(sapi_started) && EG(current_execute_data)) {
     982           0 :                 return FAILURE;
     983             :         }
     984       47900 :         sapi_module.treat_data = treat_data;
     985       47900 :         return SUCCESS;
     986             : }
     987             : 
     988       47900 : 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))
     989             : {
     990       47900 :         if (SG(sapi_started) && EG(current_execute_data)) {
     991           0 :                 return FAILURE;
     992             :         }
     993       47900 :         sapi_module.input_filter = input_filter;
     994       47900 :         sapi_module.input_filter_init = input_filter_init;
     995       47900 :         return SUCCESS;
     996             : }
     997             : 
     998      917402 : SAPI_API int sapi_flush(void)
     999             : {
    1000      917402 :         if (sapi_module.flush) {
    1001      917402 :                 sapi_module.flush(SG(server_context));
    1002      917402 :                 return SUCCESS;
    1003             :         } else {
    1004           0 :                 return FAILURE;
    1005             :         }
    1006             : }
    1007             : 
    1008          19 : SAPI_API zend_stat_t *sapi_get_stat(void)
    1009             : {
    1010          19 :         if (sapi_module.get_stat) {
    1011           0 :                 return sapi_module.get_stat();
    1012             :         } else {
    1013          19 :                 if (!SG(request_info).path_translated || (VCWD_STAT(SG(request_info).path_translated, &SG(global_stat)) == -1)) {
    1014           0 :                         return NULL;
    1015             :                 }
    1016          19 :                 return &SG(global_stat);
    1017             :         }
    1018             : }
    1019             : 
    1020       30159 : SAPI_API char *sapi_getenv(char *name, size_t name_len)
    1021             : {
    1022       30159 :         if (!strncasecmp(name, "HTTP_PROXY", name_len)) {
    1023             :                 /* Ugly fix for HTTP_PROXY issue, see bug #72573 */
    1024           0 :                 return NULL;
    1025             :         }
    1026       30159 :         if (sapi_module.getenv) {
    1027           8 :                 char *value, *tmp = sapi_module.getenv(name, name_len);
    1028           8 :                 if (tmp) {
    1029           8 :                         value = estrdup(tmp);
    1030             :                 } else {
    1031           0 :                         return NULL;
    1032             :                 }
    1033           8 :                 if (sapi_module.input_filter) {
    1034           8 :                         sapi_module.input_filter(PARSE_STRING, name, &value, strlen(value), NULL);
    1035             :                 }
    1036           8 :                 return value;
    1037             :         }
    1038       30151 :         return NULL;
    1039             : }
    1040             : 
    1041           0 : SAPI_API int sapi_get_fd(int *fd)
    1042             : {
    1043           0 :         if (sapi_module.get_fd) {
    1044           0 :                 return sapi_module.get_fd(fd);
    1045             :         } else {
    1046           0 :                 return FAILURE;
    1047             :         }
    1048             : }
    1049             : 
    1050           0 : SAPI_API int sapi_force_http_10(void)
    1051             : {
    1052           0 :         if (sapi_module.force_http_10) {
    1053           0 :                 return sapi_module.force_http_10();
    1054             :         } else {
    1055           0 :                 return FAILURE;
    1056             :         }
    1057             : }
    1058             : 
    1059             : 
    1060           0 : SAPI_API int sapi_get_target_uid(uid_t *obj)
    1061             : {
    1062           0 :         if (sapi_module.get_target_uid) {
    1063           0 :                 return sapi_module.get_target_uid(obj);
    1064             :         } else {
    1065           0 :                 return FAILURE;
    1066             :         }
    1067             : }
    1068             : 
    1069           0 : SAPI_API int sapi_get_target_gid(gid_t *obj)
    1070             : {
    1071           0 :         if (sapi_module.get_target_gid) {
    1072           0 :                 return sapi_module.get_target_gid(obj);
    1073             :         } else {
    1074           0 :                 return FAILURE;
    1075             :         }
    1076             : }
    1077             : 
    1078       24025 : SAPI_API double sapi_get_request_time(void)
    1079             : {
    1080       24025 :         if(SG(global_request_time)) return SG(global_request_time);
    1081             : 
    1082       24025 :         if (sapi_module.get_request_time && SG(server_context)) {
    1083           0 :                 SG(global_request_time) = sapi_module.get_request_time();
    1084             :         } else {
    1085       24025 :                 struct timeval tp = {0};
    1086       24025 :                 if (!gettimeofday(&tp, NULL)) {
    1087       24025 :                         SG(global_request_time) = (double)(tp.tv_sec + tp.tv_usec / 1000000.00);
    1088             :                 } else {
    1089           0 :                         SG(global_request_time) = (double)time(0);
    1090             :                 }
    1091             :         }
    1092       24025 :         return SG(global_request_time);
    1093             : }
    1094             : 
    1095           0 : SAPI_API void sapi_terminate_process(void) {
    1096           0 :         if (sapi_module.terminate_process) {
    1097           0 :                 sapi_module.terminate_process();
    1098             :         }
    1099           0 : }
    1100             : 
    1101             : /*
    1102             :  * Local variables:
    1103             :  * tab-width: 4
    1104             :  * c-basic-offset: 4
    1105             :  * End:
    1106             :  * vim600: sw=4 ts=4 fdm=marker
    1107             :  * vim<600: sw=4 ts=4
    1108             :  */

Generated by: LCOV version 1.10

Generated at Tue, 27 Sep 2016 10:26:12 +0000 (32 hours ago)

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