config parser intial working version; test action in core plugin with more outpot

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent 6467329144
commit b1000d2ca4
  1. 3
      src/config_parser.h
  2. 119
      src/config_parser.rl
  3. 3
      src/lighttpd.c
  4. 4
      src/plugin.c
  5. 20
      src/plugin_core.c

@ -32,15 +32,18 @@ struct config_parser_context_t {
gchar *mark;
gboolean in_setup_block;
gboolean condition_with_key;
comp_operator_t op;
gchar value_op;
GHashTable *action_blocks; /* foo { } */
GHashTable *uservars; /* var.foo */
GQueue *action_list_stack; /* first entry is current action list */
GQueue *option_stack; /* stack of option* */
GQueue *condition_stack; /* stack of condition* */
/* information about currenty parsed file */
gchar *filename;

@ -2,7 +2,7 @@
#include "condition.h"
#include "config_parser.h"
#if 1
#if 0
#define _printf(fmt, ...) g_print(fmt, __VA_ARGS__)
#else
#define _printf(fmt, ...) /* */
@ -380,7 +380,7 @@
if (ctx->in_setup_block) {
/* in setup { } block => set default values for options */
option_free(name);
/* todo name */
}
else if (g_str_has_prefix(name->value.opt_string->str, "var.")) {
/* assignment vor user defined variable, insert into hashtable */
@ -388,23 +388,51 @@
}
else {
/* normal assignment */
a = option_action(srv, name->value.opt_string->str, val);
if (a == NULL)
return FALSE;
al = g_queue_peek_head(ctx->action_list_stack);
g_array_append_val(al->value.list, a);
option_free(name);
}
}
/*
al = g_queue_peek_head(ctx->action_list_stack);
action function_noparam {
option *name;
action *a, *al;
a = action_new_setting(srv, name->value.opt_string->str, val);
name = g_queue_pop_head(ctx->option_stack);
if (a == NULL)
return FALSE;
assert(name->type == OPTION_STRING);
_printf("got function: %s; in line %zd\n", name->value.opt_string->str, ctx->line);
if (g_str_equal(name->value.opt_string->str, "break")) {
}
else if (g_str_equal(name->value.opt_string->str, "__halt")) {
}
else {
if (ctx->in_setup_block) {
/* we are in the setup { } block, call setups and don't append to action list */
if (!call_setup(srv, name->value.opt_string->str, NULL)) {
return FALSE;
}
}
else {
al = g_queue_peek_head(ctx->action_list_stack);
a = create_action(srv, name->value.opt_string->str, NULL);
if (a == NULL)
return FALSE;
g_array_append_val(al->actions, a);
*/
UNUSED(a); UNUSED(al);
g_array_append_val(al->value.list, a);
}
}
}
action function {
action function_param {
/* similar to assignment */
option *val, *name;
action *a, *al;
@ -453,6 +481,8 @@ UNUSED(a); UNUSED(al);
if (a == NULL)
return FALSE;
g_array_append_val(al->value.list, a);
}
}
@ -460,17 +490,68 @@ UNUSED(a); UNUSED(al);
}
action condition_start {
/* stack: value, varname */
option *v, *n;
/* stack: value, varname OR value, key, varname */
option *v, *n, *k;
gchar *str;
condition *cond;
condition_lvalue *lvalue;
v = g_queue_pop_head(ctx->option_stack);
if (ctx->condition_with_key)
k = g_queue_pop_head(ctx->option_stack);
else
k = NULL;
n = g_queue_pop_head(ctx->option_stack);
assert(n->type == OPTION_STRING);
_printf("got condition: %s %s %s in line %zd\n", n->value.opt_string->str, comp_op_to_string(ctx->op), option_type_string(v->type), ctx->line);
_printf("got condition: %s:%s %s %s in line %zd\n", n->value.opt_string->str, ctx->condition_with_key ? k->value.opt_string->str : "", comp_op_to_string(ctx->op), option_type_string(v->type), ctx->line);
/* create condition lvalue */
str = n->value.opt_string->str;
if (g_str_equal(str, "req.path") || g_str_equal(str, "request.path"))
lvalue = condition_lvalue_new(COMP_REQUEST_PATH, NULL);
else {
log_warning(srv, NULL, "unkown lvalue for condition: %s", str);
return FALSE;
}
if (v->type == OPTION_STRING) {
cond = condition_new_string(srv, ctx->op, lvalue, v->value.opt_string);
}
else if (v->type == OPTION_INT)
cond = condition_new_int(srv, ctx->op, lvalue, (gint64) v->value.opt_int);
else {
cond = NULL;
}
if (cond == NULL) {
log_warning(srv, NULL, "could not create condition", "");
return FALSE;
}
g_queue_push_head(ctx->condition_stack, cond);
g_queue_push_head(ctx->action_list_stack, action_new_list());
/* TODO: free stuff */
ctx->condition_with_key = FALSE;
}
action condition_end {
condition *cond;
action *a, *al;
cond = g_queue_pop_head(ctx->condition_stack);
al = g_queue_pop_head(ctx->action_list_stack);
a = action_new_condition(cond, al);
al = g_queue_peek_head(ctx->action_list_stack);
g_array_append_val(al->value.list, a);
}
action condition_key {
ctx->condition_with_key = TRUE;
}
action action_block_start {
@ -553,9 +634,11 @@ UNUSED(a); UNUSED(al);
# statements
assignment = ( varname ws* '=' ws* value_statement ';' ) %assignment;
function = ( varname ws+ value ';' ) %function;
condition = ( varname ws* operator ws* value noise* block >condition_start ) %condition_end;
action_block = ( varname ws* block >action_block_start ) %action_block_end;
function_noparam = ( varname ';' ) %function_noparam;
function_param = ( varname ws+ value_statement ';') %function_param;
function = ( function_noparam | function_param );
condition = ( varname ('[' string >mark ']' %condition_key)? ws* operator ws* value_statement noise* block >condition_start ) %condition_end;
action_block = ( varname noise* block >action_block_start ) %action_block_end;
statement = ( assignment | function | condition | action_block );
@ -638,6 +721,7 @@ config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack
/* inherit old stacks */
ctx->action_list_stack = ((config_parser_context_t*) ctx_stack->data)->action_list_stack;
ctx->option_stack = ((config_parser_context_t*) ctx_stack->data)->option_stack;
ctx->condition_stack = ((config_parser_context_t*) ctx_stack->data)->condition_stack;
ctx->action_blocks = ((config_parser_context_t*) ctx_stack->data)->action_blocks;
ctx->uservars = ((config_parser_context_t*) ctx_stack->data)->uservars;
@ -648,6 +732,7 @@ config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack
ctx->action_list_stack = g_queue_new();
ctx->option_stack = g_queue_new();
ctx->condition_stack = g_queue_new();
}
return ctx;

