2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
18 #ifndef PHP_HTTP_CACHE_API_H
19 #define PHP_HTTP_CACHE_API_H
23 #include "ext/standard/md5.h"
24 #include "ext/standard/sha1.h"
25 #include "ext/standard/crc32.h"
27 #include "php_http_std_defs.h"
29 #include "php_http_api.h"
30 #include "php_http_send_api.h"
32 #ifdef HTTP_HAVE_MHASH
36 ZEND_EXTERN_MODULE_GLOBALS(http
);
38 #define http_cache_global_init() _http_cache_global_init(INIT_FUNC_ARGS_PASSTHRU)
39 extern STATUS
_http_cache_global_init(INIT_FUNC_ARGS
);
47 #ifdef HTTP_HAVE_MHASH
48 static void *http_etag_alloc_mhash_digest(size_t size
)
54 #define http_etag_digest(d, l) _http_etag_digest((d), (l) TSRMLS_CC)
55 static inline char *_http_etag_digest(const unsigned char *digest
, int len TSRMLS_DC
)
58 char *hex
= emalloc(len
* 2 + 1);
62 look at apache's make_etag */
63 for (i
= 0; i
< len
; ++i
) {
64 sprintf(ptr
, "%02x", digest
[i
]);
72 #define http_etag_init() _http_etag_init(TSRMLS_C)
73 static inline void *_http_etag_init(TSRMLS_D
)
76 long mode
= INI_INT("http.etag_mode");
81 ctx
= emalloc(sizeof(unsigned int));
82 memset(ctx
, 1, sizeof(unsigned int));
86 PHP_SHA1Init(ctx
= emalloc(sizeof(PHP_SHA1_CTX
)));
90 #ifndef HTTP_HAVE_MHASH
93 PHP_MD5Init(ctx
= emalloc(sizeof(PHP_MD5_CTX
)));
96 #ifdef HTTP_HAVE_MHASH
98 if ((mode
< 0) || ((ulong
)mode
> mhash_count()) || (!(ctx
= mhash_init(mode
)))) {
99 http_error_ex(HE_ERROR
, HTTP_E_RUNTIME
, "Invalid ETag mode: %ld", mode
);
108 #define http_etag_finish(c) _http_etag_finish((c) TSRMLS_CC)
109 static inline char *_http_etag_finish(void *ctx TSRMLS_DC
)
112 unsigned char digest
[20];
113 long mode
= INI_INT("http.etag_mode");
117 case HTTP_ETAG_CRC32
:
118 *((unsigned int *) ctx
) = ~*((unsigned int *) ctx
);
119 etag
= http_etag_digest((const unsigned char *) ctx
, sizeof(unsigned int));
124 PHP_SHA1Final(digest
, ctx
);
125 etag
= http_etag_digest(digest
, 20);
130 #ifndef HTTP_HAVE_MHASH
133 PHP_MD5Final(digest
, ctx
);
134 etag
= http_etag_digest(digest
, 16);
138 #ifdef HTTP_HAVE_MHASH
141 unsigned char *mhash_digest
= mhash_end_m(ctx
, http_etag_alloc_mhash_digest
);
142 etag
= http_etag_digest(mhash_digest
, mhash_get_block_size(mode
));
152 #define http_etag_update(c, d, l) _http_etag_update((c), (d), (l) TSRMLS_CC)
153 static inline void _http_etag_update(void *ctx
, const char *data_ptr
, size_t data_len TSRMLS_DC
)
155 switch (INI_INT("http.etag_mode"))
157 case HTTP_ETAG_CRC32
:
159 unsigned int i
, c
= *((unsigned int *) ctx
);
161 for (i
= 0; i
< data_len
; ++i
) {
162 c
= CRC32(c
, data_ptr
[i
]);
164 *((unsigned int *)ctx
) = c
;
169 PHP_SHA1Update(ctx
, (const unsigned char *) data_ptr
, data_len
);
173 #ifndef HTTP_HAVE_MHASH
176 PHP_MD5Update(ctx
, (const unsigned char *) data_ptr
, data_len
);
179 #ifdef HTTP_HAVE_MHASH
181 mhash(ctx
, data_ptr
, data_len
);
187 #define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC)
188 PHP_HTTP_API
char *_http_etag(const void *data_ptr
, size_t data_len
, http_send_mode data_mode TSRMLS_DC
);
190 #define http_last_modified(p, m) _http_last_modified((p), (m) TSRMLS_CC)
191 PHP_HTTP_API
time_t _http_last_modified(const void *data_ptr
, http_send_mode data_mode TSRMLS_DC
);
193 #define http_match_last_modified(entry, modified) _http_match_last_modified_ex((entry), (modified), 1 TSRMLS_CC)
194 #define http_match_last_modified_ex(entry, modified, ep) _http_match_last_modified_ex((entry), (modified), (ep) TSRMLS_CC)
195 PHP_HTTP_API zend_bool
_http_match_last_modified_ex(const char *entry
, time_t t
, zend_bool enforce_presence TSRMLS_DC
);
197 #define http_match_etag(entry, etag) _http_match_etag_ex((entry), (etag), 1 TSRMLS_CC)
198 #define http_match_etag_ex(entry, etag, ep) _http_match_etag_ex((entry), (etag), (ep) TSRMLS_CC)
199 PHP_HTTP_API zend_bool
_http_match_etag_ex(const char *entry
, const char *etag
, zend_bool enforce_presence TSRMLS_DC
);
201 #define http_cache_last_modified(l, s, cc, ccl) _http_cache_last_modified((l), (s), (cc), (ccl) TSRMLS_CC)
202 PHP_HTTP_API STATUS
_http_cache_last_modified(time_t last_modified
, time_t send_modified
, const char *cache_control
, size_t cc_len TSRMLS_DC
);
204 #define http_cache_etag(e, el, cc, ccl) _http_cache_etag((e), (el), (cc), (ccl) TSRMLS_CC)
205 PHP_HTTP_API STATUS
_http_cache_etag(const char *etag
, size_t etag_len
, const char *cache_control
, size_t cc_len TSRMLS_DC
);
207 #define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
208 PHP_HTTP_API
void _http_ob_etaghandler(char *output
, uint output_len
, char **handled_output
, uint
*handled_output_len
, int mode TSRMLS_DC
);
217 * vim600: noet sw=4 ts=4 fdm=marker
218 * vim<600: noet sw=4 ts=4