Skip to content

Commit

Permalink
Added extra stream filtering based on transport value
Browse files Browse the repository at this point in the history
The stream_find() and stream_delete() take an extra optional param to match the stream's transport value.
  • Loading branch information
bogdan-iancu committed Sep 21, 2021
1 parent 25188a4 commit 6ed68a5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
22 changes: 16 additions & 6 deletions modules/sipmsgops/codecs.c
Expand Up @@ -728,7 +728,8 @@ int codec_move_down(struct sip_msg* msg, str* codec, str* clock)
}


static int handle_streams(struct sip_msg* msg, regex_t* re, int delete)
static int handle_streams(struct sip_msg* msg, regex_t* re, regex_t* re2,
int delete)
{
struct sdp_session_cell *session;
struct sdp_stream_cell *stream;
Expand Down Expand Up @@ -761,14 +762,23 @@ static int handle_streams(struct sip_msg* msg, regex_t* re, int delete)
stream->media.s[stream->media.len] = 0;
match = regexec( re, stream->media.s, 1, &pmatch, 0) == 0;
stream->media.s[stream->media.len] = temp;
/* optionally check the transport in stream also */
if (match && re2) {
temp = stream->transport.s[stream->transport.len];
stream->transport.s[stream->transport.len] = 0;
match = regexec( re2, stream->transport.s, 1, &pmatch, 0) == 0;
stream->transport.s[stream->transport.len] = temp;
}
if (match) break;
}
}

if (!match)
return -1;

LM_DBG(" found stream [%.*s]\n",stream->media.len,stream->media.s);
LM_DBG(" found stream media [%.*s], transport [%.*s]\n",
stream->media.len,stream->media.s,
stream->transport.len,stream->transport.s);

/* stream found */
if (!delete)
Expand Down Expand Up @@ -825,15 +835,15 @@ static int handle_streams(struct sip_msg* msg, regex_t* re, int delete)
}


int stream_find(struct sip_msg* msg, regex_t* re)
int stream_find(struct sip_msg* msg, regex_t* re, regex_t* re2)
{
return handle_streams(msg, re, 0);
return handle_streams(msg, re, re2, 0);
}


int stream_delete(struct sip_msg* msg, regex_t* re)
int stream_delete(struct sip_msg* msg, regex_t* re, regex_t* re2)
{
return handle_streams(msg, re, 1);
return handle_streams(msg, re, re2, 1);
}


Expand Down
4 changes: 2 additions & 2 deletions modules/sipmsgops/codecs.h
Expand Up @@ -38,8 +38,8 @@ int codec_delete_except_re(struct sip_msg* msg, regex_t* re);
int codec_move_up_re(struct sip_msg* msg, regex_t* re);
int codec_move_down_re(struct sip_msg* msg, regex_t* re);

int stream_find(struct sip_msg* msg, regex_t* re);
int stream_delete(struct sip_msg* msg, regex_t* re);
int stream_find(struct sip_msg* msg, regex_t* re, regex_t* re2);
int stream_delete(struct sip_msg* msg, regex_t* re, regex_t* re2);



Expand Down
16 changes: 14 additions & 2 deletions modules/sipmsgops/doc/sipmsgops_admin.xml
Expand Up @@ -1324,7 +1324,7 @@ onreply_route {

<section id="func_stream_exists" xreflabel="stream_exists()">
<title>
<function moreinfo="none">stream_exists(regexp)</function>
<function moreinfo="none">stream_exists(regexp[,regexp2])</function>
</title>
<para>
This function can be used to verify if a stream exists inside an
Expand All @@ -1339,6 +1339,11 @@ onreply_route {
to match the stream media name.
</para>
</listitem>
<listitem>
<para><emphasis>regexp2</emphasis> - an optional POSIX regular
expression to match the stream transport name.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
Expand All @@ -1351,13 +1356,15 @@ onreply_route {
# check for FAX
stream_exists("image");
...
stream_exists("audio","SAVP");
...
</programlisting>
</example>
</section>

<section id="func_stream_delete" xreflabel="stream_delete()">
<title>
<function moreinfo="none">stream_delete(regexp)</function>
<function moreinfo="none">stream_delete(regexp[,regexp2])</function>
</title>
<para>
This function can be used to delete a whole stream from inside an
Expand All @@ -1373,6 +1380,11 @@ stream_exists("image");
to match the stream media name.
</para>
</listitem>
<listitem>
<para><emphasis>regexp2</emphasis> - an optional POSIX regular
expression to match the stream transport name.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
Expand Down
6 changes: 4 additions & 2 deletions modules/sipmsgops/sipmsgops.c
Expand Up @@ -238,11 +238,13 @@ static cmd_export_t cmds[]={
ONREPLY_ROUTE },

{"stream_exists", (cmd_function)stream_find, {
{CMD_PARAM_REGEX, 0, 0}, {0, 0, 0}},
{CMD_PARAM_REGEX, 0, 0},
{CMD_PARAM_REGEX|CMD_PARAM_OPT, 0, 0}, {0, 0, 0}},
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},

{"stream_delete", (cmd_function)stream_delete, {
{CMD_PARAM_REGEX, 0, 0}, {0, 0, 0}},
{CMD_PARAM_REGEX, 0, 0},
{CMD_PARAM_REGEX|CMD_PARAM_OPT, 0, 0}, {0, 0, 0}},
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},

{"list_hdr_has_option", (cmd_function)list_hdr_has_option, {
Expand Down

0 comments on commit 6ed68a5

Please sign in to comment.