[OpenSER-Devel] [ openser-Feature Requests-1835933 ] mediaproxy module does not rewrite a=rtcp:12345

SourceForge.net noreply at sourceforge.net
Sun Dec 30 14:11:02 UTC 2007


Feature Requests item #1835933, was opened at 2007-11-21 23:58
Message generated for change (Comment added) made by rubel001
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743023&aid=1835933&group_id=139143

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: modules
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Aron Rosenberg (amr42)
Assigned to: Nobody/Anonymous (nobody)
Summary: mediaproxy module does not rewrite a=rtcp:12345

Initial Comment:
When using the mediaproxy module it does not update the SDP if a a=rtcp line is added under a m= line. a=rtcp is defined in RFC 3605.

The same might be true with the nathelper module, but we don't use that so I can't verify.

Example (before processing by mediaproxy)

m=audio 10000 RTP/AVP 0
a=rtcp:10001

After processing (actual)

m=audio 60320 RTP/AVP 0
a=rtcp:10001

(Expected)

m=audio 60320 RTP/AVP 0
a=rtcp:60321



----------------------------------------------------------------------

Comment By: Salahuddin Ahmed (rubel001)
Date: 2007-12-30 20:11

Message:
Logged In: YES 
user_id=1953307
Originator: NO

I am using BlackCat with nathelper module. The rtcp port of sdp message is
not rewrite also in this module. I make a simple patch which can do this
work. To test this I using SIPp and test some cases. I find that most of
user agent is not use this attribute line. When any user agent is not use
this line then this patch log some error message and the function will
exited without rewrite sdp message that's why I use a flag(p or P) to
enable this feature which need to set when we need this line, as Default
this is false. We use this flag in the 'force_rtp_proxy' function like
force_rtp_proxy("p"). I think this will work for you.

Patch:
==========================================================
--- nathelper.c	2007-12-13 19:38:40.000000000 +0600
+++ nathelper_my_patch.c	2007-12-30 18:59:15.000000000 +0600
@@ -274,7 +274,7 @@
 static int extract_mediaip(str *, str *, int *, char *);
 static int extract_mediaport(str *, str *);
 static int alter_mediaip(struct sip_msg *, str *, str *, int, str *, int,
int);
-static int alter_mediaport(struct sip_msg *, str *, str *, str *, int);
+static int alter_mediaport(struct sip_msg *, str *, str *, str *, int,
int);
 static char *gencookie();
 static int rtpp_test(struct rtpp_node*, int, int);
 static char *send_rtpp_command(struct rtpp_node*, struct iovec *, int);
@@ -1729,6 +1729,37 @@
 }
 
 static int
+extract_rtcp_port( char *p, char *plimit, str *oldport)
+{
+  static char rtcp_line_head[8]="a=rtcp:";
+  char *cp, *cp1;
+  int len;
+
+  oldport->s=NULL;
+  oldport->len=0;
+  cp1 = NULL;
+  cp=p;
+  for(;;){
+    if(cp>=plimit)
+      return -1;
+    if((cp1=ser_memmem( cp, rtcp_line_head, plimit-cp, 7))==NULL){
+      return -1;
+    }
+    if (cp1[-1] == '\n' || cp1[-1] == '\r'){
+      oldport->s = cp1 + 7; /* scip 'a=rtcp:' */
+      len = eat_line( oldport->s,
+		      plimit-oldport->s) - oldport->s;
+      oldport->len = eat_token_end( oldport->s,
+				    oldport->s+len)-oldport->s;
+      return 1;
+    }
+    if (plimit - cp1 < 7)
+      return -1;
+    cp = cp1 + 7;
+  }
+}
+
+static int
 extract_mediaport(str *body, str *mediaport)
 {
 	char *cp, *cp1;
@@ -1889,7 +1920,7 @@
 
 static int
 alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str
*newport,
-  int preserve)
+  int preserve, int alter_rtcp_port)
 {
 	char *buf;
 	int offset;
@@ -1955,7 +1986,32 @@
 		pkg_free(buf);
 		return -1;
 	}
-
+	/* Alter RTCP port */
+	if(alter_rtcp_port == 1){
+	  newport++;
+	  oldport++;
+	
+	  if(oldport->len > 0 && oldport->s != NULL){
+	    buf = pkg_malloc(newport->len);
+	    if (buf == NULL) {
+	      LM_ERR("out of pkg memory\n");
+	      return -1;
+	    }
+	    offset = oldport->s - msg->buf;
+	    anchor = del_lump(msg, offset, oldport->len, 0);
+	    if (anchor == NULL) {
+	      LM_ERR("del_lump failed\n");
+	      pkg_free(buf);
+	      return -1;
+	    }
+	    memcpy(buf, newport->s, newport->len);
+	    if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) {
+	      LM_ERR("insert_new_lump_after failed\n");
+	      pkg_free(buf);
+	      return -1;
+	    }
+	  }
+	}
 #if 0
 	msg->msg_flags |= FL_SDP_PORT_AFS;
 #endif
