- fix usage of request time
authorMichael Wallner <mike@php.net>
Sat, 27 May 2006 17:20:09 +0000 (17:20 +0000)
committerMichael Wallner <mike@php.net>
Sat, 27 May 2006 17:20:09 +0000 (17:20 +0000)
- fixup tests

27 files changed:
http.c
http_api.c
http_cache_api.c
http_functions.c
http_request_api.c
http_request_method_api.c
http_send_api.c
php_http.h
tests/INI_001.phpt [deleted file]
tests/allowed_methods_001.phpt
tests/allowed_methods_002.phpt
tests/etag_mode_001.phpt
tests/etag_mode_002.phpt
tests/etag_mode_003.phpt
tests/etag_mode_004.phpt
tests/etag_mode_011.phpt
tests/etag_mode_012.phpt
tests/etag_mode_013.phpt
tests/etag_mode_014.phpt
tests/etag_mode_031.phpt
tests/etag_mode_032.phpt
tests/etag_mode_033.phpt
tests/etag_mode_034.phpt
tests/etag_mode_041.phpt
tests/etag_mode_042.phpt
tests/etag_mode_043.phpt
tests/etag_mode_044.phpt

diff --git a/http.c b/http.c
index 9eb59b99e600625eb57946d109e65f6d699dd8aa..1d338647995718d39b9507eb3dfdca16de379ded 100644 (file)
--- 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;
 }
 
index 22542083ee1e88b3a01bbbe46909ae644f1dc281..db8f46c0097d0432408ba17d52ee500755736bbd 100644 (file)
@@ -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;
index 7c748cc46023c73769fc5099bce37d003aed13bf..9a6ea89057ea0d122ad68d98b63b958de507f614 100644 (file)
@@ -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;
        }
index e894b19ebe4ec892a94e3fb7fab5f0c1533c5b5b..ad220d3024c349849303ff1aee2a47fb881ae5bf 100644 (file)
@@ -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)
 {
index b59d943e736853f43eb23df6db80c8fcc0dd784e..7bb54a86c7cc4555186c0f666fcddcbe6db0a52f 100644 (file)
@@ -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 {
index 9e428d15ce9ff37960e69f786daad2cca2416a4e..3359b28ad501f5fce3b474b7fbb0b80b7678f114 100644 (file)
@@ -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));
index 10b02f69663095feb7a7576edae547274cb99d44..1a7765282ee8afa88a302f87040b5eddf19da48b 100644 (file)
@@ -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);
index 4e2a7c67bc5e0c2b49f418b354c39224af60e1b8..6c378a224e5926827f95c50d23c92920e020588b 100644 (file)
@@ -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 (file)
index 9210aad..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-INI entries
---SKIPIF--
-<?php
-include 'skip.inc';
-?>
---FILE--
-<?php
-echo "-TEST\n";
-ini_set('http.cache_log', 'cache.log');
-var_dump(ini_get('http.cache_log'));
-ini_set('http.allowed_methods', 'POST, HEAD, GET');
-var_dump(ini_get('http.allowed_methods'));
-ini_set('http.only_exceptions', true);
-var_dump(ini_get('http.only_exceptions'));
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-string(9) "cache.log"
-string(15) "POST, HEAD, GET"
-string(1) "1"
-Done
-
index b7e3ba5725c7a42bd7979e7caa7db0177b584c8f..e0940b38f5226116fc56f48f0913729842f89f46 100644 (file)
@@ -10,7 +10,7 @@ checkmax(5.0);
 <?php
 include 'log.inc';
 log_prepare(_AMETH_LOG);
-ini_set('http.allowed_methods', 'POST');
+ini_set('http.request.methods.allowed', 'POST');
 echo "Done\n";
 ?>
 --EXPECTF--
index 2185d8b3ca945dfa1f57a7a2de6bee5719324dca..800a805f3ba69d5a72b6fce3760bbc9748cbf479 100644 (file)
@@ -10,7 +10,7 @@ checkmin(5.1);
 <?php
 include 'log.inc';
 log_prepare(_AMETH_LOG);
-ini_set('http.allowed_methods', 'POST');
+ini_set('http.request.methods.allowed', 'POST');
 echo "Done\n";
 ?>
 --EXPECTF--
index 5acd930792b0ebf4b4f0e9ef2e1e8f6ee28b895c..809efeea9d65d660336bda5f8ec7407e563e8ec6 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'crc32');
+ini_set('http.etag.mode', 'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 5ca8d8ff90b071612b18128ce25b6a4f67de667c..3312f32a8f99ab91c9092192a3d4cd9c3a1ebeb6 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha1');
+ini_set('http.etag.mode', 'sha1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 0b98f9f45573802b00221f03fedab09b3bb26a48..fd67461cce5a3207f968b934c53d1d0a9388efee 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'md5');
+ini_set('http.etag.mode', 'md5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index cd56bae38eb5fbc75e78709b71e540860c94a958..5ec9f22c5ff97e2fe3eb4d60d43e596eb9dc2736 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 205b60ac8dae75c54e69bab4e0f30329f1f4d0be..1d6f039981c372e98ebc38e9c916ddb9c0503c96 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'crc32');
+ini_set('http.etag.mode', 'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 5a8702ed9569f5c98eb3db396517fe08265f42b1..1e4d779f6c67699db7fc1d54b13ee0e8ae5b2ee5 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha1');
+ini_set('http.etag.mode', 'sha1');
 http_cache_etag();
 print("abc\n");
 ?>
index 919d34e9d0bbd457dc1b5e993b46df19b5610cf5..3c354f8e0dcdf4fdd23cd4eec2af6abe36994426 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'md5');
+ini_set('http.etag.mode', 'md5');
 http_cache_etag();
 print("abc\n");
 ?>
index c6f17314a08acad1e29085f1e16d28204a8c585f..bcdefcae9733c38cec064e6c846b10829ea1ed03 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>
index a7d02f16062e30c3aed48ed6292363e417d0176c..813b309373e60b293f2f6360ef4f3a616637ee83 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', extension_loaded('hash')?'crc32b':'crc32');
+ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 71ae9d32cdc0be5edbf0ac22714a52eef2cdb091..87571182c53cfaaf64a0c3149d791fcc57ba3492 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'SHA1');
+ini_set('http.etag.mode', 'SHA1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index f72b524a6091840dc4eca4a77fff021690ee9d46..3f75c1608d759813cc963d8d615e7b0bd5e9dcd3 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'MD5');
+ini_set('http.etag.mode', 'MD5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index bc9d31161f83b570d1e16c86133c78247a66904c..bce9e527c883e51f237beab45a0d517e46f36fca 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index e367de8cf536787e08e1b45e2546f08fed8e2687..694608ed5ab6b4fddf461e7a8494fcf60585028d 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', extension_loaded('hash')?'crc32b':'crc32');
+ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 5c77db4ca3160cec72602ca5af15c90e0a41c532..59d7f42a8bac78149614da094760eed30e791141 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'SHA1');
+ini_set('http.etag.mode', 'SHA1');
 http_cache_etag();
 print("abc\n");
 ?>
index dbb5438e6577abc4abae606417dfdd497b5c9142..065bc936d8ba77a5c75f73d4346be0cbe4440445 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'bogus');
+ini_set('http.etag.mode', 'bogus');
 http_cache_etag();
 print("abc\n");
 ?>
index 055395a71d86eae264f301fc8438ef5727df09bc..0d8129ad257d093bd02ca1d4dae056e459080fd3 100644 (file)
@@ -9,7 +9,7 @@ skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', 'sha256');
+ini_set('http.etag.mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>