2 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
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"
20 #if PHP_VERSION_ID >= 80100
21 # define HASH_INIT_ARGS ,NULL
23 # define HASH_INIT_ARGS
26 php_http_etag_t
*php_http_etag_init(const char *mode
)
29 zend_string
*mode_str
= zend_string_init(mode
, strlen(mode
), 0);
30 const php_hash_ops
*eho
= php_hash_fetch_ops(mode_str
);
33 zend_string_release(mode_str
);
36 zend_string_release(mode_str
);
38 e
= emalloc(sizeof(*e
) + eho
->context_size
- 1);
40 eho
->hash_init(e
->ctx HASH_INIT_ARGS
);
45 char *php_http_etag_finish(php_http_etag_t
*e
)
47 unsigned char digest
[128] = {0};
50 e
->ops
->hash_final(digest
, e
->ctx
);
51 etag
= php_http_etag_digest(digest
, e
->ops
->digest_size
);
57 size_t php_http_etag_update(php_http_etag_t
*e
, const char *data_ptr
, size_t data_len
)
59 e
->ops
->hash_update(e
->ctx
, (const unsigned char *) data_ptr
, data_len
);
70 * vim600: noet sw=4 ts=4 fdm=marker
71 * vim<600: noet sw=4 ts=4