Adjust the LUA database connection to accommodate native PostgreSQL support and the recent change to the database connection syntax.

This commit is contained in:
Mark Crane
2013-03-31 08:18:41 +00:00
parent 0e9c9c5753
commit 4930d592e1
17 changed files with 169 additions and 215 deletions

View File

@@ -37,20 +37,12 @@
debug["xml_string"] = false;
debug["cache"] = false;
--include the lua script
--include config.lua
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
include = assert(loadfile(scripts_dir .. "/resources/config.lua"));
include();
dofile(scripts_dir.."/resources/config.lua");
--connect to the database
--ODBC - data source name
if (dsn_name) then
dbh = freeswitch.Dbh(dsn_name,dsn_username,dsn_password);
end
--FreeSWITCH core db handler
if (db_type == "sqlite") then
dbh = freeswitch.Dbh("sqlite://"..db_path.."/"..db_name);
end
dbh = freeswitch.Dbh(database["system"]);
--add the trim function
function trim(s)
@@ -59,7 +51,7 @@
end
--add the explode function
function explode ( seperator, str )
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
@@ -86,7 +78,7 @@
end
--get the params and set them as variables
local domain_uuid = params:getHeader("variable_domain_uuid");
local domain_name = params:getHeader("sip_from_host");
if (domain_uuid == nil) then
local domain_uuid = params:getHeader("domain_uuid");
end
@@ -723,111 +715,117 @@
table.insert(xml, [[<document type="freeswitch/xml">]]);
table.insert(xml, [[ <section name="directory">]]);
table.insert(xml, [[ <domain name="]] .. domain_name .. [[">]]);
table.insert(xml, [[ <groups>]]);
table.insert(xml, [[ <group name="default">]]);
table.insert(xml, [[ <users>]]);
if (number_alias) then
if (cidr) then
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. cidr .. number_alias .. [[>]]);
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. cidr .. number_alias .. [[ type=>]]);
else
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. number_alias .. [[>]]);
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. number_alias .. [[>]]);
end
else
if (cidr) then
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. cidr .. [[>]]);
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. cidr .. [[>]]);
else
table.insert(xml, [[ <user id="]] .. extension .. [[">]]);
table.insert(xml, [[ <user id="]] .. extension .. [[">]]);
end
end
table.insert(xml, [[ <params>]]);
table.insert(xml, [[ <param name="password" value="]] .. password .. [["/>]]);
table.insert(xml, [[ <param name="vm-enabled" value="]] .. vm_enabled .. [["/>]]);
table.insert(xml, [[ <params>]]);
table.insert(xml, [[ <param name="password" value="]] .. password .. [["/>]]);
table.insert(xml, [[ <param name="vm-enabled" value="]] .. vm_enabled .. [["/>]]);
if (string.len(vm_mailto) > 0) then
table.insert(xml, [[ <param name="vm-password" value="]] .. vm_password .. [["/>]]);
table.insert(xml, [[ <param name="vm-email-all-messages" value="]] .. vm_enabled ..[["/>]]);
table.insert(xml, [[ <param name="vm-attach-file" value="]] .. vm_attach_file .. [["/>]]);
table.insert(xml, [[ <param name="vm-keep-local-after-email" value="]] .. vm_keep_local_after_email .. [["/>]]);
table.insert(xml, [[ <param name="vm-mailto" value="]] .. vm_mailto .. [["/>]]);
table.insert(xml, [[ <param name="vm-password" value="]] .. vm_password .. [["/>]]);
table.insert(xml, [[ <param name="vm-email-all-messages" value="]] .. vm_enabled ..[["/>]]);
table.insert(xml, [[ <param name="vm-attach-file" value="]] .. vm_attach_file .. [["/>]]);
table.insert(xml, [[ <param name="vm-keep-local-after-email" value="]] .. vm_keep_local_after_email .. [["/>]]);
table.insert(xml, [[ <param name="vm-mailto" value="]] .. vm_mailto .. [["/>]]);
end
if (string.len(mwi_account) > 0) then
table.insert(xml, [[ <param name="MWI-Account" value="]] .. mwi_account .. [["/>]]);
table.insert(xml, [[ <param name="MWI-Account" value="]] .. mwi_account .. [["/>]]);
end
if (string.len(auth_acl) > 0) then
table.insert(xml, [[ <param name="auth-acl" value="]] .. auth_acl .. [["/>]]);
table.insert(xml, [[ <param name="auth-acl" value="]] .. auth_acl .. [["/>]]);
end
table.insert(xml, [[ <param name="dial-string" value="]] .. dial_string .. [["/>]]);
table.insert(xml, [[ </params>]]);
table.insert(xml, [[ <variables>]]);
table.insert(xml, [[ <variable name="domain_uuid" value="]] .. domain_uuid .. [["/>]]);
table.insert(xml, [[ <variable name="domain_name" value="]] .. domain_name .. [["/>]]);
table.insert(xml, [[ <variable name="extension_uuid" value="]] .. extension_uuid .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_name" value="]] .. sip_from_user .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_number" value="]] .. sip_from_user .. [["/>]]);
table.insert(xml, [[ <param name="dial-string" value="]] .. dial_string .. [["/>]]);
table.insert(xml, [[ </params>]]);
table.insert(xml, [[ <variables>]]);
table.insert(xml, [[ <variable name="domain_uuid" value="]] .. domain_uuid .. [["/>]]);
table.insert(xml, [[ <variable name="domain_name" value="]] .. domain_name .. [["/>]]);
table.insert(xml, [[ <variable name="extension_uuid" value="]] .. extension_uuid .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_name" value="]] .. sip_from_user .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_number" value="]] .. sip_from_user .. [["/>]]);
if (string.len(call_group) > 0) then
table.insert(xml, [[ <variable name="call_group" value="]] .. call_group .. [["/>]]);
table.insert(xml, [[ <variable name="call_group" value="]] .. call_group .. [["/>]]);
end
if (string.len(hold_music) > 0) then
table.insert(xml, [[ <variable name="hold_music" value="]] .. hold_music .. [["/>]]);
table.insert(xml, [[ <variable name="hold_music" value="]] .. hold_music .. [["/>]]);
end
if (string.len(toll_allow) > 0) then
table.insert(xml, [[ <variable name="toll_allow" value="]] .. toll_allow .. [["/>]]);
table.insert(xml, [[ <variable name="toll_allow" value="]] .. toll_allow .. [["/>]]);
end
if (string.len(accountcode) > 0) then
table.insert(xml, [[ <variable name="accountcode" value="]] .. accountcode .. [["/>]]);
table.insert(xml, [[ <variable name="accountcode" value="]] .. accountcode .. [["/>]]);
end
table.insert(xml, [[ <variable name="user_context" value="]] .. user_context .. [["/>]]);
table.insert(xml, [[ <variable name="user_context" value="]] .. user_context .. [["/>]]);
if (string.len(effective_caller_id_name) > 0) then
table.insert(xml, [[ <variable name="effective_caller_id_name" value="]] .. effective_caller_id_name.. [["/>]]);
table.insert(xml, [[ <variable name="effective_caller_id_name" value="]] .. effective_caller_id_name.. [["/>]]);
end
if (string.len(effective_caller_id_number) > 0) then
table.insert(xml, [[ <variable name="effective_caller_id_number" value="]] .. effective_caller_id_number.. [["/>]]);
table.insert(xml, [[ <variable name="effective_caller_id_number" value="]] .. effective_caller_id_number.. [["/>]]);
end
if (string.len(outbound_caller_id_name) > 0) then
table.insert(xml, [[ <variable name="outbound_caller_id_name" value="]] .. outbound_caller_id_name .. [["/>]]);
table.insert(xml, [[ <variable name="outbound_caller_id_name" value="]] .. outbound_caller_id_name .. [["/>]]);
end
if (string.len(outbound_caller_id_number) > 0) then
table.insert(xml, [[ <variable name="outbound_caller_id_number" value="]] .. outbound_caller_id_number .. [["/>]]);
table.insert(xml, [[ <variable name="outbound_caller_id_number" value="]] .. outbound_caller_id_number .. [["/>]]);
end
if (string.len(emergency_caller_id_number) > 0) then
table.insert(xml, [[ <variable name="emergency_caller_id_number" value="]] .. emergency_caller_id_number .. [["/>]]);
table.insert(xml, [[ <variable name="emergency_caller_id_number" value="]] .. emergency_caller_id_number .. [["/>]]);
end
if (string.len(directory_full_name) > 0) then
table.insert(xml, [[ <variable name="directory_full_name" value="]] .. directory_full_name .. [["/>]]);
table.insert(xml, [[ <variable name="directory_full_name" value="]] .. directory_full_name .. [["/>]]);
end
if (string.len(directory_visible) > 0) then
table.insert(xml, [[ <variable name="directory-visible" value="]] .. directory_visible .. [["/>]]);
table.insert(xml, [[ <variable name="directory-visible" value="]] .. directory_visible .. [["/>]]);
end
if (string.len(directory_exten_visible) > 0) then
table.insert(xml, [[ <variable name="directory-exten-visible" value="]] .. directory_exten_visible .. [["/>]]);
table.insert(xml, [[ <variable name="directory-exten-visible" value="]] .. directory_exten_visible .. [["/>]]);
end
if (string.len(limit_max) > 0) then
table.insert(xml, [[ <variable name="limit_max" value="]] .. limit_max .. [["/>]]);
table.insert(xml, [[ <variable name="limit_max" value="]] .. limit_max .. [["/>]]);
else
table.insert(xml, [[ <variable name="limit_max" value="5"/>]]);
table.insert(xml, [[ <variable name="limit_max" value="5"/>]]);
end
if (string.len(limit_destination) > 0) then
table.insert(xml, [[ <variable name="limit_destination" value="]] .. limit_destination .. [["/>]]);
table.insert(xml, [[ <variable name="limit_destination" value="]] .. limit_destination .. [["/>]]);
end
if (string.len(sip_force_contact) > 0) then
table.insert(xml, [[ <variable name="sip_force_contact" value="]] .. sip_force_contact .. [["/>]]);
table.insert(xml, [[ <variable name="sip_force_contact" value="]] .. sip_force_contact .. [["/>]]);
end
if (string.len(sip_force_expires) > 0) then
table.insert(xml, [[ <variable name="sip-force-expires" value="]] .. sip_force_expires .. [["/>]]);
table.insert(xml, [[ <variable name="sip-force-expires" value="]] .. sip_force_expires .. [["/>]]);
end
if (string.len(nibble_account) > 0) then
table.insert(xml, [[ <variable name="nibble_account" value="]] .. nibble_account .. [["/>]]);
table.insert(xml, [[ <variable name="nibble_account" value="]] .. nibble_account .. [["/>]]);
end
if (sip_bypass_media == "bypass-media") then
table.insert(xml, [[ <variable name="bypass_media" value="true"/>]]);
table.insert(xml, [[ <variable name="bypass_media" value="true"/>]]);
end
if (sip_bypass_media == "bypass-media-after-bridge") then
table.insert(xml, [[ <variable name="bypass_media_after_bridge" value="true"/>]]);
table.insert(xml, [[ <variable name="bypass_media_after_bridge" value="true"/>]]);
end
if (sip_bypass_media == "proxy-media") then
table.insert(xml, [[ <variable name="proxy_media" value="true"/>]]);
table.insert(xml, [[ <variable name="proxy_media" value="true"/>]]);
end
table.insert(xml, [[ <variable name="record_stereo" value="true"/>]]);
table.insert(xml, [[ <variable name="transfer_fallback_extension" value="operator"/>]]);
table.insert(xml, [[ <variable name="export_vars" value="domain_name"/>]]);
table.insert(xml, [[ </variables>]]);
table.insert(xml, [[ </user>]]);
table.insert(xml, [[ <variable name="record_stereo" value="true"/>]]);
table.insert(xml, [[ <variable name="transfer_fallback_extension" value="operator"/>]]);
table.insert(xml, [[ <variable name="export_vars" value="domain_name"/>]]);
table.insert(xml, [[ </variables>]]);
table.insert(xml, [[ </user>]]);
table.insert(xml, [[ </users>]]);
table.insert(xml, [[ </group>]]);
table.insert(xml, [[ </groups>]]);
table.insert(xml, [[ </domain>]]);
table.insert(xml, [[ </section>]]);
table.insert(xml, [[</document>]]);
@@ -1132,4 +1130,4 @@
end
--close the database connection
--dbh:release();
dbh:release();