- drop mhash support
authorMichael Wallner <mike@php.net>
Mon, 21 Nov 2005 16:48:27 +0000 (16:48 +0000)
committerMichael Wallner <mike@php.net>
Mon, 21 Nov 2005 16:48:27 +0000 (16:48 +0000)
35 files changed:
config.m4
config.w32
docs/functions.html
docs/http.ini
http.c
http.dsp
http_api.c
http_cache_api.c
http_functions.c
http_response_object.c
package2.xml
php_http.h
php_http_api.h
php_http_cache_api.h
tests/etag_mode_001.phpt
tests/etag_mode_002.phpt
tests/etag_mode_003.phpt
tests/etag_mode_004.phpt
tests/etag_mode_005.phpt [deleted file]
tests/etag_mode_011.phpt
tests/etag_mode_012.phpt
tests/etag_mode_013.phpt
tests/etag_mode_014.phpt
tests/etag_mode_015.phpt [deleted file]
tests/etag_mode_031.phpt
tests/etag_mode_032.phpt
tests/etag_mode_033.phpt
tests/etag_mode_034.phpt
tests/etag_mode_035.phpt [deleted file]
tests/etag_mode_041.phpt
tests/etag_mode_042.phpt
tests/etag_mode_043.phpt
tests/etag_mode_044.phpt
tests/etag_mode_045.phpt [deleted file]
tests/etag_mode_crc.phpt [deleted file]

index 9b6176f48f49105e89a250f861d66692847c9f2e..1e8eff1a44d228fa434bebd4d35264ecd3e9929b 100644 (file)
--- a/config.m4
+++ b/config.m4
@@ -7,9 +7,6 @@ PHP_ARG_ENABLE([http], [whether to enable extended HTTP support],
 PHP_ARG_WITH([http-curl-requests], [whether to enable cURL HTTP requests],
 [  --with-http-curl-requests[=CURLDIR]
                            With cURL HTTP request support])
-PHP_ARG_WITH([http-mhash-etags], [whether to enable mhash ETag generator],
-[  --with-http-mhash-etags[=MHASHDIR]
-                           With mhash ETag generator support])
 PHP_ARG_WITH([http-magic-mime], [whether to enable response content type guessing],
 [  --with-http-magic-mime[=MAGICDIR]
                            With magic mime response content type guessing])
@@ -133,31 +130,6 @@ dnl ----
                )
        fi
 
-dnl ----
-dnl MHASH
-dnl ----
-       if test "$PHP_HTTP_MHASH_ETAGS" != "no"; then
-       
-               AC_MSG_CHECKING([for mhash.h])
-               MHASH_DIR=
-               for i in "$PHP_HTTP_MHASH_ETAGS" /usr/local /usr /opt; do
-                       if test -f "$i/include/mhash.h"; then
-                               MHASH_DIR=$i
-                               break
-                       fi
-               done
-               if test -z "$MHASH_DIR"; then
-                       AC_MSG_RESULT([not found])
-                       AC_MSG_ERROR([could not find mhash.h])
-               else
-                       AC_MSG_RESULT([found in $MHASH_DIR])
-               fi
-       
-               PHP_ADD_INCLUDE($MHASH_DIR/include)
-               PHP_ADD_LIBRARY_WITH_PATH(mhash, $MHASH_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-               AC_DEFINE([HTTP_HAVE_MHASH], [1], [Have mhash support])
-       fi
-
 dnl ----
 dnl MAGIC
 dnl ----
@@ -183,6 +155,12 @@ dnl ----
                AC_DEFINE([HTTP_HAVE_MAGIC], [1], [Have magic mime support])
        fi
 
+dnl ----
+dnl HASH
+dnl ----
+
+       dnl TODO
+
 dnl ----
 dnl DONE
 dnl ----
@@ -206,7 +184,7 @@ dnl ----
        dnl outside src dir, adds install-http target
        PHP_ADD_MAKEFILE_FRAGMENT
        dnl within src dir, installs http headers
-       ifdef([PHP_INSTALL_HEADERS], [PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADER_FILES)], [ ])
+       ifdef([PHP_INSTALL_HEADERS], [PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)], [ ])
 
        AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
 fi
