Module: sip-router Branch: master Commit: e4d2b647d1b0e8764b1eb0cfe07d446231af0df8 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e4d2b647...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Nov 1 16:18:34 2011 +0100
sdpops: support for codecs with same name and many different ids
- reported by Juha Heinanen
---
modules/sdpops/sdpops_data.c | 50 ++++++++++++++++++++++++++--------------- 1 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/modules/sdpops/sdpops_data.c b/modules/sdpops/sdpops_data.c index d1d2a56..a360b88 100644 --- a/modules/sdpops/sdpops_data.c +++ b/modules/sdpops/sdpops_data.c @@ -138,17 +138,19 @@ int sdpops_get_ids_by_name(str *name, str *ids) }
/** - * get codec ID from a= line based on name + * get codec IDs from a= lines based on name */ -int sdpops_sdp_get_ids_by_name(sdp_info_t *sdp, str *cname, str *cid) +int sdpops_sdp_get_ids_by_name(sdp_info_t *sdp, str *cname, str *cids, int n) { int sdp_session_num; int sdp_stream_num; sdp_session_cell_t *sdp_session; sdp_stream_cell_t *sdp_stream; sdp_payload_attr_t *sdp_payload; + int i;
sdp_session_num = 0; + i = 0; for(;;) { sdp_session = get_sdp_session_sdp(sdp, sdp_session_num); @@ -165,8 +167,10 @@ int sdpops_sdp_get_ids_by_name(sdp_info_t *sdp, str *cname, str *cid) && strncasecmp(cname->s, sdp_payload->rtp_enc.s, cname->len)==0) { - *cid = sdp_payload->rtp_payload; - return 0; + if(i==n) + goto notfound; + cids[i] = sdp_payload->rtp_payload; + i++; }
sdp_payload=sdp_payload->next; @@ -176,8 +180,15 @@ int sdpops_sdp_get_ids_by_name(sdp_info_t *sdp, str *cname, str *cid) sdp_session_num++; }
- cid->s = NULL; - cid->len = 0; + if(i==0) + goto notfound; + if(i<n) + cids[i].s = NULL; + return 0; + +notfound: + cids[0].s = NULL; + cids[0].len = 0; return -1; }
@@ -190,8 +201,10 @@ int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids) static char _local_idslist[SDPOPS_MAX_LIST_SIZE]; str tmp; str codec; - str cids; +#define SDPOPS_CIDS_SIZE 8 + str cids[SDPOPS_CIDS_SIZE]; char *p; + int i;
tmp = *names; ids->len = 0; @@ -203,33 +216,34 @@ int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids) tmp.len -= (int)(&codec.s[codec.len]-codec.s); tmp.s = codec.s + codec.len;
- cids.s = NULL; - if(sdpops_get_ids_by_name(&codec, &cids)==0) { + 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.len, cids.s); + cids[0].len, cids[0].s); + cids[1].s = NULL; } else { - if(sdpops_sdp_get_ids_by_name(sdp, &codec, &cids)==0) { - LM_DBG("codecs list [%.*s] - at name [%.*s] with sdp id [%.*s]\n", + 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.len, cids.s); + cids[0].len, cids[0].s); } } - if(cids.s!=NULL) { - if(ids->len + cids.len>=SDPOPS_MAX_LIST_SIZE) + 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.s, cids.len); - p += cids.len; + strncpy(p, cids[i].s, cids[i].len); + p += cids[i].len; *p = ','; p++; - ids->len += cids.len + 1; + ids->len += cids[i].len + 1; } } if(ids->len>0)