Commit 01f7b920 authored by jehan's avatar jehan

add support for header supported

parent 4c1cb2bf
......@@ -686,6 +686,21 @@ BELLESIP_EXPORT void belle_sip_header_event_set_id(belle_sip_header_event_t* eve
#define BELLE_SIP_HEADER_EVENT(t) BELLE_SIP_CAST(t,belle_sip_header_event_t)
#define BELLE_SIP_EVENT "Event"
/******************************
* Supported header object inherent from header
*
******************************/
typedef struct _belle_sip_header_supported belle_sip_header_supported_t;
BELLESIP_EXPORT belle_sip_header_supported_t* belle_sip_header_supported_new();
BELLESIP_EXPORT belle_sip_header_supported_t* belle_sip_header_supported_parse(const char* supported) ;
BELLESIP_EXPORT belle_sip_header_supported_t* belle_sip_header_supported_create(const char* supported);
BELLESIP_EXPORT void belle_sip_header_supported_add_supported(belle_sip_header_supported_t* supported, const char* value);
BELLESIP_EXPORT void belle_sip_header_supported_set_supported(belle_sip_header_supported_t* supported, belle_sip_list_t* supported_values);
BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_supported_get_supported(const belle_sip_header_supported_t* supported);
#define BELLE_SIP_HEADER_SUPPORTED(t) BELLE_SIP_CAST(t,belle_sip_header_supported_t)
#define BELLE_SIP_SUPPORTED "Supported"
BELLE_SIP_END_DECLS
......
......@@ -131,7 +131,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_user_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_file_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_multipart_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_header_event_t)
BELLE_SIP_TYPE_ID(belle_sip_header_event_t),
BELLE_SIP_TYPE_ID(belle_sip_header_supported_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -133,6 +133,8 @@ set(SOURCE_FILES
transports/stream_listeningpoint.c
transports/udp_channel.c
transports/udp_listeningpoint.c
grammars/belle_sip_message.g
grammars/belle_sdp.g
${SDP_GENERATED_SOURCE_FILES}
${SIP_MESSAGE_GENERATED_SOURCE_FILES}
${TLS_SOURCE_FILES}
......
......@@ -77,6 +77,8 @@ static struct header_name_func_pair header_table[] = {
,{PROTO_SIP, BELLE_SIP_P_PREFERRED_IDENTITY, (header_parse_func)belle_sip_header_p_preferred_identity_parse}
,{PROTO_SIP, BELLE_SIP_PRIVACY, (header_parse_func)belle_sip_header_privacy_parse}
,{PROTO_SIP, BELLE_SIP_EVENT, (header_parse_func)belle_sip_header_event_parse}
,{PROTO_SIP, BELLE_SIP_SUPPORTED, (header_parse_func)belle_sip_header_privacy_parse}
,{PROTO_SIP, "k", (header_parse_func)belle_sip_header_privacy_parse}
};
static belle_sip_header_t* belle_header_create(const char* name,const char* value,int protocol) {
......@@ -1855,4 +1857,50 @@ belle_sip_header_event_t* belle_sip_header_event_create (const char* package_nam
return event;
}
/******************************
* Supported header inherits from header
*
******************************/
struct _belle_sip_header_supported {
belle_sip_header_t header;
belle_sip_list_t* supported;
};
static void belle_sip_header_supported_destroy(belle_sip_header_supported_t* p) {
belle_sip_header_supported_set_supported(p,NULL);
}
static void belle_sip_header_supported_clone(belle_sip_header_supported_t* p, const belle_sip_header_supported_t* orig){
belle_sip_list_t* list=orig->supported;
for(;list!=NULL;list=list->next){
belle_sip_header_supported_add_supported(p,(const char *)list->data);
}
}
belle_sip_error_code belle_sip_header_supported_marshal(belle_sip_header_supported_t* p, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
belle_sip_list_t* list = p->supported;
error=belle_sip_header_marshal(BELLE_SIP_HEADER(p), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
for(;list!=NULL;list=list->next){
error=belle_sip_snprintf(buff,buff_size,offset,list==p->supported ? "%s" : ", %s",(const char *)list->data);
if (error!=BELLE_SIP_OK) return error;
}
return error;
}
BELLE_SIP_NEW_HEADER(header_supported,header,BELLE_SIP_SUPPORTED)
BELLE_SIP_PARSE(header_supported)
belle_sip_list_t* belle_sip_header_supported_get_supported(const belle_sip_header_supported_t* p) {
return p->supported;
}
SET_ADD_STRING_LIST(belle_sip_header_supported,supported)
belle_sip_header_supported_t* belle_sip_header_supported_create(const char* supported) {
belle_sip_header_supported_t* supported_header=belle_sip_header_supported_new();
belle_sip_header_supported_add_supported(supported_header,supported);
return supported_header;
}
......@@ -205,6 +205,7 @@ BELLE_SIP_DECLARE_VPTR(belle_http_callbacks_t);
BELLE_SIP_DECLARE_VPTR(belle_tls_verify_policy_t);
BELLE_SIP_DECLARE_VPTR(belle_http_header_authorization_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_event_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_supported_t);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......
......@@ -1405,6 +1405,22 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
}
privacy_val: token {belle_sip_header_privacy_add_privacy($header_privacy::current,(const char*)$token.text->chars);};
//**********************************Supported*******************************//
header_supported returns [belle_sip_header_supported_t* ret]
scope { belle_sip_header_supported_t* current; }
@init { $header_supported::current = belle_sip_header_supported_new();$ret = $header_supported::current;}
: {IS_TOKEN(Supported)}? token /*'Supported'*/ hcolon supported_val (comma supported_val)*;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
supported_val: token {belle_sip_header_supported_add_supported($header_supported::current,(const char*)$token.text->chars);};
header returns [belle_sip_header_t* ret=NULL]
: header_extension_base[FALSE] {$ret=$header_extension_base.ret;};
......
......@@ -1010,6 +1010,39 @@ static void test_event_header(void) {
BC_ASSERT_PTR_NULL(belle_sip_header_event_parse("nimportequoi"));
}
static void test_supported(const char* raw_header,const char* values[],size_t number_values) {
belle_sip_list_t* list;
belle_sip_header_supported_t* L_tmp;
belle_sip_header_supported_t* L_supported = belle_sip_header_supported_parse(raw_header);
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_supported));
size_t i=0;
belle_sip_object_unref(BELLE_SIP_OBJECT(L_supported));
L_tmp = belle_sip_header_supported_parse(l_raw_header);
L_supported = BELLE_SIP_HEADER_SUPPORTED(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
list = belle_sip_header_supported_get_supported(L_supported);
for(i=0;i<number_values;i++){
BC_ASSERT_PTR_NOT_NULL(list);
if (list) {
BC_ASSERT_STRING_EQUAL((const char *)(list->data),values[i]);
list=list->next;
}
}
belle_sip_object_unref(BELLE_SIP_OBJECT(L_supported));
BC_ASSERT_PTR_NULL(belle_sip_header_supported_parse("nimportequoi"));
}
static void test_supported_header(void) {
const char* value1[] ={"user","critical"};
const char* value2[] ={"id"};
test_supported("Supported: user, critical",value1,2);
test_supported("Supported: id",value2,1);
}
test_t headers_tests[] = {
{ "Address", test_address_header },
{ "Address tel uri", test_address_header_with_tel_uri },
......@@ -1048,7 +1081,8 @@ test_t headers_tests[] = {
{ "WWW-Authenticate", test_www_authenticate_header },
{ "Header extension", test_header_extension_1 },
{ "Header extension 2", test_header_extension_2 },
{ "Header event", test_event_header }
{ "Header event", test_event_header },
{ "Header Supported", test_supported_header }
};
......
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