index af89ae71b32489b3c69d95d387f03fab68907deb..a53455ee5ca019956006f8aa3f3655db6c64eaf8 100644 (file)
@@ -31,21 +31,19 @@ if (PHP_HTTP != "no") {
        }
        
        if (PHP_HASH != "no") {
-               if (glob(configure_module_dirname +"\\..\\hash\\php_hash_sha.h").length) {
-                       ADD_FLAG("CFLAGS_HTTP", "/I"+ configure_module_dirname +"\\..\\hash");
-                       AC_DEFINE("HTTP_HAVE_HASH_EXT_INCLUDES", 1, "");
+               var f;
+               STDOUT.Write("Checking for ext/hash ...  ");
+               if (glob((f = configure_module_dirname +"\\..\\hash") +"\\php_hash.h").length ||
+                       glob((f = configure_module_dirname +"\\..\\..\\..\\pecl\\hash") +"\\php_hash.h").length) {
+                       ADD_FLAG("CFLAGS_HTTP", "/I"+ f);
+                       AC_DEFINE("HTTP_HAVE_EXT_HASH", 1, "");
+                       ADD_EXTENSION_DEP("http", "hash", true);
+                       STDOUT.WriteLine(condense_path(f));
+               } else {
+                       STDOUT.WriteLine("<not found>");
                }
        }
 
-       MHASH_LIB = PHP_DEBUG != "no" ? "libmhash-staticd.lib":"libmhash-static.lib";
-       if (CHECK_HEADER_ADD_INCLUDE('mhash.h', 'CFLAGS_HTTP') &&
-                       (CHECK_LIB(MHASH_LIB, 'http', PHP_HTTP) ||
-                               CHECK_LIB('libmhash.lib', 'http', PHP_HTTP))) {
-               AC_DEFINE('HTTP_HAVE_MHASH', 1 , "Have mhash library");
-       } else {
-               WARNING("mhash etag generator not enabled; libraries and headers not found");
-       }
-
        CURL_LIB = PHP_DEBUG != "no" ? "libcurld.lib":"libcurl.lib";
     if (CHECK_HEADER_ADD_INCLUDE("curl/curl.h", "CFLAGS_HTTP") &&
                CHECK_HEADER_ADD_INCLUDE("openssl/crypto.h", "CFLAGS_HTTP") &&
index e1329bb6d9034cea8ed295454eae73dda45a755c..b815071d31a3cf5b33523658f2e578956c086127 100644 (file)
@@ -113,6 +113,19 @@ if none match.</p>
 <span style="color: #0000BB">&lt;?php<br />$charsets&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #FF8000">//&nbsp;default<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-2'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-15'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'utf-8'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$pref&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">http_negotiate_charset</span><span style="color: #007700">(</span><span style="color: #0000BB">$charsets</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">strcmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$pref</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">iconv_set_encoding</span><span style="color: #007700">(</span><span style="color: #DD0000">'internal_encoding'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">iconv_set_encoding</span><span style="color: #007700">(</span><span style="color: #DD0000">'output_encoding'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pref</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ob_start</span><span style="color: #007700">(</span><span style="color: #DD0000">'ob_iconv_handler'</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span><br />
 </span></code></blockquote></p>
 <p></pre></p>
+<h2 id="http_negotiate_content_type">string http_negotiate_ctype(array supported[, array &result])</h2>
+<p>This function negotiates the clients preferred content type based on its<br />
+Accept HTTP header.  The qualifier is recognized and content types <br />
+without qualifier are rated highest.</p>
+<p>Expects an array as parameter cotaining the supported content types as values.<br />
+If the optional second parameter is supplied, it will be filled with an<br />
+array containing the negotiation results.</p>
+<p>Returns the negotiated content type or the default content type <br />
+(i.e. first array entry) if none match.</p>
+<p>Example:</p><pre><blockquote><code><span style="color: #000000"><br />
+<span style="color: #0000BB">&lt;?php<br />$ctypes&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'application/xhtml+xml'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'text/html'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">http_send_content_type</span><span style="color: #007700">(</span><span style="color: #0000BB">http_negotiate_content_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$ctypes</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span><br />
+</span></code></blockquote></p>
+<p></pre></p>
 <h2 id="http_send_status">bool http_send_status(int status)</h2>
 <p>Send HTTP status code.</p>
 <p>Expects an HTTP status code as parameter.</p>
@@ -384,8 +397,6 @@ all supported features that depend on external libraries.</p>
       and SSL requests can be issued <br />
  <li> HTTP_SUPPORT_ENCODINGS: whether ext/http was linked against zlib,<br />
       and compressed HTTP responses can be decoded<br />
- <li> HTTP_SUPPORT_MHASHETAGS: whether ext/http was linked against libmhash,<br />
-      and ETags can be generated with the available mhash algorithms<br />
  <li> HTTP_SUPPORT_MAGICMIME: whether ext/http was linked against libmagic,<br />
       and the HttpResponse::guessContentType() method is usable<br />
 </ul></p>
@@ -480,6 +491,15 @@ This provides limited functionality compared to HttpRequest and HttpResponse.</p
 <p>Accepts a bool parameter which specifies whether the returned string<br />
 should also contain any parent messages.</p>
 <p>Returns the full message as string.</p>
+<h3 id="HttpMessage_count">int HttpMessage::count()</h3>
+<p>Implements Countable.</p>
+<p>Returns the number of parent messages + 1.</p>
+<h3 id="HttpMessage_serialize">string HttpMessage::serialize()</h3>
+<p>Implements Serializable.</p>
+<p>Returns the serialized representation of the HttpMessage.</p>
+<h3 id="HttpMessage_unserialize">void HttpMessage::unserialize(string serialized)</h3>
+<p>Implements Serializable.</p>
+<p>Re-constructs the HttpMessage based upon the serialized string.</p>
 <hr noshade>
 <h1 id="http_request_object.c">http_request_object.c</h1>
 <h2 id="HttpRequest" class="o">HttpRequest</h2>
@@ -697,6 +717,11 @@ cycle.</p>
 references the last received response.  Use HttpMessage::getParentMessage()<br />
 to access the data of previously sent requests whithin this request<br />
 cycle.</p>
+<p>Note that the internal request message is immutable, that means that the<br />
+request message received through HttpRequest::getRequestMessage() will<br />
+always look the same for the same request, regardless of any changes you<br />
+may have made to the returned object.</p>
+<p>Throws HttpMalformedHeadersException, HttpEncodingException.</p>
 <h3 id="HttpRequest_getHistory">HttpMessage HttpRequest::getHistory()</h3>
 <p>Get all sent requests and received responses as an HttpMessage object.</p>
 <p>If you don't want to record history at all, set the instance variable<br />
@@ -705,12 +730,18 @@ HttpRequest::$recoedHistory to FALSE. </p>
 history.</p>
 <p>The object references the last received response, use HttpMessage::getParentMessage() <br />
 to access the data of previously sent requests and received responses.</p>
-<p>Throws HttpMalformedHeaderException.</p>
+<p>Note that the internal history is immutable, that means that any changes<br />
+you make the the message list won't affect a history message list newly <br />
+created by another call to HttpRequest::getHistory().</p>
+<p>Throws HttpMalformedHeaderException, HttpEncodingException.</p>
 <h3 id="HttpRequest_clearHistory">void HttpRequest::clearHistory()</h3>
 <p>Clear the history.</p>
 <h3 id="HttpRequest_send">HttpMessage HttpRequest::send()</h3>
 <p>Send the HTTP request.</p>
 <p>Returns the received response as HttpMessage object.</p>
+<p>NOTE: While an exception may be thrown, the transfer could have succeeded <br />
+at least partially, so you might want to check the return values of various<br />
+HttpRequest::getResponse*() methods.</p>
 <p>Throws HttpRuntimeException, HttpRequestException, <br />
 HttpMalformedHeaderException, HttpEncodingException.</p>
 <p>GET example:</p><pre><blockquote><code><span style="color: #000000"><br />
@@ -778,6 +809,9 @@ HttpRequestPoolException, HttpMalformedHeaderException.</p>
 <p>Implements Iterator::next().</p>
 <h3 id="HttpRequestPool_rewind">void HttpRequestPool::rewind()</h3>
 <p>Implements Iterator::rewind().</p>
+<h3 id="HttpRequestPool_count">int HttpRequestPool::count()</h3>
+<p>Implements Countable.</p>
+<p>Returns the number of attached HttpRequest objects.</p>
 <h3 id="HttpRequestPool_getAttachedRequests">array HttpRequestPool::getAttachedRequests()</h3>
 <p>Get attached HttpRequest objects.</p>
 <p>Returns an array containing all currently attached HttpRequest objects.</p>
@@ -953,6 +987,8 @@ http.cache_log is set.</p>
 </li>
 <li><a href="#http_negotiate_charset">http_negotiate_charset</a>
 </li>
+<li><a href="#http_negotiate_content_type">http_negotiate_content_type</a>
+</li>
 <li><a href="#http_send_status">http_send_status</a>
 </li>
 <li><a href="#http_send_last_modified">http_send_last_modified</a>
@@ -1053,6 +1089,9 @@ http.cache_log is set.</p>
 <li><a href="#HttpMessage_getParentMessage">HttpMessage::getParentMessage()</a></li>
 <li><a href="#HttpMessage_send">HttpMessage::send()</a></li>
 <li><a href="#HttpMessage_toString">HttpMessage::toString()</a></li>
+<li><a href="#HttpMessage_count">HttpMessage::count()</a></li>
+<li><a href="#HttpMessage_serialize">HttpMessage::serialize()</a></li>
+<li><a href="#HttpMessage_unserialize">HttpMessage::unserialize()</a></li>
 </li>
 </ul>
 </li>
@@ -1120,6 +1159,7 @@ http.cache_log is set.</p>
 <li><a href="#HttpRequestPool_key">HttpRequestPool::key()</a></li>
 <li><a href="#HttpRequestPool_next">HttpRequestPool::next()</a></li>
 <li><a href="#HttpRequestPool_rewind">HttpRequestPool::rewind()</a></li>
+<li><a href="#HttpRequestPool_count">HttpRequestPool::count()</a></li>
 <li><a href="#HttpRequestPool_getAttachedRequests">HttpRequestPool::getAttachedRequests()</a></li>
 <li><a href="#HttpRequestPool_getFinishedRequests">HttpRequestPool::getFinishedRequests()</a></li>
 </li>
@@ -1161,7 +1201,7 @@ http.cache_log is set.</p>
 </li>
 </ul>
 </div>
-    <p><b>Generated at: Fri, 04 Nov 2005 12:29:06 +0100</b></p>
+    <p><b>Generated at: Mon, 21 Nov 2005 16:56:18 +0100</b></p>
 </body>
 </html>
 
index 372c1f33268564f5169fff0dd8d1aa4c38816028..11e818996440614790891a91c4b8799b57c6bb77 100644 (file)
@@ -8,11 +8,10 @@
 ; disable if you want php not to exit in case of redirects and cache hits
 ;http.force_exit = 0
 
-; the hashing algorithm with wich ETags are generated
-; you can use mhash constants if ext/mhash is enabled, or their 
-; literal representation if ext/http was linked against libmhash
-;http.etag_mode = HTTP_ETAG_MHASH_TIGER ; same as 7
-http.etag_mode = HTTP_ETAG_MD5
+; the hashing algorithm with wich ETags are generated (MD5, SHA1, CRC32B)
+; if ext/hash is available, this can be set to any hash algorithm ext/hash supports
+; MD5 is the default and fallback algorithm
+http.etag_mode = "MD5"
 
 ; allowed request methods
 ; by default PHP ignores unkown request methods
diff --git a/http.c b/http.c
index ffbae18cdb8f848e301ab70b97f8a4293aacd9cb..1c4a6a4e5cf19a746139019dfb5056a55803be83 100644 (file)
--- a/http.c
+++ b/http.c
@@ -58,9 +58,6 @@
 #      endif
 #      include <curl/curl.h>
 #endif
-#ifdef HTTP_HAVE_MHASH
-#      include <mhash.h>
-#endif
 #ifdef HTTP_HAVE_ZLIB
 #      include <zlib.h>
 #endif
@@ -218,56 +215,6 @@ PHP_INI_MH(http_update_allowed_methods)
        return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
 }
 
-#undef CASE_HTTP_ETAG_HASH
-#define CASE_HTTP_ETAG_HASH(HASH) \
-       case HTTP_ETAG_##HASH: \
-               ZEND_WRITE("HTTP_ETAG_"#HASH, lenof("HTTP_ETAG_"#HASH)); \
-       break;
-PHP_INI_DISP(http_etag_mode_displayer)
-{
-       long value;
-       
-       if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
-               value = (ini_entry->orig_value) ? atoi(ini_entry->orig_value) : HTTP_ETAG_MD5;
-       } else if (ini_entry->value) {
-               value = (ini_entry->value[0]) ? atoi(ini_entry->value) : HTTP_ETAG_MD5;
-       } else {
-               value = HTTP_ETAG_MD5;
-       }
-       
-       switch (value)
-       {
-#ifdef HTTP_HAVE_HASH_EXT
-               CASE_HTTP_ETAG_HASH(RIPEMD160);
-               CASE_HTTP_ETAG_HASH(RIPEMD128);
-               CASE_HTTP_ETAG_HASH(SHA512);
-               CASE_HTTP_ETAG_HASH(SHA384);
-               CASE_HTTP_ETAG_HASH(SHA256);
-#endif
-               CASE_HTTP_ETAG_HASH(CRC32);
-               CASE_HTTP_ETAG_HASH(SHA1);
-#ifndef HTTP_HAVE_MHASH
-               default:
-#endif
-               CASE_HTTP_ETAG_HASH(MD5);
-               
-#ifdef HTTP_HAVE_MHASH
-               default:
-               {
-                       const char *hash_name = mhash_get_hash_name_static(value);
-                       
-                       if (!hash_name) {
-                               ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5"));
-                       } else {
-                               ZEND_WRITE("HTTP_ETAG_MHASH_", lenof("HTTP_ETAG_MHASH_"));
-                               ZEND_WRITE(hash_name, strlen(hash_name));
-                       }
-               }
-               break;
-#endif
-       }
-}
-
 #ifndef ZEND_ENGINE_2
 #      define OnUpdateLong OnUpdateInt
 #endif
@@ -278,7 +225,7 @@ PHP_INI_BEGIN()
        HTTP_PHP_INI_ENTRY("http.redirect_log", "", PHP_INI_ALL, OnUpdateString, log.redirect)
        HTTP_PHP_INI_ENTRY("http.allowed_methods_log", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
        HTTP_PHP_INI_ENTRY("http.composite_log", "", PHP_INI_ALL, OnUpdateString, log.composite)
-       HTTP_PHP_INI_ENTRY_EX("http.etag_mode", "-2", PHP_INI_ALL, OnUpdateLong, http_etag_mode_displayer, etag.mode)
+       HTTP_PHP_INI_ENTRY("http.etag_mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
 #ifdef ZEND_ENGINE_2
        HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions)
 #endif
@@ -297,7 +244,6 @@ PHP_MINIT_FUNCTION(http)
        
        if (    (SUCCESS != PHP_MINIT_CALL(http_support))       ||
                        (SUCCESS != PHP_MINIT_CALL(http_headers))       ||
-                       (SUCCESS != PHP_MINIT_CALL(http_cache))         ||
 #ifdef HTTP_HAVE_CURL
                        (SUCCESS != PHP_MINIT_CALL(http_request))       ||
 #endif /* HTTP_HAVE_CURL */
@@ -386,16 +332,6 @@ PHP_MINFO_FUNCTION(http)
 #else
                php_info_print_table_row(2, "zlib GZIP Encodings", "disabled");
 #endif
-#ifdef HTTP_HAVE_MHASH
-               {
-                       char mhash_info[32];
-                       
-                       snprintf(mhash_info, 32, "libmhash/%d", MHASH_API_VERSION);
-                       php_info_print_table_row(2, "mhash ETag Generator", mhash_info);
-               }
-#else
-               php_info_print_table_row(2, "mhash ETag Generator", "disabled");
-#endif
 #if defined(HTTP_HAVE_MAGIC) && !defined(WONKY)
                php_info_print_table_row(2, "magic MIME Guessing", "libmagic/unknown");
 #else
@@ -419,37 +355,6 @@ PHP_MINFO_FUNCTION(http)
        }
        php_info_print_table_end();
        
-       php_info_print_table_start();
-       php_info_print_table_colspan_header(2, "Supported ETag Hash Algorithms");
-       {
-                       
-               php_info_print_table_row(2, "PHP", "CRC32, MD5, SHA1"
-#ifdef HTTP_HAVE_HASH_EXT
-                       ", SHA256, SHA384, SHA512, RIPEMD128, RIPEMD160"
-#endif
-               );
-#ifdef HTTP_HAVE_MHASH
-               {
-                       phpstr *algos = phpstr_new();
-                       int i, c = mhash_count();
-                       
-                       for (i = 0; i <= c; ++i) {
-                               const char *hash = mhash_get_hash_name_static(i);
-                               
-                               if (hash) {
-                                       phpstr_appendf(algos, "%s, ", hash);
-                               }
-                       }
-                       phpstr_fix(algos);
-                       php_info_print_table_row(2, "MHASH", PHPSTR_VAL(algos));
-                       phpstr_free(&algos);
-               }
-#else
-               php_info_print_table_row(2, "MHASH", "not available");
-#endif
-       }
-       php_info_print_table_end();
-
        php_info_print_table_start();
        php_info_print_table_colspan_header(2, "Request Methods");
        {
index e752a927d4f89edb60721b0cea3e8571d6df0db7..c52aec830080775dc81daec6d6152bbc05d70809 100644 (file)
--- a/http.dsp
+++ b/http.dsp
@@ -54,7 +54,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386\r
-# ADD LINK32 libmhash.lib libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_http.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"\r
+# ADD LINK32 libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_http.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"\r
 \r
 !ELSEIF  "$(CFG)" == "http - Win32 Debug_TS"\r
 \r
@@ -81,7 +81,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386\r
-# ADD LINK32 libmhash.lib libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts_debug.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/http.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"\r
+# ADD LINK32 libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts_debug.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/http.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"\r
 \r
 !ENDIF \r
 \r
index 2be27d0c79632b50722ecdaec6493b5bb781cda6..a392801401de9cf2f77e437511dadfd44bd90bc6 100644 (file)
@@ -50,7 +50,6 @@ PHP_MINIT_FUNCTION(http_support)
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_REQUESTS", HTTP_SUPPORT_REQUESTS);
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_MAGICMIME", HTTP_SUPPORT_MAGICMIME);
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS);
-       HTTP_LONG_CONSTANT("HTTP_SUPPORT_MHASHETAGS", HTTP_SUPPORT_MHASHETAGS);
        HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS);
        
        return SUCCESS;
@@ -66,9 +65,6 @@ PHP_HTTP_API long _http_support(long feature)
        support |= HTTP_SUPPORT_SSLREQUESTS;
 #      endif
 #endif
-#ifdef HTTP_HAVE_MHASH
-       support |= HTTP_SUPPORT_MHASHETAGS;
-#endif
 #ifdef HTTP_HAVE_MAGIC
        support |= HTTP_SUPPORT_MAGICMIME;
 #endif
index 963bb7e1d0c1aecac81b10047662715b9407006c..dab555238c98cfb82509f75d3d453e8967b7cf40 100644 (file)
@@ -20,8 +20,6 @@
 #include "SAPI.h"
 #include "php_streams.h"
 #include "php_output.h"
-#include "ext/standard/md5.h"
-#include "ext/standard/sha1.h"
 
 #include "php_http.h"
 #include "php_http_std_defs.h"
 #include "php_http_send_api.h"
 #include "php_http_date_api.h"
 
-#ifdef HTTP_HAVE_MHASH
-#      include <mhash.h>
-#endif
-
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
-PHP_MINIT_FUNCTION(http_cache)
-{
-       HTTP_LONG_CONSTANT("HTTP_ETAG_MD5", HTTP_ETAG_MD5);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_SHA1", HTTP_ETAG_SHA1);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_CRC32", HTTP_ETAG_CRC32);
-
-#ifdef HTTP_HAVE_HASH_EXT
-       HTTP_LONG_CONSTANT("HTTP_ETAG_SHA256", HTTP_ETAG_SHA256);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_SHA384", HTTP_ETAG_SHA384);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_SHA512", HTTP_ETAG_SHA512);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_RIPEMD128", HTTP_ETAG_RIPEMD128);
-       HTTP_LONG_CONSTANT("HTTP_ETAG_RIPEMD160", HTTP_ETAG_RIPEMD160);
-#endif
-
-#ifdef HTTP_HAVE_MHASH
-       {
-               int l, i, c = mhash_count();
-               
-               for (i = 0; i <= c; ++i) {
-                       char const_name[256] = {0};
-                       const char *hash_name = mhash_get_hash_name_static(i);
-                       
-                       if (hash_name) {
-                               l = snprintf(const_name, 255, "HTTP_ETAG_MHASH_%s", hash_name);
-                               zend_register_long_constant(const_name, l + 1, i, CONST_CS|CONST_PERSISTENT, module_number TSRMLS_CC);
-                       }
-               }
-       }
-#endif
-
-       return SUCCESS;
-}
-
 /* {{{ char *http_etag(void *, size_t, http_send_mode) */
 PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
 {
@@ -87,7 +48,7 @@ PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_m
                }
                
                if (SUCCESS != ss) {
-                       http_etag_free(&ctx);
+                       efree(ctx);
                        return NULL;
                } else {
                        size_t ssb_len;
@@ -100,7 +61,7 @@ PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_m
                }
        }
        
