Skip to content

Commit

Permalink
modules/rtpengine: return the new SDP in an AVP
Browse files Browse the repository at this point in the history
if the new module param `write_sdp_pv` is set to a valid $avp() or $var()
specifier, the SDP returned by rtpengine in the offer/answer operations is
returned in the specified pv instead of the message body
  • Loading branch information
camilleoudot committed Feb 9, 2015
1 parent d60f014 commit e625224
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
20 changes: 20 additions & 0 deletions modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -257,6 +257,26 @@ modparam("rtpengine", "setid_avp", "$avp(setid)")
...
modparam("rtpengine", "force_send_interface", "10.3.7.123")
...
</programlisting>
</example>
</section>
<section id="rtpengine.p.write_sdp_avp">
<title><varname>write_sdp_avp</varname> (string)</title>
<para>
If this parameter is set to a valid AVP specifier, the
SDP returned by rtpengine in the offer/answer operations
is returned in the specified SDP instead of the
message body.
</para>
<para>
There is no default value.
</para>
<example>
<title>Set <varname>write_sdp_avp</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpengine", "write_sdp_avp", "$avp(sdp)")
...
</programlisting>
</example>
</section>
Expand Down
47 changes: 39 additions & 8 deletions modules/rtpengine/rtpengine.c
Expand Up @@ -211,8 +211,13 @@ static int *rtpp_socks = 0;
static int setid_avp_type;
static int_str setid_avp;

static str write_sdp_pvar_str = {NULL, 0};
static pv_spec_t* write_sdp_pvar = NULL;


char* force_send_ip_str="";


typedef struct rtpp_set_link {
struct rtpp_set *rset;
pv_spec_t *rpv;
Expand Down Expand Up @@ -282,6 +287,7 @@ static param_export_t params[] = {
{"setid_avp", PARAM_STRING, &setid_avp_param },
{"force_send_interface", PARAM_STRING, &force_send_ip_str },
{"rtp_inst_pvar", PARAM_STR, &rtp_inst_pv_param },
{"write_sdp_pv", PARAM_STR, &write_sdp_pvar_str },
{0, 0, 0}
};

Expand Down Expand Up @@ -853,6 +859,16 @@ mod_init(void)
setid_avp_type = avp_flags;
}

if (write_sdp_pvar_str.len > 0) {
write_sdp_pvar = pv_cache_get(&write_sdp_pvar_str);
if (write_sdp_pvar == NULL
|| (write_sdp_pvar->type != PVT_AVP && write_sdp_pvar->type != PVT_SCRIPTVAR) ) {
LM_ERR("write_sdp_pv: not a valid AVP or VAR definition <%.*s>\n",
write_sdp_pvar_str.len, write_sdp_pvar_str.s);
return -1;
}
}

if (rtpp_strings)
pkg_free(rtpp_strings);

Expand Down Expand Up @@ -1962,6 +1978,7 @@ rtpengine_offer_answer(struct sip_msg *msg, const char *flags, int op, int more)
bencode_item_t *dict;
str body, newbody;
struct lump *anchor;
pv_value_t pv_val;

dict = rtpp_function_call_ok(&bencbuf, msg, op, flags, &body);
if (!dict)
Expand All @@ -1978,14 +1995,28 @@ rtpengine_offer_answer(struct sip_msg *msg, const char *flags, int op, int more)
if (more)
body_intermediate = newbody;
else {
anchor = del_lump(msg, body.s - msg->buf, body.len, 0);
if (!anchor) {
LM_ERR("del_lump failed\n");
goto error_free;
}
if (!insert_new_lump_after(anchor, newbody.s, newbody.len, 0)) {
LM_ERR("insert_new_lump_after failed\n");
goto error_free;
if (write_sdp_pvar!= NULL) {
pv_val.rs = newbody;
pv_val.flags = PV_VAL_STR;

if (write_sdp_pvar->setf(msg,&write_sdp_pvar->pvp, (int)EQ_T, &pv_val) < 0)
{
LM_ERR("error setting pvar <%.*s>\n", write_sdp_pvar_str.len, write_sdp_pvar_str.s);
goto error_free;
}

pkg_free(newbody.s);

} else {
anchor = del_lump(msg, body.s - msg->buf, body.len, 0);
if (!anchor) {
LM_ERR("del_lump failed\n");
goto error_free;
}
if (!insert_new_lump_after(anchor, newbody.s, newbody.len, 0)) {
LM_ERR("insert_new_lump_after failed\n");
goto error_free;
}
}
}

Expand Down

0 comments on commit e625224

Please sign in to comment.