Commit 0070128e authored by Ghislain MARY's avatar Ghislain MARY

Restore belle_sdp_attribute_get_value() instead of belle_sdp_raw_attribute_get_value().

parent 10798d9f
......@@ -35,6 +35,8 @@ BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_attribute_parse (const char* at
BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_attribute_create (const char* name,const char* value);
BELLESIP_EXPORT const char* belle_sdp_attribute_get_name(const belle_sdp_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_attribute_set_name(belle_sdp_attribute_t* attribute, const char* name);
BELLESIP_EXPORT const char* belle_sdp_attribute_get_value(belle_sdp_attribute_t* attribute);
BELLESIP_EXPORT unsigned int belle_sdp_attribute_has_value(belle_sdp_attribute_t* attribute);
#define BELLE_SDP_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_attribute_t)
#define belle_sdp_attribute_init(obj) /*nothing*/
/***************************************************************************************
......@@ -45,8 +47,6 @@ typedef struct _belle_sdp_raw_attribute belle_sdp_raw_attribute_t;
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_new();
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_parse(const char* attribute);
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_create(const char* name, const char* value);
BELLESIP_EXPORT const char* belle_sdp_raw_attribute_get_value(const belle_sdp_raw_attribute_t* attribute);
BELLESIP_EXPORT unsigned int belle_sdp_raw_attribute_has_value(const belle_sdp_raw_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_raw_attribute_set_value(belle_sdp_raw_attribute_t* attribute, const char* value);
#define BELLE_SDP_RAW_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_raw_attribute_t)
/***************************************************************************************
......@@ -192,7 +192,7 @@ BELLESIP_EXPORT belle_sdp_media_description_t* belle_sdp_media_description_creat
,belle_sip_list_t* static_media_formats);
BELLESIP_EXPORT void belle_sdp_media_description_add_dynamic_payloads(belle_sdp_media_description_t* media_description, belle_sip_list_t* payloadNames, belle_sip_list_t* payloadValues);
BELLESIP_EXPORT const char* belle_sdp_media_description_get_attribute_value(const belle_sdp_media_description_t* media_description, const char* name);
BELLESIP_EXPORT const belle_sdp_attribute_t* belle_sdp_media_description_get_attribute(const belle_sdp_media_description_t* media_description, const char* name);
BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_media_description_get_attribute(const belle_sdp_media_description_t* media_description, const char* name);
BELLESIP_EXPORT belle_sip_list_t* belle_sdp_media_description_get_attributes(const belle_sdp_media_description_t* media_description);
BELLESIP_EXPORT int belle_sdp_media_description_get_bandwidth(const belle_sdp_media_description_t* media_description, const char* name);
BELLESIP_EXPORT belle_sip_list_t* belle_sdp_media_description_get_bandwidths(const belle_sdp_media_description_t* media_description);
......
......@@ -48,6 +48,7 @@ static struct attribute_name_func_pair attribute_table[] = {
struct _belle_sdp_attribute {
belle_sip_object_t base;
const char* name;
char *unparsed_value;
};
void belle_sdp_attribute_destroy(belle_sdp_attribute_t* attribute) {
DESTROY_STRING(attribute,name)
......@@ -83,6 +84,23 @@ belle_sdp_attribute_t* belle_sdp_attribute_create(const char* name, const char*
/* Not a specialized SDP attribute */
return BELLE_SDP_ATTRIBUTE(belle_sdp_raw_attribute_create(name, value));
}
const char *belle_sdp_attribute_get_value(belle_sdp_attribute_t *attribute) {
char *ret;
char *end;
if (attribute->unparsed_value) {
belle_sip_free(attribute->unparsed_value);
attribute->unparsed_value = NULL;
}
attribute->unparsed_value = belle_sip_object_to_string(attribute);
ret = attribute->unparsed_value;
ret += strlen(attribute->name) + 3; /* "a=" + name + semicolon */
for (; *ret == ' '; ret++) {}; /* skip spaces */
return ret;
}
unsigned int belle_sdp_attribute_has_value(belle_sdp_attribute_t* attribute) {
return belle_sdp_attribute_get_value(attribute) != NULL;
}
BELLE_SDP_NEW(attribute,belle_sip_object)
BELLE_SDP_PARSE(attribute)
GET_SET_STRING(belle_sdp_attribute,name);
......@@ -98,7 +116,9 @@ void belle_sdp_raw_attribute_destroy(belle_sdp_raw_attribute_t* attribute) {
DESTROY_STRING(attribute,value)
}
void belle_sdp_raw_attribute_clone(belle_sdp_raw_attribute_t* attribute, const belle_sdp_raw_attribute_t* orig) {
CLONE_STRING(belle_sdp_raw_attribute,value,attribute,orig)
if (belle_sdp_attribute_get_value(BELLE_SDP_ATTRIBUTE(orig))) {
belle_sdp_raw_attribute_set_value(attribute, belle_sdp_attribute_get_value(BELLE_SDP_ATTRIBUTE(orig)));
}
}
belle_sip_error_code belle_sdp_raw_attribute_marshal(belle_sdp_raw_attribute_t* attribute, char* buff, size_t buff_size, size_t* offset) {
belle_sip_error_code error = belle_sdp_attribute_marshal(BELLE_SDP_ATTRIBUTE(attribute), buff, buff_size, offset);
......@@ -116,9 +136,11 @@ belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_create(const char* name, cons
belle_sdp_raw_attribute_set_value(attribute, value);
return attribute;
}
GET_SET_STRING(belle_sdp_raw_attribute,value);
unsigned int belle_sdp_raw_attribute_has_value(const belle_sdp_raw_attribute_t* attribute) {
return attribute->value!=NULL;
void belle_sdp_raw_attribute_set_value(belle_sdp_raw_attribute_t* attribute, const char* value) {
if (attribute->value != NULL) belle_sip_free((void*)attribute->value);
if (value) {
attribute->value = belle_sip_strdup(value);
} else attribute->value = NULL;
}
/***************************************************************************************
* RTCP-XR Attribute
......@@ -452,7 +474,7 @@ BELLE_SIP_INSTANCIATE_VPTR(belle_sdp_base_description_t
static int belle_sdp_base_description_attribute_comp_func(const belle_sdp_attribute_t* a, const char*b) {
return strcmp(a->name,b);
}
const belle_sdp_attribute_t* belle_sdp_base_description_get_attribute(const belle_sdp_base_description_t* base_description, const char* name) {
belle_sdp_attribute_t* belle_sdp_base_description_get_attribute(const belle_sdp_base_description_t* base_description, const char* name) {
belle_sip_list_t* attribute;
attribute = belle_sip_list_find_custom(base_description->attributes, (belle_sip_compare_func)belle_sdp_base_description_attribute_comp_func, name);
if (attribute) {
......@@ -462,14 +484,9 @@ const belle_sdp_attribute_t* belle_sdp_base_description_get_attribute(const bell
}
}
const char* belle_sdp_base_description_get_attribute_value(const belle_sdp_base_description_t* base_description, const char* name) {
const belle_sdp_attribute_t* attribute = belle_sdp_base_description_get_attribute(base_description,name);
belle_sdp_attribute_t* attribute = belle_sdp_base_description_get_attribute(base_description,name);
if (attribute) {
if (BELLE_SIP_IS_INSTANCE_OF(attribute, belle_sdp_raw_attribute_t)) {
return belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attribute));
} else {
belle_sip_error("Cannot get value of non-raw SDP attribute '%s'! Use specialized attribute object.", name);
return NULL;
}
return belle_sdp_attribute_get_value(attribute);
} else return NULL;
}
......@@ -593,7 +610,7 @@ BELLE_SDP_PARSE(media_description)
void belle_sdp_media_description_add_dynamic_payloads(belle_sdp_media_description_t* media_description, belle_sip_list_t* payloadNames, belle_sip_list_t* payloadValues) {
belle_sip_error("belle_sdp_media_description_add_dynamic_payloads not implemented yet");
}
const belle_sdp_attribute_t* belle_sdp_media_description_get_attribute(const belle_sdp_media_description_t* media_description, const char* name) {
belle_sdp_attribute_t* belle_sdp_media_description_get_attribute(const belle_sdp_media_description_t* media_description, const char* name) {
return belle_sdp_base_description_get_attribute(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),name);
}
const char* belle_sdp_media_description_get_attribute_value(const belle_sdp_media_description_t* media_description, const char* name) {
......@@ -767,16 +784,16 @@ static const char *belle_sdp_media_description_a_attr_value_get_with_pt(const be
;attribute_list=attribute_list->next) {
attr = BELLE_SDP_ATTRIBUTE(attribute_list->data);
if (strcmp(field,belle_sdp_attribute_get_name(attr))==0 && belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr))!=NULL){
int nb = sscanf(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),"%i %n",&tmppt,&scanned);
if (strcmp(field,belle_sdp_attribute_get_name(attr))==0 && belle_sdp_attribute_get_value(attr)!=NULL){
int nb = sscanf(belle_sdp_attribute_get_value(attr),"%i %n",&tmppt,&scanned);
/* the return value may depend on how %n is interpreted by the libc: see manpage*/
if (nb == 1 || nb==2 ){
if (pt==tmppt){
tmp=belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr))+scanned;
tmp=belle_sdp_attribute_get_value(attr)+scanned;
if (strlen(tmp)>0)
return tmp;
}
}else belle_sip_warning("sdp has a strange a= line (%s) nb=%i",belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),nb);
}else belle_sip_warning("sdp has a strange a= line (%s) nb=%i",belle_sdp_attribute_get_value(attr),nb);
}
}
return NULL;
......
......@@ -57,16 +57,16 @@ static belle_sdp_attribute_t* attribute_parse_marshall_parse_clone(const char* r
static void test_attribute(void) {
belle_sdp_attribute_t* lAttribute = attribute_parse_marshall_parse_clone("a=rtpmap:101 telephone-event/8000");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "rtpmap");
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)), "101 telephone-event/8000");
CU_ASSERT_TRUE(belle_sdp_raw_attribute_has_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value(lAttribute), "101 telephone-event/8000");
CU_ASSERT_TRUE(belle_sdp_attribute_has_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
static void test_attribute_2(void) {
belle_sdp_attribute_t* lAttribute = attribute_parse_marshall_parse_clone("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "ice-pwd");
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)), "31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_TRUE(belle_sdp_raw_attribute_has_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value(lAttribute), "31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_TRUE(belle_sdp_attribute_has_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
......@@ -269,7 +269,7 @@ static void test_media_description_base(belle_sdp_media_description_t* media_des
CU_ASSERT_PTR_NOT_NULL(list);
i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE((belle_sdp_attribute_t*)(list->data))),attr[i++]);
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value((belle_sdp_attribute_t*)(list->data)),attr[i++]);
}
}
......@@ -498,7 +498,7 @@ static void check_mime_param (belle_sdp_mime_parameter_t* mime_param
}
int static compare_attribute(belle_sdp_attribute_t* attr, const char* value) {
return strcasecmp(belle_sdp_attribute_get_name(attr),"rtpmap")==0
|| strcasecmp(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),value)==0;
|| strcasecmp(belle_sdp_attribute_get_value(attr),value)==0;
}
static void test_mime_parameter(void) {
const char* l_src = "m=audio 7078 RTP/AVP 111 110 0 8 9 3 18 101\r\n"\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment