Commit 5b70760f authored by jehan's avatar jehan

add header Refer-To

parent 3017fe57
......@@ -99,6 +99,7 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_refresher_t),
BELLE_SIP_TYPE_ID(belle_sip_header_subscription_state_t),
BELLE_SIP_TYPE_ID(belle_sip_header_service_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_refer_to_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -513,5 +513,16 @@ void belle_sip_header_subscription_state_set_retry_after(belle_sip_header_subscr
#define BELLE_SIP_SUBSCRIPTION_STATE_PENDING "pending"
#define BELLE_SIP_SUBSCRIPTION_STATE_TERMINATED "terminated"
/******************************
* Refer-To header object inherent from header_address
*
******************************/
typedef struct _belle_sip_header_refer_to belle_sip_header_refer_to_t;
belle_sip_header_refer_to_t* belle_sip_header_refer_to_new();
BELLESIP_EXPORT belle_sip_header_refer_to_t* belle_sip_header_refer_to_parse(const char* refer_to) ;
BELLESIP_EXPORT belle_sip_header_refer_to_t* belle_sip_header_refer_to_create(const belle_sip_header_address_t *address);
#define BELLE_SIP_HEADER_REFER_TO(t) BELLE_SIP_CAST(t,belle_sip_header_refer_to_t)
#define BELLE_SIP_REFER_TO "Refer-To"
#endif /* HEADERS_H_ */
......@@ -1186,3 +1186,30 @@ belle_sip_header_subscription_state_t* belle_sip_header_subscription_state_creat
belle_sip_header_subscription_state_set_expires(sub_state,expires);
return sub_state;
}
/**************************
* Refer-To header object inherits from header_address
****************************
*/
struct _belle_sip_header_refer_to {
belle_sip_header_address_t address;
};
static void belle_sip_header_refer_to_destroy(belle_sip_header_refer_to_t* refer_to) {
}
void belle_sip_header_refer_to_clone(belle_sip_header_refer_to_t *contact, const belle_sip_header_refer_to_t *orig){
}
int belle_sip_header_refer_to_marshal(belle_sip_header_refer_to_t* refer_to, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(refer_to)
}
BELLE_SIP_NEW_HEADER(header_refer_to,header_address,BELLE_SIP_REFER_TO)
BELLE_SIP_PARSE(header_refer_to)
belle_sip_header_refer_to_t* belle_sip_header_refer_to_create(const belle_sip_header_address_t* address) {
belle_sip_header_refer_to_t* header= belle_sip_header_refer_to_new();
_belle_sip_object_copy((belle_sip_object_t*)header,(belle_sip_object_t*)address);
belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_REFER_TO); /*restaure header name*/
return header;
}
......@@ -179,6 +179,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sdp_mime_parameter_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_refresher_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_subscription_state_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_service_route_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_refer_to_t);
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
......
......@@ -972,6 +972,25 @@ to_spec
( semi to_param )*;
to_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_to::current)];
refer_to_token: {IS_TOKEN(Refer-To)}? token;
header_refer_to returns [belle_sip_header_refer_to_t* ret]
scope { belle_sip_header_refer_to_t* current; }
@init { $header_refer_to::current = belle_sip_header_refer_to_new(); }
: refer_to_token /*'Refer-To'*/ hcolon refer_to_spec {$ret = $header_refer_to::current;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($header_refer_to::current);
$ret=NULL;
}
refer_to_spec
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_refer_to::current)] | paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_refer_to::current)] )
( semi refer_to_param )*;
refer_to_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_refer_to::current)];
/*
unsupported
: 'Unsupported' HCOLON option_tag (COMMA option_tag)*;
......@@ -1140,6 +1159,8 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_subscription_state_parse((const char*)$header_extension.text->chars));
}else if (check_for_known_header && strcasecmp(BELLE_SIP_SERVICE_ROUTE,(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_service_route_parse((const char*)$header_extension.text->chars));
}else if (check_for_known_header && strcasecmp(BELLE_SIP_REFER_TO,(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_refer_to_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);
......
......@@ -330,9 +330,9 @@ belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
}
static void channel_invoke_state_listener(belle_sip_channel_t *obj){
belle_sip_object_ref(obj);
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_state_changed,obj,obj->state);
belle_sip_object_unref(obj);
belle_sip_list_t* list=belle_sip_list_copy(obj->listeners); /*copy list because error state alter this list (I.E by provider)*/
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(list,belle_sip_channel_listener_t,on_state_changed,obj,obj->state);
belle_sip_list_free(list);
}
void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state) {
......
......@@ -553,6 +553,28 @@ void test_header_subscription_state(void) {
CU_ASSERT_EQUAL(belle_sip_header_subscription_state_get_expires(L_subscription_state), 600);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_subscription_state));
}
void test_simple_header_refer_to(void) {
belle_sip_uri_t* L_uri;
belle_sip_header_refer_to_t* L_refer_to = belle_sip_header_refer_to_parse("Refer-To: <sip:dave@denver.example.org?Replaces=12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994>");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_refer_to));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
L_refer_to = belle_sip_header_refer_to_parse(l_raw_header);
belle_sip_free(l_raw_header);
L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri),"dave");
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "denver.example.org");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
/*test factory*/
L_refer_to = belle_sip_header_refer_to_create(belle_sip_header_address_parse("\"super man\" <sip:titi.com>"));
CU_ASSERT_PTR_NOT_NULL_FATAL(L_refer_to);
L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));
CU_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname(BELLE_SIP_HEADER_ADDRESS(L_refer_to)), "super man");
belle_sip_object_unref(L_refer_to);
}
int belle_sip_headers_test_suite() {
......@@ -643,5 +665,8 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test_header_contact_with_paramless_address_spec",test_header_contact_with_paramless_address_spec )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_simple_header_refer_to",test_simple_header_refer_to )) {
return CU_get_error();
}
return 0;
}
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