@@ -2326,10 +2382,10 @@
 static int
 force_rtp_proxy2_f(struct sip_msg* msg, char* str1, char* str2)
 {
-	str body, body1, oldport, oldip, newport, newip;
+	str body, body1, oldport[2], oldip, newport[2], newip;
 	str callid, from_tag, to_tag, tmp;
 	int create, port, len, asymmetric, flookup, argc, proxied, real;
-	int orgip, commip;
+	int orgip, commip, attrb_rtcp;
 	int oidx, pf, pf1, force, swap;
 	char opts[16];
 	char *cp, *cp1;
@@ -2362,7 +2418,7 @@
 	int c1p_altered;
 
 	v[1].iov_base=opts;
-	asymmetric = flookup = force = real = orgip = commip = swap = 0;
+	asymmetric = flookup = force = real = orgip = commip = attrb_rtcp = swap
= 0;
 	oidx = 1;
 	for (cp = str1; *cp != '\0'; cp++) {
 		switch (*cp) {
@@ -2418,6 +2474,11 @@
 			opts[oidx++] = 'S';
 			break;
 
+		case 'p':
+		case 'P':
+		  attrb_rtcp = 1;
+		  break;
+
 		default:
 			LM_ERR("unknown option `%c'\n", *cp);
 			return -1;
@@ -2572,10 +2633,18 @@
 			}
 			tmpstr1.s = m1p;
 			tmpstr1.len = m2p - m1p;
-			if (extract_mediaport(&tmpstr1, &oldport) == -1) {
+			if (extract_mediaport(&tmpstr1, &oldport[0]) == -1) {
 				LM_ERR("can't extract media port from the message\n");
 				return -1;
 			}
+
+			if(attrb_rtcp == 1){
+			  if (extract_rtcp_port( m1p, m2p, &oldport[1]) == -1) {
+			    LM_ERR("can't extract media rtcp port from the message\n");
+			    return -1;
+			  }
+			}
+
 			++medianum;
 			if (asymmetric != 0 || real != 0) {
 				newip = oldip;
@@ -2592,7 +2661,7 @@
 			v[1].iov_len = oidx;
 			STR2IOVEC(callid, v[3]);
 			STR2IOVEC(newip, v[5]);
-			STR2IOVEC(oldport, v[7]);
+			STR2IOVEC(oldport[0], v[7]);
 			STR2IOVEC(from_tag, v[9]);
 			if (1 || media_multi) /* XXX netch: can't choose now*/
 			{
@@ -2655,7 +2724,8 @@
 				newip.len = strlen(newip.s);
 			}
 			/* marker to double check : newport goes: str -> int -> str ?!?! */
-			newport.s = int2str(port, &newport.len); /* beware static buffer */
+			newport[0].s = strdup(int2str(port, &newport[0].len));/* beware static
buffer */
+			newport[1].s = strdup(int2str(port+1, &newport[1].len));
 			/* Alter port. */
 			body1.s = m1p;
 			body1.len = bodylimit - body1.s;
@@ -2664,11 +2734,16 @@
 			 *   by returning also 0
 			 * - or by not sending to rtpproxy the old port if 0
 			 */
-			if(oldport.len!=1 || oldport.s[0]!='0')
+			if(oldport[0].len!=1 || oldport[0].s[0]!='0')
 			{
-				if (alter_mediaport(msg, &body1, &oldport, &newport, 0) == -1)
-					return -1;
+			  if (alter_mediaport(msg, &body1, oldport, newport, 0, attrb_rtcp) ==
-1){
+			    free(newport[0].s);
+			    free(newport[1].s);
+			    return -1;
+			  }
 			}
+			free(newport[0].s);
+			free(newport[1].s);
 			/*
 			 * Alter IP. Don't alter IP common for the session
 			 * more than once.

==========================================================
Regards,
Salahuddin Ahmed

----------------------------------------------------------------------

Comment By: Dan (dan_pascu)
Date: 2007-11-22 02:28

Message:
Logged In: YES 
user_id=1296758
Originator: NO

I consider this a feature request not a bug, so it was moved accordingly.
Patches are welcome.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743023&aid=1835933&group_id=139143



More information about the Devel mailing list