[sr-dev] git:master: core: sdp parser

Ovidiu Sas osas at voipembedded.com
Fri Jun 25 19:54:34 CEST 2010


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

Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date:   Fri Jun 25 13:59:15 2010 -0400

core: sdp parser

 - added support for session common IP and session origin IP

---

 parser/sdp/sdp.c |   45 +++++++++++++++++++++++++++++++++++++++++----
 parser/sdp/sdp.h |    6 ++++++
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/parser/sdp/sdp.c b/parser/sdp/sdp.c
index 367651b..11aa8f1 100644
--- a/parser/sdp/sdp.c
+++ b/parser/sdp/sdp.c
@@ -396,7 +396,7 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 	}
 	/* get session origin */
 	o1p = find_sdp_line(v1p, bodylimit, 'o');
-	if (o1p==0) {
+	if (o1p == NULL) {
 		LM_ERR("no o= in session\n");
 		return -1;
 	}
@@ -408,12 +408,29 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 	}
 	/* Allocate a session cell */
 	session = add_sdp_session(_sdp, session_num, cnt_disp);
-	if (session == 0) return -1;
+	if (session == NULL) return -1;
+
+	/* Get origin IP */
+	tmpstr1.s = o1p;
+	tmpstr1.len = bodylimit - tmpstr1.s; /* limit is session limit text */
+	if (extract_mediaip(&tmpstr1, &session->o_ip_addr, &session->o_pf,"o=") == -1) {
+		LM_ERR("can't extract origin media IP from the message\n");
+		return -1;
+	}
 
 	/* Find c1p only between session begin and first media.
 	 * c1p will give common c= for all medias. */
 	c1p = find_sdp_line(o1p, m1p, 'c');
 
+	if (c1p) {
+		tmpstr1.s = c1p;
+		tmpstr1.len = bodylimit - tmpstr1.s; /* limit is session limit text */
+		if (extract_mediaip(&tmpstr1, &session->ip_addr, &session->pf,"c=") == -1) {
+			LM_ERR("can't extract common media IP from the message\n");
+			return -1;
+		}
+	}
+
 	/* Find b1p only between session begin and first media.
 	 * b1p will give common b= for all medias. */
 	b1p = find_sdp_line(o1p, m1p, 'b');
@@ -1080,8 +1097,12 @@ sdp_session_cell_t * clone_sdp_session_cell(sdp_session_cell_t *session)
 		LM_ERR("arg:NULL\n");
 		return NULL;
 	}
-	len = sizeof(sdp_session_cell_t) + session->cnt_disp.len +
-		session->bw_type.len + session->bw_width.len;
+	len = sizeof(sdp_session_cell_t) +
+		session->cnt_disp.len +
+		session->ip_addr.len +
+		session->o_ip_addr.len +
+		session->bw_type.len +
+		session->bw_width.len;
 	clone_session = (sdp_session_cell_t*)shm_malloc(len);
 	if (clone_session == NULL) {
 		LM_ERR("no more shm mem (%d)\n",len);
@@ -1111,6 +1132,8 @@ sdp_session_cell_t * clone_sdp_session_cell(sdp_session_cell_t *session)
 	}
 
 	clone_session->session_num = session->session_num;
+	clone_session->pf = session->pf;
+	clone_session->o_pf = session->o_pf;
 	clone_session->streams_num = session->streams_num;
 
 	if (session->cnt_disp.len) {
@@ -1120,6 +1143,20 @@ sdp_session_cell_t * clone_sdp_session_cell(sdp_session_cell_t *session)
 		p += session->cnt_disp.len;
 	}
 
+	if (session->ip_addr.len) {
+		clone_session->ip_addr.s = p;
+		clone_session->ip_addr.len = session->ip_addr.len;
+		memcpy( p, session->ip_addr.s, session->ip_addr.len);
+		p += session->ip_addr.len;
+	}
+
+	if (session->o_ip_addr.len) {
+		clone_session->o_ip_addr.s = p;
+		clone_session->o_ip_addr.len = session->o_ip_addr.len;
+		memcpy( p, session->o_ip_addr.s, session->o_ip_addr.len);
+		p += session->o_ip_addr.len;
+	}
+
 	if (session->bw_type.len) {
 		clone_session->bw_type.s = p;
 		clone_session->bw_type.len = session->bw_type.len;
diff --git a/parser/sdp/sdp.h b/parser/sdp/sdp.h
index 481afec..c26a568 100644
--- a/parser/sdp/sdp.h
+++ b/parser/sdp/sdp.h
@@ -76,6 +76,12 @@ typedef struct sdp_session_cell {
 	struct sdp_session_cell *next;
 	int session_num;  /**< session index inside sdp */
 	str cnt_disp;     /**< the Content-Disposition header (for Content-Type:multipart/mixed) */
+	/* c=<network type> <address type> <connection address> */
+	int pf;		/**< connection address family: AF_INET/AF_INET6 */
+	str ip_addr;	/**< connection address */
+	/* o=<username> <session id> <version> <network type> <address type> <address> */
+	int o_pf;	/**< origin address family: AF_INET/AF_INET6 */
+	str o_ip_addr;	/**< origin address */
 	/* b=<bwtype>:<bandwidth> */
 	str bw_type;      /**< alphanumeric modifier giving the meaning of the <bandwidth> figure:
 				CT - conference total;




More information about the sr-dev mailing list