2
0
Fork 0

[core] Change cond_lvalue_form_string() and move it from utils.c to condition.c

This commit is contained in:
Thomas Porzelt 2009-06-01 17:58:48 +02:00
parent c964f6bc52
commit fd8f6ed60f
4 changed files with 53 additions and 76 deletions

View File

@ -52,7 +52,9 @@ typedef enum {
COMP_PHYSICAL_ISFILE,
/* needs a key */
COMP_REQUEST_HEADER /**< needs lowercase key, enforced by condition_lvalue_new */
COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by condition_lvalue_new */
COMP_UNKNOWN
} cond_lvalue_t;
#define COND_LVALUE_FIRST_WITH_KEY COMP_REQUEST_HEADER
@ -122,6 +124,7 @@ LI_API void condition_release(server *srv, condition* c);
LI_API const char* comp_op_to_string(comp_operator_t op);
LI_API const char* cond_lvalue_to_string(cond_lvalue_t t);
LI_API cond_lvalue_t cond_lvalue_from_string(const gchar *str, guint len);
struct vrequest;
LI_API handler_t condition_check(struct vrequest *vr, condition *cond, gboolean *result);

View File

@ -72,6 +72,4 @@ LI_API void l_g_string_append_int(GString *dest, gint64 val);
LI_API gsize dirent_buf_size(DIR * dirp);
LI_API guint cond_lvalue_from_str(gchar *c, cond_lvalue_t *lval);
#endif

View File

