[sr-dev] git:master:e6252246: modules/rtpengine: return the new SDP in an AVP

Camille Oudot camille.oudot at orange.com
Mon Feb 9 16:42:02 CET 2015


Module: kamailio
Branch: master
Commit: e6252246ea8056e06115d82a57372c8f241164a2
URL: https://github.com/kamailio/kamailio/commit/e6252246ea8056e06115d82a57372c8f241164a2

Author: Camille Oudot <camille.oudot at orange.com>
Committer: Camille Oudot <camille.oudot at orange.com>
Date: 2015-02-09T13:51:27+01:00

modules/rtpengine: return the new SDP in an AVP

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

---

Modified: modules/rtpengine/doc/rtpengine_admin.xml
Modified: modules/rtpengine/rtpengine.c

---

Diff:  https://github.com/kamailio/kamailio/commit/e6252246ea8056e06115d82a57372c8f241164a2.diff
Patch: https://github.com/kamailio/kamailio/commit/e6252246ea8056e06115d82a57372c8f241164a2.patch

---

diff --git a/modules/rtpengine/doc/rtpengine_admin.xml b/modules/rtpengine/doc/rtpengine_admin.xml
index 4a1ea6f..7a01b0d 100644
--- a/modules/rtpengine/doc/rtpengine_admin.xml
+++ b/modules/rtpengine/doc/rtpengine_admin.xml
@@ -260,6 +260,26 @@ 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>
 
 	<section id="rtpengine.p.rtp_inst_pvar">
 		<title><varname>rtp_inst_pvar</varname> (string)</title>
diff --git a/modules/rtpengine/rtpengine.c b/modules/rtpengine/rtpengine.c
index 5ff6f36..ff9223d 100644
--- a/modules/rtpengine/rtpengine.c
+++ b/modules/rtpengine/rtpengine.c
@@ -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;
@@ -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}
 };
 
@@ -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);
 
@@ -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)
@@ -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;
+			}
 		}
 	}
 




More information about the sr-dev mailing list