[sr-dev] git:5.5:96f24cae: sdpops: refactored sdp_remove_str_codec_id_attrs()

Daniel-Constantin Mierla miconda at gmail.com
Fri Aug 20 10:01:13 CEST 2021


Module: kamailio
Branch: 5.5
Commit: 96f24caed768b1b382b166eea835e555eac5e933
URL: https://github.com/kamailio/kamailio/commit/96f24caed768b1b382b166eea835e555eac5e933

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-08-19T21:30:01+02:00

sdpops: refactored sdp_remove_str_codec_id_attrs()

- line oriented matching of codec addributes
- support to remove a=rtcp-fb per codec, GH #2755

(cherry picked from commit 1a15a18eacd5764e9ba6240acbe37e645368f825)

---

Modified: src/modules/sdpops/sdpops_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/96f24caed768b1b382b166eea835e555eac5e933.diff
Patch: https://github.com/kamailio/kamailio/commit/96f24caed768b1b382b166eea835e555eac5e933.patch

---

diff --git a/src/modules/sdpops/sdpops_mod.c b/src/modules/sdpops/sdpops_mod.c
index bebe01ba5c..37655fde4b 100644
--- a/src/modules/sdpops/sdpops_mod.c
+++ b/src/modules/sdpops/sdpops_mod.c
@@ -195,48 +195,45 @@ int sdp_locate_line(sip_msg_t* msg, char *pos, str *aline)
 int sdp_remove_str_codec_id_attrs(sip_msg_t* msg,
 		sdp_stream_cell_t* sdp_stream, str *rm_codec)
 {
+	str sdp_attrs_list[] = {
+		str_init("a=rtpmap:"),
+		str_init("a=fmtp:"),
+		str_init("a=rtcp-fb:"),
+		{0, 0}
+	};
+	int i;
 	str aline = {0, 0};
-	sdp_payload_attr_t *payload;
+	str raw_stream = {0, 0};
 	struct lump *anchor;
 
-	payload = sdp_stream->payload_attr;
-	while (payload) {
-		LM_DBG("a= ... for codec %.*s/%.*s\n",
-				payload->rtp_payload.len, payload->rtp_payload.s,
-				payload->rtp_enc.len, payload->rtp_enc.s);
-		if(rm_codec->len==payload->rtp_payload.len
-				&& strncmp(payload->rtp_payload.s, rm_codec->s,
-					rm_codec->len)==0) {
-			if(payload->rtp_enc.s!=NULL) {
-				if(sdp_locate_line(msg, payload->rtp_enc.s, &aline)==0)
-				{
-					LM_DBG("removing line: %.*s", aline.len, aline.s);
-					anchor = del_lump(msg, aline.s - msg->buf,
-							aline.len, 0);
-					if (anchor == NULL) {
-						LM_ERR("failed to remove [%.*s] inside [%.*s]\n",
-								rm_codec->len, rm_codec->s,
-								aline.len, aline.s);
-						return -1;
-					}
-				}
-			}
-			if(payload->fmtp_string.s!=NULL) {
-				if(sdp_locate_line(msg, payload->fmtp_string.s, &aline)==0)
-				{
-					LM_DBG("removing line: %.*s\n", aline.len, aline.s);
-					anchor = del_lump(msg, aline.s - msg->buf,
-							aline.len, 0);
-					if (anchor == NULL) {
-						LM_ERR("failed to remove [%.*s] inside [%.*s]\n",
-								rm_codec->len, rm_codec->s,
-								aline.len, aline.s);
-						return -1;
+	raw_stream = sdp_stream->raw_stream;
+	while(raw_stream.len>5) {
+		sdp_locate_line(msg, raw_stream.s, &aline);
+		/* process attribute lines: a=x:c... */
+		if((aline.len>5) && ((aline.s[0] | 0x20)=='a')) {
+			LM_DBG("processing sdp line [%.*s]\n", aline.len, aline.s);
+			for(i=0; sdp_attrs_list[i].s!=NULL; i++) {
+				if(aline.len > sdp_attrs_list[i].len + rm_codec->len) {
+					if(strncasecmp(aline.s, sdp_attrs_list[i].s,
+								sdp_attrs_list[i].len)==0
+							&& strncmp(aline.s+sdp_attrs_list[i].len, rm_codec->s,
+								rm_codec->len)==0
+							&& aline.s[sdp_attrs_list[i].len + rm_codec->len]==' ') {
+						LM_DBG("removing line: [%.*s]\n", aline.len, aline.s);
+						anchor = del_lump(msg, aline.s - msg->buf,
+								aline.len, 0);
+						if (anchor == NULL) {
+							LM_ERR("failed to remove - id [%.*s] line [%.*s]\n",
+									rm_codec->len, rm_codec->s,
+									aline.len, aline.s);
+							return -1;
+						}
 					}
 				}
 			}
 		}
-		payload=payload->next;
+		raw_stream.s = aline.s + aline.len;
+		raw_stream.len -= aline.len;
 	}
 
 	return 0;




More information about the sr-dev mailing list