Add group call capability to the xml handler this enables it to work with call groups.
This commit is contained in:
parent
b6e029258a
commit
98ae72f8cf
|
|
@ -57,6 +57,17 @@
|
|||
return s:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
end
|
||||
|
||||
--add the explode function
|
||||
function explode ( seperator, str )
|
||||
local pos, arr = 0, {}
|
||||
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
|
||||
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
|
||||
pos = sp + 1 -- jump past current divider
|
||||
end
|
||||
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
--if the params class and methods do not exist then add them to prevent errors
|
||||
if (not params) then
|
||||
params = {}
|
||||
|
|
@ -445,11 +456,93 @@
|
|||
end --section configuration
|
||||
|
||||
--handle the directory
|
||||
if (XML_REQUEST["section"] == "directory" and key and user and domain_name) then
|
||||
if (XML_REQUEST["section"] == "directory") then
|
||||
|
||||
--set the default
|
||||
continue = true;
|
||||
|
||||
--get the action
|
||||
action = params:getHeader("action");
|
||||
--sip_auth - registration
|
||||
--group_call - call group has been called
|
||||
--user_call - user has been called
|
||||
|
||||
--determine the correction action to perform
|
||||
if (action == "group_call") then
|
||||
--handles action
|
||||
--group_call
|
||||
|
||||
--build the call group array
|
||||
sql = [[
|
||||
select * from v_extensions
|
||||
where domain_uuid = ']]..domain_uuid..[['
|
||||
order by call_group asc
|
||||
]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
call_group_array = {};
|
||||
status = dbh:query(sql, function(row)
|
||||
call_group = row['call_group'];
|
||||
--call_group = str_replace(";", ",", call_group);
|
||||
tmp_array = explode(",", call_group);
|
||||
for key,value in pairs(tmp_array) do
|
||||
value = trim(value);
|
||||
--freeswitch.consoleLog("notice", "[directory] Key: " .. key .. " Value: " .. value .. " " ..row['extension'] .."\n");
|
||||
if (string.len(value) == 0) then
|
||||
|
||||
else
|
||||
if (call_group_array[value] == nil) then
|
||||
call_group_array[value] = row['extension'];
|
||||
else
|
||||
call_group_array[value] = call_group_array[value]..','..row['extension'];
|
||||
end
|
||||
end
|
||||
end
|
||||
end);
|
||||
--for key,value in pairs(call_group_array) do
|
||||
-- freeswitch.consoleLog("notice", "[directory] Key: " .. key .. " Value: " .. value .. "\n");
|
||||
--end
|
||||
|
||||
--build the xml array
|
||||
local xml = {}
|
||||
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
|
||||
table.insert(xml, [[<document type="freeswitch/xml">]]);
|
||||
table.insert(xml, [[ <section name="directory">]]);
|
||||
table.insert(xml, [[ <domain name="]] .. domain_name .. [[">]]);
|
||||
table.insert(xml, [[ <groups>]]);
|
||||
previous_call_group = "";
|
||||
for key, value in pairs(call_group_array) do
|
||||
call_group = trim(key);
|
||||
extension_list = trim(value);
|
||||
if (string.len(call_group) > 0) then
|
||||
freeswitch.consoleLog("notice", "[directory] call_group: " .. call_group .. "\n");
|
||||
freeswitch.consoleLog("notice", "[directory] extension_list: " .. extension_list .. "\n");
|
||||
if (previous_call_group ~= call_group) then
|
||||
table.insert(xml, [[ <group name="]]..call_group..[[">]]);
|
||||
table.insert(xml, [[ <users>]]);
|
||||
extension_array = explode(",", extension_list);
|
||||
for index,tmp_extension in pairs(extension_array) do
|
||||
table.insert(xml, [[ <user id="]]..tmp_extension..[[" type="pointer"/>]]);
|
||||
end
|
||||
table.insert(xml, [[ </users>]]);
|
||||
table.insert(xml, [[ </group>]]);
|
||||
end
|
||||
previous_call_group = call_group;
|
||||
end
|
||||
end
|
||||
table.insert(xml, [[ </groups>]]);
|
||||
table.insert(xml, [[ </domain>]]);
|
||||
table.insert(xml, [[ </section>]]);
|
||||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
freeswitch.consoleLog("notice", "[directory] XML_STRING: \n" .. XML_STRING .. "\n");
|
||||
|
||||
else
|
||||
--handle action
|
||||
--all directory actions: sip_auth, user_call
|
||||
--except for the action: group_call
|
||||
|
||||
--get the cache
|
||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
||||
XML_STRING = trim(api:execute("memcache", "get " .. user .. "@" .. domain_name));
|
||||
|
|
@ -713,6 +806,7 @@
|
|||
end
|
||||
end
|
||||
end
|
||||
end --if action
|
||||
|
||||
--send the xml to the console
|
||||
if (debug["xml_string"]) then
|
||||
|
|
|
|||
Loading…
Reference in New Issue