Skip to content

Commit

Permalink
rtpengine: add block_media and unblock_media function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuchs committed Sep 24, 2018
1 parent cc2714a commit 76b1f3b
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 6 deletions.
67 changes: 66 additions & 1 deletion src/modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -2592,7 +2592,17 @@ stop_recording();
&rtp; proxy, but they won't be forwarded to the receiving peer.
</para>
<para>
The call-id flag can be used to stop recording for a different call.
The call-id flag can be used to block DTMF for a different call.
</para>
<para>
Without any flags given, DTMF events will be blocked for the entire call.
It's possible to block DTMF directionally only for individual participants.
If the <quote>directional</quote> flag is given, DTMF events will be
blocked for the UA with the currently matching <quote>From</quote> tag.
Events can be blocked for a different UA either by specifying an alternative
<quote>from-tag=...</quote>, or by matching UAs against the media address
they advertised in the &sdp; using the <quote>address=...</quote> flag
(which can contain either an IPv4 or IPv6 address).
</para>
<para>
This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
Expand All @@ -2602,6 +2612,8 @@ stop_recording();
<programlisting format="linespecific">
...
block_dtmf();
block_dtmf("directional");
block_dtmf("address=192.168.42.42");
...
</programlisting>
</example>
Expand All @@ -2613,12 +2625,65 @@ block_dtmf();
</title>
<para>
Reverses the effects of a previously issued <function>block_dtmf</function> call.
See above for a description of which flags can be used.
</para>
<para>
If DTMF events were previously blocked for individual UAs, then unblocking DTMF
events for the entire call (i.e. no flags given) will not remove these blocks.
The flag <quote>all</quote> can be used to achieve this.
</para>
<example>
<title><function>unblock_dtmf</function> usage</title>
<programlisting format="linespecific">
...
unblock_dtmf();
unblock_dtmf("all");
...
</programlisting>
</example>
</section>

<section id="rtpengine.f.block_media">
<title>
<function moreinfo="none">block_media([flags])</function>
</title>
<para>
Analogous to <quote>block_dtmf</quote>, but blocks media &rtp; packets
instead of DTMF events. When media is blocked, DTMF events still pass
through the &rtp; proxy.
</para>
<para>
See <quote>block_dtmf</quote> for a description of the flags that can be used.
</para>
<example>
<title><function>block_media</function> usage</title>
<programlisting format="linespecific">
...
block_media();
block_media("directional");
block_media("address=192.168.42.42");
...
</programlisting>
</example>
</section>

<section id="rtpengine.f.unblock_media">
<title>
<function moreinfo="none">unblock_media([flags])</function>
</title>
<para>
Analogous to <quote>unblock_dtmf</quote>, but applies to media &rtp; packets instead
of DTMF events.
</para>
<para>
See <quote>unblock_dtmf</quote> for a description of the flags that can be used.
</para>
<example>
<title><function>unblock_media</function> usage</title>
<programlisting format="linespecific">
...
unblock_media();
unblock_media("all");
...
</programlisting>
</example>
Expand Down
104 changes: 99 additions & 5 deletions src/modules/rtpengine/rtpengine.c
Expand Up @@ -114,7 +114,7 @@ enum {
#define CPORT "22222"

struct ng_flags_parse {
int via, to, packetize, transport;
int via, to, packetize, transport, directional;
bencode_item_t *dict, *flags, *direction, *replace, *rtcp_mux, *sdes,
*codec, *codec_strip, *codec_offer, *codec_transcode, *codec_mask;
str call_id, from_tag, to_tag;
Expand All @@ -130,6 +130,8 @@ static const char *command_strings[] = {
[OP_STOP_RECORDING] = "stop recording",
[OP_BLOCK_DTMF] = "block DTMF",
[OP_UNBLOCK_DTMF] = "unblock DTMF",
[OP_BLOCK_MEDIA] = "block media",
[OP_UNBLOCK_MEDIA] = "unblock media",
};

struct minmax_mos_stats {
Expand Down Expand Up @@ -173,6 +175,8 @@ static int start_recording_f(struct sip_msg *, char *, char *);
static int stop_recording_f(struct sip_msg *, char *, char *);
static int block_dtmf_f(struct sip_msg *, char *, char *);
static int unblock_dtmf_f(struct sip_msg *, char *, char *);
static int block_media_f(struct sip_msg *, char *, char *);
static int unblock_media_f(struct sip_msg *, char *, char *);
static int rtpengine_answer1_f(struct sip_msg *, char *, char *);
static int rtpengine_offer1_f(struct sip_msg *, char *, char *);
static int rtpengine_delete1_f(struct sip_msg *, char *, char *);
Expand Down Expand Up @@ -305,6 +309,24 @@ static cmd_export_t cmds[] = {
{"unblock_dtmf", (cmd_function)unblock_dtmf_f, 0,
0, 0,
ANY_ROUTE},
{"block_media", (cmd_function)block_media_f, 0,
0, 0,
ANY_ROUTE },
{"unblock_media", (cmd_function)unblock_media_f, 0,
0, 0,
ANY_ROUTE},
{"block_dtmf", (cmd_function)block_dtmf_f, 1,
fixup_spve_null, 0,
ANY_ROUTE },
{"unblock_dtmf", (cmd_function)unblock_dtmf_f, 1,
fixup_spve_null, 0,
ANY_ROUTE},
{"block_media", (cmd_function)block_media_f, 1,
fixup_spve_null, 0,
ANY_ROUTE },
{"unblock_media", (cmd_function)unblock_media_f, 1,
fixup_spve_null, 0,
ANY_ROUTE},
{"rtpengine_offer", (cmd_function)rtpengine_offer1_f, 0,
0, 0,
ANY_ROUTE},
Expand Down Expand Up @@ -2076,6 +2098,7 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
if (!val.s)
goto error;
ng_flags->from_tag = val;
ng_flags->directional = 1;
}
else
goto generic;
Expand Down Expand Up @@ -2125,8 +2148,12 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
if (!ng_flags->packetize)
goto error;
bencode_dictionary_add_integer(ng_flags->dict, "repacketize", ng_flags->packetize);
goto next;
}
else if (str_eq(&key, "directional"))
ng_flags->directional = 1;
else
goto generic;
goto next;
break;

case 12:
Expand Down Expand Up @@ -2242,6 +2269,11 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
else
bencode_dictionary_add_str(ng_flags.dict, "sdp", &body);
}
else if (op == OP_BLOCK_DTMF || op == OP_BLOCK_MEDIA || op == OP_UNBLOCK_DTMF
|| op == OP_UNBLOCK_MEDIA)
{
ng_flags.flags = bencode_list(bencbuf);
}

/*** parse flags & build dictionary ***/

Expand Down Expand Up @@ -2291,7 +2323,13 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
) );
bencode_list_add_string(item, ip_addr2a(&msg->rcv.src_ip));