-       return http_etag_finish(&ctx);
+       return http_etag_finish(ctx);
 }
 /* }}} */
 
@@ -237,7 +198,10 @@ PHP_HTTP_API zend_bool _http_interrupt_ob_etaghandler(TSRMLS_D)
 {
        if (HTTP_G(etag).started) {
                HTTP_G(etag).started = 0;
-               http_etag_free(&HTTP_G(etag).ctx);
+               if (HTTP_G(etag).ctx) {
+                       efree(HTTP_G(etag).ctx);
+                       HTTP_G(etag).ctx = NULL;
+               }
                return 1;
        }
        return 0;
@@ -264,7 +228,9 @@ void _http_ob_etaghandler(char *output, uint output_len,
                /* finish */
                if (mode & PHP_OUTPUT_HANDLER_END) {
                        char *sent_header = NULL;
-                       char *etag = http_etag_finish(&HTTP_G(etag).ctx);
+                       char *etag = http_etag_finish(HTTP_G(etag).ctx);
+                       
+                       HTTP_G(etag).ctx = NULL;
                        
                        http_send_cache_control(HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL));
                        http_send_etag_ex(etag, strlen(etag), &sent_header);
index e731d9af041343c08112d467568f228d7d7a9f75..aa495186e9b8aa72454214b188f4c762b0846bed 100644 (file)
@@ -1649,8 +1649,6 @@ PHP_FUNCTION(http_uncompress)
  *       and SSL requests can be issued 
  *  <li> HTTP_SUPPORT_ENCODINGS: whether ext/http was linked against zlib,
  *       and compressed HTTP responses can be decoded
- *  <li> HTTP_SUPPORT_MHASHETAGS: whether ext/http was linked against libmhash,
- *       and ETags can be generated with the available mhash algorithms
  *  <li> HTTP_SUPPORT_MAGICMIME: whether ext/http was linked against libmagic,
  *       and the HttpResponse::guessContentType() method is usable
  * </ul>
index 544b60337198fd4841852d8b24e75caa9463d497..0d6cfa7cd59d2c150e7ab86a2c238c947fe0029e 100644 (file)
@@ -35,9 +35,6 @@
 #include "php_http_cache_api.h"
 #include "php_http_headers_api.h"
 
-#ifdef HTTP_HAVE_MHASH
-#      include <mhash.h>
-#endif
 #ifdef HTTP_HAVE_MAGIC
 #      include <magic.h>
 #endif
@@ -243,34 +240,6 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D)
        DCL_CONST(long, "REDIRECT_PERM", HTTP_REDIRECT_PERM);
        DCL_CONST(long, "REDIRECT_POST", HTTP_REDIRECT_POST);
        DCL_CONST(long, "REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
-       
-       DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5);
-       DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1);
-       DCL_CONST(long, "ETAG_CRC32", HTTP_ETAG_CRC32);
-       
-#      ifdef HTTP_HAVE_HASH_EXT
-       DCL_CONST(long, "ETAG_SHA256", HTTP_ETAG_SHA256);
-       DCL_CONST(long, "ETAG_SHA384", HTTP_ETAG_SHA384);
-       DCL_CONST(long, "ETAG_SHA512", HTTP_ETAG_SHA512);
-       DCL_CONST(long, "ETAG_RIPEMD128", HTTP_ETAG_RIPEMD128);
-       DCL_CONST(long, "ETAG_RIPEMD160", HTTP_ETAG_RIPEMD160);
-#      endif
-
-#      ifdef HTTP_HAVE_MHASH
-       {
-               int l, i, c = mhash_count();
-               
-               for (i = 0; i <= c; ++i) {
-                       char const_name[256] = {0};
-                       const char *hash_name = mhash_get_hash_name_static(i);
-                       
-                       if (hash_name) {
-                               l = snprintf(const_name, 255, "ETAG_MHASH_%s", hash_name);
-                               zend_declare_class_constant_long(ce, const_name, l, i TSRMLS_CC);
-                       }
-               }
-       }
-#      endif /* HTTP_HAVE_MHASH */
 #endif /* WONKY */
 }
 
