1: #include "buffer.h"
2: #include "etag.h"
3:
4: #if defined HAVE_STDINT_H
5: # include <stdint.h>
6: #elif defined HAVE_INTTYPES_H
7: # include <inttypes.h>
8: #endif
9:
10: #include <string.h>
11:
12: int etag_is_equal(buffer *etag, const char *matches) {
13: if (etag && !buffer_is_empty(etag) && 0 == strcmp(etag->ptr, matches)) return 1;
14: return 0;
15: }
16:
17: int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) {
18: if (0 == flags) return 0;
19:
20: buffer_reset(etag);
21:
22: if (flags & ETAG_USE_INODE) {
23: buffer_append_off_t(etag, st->st_ino);
24: buffer_append_string_len(etag, CONST_STR_LEN("-"));
25: }
26:
27: if (flags & ETAG_USE_SIZE) {
28: buffer_append_off_t(etag, st->st_size);
29: buffer_append_string_len(etag, CONST_STR_LEN("-"));
30: }
31:
32: if (flags & ETAG_USE_MTIME) {
33: buffer_append_long(etag, st->st_mtime);
34: }
35:
36: return 0;
37: }
38:
39: int etag_mutate(buffer *mut, buffer *etag) {
40: size_t i;
41: uint32_t h;
42:
43: for (h=0, i=0; i < etag->used-1; ++i) h = (h<<5)^(h>>27)^(etag->ptr[i]);
44:
45: buffer_reset(mut);
46: buffer_copy_string_len(mut, CONST_STR_LEN("\""));
47: buffer_append_off_t(mut, h);
48: buffer_append_string_len(mut, CONST_STR_LEN("\""));
49:
50: return 0;
51: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>