config_cond_t renamed to comp_operator_t
parent
33dd2691c1
commit
781dfd07cf
|
@ -4,10 +4,10 @@
|
|||
|
||||
static condition* condition_find_cached(server *srv, GString *key);
|
||||
static void condition_cache_insert(server *srv, GString *key, condition *c);
|
||||
static condition* condition_new(config_cond_t cond, comp_key_t comp);
|
||||
static condition* cond_new_string(config_cond_t cond, comp_key_t comp, GString *str);
|
||||
static condition* cond_new_socket(config_cond_t cond, comp_key_t comp, GString *str);
|
||||
static condition* condition_new_from_string(config_cond_t cond, comp_key_t comp, GString *str);
|
||||
static condition* condition_new(comp_operator_t op, comp_key_t comp);
|
||||
static condition* cond_new_string(comp_operator_t op, comp_key_t comp, GString *str);
|
||||
static condition* cond_new_socket(comp_operator_t op, comp_key_t comp, GString *str);
|
||||
static condition* condition_new_from_string(comp_operator_t op, comp_key_t comp, GString *str);
|
||||
static void condition_free(condition *c);
|
||||
|
||||
static gboolean condition_check_eval(server *srv, connection *con, condition *cond);
|
||||
|
@ -26,18 +26,18 @@ static void condition_cache_insert(server *srv, GString *key, condition *c) {
|
|||
g_string_free(key, TRUE);
|
||||
}
|
||||
|
||||
static condition* condition_new(config_cond_t cond, comp_key_t comp) {
|
||||
static condition* condition_new(comp_operator_t op, comp_key_t comp) {
|
||||
condition *c = g_slice_new0(condition);
|
||||
c->refcount = 1;
|
||||
c->cache_index = -1;
|
||||
c->cond = cond;
|
||||
c->op = op;
|
||||
c->comp = comp;
|
||||
return c;
|
||||
}
|
||||
|
||||
static condition* cond_new_string(config_cond_t cond, comp_key_t comp, GString *str) {
|
||||
condition *c = condition_new(cond, comp);
|
||||
switch (c->cond) {
|
||||
static condition* cond_new_string(comp_operator_t op, comp_key_t comp, GString *str) {
|
||||
condition *c = condition_new(op, comp);
|
||||
switch (op) {
|
||||
case CONFIG_COND_EQ: /** == */
|
||||
case CONFIG_COND_NE: /** != */
|
||||
c->value.string = str;
|
||||
|
@ -47,14 +47,14 @@ static condition* cond_new_string(config_cond_t cond, comp_key_t comp, GString *
|
|||
#ifdef HAVE_PCRE_H
|
||||
/* TODO */
|
||||
ERROR("Regular expressions not supported for now in condition: %s %s '%s'",
|
||||
config_cond_to_string(cond), comp_key_to_string(comp),
|
||||
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'",
|
||||
config_cond_to_string(cond), comp_key_to_string(comp),
|
||||
condition_op_to_string(op), comp_key_to_string(comp),
|
||||
str->str);
|
||||
condition_free(c);
|
||||
return NULL;
|
||||
|
@ -64,7 +64,7 @@ static condition* cond_new_string(config_cond_t cond, comp_key_t comp, GString *
|
|||
case CONFIG_COND_LT: /** < */
|
||||
case CONFIG_COND_LE: /** <= */
|
||||
ERROR("Cannot compare with strings in condition: %s %s '%s'",
|
||||
config_cond_to_string(cond), comp_key_to_string(comp),
|
||||
condition_op_to_string(op), comp_key_to_string(comp),
|
||||
str->str);
|
||||
condition_free(c);
|
||||
return NULL;
|
||||
|
@ -73,16 +73,16 @@ static condition* cond_new_string(config_cond_t cond, comp_key_t comp, GString *
|
|||
return c;
|
||||
}
|
||||
|
||||
static condition* cond_new_socket(config_cond_t cond, comp_key_t comp, GString *str) {
|
||||
return cond_new_string(cond, comp, str);
|
||||
static condition* cond_new_socket(comp_operator_t op, comp_key_t comp, GString *str) {
|
||||
return cond_new_string(op, comp, str);
|
||||
/* TODO: parse str as socket addr */
|
||||
}
|
||||
|
||||
static condition* condition_new_from_string(config_cond_t cond, comp_key_t comp, GString *str) {
|
||||
static condition* condition_new_from_string(comp_operator_t op, comp_key_t comp, GString *str) {
|
||||
switch (comp) {
|
||||
case COMP_SERVER_SOCKET:
|
||||
case COMP_REQUEST_REMOTE_IP:
|
||||
return cond_new_socket(cond, comp, str);
|
||||
return cond_new_socket(op, comp, str);
|
||||
case COMP_REQUEST_PATH:
|
||||
case COMP_REQUEST_HOST:
|
||||
case COMP_REQUEST_REFERER:
|
||||
|
@ -93,7 +93,7 @@ static condition* condition_new_from_string(config_cond_t cond, comp_key_t comp,
|
|||
case COMP_REQUEST_METHOD:
|
||||
case COMP_PHYSICAL_PATH:
|
||||
case COMP_PHYSICAL_PATH_EXISTS:
|
||||
return cond_new_string(cond, comp, str);
|
||||
return cond_new_string(op, comp, str);
|
||||
case COMP_PHYSICAL_SIZE:
|
||||
case COMP_REQUEST_CONTENT_LENGTH:
|
||||
// TODO: die with error
|
||||
|
@ -103,31 +103,31 @@ static condition* condition_new_from_string(config_cond_t cond, comp_key_t comp,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
condition* condition_new_string(server *srv, config_cond_t cond, comp_key_t comp, GString *str) {
|
||||
condition* condition_new_string(server *srv, comp_operator_t op, comp_key_t comp, GString *str) {
|
||||
condition *c;
|
||||
GString *key = g_string_sized_new(0);
|
||||
g_string_sprintf(key, "%i:%i:%s", (int) cond, (int) comp, str->str);
|
||||
g_string_sprintf(key, "%i:%i:%s", (int) op, (int) comp, str->str);
|
||||
|
||||
if (NULL != (c = condition_find_cached(srv, key))) {
|
||||
g_string_free(key, TRUE);
|
||||
return c;
|
||||
}
|
||||
|
||||
c = condition_new_from_string(cond, comp, str);
|
||||
c = condition_new_from_string(op, comp, str);
|
||||
condition_cache_insert(srv, key, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
condition* condition_new_string_uncached(server *srv, config_cond_t cond, comp_key_t comp, GString *str) {
|
||||
condition* condition_new_string_uncached(server *srv, comp_operator_t op, comp_key_t comp, GString *str) {
|
||||
condition *c;
|
||||
GString *key = g_string_sized_new(0);
|
||||
g_string_sprintf(key, "%i:%i:%s", (int) cond, (int) comp, str->str);
|
||||
g_string_sprintf(key, "%i:%i:%s", (int) op, (int) comp, str->str);
|
||||
|
||||
c = condition_find_cached(srv, key);
|
||||
g_string_free(key, TRUE);
|
||||
if (NULL != c) return c;
|
||||
|
||||
return condition_new_from_string(cond, comp, str);
|
||||
return condition_new_from_string(op, comp, str);
|
||||
}
|
||||
|
||||
static void condition_free(condition *c) {
|
||||
|
@ -138,7 +138,7 @@ static void condition_free(condition *c) {
|
|||
/* nothing to free */
|
||||
break;
|
||||
case COND_VALUE_STRING:
|
||||
if (c->cond == CONFIG_COND_MATCH || c->cond == CONFIG_COND_NOMATCH) {
|
||||
if (c->op == CONFIG_COND_MATCH || c->op == CONFIG_COND_NOMATCH) {
|
||||
#ifdef HAVE_PCRE_H
|
||||
if (c->value.regex) pcre_free(c->value.regex);
|
||||
if (c->value.regex_study) pcre_free(c->value.regex_study);
|
||||
|
@ -158,11 +158,19 @@ void condition_release(condition* c) {
|
|||
}
|
||||
}
|
||||
|
||||
const char* config_cond_to_string(config_cond_t cond) {
|
||||
UNUSED(cond);
|
||||
const char* condition_op_to_string(comp_operator_t op) {
|
||||
switch (op) {
|
||||
case CONFIG_COND_EQ: return "==";
|
||||
case CONFIG_COND_GE: return ">=";
|
||||
case CONFIG_COND_GT: return ">";
|
||||
case CONFIG_COND_LE: return "<=";
|
||||
case CONFIG_COND_LT: return "<";
|
||||
case CONFIG_COND_MATCH: return "=~";
|
||||
case CONFIG_COND_NE: return "!=";
|
||||
case CONFIG_COND_NOMATCH: return "!~";
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
return "";
|
||||
return "<unkown>";
|
||||
}
|
||||
|
||||
const char* comp_key_to_string(comp_key_t comp) {
|
||||
|
@ -223,7 +231,7 @@ static gboolean condition_check_eval_string(server *srv, connection *con, condit
|
|||
break;
|
||||
}
|
||||
|
||||
if (value) switch (cond->cond) {
|
||||
if (value) switch (cond->op) {
|
||||
case CONFIG_COND_EQ: /** == */
|
||||
result = 0 == strcmp(value, cond->value.string->str);
|
||||
break;
|
||||
|
@ -262,7 +270,7 @@ static gboolean condition_check_eval_int(server *srv, connection *con, condition
|
|||
value = -1;
|
||||
}
|
||||
|
||||
if (value > 0) switch (cond->cond) {
|
||||
if (value > 0) switch (cond->op) {
|
||||
case CONFIG_COND_EQ: /** == */
|
||||
return (value == cond->value.i);
|
||||
case CONFIG_COND_NE: /** != */
|
||||
|
|
|
@ -18,7 +18,7 @@ typedef enum {
|
|||
CONFIG_COND_GE, /** >= */
|
||||
CONFIG_COND_LT, /** < */
|
||||
CONFIG_COND_LE /** <= */
|
||||
} config_cond_t;
|
||||
} comp_operator_t;
|
||||
|
||||
/**
|
||||
* possible fields to match against
|
||||
|
@ -55,7 +55,7 @@ typedef struct condition condition;
|
|||
struct condition {
|
||||
int refcount;
|
||||
|
||||
config_cond_t cond;
|
||||
comp_operator_t op;
|
||||
comp_key_t comp;
|
||||
|
||||
/* index into connection conditional caching table, -1 if uncached */
|
||||
|
@ -85,15 +85,15 @@ struct condition {
|
|||
} value;
|
||||
};
|
||||
|
||||
LI_API condition* condition_new_string(server *srv, config_cond_t cond, comp_key_t comp, GString *str);
|
||||
LI_API condition* condition_new_int(server *srv, config_cond_t cond, comp_key_t comp, gint i);
|
||||
LI_API condition* condition_new_string(server *srv, comp_operator_t op, comp_key_t comp, GString *str);
|
||||
LI_API condition* condition_new_int(server *srv, comp_operator_t op, comp_key_t comp, gint i);
|
||||
|
||||
LI_API condition* condition_new_string_uncached(server *srv, config_cond_t cond, comp_key_t comp, GString *str);
|
||||
LI_API condition* condition_new_int_uncached(server *srv, config_cond_t cond, comp_key_t comp, gint i);
|
||||
LI_API condition* condition_new_string_uncached(server *srv, comp_operator_t op, comp_key_t comp, GString *str);
|
||||
LI_API condition* condition_new_int_uncached(server *srv, comp_operator_t op, comp_key_t comp, gint i);
|
||||
|
||||
LI_API void condition_release(condition* c);
|
||||
|
||||
LI_API const char* config_cond_to_string(config_cond_t cond);
|
||||
LI_API const char* condition_op_to_string(comp_operator_t op);
|
||||
LI_API const char* comp_key_to_string(comp_key_t comp);
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "condition.h"
|
||||
|
||||
struct config_parser_data_t;
|
||||
typedef struct config_parser_data_t config_parser_data_t;
|
||||
|
||||
|
@ -35,6 +37,9 @@ struct config_parser_data_t {
|
|||
gint64 val_int;
|
||||
gboolean val_bool;
|
||||
|
||||
/* operator */
|
||||
config_cond_t operator;
|
||||
|
||||
/* name of current variable */
|
||||
GString *varname;
|
||||
};
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
#include "config_parser.h"
|
||||
|
||||
#if 0
|
||||
#define _printf(fmt, ...) printf(fmt, __VA_ARGS__)
|
||||
#if 1
|
||||
#define _printf(fmt, ...) printf(fmt, __VA_ARGS__)
|
||||
#else
|
||||
#define _printf(fmt, ...) /* */
|
||||
#define _printf(fmt, ...) /* */
|
||||
#endif
|
||||
|
||||
/** config parser state machine **/
|
||||
|
@ -43,13 +43,13 @@
|
|||
cpd->val_bool = TRUE;
|
||||
else
|
||||
cpd->val_bool = FALSE;
|
||||
//_printf("got boolean %s in line %zd of %s\n", cpd->val_bool ? "true" : "false", cpd->line, cpd->filename);
|
||||
_printf("got boolean %s in line %zd of %s\n", cpd->val_bool ? "true" : "false", cpd->line, cpd->filename);
|
||||
}
|
||||
action string {
|
||||
g_string_truncate(cpd->val_str, 0);
|
||||
g_string_append_len(cpd->val_str, cpd->mark + 1, fpc - cpd->mark - 2);
|
||||
cpd->val_type = CONFP_STR;
|
||||
//_printf("got string: \"%s\" in line %zd of %s\n", cpd->val_str->str, cpd->line, cpd->filename);
|
||||
_printf("got string: \"%s\" in line %zd of %s\n", cpd->val_str->str, cpd->line, cpd->filename);
|
||||
}
|
||||
action integer
|
||||
{
|
||||
|
@ -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: %d in line %d\n", config_parser_data.val_int, line);
|
||||
_printf("got integer: %zd 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); }
|
||||
|
@ -70,10 +70,43 @@
|
|||
action varname {
|
||||
g_string_truncate(cpd->varname, 0);
|
||||
g_string_append_len(cpd->varname, cpd->mark_var, fpc - cpd->mark_var);
|
||||
//_printf("got varname: \"%s\" in line %zd of %s\n", cpd->varname->str, cpd->line, cpd->filename);
|
||||
_printf("got varname: \"%s\" in line %zd of %s\n", cpd->varname->str, cpd->line, cpd->filename);
|
||||
}
|
||||
|
||||
action operator { }
|
||||
action operator {
|
||||
if ((fpc - cpd->mark) == 1) {
|
||||
/* 1 char operator: < or > */
|
||||
cpd->operator = (*fpc == '<') ? CONFIG_COND_LT : CONFIG_COND_GT;
|
||||
}
|
||||
else {
|
||||
/* 2 char operator */
|
||||
char frst = *cpd->mark, scnd = *(fpc-1);
|
||||
_printf(" [%c %c] ", frst, scnd);
|
||||
if (frst == '<' && scnd == '=') {
|
||||
cpd->operator = CONFIG_COND_LE;
|
||||
}
|
||||
else if (frst == '>' && scnd == '=') {
|
||||
cpd->operator = CONFIG_COND_GE;
|
||||
}
|
||||
else if (frst == '!' && scnd == '=') {
|
||||
cpd->operator = CONFIG_COND_NE;
|
||||
}
|
||||
else if (frst == '=' && scnd == '=') {
|
||||
cpd->operator = CONFIG_COND_EQ;
|
||||
}
|
||||
else if (frst == '=' && scnd == '~') {
|
||||
cpd->operator = CONFIG_COND_MATCH;
|
||||
}
|
||||
else if (frst == '!' && scnd == '~') {
|
||||
cpd->operator = CONFIG_COND_NOMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
_printf("got operator: %s", "");
|
||||
for (char* c=cpd->mark; c < fpc; c++)
|
||||
_printf("%c", (int)*c);
|
||||
_printf(" (%d) in line %zd of %s\n", cpd->operator, cpd->line, cpd->filename);
|
||||
}
|
||||
action assignment { _printf("got assignment for var %s in line %zd of %s\n", cpd->varname->str, cpd->line, cpd->filename); }
|
||||
action function {
|
||||
if (g_str_equal(cpd->varname->str, "include") || g_str_equal(cpd->varname->str, "include_shell"))
|
||||
|
@ -141,7 +174,7 @@
|
|||
|
||||
varname = ( alpha ( alnum | [_.\-] )* ) >mark_var %varname;
|
||||
|
||||
operator = ( '==' | '!=' | '=~' | '!~' | '<' | '<=' | '>' | '>=' ) %operator;
|
||||
operator = ( '==' | '!=' | '=~' | '!~' | '<' | '<=' | '>' | '>=' ) >mark %operator;
|
||||
|
||||
assignment = ( varname ws* '=' ws* (value|valuepair|list|hash) ';' ) %assignment;
|
||||
|
||||
|
|
Loading…
Reference in New Issue