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: 367 514 71.4 %
Date: 2014-07-27 Functions: 31 37 83.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* 
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2013 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             : #endif
      41             : 
      42             : #include "rfc1867.h"
      43             : 
      44             : #ifdef PHP_WIN32
      45             : #define STRCASECMP stricmp
      46             : #else
      47             : #define STRCASECMP strcasecmp
      48             : #endif
      49             : 
      50             : #include "php_content_types.h"
      51             : 
      52             : #ifdef ZTS
      53             : SAPI_API int sapi_globals_id;
      54             : #else
      55             : sapi_globals_struct sapi_globals;
      56             : #endif
      57             : 
      58       19341 : static void sapi_globals_ctor(sapi_globals_struct *sapi_globals TSRMLS_DC)
      59             : {
      60       19341 :         memset(sapi_globals, 0, sizeof(*sapi_globals));
      61       19341 :         zend_hash_init_ex(&sapi_globals->known_post_content_types, 5, NULL, NULL, 1, 0);
      62       19341 :         php_setup_sapi_content_types(TSRMLS_C);
      63       19341 : }
      64             : 
      65       19376 : static void sapi_globals_dtor(sapi_globals_struct *sapi_globals TSRMLS_DC)
      66             : {
      67       19376 :         zend_hash_destroy(&sapi_globals->known_post_content_types);
      68       19376 : }
      69             : 
      70             : /* True globals (no need for thread safety) */
      71             : SAPI_API sapi_module_struct sapi_module;
      72             : 
      73             : 
      74       19341 : SAPI_API void sapi_startup(sapi_module_struct *sf)
      75             : {
      76       19341 :         sf->ini_entries = NULL;
      77       19341 :         sapi_module = *sf;
      78             : 
      79             : #ifdef ZTS
      80             :         ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
      81             : # ifdef PHP_WIN32
      82             :         _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
      83             : # endif
      84             : #else
      85       19341 :         sapi_globals_ctor(&sapi_globals);
      86             : #endif
      87             : 
      88       19341 :         virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
      89             : 
      90             : #ifdef PHP_WIN32
      91             :         tsrm_win32_startup();
      92             : #endif
      93             : 
      94             :         reentrancy_startup();
      95       19341 : }
      96             : 
      97       19376 : SAPI_API void sapi_shutdown(void)
      98             : {
      99             : #ifdef ZTS
     100             :         ts_free_id(sapi_globals_id);
     101             : #else
     102       19376 :         sapi_globals_dtor(&sapi_globals);
     103             : #endif
     104             : 
     105             :         reentrancy_shutdown();
     106             : 
     107       19376 :         virtual_cwd_shutdown();
     108             : 
     109             : #ifdef PHP_WIN32
     110             :         tsrm_win32_shutdown();
     111             : #endif
     112       19376 : }
     113             : 
     114             : 
     115       39930 : SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
     116             : {
     117       39930 :         efree(sapi_header->header);
     118       39930 : }
     119             : 
     120             : 
     121          60 : SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
     122             : {
     123          60 :         if (SG(request_info).post_entry && SG(request_info).content_type_dup) {
     124          59 :                 SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg TSRMLS_CC);
     125          59 :                 if (SG(request_info).post_data) {
     126          36 :                         efree(SG(request_info).post_data);
     127          36 :                         SG(request_info).post_data = NULL;
     128             :                 }
     129          59 :                 efree(SG(request_info).content_type_dup);
     130          59 :                 SG(request_info).content_type_dup = NULL;
     131             :         }
     132          60 : }
     133             : 
     134          61 : static void sapi_read_post_data(TSRMLS_D)
     135             : {
     136             :         sapi_post_entry *post_entry;
     137          61 :         uint content_type_length = strlen(SG(request_info).content_type);
     138          61 :         char *content_type = estrndup(SG(request_info).content_type, content_type_length);
     139             :         char *p;
     140          61 :         char oldchar=0;
     141          61 :         void (*post_reader_func)(TSRMLS_D) = NULL;
     142             : 
     143             : 
     144             :         /* dedicated implementation for increased performance:
     145             :          * - Make the content type lowercase
     146             :          * - Trim descriptive data, stay with the content-type only
     147             :          */
     148        1753 :         for (p=content_type; p<content_type+content_type_length; p++) {
     149        1692 :                 switch (*p) {
     150             :                         case ';':
     151             :                         case ',':
     152             :                         case ' ':
     153          22 :                                 content_type_length = p-content_type;
     154          22 :                                 oldchar = *p;
     155          22 :                                 *p = 0;
     156          22 :                                 break;
     157             :                         default:
     158        1670 :                                 *p = tolower(*p);
     159             :                                 break;
     160             :                 }
     161             :         }
     162             : 
     163             :         /* now try to find an appropriate POST content handler */
     164          61 :         if (zend_hash_find(&SG(known_post_content_types), content_type,
     165             :                         content_type_length+1, (void **) &post_entry) == SUCCESS) {
     166             :                 /* found one, register it for use */
     167          60 :                 SG(request_info).post_entry = post_entry;
     168          60 :                 post_reader_func = post_entry->post_reader;
     169             :         } else {
     170             :                 /* fallback */
     171           1 :                 SG(request_info).post_entry = NULL;
     172           1 :                 if (!sapi_module.default_post_reader) {
     173             :                         /* no default reader ? */
     174           0 :                         SG(request_info).content_type_dup = NULL;
     175           0 :                         sapi_module.sapi_error(E_WARNING, "Unsupported content type:  '%s'", content_type);
     176           0 :                         return;
     177             :                 }
     178             :         }
     179          61 :         if (oldchar) {
     180          22 :                 *(p-1) = oldchar;
     181             :         }
     182             : 
     183          61 :         SG(request_info).content_type_dup = content_type;
     184             : 
     185          61 :         if(post_reader_func) {
     186          37 :                 post_reader_func(TSRMLS_C);
     187             :         }
     188             : 
     189          61 :         if(sapi_module.default_post_reader) {
     190          61 :                 sapi_module.default_post_reader(TSRMLS_C);
     191             :         }
     192             : }
     193             : 
     194             : 
     195          38 : SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
     196             : {
     197             :         int read_bytes;
     198          38 :         int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
     199             : 
     200          38 :         if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) {
     201           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",
     202             :                                         SG(request_info).content_length, SG(post_max_size));
     203           1 :                 return;
     204             :         }
     205          37 :         SG(request_info).post_data = emalloc(allocated_bytes);
     206             : 
     207             :         for (;;) {
     208          37 :                 read_bytes = sapi_module.read_post(SG(request_info).post_data+SG(read_post_bytes), SAPI_POST_BLOCK_SIZE TSRMLS_CC);
     209          37 :                 if (read_bytes<=0) {
     210           0 :                         break;
     211             :                 }
     212          37 :                 SG(read_post_bytes) += read_bytes;
     213          37 :                 if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) {
     214           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size));
     215           0 :                         break;
     216             :                 }
     217          37 :                 if (read_bytes < SAPI_POST_BLOCK_SIZE) {
     218          37 :                         break;
     219             :                 }
     220           0 :                 if (SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE >= allocated_bytes) {
     221           0 :                         allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1;
     222           0 :                         SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes);
     223             :                 }
     224           0 :         }
     225          37 :         SG(request_info).post_data[SG(read_post_bytes)] = 0;  /* terminating NULL */
     226          37 :         SG(request_info).post_data_length = SG(read_post_bytes);
     227             : }
     228             : 
     229             : 
     230       19041 : SAPI_API char *sapi_get_default_content_type(TSRMLS_D)
     231             : {
     232             :         char *mimetype, *charset, *content_type;
     233             : 
     234       19041 :         mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
     235       19041 :         charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
     236             : 
     237       19161 :         if (strncasecmp(mimetype, "text/", 5) == 0 && *charset) {
     238         120 :                 int len = strlen(mimetype) + sizeof("; charset=") + strlen(charset); /* sizeof() includes \0 */
     239         120 :                 content_type = emalloc(len);
     240         120 :                 snprintf(content_type, len, "%s; charset=%s", mimetype, charset);
     241             :         } else {
     242       18921 :                 content_type = estrdup(mimetype);
     243             :         }
     244       19041 :         return content_type;
     245             : }
     246             : 
     247             : 
     248       19041 : SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC)
     249             : {
     250       19041 :         char *default_content_type = sapi_get_default_content_type(TSRMLS_C);
     251       19041 :         int default_content_type_len = strlen(default_content_type);
     252             : 
     253       19041 :         default_header->header_len = (sizeof("Content-type: ")-1) + default_content_type_len;
     254       19041 :         default_header->header = emalloc(default_header->header_len+1);
     255       19041 :         memcpy(default_header->header, "Content-type: ", sizeof("Content-type: "));
     256       19041 :         memcpy(default_header->header+sizeof("Content-type: ")-1, default_content_type, default_content_type_len);
     257       19041 :         default_header->header[default_header->header_len] = 0;
     258       19041 :         efree(default_content_type);
     259       19041 : }
     260             : 
     261             : /*
     262             :  * Add charset on content-type header if the MIME type starts with
     263             :  * "text/", the default_charset directive is not empty and
     264             :  * there is not already a charset option in there.
     265             :  *
     266             :  * If "mimetype" is non-NULL, it should point to a pointer allocated
     267             :  * with emalloc().  If a charset is added, the string will be
     268             :  * re-allocated and the new length is returned.  If mimetype is
     269             :  * unchanged, 0 is returned.
     270             :  *
     271             :  */
     272       19232 : SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC)
     273             : {
     274             :         char *charset, *newtype;
     275             :         size_t newlen;
     276       19232 :         charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
     277             : 
     278       19232 :         if (*mimetype != NULL) {
     279       19232 :                 if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) {
     280           4 :                         newlen = len + (sizeof(";charset=")-1) + strlen(charset);
     281           4 :                         newtype = emalloc(newlen + 1);
     282           4 :                         PHP_STRLCPY(newtype, *mimetype, newlen + 1, len);
     283           4 :                         strlcat(newtype, ";charset=", newlen + 1);
     284           4 :                         strlcat(newtype, charset, newlen + 1);
     285           4 :                         efree(*mimetype);
     286           4 :                         *mimetype = newtype;
     287           4 :                         return newlen;
     288             :                 }
     289             :         }
     290       19228 :         return 0;
     291             : }
     292             : 
     293           0 : SAPI_API void sapi_activate_headers_only(TSRMLS_D)
     294             : {
     295           0 :         if (SG(request_info).headers_read == 1)
     296           0 :                 return;
     297           0 :         SG(request_info).headers_read = 1;
     298           0 :         zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), 
     299             :                         (void (*)(void *)) sapi_free_header, 0);
     300           0 :         SG(sapi_headers).send_default_content_type = 1;
     301             : 
     302             :         /* SG(sapi_headers).http_response_code = 200; */ 
     303           0 :         SG(sapi_headers).http_status_line = NULL;
     304           0 :         SG(sapi_headers).mimetype = NULL;
     305           0 :         SG(read_post_bytes) = 0;
     306           0 :         SG(request_info).post_data = NULL;
     307           0 :         SG(request_info).raw_post_data = NULL;
     308           0 :         SG(request_info).current_user = NULL;
     309           0 :         SG(request_info).current_user_length = 0;
     310           0 :         SG(request_info).no_headers = 0;
     311           0 :         SG(request_info).post_entry = NULL;
     312           0 :         SG(global_request_time) = 0;
     313             : 
     314             :         /*
     315             :          * It's possible to override this general case in the activate() callback, 
     316             :          * if necessary.
     317             :          */
     318           0 :         if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
     319           0 :                 SG(request_info).headers_only = 1;
     320             :         } else {
     321           0 :                 SG(request_info).headers_only = 0;
     322             :         }
     323           0 :         if (SG(server_context)) {
     324           0 :                 SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
     325           0 :                 if (sapi_module.activate) {
     326           0 :                         sapi_module.activate(TSRMLS_C);
     327             :                 }
     328             :         }
     329           0 :         if (sapi_module.input_filter_init ) {
     330           0 :                 sapi_module.input_filter_init(TSRMLS_C);
     331             :         }
     332             : }
     333             : 
     334             : /*
     335             :  * Called from php_request_startup() for every request.
     336             :  */
     337             : 
     338       38668 : SAPI_API void sapi_activate(TSRMLS_D)
     339             : {
     340       38668 :         zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
     341       38668 :         SG(sapi_headers).send_default_content_type = 1;
     342             : 
     343             :         /*
     344             :         SG(sapi_headers).http_response_code = 200;
     345             :         */
     346       38668 :         SG(sapi_headers).http_status_line = NULL;
     347       38668 :         SG(sapi_headers).mimetype = NULL;
     348       38668 :         SG(headers_sent) = 0;
     349       38668 :         SG(read_post_bytes) = 0;
     350       38668 :         SG(request_info).post_data = NULL;
     351       38668 :         SG(request_info).raw_post_data = NULL;
     352       38668 :         SG(request_info).current_user = NULL;
     353       38668 :         SG(request_info).current_user_length = 0;
     354       38668 :         SG(request_info).no_headers = 0;
     355       38668 :         SG(request_info).post_entry = NULL;
     356       38668 :         SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
     357       38668 :         SG(global_request_time) = 0;
     358             : 
     359             :         /* It's possible to override this general case in the activate() callback, if
     360             :          * necessary.
     361             :          */
     362       38668 :         if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
     363           0 :                 SG(request_info).headers_only = 1;
     364             :         } else {
     365       38668 :                 SG(request_info).headers_only = 0;
     366             :         }
     367       38668 :         SG(rfc1867_uploaded_files) = NULL;
     368             : 
     369             :         /* handle request mehtod */
     370       38668 :         if (SG(server_context)) {
     371         342 :                 if ( SG(request_info).request_method) {
     372         302 :                         if(!strcmp(SG(request_info).request_method, "POST")
     373          61 :                            && (SG(request_info).content_type)) {
     374             :                                 /* HTTP POST -> may contain form data to be read into variables
     375             :                                    depending on content type given
     376             :                                 */
     377          61 :                                 sapi_read_post_data(TSRMLS_C);
     378             :                         } else {
     379             :                                 /* any other method with content payload will fill 
     380             :                                    $HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data 
     381             :                                    it is up to the webserver to decide whether to allow a method or not
     382             :                                 */
     383         119 :                                 SG(request_info).content_type_dup = NULL;
     384         119 :                                 if(sapi_module.default_post_reader) {
     385         119 :                                         sapi_module.default_post_reader(TSRMLS_C);
     386             :                                 }
     387             :                         }
     388             :                 } else {
     389         162 :                         SG(request_info).content_type_dup = NULL;
     390             :                 }
     391             : 
     392             :                 /* Cookies */
     393         342 :                 SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
     394         342 :                 if (sapi_module.activate) {
     395         342 :                         sapi_module.activate(TSRMLS_C);
     396             :                 }
     397             :         }
     398       38668 :         if (sapi_module.input_filter_init ) {
     399       19327 :                 sapi_module.input_filter_init(TSRMLS_C);
     400             :         }
     401       38668 : }
     402             : 
     403             : 
     404       57938 : static void sapi_send_headers_free(TSRMLS_D)
     405             : {
     406       57938 :         if (SG(sapi_headers).http_status_line) {
     407         146 :                 efree(SG(sapi_headers).http_status_line);
     408         146 :                 SG(sapi_headers).http_status_line = NULL;
     409             :         }
     410       57938 : }
     411             :         
     412       38717 : SAPI_API void sapi_deactivate(TSRMLS_D)
     413             : {
     414       38717 :         zend_llist_destroy(&SG(sapi_headers).headers);
     415       38717 :         if (SG(request_info).post_data) {
     416           1 :                 efree(SG(request_info).post_data);
     417       38716 :         }  else         if (SG(server_context)) {
     418         338 :                 if(sapi_module.read_post) { 
     419             :                         /* make sure we've consumed all request input data */
     420             :                         char dummy[SAPI_POST_BLOCK_SIZE];
     421             :                         int read_bytes;
     422             : 
     423         680 :                         while((read_bytes = sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC)) > 0) {
     424           4 :                                 SG(read_post_bytes) += read_bytes;
     425             :                         }
     426             :                 }
     427             :         }
     428       38717 :         if (SG(request_info).raw_post_data) {
     429          37 :                 efree(SG(request_info).raw_post_data);
     430             :         } 
     431       38717 :         if (SG(request_info).auth_user) {
     432           0 :                 efree(SG(request_info).auth_user);
     433             :         }
     434       38717 :         if (SG(request_info).auth_password) {
     435           0 :                 efree(SG(request_info).auth_password);
     436             :         }
     437       38717 :         if (SG(request_info).auth_digest) {
     438           0 :                 efree(SG(request_info).auth_digest);
     439             :         }
     440       38717 :         if (SG(request_info).content_type_dup) {
     441           2 :                 efree(SG(request_info).content_type_dup);
     442             :         }
     443       38717 :         if (SG(request_info).current_user) {
     444           9 :                 efree(SG(request_info).current_user);
     445             :         }
     446       38717 :         if (sapi_module.deactivate) {
     447       38717 :                 sapi_module.deactivate(TSRMLS_C);
     448             :         }
     449       38717 :         if (SG(rfc1867_uploaded_files)) {
     450          20 :                 destroy_uploaded_files_hash(TSRMLS_C);
     451             :         }
     452       38717 :         if (SG(sapi_headers).mimetype) {
     453       19224 :                 efree(SG(sapi_headers).mimetype);
     454       19224 :                 SG(sapi_headers).mimetype = NULL;
     455             :         }
     456       38717 :         sapi_send_headers_free(TSRMLS_C);
     457       38717 :         SG(sapi_started) = 0;
     458       38717 :         SG(headers_sent) = 0;
     459       38717 :         SG(request_info).headers_read = 0;
     460       38717 :         SG(global_request_time) = 0;
     461       38717 : }
     462             : 
     463             : 
     464       19341 : SAPI_API void sapi_initialize_empty_request(TSRMLS_D)
     465             : {
     466       19341 :         SG(server_context) = NULL;
     467       19341 :         SG(request_info).request_method = NULL;
     468       19341 :         SG(request_info).auth_digest = SG(request_info).auth_user = SG(request_info).auth_password = NULL;
     469       19341 :         SG(request_info).content_type_dup = NULL;
     470       19341 : }
     471             : 
     472             : 
     473         146 : static int sapi_extract_response_code(const char *header_line)
     474             : {
     475         146 :         int code = 200;
     476             :         const char *ptr;
     477             : 
     478        1314 :         for (ptr = header_line; *ptr; ptr++) {
     479        1314 :                 if (*ptr == ' ' && *(ptr + 1) != ' ') {
     480         146 :                         code = atoi(ptr + 1);
     481         146 :                         break;
     482             :                 }
     483             :         }
     484             :         
     485         146 :         return code;
     486             : }
     487             : 
     488             : 
     489         147 : static void sapi_update_response_code(int ncode TSRMLS_DC)
     490             : {
     491             :         /* if the status code did not change, we do not want
     492             :            to change the status line, and no need to change the code */
     493         147 :         if (SG(sapi_headers).http_response_code == ncode) {
     494           0 :                 return;
     495             :         }
     496             : 
     497         147 :         if (SG(sapi_headers).http_status_line) {
     498           0 :                 efree(SG(sapi_headers).http_status_line);
     499           0 :                 SG(sapi_headers).http_status_line = NULL;
     500             :         }
     501         147 :         SG(sapi_headers).http_response_code = ncode;
     502             : }
     503             : 
     504             : /* 
     505             :  * since zend_llist_del_element only remove one matched item once,
     506             :  * we should remove them by ourself
     507             :  */
     508         419 : static void sapi_remove_header(zend_llist *l, char *name, uint len) {
     509             :         sapi_header_struct *header;
     510             :         zend_llist_element *next;
     511         419 :         zend_llist_element *current=l->head;
     512             : 
     513         950 :         while (current) {
     514         112 :                 header = (sapi_header_struct *)(current->data);
     515         112 :                 next = current->next;
     516         146 :                 if (header->header_len > len && header->header[len] == ':'
     517          34 :                                 && !strncasecmp(header->header, name, len)) {
     518           4 :                         if (current->prev) {
     519           4 :                                 current->prev->next = next;
     520             :                         } else {
     521           0 :                                 l->head = next;
     522             :                         }
     523           4 :                         if (next) {
     524           2 :                                 next->prev = current->prev;
     525             :                         } else {
     526           2 :                                 l->tail = current->prev;
     527             :                         }
     528           4 :                         sapi_free_header(header);
     529           4 :                         efree(current);
     530           4 :                         --l->count;
     531             :                 }
     532         112 :                 current = next;
     533             :         }
     534         419 : }
     535             : 
     536       40523 : SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC)
     537             : {
     538       40523 :         sapi_header_line ctr = {0};
     539             :         int r;
     540             :         
     541       40523 :         ctr.line = header_line;
     542       40523 :         ctr.line_len = header_line_len;
     543             : 
     544       40523 :         r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD,
     545             :                         &ctr TSRMLS_CC);
     546             : 
     547       40523 :         if (!duplicate)
     548       19333 :                 efree(header_line);
     549             : 
     550       40523 :         return r;
     551             : }
     552             : 
     553       40649 : SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
     554             : {
     555             :         int retval;
     556             :         sapi_header_struct sapi_header;
     557             :         char *colon_offset;
     558       40649 :         long myuid = 0L;
     559             :         char *header_line;
     560             :         uint header_line_len;
     561             :         int http_response_code;
     562             :         
     563       40649 :         if (SG(headers_sent) && !SG(request_info).no_headers) {
     564         557 :                 char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
     565         557 :                 int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
     566             : 
     567         557 :                 if (output_start_filename) {
     568         556 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)",
     569             :                                 output_start_filename, output_start_lineno);
     570             :                 } else {
     571           1 :                         sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent");
     572             :                 }
     573         557 :                 return FAILURE;
     574             :         }
     575             : 
     576       40092 :         switch (op) {
     577             :                 case SAPI_HEADER_SET_STATUS:
     578           0 :                         sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC);
     579           0 :                         return SUCCESS;
     580             : 
     581             :                 case SAPI_HEADER_ADD:
     582             :                 case SAPI_HEADER_REPLACE:
     583             :                 case SAPI_HEADER_DELETE: {
     584       40090 :                                 sapi_header_line *p = arg;
     585             : 
     586       40090 :                                 if (!p->line || !p->line_len) {
     587           1 :                                         return FAILURE;
     588             :                                 }
     589       40089 :                                 header_line = p->line;
     590       40089 :                                 header_line_len = p->line_len;
     591       40089 :                                 http_response_code = p->response_code;
     592       40089 :                                 break;
     593             :                         }
     594             : 
     595             :                 case SAPI_HEADER_DELETE_ALL:
     596           2 :                         if (sapi_module.header_handler) {
     597           0 :                                 sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
     598             :                         }
     599           2 :                         zend_llist_clean(&SG(sapi_headers).headers);
     600           2 :                         return SUCCESS;
     601             : 
     602             :                 default:
     603           0 :                         return FAILURE;
     604             :         }
     605             : 
     606       40089 :         header_line = estrndup(header_line, header_line_len);
     607             : 
     608             :         /* cut of trailing spaces, linefeeds and carriage-returns */
     609       80185 :         while(header_line_len && isspace(header_line[header_line_len-1])) 
     610           7 :                   header_line[--header_line_len]='\0';
     611             :         
     612       40089 :         if (op == SAPI_HEADER_DELETE) {
     613           6 :                 if (strchr(header_line, ':')) {
     614           3 :                         efree(header_line);
     615           3 :                         sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon.");
     616           3 :                         return FAILURE;
     617             :                 }
     618             :         } else {
     619             :                 /* new line/NUL character safety check */
     620             :                 int i;
     621     1090613 :                 for (i = 0; i < header_line_len; i++) {
     622             :                         /* RFC 2616 allows new lines if followed by SP or HT */
     623             :                         int illegal_break =
     624     3064847 :                                         (header_line[i+1] != ' ' && header_line[i+1] != '\t')
     625             :                                         && (
     626     1007155 :                                                 header_line[i] == '\n'
     627     2057692 :                                                 || (header_line[i] == '\r' && header_line[i+1] != '\n'));
     628     1050534 :                         if (illegal_break) {
     629           3 :                                 efree(header_line);
     630           3 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain "
     631             :                                                 "more than a single header, new line detected");
     632           3 :                                 return FAILURE;
     633             :                         }
     634     1050531 :                         if (header_line[i] == '\0') {
     635           1 :                                 efree(header_line);
     636           1 :                                 sapi_module.sapi_error(E_WARNING, "Header may not contain NUL bytes");
     637           1 :                                 return FAILURE;
     638             :                         }
     639             :                 }
     640             :         }
     641             : 
     642       40082 :         sapi_header.header = header_line;
     643       40082 :         sapi_header.header_len = header_line_len;
     644             : 
     645       40082 :         if (op == SAPI_HEADER_DELETE) {
     646           3 :                 if (sapi_module.header_handler) {
     647           0 :                         sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
     648             :                 }
     649           3 :                 sapi_remove_header(&SG(sapi_headers).headers, sapi_header.header, sapi_header.header_len);
     650           3 :                 sapi_free_header(&sapi_header);
     651           3 :                 return SUCCESS;
     652             :         }
     653             : 
     654             :         /* Check the header for a few cases that we have special support for in SAPI */
     655       80158 :         if (header_line_len>=5 
     656       40079 :                 && !strncasecmp(header_line, "HTTP/", 5)) {
     657             :                 /* filter out the response code */
     658         146 :                 sapi_update_response_code(sapi_extract_response_code(header_line) TSRMLS_CC);
     659             :                 /* sapi_update_response_code doesn't free the status line if the code didn't change */
     660         146 :                 if (SG(sapi_headers).http_status_line) {
     661           0 :                         efree(SG(sapi_headers).http_status_line);
     662             :                 }
     663         146 :                 SG(sapi_headers).http_status_line = header_line;
     664         146 :                 return SUCCESS;
     665             :         } else {
     666       39933 :                 colon_offset = strchr(header_line, ':');
     667       39933 :                 if (colon_offset) {
     668       39932 :                         *colon_offset = 0;
     669       39932 :                         if (!STRCASECMP(header_line, "Content-Type")) {
     670       19232 :                                 char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
     671       19232 :                                 size_t len = header_line_len - (ptr - header_line), newlen;
     672       57694 :                                 while (*ptr == ' ') {
     673       19230 :                                         ptr++;
     674       19230 :                                         len--;
     675             :                                 }
     676             : 
     677             :                                 /* Disable possible output compression for images */
     678       19232 :                                 if (!strncmp(ptr, "image/", sizeof("image/")-1)) {
     679           4 :                                         zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
     680             :                                 }
     681             : 
     682       19232 :                                 mimetype = estrdup(ptr);
     683       19232 :                                 newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC);
     684       19232 :                                 if (!SG(sapi_headers).mimetype){
     685       19221 :                                         SG(sapi_headers).mimetype = estrdup(mimetype);
     686             :                                 }
     687             : 
     688       19232 :                                 if (newlen != 0) {
     689           4 :                                         newlen += sizeof("Content-type: ");
     690           4 :                                         newheader = emalloc(newlen);
     691           4 :                                         PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1);
     692           4 :                                         strlcat(newheader, mimetype, newlen);
     693           4 :                                         sapi_header.header = newheader;
     694           4 :                                         sapi_header.header_len = newlen - 1;
     695           4 :                                         efree(header_line);
     696             :                                 }
     697       19232 :                                 efree(mimetype);
     698       19232 :                                 SG(sapi_headers).send_default_content_type = 0;
     699       20700 :                         } else if (!STRCASECMP(header_line, "Location")) {
     700          24 :                                 if ((SG(sapi_headers).http_response_code < 300 ||
     701          12 :                                         SG(sapi_headers).http_response_code > 307) &&
     702           0 :                                         SG(sapi_headers).http_response_code != 201) {
     703             :                                         /* Return a Found Redirect if one is not already specified */
     704           0 :                                         if (http_response_code) { /* user specified redirect code */
     705           0 :                                                 sapi_update_response_code(http_response_code TSRMLS_CC);
     706           0 :                                         } else if (SG(request_info).proto_num > 1000 && 
     707           0 :                                            SG(request_info).request_method && 
     708           0 :                                            strcmp(SG(request_info).request_method, "HEAD") &&
     709           0 :                                            strcmp(SG(request_info).request_method, "GET")) {
     710           0 :                                                 sapi_update_response_code(303 TSRMLS_CC);
     711             :                                         } else {
     712           0 :                                                 sapi_update_response_code(302 TSRMLS_CC);
     713             :                                         }
     714             :                                 }
     715       20688 :                         } else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
     716             : 
     717           0 :                                 sapi_update_response_code(401 TSRMLS_CC); /* authentication-required */
     718             : 
     719           0 :                                 if(PG(safe_mode)) 
     720             : #if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
     721             :                                 {
     722             :                                         zval *repl_temp;
     723           0 :                                         char *ptr = colon_offset+1, *result, *newheader;
     724           0 :                                         int ptr_len=0, result_len = 0, newlen = 0;
     725             : 
     726             :                                         /* skip white space */
     727           0 :                                         while (isspace(*ptr)) {
     728           0 :                                                 ptr++;
     729             :                                         }
     730             : 
     731           0 :                                         myuid = php_getuid();
     732             : 
     733           0 :                                         ptr_len = strlen(ptr);
     734           0 :                                         MAKE_STD_ZVAL(repl_temp);
     735           0 :                                         Z_TYPE_P(repl_temp) = IS_STRING;
     736           0 :                                         Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\"\\1-%ld\"", myuid);
     737             :                                         /* Modify quoted realm value */
     738           0 :                                         result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
     739             :                                                                                          ptr, ptr_len,
     740             :                                                                                          repl_temp,
     741             :                                                                                          0, &result_len, -1, NULL TSRMLS_CC);
     742           0 :                                         if(result_len==ptr_len) {
     743           0 :                                                 efree(result);
     744           0 :                                                 efree(Z_STRVAL_P(repl_temp));
     745           0 :                                                 Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\\1-%ld\\2", myuid);
     746             :                                                 /* modify unquoted realm value */
     747           0 :                                                 result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21, 
     748             :                                                                                                 ptr, ptr_len,
     749             :                                                                                                 repl_temp,
     750             :                                                                                                 0, &result_len, -1, NULL TSRMLS_CC);
     751           0 :                                                 if(result_len==ptr_len) {
     752           0 :                                                         char *lower_temp = estrdup(ptr);        
     753             :                                                         char conv_temp[32];
     754             :                                                         int conv_len;
     755             : 
     756           0 :                                                         php_strtolower(lower_temp,strlen(lower_temp));
     757             :                                                         /* If there is no realm string at all, append one */
     758           0 :                                                         if(!strstr(lower_temp,"realm")) {
     759           0 :                                                                 efree(result);
     760           0 :                                                                 conv_len = slprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
     761           0 :                                                                 result = emalloc(ptr_len+conv_len+1);
     762           0 :                                                                 result_len = ptr_len+conv_len;
     763           0 :                                                                 memcpy(result, ptr, ptr_len);   
     764           0 :                                                                 memcpy(result+ptr_len, conv_temp, conv_len);
     765           0 :                                                                 *(result+ptr_len+conv_len) = '\0';
     766             :                                                         }
     767           0 :                                                         efree(lower_temp);
     768             :                                                 }
     769             :                                         }
     770           0 :                                         newlen = spprintf(&newheader, 0, "WWW-Authenticate: %s", result);
     771           0 :                                         efree(header_line);
     772           0 :                                         sapi_header.header = newheader;
     773           0 :                                         sapi_header.header_len = newlen;
     774           0 :                                         efree(result);
     775           0 :                                         efree(Z_STRVAL_P(repl_temp));
     776           0 :                                         efree(repl_temp);
     777             :                                 } 
     778             : #else
     779             :                                 {
     780             :                                         myuid = php_getuid();
     781             :                                         efree(header_line);
     782             :                                         sapi_header.header_len = spprintf(&sapi_header.header, 0, "WWW-Authenticate: Basic realm=\"%ld\"", myuid);
     783             :                                 }
     784             : #endif
     785             :                         }
     786       39932 :                         if (sapi_header.header==header_line) {
     787       39928 :                                 *colon_offset = ':';
     788             :                         }
     789             :                 }
     790             :         }
     791       39933 :         if (http_response_code) {
     792           1 :                 sapi_update_response_code(http_response_code TSRMLS_CC);
     793             :         }
     794       39933 :         if (sapi_module.header_handler) {
     795       39333 :                 retval = sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
     796             :         } else {
     797         600 :                 retval = SAPI_HEADER_ADD;
     798             :         }
     799       39933 :         if (retval & SAPI_HEADER_ADD) {
     800             :                 /* in replace mode first remove the header if it already exists in the headers llist */
     801         600 :                 if (op == SAPI_HEADER_REPLACE) {
     802         416 :                         colon_offset = strchr(sapi_header.header, ':');
     803         416 :                         if (colon_offset) {
     804             :                                 char sav;
     805         416 :                                 sav = *colon_offset;
     806         416 :                                 *colon_offset = 0;
     807         416 :                         sapi_remove_header(&SG(sapi_headers).headers, sapi_header.header, strlen(sapi_header.header));
     808         416 :                                 *colon_offset = sav;
     809             :                         }
     810             :                 }
     811             : 
     812         600 :                 zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header);
     813             :         } else {
     814       39333 :                 sapi_free_header(&sapi_header);
     815             :         }
     816       39933 :         return SUCCESS;
     817             : }
     818             : 
     819             : 
     820       32065 : SAPI_API int sapi_send_headers(TSRMLS_D)
     821             : {
     822             :         int retval;
     823       32065 :         int ret = FAILURE;
     824             : 
     825       32065 :         if (SG(headers_sent) || SG(request_info).no_headers) {
     826       12844 :                 return SUCCESS;
     827             :         }
     828             : 
     829             :         /* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
     830             :          * in case of an error situation.
     831             :          */
     832       19221 :         if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) {
     833             :                 sapi_header_struct default_header;
     834       19041 :                 sapi_get_default_content_type_header(&default_header TSRMLS_CC);
     835       19041 :                 sapi_add_header_ex(default_header.header, default_header.header_len, 0, 0 TSRMLS_CC);
     836             :         }
     837             : 
     838       19221 :         SG(headers_sent) = 1;
     839             : 
     840       19221 :         if (sapi_module.send_headers) {
     841       19221 :                 retval = sapi_module.send_headers(&SG(sapi_headers) TSRMLS_CC);
     842             :         } else {
     843           0 :                 retval = SAPI_HEADER_DO_SEND;
     844             :         }
     845             : 
     846       19221 :         switch (retval) {
     847             :                 case SAPI_HEADER_SENT_SUCCESSFULLY:
     848       19221 :                         ret = SUCCESS;
     849       19221 :                         break;
     850             :                 case SAPI_HEADER_DO_SEND: {
     851             :                                 sapi_header_struct http_status_line;
     852             :                                 char buf[255];
     853             : 
     854           0 :                                 if (SG(sapi_headers).http_status_line) {
     855           0 :                                         http_status_line.header = SG(sapi_headers).http_status_line;
     856           0 :                                         http_status_line.header_len = strlen(SG(sapi_headers).http_status_line);
     857             :                                 } else {
     858           0 :                                         http_status_line.header = buf;
     859           0 :                                         http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
     860             :                                 }
     861           0 :                                 sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC);
     862             :                         }
     863           0 :                         zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context) TSRMLS_CC);
     864           0 :                         if(SG(sapi_headers).send_default_content_type) {
     865             :                                 sapi_header_struct default_header;
     866             : 
     867           0 :                                 sapi_get_default_content_type_header(&default_header TSRMLS_CC);
     868           0 :                                 sapi_module.send_header(&default_header, SG(server_context) TSRMLS_CC);
     869           0 :                                 sapi_free_header(&default_header);
     870             :                         }
     871           0 :                         sapi_module.send_header(NULL, SG(server_context) TSRMLS_CC);
     872           0 :                         ret = SUCCESS;
     873           0 :                         break;
     874             :                 case SAPI_HEADER_SEND_FAILED:
     875           0 :                         SG(headers_sent) = 0;
     876           0 :                         ret = FAILURE;
     877             :                         break;
     878             :         }
     879             : 
     880       19221 :         sapi_send_headers_free(TSRMLS_C);
     881             : 
     882       19221 :         return ret;
     883             : }
     884             : 
     885             : 
     886       38693 : SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC)
     887             : {
     888       38693 :         sapi_post_entry *p=post_entries;
     889             : 
     890      135409 :         while (p->content_type) {
     891       77375 :                 if (sapi_register_post_entry(p TSRMLS_CC) == FAILURE) {
     892       19352 :                         return FAILURE;
     893             :                 }
     894       58023 :                 p++;
     895             :         }
     896       19341 :         return SUCCESS;
     897             : }
     898             : 
     899             : 
     900       77375 : SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
     901             : {
     902       77375 :         if (SG(sapi_started) && EG(in_execution)) {
     903           0 :                 return FAILURE;
     904             :         }
     905       77375 :         return zend_hash_add(&SG(known_post_content_types),
     906             :                         post_entry->content_type, post_entry->content_type_len+1,
     907             :                         (void *) post_entry, sizeof(sapi_post_entry), NULL);
     908             : }
     909             : 
     910       19341 : SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
     911             : {
     912       19341 :         if (SG(sapi_started) && EG(in_execution)) {
     913           0 :                 return;
     914             :         }
     915       19341 :         zend_hash_del(&SG(known_post_content_types), post_entry->content_type,
     916             :                         post_entry->content_type_len+1);
     917             : }
     918             : 
     919             : 
     920       19341 : SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D))
     921             : {
     922             :         TSRMLS_FETCH();
     923       19341 :         if (SG(sapi_started) && EG(in_execution)) {
     924           0 :                 return FAILURE;
     925             :         }
     926       19341 :         sapi_module.default_post_reader = default_post_reader;
     927       19341 :         return SUCCESS;
     928             : }
     929             : 
     930             : 
     931       38682 : SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC))
     932             : {
     933             :         TSRMLS_FETCH();
     934       38682 :         if (SG(sapi_started) && EG(in_execution)) {
     935           0 :                 return FAILURE;
     936             :         }
     937       38682 :         sapi_module.treat_data = treat_data;
     938       38682 :         return SUCCESS;
     939             : }
     940             : 
     941       38682 : SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D))
     942             : {
     943             :         TSRMLS_FETCH();
     944       38682 :         if (SG(sapi_started) && EG(in_execution)) {
     945           0 :                 return FAILURE;
     946             :         }
     947       38682 :         sapi_module.input_filter = input_filter;
     948       38682 :         sapi_module.input_filter_init = input_filter_init;
     949       38682 :         return SUCCESS;
     950             : }
     951             : 
     952      916293 : SAPI_API int sapi_flush(TSRMLS_D)
     953             : {
     954      916293 :         if (sapi_module.flush) {
     955      916293 :                 sapi_module.flush(SG(server_context));
     956      916293 :                 return SUCCESS;
     957             :         } else {
     958           0 :                 return FAILURE;
     959             :         }
     960             : }
     961             : 
     962          41 : SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
     963             : {
     964          41 :         if (sapi_module.get_stat) {
     965           0 :                 return sapi_module.get_stat(TSRMLS_C);
     966             :         } else {
     967          41 :                 if (!SG(request_info).path_translated || (VCWD_STAT(SG(request_info).path_translated, &SG(global_stat)) == -1)) {
     968           0 :                         return NULL;
     969             :                 }
     970          41 :                 return &SG(global_stat);
     971             :         }
     972             : }
     973             : 
     974       29280 : SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
     975             : {
     976       29280 :         if (sapi_module.getenv) { 
     977           0 :                 char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
     978           0 :                 if (tmp) {
     979           0 :                         value = estrdup(tmp);
     980             :                 } else {
     981           0 :                         return NULL;
     982             :                 }
     983           0 :                 if (sapi_module.input_filter) {
     984           0 :                         sapi_module.input_filter(PARSE_ENV, name, &value, strlen(value), NULL TSRMLS_CC);
     985             :                 }
     986           0 :                 return value;
     987             :         }
     988       29280 :         return NULL;
     989             : }
     990             : 
     991           0 : SAPI_API int sapi_get_fd(int *fd TSRMLS_DC)
     992             : {
     993           0 :         if (sapi_module.get_fd) {
     994           0 :                 return sapi_module.get_fd(fd TSRMLS_CC);
     995             :         } else {
     996           0 :                 return FAILURE;
     997             :         }
     998             : }
     999             : 
    1000           0 : SAPI_API int sapi_force_http_10(TSRMLS_D)
    1001             : {
    1002           0 :         if (sapi_module.force_http_10) {
    1003           0 :                 return sapi_module.force_http_10(TSRMLS_C);
    1004             :         } else {
    1005           0 :                 return FAILURE;
    1006             :         }
    1007             : }
    1008             : 
    1009             : 
    1010           0 : SAPI_API int sapi_get_target_uid(uid_t *obj TSRMLS_DC)
    1011             : {
    1012           0 :         if (sapi_module.get_target_uid) {
    1013           0 :                 return sapi_module.get_target_uid(obj TSRMLS_CC);
    1014             :         } else {
    1015           0 :                 return FAILURE;
    1016             :         }
    1017             : }
    1018             : 
    1019           0 : SAPI_API int sapi_get_target_gid(gid_t *obj TSRMLS_DC)
    1020             : {
    1021           0 :         if (sapi_module.get_target_gid) {
    1022           0 :                 return sapi_module.get_target_gid(obj TSRMLS_CC);
    1023             :         } else {
    1024           0 :                 return FAILURE;
    1025             :         }
    1026             : }
    1027             : 
    1028       19322 : SAPI_API time_t sapi_get_request_time(TSRMLS_D)
    1029             : {
    1030       19322 :         if(SG(global_request_time)) return SG(global_request_time);
    1031             : 
    1032       19322 :         if (sapi_module.get_request_time && SG(server_context)) {
    1033           0 :                 SG(global_request_time) = sapi_module.get_request_time(TSRMLS_C);
    1034             :         } else {
    1035       19322 :                 SG(global_request_time) = time(0);
    1036             :         }
    1037       19322 :         return SG(global_request_time);
    1038             : }
    1039             : 
    1040           0 : SAPI_API void sapi_terminate_process(TSRMLS_D) {
    1041           0 :         if (sapi_module.terminate_process) {
    1042           0 :                 sapi_module.terminate_process(TSRMLS_C);
    1043             :         }
    1044           0 : }
    1045             : 
    1046             : /*
    1047             :  * Local variables:
    1048             :  * tab-width: 4
    1049             :  * c-basic-offset: 4
    1050             :  * End:
    1051             :  * vim600: sw=4 ts=4 fdm=marker
    1052             :  * vim<600: sw=4 ts=4
    1053             :  */

Generated by: LCOV version 1.10

Generated at Sun, 27 Jul 2014 12:58:42 +0000 (23 hours ago)

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