2005-02-20 14:27:00 +00:00
|
|
|
#include <string.h>
|
2007-08-15 09:49:15 +00:00
|
|
|
#include <stdint.h>
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "etag.h"
|
|
|
|
|
|
|
|
int etag_is_equal(buffer *etag, const char *matches) {
|
2007-08-27 21:54:45 +00:00
|
|
|
if (etag && !buffer_is_empty(etag) && 0 == strcmp(etag->ptr, matches)) return 1;
|
2005-02-20 14:27:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-15 15:51:16 +00:00
|
|
|
int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) {
|
|
|
|
if (0 == flags) return 0;
|
2007-07-03 17:16:21 +00:00
|
|
|
|
|
|
|
buffer_reset(etag);
|
|
|
|
|
2007-06-15 15:51:16 +00:00
|
|
|
if (flags & ETAG_USE_INODE) {
|
2007-07-03 17:16:21 +00:00
|
|
|
buffer_append_off_t(etag, st->st_ino);
|
2007-06-15 15:51:16 +00:00
|
|
|
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);
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int etag_mutate(buffer *mut, buffer *etag) {
|
2007-08-15 09:49:15 +00:00
|
|
|
size_t i;
|
|
|
|
uint32_t h;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
for (h=0, i=0; i < etag->used; ++i) h = (h<<5)^(h>>27)^(etag->ptr[i]);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer_reset(mut);
|
2005-06-12 09:18:17 +00:00
|
|
|
buffer_copy_string_len(mut, CONST_STR_LEN("\""));
|
|
|
|
buffer_append_long(mut, h);
|
|
|
|
buffer_append_string_len(mut, CONST_STR_LEN("\""));
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|