1ef7b2308c537674a6d832fb095d3ca60e50959f
[m6w6/ext-http] / php_http_etag.h
1 #ifndef PHP_HTTP_ETAG_H
2 #define PHP_HTTP_ETAG_H
3
4 typedef struct php_http_etag {
5 void *ctx;
6 char *mode;
7
8 #ifdef ZTS
9 void ***ts;
10 #endif
11 } php_http_etag_t;
12
13 PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC);
14 PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len);
15 PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e);
16
17 static inline char *php_http_etag_digest(const unsigned char *digest, int len)
18 {
19 static const char hexdigits[17] = "0123456789abcdef";
20 int i;
21 char *hex = emalloc(len * 2 + 1);
22 char *ptr = hex;
23
24 for (i = 0; i < len; ++i) {
25 *ptr++ = hexdigits[digest[i] >> 4];
26 *ptr++ = hexdigits[digest[i] & 0xF];
27 }
28 *ptr = '\0';
29
30 return hex;
31 }
32
33 #endif /* PHP_HTTP_ETAG_H */