@ -245,18 +245,61 @@ const char* cond_lvalue_to_string(cond_lvalue_t t) {
case COMP_REQUEST_PATH: return "request.path";
case COMP_REQUEST_HOST: return "request.host";
case COMP_REQUEST_SCHEME: return "request.scheme";
case COMP_REQUEST_QUERY_STRING: return "request.querystring";
case COMP_REQUEST_QUERY_STRING: return "request.query";
case COMP_REQUEST_METHOD: return "request.method";
case COMP_REQUEST_CONTENT_LENGTH: return "request.length";
case COMP_PHYSICAL_PATH: return "physical.path";
case COMP_PHYSICAL_PATH_EXISTS: return "physical.pathexist";
case COMP_PHYSICAL_PATH_EXISTS: return "physical.exist";
case COMP_PHYSICAL_SIZE: return "physical.size";
case COMP_PHYSICAL_ISDIR: return "physical.is_dir";
case COMP_PHYSICAL_ISFILE: return "physical.is_file";
case COMP_REQUEST_HEADER: return "request.header";
case COMP_UNKNOWN: return "<unknown>";
}
return "<unknown>";
return "<unkown>";
}
cond_lvalue_t cond_lvalue_from_string(const gchar *str, guint len) {
gchar *c = (gchar*)str;
if (g_str_has_prefix(c, "request.")) {
c += sizeof("request.")-1;
if (strncmp(c, "localip", len) == 0)
return COMP_REQUEST_LOCALIP;
else if (strncmp(c, "remoteip", len) == 0)
return COMP_REQUEST_REMOTEIP;
else if (strncmp(c, "path", len) == 0)
return COMP_REQUEST_PATH;
else if (strncmp(c, "host", len) == 0)
return COMP_REQUEST_HOST;
else if (strncmp(c, "scheme", len) == 0)
return COMP_REQUEST_SCHEME;
else if (strncmp(c, "query", len) == 0)
return COMP_REQUEST_QUERY_STRING;
else if (strncmp(c, "method", len) == 0)
return COMP_REQUEST_METHOD;
else if (strncmp(c, "length", len) == 0)
return COMP_REQUEST_CONTENT_LENGTH;
else if (strncmp(c, "header", len) == 0)
return COMP_REQUEST_HEADER;
} else if (strncmp(c, "physical.", sizeof("physical.")-1) == 0) {
c += sizeof("physical.")-1;
if (strncmp(c, "path", len) == 0)
return COMP_PHYSICAL_PATH;
else if (strncmp(c, "exists", len) == 0)
return COMP_PHYSICAL_PATH_EXISTS;
else if (strncmp(c, "size", len) == 0)
return COMP_PHYSICAL_SIZE;
else if (strncmp(c, "is_file", len) == 0)
return COMP_PHYSICAL_ISFILE;
else if (strncmp(c, "is_dir", len) == 0)
return COMP_PHYSICAL_ISDIR;
}
return COMP_UNKNOWN;
}
static handler_t condition_check_eval_bool(vrequest *vr, condition *cond, gboolean *res) {
@ -546,6 +589,9 @@ static handler_t condition_check_eval_ip(vrequest *vr, condition *cond, gboolean
case COMP_PHYSICAL_ISFILE:
VR_ERROR(vr, "%s", "phys.is_dir and phys.is_file are boolean conditionals");
return HANDLER_ERROR;
case COMP_UNKNOWN:
VR_ERROR(vr, "%s", "Cannot parse unknown condition value");
return HANDLER_ERROR;
}
if (ipval.type == COND_VALUE_NUMBER) {

View File

@ -683,73 +683,3 @@ gsize dirent_buf_size(DIR * dirp) {
return (name_end > sizeof(struct dirent) ? name_end : sizeof(struct dirent));
}
guint cond_lvalue_from_str(gchar *c, cond_lvalue_t *lval) {
const gchar *c_orig = c;
if (g_str_has_prefix(c, "req")) {
c += sizeof("req")-1;
if (*c == '.')
c++;
else if (g_str_has_prefix(c, "uest."))
c += sizeof("uest.")-1;
else
return 0;
if (g_str_has_prefix(c, "localip")) {
*lval = COMP_REQUEST_LOCALIP;
return c - c_orig + sizeof("localip")-1;
} else if (g_str_has_prefix(c, "remoteip")) {
*lval = COMP_REQUEST_REMOTEIP;
return c - c_orig + sizeof("remoteip")-1;
} else if (g_str_has_prefix(c, "path")) {
*lval = COMP_REQUEST_PATH;
return c - c_orig + sizeof("path")-1;
} else if (g_str_has_prefix(c, "host")) {
*lval = COMP_REQUEST_HOST;
return c - c_orig + sizeof("host")-1;
} else if (g_str_has_prefix(c, "scheme")) {
*lval = COMP_REQUEST_SCHEME;
return c - c_orig + sizeof("scheme")-1;
} else if (g_str_has_prefix(c, "query")) {
*lval = COMP_REQUEST_QUERY_STRING;
return c - c_orig + sizeof("query")-1;
} else if (g_str_has_prefix(c, "method")) {
*lval = COMP_REQUEST_METHOD;
return c - c_orig + sizeof("method")-1;
} else if (g_str_has_prefix(c, "content_length")) {
*lval = COMP_REQUEST_CONTENT_LENGTH;
return c - c_orig + sizeof("content_length")-1;
}
} else if (g_str_has_prefix(c, "phys")) {
c += sizeof("phys")-1;
if (*c == '.')
c++;
else if (g_str_has_prefix(c, "ical."))
c += sizeof("ical.")-1;
else
return 0;
if (g_str_has_prefix(c, "path")) {
*lval = COMP_PHYSICAL_PATH;
return c - c_orig + sizeof("path")-1;
} else if (g_str_has_prefix(c, "exists")) {
*lval = COMP_PHYSICAL_PATH_EXISTS;
return c - c_orig + sizeof("exists")-1;
} else if (g_str_has_prefix(c, "size")) {
*lval = COMP_PHYSICAL_SIZE;
return c - c_orig + sizeof("size")-1;
} else if (g_str_has_prefix(c, "sidir")) {
*lval = COMP_PHYSICAL_ISDIR;
return c - c_orig + sizeof("sidir")-1;
} else if (g_str_has_prefix(c, "isfile")) {
*lval = COMP_PHYSICAL_ISFILE;
return sizeof("isfile")-1;
}
}
return 0;
}