Просмотр исходного кода

sdpops: allow setting a mediatype (e.g. video or audio), when removing a codec from the SDP

Carsten Bock 9 лет назад
Родитель
Сommit
5fffc9bd84
2 измененных файлов с 65 добавлено и 24 удалено
  1. 12 2
      modules/sdpops/doc/sdpops_admin.xml
  2. 53 22
      modules/sdpops/sdpops_mod.c

+ 12 - 2
modules/sdpops/doc/sdpops_admin.xml

@@ -68,7 +68,7 @@
 	<title>Functions</title>
 	<section id="sdpops.f.remove_codecs_by_id">
 	    <title>
-		<function moreinfo="none">sdp_remove_codecs_by_id(list)</function>
+		<function moreinfo="none">sdp_remove_codecs_by_id(list [, mtype])</function>
 	    </title>
 	    <para>
 			Remove the codecs provided in the parameter 'list' from all
@@ -88,13 +88,15 @@
 sdp_remove_codecs_by_id("0");
 # remove PCMU, PCMA and GSM
 sdp_remove_codecs_by_id("0,8,3");
+sdp_remove_codecs_by_id("17", "audio");
+sdp_remove_codecs_by_id("23", "video");
 ...
 </programlisting>
 	    </example>
 	</section>
 	<section id="sdpops.f.remove_codecs_by_name">
 	    <title>
-		<function moreinfo="none">sdp_remove_codecs_by_name(list)</function>
+		<function moreinfo="none">sdp_remove_codecs_by_name(list [, mtype])</function>
 	    </title>
 	    <para>
 			Remove the codecs provided in the parameter 'list' from all
@@ -102,6 +104,10 @@ sdp_remove_codecs_by_id("0,8,3");
 			be one item or a comma separated list of codec names. The
 			parameter can be a static string or a variable holding the
 			list of codec names.
+	    </para>
+		<para>
+			Optional parameter mtype can be provided to apply the operations
+			only to the streams matching m=mtype.
 	    </para>
 		<para>
 			This function can be used from ANY_ROUTE.
@@ -126,6 +132,10 @@ sdp_remove_codecs_by_name("PCMU,PCMA,GSM");
 			Remove all SDP attribute lines beginning with 'string'
 			in all media streams.
 	</para>
+		<para>
+			Optional parameter mtype can be provided to apply the operations
+			only to the streams matching m=mtype.
+	    </para>
 	<para>
 			This function can be used from ANY_ROUTE.
 	</para>

+ 53 - 22
modules/sdpops/sdpops_mod.c

@@ -43,10 +43,10 @@
 MODULE_VERSION
 
 static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* bar);
-static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char *bar);
-static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char *bar);
-static int w_sdp_keep_codecs_by_id(sip_msg_t* msg, char* codecs, char *bar);
-static int w_sdp_keep_codecs_by_name(sip_msg_t* msg, char* codecs, char *bar);
+static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char *media);
+static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char *media);
+static int w_sdp_keep_codecs_by_id(sip_msg_t* msg, char* codecs, char *media);
+static int w_sdp_keep_codecs_by_name(sip_msg_t* msg, char* codecs, char *media);
 static int w_sdp_with_media(sip_msg_t* msg, char* media, char *bar);
 static int w_sdp_with_active_media(sip_msg_t* msg, char* media, char *bar);
 static int w_sdp_with_transport(sip_msg_t* msg, char* transport, char *bar);
@@ -75,8 +75,12 @@ static cmd_export_t cmds[] = {
 		1, fixup_spve_null,  0, ANY_ROUTE},
 	{"sdp_remove_codecs_by_id",    (cmd_function)w_sdp_remove_codecs_by_id,
 		1, fixup_spve_null,  0, ANY_ROUTE},
+	{"sdp_remove_codecs_by_id",    (cmd_function)w_sdp_remove_codecs_by_id,
+		2, fixup_spve_spve,  0, ANY_ROUTE},
 	{"sdp_remove_codecs_by_name",  (cmd_function)w_sdp_remove_codecs_by_name,
 		1, fixup_spve_null,  0, ANY_ROUTE},
