- some housekeeping
authorMichael Wallner <mike@php.net>
Thu, 19 Jan 2006 11:42:08 +0000 (11:42 +0000)
committerMichael Wallner <mike@php.net>
Thu, 19 Jan 2006 11:42:08 +0000 (11:42 +0000)
- use sapi_get_request_time() where reasonable

27 files changed:
http.c
http_api.c
http_cache_api.c
http_date_api.c
http_deflatestream_object.c
http_encoding_api.c
http_exception_object.c
http_filter_api.c
http_functions.c
http_headers_api.c
http_inflatestream_object.c
http_info_api.c
http_message_api.c
http_message_object.c
http_request_api.c
http_request_body_api.c
http_request_method_api.c
http_request_object.c
http_request_pool_api.c
http_requestpool_object.c
http_response_object.c
http_send_api.c
http_url_api.c
http_util_object.c
missing.c
php_http.h
php_http_cache_api.h

diff --git a/http.c b/http.c
index 26ab4d3bb0981924860f060dcde9521f19f9451c..768277ca00ab1f6bd7f56e05c5c2270f5e0069b3 100644 (file)
--- a/http.c
+++ b/http.c
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
 #define HTTP_WANT_ZLIB
 #define HTTP_WANT_MAGIC
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "php_ini.h"
 #include "ext/standard/info.h"
 #include "zend_extensions.h"
@@ -171,6 +167,9 @@ static void http_globals_init_once(zend_http_globals *G)
 static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
 {
        G->send.buffer_size = HTTP_SENDBUF_SIZE;
+#ifndef HTTP_HAVE_SAPI_RTIME
+       G->request_time = time(NULL);
+#endif
 }
 
 #define http_globals_free(g) _http_globals_free((g) TSRMLS_CC)
