朔州网站建设价格低,快猫,wordpress推介,有关建设旅游网站的公司概述
freeswitch是一款简单好用的VOIP开源软交换平台。
mod_xml_curl模块支持从web服务获取xml配置#xff0c;本文介绍如何动态获取dialplan配置。
环境
centos#xff1a;CentOS release 7.0 (Final)或以上版本
freeswitch#xff1a;v1.6.20
GCC#xff1a;4.8.5… 概述
freeswitch是一款简单好用的VOIP开源软交换平台。
mod_xml_curl模块支持从web服务获取xml配置本文介绍如何动态获取dialplan配置。
环境
centosCentOS release 7.0 (Final)或以上版本
freeswitchv1.6.20
GCC4.8.5
dialplan查找流程
我们在“switch_xml_parse_file”函数中设置一个断点并打印堆栈。
Breakpoint 1, switch_xml_parse_file (filefileentry0x7fdda1a015f0 /tmp/34096cac-311f-11ee-b31e-672fb2a27310.tmp.xml) at src/switch_xml.c:1625
1625 if ((xml switch_xml_parse_fd(fd))) {
(gdb) bt
#0 switch_xml_parse_file (filefileentry0x7fdda1a015f0 /tmp/34096cac-311f-11ee-b31e-672fb2a27310.tmp.xml) at src/switch_xml.c:1625
#1 0x00007fddee4d5258 in xml_url_fetch (sectionoptimized out, tag_nameoptimized out, key_nameoptimized out, key_valueoptimized out, params0x7fdd68004d10, user_data0x1ad1ae8) at mod_xml_curl.c:311
#2 0x00007fddf71e0ec0 in switch_xml_locate (sectionsectionentry0x7fddae9fc7e8 dialplan, tag_nametag_nameentry0x0, key_namekey_nameentry0x0, key_valuekey_valueentry0x0, rootrootentry0x7fdda1a01b00, nodenodeentry0x7fdda1a01af8, params0x7fdd68004d10, clonecloneentrySWITCH_FALSE) at src/switch_xml.c:1675
#3 0x00007fddae9fc214 in dialplan_xml_locate (node0x7fdda1a01af8, root0x7fdda1a01b00, caller_profile0x7fddd004d690, session0x7fddd0030328) at mod_dialplan_xml.c:613
#4 dialplan_hunt (session0x7fddd0030328, argoptimized out, caller_profile0x7fddd004d690) at mod_dialplan_xml.c:658
#5 0x00007fddf71342ef in switch_core_standard_on_routing (session0x7fddd0030328) at src/switch_core_state_machine.c:281
#6 switch_core_session_run (session0x7fddd0030328) at src/switch_core_state_machine.c:643
#7 0x00007fddf712c9fe in switch_core_session_thread (threadoptimized out, obj0x7fddd0030328) at src/switch_core_session.c:1648
#8 0x00007fddf71286f3 in switch_core_session_thread_pool_worker (thread0x7fddd004f5e0, objoptimized out) at src/switch_core_session.c:1711
#9 0x00007fddf7213e10 in dummy_worker (opaque0x7fddd004f5e0) at threadproc/unix/thread.c:151
#10 0x00007fddf4a11ea5 in start_thread () from /lib64/libpthread.so.0
#11 0x00007fddf4065b0d in clone () from /lib64/libc.so.6
(gdb) 从堆栈中可以看出一通呼叫查找动态dialplan的流程如下。
switch_core_session_thread
switch_core_session_run
switch_core_standard_on_routing
dialplan_hunt
dialplan_xml_locate
switch_xml_locate
xml_url_fetch
switch_xml_parse_file web服务
mod_xml_curl模块依赖于web服务需要自己创建一个web接口并动态的返回xml配置。
下面是python3.10实现的一个简单的web服务接口函数从基类“BaseHTTPRequestHandler”继承并实现简单的返回逻辑。 def fsDialplan(self): length int(self.headers[content-length]) datas self.rfile.read(length) logging.info(/fs/dialplan request, data%s % urllib.parse.unquote(datas)) respcode document typefreeswitch/xml
section namedialplan descriptiondialplan-url include context namepublic extension nametest-url continuefalse condition fielddestination_number expression^(\d)$ action applicationanswer/ action applicationplayback data/usr/local/freeswitch/sounds/dialplan-test-url.wav/ /condition /extension /context /include
/section
/document self.send_response(200) self.send_header(Content-Type, application;charsetutf-8) self.end_headers() self.wfile.write(respcode.encode(utf-8)) return web服务响应消息格式注意事项必须有“section”段xml格式不能使用压缩格式否则会解析错误。
配置
检查conf/autoload_configs/modules.conf.xml文件mod_xml_curl模块要放在配置的顶部。
load modulemod_console/
load modulemod_logfile/
load modulemod_xml_curl/ 修改conf/autoload_configs/xml_curl.conf.xml文件。
configuration namexml_curl.conf descriptioncURL XML Gateway bindings binding namedialplan param namegateway-url valuehttp://10.55.55.137:8080/fs/dialplan bindingsdialplan/ /binding /bindings
/configuration 测试
使用10011发起呼叫日志如下。
2023-08-03 11:08:27.438976 [INFO] mod_dialplan_xml.c:637 Processing 10011 10011-13712345678 in context public
2023-08-03 11:08:27.478976 [CONSOLE] mod_xml_curl.c:323 XML response is in /tmp/042fcd1e-31ab-11ee-b34d-672fb2a27310.tmp.xml
Dialplan: sofia/external/1001110.55.55.138 parsing [public-test-url] continuefalse
Dialplan: sofia/external/1001110.55.55.138 Regex (PASS) [test-url] destination_number(13712345678) ~ /^(\d)$/ breakon-false
Dialplan: sofia/external/1001110.55.55.138 Action answer()
Dialplan: sofia/external/1001110.55.55.138 Action playback(/usr/local/freeswitch/sounds/dialplan-test-url.wav) 呼叫结果符合预期。
问题
网友的问题当使用 dialplan时这个动态获取的dialplan优先级最高每通电话都会执行到这个dialplan。 而有些电话我不想走xml动态获取的就想走本地配置的这个问题怎解决呢
方案1mod_xml_curl模块内部已实现的逻辑当web服务返回“NOT FOUND”时自动走本地配置。缺点是对web服务依赖每通呼叫都会到web服务查询。
方案2修改“switch_xml_locate”函数增加条件控制比如caller是“123456”时直接使用本地配置。缺点是不够灵活配置条件修改较困难。
方案3修改mod_xml_curl模块的“xml_url_fetch”函数对web响应的xml结果进行缓存设置过期时间减少了对web服务的依赖又有动态配置的优点。缺点是web配置的生效会增加缓存的延迟弱一致性。
以上方案仅仅从测试结果推导并未真正实现实现细节有不确定性。
总结
mod_xml_curl模块动态获取dialplan数据控制呼叫流程。
未解决问题。
如何更灵活的控制从web服务和本地xml文件获取配置。
如何缓存web服务的xml配置。
如何解决web服务不可用的时候呼叫流程问题。 空空如常
求真得真