if ((msg->first_line.type == SIP_REQUEST && op != OP_ANSWER)
if (op == OP_BLOCK_DTMF || op == OP_BLOCK_MEDIA || op == OP_UNBLOCK_DTMF
|| op == OP_UNBLOCK_MEDIA)
{
if (ng_flags.directional)
bencode_dictionary_add_str(ng_flags.dict, "from-tag", &ng_flags.from_tag);
}
else if ((msg->first_line.type == SIP_REQUEST && op != OP_ANSWER)
|| (msg->first_line.type == SIP_REPLY && op == OP_DELETE)
|| (msg->first_line.type == SIP_REPLY && op == OP_ANSWER))
{
Expand Down Expand Up @@ -3552,13 +3590,69 @@ static int rtpengine_unblock_dtmf_wrap(struct sip_msg *msg, void *d, int more) {
static int
block_dtmf_f(struct sip_msg* msg, char *str1, char *str2)
{
return rtpengine_rtpp_set_wrap(msg, rtpengine_block_dtmf_wrap, NULL, 1);
str flags;
flags.s = NULL;
if (str1) {
if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
LM_ERR("Error getting string parameter\n");
return -1;
}
}

return rtpengine_rtpp_set_wrap(msg, rtpengine_block_dtmf_wrap, flags.s, 1);
}

static int
unblock_dtmf_f(struct sip_msg* msg, char *str1, char *str2)
{
return rtpengine_rtpp_set_wrap(msg, rtpengine_unblock_dtmf_wrap, NULL, 1);
str flags;
flags.s = NULL;
if (str1) {
if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
LM_ERR("Error getting string parameter\n");
return -1;
}
}

return rtpengine_rtpp_set_wrap(msg, rtpengine_unblock_dtmf_wrap, flags.s, 1);
}

static int rtpengine_block_media_wrap(struct sip_msg *msg, void *d, int more) {
return rtpp_function_call_simple(msg, OP_BLOCK_MEDIA, d);
}

static int rtpengine_unblock_media_wrap(struct sip_msg *msg, void *d, int more) {
return rtpp_function_call_simple(msg, OP_UNBLOCK_MEDIA, d);
}

static int
block_media_f(struct sip_msg* msg, char *str1, char *str2)
{
str flags;
flags.s = NULL;
if (str1) {
if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
LM_ERR("Error getting string parameter\n");
return -1;
}
}

return rtpengine_rtpp_set_wrap(msg, rtpengine_block_media_wrap, flags.s, 1);
}

static int
unblock_media_f(struct sip_msg* msg, char *str1, char *str2)
{
str flags;
flags.s = NULL;
if (str1) {
if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
LM_ERR("Error getting string parameter\n");
return -1;
}
}

return rtpengine_rtpp_set_wrap(msg, rtpengine_unblock_media_wrap, flags.s, 1);
}

static int rtpengine_rtpstat_wrap(struct sip_msg *msg, void *d, int more) {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/rtpengine/rtpengine.h
Expand Up @@ -40,6 +40,8 @@ enum rtpe_operation {
OP_PING,
OP_BLOCK_DTMF,
OP_UNBLOCK_DTMF,
OP_BLOCK_MEDIA,
OP_UNBLOCK_MEDIA,
};

struct rtpp_node {
Expand Down

0 comments on commit 76b1f3b

Please sign in to comment.