Fixed the test rspec to match the new values.
Sapan Bhatia [Tue, 22 Sep 2009 20:24:23 +0000 (20:24 +0000)]
sfatables/runtime.py
sfatables/test.sfarspec
sfatables/xmlrule.py

index dc9e7cb..0cfac14 100644 (file)
@@ -29,7 +29,8 @@ class SFATablesRules:
             if (rule.terminal):
                 break
 
-        return intermediate_rspec
+        final_rspec = XMLRule().wrap_up(intermediate_rspec) 
+        return final_rspec
 
 def main():
     incoming = SFATablesRules('INCOMING')
@@ -37,8 +38,6 @@ def main():
 
     rspec = open(sys.argv[1]).read()
 
-
-    
     print "%d rules loaded for INCOMING chain\n"%len(incoming.sorted_rule_list)
     print "%d rules loaded for OUTGOING chain\n"%len(outgoing.sorted_rule_list)
 
index c84a56d..0b8942f 100644 (file)
@@ -5,7 +5,7 @@
         <sfa><user><hrn>plc.princeton.sapanb</hrn></user></sfa>
     </request-context>
 
-    <sfatables-rule>
+    <rule-context>
             <argument>
                 <name>hrn</name>
                 <value>plc</value>
@@ -18,7 +18,7 @@
                 <name>blacklist</name>
                 <value>plc.tp</value>
             </argument>
-    </sfatables-rule>
+    </rule-context>
     <request>
         <nodespec>
             <node name="plc.princeton.planetlab-01"/>
index 92a06e2..70055dd 100644 (file)
@@ -7,6 +7,7 @@ class XMLRule:
     chain = None
     xmldoc = None
     terminal = 0
+    final_processor = '__sfatables_wrap_up__.xsl'
 
     arguments = {'match':None,'target':None}
     processors = {'match':None,'target':None}
@@ -37,6 +38,19 @@ class XMLRule:
         doc.freeDoc()
         result.freeDoc()
 
+        return stylesheet_result
+
+    def wrap_up(self, rspec):
+        filepath = 'processors/' + self.final_processor
+
+        styledoc = libxml2.parseFile(filepath)
+        style = libxslt.parseStylesheetDoc(styledoc)
+        doc = libxml2.parseDoc(rspec)
+        result = style.applyStylesheet(doc, None)
+        stylesheet_result = style.saveResultToString(result)
+        style.freeStylesheet()
+        doc.freeDoc()
+        result.freeDoc()
 
         return stylesheet_result
 
@@ -97,13 +111,12 @@ class XMLRule:
         root_node.addChild(arguments[type])
         return rspec
 
-    def __init__(self, chain, rule_number):
-
-        self.load_xml_extension('match', chain, rule_number)
-        self.load_xml_extension('target',chain, rule_number)
-        self.rule_number = rule_number
-        self.chain = chain
-
+    def __init__(self, chain=None, rule_number=None):
+        if (chain and rule_number):
+            self.load_xml_extension('match', chain, rule_number)
+            self.load_xml_extension('target',chain, rule_number)
+            self.rule_number = rule_number
+            self.chain = chain
         return
         
     def free(self):