Exemple #1
0
int sdp_keep_codecs_by_id(sip_msg_t* msg, str* codecs)
{
	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;
	str sdp_codecs;
	str tmp_codecs;
	str rm_codec;

	if(parse_sdp(msg) < 0) {
		LM_ERR("Unable to parse sdp\n");
		return -1;
	}

	LM_ERR("attempting to keep codecs in sdp: [%.*s]\n",
			codecs->len, codecs->s);

	sdp = (sdp_info_t*)msg->body;

	sdp_session_num = 0;
	for(;;)
	{
		sdp_session = get_sdp_session(msg, sdp_session_num);
		if(!sdp_session) break;
		sdp_stream_num = 0;
		for(;;)
		{
			sdp_stream = get_sdp_stream(msg, sdp_session_num, sdp_stream_num);
			if(!sdp_stream) break;

			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 = sdp_stream->payloads;
			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;

				if(sdp_codec_in_str(codecs, &rm_codec, ',')==0) {
					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++;
		}
		sdp_session_num++;
	}

	return 0;
}
/**
 * build the csv list of ids from csv list of names
 */
int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids)
{
#define SDPOPS_MAX_LIST_SIZE	128
	static char _local_idslist[SDPOPS_MAX_LIST_SIZE];
	str tmp;
	str codec;
#define SDPOPS_CIDS_SIZE	16
	str cids[SDPOPS_CIDS_SIZE];
	char *p;
	int i;

	tmp = *names;
	ids->len = 0;
	ids->s   = 0;
	p = _local_idslist;
	while(str_find_token(&tmp, &codec, ',')==0
		&& codec.len>0)
	{
		tmp.len -= (int)(&codec.s[codec.len]-codec.s);
		tmp.s = codec.s + codec.len;

		cids[0].s = NULL;
		if(sdpops_get_ids_by_name(&codec, &cids[0])==0) {
			LM_DBG("codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n",
				names->len, names->s,
				codec.len, codec.s,
				cids[0].len,  cids[0].s);
			cids[1].s = NULL;
		} else {
			if(sdpops_sdp_get_ids_by_name(sdp, &codec, cids, SDPOPS_CIDS_SIZE)==0) {
				LM_DBG("codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n",
					names->len, names->s,
					codec.len, codec.s,
					cids[0].len,  cids[0].s);
			}
		}
		for(i=0; i<SDPOPS_CIDS_SIZE && cids[i].s!=NULL; i++) {
			if(ids->len + cids[i].len>=SDPOPS_MAX_LIST_SIZE)
			{
				LM_ERR("the list with codecs ids is too big\n");
				ids->len = 0;
				ids->s = 0;
				return -1;
			}
			strncpy(p, cids[i].s, cids[i].len);
			p += cids[i].len;
			*p = ',';
			p++;
			ids->len += cids[i].len + 1;
		}
	}
	if(ids->len>0)
	{
		p--;
		ids->len--;
		*p = '\0';
		ids->s = _local_idslist;
		LM_DBG("codecs list [%.*s] - ids list [%.*s]\n",
				names->len, names->s,
				ids->len, ids->s);
		return 0;
	}
	return -1;
}
Exemple #3
0
int sdp_with_codecs_by_id(sip_msg_t* msg, str* codecs)
{
	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;
	str sdp_codecs;
	str tmp_codecs;
	str fnd_codec;
	int foundone = 0;
	int notfound = 0;

	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;
	}

	LM_DBG("attempting to search codecs in sdp: [%.*s]\n",
			codecs->len, codecs->s);

	sdp_session_num = 0;
	for(;;)
	{
		sdp_session = get_sdp_session(msg, sdp_session_num);
		if(!sdp_session) break;
		sdp_stream_num = 0;
		for(;;)
		{
			sdp_stream = get_sdp_stream(msg, sdp_session_num, sdp_stream_num);
			if(!sdp_stream) break;

			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, &fnd_codec, ',')==0
					&& fnd_codec.len>0)
			{
				tmp_codecs.len -=(int)(&fnd_codec.s[fnd_codec.len]-tmp_codecs.s);
				tmp_codecs.s = fnd_codec.s + fnd_codec.len;

				if(sdp_codec_in_str(&sdp_codecs, &fnd_codec, ' ')==0) {
					LM_DBG("codecs [%.*s] - not found [%.*s]\n",
							sdp_codecs.len, sdp_codecs.s,
							fnd_codec.len, fnd_codec.s);
					notfound = 1;
				} else {
					LM_DBG("codecs [%.*s] - found [%.*s]\n",
							sdp_codecs.len, sdp_codecs.s,
							fnd_codec.len, fnd_codec.s);
					foundone = 1;
				}
			}
			sdp_stream_num++;
		}
		sdp_session_num++;
	}

	return (foundone + ((foundone)?notfound:0));
}