fix merging of auto-indexing element, and make autoload modules hack to use array merging

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@616 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.2
Xuefer 2005-08-23 14:35:01 +00:00
parent 9a2e653557
commit f387d89870
12 changed files with 79 additions and 49 deletions

View File

@ -28,7 +28,6 @@ array *array_init_array(array *src) {
a->size = src->size;
a->next_power_of_2 = src->next_power_of_2;
a->unique_ndx = src->unique_ndx;
a->is_array = src->is_array;
a->data = malloc(sizeof(*src->data) * src->size);
for (i = 0; i < src->size; i++) {
@ -167,9 +166,9 @@ int array_insert_unique(array *a, data_unset *str) {
size_t j;
/* generate unique index if neccesary */
if (str->key->used == 0) {
if (str->key->used == 0 || str->is_index_key) {
buffer_copy_long(str->key, a->unique_ndx++);
a->is_array = 1;
str->is_index_key = 1;
}
/* try to find the string */
@ -251,12 +250,6 @@ size_t array_get_max_key_length(array *a) {
return maxlen;
}
static inline int str_int_equal(const char *str, int i) {
char buf[16];
snprintf(buf, sizeof(buf), "%d", i);
return strcmp(str, buf) == 0;
}
int array_print(array *a, int depth) {
size_t i;
size_t maxlen;
@ -267,7 +260,7 @@ int array_print(array *a, int depth) {
}
for (i = 0; i < a->used && oneline; i++) {
data_unset *du = a->data[i];
if (!str_int_equal(du->key->ptr, i)) {
if (!du->is_index_key) {
oneline = 0;
break;
}
@ -299,7 +292,7 @@ int array_print(array *a, int depth) {
for (i = 0; i < a->used; i++) {
data_unset *du = a->data[i];
array_print_indent(depth + 1);
if (!str_int_equal(du->key->ptr, i)) {
if (!du->is_index_key) {
int j;
if (i && (i % 5) == 0) {

View File

@ -14,6 +14,7 @@ typedef enum { TYPE_UNSET, TYPE_STRING, TYPE_COUNT, TYPE_ARRAY, TYPE_INTEGER, TY
#define DATA_UNSET \
data_type_t type; \
buffer *key; \
int is_index_key; /* 1 if key is a array index (autogenerated keys) */ \
struct data_unset *(*copy)(const struct data_unset *src); \
void (* free)(struct data_unset *p); \
void (* reset)(struct data_unset *p); \
@ -33,7 +34,6 @@ typedef struct {
size_t size;
size_t unique_ndx;
int is_array; /* 0 if it is a hash, 1 for array (autogenerated keys) */
size_t next_power_of_2;
int is_weakref; /* data is weakref, don't bother the data */

View File

@ -42,7 +42,7 @@ int config_insert_values_internal(server *srv, array *ca, const config_values_t
data_string *ds = data_string_init();
buffer_copy_string_buffer(ds->value, ((data_string *)(da->value->data[j]))->value);
if (!da->value->is_array) {
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_indexfiles as it has to be loaded
* before mod_fastcgi and friends */

View File

@ -26,7 +26,6 @@ static int config_insert(server *srv) {
size_t i;
int ret = 0;
buffer *stat_cache_string;
data_string *ds;
config_values_t cv[] = {
{ "server.bind", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 0 */
@ -117,13 +116,6 @@ static int config_insert(server *srv) {
assert(srv->config_storage);
/* prepend default modules */
if (NULL == array_get_element(srv->srvconf.modules, "mod_indexfile")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_indexfile");
array_insert_unique(srv->srvconf.modules, (data_unset *)ds);
}
for (i = 0; i < srv->config_context->used; i++) {
specific_config *s;
@ -211,21 +203,6 @@ static int config_insert(server *srv) {
buffer_free(stat_cache_string);
srv->srvconf.modules->unique_ndx = srv->srvconf.modules->used;
/* append default modules */
if (NULL == array_get_element(srv->srvconf.modules, "mod_dirlisting")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_dirlisting");
array_insert_unique(srv->srvconf.modules, (data_unset *)ds);
}
if (NULL == array_get_element(srv->srvconf.modules, "mod_staticfile")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_staticfile");
array_insert_unique(srv->srvconf.modules, (data_unset *)ds);
}
return ret;
}
@ -923,6 +900,7 @@ int config_read(server *srv, const char *fn) {
data_config *dc;
int ret;
char *pos;
data_array *modules;
context_init(srv, &context);
context.all_configs = srv->config_context;
@ -960,16 +938,55 @@ int config_read(server *srv, const char *fn) {
return ret;
}
if (0 != config_insert(srv)) {
return -1;
}
if (NULL != (dc = (data_config *)array_get_element(srv->config_context, "global"))) {
srv->config = dc->value;
} else {
return -1;
}
if (NULL != (modules = (data_array *)array_get_element(srv->config, "server.modules"))) {
data_string *ds;
data_array *prepends;
if (modules->type != TYPE_ARRAY) {
fprintf(stderr, "server.modules must be an array");
return -1;
}
prepends = data_array_init();
/* prepend default modules */
if (NULL == array_get_element(modules->value, "mod_indexfile")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_indexfile");
array_insert_unique(prepends->value, (data_unset *)ds);
}
prepends = (data_array *)configparser_merge_data((data_unset *)prepends, (data_unset *)modules);
buffer_copy_string_buffer(prepends->key, modules->key);
array_replace(srv->config, (data_unset *)prepends);
modules->free((data_unset *)modules);
modules = prepends;
/* append default modules */
if (NULL == array_get_element(modules->value, "mod_dirlisting")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_dirlisting");
array_insert_unique(modules->value, (data_unset *)ds);
}
if (NULL == array_get_element(modules->value, "mod_staticfile")) {
ds = data_string_init();
buffer_copy_string(ds->value, "mod_staticfile");
array_insert_unique(modules->value, (data_unset *)ds);
}
}
if (0 != config_insert(srv)) {
return -1;
}
return 0;
}

View File

@ -19,5 +19,6 @@ void configparserFree(void *p, void (*freeProc)(void*));
void configparser(void *yyp, int yymajor, buffer *yyminor, config_t *ctx);
int config_parse_file(server *srv, config_t *context, const char *fn);
int config_parse_cmd(server *srv, config_t *context, const char *cmd);
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2);
#endif

View File

@ -70,7 +70,7 @@ static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
/* op1 is to be eat/return by this function, op1->key is not cared
op2 is left untouch, unreferenced
*/
data_unset *configparser_merge_data(config_t *ctx, data_unset *op1, const data_unset *op2) {
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
/* type mismatch */
if (op1->type != op2->type) {
if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
@ -85,7 +85,6 @@ data_unset *configparser_merge_data(config_t *ctx, data_unset *op1, const data_u
return (data_unset *)ds;
} else {
fprintf(stderr, "data type mismatch, cannot be merge\n");
ctx->ok = 0;
op1->free(op1);
return NULL;
}
@ -179,13 +178,23 @@ varline ::= key(A) APPEND expression(B). {
if (NULL != (du = array_get_element(vars, A->ptr))) {
/* exists in current block */
du = configparser_merge_data(ctx, du, B);
buffer_copy_string_buffer(du->key, A);
array_replace(vars, du);
du = configparser_merge_data(du, B);
if (NULL == du) {
ctx->ok = 0;
}
else {
buffer_copy_string_buffer(du->key, A);
array_replace(vars, du);
}
} else if (NULL != (du = configparser_get_variable(ctx, A))) {
du = configparser_merge_data(ctx, du, B);
buffer_copy_string_buffer(du->key, A);
array_insert_unique(ctx->current->value, du);
du = configparser_merge_data(du, B);
if (NULL == du) {
ctx->ok = 0;
}
else {
buffer_copy_string_buffer(du->key, A);
array_insert_unique(ctx->current->value, du);
}
} else {
fprintf(stderr, "Undefined config variable in conditional 1 %s: %s\n",
ctx->current->key->ptr, A->ptr);
@ -210,7 +219,10 @@ key(A) ::= LKEY(B). {
}
expression(A) ::= expression(B) PLUS value(C). {
A = configparser_merge_data(ctx, B, C);
A = configparser_merge_data(B, C);
if (NULL == A) {
ctx->ok = 0;
}
B = NULL;
C->free(C);
C = NULL;

View File

@ -11,6 +11,7 @@ static data_unset *data_array_copy(const data_unset *s) {
buffer_copy_string_buffer(ds->key, src->key);
array_free(ds->value);
ds->value = array_init_array(src->value);
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}

View File

@ -10,6 +10,7 @@ static data_unset *data_count_copy(const data_unset *s) {
buffer_copy_string_buffer(ds->key, src->key);
ds->count = src->count;
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}

View File

@ -11,6 +11,7 @@ static data_unset *data_fastcgi_copy(const data_unset *s) {
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->host, src->host);
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}

View File

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

View File

@ -11,6 +11,7 @@ static data_unset *data_string_copy(const data_unset *s) {
buffer_copy_string_buffer(ds->key, src->key);
buffer_copy_string_buffer(ds->value, src->value);
ds->is_index_key = src->is_index_key;
return (data_unset *)ds;
}

View File

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define _XOPEN_SOURCE /* glibc 2.0 */
#define __USE_XOPEN /* glibc 2.3 */
#include <time.h>
#include "base.h"