index 316ac11c9a9c709398a08fa157716f4cff45be7a..3e18b156459782850a288088579783ccb4b80466 100644 (file)
@@ -41,6 +41,8 @@
  <notes><![CDATA[
 * Fixed bug in http_negotiate_*() when client sends spaces within accept headers
 
+- Removed support for ETag hashing through libmhash
+
 + Added http_negotiate_content_type()
 ]]></notes>
  <contents>
     <file role="test" name="etag_mode_042.phpt"/>
     <file role="test" name="etag_mode_043.phpt"/>
     <file role="test" name="etag_mode_044.phpt"/>
-    <file role="test" name="etag_mode_crc.phpt"/>
     <file role="test" name="exceptions.phpt"/>
     <file role="test" name="get_request_data_001.phpt"/>
     <file role="test" name="HttpMessage_001.phpt"/>
    prompt="whether to enable cURL HTTP requests; specify libcurl directory"
    default="yes"
   />
-  <configureoption
-   name="with-http-mhash-etags"
-   prompt="whether to enable mhash ETag generator; specify libmhash directory"
-   default="yes"
-  />
   <configureoption
    name="with-http-magic-mime"
    prompt="whether to enable response content type guessing; specify libmagic directory"
index 4ebbc5c60c0a34f2cd4e6ab8a41735a9bf05a668..2f0eadedf7d4247a22be9a8692deb6a3d02da175 100644 (file)
@@ -35,7 +35,7 @@ extern int http_module_number;
 ZEND_BEGIN_MODULE_GLOBALS(http)
 
        struct _http_globals_etag {
-               long mode;
+               char *mode;
                void *ctx;
                zend_bool started;
        } etag;
index e0e01505b2bed953f637ccf0706bc80c32a60281..3073ab4493f2115295a9efd82c812012a3ae7bbb 100644 (file)
@@ -22,7 +22,6 @@
 #define HTTP_SUPPORT_REQUESTS          0x02L
 #define HTTP_SUPPORT_MAGICMIME         0x04L
 #define HTTP_SUPPORT_ENCODINGS         0x08L
-#define HTTP_SUPPORT_MHASHETAGS                0x10L
 #define HTTP_SUPPORT_SSLREQUESTS       0x20L
 
 extern PHP_MINIT_FUNCTION(http_support);
index 7017dfd1be7de2704d038d0393fc72bf9c121093..03ea1134be656f6412583633e544c9eaaa9069c5 100644 (file)
 
 #include "zend_ini.h"
 
-#include "ext/standard/md5.h"
-#include "ext/standard/sha1.h"
 #include "ext/standard/crc32.h"
+#include "ext/standard/sha1.h"
+#include "ext/standard/md5.h"
 
 #include "php_http_std_defs.h"
 #include "php_http.h"
 #include "php_http_api.h"
 #include "php_http_send_api.h"
 
-#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH) && defined(HTTP_HAVE_HASH_EXT_INCLUDES)
-#      define HTTP_HAVE_HASH_EXT
+#ifdef HTTP_HAVE_EXT_HASH
 #      include "php_hash.h"
-#      include "php_hash_sha.h"
-#      include "php_hash_ripemd.h"
-#endif
-
-#ifdef HTTP_HAVE_MHASH
-#      include <mhash.h>
 #endif
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
-typedef enum {
-#ifdef HTTP_HAVE_HASH_EXT
-       HTTP_ETAG_RIPEMD160 = -8,
-       HTTP_ETAG_RIPEMD128 = -7,
-       HTTP_ETAG_SHA512 = -6,
-       HTTP_ETAG_SHA384 = -5,
-       HTTP_ETAG_SHA256 = -4,
-#endif
-       HTTP_ETAG_CRC32 = -3,
-       HTTP_ETAG_MD5 = -2,
-       HTTP_ETAG_SHA1 = -1,
-} http_etag_mode;
-
-extern PHP_MINIT_FUNCTION(http_cache);
-
-#ifdef HTTP_HAVE_MHASH
-static void *http_etag_alloc_mhash_digest(size_t size)
-{
-       return emalloc(size);
-}
-#endif
-
-#define http_etag_digest(d, l) _http_etag_digest((d), (l) TSRMLS_CC)
-static inline char *_http_etag_digest(const unsigned char *digest, int len TSRMLS_DC)
+#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";
        int i;
