java 17-23
2012-02-14 17:11
106 查看
#!/usr/bin/lua
--Author:jncheng
--Version:20150520
--Email:burtte@sina.com
-------------------------------------------------------------------------------------------
session:setVariable("continue_on_fail","USER_BUSY,NO_ANSWER,TIMEOUT,NO_USER_RESPONSE")
--session:setVariable("call_time_out","10")
--session:setVariable("bridge_answer_timeout","10")
--get the dial extension number
dest_exten = session:getVariable("destination_number")
src_exten = session:getVariable("caller_id_number")
exten_len=string.len(dest_exten)
fs_ivr_dir = "/usr/local/freeswitch/sounds"
cai_lin = fs_ivr_dir.."/ring.wav"
session:setVariable("ringback",cai_lin)
session:setVariable("effective_caller_id_name",src_exten)
--test the dial length
if (exten_len == 4) then
--freeswitch.consoleLog("INFO","the src dialpled numbers is:"..src_exten.."\n")
--Connect the local MySQL database(DBname,User,Password)
--local dbh = freeswitch.Dbh("test","fs","123qwe")
--Connect the ODBC DSN Database(odbcsourcename:Username:Passwod),in odbc.ini
local dbh = freeswitch.Dbh("odbc://fs:fs:123qwe")
--freeswitch.consoleLog("NOTICE","start connect DB...\r\n")
assert(dbh:connected())
--Get the dest_exten SIP Host
dbh:query("select sub_to_host as host from sip_subscriptions where sip_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
dest_host_2 = string.format("%s",row.host)
end);
--freeswitch.consoleLog("INFO","the dest_exten host is:"..dest_host_2.."\n")
dbh:query("select realm as host from registrations where reg_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
dest_host = string.format("%s",row.host)
end);
--freeswitch.consoleLog("INFO","the dest_exten host2 is:"..dest_host.."\n")
--if the dest_host is nil,it mean the user not register,tell and hangup.
if (dest_host == nil and dest_host_2 == nil) then
session:answer()
session:setVariable("call_time_out","20")
session:sleep(2000)
session:streamFile(fs_ivr_dir.."/dialed_again.wav")
session:sleep(2000)
session:hangup()
else
--Get the src_exten SIP Host 1
dbh:query("select sub_to_host as host from sip_subscriptions where sip_user="..src_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
src_host_2 = string.format("%s",row.host)
end);
--Get the src_exten SIP Host 2
dbh:query("select realm as host from registrations where reg_user="..src_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
src_host = string.format("%s",row.host)
end);
--If the src host == dest host,it meaning the user register on same host
if (dest_host == src_host or dest_host_2 == src_host or dest_host == src_host_2 or dest_host_2 == src_host_2) then
--get the local dial string
dbh:query("select url from registrations where reg_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.url))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
exten_url = string.format("%s",row.url)
end);
--define the split function,This not write by me.From internet
function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
local list = Split(exten_url,";")
local local_url = list[1]
--the log use for debug
--freeswitch.consoleLog("INFO","the dest_exten host is:"..dest_host.."\n")
--freeswitch.consoleLog("INFO","the src local url is:"..local_url.."\n")
--freeswitch.consoleLog("INFO","the dest_exten host2 is:"..dest_host_2.."\n")
session:setVariable("call_timeout","60")
session:execute("bridge",local_url)
--Add tell why not scueefull bridge
session:answer()
local fail_cause=session:getVariable("originate_disposition")
--freeswitch.consoleLog("ERR","the hangupCause is:"..fail_cause.."\n")
--fail_cause mail cause is : USER_BUSY,NO_ANSWER,CALL_REJECT
session:streamFile(fs_ivr_dir.."/"..fail_cause..".wav")
session:sleep(2000)
session:hangup()
else
--if the src host != dest host ,then dial string is soifa/external/80090@$host:5080
if (dest_host == nil) then
dest_url_new = "sofia/external/"..dest_exten.."@"..dest_host_2..":5080"
else
dest_url_new = "sofia/external/"..dest_exten.."@"..dest_host..":5080"
end
--freeswitch.consoleLog("INFO","the dest url is:"..dest_host_new.."\n")
session:setVariable("call_timeout","60")
session:execute("bridge",dest_url_new)
--Add tell why not scueefull bridge
session:answer()
local fail_cause=session:getVariable("originate_disposition")
--freeswitch.consoleLog("ERR","the hangupCause is:"..fail_cause.."\n")
--fail_cause mail cause is : USER_BUSY,NO_ANSWER,CALL_REJECT
session:streamFile(fs_ivr_dir.."/"..fail_cause..".wav")
session:sleep(2000)
session:hangup()
end
end
--if the dialpled number length is not 4,tell use check the number
else
session:answer()
session:setVariable("call_time_out","20")
session:sleep(2000)
session:streamFile(fs_ivr_dir.."/check_number.wav")
session:sleep(2000)
session:hangup()
end
本文出自 “什么也没有留下” 博客,请务必保留此出处http://3357278.blog.51cto.com/3347278/1642420
--Author:jncheng
--Version:20150520
--Email:burtte@sina.com
-------------------------------------------------------------------------------------------
session:setVariable("continue_on_fail","USER_BUSY,NO_ANSWER,TIMEOUT,NO_USER_RESPONSE")
--session:setVariable("call_time_out","10")
--session:setVariable("bridge_answer_timeout","10")
--get the dial extension number
dest_exten = session:getVariable("destination_number")
src_exten = session:getVariable("caller_id_number")
exten_len=string.len(dest_exten)
fs_ivr_dir = "/usr/local/freeswitch/sounds"
cai_lin = fs_ivr_dir.."/ring.wav"
session:setVariable("ringback",cai_lin)
session:setVariable("effective_caller_id_name",src_exten)
--test the dial length
if (exten_len == 4) then
--freeswitch.consoleLog("INFO","the src dialpled numbers is:"..src_exten.."\n")
--Connect the local MySQL database(DBname,User,Password)
--local dbh = freeswitch.Dbh("test","fs","123qwe")
--Connect the ODBC DSN Database(odbcsourcename:Username:Passwod),in odbc.ini
local dbh = freeswitch.Dbh("odbc://fs:fs:123qwe")
--freeswitch.consoleLog("NOTICE","start connect DB...\r\n")
assert(dbh:connected())
--Get the dest_exten SIP Host
dbh:query("select sub_to_host as host from sip_subscriptions where sip_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
dest_host_2 = string.format("%s",row.host)
end);
--freeswitch.consoleLog("INFO","the dest_exten host is:"..dest_host_2.."\n")
dbh:query("select realm as host from registrations where reg_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
dest_host = string.format("%s",row.host)
end);
--freeswitch.consoleLog("INFO","the dest_exten host2 is:"..dest_host.."\n")
--if the dest_host is nil,it mean the user not register,tell and hangup.
if (dest_host == nil and dest_host_2 == nil) then
session:answer()
session:setVariable("call_time_out","20")
session:sleep(2000)
session:streamFile(fs_ivr_dir.."/dialed_again.wav")
session:sleep(2000)
session:hangup()
else
--Get the src_exten SIP Host 1
dbh:query("select sub_to_host as host from sip_subscriptions where sip_user="..src_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
src_host_2 = string.format("%s",row.host)
end);
--Get the src_exten SIP Host 2
dbh:query("select realm as host from registrations where reg_user="..src_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.host))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
src_host = string.format("%s",row.host)
end);
--If the src host == dest host,it meaning the user register on same host
if (dest_host == src_host or dest_host_2 == src_host or dest_host == src_host_2 or dest_host_2 == src_host_2) then
--get the local dial string
dbh:query("select url from registrations where reg_user="..dest_exten,function(row)
--freeswitch.consoleLog("NOTICE","------------------------------------------")
--freeswitch.consoleLog("NOTICE",string.format("%s\n",row.url))
--freeswitch.consoleLog("NOTICE","------------------------------------------")
exten_url = string.format("%s",row.url)
end);
--define the split function,This not write by me.From internet
function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
local list = Split(exten_url,";")
local local_url = list[1]
--the log use for debug
--freeswitch.consoleLog("INFO","the dest_exten host is:"..dest_host.."\n")
--freeswitch.consoleLog("INFO","the src local url is:"..local_url.."\n")
--freeswitch.consoleLog("INFO","the dest_exten host2 is:"..dest_host_2.."\n")
session:setVariable("call_timeout","60")
session:execute("bridge",local_url)
--Add tell why not scueefull bridge
session:answer()
local fail_cause=session:getVariable("originate_disposition")
--freeswitch.consoleLog("ERR","the hangupCause is:"..fail_cause.."\n")
--fail_cause mail cause is : USER_BUSY,NO_ANSWER,CALL_REJECT
session:streamFile(fs_ivr_dir.."/"..fail_cause..".wav")
session:sleep(2000)
session:hangup()
else
--if the src host != dest host ,then dial string is soifa/external/80090@$host:5080
if (dest_host == nil) then
dest_url_new = "sofia/external/"..dest_exten.."@"..dest_host_2..":5080"
else
dest_url_new = "sofia/external/"..dest_exten.."@"..dest_host..":5080"
end
--freeswitch.consoleLog("INFO","the dest url is:"..dest_host_new.."\n")
session:setVariable("call_timeout","60")
session:execute("bridge",dest_url_new)
--Add tell why not scueefull bridge
session:answer()
local fail_cause=session:getVariable("originate_disposition")
--freeswitch.consoleLog("ERR","the hangupCause is:"..fail_cause.."\n")
--fail_cause mail cause is : USER_BUSY,NO_ANSWER,CALL_REJECT
session:streamFile(fs_ivr_dir.."/"..fail_cause..".wav")
session:sleep(2000)
session:hangup()
end
end
--if the dialpled number length is not 4,tell use check the number
else
session:answer()
session:setVariable("call_time_out","20")
session:sleep(2000)
session:streamFile(fs_ivr_dir.."/check_number.wav")
session:sleep(2000)
session:hangup()
end
本文出自 “什么也没有留下” 博客,请务必保留此出处http://3357278.blog.51cto.com/3347278/1642420
相关文章推荐
- 17.JavaWeb基础 Ajax(局部刷新)
- at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)异常解决
- android-23 View.java - dispatchTouchEvent源码
- 《Python Web开发实战》踩地雷记17/3/23
- 17---java中Annotation01(系统内置的)
- ArcGIS Server Java ADF 案例教程 17
- Java中的23中设计模式
- at org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)
- LEETCODE 17 Letter Combinations of a Phone Number (JAVA题解)
- Android的开发之&java23中设计模式------>装饰模式
- java(08-17)
- Java4android学习笔记22-23
- JAVA基础第二天;基本代码的编写(15-6-17)
- (java)leetcode-17
- 23_java多线程
- Java基础知识强化之网络编程笔记17:Android网络通信之 使用Http的Post方式读取网络数据(基于HTTP通信技术)
- Java网络编程从入门到精通(17):Socket类的getter和setter方法(1)
- 【Java并发编程】17、SynchronousQueue源码分析
- java设计模式_23中设计模式的记忆方法
- Java上路17-I/O-字符与字节