请声明出处:http://blog.csdn.net/u012377333/article/details/46332615
说明:本文从代码层面配合配置文件叙述Yate的文件认证方式
Yate认证方式--文件认证(Regfile)
从官网或者网上的介绍Yate的Blog上面,大致都可以了解到Yate的认证方式有三种:文件认证(regfile.cpp)方式、 Radius 方式、数据库方式;同时最新的Yate对数据库的支持类型也更多了,有MySql、PgSql、Sqlite;
加载模块regfile
INIT_PLUGIN(RegfilePlugin); //这个就是静态的加载文件认证插件(RegfilePlugin)
注册模块regfile
class RegfilePlugin : public Plugin
{
public:
RegfilePlugin();
~RegfilePlugin();
virtual void initialize();
void populate(bool first);
private:
bool m_init;
};
在构造函数中,注册了插件regfile
RegfilePlugin::RegfilePlugin()
: Plugin("regfile"),
m_init(false)
{
Output("Loaded module Registration from file");
}
初始化模块regfile
函数重载,重新定义了模块的初始化函数initialize()
void RegfilePlugin::initialize()
{
Output("Initializing module Register from file");
Lock lock(s_mutex);
s_cfg.load();
bool first = !m_init;
if (!m_init) {
m_init = true;
s_create = s_cfg.getBoolValue("general","autocreate",false);
String conf = s_cfg.getValue("general","file");
Engine::self()->runParams().replaceParams(conf);
if (conf) {
s_accounts = conf;
s_accounts.load();
}
Engine::install(new AuthHandler("user.auth",s_cfg.getIntValue("general","auth",100)));
Engine::install(new RegistHandler("user.register",s_cfg.getIntValue("general","register",100)));
Engine::install(new UnRegistHandler("user.unregister",s_cfg.getIntValue("general","register",100)));
Engine::install(new RouteHandler("call.route",s_cfg.getIntValue("general","route",100)));
Engine::install(new StatusHandler("engine.status"));
Engine::install(new CommandHandler("engine.command"));
Engine::install(new ExpireHandler());
}
populate(first);
}
接受消息
卸载模块regfile
析构函数,在释放所有资源之前,保存了配置文件
RegfilePlugin::~RegfilePlugin()
{
Output("Unload module Registration from file");
if (s_accounts)
s_accounts.save();
}