@@ -78,184 +49,83 @@ static inline char *_http_etag_digest(const unsigned char *digest, int len TSRML
        return hex;
 }
 
-#undef CASE_HTTP_ETAG_HASH
-#define CASE_HTTP_ETAG_HASH(HASH) \
-       case HTTP_ETAG_##HASH: \
-               PHP_##HASH##Init(ctx = emalloc(sizeof(PHP_##HASH##_CTX))); \
-       break;
 #define http_etag_init() _http_etag_init(TSRMLS_C)
 static inline void *_http_etag_init(TSRMLS_D)
 {
        void *ctx = NULL;
-       long mode = HTTP_G(etag).mode;
-
-       switch (mode)
-       {
-               case HTTP_ETAG_CRC32:
-                       ctx = emalloc(sizeof(uint));
-                       *((uint *) ctx) = ~0;
-               break;
-               
-#ifdef HTTP_HAVE_HASH_EXT
-               CASE_HTTP_ETAG_HASH(RIPEMD160);
-               CASE_HTTP_ETAG_HASH(RIPEMD128);
-               CASE_HTTP_ETAG_HASH(SHA512);
-               CASE_HTTP_ETAG_HASH(SHA384);
-               CASE_HTTP_ETAG_HASH(SHA256);
-#endif
-               CASE_HTTP_ETAG_HASH(SHA1);
-#ifndef HTTP_HAVE_MHASH
-               default:
-#endif
-               CASE_HTTP_ETAG_HASH(MD5);
-               
-#ifdef HTTP_HAVE_MHASH
-               default:
-                       if ((mode < 0) || ((ulong)mode > mhash_count()) || (!(ctx = mhash_init(mode)))) {
-                               http_error_ex(HE_ERROR, HTTP_E_RUNTIME, "Invalid ETag mode: %ld", mode);
-                       }
-               break;
-#endif
+       char *mode = HTTP_G(etag).mode;
+       
+#ifdef HTTP_HAVE_EXT_HASH
+       php_hash_ops *eho = NULL;
+       
+       if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
+               ctx = emalloc(eho->context_size);
+               eho->hash_init(ctx);
+       } else
+#endif
+       if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
+               ctx = emalloc(sizeof(uint));
+               *((uint *) ctx) = ~0;
+       } else if (mode && !strcasecmp(mode, "sha1")) {
+               PHP_SHA1Init(ctx = emalloc(sizeof(PHP_SHA1_CTX)));
+       } else {
+               PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX)));
        }
        
        return ctx;
 }
 
