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-c4023f1b3aa9svn/tags/lighttpd-1.4.2
parent
bcbafe63db
commit
8b07d57d66
21
src/array.c
21
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;
|
||||
}
|
||||
|
|
13
src/array.h
13
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 */
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 : "");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue