|
Revision 2245, 1.1 kB
(checked in by stbuehler, 4 weeks ago)
|
|
merged from @1874: add ETag configuration (#1442)
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | #include <string.h> |
|---|
| 2 | |
|---|
| 3 | #ifdef HAVE_CONFIG_H |
|---|
| 4 | #include "config.h" |
|---|
| 5 | #endif |
|---|
| 6 | |
|---|
| 7 | #if defined HAVE_STDINT_H |
|---|
| 8 | #include <stdint.h> |
|---|
| 9 | #elif defined HAVE_INTTYPES_H |
|---|
| 10 | #include <inttypes.h> |
|---|
| 11 | #endif |
|---|
| 12 | |
|---|
| 13 | #include "buffer.h" |
|---|
| 14 | #include "etag.h" |
|---|
| 15 | |
|---|
| 16 | int etag_is_equal(buffer *etag, const char *matches) { |
|---|
| 17 | if (buffer_is_equal_string(etag, matches, strlen(matches))) return 1; |
|---|
| 18 | return 0; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | int etag_create(buffer *etag, struct stat *st, etag_flags_t flags) { |
|---|
| 22 | |
|---|
| 23 | if (0 == flags) return 0; |
|---|
| 24 | |
|---|
| 25 | buffer_reset(etag); |
|---|
| 26 | |
|---|
| 27 | if (flags & ETAG_USE_INODE) { |
|---|
| 28 | buffer_append_off_t(etag, st->st_ino); |
|---|
| 29 | buffer_append_string_len(etag, CONST_STR_LEN("-")); |
|---|
| 30 | } |
|---|
| 31 | if (flags & ETAG_USE_SIZE) { |
|---|
| 32 | buffer_append_off_t(etag, st->st_size); |
|---|
| 33 | buffer_append_string_len(etag, CONST_STR_LEN("-")); |
|---|
| 34 | } |
|---|
| 35 | if (flags & ETAG_USE_MTIME) { |
|---|
| 36 | buffer_append_long(etag, st->st_mtime); |
|---|
| 37 | } |
|---|
| 38 | return 0; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | int etag_mutate(buffer *mut, buffer *etag) { |
|---|
| 42 | size_t i; |
|---|
| 43 | uint32_t h; |
|---|
| 44 | |
|---|
| 45 | for (h=0, i=0; i < etag->used; ++i) h = (h<<5)^(h>>27)^(etag->ptr[i]); |
|---|
| 46 | |
|---|
| 47 | buffer_reset(mut); |
|---|
| 48 | buffer_copy_string_len(mut, CONST_STR_LEN("\"")); |
|---|
| 49 | buffer_append_long(mut, h); |
|---|
| 50 | buffer_append_string_len(mut, CONST_STR_LEN("\"")); |
|---|
| 51 | |
|---|
| 52 | return 0; |
|---|
| 53 | } |
|---|