- php_info fun
authorMichael Wallner <mike@php.net>
Tue, 20 Sep 2005 15:32:23 +0000 (15:32 +0000)
committerMichael Wallner <mike@php.net>
Tue, 20 Sep 2005 15:32:23 +0000 (15:32 +0000)
- add PHPs CRC32 to the supported ETag hash algos (no idea yet why it differs to that of MHASH)
- save strlen() calls in http_send_ranges()

http.c
http_cache_api.c
http_response_object.c
http_send_api.c
php_http_cache_api.h

diff --git a/http.c b/http.c
index 528f8bad300a77dac1dfaaaa6c5fbf19abc835fe..5d0491a19ff14ce1db779ee34e1591e7c92c3bdb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -205,6 +205,10 @@ PHP_INI_DISP(http_etag_mode_displayer)
        
        switch (value)
        {
+               case HTTP_ETAG_CRC32:
+                       ZEND_WRITE("HTTP_ETAG_CRC32", lenof("HTTP_ETAG_CRC32"));
+               break;
+               
                case HTTP_ETAG_SHA1:
                        ZEND_WRITE("HTTP_ETAG_SHA1", lenof("HTTP_ETAG_SHA1"));
                break;
@@ -333,29 +337,29 @@ PHP_MINFO_FUNCTION(http)
 {
        php_info_print_table_start();
        {
-               php_info_print_table_row(2, "Extended HTTP support:", "enabled");
-               php_info_print_table_row(2, "Extension Version:", HTTP_PEXT_VERSION);
+               php_info_print_table_row(2, "Extended HTTP support", "enabled");
+               php_info_print_table_row(2, "Extension Version", HTTP_PEXT_VERSION);
 #ifdef HTTP_HAVE_CURL
-               php_info_print_table_row(2, "cURL HTTP Requests:", curl_version());
+               php_info_print_table_row(2, "cURL HTTP Requests", curl_version());
 #else
-               php_info_print_table_row(2, "cURL HTTP Requests:", "disabled");
+               php_info_print_table_row(2, "cURL HTTP Requests", "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);
+                       php_info_print_table_row(2, "mhash ETag Generator", mhash_info);
                }
 #else
-               php_info_print_table_row(2, "mhash ETag Generator:", "disabled");
+               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");
+               php_info_print_table_row(2, "magic MIME Guessing", "libmagic/unknown");
 #else
-               php_info_print_table_row(2, "magic MIME Guessing:", "disabled");
+               php_info_print_table_row(2, "magic MIME Guessing", "disabled");
 #endif
-               php_info_print_table_row(2, "Registered Classes:",
+               php_info_print_table_row(2, "Registered Classes",
 #ifndef ZEND_ENGINE_2
                        "none"
 #else
@@ -372,8 +376,36 @@ 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_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");
        {
                unsigned i;
                zval **custom_method;
@@ -393,10 +425,11 @@ PHP_MINFO_FUNCTION(http)
                phpstr_fix(known_request_methods);
                phpstr_fix(custom_request_methods);
 
-               php_info_print_table_row(2, "Known Request Methods:", PHPSTR_VAL(known_request_methods));
-               php_info_print_table_row(2, "Custom Request Methods:",
+               php_info_print_table_row(2, "Known", PHPSTR_VAL(known_request_methods));
+               php_info_print_table_row(2, "Custom",
                        PHPSTR_LEN(custom_request_methods) ? PHPSTR_VAL(custom_request_methods) : "none registered");
-
+               php_info_print_table_row(2, "Allowed", strlen(HTTP_G(request).methods.allowed) ? HTTP_G(request).methods.allowed : "(ANY)");
+               
                phpstr_free(&known_request_methods);
                phpstr_free(&custom_request_methods);
        }
index 0cab6d9d6744697b47df352466421814d06560e0..d03ee85c2c17bae53da40b24e2edb9055f1be025 100644 (file)
@@ -43,6 +43,7 @@ STATUS _http_cache_global_init(INIT_FUNC_ARGS)
 {
        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_MHASH
        {
index 61b3c82353220524775c7830ba036c8dcc7ccf11..dfc2476a8819259df634f5b2dbad0577cf9c3cf2 100644 (file)
@@ -240,6 +240,7 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D)
 #ifndef WONKY
        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_MHASH
        {
index 6dfc677f993b5be0eef58657c291506311b986c8..3f6f2a6ef524c75e9b5071b9ba8e52cd55338eba 100644 (file)
@@ -289,6 +289,7 @@ PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, size_
 
        /* multi range */
        else {
+               size_t preface_len;
                char bound[23] = {0}, preface[1024] = {0},
                        multi_header[68] = "Content-Type: multipart/byteranges; boundary=";
 
@@ -307,7 +308,7 @@ PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, size_
                                break;
                        }
 
-                       snprintf(preface, 1023,
+                       preface_len = snprintf(preface, 1023,
                                HTTP_CRLF "%s"
                                HTTP_CRLF "Content-Type: %s"
                                HTTP_CRLF "Content-Range: bytes %ld-%ld/%lu"
@@ -321,7 +322,7 @@ PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, size_
                                (ulong) size
                        );
 
-                       PHPWRITE(preface, strlen(preface));
+                       PHPWRITE(preface, preface_len);
                        http_send_chunk(data, Z_LVAL_PP(zbegin), Z_LVAL_PP(zend) + 1, mode);
                }
 
index d7e53b77b41bc5c073ae52e6ef3c66a750919387..14ae720d0886ce9829f430a744db8d2dc3fc554f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "ext/standard/md5.h"
 #include "ext/standard/sha1.h"
+#include "ext/standard/crc32.h"
 
 #include "php_http_std_defs.h"
 #include "php_http.h"
@@ -38,6 +39,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 extern STATUS _http_cache_global_init(INIT_FUNC_ARGS);
 
 typedef enum {
+       HTTP_ETAG_CRC32 = -3,
        HTTP_ETAG_MD5 = -2,
        HTTP_ETAG_SHA1 = -1,
 } http_etag_mode;
@@ -75,6 +77,11 @@ static inline void *_http_etag_init(TSRMLS_D)
        
        switch (mode)
        {
+               case HTTP_ETAG_CRC32:
+                       ctx = emalloc(sizeof(unsigned int));
+                       memset(ctx, 1, sizeof(unsigned int));
+               break;
+               
                case HTTP_ETAG_SHA1:
                        PHP_SHA1Init(ctx = emalloc(sizeof(PHP_SHA1_CTX)));
                break;
@@ -107,6 +114,12 @@ static inline char *_http_etag_finish(void *ctx TSRMLS_DC)
        
        switch (mode)
        {
+               case HTTP_ETAG_CRC32:
+                       *((unsigned int *) ctx) = ~*((unsigned int *) ctx);
+                       etag = http_etag_digest((const unsigned char *) ctx, sizeof(unsigned int));
+                       efree(ctx);
+               break;
+               
                case HTTP_ETAG_SHA1:
                        PHP_SHA1Final(digest, ctx);
                        etag = http_etag_digest(digest, 20);
@@ -141,6 +154,17 @@ static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t dat
 {
        switch (INI_INT("http.etag_mode"))
        {
+               case HTTP_ETAG_CRC32:
+               {
+                       unsigned int i, c = *((unsigned int *) ctx);
+                       
+                       for (i = 0; i < data_len; ++i) {
+                               c = CRC32(c, data_ptr[i]);
+                       }
+                       *((unsigned int *)ctx) = c;
+               }
+               break;
+               
                case HTTP_ETAG_SHA1:
                        PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
                break;