+	{"sdp_remove_codecs_by_name",    (cmd_function)w_sdp_remove_codecs_by_name,
+		2, fixup_spve_spve,  0, ANY_ROUTE},
 	{"sdp_keep_codecs_by_id",    (cmd_function)w_sdp_keep_codecs_by_id,
 		1, fixup_spve_null,  0, ANY_ROUTE},
 	{"sdp_keep_codecs_by_id",    (cmd_function)w_sdp_keep_codecs_by_id,
@@ -317,7 +321,7 @@ int sdp_remove_str_codec_id(sip_msg_t* msg, str *allcodecs, str* rmcodec)
 /**
  *
  */
-int sdp_remove_codecs_by_id(sip_msg_t* msg, str* codecs)
+int sdp_remove_codecs_by_id(sip_msg_t* msg, str* codecs, str* media)
 {
 	sdp_info_t *sdp = NULL;
 	int sdp_session_num;
@@ -357,19 +361,26 @@ int sdp_remove_codecs_by_id(sip_msg_t* msg, str* codecs)
 			LM_DBG("stream %d of %d - payloads [%.*s]\n",
 					sdp_stream_num, sdp_session_num,
 					sdp_stream->payloads.len, sdp_stream->payloads.s);
-			sdp_codecs = sdp_stream->payloads;
-			tmp_codecs = *codecs;
-			while(str_find_token(&tmp_codecs, &rm_codec, ',')==0
-					&& rm_codec.len>0)
+
+			if((media==NULL) || (media->len==0)
+					|| (media->len==sdp_stream->media.len
+						&& strncasecmp(sdp_stream->media.s, media->s,
+							media->len)==0))
 			{
-				tmp_codecs.len -=(int)(&rm_codec.s[rm_codec.len]-tmp_codecs.s);
-				tmp_codecs.s = rm_codec.s + rm_codec.len;
-
-				LM_DBG("codecs [%.*s] - remove [%.*s]\n",
-						sdp_codecs.len, sdp_codecs.s,
-						rm_codec.len, rm_codec.s);
-				sdp_remove_str_codec_id(msg, &sdp_codecs, &rm_codec);
-				sdp_remove_str_codec_id_attrs(msg, sdp_stream, &rm_codec);
+				sdp_codecs = sdp_stream->payloads;
+				tmp_codecs = *codecs;
+				while(str_find_token(&tmp_codecs, &rm_codec, ',')==0
+						&& rm_codec.len>0)
+				{
+					tmp_codecs.len -=(int)(&rm_codec.s[rm_codec.len]-tmp_codecs.s);
+					tmp_codecs.s = rm_codec.s + rm_codec.len;
+
+					LM_DBG("codecs [%.*s] - remove [%.*s]\n",
+							sdp_codecs.len, sdp_codecs.s,
+							rm_codec.len, rm_codec.s);
+					sdp_remove_str_codec_id(msg, &sdp_codecs, &rm_codec);
+					sdp_remove_str_codec_id_attrs(msg, sdp_stream, &rm_codec);
+				}
 			}
 			sdp_stream_num++;
 		}
@@ -501,7 +512,7 @@ static int w_sdp_remove_line_by_prefix(sip_msg_t* msg, char* prefix, char* bar)
 /**
  *
  */
-static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char* bar)
+static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char* media)
 {
 	str lcodecs = {0, 0};
 
@@ -517,6 +528,15 @@ static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char* bar)
 		return -1;
 	}
 
+	if(media!=NULL)
+	{
+		if(fixup_get_svalue(msg, (gparam_p)media, &lmedia)!=0)
+		{
+			LM_ERR("unable to get the media type\n");
+			return -1;
+		}
+	}
+
 	if(sdp_remove_codecs_by_id(msg, &lcodecs)<0)
 		return -1;
 	return 1;
@@ -525,7 +545,7 @@ static int w_sdp_remove_codecs_by_id(sip_msg_t* msg, char* codecs, char* bar)
 /**
  *
  */
-int sdp_remove_codecs_by_name(sip_msg_t* msg, str* codecs)
+int sdp_remove_codecs_by_name(sip_msg_t* msg, str* codecs, str* media)
 {
 	sdp_info_t *sdp = NULL;
 	str idslist;
@@ -548,7 +568,7 @@ int sdp_remove_codecs_by_name(sip_msg_t* msg, str* codecs)
 	if(sdpops_build_ids_list(sdp, codecs, &idslist)<0)
 		return -1;
 
-	if(sdp_remove_codecs_by_id(msg, &idslist)<0)
+	if(sdp_remove_codecs_by_id(msg, &idslist, media)<0)
 		return -1;
 
 	return 0;
@@ -558,9 +578,10 @@ int sdp_remove_codecs_by_name(sip_msg_t* msg, str* codecs)
 /**
  *
  */
-static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char* bar)
+static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char* media)
 {
 	str lcodecs = {0, 0};
+	str lmedia = {0, 0};
 
 	if(codecs==0)
 	{
@@ -574,8 +595,18 @@ static int w_sdp_remove_codecs_by_name(sip_msg_t* msg, char* codecs, char* bar)
 		return -1;
 	}
 
-	if(sdp_remove_codecs_by_name(msg, &lcodecs)<0)
+	if(media!=NULL)
+	{
+		if(fixup_get_svalue(msg, (gparam_p)media, &lmedia)!=0)
+		{
+			LM_ERR("unable to get the media type\n");
+			return -1;
+		}
+	}
+
+	if(sdp_remove_codecs_by_name(msg, &lcodecs, &lmedia)<0)
 		return -1;
+
 	return 1;
 }