Module: sip-router
Branch: master
Commit: 511dc62e6a6ca74324f42b66a23bd9d80b377252
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=511dc62…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Oct 26 21:21:22 2011 +0200
sdpops: find codec ids in sdp when not found in static table
- functions to keep/remove codecs by name work now with dynamic ids for
codecs
- reported by Juha Heinanen
---
modules/sdpops/sdpops_data.c | 60 +++++++++++++++++++++++++++++++++++++++--
modules/sdpops/sdpops_data.h | 4 ++-
modules/sdpops/sdpops_mod.c | 4 +-
3 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/modules/sdpops/sdpops_data.c b/modules/sdpops/sdpops_data.c
index 178c705..d1d2a56 100644
--- a/modules/sdpops/sdpops_data.c
+++ b/modules/sdpops/sdpops_data.c
@@ -138,9 +138,53 @@ int sdpops_get_ids_by_name(str *name, str *ids)
}
/**
+ * get codec ID from a= line based on name
+ */
+int sdpops_sdp_get_ids_by_name(sdp_info_t *sdp, str *cname, str *cid)
+{
+ 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;
+
+ sdp_session_num = 0;
+ for(;;)
+ {
+ sdp_session = get_sdp_session_sdp(sdp, sdp_session_num);
+ if(!sdp_session) break;
+ sdp_stream_num = 0;
+ for(;;)
+ {
+ sdp_stream = get_sdp_stream_sdp(sdp, sdp_session_num,
+ sdp_stream_num);
+ if(!sdp_stream) break;
+ sdp_payload = sdp_stream->payload_attr;
+ while (sdp_payload) {
+ if(sdp_payload->rtp_enc.len==cname->len
+ && strncasecmp(cname->s, sdp_payload->rtp_enc.s,
+ cname->len)==0)
+ {
+ *cid = sdp_payload->rtp_payload;
+ return 0;
+ }
+
+ sdp_payload=sdp_payload->next;
+ }
+ sdp_stream_num++;
+ }
+ sdp_session_num++;
+ }
+
+ cid->s = NULL;
+ cid->len = 0;
+ return -1;
+}
+
+/**
* build the csv list of ids from csv list of names
*/
-int sdpops_build_ids_list(str *names, str *ids)
+int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids)
{
#define SDPOPS_MAX_LIST_SIZE 64
static char _local_idslist[SDPOPS_MAX_LIST_SIZE];
@@ -159,11 +203,21 @@ int sdpops_build_ids_list(str *names, str *ids)
tmp.len -= (int)(&codec.s[codec.len]-codec.s);
tmp.s = codec.s + codec.len;
- if( sdpops_get_ids_by_name(&codec, &cids)==0) {
- LM_DBG("codecs list [%.*s] - at name [%.*s] with ids [%.*s]\n",
+ cids.s = NULL;
+ if(sdpops_get_ids_by_name(&codec, &cids)==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);
+ } 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",
+ names->len, names->s,
+ codec.len, codec.s,
+ cids.len, cids.s);
+ }
+ }
+ if(cids.s!=NULL) {
if(ids->len + cids.len>=SDPOPS_MAX_LIST_SIZE)
{
LM_ERR("the list with codecs ids is too big\n");
diff --git a/modules/sdpops/sdpops_data.h b/modules/sdpops/sdpops_data.h
index 2d05f2b..3112ac2 100644
--- a/modules/sdpops/sdpops_data.h
+++ b/modules/sdpops/sdpops_data.h
@@ -24,10 +24,12 @@
#ifndef _SDPOPS_DATA_H_
#define _SDPOPS_DATA_H_
+
#include "../../str.h"
+#include "../../parser/sdp/sdp.h"
int sdpops_get_ids_by_name(str *name, str *ids);
int str_find_token(str *text, str *result, char delim);
-int sdpops_build_ids_list(str *names, str *ids);
+int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids);
#endif
diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c
index 732acf2..725dcf6 100644
--- a/modules/sdpops/sdpops_mod.c
+++ b/modules/sdpops/sdpops_mod.c
@@ -356,7 +356,7 @@ int sdp_remove_codecs_by_name(sip_msg_t* msg, str* codecs)
LM_ERR("attempting to remove codecs from sdp: [%.*s]\n",
codecs->len, codecs->s);
- if(sdpops_build_ids_list(codecs, &idslist)<0)
+ if(sdpops_build_ids_list((sdp_info_t*)msg->body, codecs, &idslist)<0)
return -1;
if(sdp_remove_codecs_by_id(msg, &idslist)<0)
@@ -491,7 +491,7 @@ int sdp_keep_codecs_by_name(sip_msg_t* msg, str* codecs)
LM_ERR("attempting to keep codecs in sdp: [%.*s]\n",
codecs->len, codecs->s);
- if(sdpops_build_ids_list(codecs, &idslist)<0)
+ if(sdpops_build_ids_list((sdp_info_t*)msg->body, codecs, &idslist)<0)
return -1;
if(sdp_keep_codecs_by_id(msg, &idslist)<0)