Commit fbb27d34 authored by jehan's avatar jehan

add support for header Content-Disposition

parent f84d9559
......@@ -701,6 +701,21 @@ BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_supported_get_supported(const
#define BELLE_SIP_HEADER_SUPPORTED(t) BELLE_SIP_CAST(t,belle_sip_header_supported_t)
#define BELLE_SIP_SUPPORTED "Supported"
/******************************
* Content Disposition header object inherent from header
*
******************************/
typedef struct _belle_sip_header_content_disposition belle_sip_header_content_disposition_t;
BELLESIP_EXPORT belle_sip_header_content_disposition_t* belle_sip_header_content_disposition_new();
BELLESIP_EXPORT belle_sip_header_content_disposition_t* belle_sip_header_content_disposition_parse(const char* content_disposition) ;
BELLESIP_EXPORT belle_sip_header_content_disposition_t* belle_sip_header_content_disposition_create(const char* content_disposition);
BELLESIP_EXPORT void belle_sip_header_content_disposition_add_content_disposition(belle_sip_header_content_disposition_t* content_disposition, const char* value);
BELLESIP_EXPORT void belle_sip_header_content_disposition_set_content_disposition(belle_sip_header_content_disposition_t* content_disposition, belle_sip_list_t* content_disposition_values);
BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_content_disposition_get_content_disposition(const belle_sip_header_content_disposition_t* content_disposition);
#define BELLE_SIP_HEADER_CONTENT_DISPOSITION(t) BELLE_SIP_CAST(t,belle_sip_header_content_disposition_t)
#define BELLE_SIP_CONTENT_DISPOSITION "Content-Disposition"
BELLE_SIP_END_DECLS
......
......@@ -132,7 +132,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
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_supported_t)
BELLE_SIP_TYPE_ID(belle_sip_header_supported_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_disposition_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -79,6 +79,7 @@ static struct header_name_func_pair header_table[] = {
,{PROTO_SIP, BELLE_SIP_EVENT, (header_parse_func)belle_sip_header_event_parse}
,{PROTO_SIP, BELLE_SIP_SUPPORTED, (header_parse_func)belle_sip_header_supported_parse}
,{PROTO_SIP, "k", (header_parse_func)belle_sip_header_supported_parse}
,{PROTO_SIP, BELLE_SIP_CONTENT_DISPOSITION, (header_parse_func)belle_sip_header_content_disposition_parse}
};
static belle_sip_header_t* belle_header_create(const char* name,const char* value,int protocol) {
......@@ -1902,5 +1903,49 @@ belle_sip_header_supported_t* belle_sip_header_supported_create(const char* supp
return supported_header;
}
/******************************
* Content-Disposition header inherits from header
*
******************************/
struct _belle_sip_header_content_disposition {
belle_sip_header_t header;
belle_sip_list_t* content_disposition;
};
static void belle_sip_header_content_disposition_destroy(belle_sip_header_content_disposition_t* p) {
belle_sip_header_content_disposition_set_content_disposition(p,NULL);
}
static void belle_sip_header_content_disposition_clone(belle_sip_header_content_disposition_t* p, const belle_sip_header_content_disposition_t* orig){
belle_sip_list_t* list=orig->content_disposition;
for(;list!=NULL;list=list->next){
belle_sip_header_content_disposition_add_content_disposition(p,(const char *)list->data);
}
}
belle_sip_error_code belle_sip_header_content_disposition_marshal(belle_sip_header_content_disposition_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->content_disposition;
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->content_disposition ? "%s" : "; %s",(const char *)list->data);
if (error!=BELLE_SIP_OK) return error;
}
return error;
}
BELLE_SIP_NEW_HEADER(header_content_disposition,header,BELLE_SIP_CONTENT_DISPOSITION)
BELLE_SIP_PARSE(header_content_disposition)
belle_sip_list_t* belle_sip_header_content_disposition_get_content_disposition(const belle_sip_header_content_disposition_t* p) {
return p->content_disposition;
}
SET_ADD_STRING_LIST(belle_sip_header_content_disposition,content_disposition)
belle_sip_header_content_disposition_t* belle_sip_header_content_disposition_create(const char* content_disposition) {
belle_sip_header_content_disposition_t* content_disposition_header=belle_sip_header_content_disposition_new();
belle_sip_header_content_disposition_add_content_disposition(content_disposition_header,content_disposition);
return content_disposition_header;
}
......@@ -206,6 +206,7 @@ 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_VPTR(belle_sip_header_content_disposition_t);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......
......@@ -1418,6 +1418,20 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
}
supported_val: token {belle_sip_header_supported_add_supported($header_supported::current,(const char*)$token.text->chars);};
//**********************************Content-Disposition*******************************//
header_content_disposition returns [belle_sip_header_content_disposition_t* ret]
scope { belle_sip_header_content_disposition_t* current; }
@init { $header_content_disposition::current = belle_sip_header_content_disposition_new();$ret = $header_content_disposition::current;}
: {IS_TOKEN(Content-Disposition)}? token /*'Content-Disposition'*/ hcolon content_disposition_val (semi content_disposition_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;
}
content_disposition_val: token {belle_sip_header_content_disposition_add_content_disposition($header_content_disposition::current,(const char*)$token.text->chars);};
......
......@@ -1042,6 +1042,39 @@ static void test_supported_header(void) {
test_supported("Supported", "id",value2,1);
}
static void test_content_disposition(const char* header_name, const char * header_value, const char* values[],size_t number_values) {
belle_sip_list_t* list;
belle_sip_header_content_disposition_t* L_tmp;
belle_sip_header_content_disposition_t* L_content_disposition = BELLE_SIP_HEADER_CONTENT_DISPOSITION(belle_sip_header_create(header_name,header_value));
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_content_disposition));
size_t i=0;
belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_disposition));
L_tmp = belle_sip_header_content_disposition_parse(l_raw_header);
L_content_disposition = BELLE_SIP_HEADER_CONTENT_DISPOSITION(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_content_disposition_get_content_disposition(L_content_disposition);
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_content_disposition));
BC_ASSERT_PTR_NULL(belle_sip_header_content_disposition_parse("nimportequoi"));
}
static void test_content_disposition_header(void) {
const char* value1[] ={"user","critical"};
const char* value2[] ={"recipient-list"};
test_content_disposition("Content-Disposition", "recipient-list",value2,1);
test_content_disposition("Content-Disposition","user; critical",value1,2);
}
test_t headers_tests[] = {
{ "Address", test_address_header },
......@@ -1082,7 +1115,8 @@ test_t headers_tests[] = {
{ "Header extension", test_header_extension_1 },
{ "Header extension 2", test_header_extension_2 },
{ "Header event", test_event_header },
{ "Header Supported", test_supported_header }
{ "Header Supported", test_supported_header },
{ "Header Content-Disposition", test_content_disposition_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