Browse code

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)
(cherry picked from commit 96f24caed768b1b382b166eea835e555eac5e933)
(cherry picked from commit 7fd662c98aa14d9b2fb730cfce0f6391ab756ed4)

Daniel-Constantin Mierla authored on 03/08/2021 06:52:19 • Henning Westerholt committed on 22/10/2021 12:04:16
Showing 1 changed files
... ...
@@ -195,48 +195,45 @@ int sdp_locate_line(sip_msg_t* msg, char *pos, str *aline)
195 195
 int sdp_remove_str_codec_id_attrs(sip_msg_t* msg,
196 196
 		sdp_stream_cell_t* sdp_stream, str *rm_codec)
197 197
 {
198
+	str sdp_attrs_list[] = {
199
+		str_init("a=rtpmap:"),
200
+		str_init("a=fmtp:"),
201
+		str_init("a=rtcp-fb:"),
202
+		{0, 0}
203
+	};
204
+	int i;
198 205
 	str aline = {0, 0};
199
-	sdp_payload_attr_t *payload;
206
+	str raw_stream = {0, 0};
200 207
 	struct lump *anchor;
201 208
 
202
-	payload = sdp_stream->payload_attr;
203
-	while (payload) {
204
-		LM_DBG("a= ... for codec %.*s/%.*s\n",
205
-				payload->rtp_payload.len, payload->rtp_payload.s,
206
-				payload->rtp_enc.len, payload->rtp_enc.s);
207
-		if(rm_codec->len==payload->rtp_payload.len
208
-				&& strncmp(payload->rtp_payload.s, rm_codec->s,
209
-					rm_codec->len)==0) {
210
-			if(payload->rtp_enc.s!=NULL) {
211
-				if(sdp_locate_line(msg, payload->rtp_enc.s, &aline)==0)
212
-				{
213
-					LM_DBG("removing line: %.*s", aline.len, aline.s);
214
-					anchor = del_lump(msg, aline.s - msg->buf,
215
-							aline.len, 0);
216
-					if (anchor == NULL) {
217
-						LM_ERR("failed to remove [%.*s] inside [%.*s]\n",
218
-								rm_codec->len, rm_codec->s,
219
-								aline.len, aline.s);
220
-						return -1;
221
-					}
222
-				}
223
-			}
224
-			if(payload->fmtp_string.s!=NULL) {
225
-				if(sdp_locate_line(msg, payload->fmtp_string.s, &aline)==0)
226
-				{
227
-					LM_DBG("removing line: %.*s\n", aline.len, aline.s);
228
-					anchor = del_lump(msg, aline.s - msg->buf,
229
-							aline.len, 0);
230
-					if (anchor == NULL) {
231
-						LM_ERR("failed to remove [%.*s] inside [%.*s]\n",
232
-								rm_codec->len, rm_codec->s,
233
-								aline.len, aline.s);
234
-						return -1;
209
+	raw_stream = sdp_stream->raw_stream;
210
+	while(raw_stream.len>5) {
211
+		sdp_locate_line(msg, raw_stream.s, &aline);
212
+		/* process attribute lines: a=x:c... */
213
+		if((aline.len>5) && ((aline.s[0] | 0x20)=='a')) {
214
+			LM_DBG("processing sdp line [%.*s]\n", aline.len, aline.s);
215
+			for(i=0; sdp_attrs_list[i].s!=NULL; i++) {
216
+				if(aline.len > sdp_attrs_list[i].len + rm_codec->len) {
217
+					if(strncasecmp(aline.s, sdp_attrs_list[i].s,
218
+								sdp_attrs_list[i].len)==0
219
+							&& strncmp(aline.s+sdp_attrs_list[i].len, rm_codec->s,
220
+								rm_codec->len)==0
221
+							&& aline.s[sdp_attrs_list[i].len + rm_codec->len]==' ') {
222
+						LM_DBG("removing line: [%.*s]\n", aline.len, aline.s);
223
+						anchor = del_lump(msg, aline.s - msg->buf,
224
+								aline.len, 0);
225
+						if (anchor == NULL) {
226
+							LM_ERR("failed to remove - id [%.*s] line [%.*s]\n",
227
+									rm_codec->len, rm_codec->s,
228
+									aline.len, aline.s);
229
+							return -1;
230
+						}
235 231
 					}
236 232
 				}
237 233
 			}
238 234
 		}
239
-		payload=payload->next;
235
+		raw_stream.s = aline.s + aline.len;
236
+		raw_stream.len -= aline.len;
240 237
 	}
241 238
 
242 239
 	return 0;