Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timeout mechanism useful by adding support for supplying timeout tag #3598

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/rtpproxy/doc/rtpproxy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</editor>
</authorgroup>
<copyright>
<year>2003-2008</year>
<year>2003-2023</year>
<holder>Sippy Software, Inc.</holder>
</copyright>
<copyright>
Expand Down
38 changes: 32 additions & 6 deletions src/modules/rtpproxy/doc/rtpproxy_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
<title>Overview</title>
<para>
This is a module that enables media streams to be proxied
via an rtpproxy. Rtpproxies know to work with this module
are Sippy RTPproxy <ulink url="http://www.rtpproxy.org"></ulink>
and ngcp-rtpproxy-ng
<ulink url="http://deb.sipwise.com/spce/2.6/pool/main/n/ngcp-mediaproxy-ng"></ulink>.
Some features of the rtpproxy module apply only to one of the two rtpproxies.
via the Sippy RTPproxy <ulink url="http://www.rtpproxy.org"></ulink>.
</para>
</section>

Expand Down Expand Up @@ -235,7 +231,37 @@ modparam("rtpproxy", "nortpproxy_str", "a=sdpmangled:yes\r\n")
<title>Set <varname>timeout_socket</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpproxy", "timeout_socket", "xmlrpc:http://127.0.0.1:8000/RPC2")
modparam("rtpproxy", "timeout_socket", "tcp:127.0.0.1:8000")
...
</programlisting>
</example>
</section>
<section id="rtpproxy.p.timeout_tag_pv">
<title><varname>timeout_tag_pv</varname> (string)</title>
<para>
The parameter devines the AVP of the string to be provided to the
RTP-Proxy.
</para>
<para>
The content of the AVP must be a valid URL-encoded string with
no spaces.
It will be decoded and send by the RTP proxy to the timeout socket if the
media timeout has happened.
</para>
<para>
This parameter is required in order for the timeout notification
mechanism to work properly.
</para>
<para>
<emphasis>
Default value is <quote></quote> (nothing).
</emphasis>
</para>
<example>
<title>Set <varname>timeout_tag_pv</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpproxy", "timeout_tag_pv", "$avp(rtpp_ntag)")
...
</programlisting>
</example>
Expand Down
53 changes: 47 additions & 6 deletions src/modules/rtpproxy/rtpproxy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2003-2008 Sippy Software, Inc., http://www.sippysoft.com
* Copyright (C) 2003-2023 Sippy Software, Inc., http://www.sippysoft.com
*
* This file is part of Kamailio, a free SIP server.
*
Expand Down Expand Up @@ -187,6 +187,8 @@ static struct tm_binds tmb;
unsigned int *natping_state = 0;

static str timeout_socket_str = {0, 0};
static str timeout_tag_pv_str = {0, 0};
static pv_elem_t *timeout_tag_pv = NULL;
static pv_elem_t *extra_id_pv = NULL;

static cmd_export_t cmds[] = {
Expand Down Expand Up @@ -243,6 +245,7 @@ static param_export_t params[] = {
{"rtpproxy_retr", INT_PARAM, &rtpproxy_retr},
{"rtpproxy_tout", INT_PARAM, &rtpproxy_tout},
{"timeout_socket", PARAM_STR, &timeout_socket_str},
{"timeout_tag_pv", PARAM_STR, &timeout_tag_pv_str},
{"ice_candidate_priority_avp", PARAM_STRING,
&ice_candidate_priority_avp_param},
{"extra_id_pv", PARAM_STR, &extra_id_pv_param},
Expand Down Expand Up @@ -735,6 +738,20 @@ static int mod_init(void)
} else {
extra_id_pv = NULL;
}
if(timeout_socket_str.s != NULL && timeout_tag_pv_str.s == NULL) {
LM_ERR("The timeout_tag_pv has to be set along with timeout_socket\n");
return -1;
}
if(timeout_tag_pv_str.s != NULL) {
if(timeout_tag_pv_str.len == 0) {
LM_ERR("Empty timeout_tag_pv is not allowed\n");
return -1;
}
if(pv_parse_format(&timeout_tag_pv_str, &timeout_tag_pv) < 0) {
LM_ERR("malformed PV string: %s\n", timeout_tag_pv_str.s);
return -1;
}
}

if(rtpp_strings)
pkg_free(rtpp_strings);
Expand Down Expand Up @@ -1488,6 +1505,21 @@ static int get_extra_id(struct sip_msg *msg, str *id_str)
}


static int get_timeout_tag(struct sip_msg *msg, str *ntag_str)
{
if(msg == NULL || timeout_tag_pv == NULL || ntag_str == NULL) {
LM_ERR("bad parameters\n");
return 0;
}
if(pv_printf_s(msg, timeout_tag_pv, ntag_str) < 0) {
LM_ERR("cannot print the notify tag\n");
return 0;
}

return 1;
}


static int unforce_rtp_proxy1_f(struct sip_msg *msg, char *str1, char *str2)
{
str flags;
Expand Down Expand Up @@ -1969,6 +2001,8 @@ static int force_rtp_proxy(
{NULL, 0}, /* medianum */
{" ", 1}, /* separator */
{NULL, 0}, /* Timeout-Socket */
{" ", 1}, /* separator */
{NULL, 0}, /* Timeout-Tag */
};
int iovec_param_count;
int autobridge_ipv4v6;
Expand Down Expand Up @@ -2410,14 +2444,21 @@ static int force_rtp_proxy(
}
if(to_tag.len > 0) {
iovec_param_count = 20;
if(opts.s.s[0] == 'U' && timeout_socket_str.len > 0) {
iovec_param_count = 22;
STR2IOVEC(timeout_socket_str, v[21]);
}
} else {
iovec_param_count = 16;
}

if(opts.s.s[0] == 'U' && timeout_socket_str.len > 0) {
str ntag = {0, 0};
if(get_timeout_tag(msg, &ntag) == 0 || ntag.s == NULL
|| ntag.len == 0) {
LM_ERR("can't get timeout notification tag\n");
FORCE_RTP_PROXY_RET(-1);
}
STR2IOVEC(timeout_socket_str, v[iovec_param_count + 1]);
iovec_param_count += 2;
STR2IOVEC(ntag, v[iovec_param_count + 1]);
iovec_param_count += 2;
}
cp = send_rtpp_command(node, v, iovec_param_count);
} while(cp == NULL);
LM_DBG("proxy reply: %s\n", cp);
Expand Down
Loading