Permalink
Browse files

Complex rule matches (and, or and not) accesses now the right internal

configuration objects. Besides fixing the server core issue, this
patch also adds a new QA test entry to project us against potential
regressions. It fixes bug #1207: http://bugs.cherokee-project.com/1207

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6841 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent b5bf9b1 commit b0b669c3ab6dde5db920d7cd6d74185bb23e4bfd @alobbs alobbs committed Sep 7, 2011
Showing with 91 additions and 8 deletions.
  1. +17 −3 cherokee/rule.c
  2. +8 −2 cherokee/rule.h
  3. +8 −0 cherokee/rule_and.c
  4. +6 −2 cherokee/rule_directory.c
  5. +7 −0 cherokee/rule_not.c
  6. +7 −0 cherokee/rule_or.c
  7. +36 −0 qa/287-rule-inheritance.py
  8. +2 −1 qa/Makefile.am
View
@@ -36,9 +36,10 @@ cherokee_rule_init_base (cherokee_rule_t *rule, cherokee_plugin_info_t *info)
cherokee_module_init_base (MODULE(rule), NULL, info);
INIT_LIST_HEAD (&rule->list_node);
- rule->match = NULL;
- rule->final = true;
- rule->priority = CHEROKEE_RULE_PRIO_NONE;
+ rule->match = NULL;
+ rule->final = true;
+ rule->priority = CHEROKEE_RULE_PRIO_NONE;
+ rule->parent_rule = NULL;
cherokee_config_entry_init (&rule->config);
return ret_ok;
@@ -115,3 +116,16 @@ cherokee_rule_match (cherokee_rule_t *rule, void *cnt, void *ret_conf)
return rule->match (rule, CONN(cnt), CONF_ENTRY(ret_conf));
}
+
+void
+cherokee_rule_get_config (cherokee_rule_t *rule,
+ cherokee_config_entry_t **config)
+{
+ cherokee_rule_t *r = rule;
+
+ while (r->parent_rule != NULL) {
+ r = r->parent_rule;
+ }
+
+ *config = &r->config;
+}
View
@@ -49,7 +49,7 @@ typedef ret_t (* rule_func_match_t) (void *rule, void *cnt, void *ret_conf)
/* Data types
*/
-typedef struct {
+struct cherokee_rule {
cherokee_module_t module;
/* Properties */
@@ -58,12 +58,14 @@ typedef struct {
cherokee_boolean_t final;
cuint_t priority;
+ struct cherokee_rule *parent_rule;
/* Virtual methods */
rule_func_match_t match;
rule_func_configure_t configure;
-} cherokee_rule_t;
+};
+typedef struct cherokee_rule cherokee_rule_t;
#define RULE(x) ((cherokee_rule_t *)(x))
/* Easy initialization
@@ -90,6 +92,10 @@ ret_t cherokee_rule_init_base (cherokee_rule_t *rule, cherokee_plugin_info_t *
ret_t cherokee_rule_match (cherokee_rule_t *rule, void *cnt, void *ret_conf);
ret_t cherokee_rule_configure (cherokee_rule_t *rule, cherokee_config_node_t *conf, void *vsrv);
+/* Utilities
+ */
+void cherokee_rule_get_config (cherokee_rule_t *rule, cherokee_config_entry_t **config);
+
CHEROKEE_END_DECLS
#endif /* CHEROKEE_RULE_H */
View
@@ -71,9 +71,17 @@ configure_branch (cherokee_rule_and_t *rule,
ret = cherokee_virtual_server_new_rule (vsrv, subconf,
RULE(rule)->priority,
branch_rule);
+
if (ret != ret_ok)
return ret;
+ if ((branch_rule == NULL) || (*branch_rule) == NULL)
+ return ret_error;
+
+ /* Let the child rule know about its parent
+ */
+ (*branch_rule)->parent_rule = RULE(rule);
+
return ret_ok;
}
@@ -38,6 +38,8 @@ match (cherokee_rule_directory_t *rule,
cherokee_connection_t *conn,
cherokee_config_entry_t *ret_conf)
{
+ cherokee_config_entry_t *conf = NULL;
+
UNUSED(ret_conf);
/* Not the same lenght
@@ -90,8 +92,10 @@ match (cherokee_rule_directory_t *rule,
/* Copy the web directory property
*/
- if ((RULE(rule)->config.handler_new_func != NULL) ||
- (RULE(rule)->config.document_root != NULL))
+ cherokee_rule_get_config (RULE(rule), &conf);
+
+ if ((conf->document_root != NULL) ||
+ (conf->handler_new_func != NULL))
{
cherokee_buffer_clean (&conn->web_directory);
cherokee_buffer_add_buffer (&conn->web_directory, &rule->directory);
View
@@ -76,6 +76,13 @@ configure (cherokee_rule_not_t *rule,
if (ret != ret_ok)
return ret;
+ if (rule->right == NULL)
+ return ret_error;
+
+ /* Let the child rule know about its parent
+ */
+ rule->right->parent_rule = RULE(rule);
+
return ret_ok;
}
View
@@ -73,6 +73,13 @@ configure_branch (cherokee_rule_or_t *rule,
if (ret != ret_ok)
return ret;
+ if ((branch_rule == NULL) || (*branch_rule) == NULL)
+ return ret_error;
+
+ /* Let the child rule know about its parent
+ */
+ (*branch_rule)->parent_rule = RULE(rule);
+
return ret_ok;
}
View
@@ -0,0 +1,36 @@
+from base import *
+
+# Tests: http://bugs.cherokee-project.com/1207
+#
+# When using a complex rule match, the child match objects were
+# accessing their own (empty) configuration objects instead of its
+# parents where the real configuration was found.
+
+DIR_WEB = "web287"
+DIR_LOCAL = "DirAnd-parent_properties"
+FILE = "filename_to_be_found"
+
+CONF = """
+vserver!1!rule!2870!match = and
+vserver!1!rule!2870!match!left = directory
+vserver!1!rule!2870!match!left!directory = /%s
+vserver!1!rule!2870!match!right = request
+vserver!1!rule!2870!match!right!request = .*
+vserver!1!rule!2870!handler = dirlist
+vserver!1!rule!2870!document_root = %s
+"""
+
+class Test (TestBase):
+ def __init__ (self):
+ TestBase.__init__ (self, __file__)
+ self.name = "Complex rules: props inheritance"
+
+ self.request = "GET /%s/ HTTP/1.0\r\n" % (DIR_WEB)
+ self.expected_error = 200
+ self.expected_content = FILE
+
+ def Prepare (self, www):
+ d = self.Mkdir (www, DIR_LOCAL)
+ self.WriteFile (d, FILE)
+
+ self.conf = CONF %(DIR_WEB, d)
View
@@ -307,7 +307,8 @@ run-tests.py \
283-Flcache-expired3.py \
284-SSI-include-recursive.py \
285-Flcache-overwrite.py \
-286-CGI-Permissions.py
+286-CGI-Permissions.py \
+287-rule-inheritance.py
test:
python -m compileall .

0 comments on commit b0b669c

Please sign in to comment.