|
@@ -27,6 +27,7 @@
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include "../../dprint.h"
|
|
|
+#include "../../trim.h"
|
|
|
#include "sdpops_data.h"
|
|
|
|
|
|
#if 0
|
|
@@ -92,7 +93,128 @@ Registration Procedures: Standards Action Process or expert approval
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-int sdpops_get_id_by_name(str *name, str *id)
|
|
|
+typedef struct _codecsmap {
|
|
|
+ str name;
|
|
|
+ str ids;
|
|
|
+} codecsmap_t;
|
|
|
+
|
|
|
+codecsmap_t sdpops_codecsmap_table[] = {
|
|
|
+ { {"PCMU", 4}, {"0", 1} },
|
|
|
+ { {"GSM", 3}, {"3", 1} },
|
|
|
+ { {"G723", 4}, {"4", 1} },
|
|
|
+ { {"DVI4", 4}, {"5,6,16,17", 9} },
|
|
|
+ { {"LPC", 3}, {"7", 1} },
|
|
|
+ { {"PCMA", 4}, {"8", 1} },
|
|
|
+ { {"G722", 4}, {"9", 1} },
|
|
|
+ { {"L16", 3}, {"10,11", 5} },
|
|
|
+ { {"QCELP", 5}, {"12", 2} },
|
|
|
+ { {"CN", 2}, {"13", 5} },
|
|
|
+ { {"MPA", 3}, {"14", 2} },
|
|
|
+ { {"G728", 4}, {"15", 2} },
|
|
|
+ { {"G729", 4}, {"18", 2} },
|
|
|
+ { {0, 0}, {0, 0} }
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * set the string with the IDs mapped to codec name
|
|
|
+ * - return 0 if found, -1 if not found
|
|
|
+ */
|
|
|
+int sdpops_get_ids_by_name(str *name, str *ids)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ for(i=0; sdpops_codecsmap_table[i].name.s!=0; i++)
|
|
|
+ {
|
|
|
+ if(name->len==sdpops_codecsmap_table[i].name.len
|
|
|
+ && strncasecmp(sdpops_codecsmap_table[i].name.s, name->s,
|
|
|
+ name->len)==0)
|
|
|
+ {
|
|
|
+ *ids = sdpops_codecsmap_table[i].ids;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ids->s = NULL;
|
|
|
+ ids->len = 0;
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * build the csv list of ids from csv list of names
|
|
|
+ */
|
|
|
+int sdpops_build_ids_list(str *names, str *ids)
|
|
|
+{
|
|
|
+#define SDPOPS_MAX_LIST_SIZE 64
|
|
|
+ static char _local_idslist[SDPOPS_MAX_LIST_SIZE];
|
|
|
+ str tmp;
|
|
|
+ str codec;
|
|
|
+ str cids;
|
|
|
+ char *p;
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ if( sdpops_get_ids_by_name(&codec, &cids)==0) {
|
|
|
+ LM_DBG("codecs list [%.*s] - at name [%.*s] with ids [%.*s]\n",
|
|
|
+ names->len, names->s,
|
|
|
+ codec.len, codec.s,
|
|
|
+ cids.len, cids.s);
|
|
|
+ if(ids->len + cids.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;
|
|
|
+ *p = ',';
|
|
|
+ p++;
|
|
|
+ ids->len += cids.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;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int str_find_token(str *text, str *result, char delim)
|
|
|
{
|
|
|
+ int i;
|
|
|
+ if(text==NULL || result==NULL)
|
|
|
+ return -1;
|
|
|
+ if(text->s[0] == delim)
|
|
|
+ {
|
|
|
+ text->s += 1;
|
|
|
+ text->len -= 1;
|
|
|
+ }
|
|
|
+ trim_leading(text);
|
|
|
+ result->s = text->s;
|
|
|
+ result->len = 0;
|
|
|
+ for (i=0; i<text->len; i++)
|
|
|
+ {
|
|
|
+ if(result->s[i]==delim || result->s[i]=='\0'
|
|
|
+ || result->s[i]=='\r' || result->s[i]=='\n')
|
|
|
+ return 0;
|
|
|
+ result->len++;
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|