Browse code

sdpops : added new function named as get_sdp_address_family (#1801)

- added new function as named get_sdp_address_family() to extract the IP address family from
the SDP body 'c' part. it returns:4 for IP4, 6 for IP6, -1 for error
- also added documentation about get_sdp_address_family() function
- removed commented out function sdp_remove_str_codec_id_attrs() from year 2016

Yasin CANER authored on 10/01/2019 22:08:24
Showing 2 changed files
... ...
@@ -555,7 +555,7 @@ if(sdp_with_ice()) {
555 555
 			<function moreinfo="none">sdp_get_line_startswith(avpvar, string)</function>
556 556
 		</title>
557 557
 		<para>
558
-			Store the search part of SDP body message with line beginning with 'string' in an AVP. 
558
+			Store the search part of SDP body message with line beginning with 'string' in an AVP.
559 559
 			Return 1 if 'string' is found in SDP, -1 on error and -2 if there is no SDP part in the message body.
560 560
 			The second parameter can contain pseudo-variables.
561 561
 		</para>
... ...
@@ -573,6 +573,28 @@ if(sdp_get_line_startswith("$avp(mline)", "m=")) {
573 573
 </programlisting>
574 574
 		</example>
575 575
 	</section>
576
+	<section id="sdpops.f.get_sdp_address_family">
577
+			<title>
578
+		<function moreinfo="none">get_sdp_address_family()</function>
579
+			</title>
580
+			<para>
581
+			it helps to get IP address family at c line from sdp body.
582
+			it returns -1 on error , 4 for IP4 and 6 for IP6
583
+			</para>
584
+		<example>
585
+		<title><function>get_sdp_address_family</function>usage</title>
586
+		<programlisting format="linespecific">
587
+	...
588
+	if(is_method("INVITE") && has_body("application/sdp")){
589
+
590
+		$avp(af) = get_sdp_address_family();
591
+		xlog("L_INFO","ADDRESS FAMILY OF SDP C line $avp(af) ");
592
+	}
593
+	...
594
+	</programlisting>
595
+			</example>
596
+	</section>
597
+
576 598
 	</section>
577 599
 
578 600
 	<section>
... ...
@@ -595,4 +617,3 @@ if(sdp_get_line_startswith("$avp(mline)", "m=")) {
595 595
 	</section>
596 596
 
597 597
 </chapter>
598
-
... ...
@@ -65,6 +65,7 @@ static int w_sdp_get_line_startswith(sip_msg_t* msg, char *foo, char *bar);
65 65
 
66 66
 static int sdp_get_sess_version(sip_msg_t* msg, str* sess_version, int* sess_version_num);
67 67
 static int sdp_set_sess_version(sip_msg_t* msg, str* sess_version, int* sess_version_num);
68
+static int w_get_sdp_address_family(sip_msg_t* msg);
68 69
 
69 70
 static int pv_get_sdp(sip_msg_t *msg, pv_param_t *param,
70 71
 		pv_value_t *res);
... ...
@@ -125,6 +126,8 @@ static cmd_export_t cmds[] = {
125 125
 		0, 0,  0, ANY_ROUTE},
126 126
 	{"sdp_get_line_startswith", (cmd_function)w_sdp_get_line_startswith,
127 127
 		2, fixup_none_spve,  0, ANY_ROUTE},
128
+	{"get_sdp_address_family", (cmd_function)w_get_sdp_address_family,
129
+			0, 0,  0, ANY_ROUTE},
128 130
 	{"bind_sdpops",                (cmd_function)bind_sdpops,
129 131
 		1, 0, 0, 0},
130 132
 	{0, 0, 0, 0, 0, 0}
... ...
@@ -530,28 +533,6 @@ int sdp_remove_line_by_prefix(sip_msg_t* msg, str* prefix, str* media)
530 530
 	return found;
531 531
 }
532 532
 
533
-
534
-/*
535
-
536
-int sdp_remove_str_codec_id_attrs(sip_msg_t* msg, sdp_stream_cell_t* sdp_stream, str *rm_codec)
537
-
538
-	str aline = {0, 0};
539
-	sdp_payload_attr_t *payload;
540
-	struct lump *anchor;
541
-
542
-	payload = sdp_stream->payload_attr;
543
-	while (payload) {
544
-		LM_DBG("a= ... for codec %.*s/%.*s\n",
545
-				payload->rtp_payload.len, payload->rtp_payload.s,
546
-				payload->rtp_enc.len, payload->rtp_enc.s);
547
-		if(rm_codec->len==payload->rtp_payload.len
548
-				&& strncmp(payload->rtp_payload.s, rm_codec->s,
549
-					rm_codec->len)==0) {
550
-			if(payload->rtp_enc.s!=NULL) {
551
-				if(sdp_locate_line(msg, payload->rtp_enc.s, &aline)==0)
552
-*/
553
-
554
-
555 533
 /**
556 534
  * removes all SDP lines that begin with script provided prefix
557 535
  * @return -1 - error; 1 - found
... ...
@@ -1013,6 +994,47 @@ static int w_sdp_with_active_media(sip_msg_t* msg, char* media, char *bar)
1013 1013
 }
1014 1014
 
1015 1015
 /**
1016
+	AF_INET 2
1017
+	AF_INET6 10
1018
+
1019
+it helps to extract IP adress family at c line  from sdp
1020
+	@param msg
1021
+	@return -1 for error,
1022
+			4 for  IP4,
1023
+			6 for  IP6
1024
+
1025
+*/
1026
+static int w_get_sdp_address_family(sip_msg_t *msg){
1027
+
1028
+	sdp_session_cell_t* session;
1029
+	int sdp_session_num;
1030
+	int result= -1;
1031
+	if(parse_sdp(msg) < 0) {
1032
+		LM_ERR("Unable to parse sdp body \n");
1033
+		return -1;
1034
+	}
1035
+
1036
+	sdp_session_num = 0;
1037
+
1038
+	for(;;){
1039
+
1040
+		session = get_sdp_session(msg, sdp_session_num);
1041
+		if(!session)
1042
+			break;
1043
+
1044
+		if(session->pf==AF_INET){
1045
+			result = 4;
1046
+		}else if(session->pf==AF_INET6){
1047
+			result = 6;
1048
+		}else{
1049
+			result = -1;
1050
+		}
1051
+		sdp_session_num++;
1052
+	}
1053
+
1054
+	return result;
1055
+}
1056
+/**
1016 1057
  * @brief remove streams matching the m='media'
1017 1058
  * @return -1 - error; 0 - not found; >=1 - found
1018 1059
  */