diff options
author | Arno Töll <arno@debian.org> | 2012-11-21 23:57:42 +0100 |
---|---|---|
committer | Arno Töll <arno@debian.org> | 2012-11-21 23:57:42 +0100 |
commit | 47236ea4c1d5601fc6bea1b280d36152ec5ff32b (patch) | |
tree | 89c109c0bef460fa747a3413610034002fac1cb4 /src/etag.c | |
parent | dae92c799e85ec3b65f46da6a776e4386bc99d6c (diff) | |
download | lighttpd-47236ea4c1d5601fc6bea1b280d36152ec5ff32b.tar.gz |
Imported Upstream version 1.4.32
Diffstat (limited to 'src/etag.c')
-rw-r--r-- | src/etag.c | 49 |
1 files changed, 34 insertions, 15 deletions
@@ -1,32 +1,51 @@ -#include <string.h> - #include "buffer.h" #include "etag.h" +#if defined HAVE_STDINT_H +# include <stdint.h> +#elif defined HAVE_INTTYPES_H +# include <inttypes.h> +#endif + +#include <string.h> + int etag_is_equal(buffer *etag, const char *matches) { - if (0 == strcmp(etag->ptr, matches)) return 1; + if (etag && !buffer_is_empty(etag) && 0 == strcmp(etag->ptr, matches)) return 1; return 0; } -int etag_create(buffer *etag, struct stat *st) { - buffer_copy_off_t(etag, st->st_ino); - buffer_append_string_len(etag, CONST_STR_LEN("-")); - buffer_append_off_t(etag, st->st_size); - buffer_append_string_len(etag, CONST_STR_LEN("-")); - buffer_append_long(etag, st->st_mtime); +int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) { + if (0 == flags) return 0; + + buffer_reset(etag); + + if (flags & ETAG_USE_INODE) { + buffer_append_off_t(etag, st->st_ino); + buffer_append_string_len(etag, CONST_STR_LEN("-")); + } + + if (flags & ETAG_USE_SIZE) { + buffer_append_off_t(etag, st->st_size); + buffer_append_string_len(etag, CONST_STR_LEN("-")); + } + if (flags & ETAG_USE_MTIME) { + buffer_append_long(etag, st->st_mtime); + } + return 0; } int etag_mutate(buffer *mut, buffer *etag) { - size_t h, i; - - for (h=0, i=0; i < etag->used; ++i) h = (h<<5)^(h>>27)^(etag->ptr[i]); - + size_t i; + uint32_t h; + + for (h=0, i=0; i < etag->used-1; ++i) h = (h<<5)^(h>>27)^(etag->ptr[i]); + buffer_reset(mut); buffer_copy_string_len(mut, CONST_STR_LEN("\"")); - buffer_append_long(mut, h); + buffer_append_off_t(mut, h); buffer_append_string_len(mut, CONST_STR_LEN("\"")); - + return 0; } |