fix usage of hash_init() in 8.1
[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 #if PHP_VERSION_ID >= 80100
21 # define HASH_INIT_ARGS ,NULL
22 #else
23 # define HASH_INIT_ARGS
24 #endif
25
26 php_http_etag_t *php_http_etag_init(const char *mode)
27 {
28 php_http_etag_t *e;
29 zend_string *mode_str = zend_string_init(mode, strlen(mode), 0);
30 const php_hash_ops *eho = php_hash_fetch_ops(mode_str);
31
32 if (!eho) {
33 zend_string_release(mode_str);
34 return NULL;
35 }
36 zend_string_release(mode_str);
37
38 e = emalloc(sizeof(*e) + eho->context_size - 1);
39 e->ops = eho;
40 eho->hash_init(e->ctx HASH_INIT_ARGS);
41
42 return e;
43 }
44
45 char *php_http_etag_finish(php_http_etag_t *e)
46 {
47 unsigned char digest[128] = {0};
48 char *etag;
49
50 e->ops->hash_final(digest, e->ctx);
51 etag = php_http_etag_digest(digest, e->ops->digest_size);
52 efree(e);
53
54 return etag;
55 }
56
57 size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len)
58 {
59 e->ops->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len);
60
61 return data_len;
62 }
63
64
65 /*
66 * Local variables:
67 * tab-width: 4
68 * c-basic-offset: 4
69 * End:
70 * vim600: noet sw=4 ts=4 fdm=marker
71 * vim<600: noet sw=4 ts=4
72 */