2
0
Fork 0

[core] Support req. phys. and resp. abbreviations in li_cond_lvalue_from_string() and make config parser use this function instead of own code

personal/stbuehler/wip
Thomas Porzelt 2010-02-21 14:32:58 +01:00
parent 3dc644cf40
commit 5892c78e7d
2 changed files with 41 additions and 108 deletions

View File

@ -474,9 +474,16 @@ const char* li_cond_lvalue_to_string(liCondLValue t) {
liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len) {
gchar *c = (gchar*)str;
if (g_str_has_prefix(c, "request.")) {
c += sizeof("request.")-1;
len -= sizeof("request.")-1;
if (g_str_has_prefix(c, "req")) {
if (g_str_has_prefix(c, "req.")) {
c += sizeof("req.")-1;
len -= sizeof("req.")-1;
} else if (g_str_has_prefix(c, "request.")) {
c += sizeof("request.")-1;
len -= sizeof("request.")-1;
} else {
return LI_COMP_UNKNOWN;
}
if (strncmp(c, "localip", len) == 0)
return LI_COMP_REQUEST_LOCALIP;
@ -504,9 +511,16 @@ liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len) {
return LI_COMP_ENVIRONMENT;
else if (strncmp(c, "is_handled", len) == 0)
return LI_COMP_REQUEST_IS_HANDLED;
} else if (g_str_has_prefix(c, "physical.")) {
c += sizeof("physical.")-1;
len -= sizeof("physical.")-1;
} else if (g_str_has_prefix(c, "phys")) {
if (g_str_has_prefix(c, "phys.")) {
c += sizeof("phys.")-1;
len -= sizeof("phys.")-1;
} else if (g_str_has_prefix(c, "physical.")) {
c += sizeof("physical.")-1;
len -= sizeof("physical.")-1;
} else {
return LI_COMP_UNKNOWN;
}
if (strncmp(c, "path", len) == 0)
return LI_COMP_PHYSICAL_PATH;
@ -518,9 +532,16 @@ liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len) {
return LI_COMP_PHYSICAL_ISFILE;
else if (strncmp(c, "is_dir", len) == 0)
return LI_COMP_PHYSICAL_ISDIR;
} else if (g_str_has_prefix(c, "response.")) {
c += sizeof("response.")-1;
len -= sizeof("response.")-1;
} else if (g_str_has_prefix(c, "resp")) {
if (g_str_has_prefix(c, "resp.")) {
c += sizeof("resp.")-1;
len -= sizeof("resp.")-1;
} else if (g_str_has_prefix(c, "response.")) {
c += sizeof("response.")-1;
len -= sizeof("response.")-1;
} else {
return LI_COMP_UNKNOWN;
}
if (strncmp(c, "status", len) == 0)
return LI_COMP_RESPONSE_STATUS;

View File

@ -812,6 +812,7 @@
gchar *str;
liCondition *cond;
liConditionLValue *lvalue;
liCondLValue lvalue_type;
/* if condition is nonbool, then it has a value and maybe a key too on the stack */
if (ctx->condition_nonbool) {
@ -834,108 +835,19 @@
/* create condition lvalue */
str = n->data.string->str;
if (g_str_has_prefix(str, "req")) {
str += 3;
if (g_str_has_prefix(str, "."))
str++;
else if (g_str_has_prefix(str, "uest."))
str += 5;
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
if (g_str_equal(str, "host"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_HOST, NULL);
else if (g_str_equal(str, "path"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_PATH, NULL);
else if (g_str_equal(str, "query"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_QUERY_STRING, NULL);
else if (g_str_equal(str, "method"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_METHOD, NULL);
else if (g_str_equal(str, "scheme"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_SCHEME, NULL);
else if (g_str_equal(str, "remoteip"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_REMOTEIP, NULL);
else if (g_str_equal(str, "localip"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_LOCALIP, NULL);
else if (g_str_equal(str, "is_handled"))
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_IS_HANDLED, NULL);
else if (g_str_equal(str, "header")) {
if (k == NULL) {
WARNING(srv, "%s", "header conditional needs a key");
return FALSE;
}
lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_HEADER, li_value_extract_string(k));
}
else if (g_str_equal(str, "environment") || g_str_equal(str, "env")) {
if (k == NULL) {
WARNING(srv, "%s", "environment conditional needs a key");
return FALSE;
}
lvalue = li_condition_lvalue_new(LI_COMP_ENVIRONMENT, li_value_extract_string(k));
}
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
}
else if (g_str_has_prefix(str, "phys")) {
str += 4;
if (g_str_has_prefix(str, "."))
str++;
else if (g_str_has_prefix(str, "ical."))
str += 5;
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
if (g_str_equal(str, "path"))
lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_PATH, NULL);
else if (g_str_equal(str, "exists"))
lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_EXISTS, NULL);
else if (g_str_equal(str, "size"))
lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_SIZE, NULL);
else if (g_str_equal(str, "is_dir"))
lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_ISDIR, NULL);
else if (g_str_equal(str, "is_file"))
lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_ISFILE, NULL);
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
}
else if (g_str_has_prefix(str, "resp")) {
str += 4;
if (g_str_has_prefix(str, "."))
str++;
else if (g_str_has_prefix(str, "onse."))
str += 5;
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
if (g_str_equal(str, "status"))
lvalue = li_condition_lvalue_new(LI_COMP_RESPONSE_STATUS, NULL);
else if (g_str_equal(str, "header")) {
if (k == NULL) {
WARNING(srv, "%s", "header conditional needs a key");
return FALSE;
}
lvalue = li_condition_lvalue_new(LI_COMP_RESPONSE_HEADER, li_value_extract_string(k));
}
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
}
else {
WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str);
lvalue_type = li_cond_lvalue_from_string(GSTR_LEN(n->data.string));
if (lvalue_type == LI_COMP_UNKNOWN) {
ERROR(srv, "unknown lvalue for condition: %s", n->data.string->str);
return FALSE;
}
if ((lvalue_type == LI_COMP_REQUEST_HEADER || lvalue_type == LI_COMP_ENVIRONMENT || lvalue_type == LI_COMP_RESPONSE_HEADER) && k == NULL) {
ERROR(srv, "%s conditional needs a key", n->data.string->str);
return FALSE;
}
lvalue = li_condition_lvalue_new(lvalue_type, k ? li_value_extract_string(k) : NULL);
if (ctx->condition_nonbool) {
if (v->type == LI_VALUE_STRING) {
cond = li_condition_new_string(srv, ctx->op, lvalue, li_value_extract_string(v));