概述
freeswitch有非常多的周边模块,给我们供应各种各样的功能,有些功能在适当的场景下可以极大的方便我们的开拓和运用。
本日我们先容一个不常用的模块mod_xml_rpc。
freeswitch自身内置有http做事器模块,而mod_xml_rpc模块供应了一种非常方便的访问fs内部API接口的办法:通过webapi办法访问,并且可以做到和fs命令行一样的效果。

我们只须要在freeswitch的配置文件中打开一些默认配置,就可以很方便的利用该功能。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.8.7
GCC:4.8.5
安装mod_xml_rpc模块
freeswitch的源码安装支配请参照之前的文章。
mod_xml_rpc模块在fs编译安装过程中,默认是有编译安装的,不须要额外的操作步骤。
cd /usr/local/freeswitch/modll-rwxr-xr-x. 1 root root 1642704 8月 17 09:59 mod_xml_rpc.so-rwxr-xr-x. 1 root root 1347 8月 17 09:59 mod_xml_rpc.la
mod_xml_rpc模块默认安装,但是在默认配置中是没有启动的,我想该当是出于安全的考虑,毕竟大多数利用fs的职员在不清楚mod_xml_rpc的功能的情形下,是有安全风险的。
修正freeswitch模块加载文件,启动加载mod_xml_rpc模块
cd /usr/local/freeswitch/conf/autoload_configsvi modules.conf.xml<!-- XML Interfaces --><load module="mod_xml_rpc"/>
查看xml_rpc模块配置文件,个中有http端口配置,默认是8080,其余有fs的鉴权信息,如果不做修端正接打开了公网的端口,有很大的安全风险。
[root@localhost autoload_configs]# cat xml_rpc.conf.xml<configuration name="xml_rpc.conf" description="XML RPC"><settings><!-- The port where you want to run the http service (default 8080) --><param name="http-port" value="8080"/><!-- if all 3 of the following params exist all http traffic will require auth --><param name="auth-realm" value="freeswitch"/><param name="auth-user" value="freeswitch"/><param name="auth-pass" value="works"/><!-- regex pattern to match against commands called against this service.If a command with arguments matches, it will be logged at INFO level --><!--<param name="commands-to-log" value=""/> --></settings></configuration>
利用浏览器打开http://192.168.0.152:8080/,用户名密码利用xml_rpc.conf.xml文件中的配置,查看如图
利用浏览器打开http://192.168.0.152:8080/webapi/status,查看如图,和直接在命令行中利用status命令返复书息同等
利用curl办法调用fs的webapi接口
[root@localhost ~]# curl --user freeswitch:works http://192.168.0.152:8080/webapi/status<h1>FreeSWITCH Status</h1>2021-09-22 13:47:12<br>UP 0 years, 0 days, 2 hours, 15 minutes, 55 seconds, 38 milliseconds, 425 microseconds<br>FreeSWITCH (Version 1.8.7 64bit) is ready<br>0 session(s) since startup<br>0 session(s) - peak 0, last 5min 0 <br>0 session(s) per Sec out of max 30, peak 0, last 5min 0 <br>1000 session(s) max<br>min idle cpu 0.00/99.87<br>Current Stack Size/Max 240K/8192K
利用curl办法调用fs的自定义接口task,并附带参数test1 1234,mod_task模块代码见之前的文章
[root@localhost ~]# curl --user freeswitch:works http://192.168.0.152:8080/webapi/task?test1%201234task api test1, cmd:test1 1234, session:(nil)
freeswitch的mod_xml_prc模块在某些场景中有大用途,通过webapi办法调用fs内部api很方便,同时也要考虑到安全方面的风险。
freeswitch内部的API供应给外部调用的办法还是挺多的,后续我们再逐步先容。
末了,freeswitch通过webapi办法访问自定义API合营访问自定义模块的代码逻辑,可以深入研究一下。
fs官方文档:
https://freeswitch.org/confluence/display/FREESWITCH/mod_xml_rpc
空空如常
求真得真