Hello Konstantin,

attached patch provides a function that gets ports and stores them in an AVP variable.


However, there are other approaches to create these functions:

- A function to return each parameter (sdp_get_ip_c, sdp_get_port, etc)

- An only function sdp_get_address which return two AVP variables, IP and port for each stream.

- A generic function sdp_get_stream_info which receives an enum indicating what variable do you like and return it.

- Two functions: sdp_get_stream_count, sdp_get_stream_info(stream_num, enum_variable, pseudo_variable) First would get total number of streams (asuming one session in offer/answer way), and second function would return that variable value for a stream.


Daniel, as sdpops maintainer which approach would you rather?


Kind regards,
Vicente.

On 09/07/2012 04:37 PM, Konstantin M. wrote:
Hi Vicente,

It's my personal but I think would be good to also have another one function to extract a port of media stream. Because of no 'sdp_get_ip_c' and no something like 'sdp_get_port_c' - I have to parse sdb body by python script just to fetch IP/PORT of media stream...


2012/9/7 Vicente Hernando <[email protected] <mailto:[email protected]>>

    Hello,

    attached patch shows a new function in sdpops module: sdp_get_ip_c

    It receives as parameter an avp variable, and stores there every
    connection IP for each stream. If a stream has not c IP, then it
    returns session default one.


    Any opinion or criticism?


    Kind regards,
    Vicente.

    _______________________________________________
    sr-dev mailing list
    [email protected] <mailto:[email protected]>
    http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev




_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

diff --git modules/sdpops/sdpops_mod.c modules/sdpops/sdpops_mod.c
index 5ff359f..a38033f 100644
--- modules/sdpops/sdpops_mod.c
+++ modules/sdpops/sdpops_mod.c
@@ -50,6 +50,7 @@ static int w_sdp_remove_media(sip_msg_t* msg, char* media, char *bar);
 static int w_sdp_print(sip_msg_t* msg, char* level, char *bar);
 static int w_get_sdp(sip_msg_t* msg, char *bar);
 static int w_sdp_get_ip_c(sip_msg_t* msg, char *avp);
+static int w_sdp_get_port(sip_msg_t* msg, char *avp);
 
 static int mod_init(void);
 
@@ -80,6 +81,8 @@ static cmd_export_t cmds[] = {
 		1, 0,  0, ANY_ROUTE},
 	{"sdp_get_ip_c",               (cmd_function)w_sdp_get_ip_c,
 	    1, 0, 0, ANY_ROUTE},
+	{"sdp_get_port",               (cmd_function)w_sdp_get_port,
+	    1, 0, 0, ANY_ROUTE},
 	{"bind_sdpops",                (cmd_function)bind_sdpops,
 		1, 0, 0, 0},
 	{0, 0, 0, 0, 0, 0}
@@ -1094,6 +1097,92 @@ static int w_sdp_get_ip_c(sip_msg_t* msg, char *avp)
 /**
  *
  */
+static int w_sdp_get_port(sip_msg_t* msg, char *avp)
+{
+	sdp_info_t *sdp = NULL;
+	int sdp_session_num;
+	int sdp_stream_num;
+	sdp_session_cell_t *sdp_session;
+	sdp_stream_cell_t *sdp_stream;
+	int i;
+	int_str avp_val;
+	int_str avp_name;
+	static unsigned short avp_type = 0;
+	str s;
+	pv_spec_t *avp_spec = NULL;
+
+	s.s = avp; s.len = strlen(s.s);
+	if(pv_locate_name(&s) != s.len) {
+		LM_ERR("invalid parameter\n");
+		return -1;
+	}
+	if(((avp_spec = pv_cache_get(&s)) == NULL)
+			|| avp_spec->type!=PVT_AVP) {
+		LM_ERR("malformed or non AVP %s AVP definition\n", avp);
+		return -1;
+	}
+
+	if(pv_get_avp_name(0, &avp_spec->pvp, &avp_name, &avp_type)!=0) {
+		LM_ERR("[%s]- invalid AVP definition\n", avp);
+		return -1;
+	}
+
+	if(parse_sdp(msg) < 0) {
+		LM_ERR("Unable to parse sdp\n");
+		return -1;
+	}
+
+	sdp = (sdp_info_t*)msg->body;
+
+	if(sdp==NULL) {
+		LM_DBG("No sdp body\n");
+		return -1;
+	}
+
+	sdp_session_num = 0;
+	i = 0;
+	for(;;)
+	{
+		sdp_session = get_sdp_session_sdp(sdp, sdp_session_num);
+		if(!sdp_session) break;
+
+		sdp_stream_num = 0;
+		for(;;)
+		{
+			sdp_stream = get_sdp_stream_sdp(sdp, sdp_session_num,
+							sdp_stream_num);
+			if(!sdp_stream) break;
+
+			if(sdp_stream->port.s==NULL || sdp_stream->port.len==0)
+			{
+				LM_ERR("There is no port for stream: %d in session %d\n",
+					   sdp_stream_num, sdp_session_num);
+				return -1;
+			}
+			avp_val.s.s = sdp_stream->port.s;
+			avp_val.s.len = sdp_stream->port.len;
+			LM_DBG("Found port: %.*s\n", sdp_stream->port.len,
+				   sdp_stream->port.s);
+
+			if(add_avp(AVP_VAL_STR | avp_type, avp_name, avp_val) != 0)
+			{
+				LM_ERR("Failed to add port to avp");
+				return -1;
+			}
+			sdp_stream_num++;
+		}
+		sdp_session_num++;
+	}
+
+	if(i==0)
+		return -1;
+
+	return 0;
+}
+
+/**
+ *
+ */
 int bind_sdpops(struct sdpops_binds *sob){
 	if (sob == NULL) {
 		LM_WARN("bind_sdpops: Cannot load sdpops API into a NULL pointer\n");
_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to