Skip to content

Commit 22b7f9c

Browse files
committed
rtp_relay: add caller/callee pvars
Thanks to @sindy39 for reporting and testing. Close #3884
1 parent 6ab5ee1 commit 22b7f9c

2 files changed

Lines changed: 113 additions & 17 deletions

File tree

modules/rtp_relay/doc/rtp_relay_admin.xml

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
in-dialog requests. These flags can be specified through the
2525
<xref linkend="pv_rtp_relay"/> and/or
2626
<xref linkend="pv_rtp_relay_peer"/> variables at initial INVITE,
27-
and are then passed along with the RTP relay context until
28-
the end of the call. They can also be modified during sequential
29-
in-dialog requests.
27+
or through the absolute
28+
<xref linkend="pv_rtp_relay_caller"/> and
29+
<xref linkend="pv_rtp_relay_callee"/> variables, and are then
30+
passed along with the RTP relay context until the end of the call.
31+
They can also be modified during sequential in-dialog requests.
3032
</para>
3133
<para>
3234
This is not a stand-alone module that communicates directly with RTP relays,
@@ -791,8 +793,10 @@ route[rtp_relay_copy_delete] {
791793
</para>
792794
<para>
793795
The RTP session modifiers used are the ones provisioned through the
794-
<xref linkend="pv_rtp_relay"/> and/or
795-
<xref linkend="pv_rtp_relay_peer"/> variables.
796+
<xref linkend="pv_rtp_relay"/>,
797+
<xref linkend="pv_rtp_relay_peer"/>,
798+
<xref linkend="pv_rtp_relay_caller"/> and/or
799+
<xref linkend="pv_rtp_relay_callee"/> variables.
796800
</para>
797801
<para>
798802
The function can be called from the main request route - in this case
@@ -801,6 +805,18 @@ route[rtp_relay_copy_delete] {
801805
the branch where it was called, or that has an associated
802806
<emphasis>rtp_relay</emphasis> provisioned.
803807
</para>
808+
<para>
809+
When using the scope-relative <xref linkend="pv_rtp_relay"/>
810+
variable together with this function, note that its meaning depends
811+
on where it is used. In the main request route of the initial INVITE,
812+
<xref linkend="pv_rtp_relay"/> refers to the caller and
813+
<xref linkend="pv_rtp_relay_peer"/> refers to the callee. In a
814+
branch route, <xref linkend="pv_rtp_relay"/> refers to the callee
815+
branch and <xref linkend="pv_rtp_relay_peer"/> refers to the
816+
caller. To avoid depending on this route scope, use
817+
<xref linkend="pv_rtp_relay_caller"/> and
818+
<xref linkend="pv_rtp_relay_callee"/> instead.
819+
</para>
804820
<para>Meaning of the parameters is as follows:</para>
805821
<itemizedlist>
806822
<listitem>
@@ -1022,16 +1038,22 @@ $ opensips-cli -x mi rtp_relay:update_callid callid=1-3758963@127.0.0.1 \
10221038
<title><varname>$rtp_relay</varname></title>
10231039
<para>
10241040
Is used to provision the RTP back-end flags for the
1025-
current peer - if used in the initial INVITE
1026-
REQUEST route, it provisions the flags of the
1027-
caller, whereas if used in the initial INVITE BRANCH/REPLY
1028-
route, it provisions the callee's flags.
1041+
current peer. This variable is scope-relative: in the
1042+
main request route of the initial INVITE it provisions
1043+
the caller, while in the branch route or replies of the
1044+
initial INVITE transaction it provisions the callee branch.
10291045
</para>
10301046
<para>
10311047
For a sequential request, the variable represents the
10321048
flags used for the UAC that generated the request. When
10331049
used in a reply, the other UAC's flags are provisioned.
10341050
</para>
1051+
<para>
1052+
Use <xref linkend="pv_rtp_relay_caller"/> and
1053+
<xref linkend="pv_rtp_relay_callee"/> when the script
1054+
needs to address the caller or callee side directly,
1055+
independent of the route scope.
1056+
</para>
10351057
<para>
10361058
In an initial INVITE scope, the variable can be
10371059
provisioned per branch, by using the variable's index.
@@ -1080,6 +1102,40 @@ $ opensips-cli -x mi rtp_relay:update_callid callid=1-3758963@127.0.0.1 \
10801102
current one. All other fields are similar.
10811103
</para>
10821104
</section>
1105+
<section id="pv_rtp_relay_caller" xreflabel="$rtp_relay_caller">
1106+
<title><varname>$rtp_relay_caller</varname></title>
1107+
<para>
1108+
This variable has the same parameters as
1109+
<xref linkend="pv_rtp_relay"/>, but always provisions
1110+
the caller side of the RTP relay session, independent of
1111+
the route where it is used.
1112+
</para>
1113+
<para>
1114+
In the main request route of the initial INVITE this is
1115+
equivalent to <xref linkend="pv_rtp_relay"/>. In a branch
1116+
route or in replies of the initial INVITE transaction this
1117+
is equivalent to <xref linkend="pv_rtp_relay_peer"/>.
1118+
After the dialog is established, it addresses the stored
1119+
caller leg directly.
1120+
</para>
1121+
</section>
1122+
<section id="pv_rtp_relay_callee" xreflabel="$rtp_relay_callee">
1123+
<title><varname>$rtp_relay_callee</varname></title>
1124+
<para>
1125+
This variable has the same parameters as
1126+
<xref linkend="pv_rtp_relay"/>, but always provisions
1127+
the callee side of the RTP relay session, independent of
1128+
the route where it is used.
1129+
</para>
1130+
<para>
1131+
In the main request route of the initial INVITE this is
1132+
equivalent to <xref linkend="pv_rtp_relay_peer"/>. In a
1133+
branch route or in replies of the initial INVITE
1134+
transaction this is equivalent to
1135+
<xref linkend="pv_rtp_relay"/>. After the dialog is
1136+
established, it addresses the stored callee leg directly.
1137+
</para>
1138+
</section>
10831139
<section id="pv_rtp_relay_ctx" xreflabel="$rtp_relay_ctx">
10841140
<title><varname>$rtp_relay_ctx()</varname></title>
10851141
<para>
@@ -1113,4 +1169,3 @@ $ opensips-cli -x mi rtp_relay:update_callid callid=1-3758963@127.0.0.1 \
11131169
</section>
11141170
</section>
11151171
</chapter>
1116-

modules/rtp_relay/rtp_relay.c

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
#include "rtp_relay_ctx.h"
2929
#include "rtp_relay.h"
3030

31-
#define RTP_RELAY_PV_PEER 0x1
32-
#define RTP_RELAY_PV_VAR 0x2
31+
#define RTP_RELAY_PV_PEER 0x1
32+
#define RTP_RELAY_PV_VAR 0x2
33+
#define RTP_RELAY_PV_CALLER 0x4
34+
#define RTP_RELAY_PV_CALLEE 0x8
35+
#define RTP_RELAY_PV_LEG_MASK \
36+
(RTP_RELAY_PV_PEER|RTP_RELAY_PV_CALLER|RTP_RELAY_PV_CALLEE)
3337

3438
static int pv_parse_rtp_relay_var(pv_spec_p sp, const str *in);
3539
static int pv_get_rtp_relay_var(struct sip_msg *msg, pv_param_t *param,
@@ -134,6 +138,12 @@ static const pv_export_t mod_pvars[] = {
134138
{ str_const_init("rtp_relay_peer"), 2005, pv_get_rtp_relay_var,
135139
pv_set_rtp_relay_var, pv_parse_rtp_relay_var,
136140
pv_parse_rtp_relay_index, pv_init_rtp_relay_var, RTP_RELAY_PV_PEER},
141+
{ str_const_init("rtp_relay_caller"), 2007, pv_get_rtp_relay_var,
142+
pv_set_rtp_relay_var, pv_parse_rtp_relay_var,
143+
pv_parse_rtp_relay_index, pv_init_rtp_relay_var, RTP_RELAY_PV_CALLER},
144+
{ str_const_init("rtp_relay_callee"), 2008, pv_get_rtp_relay_var,
145+
pv_set_rtp_relay_var, pv_parse_rtp_relay_var,
146+
pv_parse_rtp_relay_index, pv_init_rtp_relay_var, RTP_RELAY_PV_CALLEE},
137147
{ str_const_init("rtp_relay_ctx"), 2006, pv_get_rtp_relay_ctx,
138148
pv_set_rtp_relay_ctx, pv_parse_rtp_relay_ctx,
139149
NULL, NULL, 0},
@@ -411,6 +421,7 @@ static struct rtp_relay_leg *pv_get_rtp_relay_leg(struct sip_msg *msg,
411421
struct rtp_relay_leg *leg, *peer;
412422
pv_value_t flags_name;
413423
int idx = RTP_RELAY_ALL_BRANCHES;
424+
int leg_sel, use_peer;
414425
str tag;
415426

416427
*flag = RTP_RELAY_FLAGS_UNKNOWN;
@@ -448,7 +459,27 @@ static struct rtp_relay_leg *pv_get_rtp_relay_leg(struct sip_msg *msg,
448459
}
449460
/* identify the leg in question */
450461
leg = rtp_relay_get_leg(ctx, &tag, idx);
451-
if (param->pvn.type) { /* looking for its peer */
462+
463+
leg_sel = param->pvn.type & RTP_RELAY_PV_LEG_MASK;
464+
if (leg_sel == RTP_RELAY_PV_CALLER || leg_sel == RTP_RELAY_PV_CALLEE) {
465+
if (ctx->established) {
466+
leg = ctx->established->legs[
467+
leg_sel == RTP_RELAY_PV_CALLER ?
468+
RTP_RELAY_CALLER : RTP_RELAY_CALLEE];
469+
if (!leg)
470+
return NULL;
471+
goto flags;
472+
}
473+
474+
if (leg_sel == RTP_RELAY_PV_CALLER)
475+
use_peer = (route_type == BRANCH_ROUTE || route_type == ONREPLY_ROUTE);
476+
else
477+
use_peer = !(route_type == BRANCH_ROUTE || route_type == ONREPLY_ROUTE);
478+
} else {
479+
use_peer = (leg_sel == RTP_RELAY_PV_PEER);
480+
}
481+
482+
if (use_peer) { /* looking for its peer */
452483
if (ctx->established) {
453484
if (!leg)
454485
return NULL;
@@ -457,15 +488,24 @@ static struct rtp_relay_leg *pv_get_rtp_relay_leg(struct sip_msg *msg,
457488
return NULL;
458489
}
459490
leg = leg->peer;
460-
} else if (!leg) {
461-
LM_ERR("no leg identified, so cannot figure out peer\n");
462-
return NULL;
463491
} else {
492+
if (!leg) {
493+
if (!set || leg_sel == RTP_RELAY_PV_PEER) {
494+
LM_ERR("no leg identified, so cannot figure out peer\n");
495+
return NULL;
496+
}
497+
leg = rtp_relay_new_leg(ctx, &tag, idx);
498+
if (!leg) {
499+
LM_ERR("cannot create a new leg\n");
500+
return NULL;
501+
}
502+
}
503+
464504
peer = rtp_relay_get_peer_leg(ctx, leg);
465505
if (!peer) {
466506
if (!set)
467507
return NULL;
468-
if (route_type == BRANCH_ROUTE)
508+
if (route_type == BRANCH_ROUTE || route_type == ONREPLY_ROUTE)
469509
tag = get_from(msg)->tag_value;
470510
else
471511
tag = get_to(msg)->tag_value;
@@ -490,6 +530,7 @@ static struct rtp_relay_leg *pv_get_rtp_relay_leg(struct sip_msg *msg,
490530
}
491531
}
492532

533+
flags:
493534
if (param->pvn.type & RTP_RELAY_PV_VAR) {
494535
if (pv_get_spec_value(msg, (pv_spec_p)param->pvi.u.dval, &flags_name) < 0)
495536
LM_ERR("cannot get the name of the RTP relay variable\n");

0 commit comments

Comments
 (0)