@@ -285,13 +284,13 @@ PHP_MSHUTDOWN_FUNCTION(http)
 /* {{{ PHP_RINIT_FUNCTION */
 PHP_RINIT_FUNCTION(http)
 {
+       http_globals_init(HTTP_GLOBALS);
+
        if (HTTP_G(request).methods.allowed) {
                http_check_allowed_methods(HTTP_G(request).methods.allowed, 
                        strlen(HTTP_G(request).methods.allowed));
        }
 
-       http_globals_init(HTTP_GLOBALS);
-
        if (    (SUCCESS != PHP_RINIT_CALL(http_request_method))
 #ifdef HTTP_HAVE_ZLIB  
                ||      (SUCCESS != PHP_RINIT_CALL(http_encoding))
index 3f4b7a66072b9af63905daee897931fffcc86b49..3969b82fd156d50ca69037893b199964713adbf7 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "php_output.h"
 #include "ext/standard/url.h"
 
@@ -208,7 +204,7 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
        struct tm nowtm;
        char datetime[20] = {0};
        
-       time(&now);
+       now = HTTP_GET_REQUEST_TIME();
        strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
 
 #define HTTP_LOG_WRITE(file, type, msg) \
index 2685cc99595dd3596320a7a779cc4d0beb0d1a13..c8ab27cdd8bac0fa322d56a80eb2823f1030285d 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "php_output.h"
 #include "php_streams.h"
 
@@ -69,7 +65,7 @@ PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode dat
 
        switch (data_mode)
        {
-               case SEND_DATA: return time(NULL);
+               case SEND_DATA: return HTTP_GET_REQUEST_TIME();
                case SEND_RSRC: return php_stream_stat((php_stream *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
                default:                return php_stream_stat_path((char *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
        }
index 31898de486972122ccc0d77ba5345d209d093227..ba6ef45ef13321838d508af622bf55a342aba464 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
+
 #include "php_http_api.h"
 #include "php_http_date_api.h"
 
index 1e1f0970294320fe840377f21aae16281e3552b6..560cdc6354830fb867133af8b3c0c6678c9c3851 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
index 534b7628a1e3c65bc525c1b892d31d99fd72352e..dc575cdf0d673196df1d8fa4fa7ae7fef6c0a7f0 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
index 8e1ffeedeed79a18c170484efcd688a6b5f4882f..294239f5c53bd9af4e41614786712f94ac60aba7 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
 
 #ifdef ZEND_ENGINE_2
index f7e99ec3a12c13bd488bc13468a62e55c37c1f5a..35cff1cdb2b837937cc6418c26ebd2e8462e260d 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
index 4ece6965114f435e7312445828109f59fef155e0..d9acab978d3e21568fac7179f2fe5a48282436c2 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "php_ini.h"
-#include "ext/standard/info.h"
 #include "ext/standard/php_string.h"
 #include "zend_operators.h"
 
@@ -59,7 +54,7 @@ PHP_FUNCTION(http_date)
        }
 
        if (t == -1) {
-               t = (long) time(NULL);
+               t = (long) HTTP_GET_REQUEST_TIME();
        }
 
        RETURN_STRING(http_date(t), 0);
@@ -376,7 +371,7 @@ PHP_FUNCTION(http_send_last_modified)
        }
 
        if (t == -1) {
-               t = (long) time(NULL);
+               t = (long) HTTP_GET_REQUEST_TIME();
        }
 
        RETURN_SUCCESS(http_send_last_modified(t));
@@ -456,7 +451,7 @@ PHP_FUNCTION(http_match_modified)
 
        // current time if not supplied (senseless though)
        if (t == -1) {
-               t = (long) time(NULL);
+               t = (long) HTTP_GET_REQUEST_TIME();
        }
 
        if (for_range) {
@@ -524,7 +519,7 @@ PHP_FUNCTION(http_cache_last_modified)
        
        HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
 
-       t = (long) time(NULL);
+       t = (long) HTTP_GET_REQUEST_TIME();
 
        /* 0 or omitted */
        if (!last_modified) {
index 96110d337779e2441f56668f9ab0a9db92463aa7..2493218e2ece1ed848ed6531b4f2430c10b091f8 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
 
 #include "ext/standard/url.h"
index c107cd3c1ccd23a4de4db42edec5ecc202644893..73225bd9b041d9a4ca69870c54f50673d40dccbf 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
index 2cf34f016609a1bebb8310f2a63cb4ad5cee198d..8e45de36cd8b1179866c59371c403ac40f73dc4a 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
 
 #include "php_http_api.h"
index 853cdb7d2ada74dd509e9265cfd6c0a532fe1192..93c4bf1d5cbb1ba027511b45d3f2db12d769b59e 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
 #define HTTP_WANT_ZLIB
 #include "php_http.h"
 
-#include "SAPI.h"
-
 #include "php_http_api.h"
 #include "php_http_encoding_api.h"
 #include "php_http_headers_api.h"
index b9fdc364b7a01768f06f13ec993a24716dc6c611..4634cabb143e7d2783b867d5ab548e46a0372680 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
 
 #ifdef ZEND_ENGINE_2
index 9818721a1efd0921a65baf260b4285bef6d33a76..444e43fe5a6929992d3c04317a55d9ac9485cf1c 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
@@ -590,7 +587,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                        if (Z_LVAL_P(zoption) > 0) {
                                HTTP_CURL_OPT(TIMEVALUE, Z_LVAL_P(zoption));
                        } else {
-                               HTTP_CURL_OPT(TIMEVALUE, time(NULL) + Z_LVAL_P(zoption));
+                               HTTP_CURL_OPT(TIMEVALUE, HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption));
                        }
                        HTTP_CURL_OPT(TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE);
                } else {
index e7fe1c81c9250abd91b87f61c527f302f5e2f4ac..14a235d397f662ef9e9d6e057079500270bffc1e 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
index f1bd6510e4c7135171a9261560326821d95c1424..4cc0a6ae14f5fffd1d1cfae7ee30edecc15a9f0d 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
index a9bd3bb12c3a436c92efb4275f4c8f93525dd276..80d802f81ebcdc7cc4e1e1cb63fdce821461e2e2 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
index 53ecb21555ac71ee04f1940f5222759d0315a712..31261cf1d2f4c3281e0e3c0830fc2a34bc3902ce 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
index 004ab835d70b332598fb2bd7f3ceb9100eb65c9e..65eff18c58f08d3e4240e7ee3829acb2ab5942f5 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #define HTTP_WANT_CURL
 #include "php_http.h"
 
index eda4e763cf520e964b9a1a925cb18d5e6a7b5818..73aa0d86535a47c7181018fe004a789b72584453 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_MAGIC
 #include "php_http.h"
 
 /* broken static properties in PHP 5.0 */
 #if defined(ZEND_ENGINE_2) && !defined(WONKY)
 
-#include "SAPI.h"
 #include "php_ini.h"
 
 #include "php_http_api.h"
@@ -1104,7 +1099,7 @@ PHP_METHOD(HttpResponse, send)
                cctl = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl), &cctl_p);
 
                http_cache_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
-               http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : time(NULL), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
+               http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : HTTP_GET_REQUEST_TIME(), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
 
                if (etag_p) zval_ptr_dtor(&etag_p);
                if (lmod_p) zval_ptr_dtor(&lmod_p);
index 62660359026f03581012666a8a1add9101dae87a..0db19b36a9c509640b7ff644fd46c21208eda75e 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_ZLIB
 #define HTTP_WANT_MAGIC
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "php_streams.h"
 #include "ext/standard/php_lcg.h"
 
@@ -363,7 +359,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s
                                        char boundary_str[32], range_header_str[256];
                                        size_t boundary_len, range_header_len;
                                        
-                                       boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) time(NULL), (float) php_combined_lcg(TSRMLS_C));
+                                       boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_GET_REQUEST_TIME(), (float) php_combined_lcg(TSRMLS_C));
                                        range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
                                        
                                        http_send_status_header_ex(206, range_header_str, range_header_len, 1);
