/*
- +----------------------------------------------------------------------+
- | PECL :: http |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.0 of the PHP license, that |
- | is bundled with this package in the file LICENSE, and is available |
- | through the world-wide-web at http://www.php.net/license/3_0.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
- +----------------------------------------------------------------------+
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2005, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
*/
/* $Id$ */
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_mode;
+extern PHP_MINIT_FUNCTION(http_cache);
+
#ifdef HTTP_HAVE_MHASH
static void *http_etag_alloc_mhash_digest(size_t size)
{
static inline void *_http_etag_init(TSRMLS_D)
{
void *ctx = NULL;
- long mode = INI_INT("http.etag_mode");
+ long mode = HTTP_G(etag).mode;
switch (mode)
{
case HTTP_ETAG_CRC32:
- ctx = emalloc(sizeof(unsigned int));
- memset(ctx, 1, sizeof(unsigned int));
+ ctx = emalloc(sizeof(uint));
+ *((uint *) ctx) = ~0;
break;
case HTTP_ETAG_SHA1:
return ctx;
}
+#define http_etag_free(cp) _http_etag_free((cp) TSRMLS_CC)
+static inline void _http_etag_free(void **ctx_ptr TSRMLS_DC)
+{
+ long mode = HTTP_G(etag).mode;
+
+ switch (mode)
+ {
+ case HTTP_ETAG_CRC32:
+ if (*((uint **) ctx_ptr)) {
+ efree(*((uint **) ctx_ptr));
+ *((uint **) ctx_ptr) = NULL;
+ }
+ break;
+
+ case HTTP_ETAG_SHA1:
+ if (*((PHP_SHA1_CTX **) ctx_ptr)) {
+ efree(*((PHP_SHA1_CTX **) ctx_ptr));
+ *((PHP_SHA1_CTX **) ctx_ptr) = NULL;
+ }
+ break;
+
+ case HTTP_ETAG_MD5:
+#ifndef HTTP_HAVE_MHASH
+ default:
+#endif
+ if (*((PHP_MD5_CTX **) ctx_ptr)) {
+ efree(*((PHP_MD5_CTX **) ctx_ptr));
+ *((PHP_MD5_CTX **) ctx_ptr) = NULL;
+ }
+ break;
+
+#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
+ }
+}
+
#define http_etag_finish(c) _http_etag_finish((c) TSRMLS_CC)
-static inline char *_http_etag_finish(void *ctx TSRMLS_DC)
+static inline char *_http_etag_finish(void **ctx_ptr TSRMLS_DC)
{
char *etag = NULL;
unsigned char digest[20];
- long mode = INI_INT("http.etag_mode");
+ long mode = HTTP_G(etag).mode;
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);
+ **((uint **) ctx_ptr) = ~**((uint **) ctx_ptr);
+ etag = http_etag_digest(*((const unsigned char **) ctx_ptr), sizeof(uint));
break;
case HTTP_ETAG_SHA1:
- PHP_SHA1Final(digest, ctx);
+ PHP_SHA1Final(digest, *((PHP_SHA1_CTX **) ctx_ptr));
etag = http_etag_digest(digest, 20);
- efree(ctx);
break;
case HTTP_ETAG_MD5:
#ifndef HTTP_HAVE_MHASH
default:
#endif
- PHP_MD5Final(digest, ctx);
+ PHP_MD5Final(digest, *((PHP_MD5_CTX **) ctx_ptr));
etag = http_etag_digest(digest, 16);
- efree(ctx);
break;
#ifdef HTTP_HAVE_MHASH
default:
{
- unsigned char *mhash_digest = mhash_end_m(ctx, http_etag_alloc_mhash_digest);
+ 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
}
+ http_etag_free(ctx_ptr);
+
return etag;
}
{
case HTTP_ETAG_CRC32:
{
- unsigned int i, c = *((unsigned int *) ctx);
+ uint i, c = *((uint *) ctx);
for (i = 0; i < data_len; ++i) {
c = CRC32(c, data_ptr[i]);
}
- *((unsigned int *)ctx) = c;
+ *((uint *)ctx) = c;
}
break;
}
}
+#define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
+extern void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
+
#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC)
PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC);
#define http_cache_etag(e, el, cc, ccl) _http_cache_etag((e), (el), (cc), (ccl) TSRMLS_CC)
PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len, const char *cache_control, size_t cc_len TSRMLS_DC);
-#define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
-PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
+#define http_start_ob_etaghandler() _http_start_ob_etaghandler(TSRMLS_C)
+PHP_HTTP_API STATUS _http_start_ob_etaghandler(TSRMLS_D);
+#define http_interrupt_ob_etaghandler() _http_interrupt_ob_etaghandler(TSRMLS_C)
+PHP_HTTP_API zend_bool _http_interrupt_ob_etaghandler(TSRMLS_D);
#endif