-#undef CASE_HTTP_ETAG_HASH
-#define CASE_HTTP_ETAG_HASH(HASH) \
-       case HTTP_ETAG_##HASH: \
-               if (*((PHP_##HASH##_CTX **) ctx_ptr)) { \
-                       efree(*((PHP_##HASH##_CTX **) ctx_ptr)); \
-                       *((PHP_##HASH##_CTX **) ctx_ptr) = NULL; \
-               } \
-       break;
-#define http_etag_free(cp) _http_etag_free((cp) TSRMLS_CC)
-static inline void _http_etag_free(void **ctx_ptr TSRMLS_DC)
-{
-       switch (HTTP_G(etag).mode)
-       {
-               case HTTP_ETAG_CRC32:
-                       if (*((uint **) ctx_ptr)) {
-                               efree(*((uint **) ctx_ptr));
-                               *((uint **) ctx_ptr) = NULL;
-                       }
-               break;
-
-#ifdef HTTP_HAVE_HASH_EXT
-               CASE_HTTP_ETAG_HASH(RIPEMD160);
-               CASE_HTTP_ETAG_HASH(RIPEMD128);
-               CASE_HTTP_ETAG_HASH(SHA512);
-               CASE_HTTP_ETAG_HASH(SHA384);
-               CASE_HTTP_ETAG_HASH(SHA256);
-#endif
-               CASE_HTTP_ETAG_HASH(SHA1);
-#ifndef HTTP_HAVE_MHASH
-               default:
-#endif
-               CASE_HTTP_ETAG_HASH(MD5);
-               
-#ifdef HTTP_HAVE_MHASH
-               default:
-                       /* mhash gets already freed in http_etag_finish() */
-                       if (*((MHASH *) ctx_ptr)) {
-                               mhash_deinit(*((MHASH *) ctx_ptr), NULL);
-                               *((MHASH *) ctx_ptr) = NULL;
-                       }
-               break;
-#endif
-       }
-}
-
-#undef CASE_HTTP_ETAG_HASH
-#define CASE_HTTP_ETAG_HASH(HASH, len) \
-       case HTTP_ETAG_##HASH##: \
-               PHP_##HASH##Final(digest, *((PHP_##HASH##_CTX **) ctx_ptr)); \
-               etag = http_etag_digest(digest, len); \
-       break;
 #define http_etag_finish(c) _http_etag_finish((c) TSRMLS_CC)
-static inline char *_http_etag_finish(void **ctx_ptr TSRMLS_DC)
+static inline char *_http_etag_finish(void *ctx TSRMLS_DC)
 {
+       unsigned char digest[128] = {0};
        char *etag = NULL;
-       unsigned char digest[128];
-       long mode = HTTP_G(etag).mode;
        
-       switch (mode)
-       {
-               case HTTP_ETAG_CRC32:
-                       **((uint **) ctx_ptr) = ~**((uint **) ctx_ptr);
-                       etag = http_etag_digest(*((const unsigned char **) ctx_ptr), sizeof(uint));
-               break;
-
-#ifdef HTTP_HAVE_HASH_EXT
-               CASE_HTTP_ETAG_HASH(RIPEMD160, 20);
-               CASE_HTTP_ETAG_HASH(RIPEMD128, 16);
-               CASE_HTTP_ETAG_HASH(SHA512, 64);
-               CASE_HTTP_ETAG_HASH(SHA384, 48);
-               CASE_HTTP_ETAG_HASH(SHA256, 32);
-#endif
-               CASE_HTTP_ETAG_HASH(SHA1, 20);
-#ifndef HTTP_HAVE_MHASH
-               default:
-#endif
-               CASE_HTTP_ETAG_HASH(MD5, 16);
-               
-#ifdef HTTP_HAVE_MHASH
-               default:
-               {
-                       unsigned char *mhash_digest = mhash_end_m(*((MHASH *) ctx_ptr), http_etag_alloc_mhash_digest);
-                       etag = http_etag_digest(mhash_digest, mhash_get_block_size(mode));
-                       efree(mhash_digest);
-                       /* avoid double free */
-                       *((MHASH *) ctx_ptr) = NULL;
-               }
-               break;
-#endif
-       }
+#ifdef HTTP_HAVE_EXT_HASH
+       php_hash_ops *eho = NULL;
+       char *mode = HTTP_G(etag).mode;
        
-       http_etag_free(ctx_ptr);
+       if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
+               eho->hash_final(digest, ctx);
+               etag = http_etag_digest(digest, eho->digest_size);
+       } else
+#endif
+       if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
+               *((uint *) ctx) = ~*((uint *) ctx);
+               etag = http_etag_digest((const unsigned char *) ctx, sizeof(uint));
+       } else if (mode && (!strcasecmp(mode, "sha1"))) {
+               PHP_SHA1Final(digest, ctx);
+               etag = http_etag_digest(digest, 20);
+       } else {
+               PHP_MD5Final(digest, ctx);
+               etag = http_etag_digest(digest, 16);
+       }
+       efree(ctx);
        
        return etag;
 }
 
-#undef CASE_HTTP_ETAG_HASH
-#define CASE_HTTP_ETAG_HASH(HASH) \
-       case HTTP_ETAG_##HASH: \
-               PHP_##HASH##Update(ctx, (const unsigned char *) data_ptr, data_len); \
-       break;
 #define http_etag_update(c, d, l) _http_etag_update((c), (d), (l) TSRMLS_CC)
 static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC)
 {
-       switch (HTTP_G(etag).mode)
-       {
-               case HTTP_ETAG_CRC32:
-               {
-                       uint i, c = *((uint *) ctx);
-                       
-                       for (i = 0; i < data_len; ++i) {
-                               c = CRC32(c, data_ptr[i]);
-                       }
-                       *((uint *)ctx) = c;
+#ifdef HTTP_HAVE_EXT_HASH
+       php_hash_ops *eho = NULL;
+       char *mode = HTTP_G(etag).mode;
+       
+       if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
+               eho->hash_update(ctx, (const unsigned char *) data_ptr, data_len);
+       } else
+#endif
+       if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
+               uint i, c = *((uint *) ctx);
+               for (i = 0; i < data_len; ++i) {
+                       c = CRC32(c, data_ptr[i]);
                }
-               break;
-               
-#ifdef HTTP_HAVE_HASH_EXT
-               CASE_HTTP_ETAG_HASH(RIPEMD160);
-               CASE_HTTP_ETAG_HASH(RIPEMD128);
-               CASE_HTTP_ETAG_HASH(SHA512);
-               CASE_HTTP_ETAG_HASH(SHA384);
-               CASE_HTTP_ETAG_HASH(SHA256);
-#endif
-               CASE_HTTP_ETAG_HASH(SHA1);
-#ifndef HTTP_HAVE_MHASH
-               default:
-#endif
-               CASE_HTTP_ETAG_HASH(MD5);
-               
-#ifdef HTTP_HAVE_MHASH
-               default:
-                       mhash(ctx, data_ptr, data_len);
-               break;
-#endif
+               *((uint *)ctx) = c;
+       } else if (mode && (!strcasecmp(mode, "sha1"))) {
+               PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
+       } else {
+               PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len);
        }
 }
 
index 8c396fb4786ec5ddcabfb770d9b85d2ec1d86d01..787100b92173bd7b74e3d6a5a3ba155f317254dd 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_CRC32);
+ini_set('http.etag_mode', 'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index e0d809dd3895c0a7733750c0b4d4420399aee720..5ca8d8ff90b071612b18128ce25b6a4f67de667c 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA1);
+ini_set('http.etag_mode', 'sha1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 1e7789c4d2cc9caa48b89de037abe56cafa61926..0b98f9f45573802b00221f03fedab09b3bb26a48 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MD5);
+ini_set('http.etag_mode', 'md5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index b8bb04d9f068d7df17106af9e24d315bbc697c67..cd56bae38eb5fbc75e78709b71e540860c94a958 100644 (file)
@@ -1,16 +1,15 @@
 --TEST--
-mhash etag
+ext/hash etag
 --SKIPIF--
 <?php
 include 'skip.inc';
 checkcgi();
 checkmax(5.0);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_WHIRLPOOL'), 'need whirlpool mhash support');
+skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_WHIRLPOOL);
+ini_set('http.etag_mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
@@ -19,7 +18,7 @@ Content-type: %s
 X-Powered-By: PHP/%s
 Cache-Control: private, must-revalidate, max-age=0
 Accept-Ranges: bytes
-ETag: "53efa9e423f86dabd449b3e23dd0350def661b9e7055b23ceb2230c8b61bc0766514957ea9d349a88ef794715a1a17a409b549edfd6f43d696e63407fff3541c"
+ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
 Content-Length: 4
 
 abc
diff --git a/tests/etag_mode_005.phpt b/tests/etag_mode_005.phpt
deleted file mode 100644 (file)
index cb15962..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-ext/hash etag
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcgi();
-checkmax(5.0);
-skipif(!defined('HTTP_ETAG_SHA256'), 'need ext/hash support');
-?>
---FILE--
-<?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA256);
-http_cache_etag();
-http_send_data("abc\n");
-?>
---EXPECTF--
-Content-type: %s
-X-Powered-By: PHP/%s
-Cache-Control: private, must-revalidate, max-age=0
-Accept-Ranges: bytes
-ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
-Content-Length: 4
-
-abc
index d4a2712e5b9e81213b0e1560625e9710afe084e0..5f9668e9af41791e315a6aa0e121659a7aa5a9dd 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_CRC32);
+ini_set('http.etag_mode', 'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 72901e430d2a966def9a15691646239b2efc6d45..5a8702ed9569f5c98eb3db396517fe08265f42b1 100644 (file)
@@ -5,11 +5,10 @@ ob sha1 etag
 include 'skip.inc';
 checkcgi();
 checkmax(5.0);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA1);
+ini_set('http.etag_mode', 'sha1');
 http_cache_etag();
 print("abc\n");
 ?>
index d81ba60d1e7dee8e96eab454b5676a79c0ff924c..919d34e9d0bbd457dc1b5e993b46df19b5610cf5 100644 (file)
@@ -8,7 +8,7 @@ checkmax(5.0);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MD5);
+ini_set('http.etag_mode', 'md5');
 http_cache_etag();
 print("abc\n");
 ?>
index 29be1dec19d30174049f21249823b4f3fe0aead0..c6f17314a08acad1e29085f1e16d28204a8c585f 100644 (file)
@@ -1,16 +1,15 @@
 --TEST--
-ob mhash etag
+ob ext/hash etag
 --SKIPIF--
 <?php
 include 'skip.inc';
 checkcgi();
 checkmax(5.0);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_WHIRLPOOL'), 'need whirlpool mhash support');
+skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_WHIRLPOOL);
+ini_set('http.etag_mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>
@@ -18,6 +17,6 @@ print("abc\n");
 Content-type: %s
 X-Powered-By: PHP/%s
 Cache-Control: private, must-revalidate, max-age=0
-ETag: "53efa9e423f86dabd449b3e23dd0350def661b9e7055b23ceb2230c8b61bc0766514957ea9d349a88ef794715a1a17a409b549edfd6f43d696e63407fff3541c"
+ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
 
 abc
diff --git a/tests/etag_mode_015.phpt b/tests/etag_mode_015.phpt
deleted file mode 100644 (file)
index d156bb9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
---TEST--
-ob ext/hash etag
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcgi();
-checkmax(5.0);
-skipif(!defined('HTTP_ETAG_SHA256'), 'need ext/hash support');
-?>
---FILE--
-<?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA256);
-http_cache_etag();
-print("abc\n");
-?>
---EXPECTF--
-Content-type: %s
-X-Powered-By: PHP/%s
-Cache-Control: private, must-revalidate, max-age=0
-ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
-
-abc
index 1ac27e2bec997230df56ddc5ac39c9d4b88c06a0..29a70804d965fa4818ec12704e6e58a63a848b58 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_CRC32);
+ini_set('http.etag_mode', 'crc32');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index 3806381dc849b81a81af4354640bd33ea349591b..71ae9d32cdc0be5edbf0ac22714a52eef2cdb091 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA1);
+ini_set('http.etag_mode', 'SHA1');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index f87f3fae76c3aaf65b776072a587dc925dc6bb9f..f72b524a6091840dc4eca4a77fff021690ee9d46 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MD5);
+ini_set('http.etag_mode', 'MD5');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
index b8bb04d9f068d7df17106af9e24d315bbc697c67..f0930adc7332bb8429b8d13ddddc8827aff251bc 100644 (file)
@@ -1,16 +1,15 @@
 --TEST--
