diff --git a/resources/install/scripts/app/xml_handler/index.lua b/resources/install/scripts/app/xml_handler/index.lua
index 98cc01f289..dc1cdb5199 100644
--- a/resources/install/scripts/app/xml_handler/index.lua
+++ b/resources/install/scripts/app/xml_handler/index.lua
@@ -42,13 +42,6 @@
dofile(scripts_dir.."/resources/functions/file_exists.lua");
dofile(scripts_dir.."/resources/functions/explode.lua");
---connect to the database
- dofile(scripts_dir.."/resources/functions/database_handle.lua");
- dbh = database_handle('system');
-
---exits the script if we didn't connect properly
- assert(dbh:connected());
-
--if the params class and methods do not exist then add them to prevent errors
if (not params) then
params = {}
@@ -103,21 +96,6 @@
--prepare the api object
api = freeswitch.API();
---get the domain_uuid
- if (domain_uuid == nil) then
- --get the domain_uuid
- if (domain_name ~= nil) then
- sql = "SELECT domain_uuid FROM v_domains ";
- sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
- if (debug["sql"]) then
- freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
- end
- status = dbh:query(sql, function(rows)
- domain_uuid = rows["domain_uuid"];
- end);
- end
- end
-
--process the sections
if (XML_REQUEST["section"] == "configuration") then
configuration = scripts_dir.."/app/xml_handler/resources/scripts/configuration/"..XML_REQUEST["key_value"]..".lua";
@@ -134,6 +112,3 @@
if (XML_REQUEST["section"] == "dialplan") then
dofile(scripts_dir.."/app/xml_handler/resources/scripts/dialplan/dialplan.lua");
end
-
---close the database connection
- dbh:release();
\ No newline at end of file
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua
index 19c5c060de..c057c0e41b 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua
@@ -35,6 +35,28 @@
--set the cache
if (XML_STRING == "-ERR NOT FOUND") then
+ --connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+ --exits the script if we didn't connect properly
+ assert(dbh:connected());
+
+ --get the domain_uuid
+ if (domain_uuid == nil) then
+ --get the domain_uuid
+ if (domain_name ~= nil) then
+ sql = "SELECT domain_uuid FROM v_domains ";
+ sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ status = dbh:query(sql, function(rows)
+ domain_uuid = rows["domain_uuid"];
+ end);
+ end
+ end
+
--get the variables
vars = trim(api:execute("global_getvar", ""));
@@ -234,6 +256,9 @@
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n");
end
+ --close the database connection
+ dbh:release();
+
--set the cache
result = trim(api:execute("memcache", "set configuration:sofia.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' "..expire["sofia.conf"]));
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua
index fb1df7952f..a27d762784 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua
@@ -33,6 +33,29 @@
--set the cache
if (XML_STRING == "-ERR NOT FOUND") then
+
+ --connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+ --exits the script if we didn't connect properly
+ assert(dbh:connected());
+
+ --get the domain_uuid
+ if (domain_uuid == nil) then
+ --get the domain_uuid
+ if (domain_name ~= nil) then
+ sql = "SELECT domain_uuid FROM v_domains ";
+ sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ status = dbh:query(sql, function(rows)
+ domain_uuid = rows["domain_uuid"];
+ end);
+ end
+ end
+
--set the xml array and then concatenate the array to a string
local xml = {}
table.insert(xml, [[]]);
@@ -54,9 +77,6 @@
sql = sql .. "where d.dialplan_context = '" .. call_context .. "' ";
sql = sql .. "and d.dialplan_enabled = 'true' ";
sql = sql .. "and d.dialplan_uuid = s.dialplan_uuid ";
- --if (call_context ~= "public") then
- -- sql = sql .. "and d.domain_uuid = '" .. domain_uuid .. "' ";
- --end
sql = sql .. "order by ";
sql = sql .. "d.dialplan_order asc, ";
sql = sql .. "d.dialplan_name asc, ";
@@ -253,6 +273,9 @@
if (debug["cache"]) then
freeswitch.consoleLog("notice", "[xml_handler] dialplan:"..call_context.." source: database\n");
end
+
+ --close the database connection
+ dbh:release();
else
--replace the ' back to a single quote
XML_STRING = XML_STRING:gsub("'", "'");
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua
index 5883faa55c..e0ec0d6b5e 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua
@@ -24,6 +24,13 @@
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
+--connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+--exits the script if we didn't connect properly
+ assert(dbh:connected());
+
--process when the sip profile is rescanned, sofia is reloaded, or sip redirect
local xml = {}
table.insert(xml, [[]]);
@@ -36,3 +43,6 @@
table.insert(xml, [[ ]]);
table.insert(xml, [[]]);
XML_STRING = table.concat(xml, "\n");
+
+--close the database connection
+ dbh:release();
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua
index c1479cdcda..b00c279891 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua
@@ -33,6 +33,28 @@
--set the cache
if (XML_STRING == "-ERR NOT FOUND") then
+ --connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+ --exits the script if we didn't connect properly
+ assert(dbh:connected());
+
+ --get the domain_uuid
+ if (domain_uuid == nil) then
+ --get the domain_uuid
+ if (domain_name ~= nil) then
+ sql = "SELECT domain_uuid FROM v_domains ";
+ sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ status = dbh:query(sql, function(rows)
+ domain_uuid = rows["domain_uuid"];
+ end);
+ end
+ end
+
--build the call group array
sql = [[
select * from v_extensions
@@ -98,6 +120,9 @@
table.insert(xml, [[]]);
XML_STRING = table.concat(xml, "\n");
+ --close the database connection
+ dbh:release();
+
--set the cache
result = trim(api:execute("memcache", "set directory:groups:"..domain_name.." '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua
index c7bf1b1569..f3a10d107d 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua
@@ -31,6 +31,28 @@
--group_call - call group has been called
--user_call - user has been called
+--connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+--exits the script if we didn't connect properly
+ assert(dbh:connected());
+
+--get the domain_uuid
+ if (domain_uuid == nil) then
+ --get the domain_uuid
+ if (domain_name ~= nil) then
+ sql = "SELECT domain_uuid FROM v_domains ";
+ sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ status = dbh:query(sql, function(rows)
+ domain_uuid = rows["domain_uuid"];
+ end);
+ end
+ end
+
--get the extension information
sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
if (debug["sql"]) then
@@ -70,6 +92,9 @@
table.insert(xml, [[]]);
XML_STRING = table.concat(xml, "\n");
+--close the database connection
+ dbh:release();
+
--send the xml to the console
if (debug["xml_string"]) then
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: \n" .. XML_STRING .. "\n");
diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua
index b78c2a32ed..2f67bb0a7f 100644
--- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua
+++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua
@@ -66,20 +66,21 @@
XML_STRING = trim(api:execute("memcache", "get directory:" .. user .. "@" .. domain_name));
end
if (XML_STRING == "-ERR NOT FOUND") then
+ source = "database";
+ continue = true;
+ else
+ source = "cache";
continue = true;
end
else
XML_STRING = "";
+ source = "database";
continue = true;
end
--prevent processing for invalid user
if (user == "*97") then
- continue = false;
- end
-
- --prevent processing for invalid domains
- if (domain_uuid == nil) then
+ source = "";
continue = false;
end
@@ -97,325 +98,367 @@
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
end
- --if load balancing is set to true then get the hostname
- if (load_balancing) then
- --get the domain_name from domains
- if (domain_name == nil) then
- sql = "SELECT domain_name FROM v_domains ";
- sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' ";
- status = dbh:query(sql, function(row)
- domain_name = row["domain_name"];
+ --build the XML string from the database
+ if (source == "database") then
+ --database connection
+ if (continue) then
+ --connect to the database
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh = database_handle('system');
+
+ --exits the script if we didn't connect properly
+ assert(dbh:connected());
+
+ --get the domain_uuid
+ if (domain_uuid == nil) then
+ --get the domain_uuid
+ if (domain_name ~= nil) then
+ sql = "SELECT domain_uuid FROM v_domains ";
+ sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ status = dbh:query(sql, function(rows)
+ domain_uuid = rows["domain_uuid"];
+ end);
+ end
+ end
+ end
+
+ --prevent processing for invalid domains
+ if (domain_uuid == nil) then
+ continue = false;
+ end
+
+ --if load balancing is set to true then get the hostname
+ if (continue) then
+ if (load_balancing) then
+
+ --get the domain_name from domains
+ if (domain_name == nil) then
+ sql = "SELECT domain_name FROM v_domains ";
+ sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' ";
+ status = dbh:query(sql, function(row)
+ domain_name = row["domain_name"];
+ end);
+ end
+
+ --get the caller hostname
+ local_hostname = trim(api:execute("hostname", ""));
+ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n");
+
+ --add the file_exists function
+ dofile(scripts_dir.."/resources/functions/file_exists.lua");
+
+ --connect to the switch database
+ if (file_exists(database_dir.."/core.db")) then
+ --dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite
+ dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
+ else
+ dofile(scripts_dir.."/resources/functions/database_handle.lua");
+ dbh_switch = database_handle('switch');
+ end
+
+ --get the destination hostname from the registration
+ sql = "SELECT hostname FROM registrations ";
+ sql = sql .. "WHERE reg_user = '"..dialed_extension.."' ";
+ sql = sql .. "AND realm = '"..domain_name.."'";
+ status = dbh_switch:query(sql, function(row)
+ database_hostname = row["hostname"];
+ end);
+ --freeswitch.consoleLog("notice", "[xml_handler] sql: " .. sql .. "\n");
+ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] database_hostname is " .. database_hostname .. "\n");
+
+ --hostname was not found set load_balancing to false to prevent a database_hostname concatenation error
+ if (database_hostname == nil) then
+ load_balancing = false;
+ end
+
+ --close the database connection
+ dbh_switch:release();
+ end
+ end
+
+ --get the extension from the database
+ if (continue) then
+ sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ dbh:query(sql, function(row)
+ --general
+ domain_uuid = row.domain_uuid;
+ extension_uuid = row.extension_uuid;
+ extension = row.extension;
+ cidr = "";
+ if (string.len(row.cidr) > 0) then
+ cidr = [[ cidr="]] .. row.cidr .. [["]];
+ end
+ number_alias = "";
+ if (string.len(row.number_alias) > 0) then
+ number_alias = [[ number-alias="]] .. row.number_alias .. [["]];
+ end
+ --params
+ password = row.password;
+ --vm_enabled = "true";
+ --if (string.len(row.vm_enabled) > 0) then
+ -- vm_enabled = row.vm_enabled;
+ --end
+ --vm_password = row.vm_password;
+ --vm_attach_file = "true";
+ --if (string.len(row.vm_attach_file) > 0) then
+ -- vm_attach_file = row.vm_attach_file;
+ --end
+ --vm_keep_local_after_email = "true";
+ --if (string.len(row.vm_keep_local_after_email) > 0) then
+ -- vm_keep_local_after_email = row.vm_keep_local_after_email;
+ --end
+ --if (string.len(row.vm_mailto) > 0) then
+ -- vm_mailto = row.vm_mailto;
+ --else
+ -- vm_mailto = "";
+ --end
+ mwi_account = row.mwi_account;
+ auth_acl = row.auth_acl;
+ --variables
+ sip_from_user = row.extension;
+ call_group = row.call_group;
+ hold_music = row.hold_music;
+ toll_allow = row.toll_allow;
+ accountcode = row.accountcode;
+ user_context = row.user_context;
+ effective_caller_id_name = row.effective_caller_id_name;
+ effective_caller_id_number = row.effective_caller_id_number;
+ outbound_caller_id_name = row.outbound_caller_id_name;
+ outbound_caller_id_number = row.outbound_caller_id_number;
+ emergency_caller_id_number = row.emergency_caller_id_number;
+ directory_full_name = row.directory_full_name;
+ directory_visible = row.directory_visible;
+ directory_exten_visible = row.directory_exten_visible;
+ limit_max = row.limit_max;
+ call_timeout = row.call_timeout;
+ limit_destination = row.limit_destination;
+ sip_force_contact = row.sip_force_contact;
+ sip_force_expires = row.sip_force_expires;
+ nibble_account = row.nibble_account;
+ sip_bypass_media = row.sip_bypass_media;
+
+ --set the dial_string
+ if (string.len(row.dial_string) > 0) then
+ dial_string = row.dial_string;
+ else
+ --set a default dial string
+ dial_string = "{sip_invite_domain=" .. domain_name .. ",leg_timeout=" .. call_timeout .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. user .. "@" .. domain_name .. ")}";
+ --set the an alternative dial string if the hostnames don't match
+ if (load_balancing) then
+ if (local_hostname == database_hostname) then
+ freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_host and database_host are the same\n");
+ else
+ --sofia/internal/${user_data(${destination_number}@${domain_name} attr id)}@${domain_name};fs_path=sip:server
+ user_id = trim(api:execute("user_data", user .. "@" .. domain_name .. " attr id"));
+ dial_string = "{sip_invite_domain=" .. domain_name .. ",leg_timeout=" .. call_timeout .. ",presence_id=" .. user .. "@" .. domain_name .. "}sofia/internal/" .. user_id .. "@" .. domain_name .. ";fs_path=sip:" .. database_hostname;
+ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dial_string " .. dial_string .. "\n");
+ end
+ else
+ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] seems balancing is false??" .. tostring(load_balancing) .. "\n");
+ end
+
+ --show debug informationa
+ --if (load_balancing) then
+ -- freeswitch.consoleLog("notice", "[xml_handler] local_hostname: " .. local_hostname.. " database_hostname: " .. database_hostname .. " dial_string: " .. dial_string .. "\n");
+ --end
+ end
end);
end
- --get the caller hostname
- local_hostname = trim(api:execute("hostname", ""));
- --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n");
-
- --add the file_exists function
- dofile(scripts_dir.."/resources/functions/file_exists.lua");
-
- --connect to the switch database
- if (file_exists(database_dir.."/core.db")) then
- --dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite
- dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
- else
- dofile(scripts_dir.."/resources/functions/database_handle.lua");
- dbh_switch = database_handle('switch');
+ --if the extension does not exist set continue to false;
+ if (extension_uuid == nil) then
+ continue = false;
end
- --get the destination hostname from the registration
- sql = "SELECT hostname FROM registrations ";
- sql = sql .. "WHERE reg_user = '"..dialed_extension.."' ";
- sql = sql .. "AND realm = '"..domain_name.."'";
- status = dbh_switch:query(sql, function(row)
- database_hostname = row["hostname"];
- end);
- --freeswitch.consoleLog("notice", "[xml_handler] sql: " .. sql .. "\n");
- --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] database_hostname is " .. database_hostname .. "\n");
-
- --hostname was not found set load_balancing to false to prevent a database_hostname concatenation error
- if (database_hostname == nil) then
- load_balancing = false;
+ --outbound hot desking - get the extension variables
+ if (continue) then
+ sql = "SELECT * FROM v_extensions WHERE dial_domain = '" .. domain_name .. "' and dial_user = '" .. user .. "' and enabled = 'true' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ dbh:query(sql, function(row)
+ --get the values from the database
+ extension_uuid = row.extension_uuid;
+ domain_uuid = row.domain_uuid;
+ sip_from_user = row.extension;
+ call_group = row.call_group;
+ hold_music = row.hold_music;
+ toll_allow = row.toll_allow;
+ accountcode = row.accountcode;
+ user_context = row.user_context;
+ effective_caller_id_name = row.effective_caller_id_name;
+ effective_caller_id_number = row.effective_caller_id_number;
+ outbound_caller_id_name = row.outbound_caller_id_name;
+ outbound_caller_id_number = row.outbound_caller_id_number;
+ emergency_caller_id_number = row.emergency_caller_id_number;
+ directory_full_name = row.directory_full_name;
+ directory_visible = row.directory_visible;
+ directory_exten_visible = row.directory_exten_visible;
+ limit_max = row.limit_max;
+ --call_timeout = row.call_timeout;
+ limit_destination = row.limit_destination;
+ sip_force_contact = row.sip_force_contact;
+ sip_force_expires = row.sip_force_expires;
+ nibble_account = row.nibble_account;
+ sip_bypass_media = row.sip_bypass_media;
+ end);
end
- --close the database connection
- dbh_switch:release();
- end
-
- --get the extension from the database
- if (continue) then
- sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
- if (debug["sql"]) then
- freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
- end
- dbh:query(sql, function(row)
- --general
- domain_uuid = row.domain_uuid;
- extension_uuid = row.extension_uuid;
- extension = row.extension;
- cidr = "";
- if (string.len(row.cidr) > 0) then
- cidr = [[ cidr="]] .. row.cidr .. [["]];
- end
- number_alias = "";
- if (string.len(row.number_alias) > 0) then
- number_alias = [[ number-alias="]] .. row.number_alias .. [["]];
- end
- --params
- password = row.password;
- --vm_enabled = "true";
- --if (string.len(row.vm_enabled) > 0) then
- -- vm_enabled = row.vm_enabled;
- --end
- --vm_password = row.vm_password;
- --vm_attach_file = "true";
- --if (string.len(row.vm_attach_file) > 0) then
- -- vm_attach_file = row.vm_attach_file;
- --end
- --vm_keep_local_after_email = "true";
- --if (string.len(row.vm_keep_local_after_email) > 0) then
- -- vm_keep_local_after_email = row.vm_keep_local_after_email;
- --end
- --if (string.len(row.vm_mailto) > 0) then
- -- vm_mailto = row.vm_mailto;
- --else
- -- vm_mailto = "";
- --end
- mwi_account = row.mwi_account;
- auth_acl = row.auth_acl;
- --variables
- sip_from_user = row.extension;
- call_group = row.call_group;
- hold_music = row.hold_music;
- toll_allow = row.toll_allow;
- accountcode = row.accountcode;
- user_context = row.user_context;
- effective_caller_id_name = row.effective_caller_id_name;
- effective_caller_id_number = row.effective_caller_id_number;
- outbound_caller_id_name = row.outbound_caller_id_name;
- outbound_caller_id_number = row.outbound_caller_id_number;
- emergency_caller_id_number = row.emergency_caller_id_number;
- directory_full_name = row.directory_full_name;
- directory_visible = row.directory_visible;
- directory_exten_visible = row.directory_exten_visible;
- limit_max = row.limit_max;
- call_timeout = row.call_timeout;
- limit_destination = row.limit_destination;
- sip_force_contact = row.sip_force_contact;
- sip_force_expires = row.sip_force_expires;
- nibble_account = row.nibble_account;
- sip_bypass_media = row.sip_bypass_media;
-
- --set the dial_string
- if (string.len(row.dial_string) > 0) then
- dial_string = row.dial_string;
- else
- --set a default dial string
- dial_string = "{sip_invite_domain=" .. domain_name .. ",leg_timeout=" .. call_timeout .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. user .. "@" .. domain_name .. ")}";
- --set the an alternative dial string if the hostnames don't match
- if (load_balancing) then
- if (local_hostname == database_hostname) then
- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_host and database_host are the same\n");
- else
- --sofia/internal/${user_data(${destination_number}@${domain_name} attr id)}@${domain_name};fs_path=sip:server
- user_id = trim(api:execute("user_data", user .. "@" .. domain_name .. " attr id"));
- dial_string = "{sip_invite_domain=" .. domain_name .. ",leg_timeout=" .. call_timeout .. ",presence_id=" .. user .. "@" .. domain_name .. "}sofia/internal/" .. user_id .. "@" .. domain_name .. ";fs_path=sip:" .. database_hostname;
- --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dial_string " .. dial_string .. "\n");
- end
+ --set the xml array and then concatenate the array to a string
+ if (continue and password) then
+ --build the xml
+ local xml = {}
+ table.insert(xml, [[]]);
+ table.insert(xml, [[]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ if (number_alias) then
+ if (cidr) then
+ table.insert(xml, [[ ]]);
else
- --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] seems balancing is false??" .. tostring(load_balancing) .. "\n");
+ table.insert(xml, [[ ]]);
end
+ else
+ if (cidr) then
+ table.insert(xml, [[ ]]);
+ else
+ table.insert(xml, [[ ]]);
+ end
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ --table.insert(xml, [[ ]]);
+ --if (string.len(vm_mailto) > 0) then
+ -- table.insert(xml, [[ ]]);
+ -- table.insert(xml, [[ ]]);
+ -- table.insert(xml, [[ ]]);
+ -- table.insert(xml, [[ ]]);
+ -- table.insert(xml, [[ ]]);
+ --end
+ if (string.len(mwi_account) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(auth_acl) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ --table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ if (string.len(call_group) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(hold_music) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(toll_allow) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(accountcode) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ if (string.len(effective_caller_id_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(effective_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(outbound_caller_id_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(outbound_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(emergency_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_full_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_visible) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_exten_visible) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(limit_max) > 0) then
+ table.insert(xml, [[ ]]);
+ else
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(limit_destination) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(sip_force_contact) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(sip_force_expires) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(nibble_account) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "bypass-media") then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "bypass-media-after-bridge") then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "proxy-media") then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[]]);
+ XML_STRING = table.concat(xml, "\n");
- --show debug informationa
- --if (load_balancing) then
- -- freeswitch.consoleLog("notice", "[xml_handler] local_hostname: " .. local_hostname.. " database_hostname: " .. database_hostname .. " dial_string: " .. dial_string .. "\n");
- --end
- end
- end);
+ --close the database connection
+ dbh:release();
+
+ --set the cache
+ if (user and domain_name) then
+ result = trim(api:execute("memcache", "set directory:" .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
+ end
+
+ --send the xml to the console
+ if (debug["xml_string"]) then
+ local file = assert(io.open("/tmp/" .. user .. "@" .. domain_name .. ".xml", "w"));
+ file:write(XML_STRING);
+ file:close();
+ end
+
+ --send to the console
+ if (debug["cache"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] directory:" .. user .. "@" .. domain_name .. " source: database\n");
+ end
+ end
end
- --if the extension does not exist set continue to false;
- if (extension_uuid == nil) then
- continue = false;
- end
-
- --outbound hot desking - get the extension variables
- if (continue) then
- sql = "SELECT * FROM v_extensions WHERE dial_domain = '" .. domain_name .. "' and dial_user = '" .. user .. "' and enabled = 'true' ";
- if (debug["sql"]) then
- freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
- end
- dbh:query(sql, function(row)
- --get the values from the database
- extension_uuid = row.extension_uuid;
- domain_uuid = row.domain_uuid;
- sip_from_user = row.extension;
- call_group = row.call_group;
- hold_music = row.hold_music;
- toll_allow = row.toll_allow;
- accountcode = row.accountcode;
- user_context = row.user_context;
- effective_caller_id_name = row.effective_caller_id_name;
- effective_caller_id_number = row.effective_caller_id_number;
- outbound_caller_id_name = row.outbound_caller_id_name;
- outbound_caller_id_number = row.outbound_caller_id_number;
- emergency_caller_id_number = row.emergency_caller_id_number;
- directory_full_name = row.directory_full_name;
- directory_visible = row.directory_visible;
- directory_exten_visible = row.directory_exten_visible;
- limit_max = row.limit_max;
- --call_timeout = row.call_timeout;
- limit_destination = row.limit_destination;
- sip_force_contact = row.sip_force_contact;
- sip_force_expires = row.sip_force_expires;
- nibble_account = row.nibble_account;
- sip_bypass_media = row.sip_bypass_media;
- end);
- end
-
- --set the xml array and then concatenate the array to a string
- if (continue and password) then
- --build the xml
- local xml = {}
- table.insert(xml, [[]]);
- table.insert(xml, [[]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- if (number_alias) then
- if (cidr) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
- end
- else
- if (cidr) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
- end
- end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- --table.insert(xml, [[ ]]);
- --if (string.len(vm_mailto) > 0) then
- -- table.insert(xml, [[ ]]);
- -- table.insert(xml, [[ ]]);
- -- table.insert(xml, [[ ]]);
- -- table.insert(xml, [[ ]]);
- -- table.insert(xml, [[ ]]);
- --end
- if (string.len(mwi_account) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(auth_acl) > 0) then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- --table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- if (string.len(call_group) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(hold_music) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(toll_allow) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(accountcode) > 0) then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- if (string.len(effective_caller_id_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(effective_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(outbound_caller_id_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(outbound_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(emergency_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_full_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_visible) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_exten_visible) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(limit_max) > 0) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
- end
- if (string.len(limit_destination) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(sip_force_contact) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(sip_force_expires) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(nibble_account) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "bypass-media") then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "bypass-media-after-bridge") then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "proxy-media") then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[]]);
- XML_STRING = table.concat(xml, "\n");
-
- --set the cache
- if (user and domain_name) then
- result = trim(api:execute("memcache", "set directory:" .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
- end
-
- --send the xml to the console
- if (debug["xml_string"]) then
- local file = assert(io.open("/tmp/" .. user .. "@" .. domain_name .. ".xml", "w"));
- file:write(XML_STRING);
- file:close();
- end
-
- --send to the console
- if (debug["cache"]) then
- freeswitch.consoleLog("notice", "[xml_handler] directory:" .. user .. "@" .. domain_name .. " source: database\n");
- end
- else
+ --get the XML string from the cache
+ if (source == "cache") then
--replace the ' back to a single quote
if (XML_STRING) then
XML_STRING = XML_STRING:gsub("'", "'");