FreeSWITCH使用mysql儲存使用者

2021-09-24 18:09:28 字數 2229 閱讀 9445

為什麼80%的碼農都做不了架構師?>>>

freeswitch預設是採用/directory資料夾下的xml來配置使用者的,對於後期開發來說是非常不方便的,所以本文來實現使用mysql來儲存使用者,並用lua指令碼來接管使用者驗證,步驟如下

一、配置odbc

二、建立資料庫

#建立使用者表

create table `user` (

`id` int(11) not null auto_increment,

`user` varchar(10) default null,

`password` varchar(30) default null,

primary key (`id`),

) engine=innodb auto_increment=19 default charset=utf8;

#插入兩個使用者

insert into user (user,password) values('8001','123456')

insert into user (user,password) values('8002','123456')

三、將使用者驗證轉接到lua指令碼

1、將freeswitch/conf/autoload_configs/lua.conf.xml中的兩行**修改為如下所示

2、讓lua指令碼接管使用者註冊驗證,這裡呼叫的指令碼是freeswitch/script/gen_dir_user_xml.lua內容如下,預設無該指令碼,需自行建立

freeswitch.consolelog("notice","lua take the users...\n");

local req_domain = params:getheader("domain")

local req_key = params:getheader("key")

local req_user = params:getheader("user")

local req_password = params:getheader("pass")

freeswitch.consolelog("notice","start connect db...\r\n");

local dbh = freeswitch.dbh("freeswitch","root","123456");

assert(dbh:connected());

dbh:query("select password from user where user="..req_user,function(row)

freeswitch.consolelog("notice","db select password="..string.format("%s\n",row.password))

req_password=string.format("%s",row.password)

end);

dbh:release();

freeswitch.consolelog("notice","info:"..req_domain.."--"..req_key.."--"..req_user.."--"..req_password.."\n");

if req_domain ~= nil and req_key ~= nil and req_user ~= nil then

xml_string =

[[<?xml version="1.0" encoding="utf-8" standalone="no"?>

]]else

xml_string =

[[<?xml version="1.0" encoding="utf-8" standalone="no"?>

]]end

freeswitch.consolelog("notice", "debug from gen_dir_user_xml.lua, generated xml:\n" .. xml_string .. "\n");

3、修改freeswitch/conf/directory/default.xml中的一部分內容,使得通過xml驗證使用者的功能失效,這樣lua才能真正接管使用者註冊,刪除的內容如下:

四、測試

使用sip軟**(zoiper、eyebeam等)來測試8001、或8002是否能正常登陸,可登陸即為配置成功

freeswitch 使用記錄

當新建 new 乙個channel時,它首先會進行初始化 init 然後進入路由 routing 階段,也就是我們 查詢解析dialplan的階段。在這裡,要注意乙個專門的術語 hunting 在傳統的交換機裡,它譯為選線,在這 裡我就譯為選路吧 找到合適的路由入口後,hunting會執行 exec...

freeswitch 使用外部directory

freeswitch 例子中提供了靜態檔案的directory 實際應用中都是從資料庫載入的 配置方法如下 1.首先要開啟 mod xml curl 模組 quote quote 2.配置 xml curl.conf檔案 配置了乙個 dialplan閘道器和乙個directory 閘道器 quote...

FreeSWITCH使用MySQL配置

freeswith預設使用sqlite作為資料庫,但是很多時候我們需要使用mysql等資料庫作為伺服器資料庫使用。這裡以mysql為例介紹相關配置 yum install mysql connector odbc.x86 64 unixodbc devel.x86 64vim etc odbc.in...