From 66ef95959eabf843832eeae4c844cbd05eabd5e3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 10:55:28 +0200 Subject: expression function added --- misc/freeswitch/scripts/dialplan/router.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 50653d8..c2b229d 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -160,13 +160,21 @@ function Router.route_match(self, route) table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); end result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) - if self.log_details or true then + if not common.str.blank(element.pattern) then + if self.log_details then + self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + end + result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); + end + if self.log_details then if result then self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); else self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); end end + else + self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); end end end @@ -267,3 +275,14 @@ function Router.fun_speeddial(self, number, name) end end end + + +function Router.fun_expression(self, expression_str) + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', ''); + result = loadstring("return (" .. expression_str .. ")")(); + if result then + return true, result; + else + return false, result; + end +end -- cgit v1.2.3