예제 #1
0
파일: compile.py 프로젝트: bigswitch/snac
def c_action_check(fn_name, args, translate=False):
    global __policy__

    if not isinstance(fn_name, basestring):
        return defer.succeed(None)
    if not isinstance(fn_name, unicode):
        fn_name = unicode(fn_name, 'utf-8')

    slist = strlist()
    new_args = [fn_name]
    for a in args:
        if not isinstance(a, basestring):
            try:
                a = str(a)
            except:
                return defer.succeed(None)
        if isinstance(a, unicode):
            slist.push_back(a.encode('utf-8'))
            new_args.append(a)
        else:
            slist.push_back(a)
            new_args.append(unicode(a, 'utf-8'))
    if __policy__.flow_util.valid_fn_args(fn_name.encode('utf-8'), slist):
        return defer.succeed(new_args)
    return defer.succeed(None)
예제 #2
0
파일: compile.py 프로젝트: bigswitch/snac
 def translate(self):
     decr = False
     if self.type == Flow_action.NAT:
         self.caction = Flow_action(self.type, len(self.args))
         argtype = action_info(self.type)[ARG_IDX]
         check_fn = pred_type_info(argtype)[CHECK_IDX]
         if not self.caction.set_arg(0, check_fn(self.args[0], True)):
             raise Exception('Cannot set action argument.')
         # if dladdr given, set
         if len(self.args) > 1:
             self.caction.set_arg(1, create_eaddr(self.args[1].encode('utf-8')).hb_long())
     elif self.type == Flow_action.WAYPOINT:
         argtype = action_info(self.type)[ARG_IDX]
         check_fn = pred_type_info(argtype)[CHECK_IDX]
         self.caction = Flow_action(self.type, len(self.args))
         if self.caction is None:
             raise Exception('Out of memory.')
         args = [ check_fn(arg, True) for arg in self.args ]
         for i in xrange(len(args)):
             arg = args[i]
             self.to_decrement.append(arg)
             if not self.caction.set_arg(i, args[i]):
                 raise Exception('Cannot set action argument.')
     else:
         self.caction = Flow_action(self.type)
         if self.caction is None:
             raise Exception('Out of memory.')
         if len(self.args) > 0:
             if self.type == Flow_action.C_FUNC:
                 slist = strlist()
                 fn = self.args[0].encode('utf-8')
                 for ar in self.args[1:]:
                     slist.push_back(ar.encode('utf-8'))
                 success = __policy__.flow_util.set_action_argument(self.caction, fn, slist)
             else:
                 argtype = action_info(self.type)[ARG_IDX]
                 if argtype == LOC_T or argtype == HOST_T or argtype == USER_T or argtype == GROUP_T:
                     decr = True
                 check_fn = pred_type_info(argtype)[CHECK_IDX]
                 a = check_fn(self.args[0], True)
                 if decr:
                     self.to_decrement.append(a)
                 success = self.caction.set_arg(a)
             if not success:
                 raise Exception('Cannot set action argument.')