[sr-dev] git:master: rpproxy: new function rtpproxy_manage()

Daniel-Constantin Mierla miconda at gmail.com
Sat May 28 10:17:52 CEST 2011


Module: sip-router
Branch: master
Commit: 7b7791c3e578e57ab33e9381d876ac3cf9103b8b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7b7791c3e578e57ab33e9381d876ac3cf9103b8b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sat May 28 08:57:19 2011 +0200

rpproxy: new function rtpproxy_manage()

- auto-pilot function to handle rtp proxy session management
- it can take same kind of parameters as rtpproxy_offer()
- embeds the functionality of rtpproxy_offer(), rtpproxy_answer() and
  unfroce_rtp_proxy():
  - if INVITE with SDP, then do rtpproxy offer
  - if INVITE with sdp, when tm is loaded, mark transaction with
	internal flag FL_SDP_BODY to know that the 1xx and 2xx are for rtp
	answer
  - if ACK with SDP, then do rtpproxy answer
  - if BYE or CANCEL, then do unforce rtpproxy
  - if reply to INVITE with code >= 300 do unfrce rtp proxy
  - if reply with SDP to INVITE having code 1xx and 2xx, then do rtpproxy
	answer if the request had SDP or tm is not loaded, otherwise do
	rtpproxy offer

---

 modules/rtpproxy/rtpproxy.c |  101 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c
index 23a8a2d..15cfcc1 100644
--- a/modules/rtpproxy/rtpproxy.c
+++ b/modules/rtpproxy/rtpproxy.c
@@ -219,6 +219,7 @@
 #include "../../socket_info.h"
 #include "../../mod_fix.h"
 #include "../../dset.h"
+#include "../../modules/tm/tm_load.h"
 #include "rtpproxy.h"
 #include "rtpproxy_funcs.h"
 #include "rtpproxy_stream.h"
@@ -290,6 +291,9 @@ static int rtpproxy_answer1_f(struct sip_msg *, char *, char *);
 static int rtpproxy_answer2_f(struct sip_msg *, char *, char *);
 static int rtpproxy_offer1_f(struct sip_msg *, char *, char *);
 static int rtpproxy_offer2_f(struct sip_msg *, char *, char *);
+static int rtpproxy_manage0(struct sip_msg *msg, char *flags, char *ip);
+static int rtpproxy_manage1(struct sip_msg *msg, char *flags, char *ip);
+static int rtpproxy_manage2(struct sip_msg *msg, char *flags, char *ip);
 
 static int add_rtpproxy_socks(struct rtpp_set * rtpp_list, char * rtpproxy);
 static int fixup_set_id(void ** param, int param_no);
@@ -334,6 +338,9 @@ static unsigned int rtpp_no = 0;
 static int *rtpp_socks = 0;
 
 
+/* tm */
+static struct tm_binds tmb;
+
 /*0-> disabled, 1 ->enabled*/
 unsigned int *natping_state=0;
 
@@ -379,6 +386,15 @@ static cmd_export_t cmds[] = {
 	{"rtpproxy_stop_stream2uas",(cmd_function)rtpproxy_stop_stream2uas2_f,0,
 		NULL, 0,
 		ANY_ROUTE },
+	{"rtpproxy_manage",	(cmd_function)rtpproxy_manage0,     0,
+		0, 0,
+		ANY_ROUTE},
+	{"rtpproxy_manage",	(cmd_function)rtpproxy_manage1,     1,
+		0, 0,
+		ANY_ROUTE},
+	{"rtpproxy_manage",	(cmd_function)rtpproxy_manage2,     2,
+		0, 0,
+		ANY_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -860,6 +876,12 @@ mod_init(void)
 	if (rtpp_strings)
 		pkg_free(rtpp_strings);
 
+	if (load_tm_api( &tmb ) < 0)
+	{
+		LM_DBG("could not load the TM-functions - answer-offer model"
+				" auto-detection is disabled\n");
+		memset(&tmb, 0, sizeof(struct tm_binds));
+	}
 
 	return 0;
 }
@@ -1663,6 +1685,85 @@ set_rtp_proxy_set_f(struct sip_msg * msg, char * str1, char * str2)
 }
 
 static int
+rtpproxy_manage(struct sip_msg *msg, char *flags, char *ip)
+{
+	char *cp = NULL;
+	char newip[IP_ADDR_MAX_STR_SIZE];
+	int method;
+	int nosdp;
+
+	if(msg->cseq==NULL && ((parse_headers(msg, HDR_CSEQ_F, 0)==-1)
+				|| (msg->cseq==NULL)))
+	{
+		LM_ERR("no CSEQ header\n");
+		return -1;
+	}
+
+	method = get_cseq(msg)->method_id;
+
+	if(!(method==METHOD_INVITE || method==METHOD_ACK || method==METHOD_CANCEL
+				|| method==METHOD_BYE))
+		return -1;
+
+	if(method==METHOD_CANCEL || method==METHOD_BYE)
+		return unforce_rtp_proxy_f(msg, 0, 0);
+
+	if(ip==NULL)
+	{
+		cp = ip_addr2a(&msg->rcv.dst_ip);
+		strcpy(newip, cp);
+	}
+
+	nosdp = parse_sdp(msg);
+
+	if(msg->first_line.type == SIP_REQUEST) {
+		if(method==METHOD_ACK && nosdp==0)
+			return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0,
+					(ip!=NULL)?1:0);
+		if(method==METHOD_INVITE && nosdp==0) {
+			msg->msg_flags |= FL_SDP_BODY;
+			if(tmb.t_gett!=NULL && tmb.t_gett()!=NULL)
+				tmb.t_gett()->uas.request->msg_flags |= FL_SDP_BODY;
+			return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1,
+					(ip!=NULL)?1:0);
+		}
+	} else if(msg->first_line.type == SIP_REPLY) {
+		if(msg->first_line.u.reply.statuscode>=300)
+			return unforce_rtp_proxy_f(msg, 0, 0);
+		if(nosdp==0) {
+			if(tmb.t_gett==NULL || tmb.t_gett()==NULL
+					|| tmb.t_gett()==T_UNDEFINED)
+				return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0,
+					(ip!=NULL)?1:0);
+			if(tmb.t_gett()->uas.request->msg_flags & FL_SDP_BODY)
+				return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 0,
+					(ip!=NULL)?1:0);
+			return force_rtp_proxy(msg, flags, (cp!=NULL)?newip:ip, 1,
+					(ip!=NULL)?1:0);
+		}
+	}
+	return -1;
+}
+
+static int
+rtpproxy_manage0(struct sip_msg *msg, char *flags, char *ip)
+{
+	return rtpproxy_manage(msg, 0, 0);
+}
+
+static int
+rtpproxy_manage1(struct sip_msg *msg, char *flags, char *ip)
+{
+	return rtpproxy_manage(msg, flags, 0);
+}
+
+static int
+rtpproxy_manage2(struct sip_msg *msg, char *flags, char *ip)
+{
+	return rtpproxy_manage(msg, flags, ip);
+}
+
+static int
 rtpproxy_offer1_f(struct sip_msg *msg, char *str1, char *str2)
 {
         char *cp;




More information about the sr-dev mailing list