- move specific initialization code to the respective modules
[m6w6/ext-http] / php_http_cache_api.h
index 8a9e55d83c820dab7ab6ec9ff6b1ee712d9c94fa..d7e53b77b41bc5c073ae52e6ef3c66a750919387 100644 (file)
 #ifndef PHP_HTTP_CACHE_API_H
 #define PHP_HTTP_CACHE_API_H
 
+#include "zend_ini.h"
+
+#include "ext/standard/md5.h"
+#include "ext/standard/sha1.h"
+
 #include "php_http_std_defs.h"
 #include "php_http.h"
 #include "php_http_api.h"
 #include "php_http_send_api.h"
 
-#include "zend_ini.h"
-
-#ifdef HAVE_LIBMHASH
+#ifdef HTTP_HAVE_MHASH
 #      include <mhash.h>
 #endif
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
+#define http_cache_global_init() _http_cache_global_init(INIT_FUNC_ARGS_PASSTHRU)
+extern STATUS _http_cache_global_init(INIT_FUNC_ARGS);
+
 typedef enum {
        HTTP_ETAG_MD5 = -2,
        HTTP_ETAG_SHA1 = -1,
-       HTTP_ETAG_MHASH = 0,
 } http_etag_mode;
 
-#ifdef HAVE_LIBMHASH
+#ifdef HTTP_HAVE_MHASH
 static void *http_etag_alloc_mhash_digest(size_t size)
 {
        return emalloc(size);
@@ -65,7 +70,7 @@ static inline char *_http_etag_digest(const unsigned char *digest, int len TSRML
 #define http_etag_init() _http_etag_init(TSRMLS_C)
 static inline void *_http_etag_init(TSRMLS_D)
 {
-       void *ctx;
+       void *ctx = NULL;
        long mode = INI_INT("http.etag_mode");
        
        switch (mode)
@@ -75,24 +80,19 @@ static inline void *_http_etag_init(TSRMLS_D)
                break;
                
                case HTTP_ETAG_MD5:
-invalid_flag:
+#ifndef HTTP_HAVE_MHASH
+               default:
+#endif
                        PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX)));
                break;
                
+#ifdef HTTP_HAVE_MHASH
                default:
-               {
-#ifdef HAVE_LIBMHASH
-                       if ((mode >= 0) && (mode <= mhash_count())) {
-                               ctx = mhash_init(mode);
-                       }
-                       if ((!ctx) || (ctx == MHASH_FAILED))
-#endif
-                       {
-                               HTTP_G(etag).mode = HTTP_ETAG_MD5;
-                               goto invalid_flag;
+                       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
        }
        
        return ctx;
@@ -114,20 +114,23 @@ static inline char *_http_etag_finish(void *ctx TSRMLS_DC)
                break;
                
                case HTTP_ETAG_MD5:
+#ifndef HTTP_HAVE_MHASH
+               default:
+#endif
                        PHP_MD5Final(digest, ctx);
                        etag = http_etag_digest(digest, 16);
                        efree(ctx);
                break;
                
+#ifdef HTTP_HAVE_MHASH
                default:
                {
-#ifdef HAVE_LIBMHASH
                        unsigned char *mhash_digest = mhash_end_m(ctx, http_etag_alloc_mhash_digest);
                        etag = http_etag_digest(mhash_digest, mhash_get_block_size(mode));
                        efree(mhash_digest);
-#endif
                }
                break;
+#endif
        }
        
        return etag;
@@ -139,18 +142,21 @@ static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t dat
        switch (INI_INT("http.etag_mode"))
        {
                case HTTP_ETAG_SHA1:
-                       PHP_SHA1Update(ctx, data_ptr, data_len);
+                       PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
                break;
                
                case HTTP_ETAG_MD5:
-                       PHP_MD5Update(ctx, data_ptr, data_len);
+#ifndef HTTP_HAVE_MHASH
+               default:
+#endif
+                       PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len);
                break;
                
+#ifdef HTTP_HAVE_MHASH
                default:
-#ifdef HAVE_LIBMHASH
                        mhash(ctx, data_ptr, data_len);
-#endif
                break;
+#endif
        }
 }