PHP 8 compatibility
[m6w6/ext-http] / src / php_http_etag.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #include "ext/hash/php_hash.h"
16 #include "ext/standard/crc32.h"
17 #include "ext/standard/sha1.h"
18 #include "ext/standard/md5.h"
19
20 php_http_etag_t *php_http_etag_init(const char *mode)
21 {
22 php_http_etag_t *e;
23 zend_string *mode_str = zend_string_init(mode, strlen(mode), 0);
24 const php_hash_ops *eho = php_hash_fetch_ops(mode_str);
25
26 if (!eho) {
27 zend_string_release(mode_str);
28 return NULL;
29 }
30 zend_string_release(mode_str);
31
32 e = emalloc(sizeof(*e) + eho->context_size - 1);
33 e->ops = eho;
34 eho->hash_init(e->ctx);
35
36 return e;
37 }
38
39 char *php_http_etag_finish(php_http_etag_t *e)
40 {
41 unsigned char digest[128] = {0};
42 char *etag;
43
44 e->ops->hash_final(digest, e->ctx);
45 etag = php_http_etag_digest(digest, e->ops->digest_size);
46 efree(e);
47
48 return etag;
49 }
50
51 size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len)
52 {
53 e->ops->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len);
54
55 return data_len;
56 }
57
58
59 /*
60 * Local variables:
61 * tab-width: 4
62 * c-basic-offset: 4
63 * End:
64 * vim600: noet sw=4 ts=4 fdm=marker
65 * vim<600: noet sw=4 ts=4
66 */
67