merged from rev 48

personal/stbuehler/wip
Thomas Porzelt 15 years ago
commit 9ed64ee1fc

@ -13,6 +13,21 @@ struct action_stack_element {
action *action_new_setting(server *srv, GString *name, option *value) {
option_set setting;
if (!parse_option(srv, name->str, value, &setting)) {
return NULL;
}
action *a = g_slice_new(action);
a->refcount = 1;
a->type = ACTION_TSETTING;
a->value.setting = setting;
return a;
}
void action_release(action *a) {
assert(a->refcount > 0);
if (!(--a->refcount)) {
@ -150,19 +165,3 @@ action_result action_execute(server *srv, connection *con) {
}
return ACTION_GO_ON;
}
action *action_new_setting(server *srv, GString *name, option *value) {
gsize ndx;
if (!option_get_index(srv, name, &ndx))
ERROR("unknown setting: \"%s\"", name->str);
action *a = g_slice_new(action);
a->refcount = 1;
a->type = ACTION_TSETTING;
return a;
}

@ -46,16 +46,10 @@ static condition* cond_new_string(comp_operator_t op, comp_key_t comp, GString *
case CONFIG_COND_NOMATCH: /** !~ */
#ifdef HAVE_PCRE_H
/* TODO */
ERROR("Regular expressions not supported for now in condition: %s %s '%s'",
condition_op_to_string(op), comp_key_to_string(comp),
str);
condition_free(c);
return NULL;
break;
#else
ERROR("Regular expressions not supported in condition: %s %s '%s'",
condition_op_to_string(op), comp_key_to_string(comp),
str->str);
condition_free(c);
return NULL;
#endif
@ -63,9 +57,6 @@ static condition* cond_new_string(comp_operator_t op, comp_key_t comp, GString *
case CONFIG_COND_GE: /** >= */
case CONFIG_COND_LT: /** < */
case CONFIG_COND_LE: /** <= */
ERROR("Cannot compare with strings in condition: %s %s '%s'",
condition_op_to_string(op), comp_key_to_string(comp),
str->str);
condition_free(c);
return NULL;
}
@ -113,7 +104,13 @@ condition* condition_new_string(server *srv, comp_operator_t op, comp_key_t comp
return c;
}
c = condition_new_from_string(op, comp, str);
if (NULL == (c = condition_new_from_string(op, comp, str))) {
g_string_free(key, TRUE);
ERROR(srv, "Condition creation failed: %s %s '%s' (perhaps you compiled without pcre?)",
comp_key_to_string(comp), comp_op_to_string(op),
str->str);
return NULL;
}
condition_cache_insert(srv, key, c);
return c;
}
@ -158,7 +155,7 @@ void condition_release(condition* c) {
}
}
const char* condition_op_to_string(comp_operator_t op) {
const char* comp_op_to_string(comp_operator_t op) {
switch (op) {
case CONFIG_COND_EQ: return "==";
case CONFIG_COND_GE: return ">=";

@ -93,7 +93,7 @@ LI_API condition* condition_new_int_uncached(server *srv, comp_operator_t op, co
LI_API void condition_release(condition* c);
LI_API const char* condition_op_to_string(comp_operator_t op);
LI_API const char* comp_op_to_string(comp_operator_t op);
LI_API const char* comp_key_to_string(comp_key_t comp);

@ -37,7 +37,7 @@ struct config_parser_data_t {
/* current value */
enum { CONFP_BOOL, CONFP_INT, CONFP_STR, CONFP_LIST, CONFP_HASH } val_type;
GString *val_str;
gint64 val_int;
gint val_int;
gboolean val_bool;
/* operator */

@ -58,7 +58,7 @@
for (c=cpd->mark; c<fpc; c++)
cpd->val_int = cpd->val_int * 10 + *c - 48;
cpd->val_type = CONFP_INT;
_printf("got integer: %zd in line %zd of %s\n", cpd->val_int, cpd->line, cpd->filename);
_printf("got integer: %d in line %zd of %s\n", cpd->val_int, cpd->line, cpd->filename);
}
action comment { _printf("got comment in line %zd of %s\n", cpd->line-1, cpd->filename); }

@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
if (test_config)
return 0;
TRACE("%s", "Test!");
TRACE(srv, "%s", "Test!");
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");

@ -14,15 +14,15 @@ LI_API const char *remove_path(const char *path);
#endif
#define ERROR(fmt, ...) \
log_write(NULL, NULL, "%s.%d: (error) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define ERROR(srv, fmt, ...) \
log_write(srv, NULL, "%s.%d: (error) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define TRACE(fmt, ...) \
log_write(NULL, NULL, "%s.%d: (trace) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define TRACE(srv, fmt, ...) \
log_write(srv, NULL, "%s.%d: (trace) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__)
#define SEGFAULT(fmt, ...) \
#define SEGFAULT(srv, fmt, ...) \
do { \
log_write(NULL, NULL, "%s.%d: (crashing) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
log_write(srv, NULL, "%s.%d: (crashing) "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \
/* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\
abort();\
} while(0)

@ -120,17 +120,3 @@ gpointer option_extract_value(option *opt) {
g_slice_free(option, opt);
return val;
}
gboolean option_get_index(server *srv, GString *name, gsize *ndx)
{
gpointer ptr;
ptr = g_hash_table_lookup(srv->options, (gconstpointer) name);
if (ptr == NULL)
return FALSE;
*ndx = 0;
return TRUE;
}

@ -22,7 +22,7 @@ struct option {
option_type type;
union {
gboolean opt_bool;
gint64 opt_int;
gint opt_int;
GString *opt_string;
/* array of option */
GArray *opt_list;
@ -53,6 +53,4 @@ LI_API void option_list_free(GArray *optlist);
/* Extract value from option, destroy option */
LI_API gpointer option_extract_value(option *opt);
gboolean option_get_index(server *srv, GString *name, gsize *ndx);
#endif

@ -12,7 +12,7 @@ static int lua_fixindex(lua_State *L, int ndx) {
return ndx;
}
static option* option_from_lua_table(lua_State *L, int ndx) {
static option* option_from_lua_table(server *srv, lua_State *L, int ndx) {
option *opt = NULL, *sub_option;
GArray *list = NULL;
GHashTable *hash = NULL;
@ -31,7 +31,7 @@ static option* option_from_lua_table(lua_State *L, int ndx) {
}
ikey = lua_tointeger(L, -2);
if (ikey < 0) {
ERROR("Invalid key < 0: %i - skipping entry", ikey);
ERROR(srv, "Invalid key < 0: %i - skipping entry", ikey);
lua_pop(L, 1);
continue;
}
@ -51,7 +51,7 @@ static option* option_from_lua_table(lua_State *L, int ndx) {
}
skey = lua_togstring(L, -2);
if (g_hash_table_lookup(hash, skey)) {
ERROR("Key already exists in hash: '%s' - skipping entry", skey->str);
ERROR(srv, "Key already exists in hash: '%s' - skipping entry", skey->str);
lua_pop(L, 1);
continue;
}
@ -64,7 +64,7 @@ static option* option_from_lua_table(lua_State *L, int ndx) {
break;
default:
ERROR("Unexpted key type in table: %s (%i) - skipping entry", lua_typename(L, -1), lua_type(L, -1));
ERROR(srv, "Unexpted key type in table: %s (%i) - skipping entry", lua_typename(L, -1), lua_type(L, -1));
lua_pop(L, 1);
break;
}
@ -73,13 +73,13 @@ static option* option_from_lua_table(lua_State *L, int ndx) {
return opt;
mixerror:
ERROR("%s", "Cannot mix list with hash; skipping remaining part of table");
ERROR(srv, "%s", "Cannot mix list with hash; skipping remaining part of table");
lua_pop(L, 2);
return opt;
}
option* option_from_lua(lua_State *L) {
option* option_from_lua(server *srv, lua_State *L) {
option *opt;
switch (lua_type(L, -1)) {
@ -103,7 +103,7 @@ option* option_from_lua(lua_State *L) {
return opt;
case LUA_TTABLE:
opt = option_from_lua_table(L, -1);
opt = option_from_lua_table(srv, L, -1);
lua_pop(L, 1);
return opt;
@ -113,7 +113,7 @@ option* option_from_lua(lua_State *L) {
case LUA_TTHREAD:
case LUA_TNONE:
default:
ERROR("Unexpected lua type: %s (%i)", lua_typename(L, -1), lua_type(L, -1));
ERROR(srv, "Unexpected lua type: %s (%i)", lua_typename(L, -1), lua_type(L, -1));
lua_pop(L, 1);
return NULL;
}

@ -9,7 +9,7 @@
* and pops the value
* returns NULL if it couldn't convert the value (still pops it)
*/
LI_API option* option_from_lua(lua_State *L);
LI_API option* option_from_lua(server *srv, lua_State *L);
LI_API GString* lua_togstring(lua_State *L, int ndx);

@ -13,12 +13,12 @@ gboolean parse_option(server *srv, const char *key, option *opt, option_set *mar
sopt = find_option(srv, key);
if (!sopt) {
ERROR("Unknown option '%s'", key);
ERROR(srv, "Unknown option '%s'", key);
return FALSE;
}
if (sopt->type != opt->type) {
ERROR("Unexpected option type '%s', expected '%s'",
ERROR(srv, "Unexpected option type '%s', expected '%s'",
option_type_string(opt->type), option_type_string(sopt->type));
return FALSE;
}

@ -25,7 +25,7 @@ int request_test() {
res = http_request_parse(NULL, NULL, &ctx);
if (res != HANDLER_GO_ON) {
ERROR("Parser return %i", res);
fprintf(stderr, "Parser return %i", res);
return -1;
}

Loading…
Cancel
Save