summaryrefslogtreecommitdiff
path: root/src/stat_cache.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2015-02-08 12:37:10 +0000
committerStefan Bühler <stbuehler@web.de>2015-02-08 12:37:10 +0000
commit6afad87d2ed66a48cda2a7c01dbcc59023774b73 (patch)
tree9b371e94cf911630c5794f5b4ff6e3edd6439a3b /src/stat_cache.c
parent3521be8b8599ae2cc12361c8f600fc58a473de91 (diff)
downloadlighttpd1.4-6afad87d2ed66a48cda2a7c01dbcc59023774b73.tar.gz
lighttpd1.4-6afad87d2ed66a48cda2a7c01dbcc59023774b73.zip
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
Diffstat (limited to 'src/stat_cache.c')
-rw-r--r--src/stat_cache.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/stat_cache.c b/src/stat_cache.c
index 9007325c..b5aa9ce5 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -221,7 +221,7 @@ static int stat_cache_attr_get(buffer *buf, char *name) {
attrlen = 1024;
buffer_prepare_copy(buf, attrlen);
- attrlen--;
+ attrlen = buf->size - 1;
if(0 == (ret = attr_get(name, "Content-Type", buf->ptr, &attrlen, 0))) {
buf->used = attrlen + 1;
buf->ptr[attrlen] = '\0';
@@ -234,7 +234,7 @@ static int stat_cache_attr_get(buffer *buf, char *name) {
buffer_prepare_copy(buf, attrlen);
- if (-1 != (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, "Content-Type", buf->ptr, attrlen-1))) {
+ if (-1 != (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, "Content-Type", buf->ptr, buf->size - 1))) {
buf->used = attrlen + 1;
buf->ptr[attrlen] = '\0';
return 0;
@@ -294,7 +294,7 @@ handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) {
for (j = 0; j < 2; j++) {
buffer_copy_string(sc->hash_key, fe.filename);
- buffer_append_long(sc->hash_key, j);
+ buffer_append_int(sc->hash_key, j);
ndx = hashme(sc->hash_key);
@@ -331,7 +331,7 @@ handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) {
static int buffer_copy_dirname(buffer *dst, buffer *file) {
size_t i;
- if (buffer_is_empty(file)) return -1;
+ if (buffer_string_is_empty(file)) return -1;
for (i = file->used - 1; i+1 > 0; i--) {
if (file->ptr[i] == '/') {
@@ -394,8 +394,8 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
sc = srv->stat_cache;
- buffer_copy_string_buffer(sc->hash_key, name);
- buffer_append_long(sc->hash_key, con->conf.follow_symlink);
+ buffer_copy_buffer(sc->hash_key, name);
+ buffer_append_int(sc->hash_key, con->conf.follow_symlink);
file_ndx = hashme(sc->hash_key);
sc->files = splaytree_splay(sc->files, file_ndx);
@@ -460,8 +460,8 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
return HANDLER_ERROR;
}
- buffer_copy_string_buffer(sc->hash_key, sc->dir_name);
- buffer_append_long(sc->hash_key, con->conf.follow_symlink);
+ buffer_copy_buffer(sc->hash_key, sc->dir_name);
+ buffer_append_int(sc->hash_key, con->conf.follow_symlink);
dir_ndx = hashme(sc->hash_key);
@@ -518,7 +518,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
#endif
sce = stat_cache_entry_init();
- buffer_copy_string_buffer(sce->name, name);
+ buffer_copy_buffer(sce->name, name);
sc->files = splaytree_insert(sc->files, file_ndx, sce);
#ifdef DEBUG_STAT_CACHE
@@ -577,7 +577,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
char *s_cur;
dname = buffer_init();
- buffer_copy_string_buffer(dname, name);
+ buffer_copy_buffer(dname, name);
while ((s_cur = strrchr(dname->ptr,'/'))) {
*s_cur = '\0';
@@ -615,7 +615,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
}
#endif
/* xattr did not set a content-type. ask the config */
- if (buffer_is_empty(sce->content_type)) {
+ if (buffer_string_is_empty(sce->content_type)) {
for (k = 0; k < con->conf.mimetypes->used; k++) {
data_string *ds = (data_string *)con->conf.mimetypes->data[k];
buffer *type = ds->key;
@@ -626,7 +626,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
if (type->used > name->used) continue;
if (0 == strncasecmp(name->ptr + name->used - type->used, type->ptr, type->used - 1)) {
- buffer_copy_string_buffer(sce->content_type, ds->value);
+ buffer_copy_buffer(sce->content_type, ds->value);
break;
}
}
@@ -642,7 +642,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
if (!dir_node) {
fam_dir = fam_dir_entry_init();
- buffer_copy_string_buffer(fam_dir->name, sc->dir_name);
+ buffer_copy_buffer(fam_dir->name, sc->dir_name);
fam_dir->version = 1;