From: Michael Wallner Date: Sat, 27 May 2006 17:20:09 +0000 (+0000) Subject: - fix usage of request time X-Git-Tag: RELEASE_1_0_0~15 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=98d8a1dced6ae8bde1953f439de7fd9c453e5971;p=m6w6%2Fext-http - fix usage of request time - fixup tests --- diff --git a/http.c b/http.c index 9eb59b9..1d33864 100644 --- a/http.c +++ b/http.c @@ -183,10 +183,12 @@ static void http_globals_init_once(zend_http_globals *G) #define http_globals_init(g) _http_globals_init((g) TSRMLS_CC) 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); +#ifdef HTTP_HAVE_SAPI_RTIME + G->request.time = Z_LVAL_P(http_get_server_var("REQUEST_TIME")); +#else + G->request.time = time(NULL); #endif + G->send.buffer_size = HTTP_SENDBUF_SIZE; G->read_post_data = 0; } diff --git a/http_api.c b/http_api.c index 2254208..db8f46c 100644 --- a/http_api.c +++ b/http_api.c @@ -116,7 +116,7 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC) struct tm nowtm; char datetime[20] = {0}; - now = HTTP_GET_REQUEST_TIME(); + now = HTTP_G->request.time; strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm)); #define HTTP_LOG_WRITE(file, type, msg) \ @@ -208,10 +208,10 @@ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zen if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) { return NULL; } - if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void *) &var)) || (Z_TYPE_PP(var) != IS_STRING)) { + if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void *) &var))) { return NULL; } - if (check && !(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { + if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { return NULL; } return *var; diff --git a/http_cache_api.c b/http_cache_api.c index 7c748cc..9a6ea89 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -64,7 +64,7 @@ PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode dat php_stream_statbuf ssb; switch (data_mode) { - case SEND_DATA: return HTTP_GET_REQUEST_TIME(); + case SEND_DATA: return HTTP_G->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_functions.c b/http_functions.c index e894b19..ad220d3 100644 --- a/http_functions.c +++ b/http_functions.c @@ -55,7 +55,7 @@ PHP_FUNCTION(http_date) } if (t == -1) { - t = (long) HTTP_GET_REQUEST_TIME(); + t = HTTP_G->request.time; } RETURN_STRING(http_date(t), 0); @@ -430,7 +430,7 @@ PHP_FUNCTION(http_send_last_modified) } if (t == -1) { - t = (long) HTTP_GET_REQUEST_TIME(); + t = HTTP_G->request.time; } RETURN_SUCCESS(http_send_last_modified(t)); @@ -510,7 +510,7 @@ PHP_FUNCTION(http_match_modified) // current time if not supplied (senseless though) if (t == -1) { - t = (long) HTTP_GET_REQUEST_TIME(); + t = HTTP_G->request.time; } if (for_range) { @@ -578,7 +578,7 @@ PHP_FUNCTION(http_cache_last_modified) HTTP_CHECK_HEADERS_SENT(RETURN_FALSE); - t = (long) HTTP_GET_REQUEST_TIME(); + t = HTTP_G->request.time; /* 0 or omitted */ if (!last_modified) { @@ -605,7 +605,7 @@ PHP_FUNCTION(http_cache_last_modified) /* {{{ proto bool http_cache_etag([string etag]) * * Attempts to cache the sent entity by its ETag, either supplied or generated - * by the hash algorithm specified by the INI setting "http.etag_mode". + * by the hash algorithm specified by the INI setting "http.etag.mode". * * If the clients "If-None-Match" header matches the supplied/calculated * ETag, the body is considered cached on the clients side and @@ -634,7 +634,7 @@ PHP_FUNCTION(http_cache_etag) /* {{{ proto string ob_etaghandler(string data, int mode) * * For use with ob_start(). Output buffer handler generating an ETag with - * the hash algorithm specified with the INI setting "http.etag_mode". + * the hash algorithm specified with the INI setting "http.etag.mode". */ PHP_FUNCTION(ob_etaghandler) { diff --git a/http_request_api.c b/http_request_api.c index b59d943..7bb54a8 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -745,7 +745,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti if (Z_LVAL_P(zoption) > 0) { HTTP_CURL_OPT(CURLOPT_TIMEVALUE, Z_LVAL_P(zoption)); } else { - HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption)); + HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_G->request.time + Z_LVAL_P(zoption)); } HTTP_CURL_OPT(CURLOPT_TIMECONDITION, (long) (range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE)); } else { diff --git a/http_request_method_api.c b/http_request_method_api.c index 9e428d1..3359b28 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -109,7 +109,7 @@ PHP_RINIT_FUNCTION(http_request_method) zval **data; zend_hash_init(&methods, 0, NULL, ZVAL_PTR_DTOR, 0); - http_parse_params(HTTP_G->request.methods.custom.ini, &methods); + http_parse_params(HTTP_G->request.methods.custom.ini, HTTP_PARAMS_DEFAULT, &methods); FOREACH_HASH_VAL(pos, &methods, data) { if (Z_TYPE_PP(data) == IS_STRING) { http_request_method_register(Z_STRVAL_PP(data), Z_STRLEN_PP(data)); diff --git a/http_send_api.c b/http_send_api.c index 10b02f6..1a77652 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -366,7 +366,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) HTTP_GET_REQUEST_TIME(), (float) php_combined_lcg(TSRMLS_C)); + boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_G->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/php_http.h b/php_http.h index 4e2a7c6..6c378a2 100644 --- a/php_http.h +++ b/php_http.h @@ -33,9 +33,7 @@ #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 @@ -115,6 +113,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http) } send; struct _http_globals_request { + time_t time; struct _http_globals_request_methods { char *allowed; struct _http_globals_request_methods_custom { @@ -125,9 +124,6 @@ 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/tests/INI_001.phpt b/tests/INI_001.phpt deleted file mode 100644 index 9210aad..0000000 --- a/tests/INI_001.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -INI entries ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -string(9) "cache.log" -string(15) "POST, HEAD, GET" -string(1) "1" -Done - diff --git a/tests/allowed_methods_001.phpt b/tests/allowed_methods_001.phpt index b7e3ba5..e0940b3 100644 --- a/tests/allowed_methods_001.phpt +++ b/tests/allowed_methods_001.phpt @@ -10,7 +10,7 @@ checkmax(5.0); --EXPECTF-- diff --git a/tests/allowed_methods_002.phpt b/tests/allowed_methods_002.phpt index 2185d8b..800a805 100644 --- a/tests/allowed_methods_002.phpt +++ b/tests/allowed_methods_002.phpt @@ -10,7 +10,7 @@ checkmin(5.1); --EXPECTF-- diff --git a/tests/etag_mode_001.phpt b/tests/etag_mode_001.phpt index 5acd930..809efee 100644 --- a/tests/etag_mode_001.phpt +++ b/tests/etag_mode_001.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_002.phpt b/tests/etag_mode_002.phpt index 5ca8d8f..3312f32 100644 --- a/tests/etag_mode_002.phpt +++ b/tests/etag_mode_002.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_003.phpt b/tests/etag_mode_003.phpt index 0b98f9f..fd67461 100644 --- a/tests/etag_mode_003.phpt +++ b/tests/etag_mode_003.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_004.phpt b/tests/etag_mode_004.phpt index cd56bae..5ec9f22 100644 --- a/tests/etag_mode_004.phpt +++ b/tests/etag_mode_004.phpt @@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support'); ?> --FILE-- diff --git a/tests/etag_mode_011.phpt b/tests/etag_mode_011.phpt index 205b60a..1d6f039 100644 --- a/tests/etag_mode_011.phpt +++ b/tests/etag_mode_011.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_012.phpt b/tests/etag_mode_012.phpt index 5a8702e..1e4d779 100644 --- a/tests/etag_mode_012.phpt +++ b/tests/etag_mode_012.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_013.phpt b/tests/etag_mode_013.phpt index 919d34e..3c354f8 100644 --- a/tests/etag_mode_013.phpt +++ b/tests/etag_mode_013.phpt @@ -8,7 +8,7 @@ checkmax(5.0); ?> --FILE-- diff --git a/tests/etag_mode_014.phpt b/tests/etag_mode_014.phpt index c6f1731..bcdefca 100644 --- a/tests/etag_mode_014.phpt +++ b/tests/etag_mode_014.phpt @@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support'); ?> --FILE-- diff --git a/tests/etag_mode_031.phpt b/tests/etag_mode_031.phpt index a7d02f1..813b309 100644 --- a/tests/etag_mode_031.phpt +++ b/tests/etag_mode_031.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_032.phpt b/tests/etag_mode_032.phpt index 71ae9d3..8757118 100644 --- a/tests/etag_mode_032.phpt +++ b/tests/etag_mode_032.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_033.phpt b/tests/etag_mode_033.phpt index f72b524..3f75c16 100644 --- a/tests/etag_mode_033.phpt +++ b/tests/etag_mode_033.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_034.phpt b/tests/etag_mode_034.phpt index bc9d311..bce9e52 100644 --- a/tests/etag_mode_034.phpt +++ b/tests/etag_mode_034.phpt @@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support'); ?> --FILE-- diff --git a/tests/etag_mode_041.phpt b/tests/etag_mode_041.phpt index e367de8..694608e 100644 --- a/tests/etag_mode_041.phpt +++ b/tests/etag_mode_041.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_042.phpt b/tests/etag_mode_042.phpt index 5c77db4..59d7f42 100644 --- a/tests/etag_mode_042.phpt +++ b/tests/etag_mode_042.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_043.phpt b/tests/etag_mode_043.phpt index dbb5438..065bc93 100644 --- a/tests/etag_mode_043.phpt +++ b/tests/etag_mode_043.phpt @@ -8,7 +8,7 @@ checkmin(5.1); ?> --FILE-- diff --git a/tests/etag_mode_044.phpt b/tests/etag_mode_044.phpt index 055395a..0d8129a 100644 --- a/tests/etag_mode_044.phpt +++ b/tests/etag_mode_044.phpt @@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support'); ?> --FILE--