Browse Source

fix buffer, chunk and http_chunk API

* remove unused structs and functions
    (buffer_array, read_buffer)
  * change return type from int to void for many functions,
    as the return value (indicating error/success) was never checked,
    and the function would only fail on programming errors and not on
    invalid input; changed functions to use force_assert instead of
    returning an error.
  * all "len" parameters now are the real size of the memory to be read.
    the length of strings is given always without the terminating 0.
  * the "buffer" struct still counts the terminating 0 in ->used,
    provide buffer_string_length() to get the length of a string in a
    buffer.
    unset config "strings" have used == 0, which is used in some places
    to distinguish unset values from "" (empty string) values.
  * most buffer usages should now use it as string container.
  * optimise some buffer copying by "moving" data to other buffers
  * use (u)intmax_t for generic int-to-string functions
  * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET
  * converted BUFFER_APPEND_SLASH to inline function (no macro feature
    needed)
  * refactor: create chunkqueue_steal: moving (partial) chunks into another
    queue
  * http_chunk: added separate function to terminate chunked body instead of
    magic handling in http_chunk_append_mem().
    http_chunk_append_* now handle empty chunks, and never terminate the
    chunked body.

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.36
Stefan Bühler 7 years ago
parent
commit
6afad87d2e
  1. 1
      NEWS
  2. 2
      src/array.c
  3. 752
      src/buffer.c
  4. 170
      src/buffer.h
  5. 244
      src/chunk.c
  6. 18
      src/chunk.h
  7. 16
      src/configfile-glue.c
  8. 26
      src/configfile.c
  9. 26
      src/configparser.y
  10. 28
      src/connections.c
  11. 2
      src/data_array.c
  12. 4
      src/data_config.c
  13. 2
      src/data_count.c
  14. 4
      src/data_fastcgi.c
  15. 2
      src/data_integer.c
  16. 8
      src/data_string.c
  17. 10
      src/etag.c
  18. 6
      src/http-header-glue.c
  19. 14
      src/http_auth.c
  20. 71
      src/http_chunk.c
  21. 8
      src/http_chunk.h
  22. 16
      src/log.c
  23. 2
      src/mod_access.c
  24. 22
      src/mod_accesslog.c
  25. 6
      src/mod_alias.c
  26. 6
      src/mod_auth.c
  27. 49
      src/mod_cgi.c
  28. 10
      src/mod_cml.c
  29. 14
      src/mod_cml_lua.c
  30. 20
      src/mod_compress.c
  31. 17
      src/mod_dirlisting.c
  32. 8
      src/mod_evhost.c
  33. 2
      src/mod_expire.c
  34. 219
      src/mod_fastcgi.c
  35. 4
      src/mod_flv_streaming.c
  36. 6
      src/mod_indexfile.c
  37. 8
      src/mod_magnet.c
  38. 4
      src/mod_magnet_cache.c
  39. 18
      src/mod_mysql_vhost.c
  40. 77
      src/mod_proxy.c
  41. 2
      src/mod_redirect.c
  42. 4
      src/mod_rewrite.c
  43. 12
      src/mod_rrdtool.c
  44. 135
      src/mod_scgi.c
  45. 14
      src/mod_secure_download.c
  46. 8
      src/mod_setenv.c
  47. 26
      src/mod_simple_vhost.c
  48. 33
      src/mod_ssi.c
  49. 4
      src/mod_ssi_expr.c
  50. 16
      src/mod_staticfile.c
  51. 50
      src/mod_status.c
  52. 10
      src/mod_trigger_b4_dl.c
  53. 10
      src/mod_uploadprogress.c
  54. 20
      src/mod_userdir.c
  55. 16
      src/mod_usertrack.c
  56. 62
      src/mod_webdav.c
  57. 28
      src/network.c
  58. 2
      src/plugin.c
  59. 6
      src/request.c
  60. 32
      src/response.c
  61. 2
      src/server.c
  62. 26
      src/stat_cache.c

1
NEWS

