diff options
author | Jan Kneschke <jan@kneschke.de> | 2005-08-08 17:25:06 +0000 |
---|---|---|
committer | Jan Kneschke <jan@kneschke.de> | 2005-08-08 17:25:06 +0000 |
commit | 8b07d57d66b28931a99ae6358a1644ab171cd7f1 (patch) | |
tree | 328e7bb7772e5197ea1926b13658937b3f0d0fff /src | |
parent | bcbafe63dbdbaadc2936636861b8d535ea89f164 (diff) | |
download | lighttpd-git-8b07d57d66b28931a99ae6358a1644ab171cd7f1.tar.gz |
added weak-ref and nicer print() (merged [332], [336])
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@528 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src')
-rw-r--r-- | src/array.c | 21 | ||||
-rw-r--r-- | src/array.h | 13 | ||||
-rw-r--r-- | src/data_array.c | 7 | ||||
-rw-r--r-- | src/data_config.c | 40 | ||||
-rw-r--r-- | src/data_count.c | 4 | ||||
-rw-r--r-- | src/data_fastcgi.c | 4 | ||||
-rw-r--r-- | src/data_integer.c | 4 | ||||
-rw-r--r-- | src/data_string.c | 4 |
8 files changed, 73 insertions, 24 deletions
diff --git a/src/array.c b/src/array.c index ac6737ed..035f7bad 100644 --- a/src/array.c +++ b/src/array.c @@ -44,8 +44,10 @@ void array_free(array *a) { size_t i; if (!a) return; - for (i = 0; i < a->size; i++) { - if (a->data[i]) a->data[i]->free(a->data[i]); + if (!a->is_weakref) { + for (i = 0; i < a->size; i++) { + if (a->data[i]) a->data[i]->free(a->data[i]); + } } if (a->data) free(a->data); @@ -58,8 +60,10 @@ void array_reset(array *a) { size_t i; if (!a) return; - for (i = 0; i < a->used; i++) { - a->data[i]->reset(a->data[i]); + if (!a->is_weakref) { + for (i = 0; i < a->used; i++) { + a->data[i]->reset(a->data[i]); + } } a->used = 0; @@ -227,19 +231,22 @@ int array_insert_unique(array *a, data_unset *str) { void array_print_indent(int depth) { int i; for (i = 0; i < depth; i ++) { - fprintf(stderr, " "); + fprintf(stderr, " "); } } int array_print(array *a, int depth) { size_t i; + fprintf(stderr, "{\n"); for (i = 0; i < a->used; i++) { - array_print_indent(depth); - fprintf(stderr, "%d: ", i); + array_print_indent(depth + 1); + fprintf(stderr, "%d:%s: ", i, a->data[i]->key->ptr); a->data[i]->print(a->data[i], depth + 1); fprintf(stderr, "\n"); } + array_print_indent(depth); + fprintf(stderr, "}"); return 0; } diff --git a/src/array.h b/src/array.h index c69be3bb..12c18c61 100644 --- a/src/array.h +++ b/src/array.h @@ -35,6 +35,7 @@ typedef struct { size_t unique_ndx; size_t next_power_of_2; + int is_weakref; /* data is weakref, don't bother the data */ } array; typedef struct { @@ -65,8 +66,15 @@ data_array *data_array_init(void); typedef enum { CONFIG_COND_UNSET, CONFIG_COND_EQ, CONFIG_COND_MATCH, CONFIG_COND_NE, CONFIG_COND_NOMATCH } config_cond_t; typedef enum { COND_RESULT_FALSE, COND_RESULT_TRUE, COND_RESULT_UNSET } cond_result_t; +#define PATCHES NULL, "SERVERsocket", "HTTPurl", "HTTPhost", "HTTPreferer", "HTTPuseragent", "HTTPcookie", "HTTPremoteip" +typedef enum { + COMP_UNSET, + COMP_SERVER_SOCKET, COMP_HTTP_URL, COMP_HTTP_HOST, COMP_HTTP_REFERER, COMP_HTTP_USERAGENT, COMP_HTTP_COOKIE, COMP_HTTP_REMOTEIP +} comp_key_t; + /* $HTTP["host"] == "incremental.home.kneschke.de" { ... } - * comp_key cond string/regex + * for print: comp_key op string + * for compare: comp cond string/regex */ typedef struct _data_config data_config; @@ -76,8 +84,11 @@ struct _data_config { array *value; buffer *comp_key; + comp_key_t comp; config_cond_t cond; + buffer *op; + int context_ndx; /* more or less like an id */ array *childs; /* nested */ diff --git a/src/data_array.c b/src/data_array.c index 734efd1c..51d09cb9 100644 --- a/src/data_array.c +++ b/src/data_array.c @@ -42,11 +42,8 @@ static int data_array_insert_dup(data_unset *dst, data_unset *src) { static void data_array_print(const data_unset *d, int depth) { data_array *ds = (data_array *)d; - array_print_indent(depth); - fprintf(stderr, "{%s:\n", ds->key->ptr); - array_print(ds->value, depth + 1); - array_print_indent(depth); - fprintf(stderr, "}"); + fprintf(stderr, "array "); + array_print(ds->value, depth); } data_array *data_array_init(void) { diff --git a/src/data_config.c b/src/data_config.c index fca37666..90cdd367 100644 --- a/src/data_config.c +++ b/src/data_config.c @@ -19,9 +19,11 @@ static void data_config_free(data_unset *d) { data_config *ds = (data_config *)d; buffer_free(ds->key); + buffer_free(ds->op); buffer_free(ds->comp_key); array_free(ds->value); + array_free(ds->childs); if (ds->string) buffer_free(ds->string); #ifdef HAVE_PCRE_H @@ -51,14 +53,43 @@ static int data_config_insert_dup(data_unset *dst, data_unset *src) { static void data_config_print(const data_unset *d, int depth) { data_config *ds = (data_config *)d; + size_t i; - array_print_indent(depth); - fprintf(stderr, "{%s:\n", ds->key->ptr); + if (0 == ds->context_ndx) { + fprintf(stderr, "config {\n"); + } + else { + fprintf(stderr, "$%s %s \"%s\" {\n", + ds->comp_key->ptr, ds->op->ptr, ds->string->ptr); + } + array_print_indent(depth + 1); + fprintf(stderr, "context_ndx: %d\n", ds->context_ndx); + array_print_indent(depth + 1); + fprintf(stderr, "context: "); array_print(ds->value, depth + 1); + fprintf(stderr, "\n"); + + if (ds->childs) { + for (i = 0; i < ds->childs->used; i ++) { + data_unset *du = ds->childs->data[i]; + + fprintf(stderr, "\n"); + array_print_indent(depth + 1); + du->print(du, depth + 1); + fprintf(stderr, "\n"); + } + } + array_print_indent(depth); fprintf(stderr, "}"); -} + if (ds->next) { + fprintf(stderr, "\n"); + array_print_indent(depth); + fprintf(stderr, "else "); + ds->next->print((data_unset *)ds->next, depth); + } +} data_config *data_config_init(void) { data_config *ds; @@ -66,8 +97,11 @@ data_config *data_config_init(void) { ds = calloc(1, sizeof(*ds)); ds->key = buffer_init(); + ds->op = buffer_init(); ds->comp_key = buffer_init(); ds->value = array_init(); + ds->childs = array_init(); + ds->childs->is_weakref = 1; ds->copy = data_config_copy; ds->free = data_config_free; diff --git a/src/data_count.c b/src/data_count.c index 154a3e6c..d727a106 100644 --- a/src/data_count.c +++ b/src/data_count.c @@ -42,9 +42,9 @@ static int data_count_insert_dup(data_unset *dst, data_unset *src) { static void data_count_print(const data_unset *d, int depth) { data_count *ds = (data_count *)d; + UNUSED(depth); - array_print_indent(depth); - printf("{%s: %d}", ds->key->ptr, ds->count); + fprintf(stderr, "count(%d)", ds->count); } diff --git a/src/data_fastcgi.c b/src/data_fastcgi.c index 757bee9a..da0b8435 100644 --- a/src/data_fastcgi.c +++ b/src/data_fastcgi.c @@ -41,9 +41,9 @@ static int data_fastcgi_insert_dup(data_unset *dst, data_unset *src) { static void data_fastcgi_print(const data_unset *d, int depth) { data_fastcgi *ds = (data_fastcgi *)d; + UNUSED(depth); - array_print_indent(depth); - printf("{%s: %s}", ds->key->ptr, ds->host->ptr); + fprintf(stderr, "fastcgi(%s)", ds->host->ptr); } diff --git a/src/data_integer.c b/src/data_integer.c index fa949fae..48e8c9b9 100644 --- a/src/data_integer.c +++ b/src/data_integer.c @@ -39,9 +39,9 @@ static int data_integer_insert_dup(data_unset *dst, data_unset *src) { static void data_integer_print(const data_unset *d, int depth) { data_integer *ds = (data_integer *)d; + UNUSED(depth); - array_print_indent(depth); - printf("{%s: %d}", ds->key->ptr, ds->value); + fprintf(stderr, "%d", ds->value); } diff --git a/src/data_string.c b/src/data_string.c index 1c185f18..37f108d1 100644 --- a/src/data_string.c +++ b/src/data_string.c @@ -68,9 +68,9 @@ static int data_response_insert_dup(data_unset *dst, data_unset *src) { static void data_string_print(const data_unset *d, int depth) { data_string *ds = (data_string *)d; + UNUSED(depth); - array_print_indent(depth); - fprintf(stderr, "{%s: %s}", ds->key->ptr, ds->value->used ? ds->value->ptr : ""); + fprintf(stderr, "\"%s\"", ds->value->used ? ds->value->ptr : ""); } |