X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fruntime.py;h=99226f4fbedda2803af5c5052a4bd715f39212c5;hb=bfcea75fd4f7d91b186f4f0e479db0e6f0a231ae;hp=0ed38e0628d5abf4697deb0a93d7202cb397f8b6;hpb=9a053166cdb0187d0514403e92e8719d9a3aa8ee;p=sfa.git diff --git a/sfatables/runtime.py b/sfatables/runtime.py index 0ed38e06..99226f4f 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -3,9 +3,10 @@ import sys import os import pdb +from optparse import OptionParser + import libxml2 -from optparse import OptionParser from sfatables import commands from sfatables.globals import * from sfatables.commands.List import * @@ -50,12 +51,14 @@ class SFATablesRules: childNode = self.create_xml_node(k, context_dict[k]) node.addChild(childNode) else: - node.addContent(context_dict[k]) + childNode = libxml2.newNode(k) + childNode.addContent(context_dict[k]) + node.addChild(childNode) return node def add_request_context_to_rspec(self, doc): p = doc.xpathNewContext() - context = p.xpathEval("//Rspec") + context = p.xpathEval("//RSpec") if (not context): raise Exception('Request is not an rspec') else: @@ -74,8 +77,8 @@ class SFATablesRules: intermediate_rspec = doc for rule in self.sorted_rule_list: - intermediate_rspec = rule.apply_interpreted(intermediate_rspec) - if (rule.terminal): + (matched,intermediate_rspec) = rule.apply_interpreted(intermediate_rspec) + if (rule.terminal and matched): break final_rspec = self.wrap_up(intermediate_rspec) @@ -84,16 +87,20 @@ class SFATablesRules: return final_rspec + def print_rules(self): + for rule in self.sorted_rule_list: + print rule.processors + def main(): incoming = SFATablesRules('INCOMING') incoming.set_context({'sfa':{'user':{'hrn':'plc.princeton.sapanb'}}}) outgoing = SFATablesRules('OUTGOING') print "%d rules loaded for INCOMING chain"%len(incoming.sorted_rule_list) - print incoming.sorted_rule_list[0].processors + incoming.print_rules() print "%d rules loaded for OUTGOING chain"%len(outgoing.sorted_rule_list) - print outgoing.sorted_rule_list[0].processors + outgoing.print_rules() rspec = open(sys.argv[1]).read() newrspec = incoming.apply(rspec)