[OpenSIPS-Users] Proxy, presence and x-lite
Alexander
goal81 at gmail.com
Mon Apr 13 11:00:59 CEST 2009
Hi all!
I'm trying to make Opensips 1.4.4 work as proxy and presence server.
Proxy, with NAT support, seems to work - calls are redirected, voice is
transmitted in both directions.
Now I try to configure presence - it would be nice, if X-Lite shows user's
availability and status. So, I've got 2 questions:
1) What options regarding to presence should be configured in X-Lite
(Peer-to-peer, Presence agent)?
2) What's wrong and/or missing in my OpenSips configuration file? As I
see from logs, SUBSCRIBE, PUBLISH and NOTIFY messages are received by
OpenSips, but X-Lite does not show user's availability/status.
My OpenSips configuration file is below. Note, that authorization is done
via db_oracle, and in presence module I try to use db_berkeley. It's done
dueto some reasons.
Thanks in advance!
===============================================================================
# Run rtpproxy like this:
# /usr/local/bin/rtpproxy -l xx.xxx.xxx.xx -s udp:*:7877 -F
# For details, visit:
# - http://voip.rus.net
# - http://voip.rus.net/tiki-index.php?page=Sip+Express+Router
# ------------------ module loading ---------------------------------
# Set module path.
# ----------------
mpath="/usr/local/lib/opensips/modules/"
debug = 2
fork = yes
log_stderror = no
log_facility = LOG_DAEMON
log_name = "opensips"
listen = udp:xx.xxx.xxx.xx:5060
dns = no # (cmd. line: -r)
rev_dns = no # (cmd. line: -R)
# ------------------- Load modules ----------------------------------
loadmodule "db_oracle.so"
loadmodule "db_berkeley.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "auth.so"
loadmodule "auth_db.so"
loadmodule "uri.so"
loadmodule "uri_db.so"
loadmodule "nathelper.so"
loadmodule "nat_traversal.so"
loadmodule "textops.so"
loadmodule "dialog.so"
loadmodule "xlog.so"
loadmodule "uac.so"
loadmodule "avpops.so"
loadmodule "presence.so"
loadmodule "presence_mwi.so"
loadmodule "presence_xml.so"
loadmodule "xcap_client.so"
# ------------------- Set module-specific parameters -----------------
# usrloc params
# -------------
modparam("usrloc", "db_mode", 0)
modparam("usrloc", "nat_bflag", 6)
# nathelper params
# ----------------
modparam("nathelper", "natping_interval", 20)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "rtpproxy_sock", "udp:xx.xxx.xxx.xx:7877")
modparam("nathelper", "received_avp", "$avp(i:42)")
# nat_traversal params
# --------------------
modparam("nat_traversal", "keepalive_interval", 30)
modparam("nat_traversal", "keepalive_method", "NOTIFY")
modparam("nat_traversal", "keepalive_state_file",
"/var/run/opensips/keepalive_state")
# dialog params
# -------------
modparam("dialog", "dlg_flag", 4)
# rr params
# ---------
# add value to ;lr param to make some broken UAs happy
modparam("rr", "enable_full_lr", 1)
# auth db params
# --------------
modparam("auth_db", "db_url", "oracle://user:password@localhost
/work")
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "use_domain", 0)
# auth params
# -----------
modparam("auth", "rpid_suffix",
";party=calling;id-type=subscriber;screen=yes")
# uri db params
# -------------
modparam("uri_db", "use_uri_table", 0)
modparam("uri_db", "db_url", "")
# registrar params
# ----------------
modparam("registrar", "default_expires", 60)
modparam("registrar", "min_expires", 30)
modparam("registrar", "received_avp", "$avp(s:rcv)")
# presense params
# ---------------
modparam("presence", "db_url",
"berkeley:///usr/local/etc/opensips/db_berkeley/")
modparam("presence_xml", "force_active", 1)
modparam("presence", "server_address", "sip:xx.xxx.xxx.xx:5060")
modparam("presence", "fallback2db", 0)
modparam("presence", "presentity_table", "presentity")
modparam("presence", "active_watchers_table", "active_watchers")
modparam("presence", "watchers_table", "watchers")
modparam("presence", "clean_period", 100)
modparam("presence", "to_tag_pref", 'pres')
modparam("presence", "expires_offset", 10)
# xcap params
# -----------
modparam("xcap_client", "db_url",
"berkeley:///usr/local/etc/opensips/db_berkeley/")
modparam("xcap_client", "xcap_table","xcap")
# presense_xml params
# -------------------
modparam("presence_xml", "db_url",
"berkeley:///usr/local/etc/opensips/db_berkeley/")
modparam("presence_xml", "force_active", 0)
modparam("presence_xml", "xcap_table", "xcap")
modparam("presence_xml", "pidf_manipulation", 1)
modparam("presence_xml", "integrated_xcap_server", 1)
# ------------------------- request routing logic -------------------
# main routing logic
route
{
xlog("L_DBG", "Main route\n");
# Prevent buffer overflow.
# ------------------------
if (msg:len > max_len)
{
sl_send_reply("513", "Message Overflow");
return(0);
};
# Attempt to prevent eternal loop when failures occur.
# ----------------------------------------------------
if (!mf_process_maxfwd_header("10"))
{
sl_send_reply("483", "Too Many Hops");
return(0);
};
# Record route and NAT preset.
# ----------------------------
if (method == "INVITE" && client_nat_test("3"))
{
xlog("L_INFO", "DBG [$Tf] Got INVITE from NATed client\n");
# Put the string into Record-Route section (Switch's IP and
SIP-port).
#
-----------------------------------------------------------------------
record_route_preset("xx.xxx.xxx.xx:5060;nat=yes");
}
else if (method != "REGISTER" && method != "MESSAGE")
{
# Insert OpenSips address as a via header entry in the SIP message.
# -----------------------------------------------------------------
record_route();
}
# Call tear down.
# ---------------
if ((method == "BYE" || method == "CANCEL"))
{
xlog("L_INFO", "DBG [$Tf] Unforcing RTP proxy - call tear down\n");
# Stop RTP proxy session for current call.
# ----------------------------------------
unforce_rtp_proxy();
}
# Loose Route.
# loose_route() returns true if route headers are present.
# It also removes any route header entries that match OpenSips own
address(es).
#
-----------------------------------------------------------------------------
if (loose_route())
{
if (has_totag() && (method == "INVITE" || method == "ACK"))
{
if (client_nat_test("3") || search("^Route:.*;nat=yes"))
{
setflag(6);
force_rtp_proxy();
};
};
route(1);
return(0);
};
# Call type processing.
# ---------------------
if (uri != myself)
{
route(1);
return(0);
};
# Incoming messages handling.
# ---------------------------
if (uri == myself)
{
if (method == "BYE")
{
route(4);
return(0);
}
else if (method == "CANCEL")
{
route(4);
return(0);
}
else if (method == "INVITE")
{
route(3);
return(0);
}
else if (method == "REGISTER")
{
route(2);
return(0);
}
else if (method == "OPTIONS")
{
sl_send_reply("200", "Got it");
return(0);
}
else if (method == "SUBSCRIBE" || method == "PUBLISH" || method ==
"NOTIFY")
{
route(5);
return(0);
}
else if (method == "MESSAGE")
{
xdbg("script: message not for room, from [$fu] r-uri [$ru] msg
[$rb]\n");
if (!lookup("location"))
{
sl_send_reply("404", "not found");
return(0);
}
t_relay();
return(0);
}
};
route(1);
}
# Default Message Handling
# -----------------------
route[1]
{
xlog("L_DBG", "Route 1\n");
t_on_reply("1");
if (!t_relay())
{
if ((method == "INVITE" || method == "ACK") && isflagset(6))
{
xlog("L_INFO", "DBG [$Tf] Unforcing RTP proxy - NAT flag is set\n");
unforce_rtp_proxy();
}
sl_reply_error();
};
}
# REGISTER Message Handling
# -------------------------
route[2]
{
xlog("L_DBG", "Route 4\n");
if (!search("^Contact:\ +\*") && client_nat_test("7"))
{
xlog("L_INFO", "DBG [$Tf] Client registers behind NAT - fix URI and
force rport\n");
setflag(6);
# Create URI consisting of the source IP, port, and protocol and
store
# the URI in an Attribute-Value-Pair. The URI will be appended as
"received"
# parameter to Contact in 200 OK and registrar will store it in the
user location database.
#
-----------------------------------------------------------------------------------------
fix_nated_register();
# Add public port to the top-most Via header.
# -------------------------------------------
force_rport();
# Ping NAT endpoints to keep them alive.
# --------------------------------------
nat_keepalive();
};
sl_send_reply("100", "Trying");
# Perform authorization.
# ----------------------
if (!www_authorize("", "subscriber"))
{
www_challenge("","0");
return(0);
};
if (!check_to())
{
sl_send_reply("401", "Unauthorized");
return(0);
};
consume_credentials();
if (!save("location"))
sl_reply_error();
}
# INVITE Message Handling
# -----------------------
route[3]
{
xlog("L_DBG", "Route 3\n");
# Test for NAT, perhaps fix headers
if (client_nat_test("3"))
{
xlog("L_DBG", "DBG [$Tf] NAT detected for caller\n");
setflag(7);
force_rport();
force_rtp_proxy();
# Rewrite Contact header to contain request's source address:port.
# ----------------------------------------------------------------
fix_nated_contact();
}
xlog("L_INFO", "Vars: fd = $fd, fu = $fu, od = $od, pd = $pd, rd = $rd,
si = $si\n");
# Calls from every IP (except of TelcoBridges's one) go to TelcoBridges.
# ----------------------------------------------------------------------
if ((uri =~ "sip:*@*") && ($si != "xx.xxx.xxx.xxy"))
{
xlog("L_DBG", "DBG [$Tf] Trying to authorize caller\n");
# Perform authorization.
# ----------------------
if (!proxy_authorize("", "subscriber"))
{
proxy_challenge("", "0");
return(0);
}
else if (!check_from())
{
sl_send_reply("403", "Use From ID");
return(0);
};
consume_credentials();
xlog("L_DBG", "DBG [$Tf] Redirecting call to TelcoBridges\n");
rewritehostport("xx.xxx.xxx.xxy:5061");
route(1);
return(0);
}
# Rewrite SDP body to ensure that media is passed through an RTP proxy.
# ---------------------------------------------------------------------
force_rtp_proxy();
xlog("L_DBG", "DBG [$Tf] Try to find user in usrloc\n");
if (!lookup("location"))
{
sl_send_reply("404", "User not found, sorry");
return(0);
}
# If NAT is previously detected, proxy
if (isflagset(6) || isflagset(7))
{
xlog("L_DBG", "DBG [$Tf] NAT flag was previously set, force the use of
RTP proxy\n");
force_rtp_proxy();
}
route(1);
}
# CANCEL and BYE Message Handling
# ----------------------------------
route[4]
{
xlog("L_DBG", "Route 4\n");
if (client_nat_test("3"))
{
xlog("L_DBG", "DBG [$Tf] Handling CANCEL or BYE for NATed client,
unforcing RTP proxy\n");
setflag(7);
force_rport();
fix_nated_contact();
unforce_rtp_proxy();
};
route(1);
}
# SUBSCRIBE and PUBLISH Message Handling
# --------------------------------------
route[5]
{
xlog("L_DBG", "Route 5\n");
if (!t_newtran())
{
xlog("L_DBG", "Failed to create transaction\n");
sl_reply_error();
exit;
}
if (is_method("PUBLISH"))
{
xlog("L_DBG", "Route 5 - PUBLISH \n");
handle_publish();
t_release();
}
else if (is_method("SUBSCRIBE"))
{
xlog("L_DBG", "Route 5 - SUBSCRIBE\n");
handle_subscribe();
t_release();
}
else if (is_method("NOTIFY"))
{
xlog("L_DBG", "Route 5 - NOTIFY\n");
t_reply("200", "OK");
exit;
}
exit;
}
onreply_route[1]
{
xlog("L_DBG", "OnReply route\n");
if ((isflagset(6) || isflagset(7)) && (status =~
"(180)|(183)|2[0-9][0-9]"))
{
xlog("L_DBG", "DBG [$Tf] OnReply: NAT flags are set\n");
if (!search("^Content-Length:[ ]*0"))
{
xlog("L_DBG", "DBG [$Tf] Callee answered behind NAT, forcing RTP
proxy\n");
force_rtp_proxy();
}
};
if (nat_uac_test("19") && search("Content-Type: application/sdp"))
{
xlog("L_DBG", "DBG [$Tf] OnReply: callee is behind NAT, forcing RTP
proxy on reply\n");
force_rtp_proxy();
}
xlog("L_DBG", "DBG [$Tf] Callee has answered\n");
if (isflagset(6) || isflagset(7))
{
xlog("L_DBG", "DBG [$Tf] OnReply: callee answered behind NAT, fix
it\n");
fix_nated_contact();
};
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opensips.org/pipermail/users/attachments/20090413/04358be7/attachment-0001.htm
More information about the Users
mailing list