按照项目的需求,需要使用OpenSIPS的离线功能,现在将配置过程记录以备后用。
修改OpenSIPS的配置文件opensips.cfg添加
loadmodule "msilo.so"
#加载msilo模块
modparam("msilo", "db_table", "silo")
#配置离线消息存储的表silo
modparam("msilo", "db_url","mysql://opensips:opensipsrw@localhost/opensips")
#配置数据库路径
modparam("msilo", "add_date", 1)
#配置是否显示[offline message +时间]
modparam("msilo","content_type_hdr","Content-Type: text/plain\r\n")
#配置存储类型
#注释以下这段:
/* if ( !(is_method("REGISTER") ) ) {
if (from_uri==myself)
{
# authenticate if from local subscriber
# authenticate all initial non-REGISTER request that pretend to be
# generated by local subscriber (domain from FROM URI is local)
if (!proxy_authorize("", "subscriber")) {
proxy_challenge("", "0");
exit;
}
if (!db_check_from()) {
sl_send_reply("403","Forbidden auth ID");
exit;
}
consume_credentials();
# caller authenticated
} else {
# if caller is not local, then called number must be local
if (!uri==myself) {
send_reply("403","Rely forbidden");
exit;
}
}
}
*/
#修改一下这段
if (is_method("REGISTER"))
{
# authenticate the REGISTER requests
if (!www_authorize("", "subscriber"))
{
www_challenge("", "0");
exit;
}
if (!db_check_to())
{
sl_send_reply("403","Forbidden auth ID");
exit;
}
if ( 0 ) setflag(TCP_PERSISTENT);
if (!save("location"))
sl_reply_error();
#增加部分--start
if (m_dump()){
log("MSILO:offline message dumped\n");
}else{
log("MSILO:no offline message dumped\n");
}
#增加部分--end
exit;
}
#修改这段
if (!lookup("location","m")) {
if (!db_does_uri_exist()) {
send_reply("420","Bad Extension");
exit;
}
#从这里开始修改
if(! t_newtran()){
sl_reply_error();
exit;
}
#以下为增加部分
if (!method=="MESSAGE")
{
if (!t_reply("404", "Not found"))
{
sl_reply_error();
};
exit;
};
log("MSILO:Message received -> storing using MSILO\n");
if (m_store("$ru")){
log("MSILO:offline message stored\n");
if (!t_reply("202","Accepted")){
sl_reply_error();
};
}else{
log("MSILO:offline message NOT stroed\n");
if(!t_reply("503","Service Unavailable")){
sl_reply_error();
};
};
exit;
}
t_on_failure("1"); #增加这句
if (isbflagset(NAT)) setflag(NAT);
#在配置文件最后增加:
failure_route[1] {
# forwarding failed -- check if the request was a MESSAGE
if (!method=="MESSAGE")
{
exit;
};
log(1,"MSILO:the downstream UA doesn't support MESSAGEs\n");
# we have changed the R-URI with the contact address, ignore it now
if (m_store("$ou"))
{
log("MSILO: offline message stored\n");
t_reply("202", "Accepted");
}else{
log("MSILO: offline message NOT stored\n");
t_reply("503", "Service Unavailable");
};
}