#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"
#include "php_http_api.h"
#include "php_http_send_api.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_CRC32 = -3,
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);
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;
case HTTP_ETAG_MD5:
-#ifndef HAVE_LIBMHASH
+#ifndef HTTP_HAVE_MHASH
default:
#endif
PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX)));
break;
-#ifdef HAVE_LIBMHASH
+#ifdef HTTP_HAVE_MHASH
default:
if ((mode < 0) || ((ulong)mode > mhash_count()) || (!(ctx = mhash_init(mode)))) {
- http_error_ex(HE_ERROR, HE_RUNTIME, "Invalid ETag mode: %ld", mode);
+ http_error_ex(HE_ERROR, HTTP_E_RUNTIME, "Invalid ETag mode: %ld", mode);
}
break;
#endif
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);
break;
case HTTP_ETAG_MD5:
-#ifndef HAVE_LIBMHASH
+#ifndef HTTP_HAVE_MHASH
default:
#endif
PHP_MD5Final(digest, ctx);
efree(ctx);
break;
-#ifdef HAVE_LIBMHASH
+#ifdef HTTP_HAVE_MHASH
default:
{
unsigned char *mhash_digest = mhash_end_m(ctx, http_etag_alloc_mhash_digest);
{
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, data_ptr, data_len);
+ PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
break;
case HTTP_ETAG_MD5:
-#ifndef HAVE_LIBMHASH
+#ifndef HTTP_HAVE_MHASH
default:
#endif
- PHP_MD5Update(ctx, data_ptr, data_len);
+ PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len);
break;
-#ifdef HAVE_LIBMHASH
+#ifdef HTTP_HAVE_MHASH
default:
mhash(ctx, data_ptr, data_len);
break;