From 4fcbd8e8ae31611c5197ff2369673b5939fc2b80 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 19 Jan 2006 11:42:08 +0000 Subject: [PATCH] - some housekeeping - use sapi_get_request_time() where reasonable --- http.c | 13 ++++++------- http_api.c | 8 ++------ http_cache_api.c | 8 ++------ http_date_api.c | 5 +---- http_deflatestream_object.c | 5 ----- http_encoding_api.c | 4 ---- http_exception_object.c | 5 ----- http_filter_api.c | 4 ---- http_functions.c | 15 +++++---------- http_headers_api.c | 4 ---- http_inflatestream_object.c | 5 ----- http_info_api.c | 4 ---- http_message_api.c | 7 +------ http_message_object.c | 5 ----- http_request_api.c | 7 ++----- http_request_body_api.c | 4 ---- http_request_method_api.c | 4 ---- http_request_object.c | 4 ---- http_request_pool_api.c | 4 ---- http_requestpool_object.c | 4 ---- http_response_object.c | 9 ++------- http_send_api.c | 8 ++------ http_url_api.c | 6 +----- http_util_object.c | 5 ----- missing.c | 6 ++++++ php_http.h | 19 +++++++++++++++++++ php_http_cache_api.h | 2 +- 27 files changed, 50 insertions(+), 124 deletions(-) diff --git a/http.c b/http.c index 26ab4d3..768277c 100644 --- a/http.c +++ b/http.c @@ -12,16 +12,12 @@ /* $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)) diff --git a/http_api.c b/http_api.c index 3f4b7a6..3969b82 100644 --- a/http_api.c +++ b/http_api.c @@ -12,13 +12,9 @@ /* $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) \ diff --git a/http_cache_api.c b/http_cache_api.c index 2685cc9..c8ab27c 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -12,13 +12,9 @@ /* $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; } diff --git a/http_date_api.c b/http_date_api.c index 31898de..ba6ef45 100644 --- a/http_date_api.c +++ b/http_date_api.c @@ -12,11 +12,8 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" + #include "php_http_api.h" #include "php_http_date_api.h" diff --git a/http_deflatestream_object.c b/http_deflatestream_object.c index 1e1f097..560cdc6 100644 --- a/http_deflatestream_object.c +++ b/http_deflatestream_object.c @@ -12,11 +12,6 @@ /* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_ZLIB #include "php_http.h" diff --git a/http_encoding_api.c b/http_encoding_api.c index 534b762..dc575cd 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_ZLIB #include "php_http.h" diff --git a/http_exception_object.c b/http_exception_object.c index 8e1ffee..294239f 100644 --- a/http_exception_object.c +++ b/http_exception_object.c @@ -12,11 +12,6 @@ /* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" #ifdef ZEND_ENGINE_2 diff --git a/http_filter_api.c b/http_filter_api.c index f7e99ec..35cff1c 100644 --- a/http_filter_api.c +++ b/http_filter_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_ZLIB #include "php_http.h" diff --git a/http_functions.c b/http_functions.c index 4ece696..d9acab9 100644 --- a/http_functions.c +++ b/http_functions.c @@ -12,17 +12,12 @@ /* $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) { diff --git a/http_headers_api.c b/http_headers_api.c index 96110d3..2493218 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" #include "ext/standard/url.h" diff --git a/http_inflatestream_object.c b/http_inflatestream_object.c index c107cd3..73225bd 100644 --- a/http_inflatestream_object.c +++ b/http_inflatestream_object.c @@ -12,11 +12,6 @@ /* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_ZLIB #include "php_http.h" diff --git a/http_info_api.c b/http_info_api.c index 2cf34f0..8e45de3 100644 --- a/http_info_api.c +++ b/http_info_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" #include "php_http_api.h" diff --git a/http_message_api.c b/http_message_api.c index 853cdb7..93c4bf1 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -12,16 +12,11 @@ /* $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" diff --git a/http_message_object.c b/http_message_object.c index b9fdc36..4634cab 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -12,11 +12,6 @@ /* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" #ifdef ZEND_ENGINE_2 diff --git a/http_request_api.c b/http_request_api.c index 9818721..444e43f 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -12,10 +12,7 @@ /* $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 { diff --git a/http_request_body_api.c b/http_request_body_api.c index e7fe1c8..14a235d 100644 --- a/http_request_body_api.c +++ b/http_request_body_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" diff --git a/http_request_method_api.c b/http_request_method_api.c index f1bd651..4cc0a6a 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" diff --git a/http_request_object.c b/http_request_object.c index a9bd3bb..80d802f 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" diff --git a/http_request_pool_api.c b/http_request_pool_api.c index 53ecb21..31261cf 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" diff --git a/http_requestpool_object.c b/http_requestpool_object.c index 004ab83..65eff18 100644 --- a/http_requestpool_object.c +++ b/http_requestpool_object.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" diff --git a/http_response_object.c b/http_response_object.c index eda4e76..73aa0d8 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -12,18 +12,13 @@ /* $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); diff --git a/http_send_api.c b/http_send_api.c index 6266035..0db19b3 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -12,15 +12,11 @@ /* $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); diff --git a/http_url_api.c b/http_url_api.c index 6ca3351..db4ca96 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -12,14 +12,10 @@ /* $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" diff --git a/http_util_object.c b/http_util_object.c index 7c2a107..6a45635 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -12,11 +12,6 @@ /* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "php_http.h" #ifdef ZEND_ENGINE_2 diff --git a/missing.c b/missing.c index 1ca6cbb..590c2c9 100644 --- a/missing.c +++ b/missing.c @@ -12,6 +12,12 @@ /* $Id$ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#else +# include "php_config.h" +#endif + #include "php.h" #include "missing.h" diff --git a/php_http.h b/php_http.h index 0fbbb55..7d20048 100644 --- a/php_http.h +++ b/php_http.h @@ -17,11 +17,27 @@ #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 diff --git a/php_http_cache_api.h b/php_http_cache_api.h index 7ca8998..a1d62ee 100644 --- a/php_http_cache_api.h +++ b/php_http_cache_api.h @@ -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; -- 2.30.2