天天看點

freeswitch的mod_xml_curl子產品

作者:求真得真
freeswitch的mod_xml_curl子產品

概述

freeswitch是一款簡單好用的VOIP開源軟交換平台。

随着fs服務的增多,每一台fs都需要在背景單獨配置,耗時耗力,心力憔悴。

如果有一個集中管理配置的配置中心,統一管理所有fs的配置,并可以實作動态的修改配置就好了。

于是就發現了mod_xml_curl子產品。

環境

centos:CentOS release 7.0 (Final)或以上版本

freeswitch:v1.10.7

GCC:4.8.5

子產品介紹

mod_xml_curl子產品預設不編譯安裝。

進入“freeswitch/src/mod/xml_int/mod_xml_curl”目錄,執行如下指令

sudo make install

檢查子產品安裝情況。

cd /usr/local/freeswitch/mod

ll

-rwxr-xr-x. 1 root root 104456 Jul 28 10:47 mod_xml_curl.so

-rwxr-xr-x. 1 root root 1316 Jul 28 10:47 mod_xml_curl.la

檢查conf/autoload_configs/modules.conf.xml檔案,mod_xml_curl子產品要放在配置的頂部。

<load module="mod_console"/>

<load module="mod_logfile"/>

<load module="mod_xml_curl"/>

檢查conf/autoload_configs/xml_curl.conf.xml檔案。

mod_xml_curl子產品的主要使用場景。

運作多個FreeSWITCH執行個體而不必維護多個伺服器配置。

集中的配置管理。

從連接配接到資料庫的web應用程式動态填充配置。

提供了一種自動化FreeSWITCH配置部署的簡單方法(例如,托管VoIP平台)。

mod_xml_curl的工作原理與典型的API一樣,向web應用程式發送POST請求,擷取XML格式的響應消息并重新整理本地配置。

mod_xml_curl從web接口擷取到有效響應則直接加載配置,如果收到無效響應或404則嘗試從本地磁盤查找配置檔案。

mod_xml_curl子產品可以分為4個不同的綁定章節,基本可以覆寫全部的xml配置項。

configuration,配置項,比如mod_sofia的配置。

directory,使用者鑒權目錄。

dialplan,撥号計劃。

phrases,語音短語管理。

測試

修改conf/autoload_configs/xml_curl.conf.xml檔案。

<configuration name="xml_curl.conf" description="cURL XML Gateway">

<bindings>

<binding name="dialplan">

<param name="gateway-url" value="http://10.55.55.137:8080/fs/dialplan" bindings="dialplan"/>

</binding>

</bindings>

</configuration>

啟動fs,檢查啟動日志,如下。

2023-07-28 11:56:24.029966 [NOTICE] mod_xml_curl.c:543 Binding [dialplan] XML Fetch Function [http://10.55.55.137:8080/fs/dialplan] [dialplan]

2023-07-28 11:56:24.029979 [ERR] mod_xml_curl.c:459 Binding has no url!

2023-07-28 11:56:24.029994 [CONSOLE] switch_loadable_module.c:1540 Successfully Loaded [mod_xml_curl]

2023-07-28 11:56:24.030003 [NOTICE] switch_loadable_module.c:338 Adding API Function 'xml_curl'

發起呼叫,使用10011呼叫13712345678,日志如下。

2023-07-28 15:22:15.918548 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->13712345678 in context public

2023-07-28 15:22:15.918548 [ERR] mod_xml_curl.c:315 Received HTTP error 403 trying to fetch http://10.55.55.137:8080/fs/dialplan

data: [hostname=localhost.localdomain§ion=dialplan&tag_name=&key_name=&key_value=&Event-Name=REQUEST_PARAMS&Core-UUID=54544416-2d17-11ee-87f0-0d9ab89b9404&FreeSWITCH-Hostname=localhost.localdomain…

Dialplan: sofia/external/[email protected] parsing [public->test] continue=false

Dialplan: sofia/external/[email protected] Regex (PASS) [test] destination_number(13712345678) =~ /^(\d+)$/ break=on-false

Dialplan: sofia/external/[email protected] Action answer()

從日志可以看出,呼叫流程中,首先使用“mod_xml_curl”子產品擷取“http://10.55.55.137:8080/fs/dialplan”的值,擷取失敗則使用本地dialplan繼續呼叫流程。

總結

mod_xml_curl子產品功能較複雜,涉及流程較多,同時需要web伺服器提供資料接口配合。

後續嘗試使用接口傳回dialplan資料,動态控制呼叫流程。

空空如常

求真得真

繼續閱讀