index 6ca33514e7e640a9e8bc55ca76307f1c341f12da..db4ca96fd7abe76a47fdca84c9473eddcaa44845 100644 (file)
 
 /* $Id$ */
 
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
+#define HTTP_WANT_SAPI
 #define HTTP_WANT_NETDB
 #include "php_http.h"
 
-#include "SAPI.h"
 #include "zend_ini.h"
 #include "php_output.h"
 #include "ext/standard/php_string.h"
index 7c2a10726af2526e46bf0b27ce46684c8be67656..6a45635b6c3b9d60d26d3b88b62de91e33c97a9b 100644 (file)
 
 /* $Id$ */
 
-
-#ifdef HAVE_CONFIG_H
-#      include "config.h"
-#endif
-
 #include "php_http.h"
 
 #ifdef ZEND_ENGINE_2
index 1ca6cbbbadd80a6ce49198190e7c4209f0e3babf..590c2c904982ee552cd5181d4243c1bd84921ea3 100644 (file)
--- a/missing.c
+++ b/missing.c
 
 /* $Id$ */
 
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#else
+#      include "php_config.h"
+#endif
+
 #include "php.h"
 #include "missing.h"
 
index 0fbbb55172a76353b650536c6c04c0dc0dfde6ea..7d20048083321bfab807c6938b929f7ee45d9b79 100644 (file)
 
 #define PHP_EXT_HTTP_VERSION "0.22.0-dev"
 
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#else
+#      include "php_config.h"
+#endif
+
 #include "php.h"
 #include "php_http_std_defs.h"
 #include "phpstr/phpstr.h"
 #include "missing.h"
 
+#ifdef HTTP_WANT_SAPI
+#      if PHP_API_VERSION > 20041225
+#              define HTTP_HAVE_SAPI_RTIME
+#              define HTTP_GET_REQUEST_TIME() sapi_get_request_time(TSRMLS_C)
+#      else
+#              define HTTP_GET_REQUEST_TIME() HTTP_G(request_time)
+#      endif
+#      include "SAPI.h"
+#endif
+
 #ifdef HTTP_WANT_NETDB
 #      ifdef PHP_WIN32
 #              define HTTP_HAVE_NETDB
@@ -102,6 +118,9 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
                } methods;
        } request;
 
+#ifndef HTTP_HAVE_SAPI_RTIME
+       time_t request_time;
+#endif
 #ifdef ZEND_ENGINE_2
        zend_bool only_exceptions;
 #endif
index 7ca8998dd1d5453aa4706e1ad7d3647ad4bfcff6..a1d62eef20d922e2431963317bd1ce793502ebfc 100644 (file)
@@ -33,7 +33,7 @@
 #define http_etag_digest(d, l) _http_etag_digest((d), (l))
 static inline char *_http_etag_digest(const unsigned char *digest, int len)
 {
-       static const char hexdigits[16] = "0123456789abcdef";
+       static const char hexdigits[17] = "0123456789abcdef";
        int i;
        char *hex = emalloc(len * 2 + 1);
        char *ptr = hex;