-mhash etag
+ext/hash etag
 --SKIPIF--
 <?php
 include 'skip.inc';
 checkcgi();
-checkmax(5.0);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_WHIRLPOOL'), 'need whirlpool mhash support');
+checkmin(5.1);
+skipif(!extension_loaded('hash'), 'need ext/hash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_WHIRLPOOL);
+ini_set('http.etag_mode', 'sha256');
 http_cache_etag();
 http_send_data("abc\n");
 ?>
@@ -19,7 +18,7 @@ Content-type: %s
 X-Powered-By: PHP/%s
 Cache-Control: private, must-revalidate, max-age=0
 Accept-Ranges: bytes
-ETag: "53efa9e423f86dabd449b3e23dd0350def661b9e7055b23ceb2230c8b61bc0766514957ea9d349a88ef794715a1a17a409b549edfd6f43d696e63407fff3541c"
+ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
 Content-Length: 4
 
 abc
diff --git a/tests/etag_mode_035.phpt b/tests/etag_mode_035.phpt
deleted file mode 100644 (file)
index 1cd9430..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
---TEST--
-ext/hash etag
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcgi();
-checkmin(5.1);
-skipif(!defined('HTTP_ETAG_SHA256'), 'need ext/hash support');
-?>
---FILE--
-<?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA256);
-http_cache_etag();
-http_send_data("abc\n");
-?>
---EXPECTF--
-X-Powered-By: PHP/%s
-Cache-Control: private, must-revalidate, max-age=0
-Accept-Ranges: bytes
-ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
-Content-Length: 4
-Content-type: %s
-
-abc
index 3e15bc14df29f44b7b34e62fcf33e8d6ec2f159a..1a6a2ff2728b0634d6b25f9bed50101347bad162 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_CRC32);
+ini_set('http.etag_mode', 'crc32');
 http_cache_etag();
 print("abc\n");
 ?>
index 68aab73d8c595ebdc5ca04b8f8e9cafba213674b..5c77db4ca3160cec72602ca5af15c90e0a41c532 100644 (file)
@@ -5,11 +5,10 @@ ob sha1 etag
 include 'skip.inc';
 checkcgi();
 checkmin(5.1);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA1);
+ini_set('http.etag_mode', 'SHA1');
 http_cache_etag();
 print("abc\n");
 ?>
index 251381b51d1249c2cf6eee0eaf4c522f2f242688..dbb5438e6577abc4abae606417dfdd497b5c9142 100644 (file)
@@ -8,7 +8,7 @@ checkmin(5.1);
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MD5);
+ini_set('http.etag_mode', 'bogus');
 http_cache_etag();
 print("abc\n");
 ?>
index c7c3e102720af0f851549c6c945456a40a3eb0d4..5f69d4bd921248d8fed86cc003e9880f9f0bf1f4 100644 (file)
@@ -1,23 +1,22 @@
 --TEST--
-ob mhash etag
+ob ext/hash etag
 --SKIPIF--
 <?php
 include 'skip.inc';
 checkcgi();
 checkmin(5.1);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_WHIRLPOOL'), 'need whirlpool mhash support');
+skipif(!extendion_loaded('hash'), 'need mhash support');
 ?>
 --FILE--
 <?php
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_WHIRLPOOL);
+ini_set('http.etag_mode', 'sha256');
 http_cache_etag();
 print("abc\n");
 ?>
 --EXPECTF--
 X-Powered-By: PHP/%s
 Cache-Control: private, must-revalidate, max-age=0
-ETag: "53efa9e423f86dabd449b3e23dd0350def661b9e7055b23ceb2230c8b61bc0766514957ea9d349a88ef794715a1a17a409b549edfd6f43d696e63407fff3541c"
+ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
 Content-type: %s
 
 abc
diff --git a/tests/etag_mode_045.phpt b/tests/etag_mode_045.phpt
deleted file mode 100644 (file)
index b4c5dd6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
---TEST--
-ob ext/hash etag
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcgi();
-checkmin(5.1);
-skipif(!defined('HTTP_ETAG_SHA256'), 'need ext/hash support');
-?>
---FILE--
-<?php
-ini_set('http.etag_mode', HTTP_ETAG_SHA256);
-http_cache_etag();
-print("abc\n");
-?>
---EXPECTF--
-X-Powered-By: PHP/%s
-Cache-Control: private, must-revalidate, max-age=0
-ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
-Content-type: %s
-
-abc
diff --git a/tests/etag_mode_crc.phpt b/tests/etag_mode_crc.phpt
deleted file mode 100644 (file)
index 62fbb3f..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
---TEST--
-sane crc etags
---SKIPIF--
-<?php
-include 'skip.inc';
-checkmin(5.1);
-skipif(!http_support(HTTP_SUPPORT_MHASHETAGS), 'need mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_CRC32'), 'need CRC32 mhash support');
-skipif(!defined('HTTP_ETAG_MHASH_CRC32B'), 'need CRC32B mhash support');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-ini_set('http.etag_mode', HTTP_ETAG_CRC32);
-HttpResponse::setData("abc");
-$php = HttpResponse::getEtag();
-
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_CRC32);
-HttpResponse::setData("abc");
-$crc = HttpResponse::getEtag();
-
-ini_set('http.etag_mode', HTTP_ETAG_MHASH_CRC32B);
-HttpResponse::setData("abc");
-$equ = HttpResponse::getEtag();
-
-echo $php,"\n", $equ,"\n", $crc,"\n";
-
-var_dump($equ === $php);
-var_dump($equ !== $crc);
-
-echo "Done\n";
---EXPECTF--
-%sTEST
-c2412435
-c2412435
-73bb8c64
-bool(true)
-bool(true)
-Done