Commit 0d860ad4 authored by jehan's avatar jehan

add header privacy

parent 589d000c
......@@ -107,7 +107,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_header_referred_by_t),
BELLE_SIP_TYPE_ID(belle_sip_header_replaces_t),
BELLE_SIP_TYPE_ID(belle_sip_header_date_t),
BELLE_SIP_TYPE_ID(belle_sip_header_p_preferred_identity_t)
BELLE_SIP_TYPE_ID(belle_sip_header_p_preferred_identity_t),
BELLE_SIP_TYPE_ID(belle_sip_header_privacy_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -590,7 +590,7 @@ BELLESIP_EXPORT void belle_sip_header_date_set_date(belle_sip_header_date_t *obj
#define BELLE_SIP_DATE "Date"
/******************************
* To header object inherent from header_address
* P-Preferred-Identity header object inherent from header_address
*
******************************/
typedef struct _belle_sip_header_p_preferred_identity belle_sip_header_p_preferred_identity_t;
......@@ -604,4 +604,26 @@ BELLESIP_EXPORT belle_sip_header_p_preferred_identity_t* belle_sip_header_p_pref
#define BELLE_SIP_HEADER_P_PREFERRED_IDENTITY(t) BELLE_SIP_CAST(t,belle_sip_header_p_preferred_identity_t)
#define BELLE_SIP_P_PREFERRED_IDENTITY "P-Preferred-Identity"
/******************************
* Privacy header object inherent from header
*
******************************/
typedef struct _belle_sip_header_privacy belle_sip_header_privacy_t;
BELLESIP_EXPORT belle_sip_header_privacy_t* belle_sip_header_privacy_new();
BELLESIP_EXPORT belle_sip_header_privacy_t* belle_sip_header_privacy_parse(const char* privacy) ;
BELLESIP_EXPORT belle_sip_header_privacy_t* belle_sip_header_privacy_create(const char* privacy);
BELLESIP_EXPORT void belle_sip_header_privacy_add_privacy(belle_sip_header_privacy_t* privacy, const char* value);
BELLESIP_EXPORT void belle_sip_header_privacy_set_privacy(belle_sip_header_privacy_t* privacy, belle_sip_list_t* privacy_values);
BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_privacy_get_privacy(const belle_sip_header_privacy_t* privacy);
#define BELLE_SIP_HEADER_PRIVACY(t) BELLE_SIP_CAST(t,belle_sip_header_privacy_t)
#define BELLE_SIP_PRIVACY "Privacy"
#endif /* HEADERS_H_ */
......@@ -1512,3 +1512,47 @@ belle_sip_header_p_preferred_identity_t* belle_sip_header_p_preferred_identity_c
return header;
}
/******************************
* Privacy header inherits from header
*
******************************/
struct _belle_sip_header_privacy {
belle_sip_header_t header;
belle_sip_list_t* privacy;
};
static void belle_sip_header_privacy_destroy(belle_sip_header_privacy_t* p) {
belle_sip_header_privacy_set_privacy(p,NULL);
}
static void belle_sip_header_privacy_clone(belle_sip_header_privacy_t* p, const belle_sip_header_privacy_t* orig){
belle_sip_list_t* list=orig->privacy;
for(;list!=NULL;list=list->next){
belle_sip_header_privacy_add_privacy(p,(const char *)list->data);
}
}
belle_sip_error_code belle_sip_header_privacy_marshal(belle_sip_header_privacy_t* p, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
belle_sip_list_t* list = p->privacy;
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->privacy ? "%s" : ";%s",(const char *)list->data);
if (error!=BELLE_SIP_OK) return error;
}
return error;
}
BELLE_SIP_NEW_HEADER(header_privacy,header,BELLE_SIP_PRIVACY)
BELLE_SIP_PARSE(header_privacy)
belle_sip_list_t* belle_sip_header_privacy_get_privacy(const belle_sip_header_privacy_t* p) {
return p->privacy;
}
SET_ADD_STRING_LIST(belle_sip_header_privacy,privacy)
belle_sip_header_privacy_t* belle_sip_header_privacy_create(const char* privacy) {
belle_sip_header_privacy_t* privacy_header=belle_sip_header_privacy_new();
belle_sip_header_privacy_add_privacy(privacy_header,privacy);
return privacy_header;
}
......@@ -187,6 +187,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_date_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_hop_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_object_pool_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_p_preferred_identity_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_privacy_t);
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
......
......@@ -1180,7 +1180,17 @@ header_p_preferred_identity returns [belle_sip_header_p_preferred_identity_t* re
: {IS_HEADER_NAMED(P-Preferred-Identity,NULL)}? token /*"P-Preferred-Identity"*/
hcolon header_address_base[(belle_sip_header_address_t*)belle_sip_header_p_preferred_identity_new()] {$ret=(belle_sip_header_p_preferred_identity_t*)$header_address_base.ret;};
header_privacy returns [belle_sip_header_privacy_t* ret]
scope { belle_sip_header_privacy_t* current; }
@init { $header_privacy::current = belle_sip_header_privacy_new();$ret = $header_privacy::current;}
: {IS_TOKEN(Privacy)}? token /*'Privacy'*/ hcolon privacy_val (semi privacy_val)*;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
privacy_val: token {belle_sip_header_privacy_add_privacy($header_privacy::current,(const char*)$token.text->chars);};
//********************************************************************************************//
......@@ -1237,6 +1247,8 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_date_parse((const char*)$header_extension.text->chars));
}else if (check_for_known_header && strcasecmp(BELLE_SIP_P_PREFERRED_IDENTITY,(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_p_preferred_identity_parse((const char*)$header_extension.text->chars));
}else if (check_for_known_header && strcasecmp(BELLE_SIP_PRIVACY,(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_privacy_parse((const char*)$header_extension.text->chars));
}else {
$ret = BELLE_SIP_HEADER(belle_sip_header_extension_new());
belle_sip_header_extension_set_value((belle_sip_header_extension_t*)$ret,(const char*)$header_value.text->chars);
......
......@@ -698,7 +698,37 @@ static void test_p_preferred_identity_header(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(L_p_preferred_identity));
}
static void test_privacy(const char* raw_header,const char* values[],size_t number_values) {
belle_sip_list_t* list;
belle_sip_header_privacy_t* L_tmp;
belle_sip_header_privacy_t* L_privacy = belle_sip_header_privacy_parse(raw_header);
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_privacy));
int i=0;
belle_sip_object_unref(BELLE_SIP_OBJECT(L_privacy));
L_tmp = belle_sip_header_privacy_parse(l_raw_header);
L_privacy = BELLE_SIP_HEADER_PRIVACY(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_privacy_get_privacy(L_privacy);
for(i=0;i<number_values;i++){
CU_ASSERT_PTR_NOT_NULL(list);
CU_ASSERT_STRING_EQUAL((const char *)(list->data),values[i]);
list=list->next;
}
belle_sip_object_unref(BELLE_SIP_OBJECT(L_privacy));
}
static void test_privacy_header() {
const char* value1[] ={"user","critical"};
const char* value2[] ={"id"};
test_privacy("Privacy: user; critical",value1,2);
test_privacy("Privacy: id",value2,1);
}
test_t headers_tests[] = {
{ "Address", test_address_header },
{ "Header address (very long)", test_very_long_address_header },
......@@ -717,6 +747,7 @@ test_t headers_tests[] = {
{ "From", test_from_header },
{ "From (Param-less address spec)", test_from_header_with_paramless_address_spec },
{ "Max-Forwards", test_max_forwards_header },
{ "Privacy", test_privacy_header },
{ "P-Preferred-Identity", test_p_preferred_identity_header },
{ "Proxy-Authenticate", test_proxy_authenticate_header },
{ "Proxy-Authorization", test_proxy_authorization_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