Set up different namespaces for match and target arguments.
Sapan Bhatia [Mon, 26 Oct 2009 14:48:47 +0000 (14:48 +0000)]
sfatables/runtime.py
sfatables/xmlrule.py

index 8f5c323..e948d05 100644 (file)
@@ -65,29 +65,7 @@ class SFATablesRules:
         p.xpathFreeContext()
         return doc
 
-    def add_rule_context_to_rspec(self,arguments, doc):
-        p = doc.xpathNewContext()
-        context = p.xpathEval("//rspec")
-        if (not context):
-            raise Exception('Request is not an rspec')
-        else:
-            # Add the request context
-            ruleNode = libxml2.newNode('rule-context')
-            ac = self.active_context
-            for k in ac:
-                argumentNode = libxml2.newNode('argument')
-                nameNode = libxml2.newNode('name')
-                nameNode.addContent(k)
-                valueNode = libxml2.newNode('value')
-                valueNode.addContent(ac[k])
-                argumentNode.addChild(nameNode)
-                argumentNode.addChild(valueNode)
-                ruleNode.addChild(argumentNode)
-                context[0].addChild(ruleNode)
-        p.xpathFreeContext()
-
-        return doc
-
+    
     def apply(self, rspec):
         doc = libxml2.parseDoc(rspec)
         doc = self.add_request_context_to_rspec(doc)
@@ -95,8 +73,6 @@ class SFATablesRules:
         intermediate_rspec = doc
 
         for rule in self.sorted_rule_list:
-            import pdb
-            pdb.set_trace()
             intermediate_rspec  = rule.apply_interpreted(intermediate_rspec)
             intermediate_rspec = XMLRule().wrap_up(intermediate_rspec) 
             if (rule.terminal):
index 310c843..d137e4e 100644 (file)
@@ -55,18 +55,36 @@ class XMLRule:
         target_result = self.apply_processor('target',rspec,None)
         return target_result
 
+    def add_rule_context_to_rspec(self, doc):
+        p = doc.xpathNewContext()
+        context = p.xpathEval("//rspec")
+        if (not context):
+            raise Exception('Request is not an rspec')
+        else:
+            # Add the request context
+            matchNode = libxml2.newNode('match-context')
+            matchNode.addChild(self.arguments['match'])
+            targetNode = libxml2.newNode('target-context')
+            targetNode.addChild(self.arguments['target'])
+            context[0].addChild(matchNode)
+            context[0].addChild(targetNode)
+        p.xpathFreeContext()
+
+        return doc
+
     def apply_interpreted(self, rspec):
+        self.add_rule_context_to_rspec(rspec)
         # Interpreted
         #
         # output =
         #    if (match(match_args, rspec)
         #       then target(target_args, rspec)
         #       else rspec
-
+        
         if (self.match(rspec)):
-            return self.target(rspec)
+            return self.wrap_up(self.target(rspec))
         else:
-            return rspec
+            return self.wrap_up(rspec)
 
 
     def apply_compiled(rspec):