Hi,
 
I have a working OpenSER Proxy to asterisk and would like the proxy server to handle Presence.
 
I have tried adding all of the usual presence code, however it seams that messages are not getting back to the clients. I can see time outs in the SIP messages.
 
Can anyone see what has gone wrong with this code?
 
The setup is:
 
Calls & Registrations:
 
Client --> OpenSER --> Asterisk
 
SIP Messages & Presence:
 
Client --> OpenSER
 
Thank you for your help in advance.
 
Ross
 
----------------------------- CONFIG ----------------------
# ----------- global configuration parameters ------------------------
debug=3 # debug level (cmd line: -dddddddddd)
fork=yes
log_stderror=yes # (cmd line: -E)
#/* Uncomment these lines to enter debugging mode
#fork=no
#log_stderror=yes
#*/
check_via=yes # (cmd. line: -v)
dns=no # (cmd. line: -r)
rev_dns=no # (cmd. line: -R)
listen=udp:<IP>:5065
#port=5065
children=4
# --- module loading
mpath="/usr/local/lib64/openser/modules/"
loadmodule "mysql.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "nathelper.so"
loadmodule "auth.so"
loadmodule "auth_db.so"
loadmodule "mi_fifo.so"
loadmodule "presence.so"
loadmodule "presence_xml.so"
loadmodule "xcap_client.so"
loadmodule "avpops.so"
#loadmodule "siptrace.so"
# --- setting module parameters
# -- mi_fifo params --
modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
modparam("usrloc|auth_db|presence|presence_xml|xcap_client","db_url","mysql://openser:openserrw@<address>/openser")
# -- usrloc params --
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "nat_bflag", 6)
# -- registrar params --
modparam("registrar|nathelper", "received_avp", "$avp(i:42)")
# -- auth params --
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
# -- rr params --
modparam("rr", "enable_full_lr", 1)
# -- nathelper params ---
modparam("nathelper", "rtpproxy_sock", "udp:127.0.0.1:7890")
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 7)
modparam("nathelper", "sipping_from", "sip:<address>")
# -- presence parameters ---
modparam("presence", "max_expires", 3600)
modparam("presence", "server_address", "sip:<IP>:5065" )
modparam("xcap_client", "periodical_query", 0)
modparam("xcap_client", "query_period", 50)
modparam("presence_xml", "integrated_xcap_server", 1)
#modparam("presence_xml", "xcap_server", "")
modparam("presence","fallback2db",1)
#modparam("siptrace", "trace_flag", 0)
#modparam("siptrace", "trace_on", 1)
#modparam("siptrace", "table", "sip_trace")
 
 
# --- main routing logic
route
{
######################################################
# CHECK FOR BAD SIP MESSAGES #
######################################################
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
};
if (msg:len >= 2048 ) {
sl_send_reply("513", "Message too big");
exit;
};
 
######################################################
# CHECK FOR CLIENT BEHIND A NAT ROUTER #
######################################################
route(2);
if (!method=="REGISTER")
record_route();
######################################################
# PROCESS SUBSCRIBE & NOTIFY MESSAGES #
######################################################
if(method=="PUBLISH")
{
route(4);
}
if(method=="SUBSCRIBE")
{
route(4);
}
 
if (loose_route()) {
append_hf("P-hint: rr-enforced\r\n");
route(1);
};
#####################################################
# SAVE LOCATION OF CLIENT FOR MESSAGES #
#####################################################
if (method=="REGISTER")
{
save("location","0x02");
}

####################################################
# CHECK IF REGISTERED LOCALY ELSE PASS TO ASTERISK #
####################################################
if (!lookup("location"))
{
append_hf("P-hint: outbound\r\n");
}
else
{
append_hf("P-hint: usrloc applied\r\n");
}

route(1);
}
 
route[1] {
if (subst_uri('/(sip:.*);nat=yes/\1/')){
setbflag(6);
};
if (isflagset(5)||isbflagset(6)) {
route(3);
}
if (!t_relay()) {
sl_reply_error();
};
exit;
}
route[2]{
force_rport();
if (nat_uac_test("19")) {
if (method=="REGISTER") {
fix_nated_register();
} else {
fix_nated_contact();
};
setflag(5);
};
}
 
route[3] {
if (is_method("BYE"))
{
unforce_rtp_proxy();
}
else if (is_method("INVITE"))
{
force_rtp_proxy();
t_on_failure("2");
};
if (isflagset(5))
{
search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
}
t_on_reply("1");
}
route[4]
{
# absorb retransmissions
if (! t_newtran())
{
sl_reply_error();
exit;
};

if(is_method("PUBLISH"))
{
if($hdr(Sender)!= NULL)
{
handle_publish("$hdr(Sender)");
}
else
{
handle_publish();
}
t_release();
}
if(is_method("SUBSCRIBE"))
{
handle_subscribe();
t_release();
};

exit;
}
branch_route[4]
{
log("new branch at $ru\n");
}
 
onreply_route[4]
{
log("incoming reply\n");
}
failure_route[2] {
if (isbflagset(6) || isflagset(5))
{
unforce_rtp_proxy();
}
}
onreply_route[1]
{
if ((isflagset(5) || isbflagset(6)) && status=~"(183)|(2[0-9][0-9])" && is_method("INVITE"))
{
force_rtp_proxy();
}
search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
if (isbflagset(6)) {
fix_nated_contact();
}
exit;
}
 
 
 


Get Started!