@ -75,7 +75,6 @@ int main(int argc, char *argv[]) {
log_thread_start(srv);
g_atomic_int_set(&srv->exiting, TRUE);
log_thread_wakeup(srv);
g_thread_join(srv->log_thread);
server_free(srv);
return 1;
}
@ -90,7 +89,7 @@ int main(int argc, char *argv[]) {
g_print("parsed config file in %lu seconds, %lu milliseconds, %lu microseconds\n", s, millis, micros);
g_print("option_stack: %u action_list_stack: %u (should be 0:1)\n", g_queue_get_length(ctx->option_stack), g_queue_get_length(ctx->action_list_stack));
config_parser_finish(srv, ctx_stack);
/* TODO config_parser_finish(srv, ctx_stack); */
}
else {
#ifdef HAVE_LUA_H

@ -174,8 +174,8 @@ gboolean parse_option(server *srv, const char *name, option *opt, option_set *ma
}
if (sopt->type != opt->type) {
ERROR(srv, "Unexpected option type '%s', expected '%s'",
option_type_string(opt->type), option_type_string(sopt->type));
ERROR(srv, "Unexpected option type '%s', expected '%s' for option %s",
option_type_string(opt->type), option_type_string(sopt->type), name);
return FALSE;
}

@ -173,12 +173,30 @@ static action* core_static(server *srv, plugin* p, option *opt) {
}
static action_result core_handle_test(server *srv, connection *con, gpointer param) {
GHashTableIter iter;
gpointer k, v;
GList *hv;
UNUSED(param);
if (con->state != CON_STATE_HANDLE_REQUEST_HEADER) return ACTION_GO_ON;
con->response.http_status = 200;
chunkqueue_append_mem(con->out, CONST_STR_LEN("path: "));
chunkqueue_append_mem(con->out, GSTR_LEN(con->request.uri.path));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\nquery: "));
chunkqueue_append_mem(con->out, GSTR_LEN(con->request.uri.query));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n\r\n--- Headers ---\r\n"));
g_hash_table_iter_init(&iter, con->request.headers->table);
while (g_hash_table_iter_next(&iter, &k, &v)) {
hv = g_queue_peek_head_link(&((http_header*)v)->values);
while (hv != NULL) {
chunkqueue_append_mem(con->out, GSTR_LEN(((http_header*)v)->key));
chunkqueue_append_mem(con->out, CONST_STR_LEN(": "));
chunkqueue_append_mem(con->out, GSTR_LEN((GString*)hv->data));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n"));
hv = hv->next;
}
}
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n"));
connection_handle_direct(srv, con);
@ -251,7 +269,7 @@ static gboolean core_listen(server *srv, plugin* p, option *opt) {
}
static const plugin_option options[] = {
{ "debug.log-request-handling", OPTION_BOOLEAN, NULL, NULL},
{ "debug.log_request_handling", OPTION_BOOLEAN, NULL, NULL},
{ "log.level", OPTION_STRING, NULL, NULL },
{ "static-file.exclude", OPTION_LIST, NULL, NULL },

Loading…
Cancel
Save