@ -15,6 +15,7 @@ NEWS
* [network] fix compile break in calculation of sockaddr_un size if SUN_LEN is not defined (fixes #2609)
* [connections] fix bug in connection state handling
* print backtrace in assert logging with libunwind
* major refactoring of internal buffer/chunk handling
- 1.4.35 - 2014-03-12
* [network/ssl] fix build error if TLSEXT is disabled

2
src/array.c

@ -188,7 +188,7 @@ int array_insert_unique(array *a, data_unset *str) {
/* generate unique index if neccesary */
if (str->key->used == 0 || str->is_index_key) {
buffer_copy_long(str->key, a->unique_ndx++);
buffer_copy_int(str->key, a->unique_ndx++);
str->is_index_key = 1;
}

752
src/buffer.c

File diff suppressed because it is too large

170
src/buffer.h

@ -11,74 +11,96 @@
#include <sys/types.h>
#include <stdio.h>
#if defined HAVE_STDINT_H
# include <stdint.h>
#elif defined HAVE_INTTYPES_H
# include <inttypes.h>
#endif
/* generic string + binary data container; contains a terminating 0 in both
* cases
*
* used == 0 indicates a special "empty" state (unset config values); ptr
* might be NULL too then. otherwise an empty string has used == 1 (and ptr[0]
* == 0);
*
* copy/append functions will ensure used >= 1 (i.e. never leave it in the
* special empty state); only buffer_copy_buffer will copy the special empty
* state.
*/
typedef struct {
char *ptr;
/* "used" includes a terminating 0 */
size_t used;
/* size of allocated buffer at *ptr */
size_t size;
} buffer;
typedef struct {
buffer **ptr;
size_t used;
size_t size;
} buffer_array;
typedef struct {
char *ptr;
size_t offset; /* input-pointer */
size_t used; /* output-pointer */
size_t size;
} read_buffer;
buffer_array* buffer_array_init(void);
void buffer_array_free(buffer_array *b);
void buffer_array_reset(buffer_array *b);
buffer *buffer_array_append_get_buffer(buffer_array *b);
/* create new buffer; either empty or copy given data */
buffer* buffer_init(void);
buffer* buffer_init_buffer(buffer *b);
buffer* buffer_init_string(const char *str);
void buffer_free(buffer *b);
void buffer_reset(buffer *b);
int buffer_prepare_copy(buffer *b, size_t size);
int buffer_prepare_append(buffer *b, size_t size);
int buffer_copy_string(buffer *b, const char *s);
int buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
int buffer_copy_string_buffer(buffer *b, const buffer *src);
int buffer_copy_string_hex(buffer *b, const char *in, size_t in_len);
int buffer_copy_long(buffer *b, long val);
int buffer_copy_memory(buffer *b, const char *s, size_t s_len);
int buffer_append_string(buffer *b, const char *s);
int buffer_append_string_len(buffer *b, const char *s, size_t s_len);
int buffer_append_string_buffer(buffer *b, const buffer *src);
int buffer_append_string_lfill(buffer *b, const char *s, size_t maxlen);
int buffer_append_string_rfill(buffer *b, const char *s, size_t maxlen);
int buffer_append_long_hex(buffer *b, unsigned long len);
int buffer_append_long(buffer *b, long val);
#if defined(SIZEOF_LONG) && (SIZEOF_LONG == SIZEOF_OFF_T)
#define buffer_copy_off_t(x, y) buffer_copy_long(x, y)
#define buffer_append_off_t(x, y) buffer_append_long(x, y)
#else
int buffer_copy_off_t(buffer *b, off_t val);
int buffer_append_off_t(buffer *b, off_t val);
#endif
int buffer_append_memory(buffer *b, const char *s, size_t s_len);
buffer* buffer_init_buffer(const buffer *src); /* src can be NULL */
buffer* buffer_init_string(const char *str); /* str can be NULL */
void buffer_free(buffer *b); /* b can be NULL */
/* truncates to used == 0; frees large buffers, might keep smaller ones for reuse */
void buffer_reset(buffer *b); /* b can be NULL */
/* reset b. if NULL != b && NULL != src, move src content to b. reset src. */
void buffer_move(buffer *b, buffer *src);
/* prepare for size bytes in the buffer (b->size > size), destroys content
* (sets used = 0 and ptr[0] = 0). allocates storage for terminating 0.
* @return b->ptr
*/
char* buffer_prepare_copy(buffer *b, size_t size);
/* prepare for appending size bytes to the buffer
* allocates storage for terminating 0; if used > 0 assumes ptr[used-1] == 0,
* i.e. doesn't allocate another byte for terminating 0.
* @return (b->used > 0 ? b->ptr + b->used - 1 : b->ptr) - first new character
*/
char* buffer_prepare_append(buffer *b, size_t size);
/* use after prepare_(copy,append) when you have written data to the buffer
* to increase the buffer length by size. also sets the terminating zero.
* requires enough space is present for the terminating zero (prepare with the
* same size to be sure).
*/
void buffer_commit(buffer *b, size_t size);
void buffer_copy_string(buffer *b, const char *s);
void buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
void buffer_copy_buffer(buffer *b, const buffer *src);
/* convert input to hex and store in buffer */
void buffer_copy_string_hex(buffer *b, const char *in, size_t in_len);
void buffer_append_string(buffer *b, const char *s);
void buffer_append_string_len(buffer *b, const char *s, size_t s_len);
void buffer_append_string_buffer(buffer *b, const buffer *src);
void buffer_append_long_hex(buffer *b, unsigned long len);
void buffer_append_int(buffer *b, intmax_t val);
void buffer_copy_int(buffer *b, intmax_t val);
/* '-', log_10 (2^bits) = bits * log 2 / log 10 < bits * 0.31, terminating 0 */
#define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100)
void li_itostrn(char *buf, size_t buf_len, intmax_t val);
void li_itostr(char *buf, intmax_t val); /* buf must have at least LI_ITOSTRING_LENGTH bytes */
void li_utostrn(char *buf, size_t buf_len, uintmax_t val);
void li_utostr(char *buf, uintmax_t val); /* buf must have at least LI_ITOSTRING_LENGTH bytes */
char * buffer_search_string_len(buffer *b, const char *needle, size_t len);
/* NULL buffer or empty buffer (used == 0);
* unset "string" (buffer) config options are initialized to used == 0,
* while setting an empty string leads to used == 1
*/
int buffer_is_empty(buffer *b);
/* NULL buffer, empty buffer (used == 0) or empty string (used == 1) */
int buffer_string_is_empty(buffer *b);
int buffer_is_equal(buffer *a, buffer *b);
int buffer_is_equal_right_len(buffer *a, buffer *b, size_t len);
int buffer_is_equal_string(buffer *a, const char *s, size_t b_len);
@ -86,7 +108,6 @@ int buffer_is_equal_caseless_string(buffer *a, const char *s, size_t b_len);
int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len);
typedef enum {
ENCODING_UNSET,
ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus coding / too as %2F */
ENCODING_HTML, /* & becomes &amp; and so on */
@ -95,17 +116,17 @@ typedef enum {
ENCODING_HTTP_HEADER /* encode \n with \t\n */
} buffer_encoding_t;
int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding);
void buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding);
void buffer_urldecode_path(buffer *url);
void buffer_urldecode_query(buffer *url);
void buffer_path_simplify(buffer *dest, buffer *src);
int buffer_urldecode_path(buffer *url);
int buffer_urldecode_query(buffer *url);
int buffer_path_simplify(buffer *dest, buffer *src);
void buffer_to_lower(buffer *b);
void buffer_to_upper(buffer *b);
int buffer_to_lower(buffer *b);
int buffer_to_upper(buffer *b);
/** deprecated */
int LI_ltostr(char *buf, long val);
char hex2int(unsigned char c);
char int2hex(char i);
@ -114,17 +135,17 @@ int light_isxdigit(int c);
int light_isalpha(int c);
int light_isalnum(int c);
static inline size_t buffer_string_length(const buffer *b); /* buffer string length without terminating 0 */
static inline void buffer_append_slash(buffer *b); /* append '/' no non-empty strings not ending in '/' */
#define BUFFER_APPEND_STRING_CONST(x, y) \
buffer_append_string_len(x, y, sizeof(y) - 1)
#define BUFFER_COPY_STRING_CONST(x, y) \
buffer_copy_string_len(x, y, sizeof(y) - 1)
#define BUFFER_APPEND_SLASH(x) \
if (x->used > 1 && x->ptr[x->used - 2] != '/') { BUFFER_APPEND_STRING_CONST(x, "/"); }
#define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
#define CONST_BUF_LEN(x) x->ptr, x->used ? x->used - 1 : 0
#define CONST_STR_LEN(x) x, (x) ? sizeof(x) - 1 : 0
#define CONST_BUF_LEN(x) (x)->ptr, buffer_string_length(x)
#define UNUSED(x) ( (void)(x) )
@ -134,4 +155,15 @@ void log_failed_assert(const char *filename, unsigned int line, const char *msg)
#define force_assert(x) do { if (!(x)) log_failed_assert(__FILE__, __LINE__, "assertion failed: " #x); } while(0)
#define SEGFAULT() log_failed_assert(__FILE__, __LINE__, "aborted");
/* inline implementations */
static inline size_t buffer_string_length(const buffer *b) {
return NULL != b && 0 != b->used ? b->used - 1 : 0;
}
static inline void buffer_append_slash(buffer *b) {
size_t len = buffer_string_length(b);
if (len > 0 && '/' != b->ptr[len-1]) BUFFER_APPEND_STRING_CONST(b, "/");
}
#endif

