Commit 1ced6378 authored by jehan's avatar jehan

fix both content disposition & accept header

parent 81cb1c15
......@@ -707,11 +707,10 @@ BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_supported_get_supported(const
******************************/
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);
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 const char* belle_sip_header_content_disposition_get_content_disposition(const belle_sip_header_content_disposition_t* content_disposition);
BELLESIP_EXPORT void belle_sip_header_content_disposition_set_content_disposition(belle_sip_header_content_disposition_t* obj,const char* 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"
......
......@@ -1872,7 +1872,40 @@ PRIVACY_LIKE_HEADER(supported,BELLE_SIP_SUPPORTED,",")
* Content-Disposition header inherits from header
*
******************************/
PRIVACY_LIKE_HEADER(content_disposition,BELLE_SIP_CONTENT_DISPOSITION,";")
struct _belle_sip_header_content_disposition {
belle_sip_parameters_t parameters;
const char* content_disposition;
};
static void belle_sip_header_content_disposition_destroy(belle_sip_header_content_disposition_t* content_disposition) {
DESTROY_STRING(content_disposition,content_disposition);
}
static void belle_sip_header_content_disposition_clone(belle_sip_header_content_disposition_t* content_disposition,
const belle_sip_header_content_disposition_t *orig ) {
CLONE_STRING(belle_sip_header_content_disposition,content_disposition,content_disposition,orig)
}
belle_sip_error_code belle_sip_header_content_disposition_marshal(belle_sip_header_content_disposition_t* content_disposition, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(content_disposition), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",content_disposition->content_disposition);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(content_disposition), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
return error;
}
BELLE_SIP_NEW_HEADER(header_content_disposition,parameters,BELLE_SIP_CONTENT_DISPOSITION)
BELLE_SIP_PARSE(header_content_disposition)
GET_SET_STRING(belle_sip_header_content_disposition,content_disposition);
belle_sip_header_content_disposition_t* belle_sip_header_content_disposition_create (const char* value) {
belle_sip_header_content_disposition_t* header=belle_sip_header_content_disposition_new();
belle_sip_header_content_disposition_set_content_disposition(header,value);
return header;
}
/******************************
* Accept header inherits from parameters
......
......@@ -1420,33 +1420,48 @@ supported_val: token {belle_sip_header_supported_add_supported($header_supported
//**********************************Content-Disposition*******************************//
content_disposition_value: token ;
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)*;
@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_value {belle_sip_header_content_disposition_set_content_disposition($header_content_disposition::current,(const char*)$content_disposition_value.text->chars);}
(semi generic_param [BELLE_SIP_PARAMETERS($header_content_disposition::current)])* ;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
belle_sip_object_unref($header_content_disposition::current);
$ret=NULL;
}
content_disposition_val: token {belle_sip_header_content_disposition_add_content_disposition($header_content_disposition::current,(const char*)$token.text->chars);};
//**********************************Accept*******************************//
accept_token : {IS_TOKEN(Accept)}? token;
header_accept returns [belle_sip_header_accept_t* ret=NULL]
scope { belle_sip_header_accept_t* current;}
@init { $header_accept::current = belle_sip_header_accept_new();$ret=$header_accept::current; }
: accept_token/* ( 'Accept')*/ hcolon accept_media_type;
scope { belle_sip_header_accept_t* current; belle_sip_header_accept_t* first; }
@init { $header_accept::current = NULL;$header_accept::first =NULL;$ret = NULL;}
: accept_token/* ( 'Accept')*/ hcolon accept_param (comma accept_param)* {$ret = $header_accept::first;} ;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($header_accept::current);
$ret = $header_accept::first;
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
accept_media_type
accept_param
scope { belle_sip_header_accept_t* prev;}
@init { if ($header_accept::current == NULL) {
$header_accept::first = $header_accept::current = belle_sip_header_accept_new();
$accept_param::prev=NULL;
} else {
belle_sip_header_t* header;
$accept_param::prev=$header_accept::current;
header = BELLE_SIP_HEADER($header_accept::current);
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_accept::current = belle_sip_header_accept_new()));
}
}
: accept_main_media_type {belle_sip_header_accept_set_type($header_accept::current,(const char*)$accept_main_media_type.text->chars);}
slash
accept_sub_media_type {belle_sip_header_accept_set_subtype($header_accept::current,(const char*)$accept_sub_media_type.text->chars);}
......@@ -1456,6 +1471,7 @@ accept_main_media_type: token;
accept_sub_media_type: token;
//*********************************************//
header returns [belle_sip_header_t* ret=NULL]
: header_extension_base[FALSE] {$ret=$header_extension_base.ret;};
......
......@@ -331,10 +331,13 @@ belle_sip_error_code belle_sip_headers_marshal(belle_sip_message_t *message, cha
}else
#endif
{
error=belle_sip_object_marshal(BELLE_SIP_OBJECT(h),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s","\r\n");
if (error!=BELLE_SIP_OK) return error;
while (h!=NULL) { /*header can be chained*/
error=belle_sip_object_marshal(BELLE_SIP_OBJECT(h),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s","\r\n");
if (error!=BELLE_SIP_OK) return error;
h= belle_sip_header_get_next(h);
}
}
}
}
......
......@@ -1042,43 +1042,29 @@ 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;
static void test_content_disposition_header(void) {
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));
belle_sip_header_content_disposition_t* L_content_disposition = BELLE_SIP_HEADER_CONTENT_DISPOSITION(belle_sip_header_create("Content-Disposition","form-data; name=\"File\"; filename=\"toto.jpeg\""));
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;
}
}
BC_ASSERT_STRING_EQUAL(belle_sip_header_content_disposition_get_content_disposition(L_content_disposition), "form-data");
BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_disposition), "name"), "\"File\"");
BC_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_disposition), "filename"), "\"toto.jpeg\"");
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(BELLE_SIP_CONTENT_DISPOSITION, "recipient-list",value2,1);
test_content_disposition("Content-Disposition","user; critical",value1,2);
}
static void test_accept(const char* header_name, const char * header_value, const char* values[],size_t number_values) {
static void test_accept_header(void) {
belle_sip_header_accept_t* L_tmp;
belle_sip_header_accept_t* L_accept = BELLE_SIP_HEADER_ACCEPT(belle_sip_header_create("Accept", "text/html; charset=ISO-8859-4"));
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_accept));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_accept));
L_tmp = belle_sip_header_accept_parse(l_raw_header);
L_accept = BELLE_SIP_HEADER_ACCEPT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
......@@ -1105,17 +1091,20 @@ static void test_accept(const char* header_name, const char * header_value, cons
L_accept = belle_sip_header_accept_parse(l_raw_header);
belle_sip_free(l_raw_header);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_accept));
L_accept = belle_sip_header_accept_parse("Accept: application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_type(L_accept),"application");
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_subtype(L_accept),"sdp");
L_tmp = BELLE_SIP_HEADER_ACCEPT(belle_sip_header_get_next(BELLE_SIP_HEADER(L_accept)));
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_type(L_tmp),"text");
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_subtype(L_tmp),"plain");
L_tmp = BELLE_SIP_HEADER_ACCEPT(belle_sip_header_get_next(BELLE_SIP_HEADER(L_tmp)));
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_type(L_tmp),"application");
BC_ASSERT_STRING_EQUAL(belle_sip_header_accept_get_subtype(L_tmp),"vnd.gsma.rcs-ft-http+xml");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_accept));
BC_ASSERT_PTR_NULL(belle_sip_header_accept_parse("nimportequoi"));
}
static void test_accept_header(void) {
const char* value1[] ={"user","critical"};
const char* value2[] ={"recipient-list"};
test_accept(BELLE_SIP_ACCEPT, "recipient-list",value2,1);
test_accept("Accept","user; critical",value1,2);
}
test_t headers_tests[] = {
{ "Address", test_address_header },
......@@ -1159,7 +1148,6 @@ test_t headers_tests[] = {
{ "Header Supported", test_supported_header },
{ "Header Content-Disposition", test_content_disposition_header },
{ "Header Accept", test_accept_header }
};
test_suite_t headers_test_suite = {"Headers", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
......
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