244
src/chunk.c

@ -36,30 +36,28 @@ static chunk *chunk_init(void) {
c = calloc(1, sizeof(*c));
c->type = MEM_CHUNK;
c->mem = buffer_init();
c->file.name = buffer_init();
c->file.start = c->file.length = c->file.mmap.offset = 0;
c->file.fd = -1;
c->file.mmap.start = MAP_FAILED;
c->file.mmap.length = 0;
c->file.is_temp = 0;
c->offset = 0;
c->next = NULL;
return c;
}
static void chunk_free(chunk *c) {
if (!c) return;
buffer_free(c->mem);
buffer_free(c->file.name);
free(c);
}
static void chunk_reset(chunk *c) {
if (!c) return;
if (NULL == c) return;
c->type = MEM_CHUNK;
buffer_reset(c->mem);
if (c->file.is_temp && !buffer_is_empty(c->file.name)) {
if (c->file.is_temp && !buffer_string_is_empty(c->file.name)) {
unlink(c->file.name->ptr);
}
@ -73,13 +71,28 @@ static void chunk_reset(chunk *c) {
munmap(c->file.mmap.start, c->file.mmap.length);
c->file.mmap.start = MAP_FAILED;
}
c->file.start = c->file.length = c->file.mmap.offset = 0;
c->file.mmap.length = 0;
c->file.is_temp = 0;
c->offset = 0;
c->next = NULL;
}
static void chunk_free(chunk *c) {
if (NULL == c) return;
chunk_reset(c);
buffer_free(c->mem);
buffer_free(c->file.name);
free(c);
}
void chunkqueue_free(chunkqueue *cq) {
chunk *c, *pc;
if (!cq) return;
if (NULL == cq) return;
for (c = cq->first; c; ) {
pc = c;
@ -96,11 +109,27 @@ void chunkqueue_free(chunkqueue *cq) {
free(cq);
}
static void chunkqueue_push_unused_chunk(chunkqueue *cq, chunk *c) {
force_assert(NULL != cq && NULL != c);
/* keep at max 4 chunks in the 'unused'-cache */
if (cq->unused_chunks > 4) {
chunk_free(c);
} else {
chunk_reset(c);
c->next = cq->unused;
cq->unused = c;
cq->unused_chunks++;
}
}
static chunk *chunkqueue_get_unused_chunk(chunkqueue *cq) {
chunk *c;
force_assert(NULL != cq);
/* check if we have a unused chunk */
if (!cq->unused) {
if (0 == cq->unused) {
c = chunk_init();
} else {
/* take the first element from the list (a stack) */
@ -113,130 +142,95 @@ static chunk *chunkqueue_get_unused_chunk(chunkqueue *cq) {
return c;
}
static int chunkqueue_prepend_chunk(chunkqueue *cq, chunk *c) {
static void chunkqueue_prepend_chunk(chunkqueue *cq, chunk *c) {
c->next = cq->first;
cq->first = c;
if (cq->last == NULL) {
if (NULL == cq->last) {
cq->last = c;
}
return 0;
}
static int chunkqueue_append_chunk(chunkqueue *cq, chunk *c) {
static void chunkqueue_append_chunk(chunkqueue *cq, chunk *c) {
if (cq->last) {
cq->last->next = c;
}
cq->last = c;
if (cq->first == NULL) {
if (NULL == cq->first) {
cq->first = c;
}
return 0;
}
void chunkqueue_reset(chunkqueue *cq) {
chunk *c;
/* move everything to the unused queue */
chunk *cur = cq->first;
/* mark all read written */
for (c = cq->first; c; c = c->next) {
switch(c->type) {
case MEM_CHUNK:
c->offset = c->mem->used - 1;
break;
case FILE_CHUNK:
c->offset = c->file.length;
break;
default:
break;
}
cq->first = cq->last = NULL;
while (NULL != cur) {
chunk *next = cur->next;
chunkqueue_push_unused_chunk(cq, cur);
cur = next;
}
chunkqueue_remove_finished_chunks(cq);
cq->bytes_in = 0;
cq->bytes_out = 0;
}
int chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len) {
void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len) {
chunk *c;
if (len == 0) return 0;
if (0 == len) return;
c = chunkqueue_get_unused_chunk(cq);
c->type = FILE_CHUNK;
buffer_copy_string_buffer(c->file.name, fn);
buffer_copy_buffer(c->file.name, fn);
c->file.start = offset;
c->file.length = len;
c->offset = 0;
chunkqueue_append_chunk(cq, c);
return 0;
}
int chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) {
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) {
chunk *c;
if (mem->used == 0) return 0;
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
buffer_copy_string_buffer(c->mem, mem);
chunkqueue_append_chunk(cq, c);
return 0;
}
int chunkqueue_append_buffer_weak(chunkqueue *cq, buffer *mem) {
chunk *c;
if (buffer_string_is_empty(mem)) return;
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
if (c->mem) buffer_free(c->mem);
c->mem = mem;
force_assert(NULL != c->mem);
buffer_move(c->mem, mem);
chunkqueue_append_chunk(cq, c);
return 0;
}
int chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem) {
void chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem) {
chunk *c;
if (mem->used == 0) return 0;
if (buffer_string_is_empty(mem)) return;
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
buffer_copy_string_buffer(c->mem, mem);
force_assert(NULL != c->mem);
buffer_move(c->mem, mem);
chunkqueue_prepend_chunk(cq, c);
return 0;
}
int chunkqueue_append_mem(chunkqueue *cq, const char * mem, size_t len) {
void chunkqueue_append_mem(chunkqueue *cq, const char * mem, size_t len) {
chunk *c;
if (len == 0) return 0;
if (0 == len) return;
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
buffer_copy_string_len(c->mem, mem, len - 1);
buffer_copy_string_len(c->mem, mem, len);
chunkqueue_append_chunk(cq, c);
return 0;
}
buffer * chunkqueue_get_prepend_buffer(chunkqueue *cq) {
@ -245,8 +239,6 @@ buffer * chunkqueue_get_prepend_buffer(chunkqueue *cq) {
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
buffer_reset(c->mem);
chunkqueue_prepend_chunk(cq, c);
@ -259,20 +251,15 @@ buffer *chunkqueue_get_append_buffer(chunkqueue *cq) {
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
c->offset = 0;
buffer_reset(c->mem);
chunkqueue_append_chunk(cq, c);
return c->mem;
}
int chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs) {
if (!cq) return -1;
void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs) {
force_assert(NULL != cq);
cq->tempdirs = tempdirs;
return 0;
}
chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
@ -282,7 +269,6 @@ chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
c = chunkqueue_get_unused_chunk(cq);
c->type = FILE_CHUNK;
c->offset = 0;
if (cq->tempdirs && cq->tempdirs->used) {
size_t i;
@ -292,8 +278,8 @@ chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
for (i = 0; i < cq->tempdirs->used; i++) {
data_string *ds = (data_string *)cq->tempdirs->data[i];
buffer_copy_string_buffer(template, ds->value);
BUFFER_APPEND_SLASH(template);
buffer_copy_buffer(template, ds->value);
buffer_append_slash(template);
buffer_append_string_len(template, CONST_STR_LEN("lighttpd-upload-XXXXXX"));
if (-1 != (c->file.fd = mkstemp(template->ptr))) {
@ -309,7 +295,7 @@ chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
}
}
buffer_copy_string_buffer(c->file.name, template);
buffer_copy_buffer(c->file.name, template);
c->file.length = 0;
chunkqueue_append_chunk(cq, c);
@ -319,82 +305,102 @@ chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
return c;
}
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
while (len > 0) {
chunk *c = src->first;
off_t clen = 0;
off_t chunkqueue_length(chunkqueue *cq) {
off_t len = 0;
chunk *c;
if (NULL == c) break;
for (c = cq->first; c; c = c->next) {
switch (c->type) {
case MEM_CHUNK:
len += c->mem->used ? c->mem->used - 1 : 0;
clen = buffer_string_length(c->mem);
break;
case FILE_CHUNK:
len += c->file.length;
clen = c->file.length;
break;
default:
}
force_assert(clen >= c->offset);
clen -= c->offset;
if (len >= clen) {
/* move complete chunk */
src->first = c->next;
if (c == src->last) src->last = NULL;
chunkqueue_append_chunk(dest, c);
src->bytes_out += clen;
dest->bytes_in += clen;
len -= clen;
continue;
}
/* partial chunk with length "len" */
switch (c->type) {
case MEM_CHUNK:
chunkqueue_append_mem(dest, c->mem->ptr + c->offset, len);
break;
case FILE_CHUNK:
/* tempfile flag is in "last" chunk after the split */
chunkqueue_append_file(dest, c->file.name, c->file.start + c->offset, len);
break;
}
}
return len;
c->offset += len;
src->bytes_out += len;
dest->bytes_in += len;
len = 0;
}
}
off_t chunkqueue_written(chunkqueue *cq) {
off_t chunkqueue_length(chunkqueue *cq) {
off_t len = 0;
chunk *c;
for (c = cq->first; c; c = c->next) {
off_t c_len = 0;
switch (c->type) {
case MEM_CHUNK:
case FILE_CHUNK:
len += c->offset;
c_len = buffer_string_length(c->mem);
break;
default:
case FILE_CHUNK:
c_len = c->file.length;
break;
}
force_assert(c_len >= c->offset);
len += c_len - c->offset;
}
return len;
}
int chunkqueue_is_empty(chunkqueue *cq) {
return cq->first ? 0 : 1;
return NULL == cq->first;
}
int chunkqueue_remove_finished_chunks(chunkqueue *cq) {
void chunkqueue_remove_finished_chunks(chunkqueue *cq) {
chunk *c;
for (c = cq->first; c; c = cq->first) {
int is_finished = 0;
off_t c_len = 0;
switch (c->type) {
case MEM_CHUNK:
if (c->mem->used == 0 || (c->offset == (off_t)c->mem->used - 1)) is_finished = 1;
c_len = buffer_string_length(c->mem);
break;
case FILE_CHUNK:
if (c->offset == c->file.length) is_finished = 1;
break;
default:
c_len = c->file.length;
break;
}
force_assert(c_len >= c->offset);
if (!is_finished) break;
chunk_reset(c);
if (c_len > c->offset) break; /* not finished yet */
cq->first = c->next;
if (c == cq->last) cq->last = NULL;
/* keep at max 4 chunks in the 'unused'-cache */
if (cq->unused_chunks > 4) {
chunk_free(c);
} else {
c->next = cq->unused;
cq->unused = c;
cq->unused_chunks++;
}
chunkqueue_push_unused_chunk(cq, c);
}
return 0;
}

18
src/chunk.h

@ -6,7 +6,7 @@
#include "sys-mmap.h"
typedef struct chunk {
enum { UNUSED_CHUNK, MEM_CHUNK, FILE_CHUNK } type;
enum { MEM_CHUNK, FILE_CHUNK } type;
buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
@ -48,21 +48,21 @@ typedef struct {
} chunkqueue;
chunkqueue *chunkqueue_init(void);
int chunkqueue_set_tempdirs(chunkqueue *c, array *tempdirs);
int chunkqueue_append_file(chunkqueue *c, buffer *fn, off_t offset, off_t len);
int chunkqueue_append_mem(chunkqueue *c, const char *mem, size_t len);
int chunkqueue_append_buffer(chunkqueue *c, buffer *mem);
int chunkqueue_append_buffer_weak(chunkqueue *c, buffer *mem);
int chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem);
void chunkqueue_set_tempdirs(chunkqueue *c, array *tempdirs);
void chunkqueue_append_file(chunkqueue *c, buffer *fn, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_mem(chunkqueue *c, const char *mem, size_t len); /* copies memory */
void chunkqueue_append_buffer(chunkqueue *c, buffer *mem); /* may reset "mem" */
void chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem); /* may reset "mem" */
buffer * chunkqueue_get_append_buffer(chunkqueue *c);
buffer * chunkqueue_get_prepend_buffer(chunkqueue *c);
chunk * chunkqueue_get_append_tempfile(chunkqueue *cq);
int chunkqueue_remove_finished_chunks(chunkqueue *cq);
void chunkqueue_remove_finished_chunks(chunkqueue *cq);
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
off_t chunkqueue_length(chunkqueue *c);
off_t chunkqueue_written(chunkqueue *c);
void chunkqueue_free(chunkqueue *c);
void chunkqueue_reset(chunkqueue *c);

16
src/configfile-glue.c

@ -46,12 +46,12 @@ int config_insert_values_internal(server *srv, array *ca, const config_values_t
if (da->value->data[j]->type == TYPE_STRING) {
data_string *ds = data_string_init();
buffer_copy_string_buffer(ds->value, ((data_string *)(da->value->data[j]))->value);
buffer_copy_buffer(ds->value, ((data_string *)(da->value->data[j]))->value);
if (!da->is_index_key) {
/* the id's were generated automaticly, as we copy now we might have to renumber them
* this is used to prepend server.modules by mod_indexfile as it has to be loaded
* before mod_fastcgi and friends */
buffer_copy_string_buffer(ds->key, ((data_string *)(da->value->data[j]))->key);
buffer_copy_buffer(ds->key, ((data_string *)(da->value->data[j]))->key);
}
array_insert_unique(cv[i].destination, (data_unset *)ds);
@ -73,7 +73,7 @@ int config_insert_values_internal(server *srv, array *ca, const config_values_t
if (du->type == TYPE_STRING) {
data_string *ds = (data_string *)du;
buffer_copy_string_buffer(cv[i].destination, ds->value);
buffer_copy_buffer(cv[i].destination, ds->value);
} else {
log_error_write(srv, __FILE__, __LINE__, "ssss", cv[i].key, "should have been a string like ... = \"...\"");
@ -202,7 +202,7 @@ int config_insert_values_global(server *srv, array *ca, const config_values_t cv
touched = data_string_init();
buffer_copy_string_len(touched->value, CONST_STR_LEN(""));
buffer_copy_string_buffer(touched->key, du->key);
buffer_copy_buffer(touched->key, du->key);
array_insert_unique(srv->config_touched, (data_unset *)touched);
}
@ -285,7 +285,7 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, dat
case COMP_HTTP_HOST: {
char *ck_colon = NULL, *val_colon = NULL;
if (!buffer_is_empty(con->uri.authority)) {
if (!buffer_string_is_empty(con->uri.authority)) {
/*
* append server-port to the HTTP_POST if necessary
@ -301,9 +301,9 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, dat
if (NULL != ck_colon && NULL == val_colon) {
/* condition "host:port" but client send "host" */
buffer_copy_string_buffer(srv->cond_check_buf, l);
buffer_copy_buffer(srv->cond_check_buf, l);
buffer_append_string_len(srv->cond_check_buf, CONST_STR_LEN(":"));
buffer_append_long(srv->cond_check_buf, sock_addr_get_port(&(srv_sock->addr)));
buffer_append_int(srv->cond_check_buf, sock_addr_get_port(&(srv_sock->addr)));
l = srv->cond_check_buf;
} else if (NULL != val_colon && NULL == ck_colon) {
/* condition "host" but client send "host:port" */
@ -315,7 +315,7 @@ static cond_result_t config_check_cond_nocache(server *srv, connection *con, dat
break;
}
#if defined USE_OPENSSL && ! defined OPENSSL_NO_TLSEXT
} else if (!buffer_is_empty(con->tlsext_server_name)) {
} else if (!buffer_string_is_empty(con->tlsext_server_name)) {
l = con->tlsext_server_name;
#endif
} else {

26
src/configfile.c

@ -273,7 +273,7 @@ static int config_insert(server *srv) {
}
}
if (buffer_is_empty(stat_cache_string)) {
if (buffer_string_is_empty(stat_cache_string)) {
srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_SIMPLE;
} else if (buffer_is_equal_string(stat_cache_string, CONST_STR_LEN("simple"))) {
srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_SIMPLE;
@ -323,7 +323,7 @@ int config_setup_connection(server *srv, connection *con) {
PATCH(global_bytes_per_second_cnt);
con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;
buffer_copy_string_buffer(con->server_name, s->server_name);
buffer_copy_buffer(con->server_name, s->server_name);
PATCH(log_request_header);
PATCH(log_response_header);
@ -442,7 +442,7 @@ int config_patch_connection(server *srv, connection *con, comp_key_t comp) {
PATCH(follow_symlink);
#endif
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.name"))) {
buffer_copy_string_buffer(con->server_name, s->server_name);
buffer_copy_buffer(con->server_name, s->server_name);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.tag"))) {
PATCH(server_tag);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("connection.kbytes-per-second"))) {
@ -512,7 +512,7 @@ typedef struct {
#if 0
static int tokenizer_open(server *srv, tokenizer_t *t, buffer *basedir, const char *fn) {
if (buffer_is_empty(basedir) ||
if (buffer_string_is_empty(basedir) ||
(fn[0] == '/' || fn[0] == '\\') ||
(fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {
t->file = buffer_init_string(fn);
@ -934,7 +934,7 @@ static int config_parse(server *srv, config_t *context, tokenizer_t *t) {
lasttoken = buffer_init();
token = buffer_init();
while((1 == (ret = config_tokenizer(srv, t, &token_id, token))) && context->ok) {
buffer_copy_string_buffer(lasttoken, token);
buffer_copy_buffer(lasttoken, token);
configparser(pParser, token_id, token, context);
token = buffer_init();
@ -986,7 +986,7 @@ int config_parse_file(server *srv, config_t *context, const char *fn) {
int ret;
buffer *filename;
if (buffer_is_empty(context->basedir) ||
if (buffer_string_is_empty(context->basedir) ||
(fn[0] == '/' || fn[0] == '\\') ||
(fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {
filename = buffer_init_string(fn);
@ -1057,7 +1057,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
source = buffer_init_string(cmd);
out = buffer_init();
if (!buffer_is_empty(context->basedir)) {
if (!buffer_string_is_empty(context->basedir)) {
chdir(context->basedir->ptr);
}
@ -1173,7 +1173,7 @@ int config_read(server *srv, const char *fn) {
prepends = (data_array *)configparser_merge_data((data_unset *)prepends, (data_unset *)modules);
force_assert(NULL != prepends);
buffer_copy_string_buffer(prepends->key, modules->key);
buffer_copy_buffer(prepends->key, modules->key);
array_replace(srv->config, (data_unset *)prepends);
modules->free((data_unset *)modules);
modules = prepends;
@ -1255,7 +1255,7 @@ int config_set_defaults(server *srv) {
{ FDEVENT_HANDLER_UNSET, NULL }
};
if (!buffer_is_empty(srv->srvconf.changeroot)) {
if (!buffer_string_is_empty(srv->srvconf.changeroot)) {
if (-1 == stat(srv->srvconf.changeroot->ptr, &st1)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.chroot doesn't exist:", srv->srvconf.changeroot);
@ -1268,14 +1268,14 @@ int config_set_defaults(server *srv) {
}
}
if (buffer_is_empty(s->document_root)) {
if (buffer_string_is_empty(s->document_root)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"a default document-root has to be set");
return -1;
}
buffer_copy_string_buffer(srv->tmp_buf, s->document_root);
buffer_copy_buffer(srv->tmp_buf, s->document_root);
buffer_to_lower(srv->tmp_buf);
@ -1288,7 +1288,7 @@ int config_set_defaults(server *srv) {
is_lower = buffer_is_equal(srv->tmp_buf, s->document_root);
/* lower-case existed, check upper-case */
buffer_copy_string_buffer(srv->tmp_buf, s->document_root);
buffer_copy_buffer(srv->tmp_buf, s->document_root);
buffer_to_upper(srv->tmp_buf);
@ -1356,7 +1356,7 @@ int config_set_defaults(server *srv) {
}
if (s->ssl_enabled) {
if (buffer_is_empty(s->ssl_pemfile)) {
if (buffer_string_is_empty(s->ssl_pemfile)) {
/* PEM file is require */
log_error_write(srv, __FILE__, __LINE__, "s",

26
src/configparser.y

@ -61,11 +61,11 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
if (op1->type != op2->type) {
if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
data_string *ds = (data_string *)op1;
buffer_append_long(ds->value, ((data_integer*)op2)->value);
buffer_append_int(ds->value, ((data_integer*)op2)->value);
return op1;
} else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
data_string *ds = data_string_init();
buffer_append_long(ds->value, ((data_integer*)op1)->value);
buffer_append_int(ds->value, ((data_integer*)op1)->value);
buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
op1->free(op1);
return (data_unset *)ds;
@ -145,7 +145,7 @@ metaline ::= EOL.
varline ::= key(A) ASSIGN expression(B). {
if (ctx->ok) {
buffer_copy_string_buffer(B->key, A);
buffer_copy_buffer(B->key, A);
if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
ctx->current->context_ndx,
@ -183,7 +183,7 @@ varline ::= key(A) APPEND expression(B). {
ctx->ok = 0;
}
else {
buffer_copy_string_buffer(du->key, A);
buffer_copy_buffer(du->key, A);
array_replace(vars, du);
}
B->free(B);
@ -193,12 +193,12 @@ varline ::= key(A) APPEND expression(B). {
ctx->ok = 0;
}
else {
buffer_copy_string_buffer(du->key, A);
buffer_copy_buffer(du->key, A);
array_insert_unique(ctx->current->value, du);
}
B->free(B);
} else {
buffer_copy_string_buffer(B->key, A);
buffer_copy_buffer(B->key, A);
array_insert_unique(ctx->current->value, B);
}
buffer_free(A);
@ -262,7 +262,7 @@ value(A) ::= key(B). {
value(A) ::= STRING(B). {
A = (data_unset *)data_string_init();
buffer_copy_string_buffer(((data_string *)(A))->value, B);
buffer_copy_buffer(((data_string *)(A))->value, B);
buffer_free(B);
B = NULL;
}
@ -320,7 +320,7 @@ aelement(A) ::= expression(B). {
B = NULL;
}
aelement(A) ::= stringop(B) ARRAY_ASSIGN expression(C). {
buffer_copy_string_buffer(C->key, B);
buffer_copy_buffer(C->key, B);
buffer_free(B);
B = NULL;
@ -405,7 +405,7 @@ context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expressio
}
b = buffer_init();
buffer_copy_string_buffer(b, ctx->current->key);
buffer_copy_buffer(b, ctx->current->key);
buffer_append_string(b, "/");
buffer_append_string_buffer(b, B);
buffer_append_string_buffer(b, C);
@ -441,9 +441,9 @@ context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expressio
dc = data_config_init();
buffer_copy_string_buffer(dc->key, b);
buffer_copy_string_buffer(dc->op, op);
buffer_copy_string_buffer(dc->comp_key, B);
buffer_copy_buffer(dc->key, b);
buffer_copy_buffer(dc->op, op);
buffer_copy_buffer(dc->comp_key, B);
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\""));
buffer_append_string_buffer(dc->comp_key, C);
buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]"));
@ -546,7 +546,7 @@ stringop(A) ::= expression(B). {
A = buffer_init_buffer(((data_string*)B)->value);
} else if (B->type == TYPE_INTEGER) {
A = buffer_init();
buffer_copy_long(A, ((data_integer *)B)->value);
buffer_copy_int(A, ((data_integer *)B)->value);
} else {
fprintf(stderr, "operand must be string");
ctx->ok = 0;

28
src/connections.c

@ -212,7 +212,7 @@ static int connection_handle_read_ssl(server *srv, connection *con) {
b = chunkqueue_get_append_buffer(con->read_queue);
len = SSL_pending(con->ssl);
if (len < 4*1024) len = 4*1024; /* always alloc >= 4k buffer */
buffer_prepare_copy(b, len + 1);
buffer_prepare_copy(b, len);
/* overwrite everything with 0 */
memset(b->ptr, 0, b->size);
@ -362,7 +362,7 @@ static int connection_handle_read(server *srv, connection *con) {
} else {
if (toread > MAX_READ_LIMIT) toread = MAX_READ_LIMIT;
b = chunkqueue_get_append_buffer(con->read_queue);
buffer_prepare_copy(b, toread + 1);
buffer_prepare_copy(b, toread);
}
read_offset = (b->used == 0) ? 0 : b->used - 1;
@ -473,11 +473,11 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
buffer_reset(con->physical.path);
/* try to send static errorfile */
if (!buffer_is_empty(con->conf.errorfile_prefix)) {
if (!buffer_string_is_empty(con->conf.errorfile_prefix)) {
stat_cache_entry *sce = NULL;
buffer_copy_string_buffer(con->physical.path, con->conf.errorfile_prefix);
buffer_append_long(con->physical.path, con->http_status);
buffer_copy_buffer(con->physical.path, con->conf.errorfile_prefix);
buffer_append_int(con->physical.path, con->http_status);
buffer_append_string_len(con->physical.path, CONST_STR_LEN(".html"));
if (HANDLER_ERROR != stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
@ -504,7 +504,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
" <head>\n"
" <title>"));
buffer_append_long(b, con->http_status);
buffer_append_int(b, con->http_status);
buffer_append_string_len(b, CONST_STR_LEN(" - "));
buffer_append_string(b, get_http_status_name(con->http_status));
@ -513,7 +513,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
" </head>\n"
" <body>\n"
" <h1>"));
buffer_append_long(b, con->http_status);
buffer_append_int(b, con->http_status);
buffer_append_string_len(b, CONST_STR_LEN(" - "));
buffer_append_string(b, get_http_status_name(con->http_status));
@ -554,7 +554,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
/* qlen = 0 is important for Redirects (301, ...) as they MAY have
* a content. Browsers are waiting for a Content otherwise
*/
buffer_copy_off_t(srv->tmp_buf, qlen);
buffer_copy_int(srv->tmp_buf, qlen);
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Length"), CONST_BUF_LEN(srv->tmp_buf));
}
@ -1135,7 +1135,7 @@ found_header_end:
} else {
b = chunkqueue_get_append_buffer(dst_cq);
/* prepare buffer size for remaining POST data; is < 64kb */
buffer_prepare_copy(b, con->request.content_length - dst_cq->bytes_in + 1);
buffer_prepare_copy(b, con->request.content_length - dst_cq->bytes_in);
}
buffer_append_string_len(b, c->mem->ptr + c->offset, toRead);
}
@ -1430,17 +1430,17 @@ int connection_state_machine(server *srv, connection *con) {
/* 404 error-handler */
if (con->in_error_handler == 0 &&
(!buffer_is_empty(con->conf.error_handler) ||
!buffer_is_empty(con->error_handler))) {
(!buffer_string_is_empty(con->conf.error_handler) ||
!buffer_string_is_empty(con->error_handler))) {
/* call error-handler */
con->error_handler_saved_status = con->http_status;
con->http_status = 0;
if (buffer_is_empty(con->error_handler)) {
buffer_copy_string_buffer(con->request.uri, con->conf.error_handler);
if (buffer_string_is_empty(con->error_handler)) {
buffer_copy_buffer(con->request.uri, con->conf.error_handler);
} else {
buffer_copy_string_buffer(con->request.uri, con->error_handler);
buffer_copy_buffer(con->request.uri, con->error_handler);
}
buffer_reset(con->physical.path);

2
src/data_array.c

@ -8,7 +8,7 @@ static data_unset *data_array_copy(const data_unset *s) {
data_array *src = (data_array *)s;
data_array *ds = data_array_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_buffer(ds->key, src->key);
array_free(ds->value);
ds->value = array_init_array(src->value);
ds->is_index_key = src->is_index_key;

4
src/data_config.c

@ -8,8 +8,8 @@ static data_unset *data_config_copy(const data_unset *s) {
data_config *src = (data_config *)s;
data_config *ds = data_config_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->comp_key, src->comp_key);
buffer_copy_buffer(ds->key, src->key);
buffer_copy_buffer(ds->comp_key, src->comp_key);
array_free(ds->value);
ds->value = array_init_array(src->value);
return (data_unset *)ds;

2
src/data_count.c

@ -8,7 +8,7 @@ static data_unset *data_count_copy(const data_unset *s) {
data_count *src = (data_count *)s;
data_count *ds = data_count_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_buffer(ds->key, src->key);
ds->count = src->count;
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;

4
src/data_fastcgi.c

@ -9,8 +9,8 @@ static data_unset *data_fastcgi_copy(const data_unset *s) {
data_fastcgi *src = (data_fastcgi *)s;
data_fastcgi *ds = data_fastcgi_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->host, src->host);
buffer_copy_buffer(ds->key, src->key);
buffer_copy_buffer(ds->host, src->host);
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}

2
src/data_integer.c

@ -8,7 +8,7 @@ static data_unset *data_integer_copy(const data_unset *s) {
data_integer *src = (data_integer *)s;
data_integer *ds = data_integer_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_buffer(ds->key, src->key);
ds->is_index_key = src->is_index_key;
ds->value = src->value;
return (data_unset *)ds;

8
src/data_string.c

@ -9,8 +9,8 @@ static data_unset *data_string_copy(const data_unset *s) {
data_string *src = (data_string *)s;
data_string *ds = data_string_init();
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->value, src->value);
buffer_copy_buffer(ds->key, src->key);
buffer_copy_buffer(ds->value, src->value);
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}
@ -40,7 +40,7 @@ static int data_string_insert_dup(data_unset *dst, data_unset *src) {
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", "));
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_string_buffer(ds_dst->value, ds_src->value);
buffer_copy_buffer(ds_dst->value, ds_src->value);
}
src->free(src);
@ -58,7 +58,7 @@ static int data_response_insert_dup(data_unset *dst, data_unset *src) {
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(": "));
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_string_buffer(ds_dst->value, ds_src->value);
buffer_copy_buffer(ds_dst->value, ds_src->value);
}
src->free(src);

10
src/etag.c

@ -10,7 +10,7 @@
#include <string.h>
int etag_is_equal(buffer *etag, const char *matches) {
if (etag && !buffer_is_empty(etag) && 0 == strcmp(etag->ptr, matches)) return 1;
if (etag && !buffer_string_is_empty(etag) && 0 == strcmp(etag->ptr, matches)) return 1;
return 0;
}
@ -20,17 +20,17 @@ int etag_create(buffer *etag, struct stat *st,etag_flags_t flags) {
buffer_reset(etag);
if (flags & ETAG_USE_INODE) {
buffer_append_off_t(etag, st->st_ino);
buffer_append_int(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_int(etag, st->st_size);
buffer_append_string_len(etag, CONST_STR_LEN("-"));
}
if (flags & ETAG_USE_MTIME) {
buffer_append_long(etag, st->st_mtime);
buffer_append_int(etag, st->st_mtime);
}
return 0;
@ -44,7 +44,7 @@ int etag_mutate(buffer *mut, buffer *etag) {
buffer_reset(mut);
buffer_copy_string_len(mut, CONST_STR_LEN("\""));
buffer_append_off_t(mut, h);
buffer_append_int(mut, h);
buffer_append_string_len(mut, CONST_STR_LEN("\""));
return 0;

6
src/http-header-glue.c

@ -123,7 +123,7 @@ int http_response_redirect_to_directory(server *srv, connection *con) {
o = buffer_init();
buffer_copy_string_buffer(o, con->uri.scheme);
buffer_copy_buffer(o, con->uri.scheme);
buffer_append_string_len(o, CONST_STR_LEN("://"));
if (con->uri.authority->used) {
buffer_append_string_buffer(o, con->uri.authority);
@ -197,13 +197,13 @@ int http_response_redirect_to_directory(server *srv, connection *con) {
}
if (default_port != srv->srvconf.port) {
buffer_append_string_len(o, CONST_STR_LEN(":"));
buffer_append_long(o, srv->srvconf.port);
buffer_append_int(o, srv->srvconf.port);
}
}
}
buffer_append_string_buffer(o, con->uri.path);
buffer_append_string_len(o, CONST_STR_LEN("/"));
if (!buffer_is_empty(con->uri.query)) {
if (!buffer_string_is_empty(con->uri.query)) {
buffer_append_string_len(o, CONST_STR_LEN("?"));
buffer_append_string_buffer(o, con->uri.query);
}

14
src/http_auth.c

@ -172,7 +172,7 @@ static int http_auth_get_password(server *srv, mod_auth_plugin_data *p, buffer *
stream f;
char * f_line;
if (buffer_is_empty(p->conf.auth_htdigest_userfile)) return -1;
if (buffer_string_is_empty(p->conf.auth_htdigest_userfile)) return -1;
if (0 != stream_open(&f, p->conf.auth_htdigest_userfile)) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "opening digest-userfile", p->conf.auth_htdigest_userfile, "failed:", strerror(errno));
@ -253,7 +253,7 @@ static int http_auth_get_password(server *srv, mod_auth_plugin_data *p, buffer *
auth_fn = (p->conf.auth_backend == AUTH_BACKEND_HTPASSWD) ? p->conf.auth_htpasswd_userfile : p->conf.auth_plain_userfile;
if (buffer_is_empty(auth_fn)) return -1;
if (buffer_string_is_empty(auth_fn)) return -1;