Commit 3efb7ed5 authored by jehan's avatar jehan

add partial parser for header event

parent d8af97d4
......@@ -650,6 +650,22 @@ BELLESIP_EXPORT belle_sip_list_t* belle_sip_header_privacy_get_privacy(const bel
#define BELLE_SIP_HEADER_PRIVACY(t) BELLE_SIP_CAST(t,belle_sip_header_privacy_t)
#define BELLE_SIP_PRIVACY "Privacy"
/******************************
* Event header object inherent from parameters
*
******************************/
typedef struct _belle_sip_header_event belle_sip_header_event_t;
BELLESIP_EXPORT belle_sip_header_event_t* belle_sip_header_event_new();
BELLESIP_EXPORT belle_sip_header_event_t* belle_sip_header_event_parse(const char* event) ;
BELLESIP_EXPORT belle_sip_header_event_t* belle_sip_header_event_create(const char* event);
BELLESIP_EXPORT const char* belle_sip_header_event_get_package_name(const belle_sip_header_event_t* event);
BELLESIP_EXPORT void belle_sip_header_event_set_package_name(belle_sip_header_event_t* event, const char* package_name);
BELLESIP_EXPORT const char* belle_sip_header_event_get_id(const belle_sip_header_event_t* event);
BELLESIP_EXPORT void belle_sip_header_event_set_id(belle_sip_header_event_t* event, const char* id);
#define BELLE_SIP_HEADER_EVENT(t) BELLE_SIP_CAST(t,belle_sip_header_event_t)
#define BELLE_SIP_EVENT "Event"
BELLE_SIP_END_DECLS
......
......@@ -215,7 +215,7 @@ BELLESIP_EXPORT void belle_sip_uri_set_user_password(belle_sip_uri_t* uri,const
* This method returns the URI as a string.
*
*/
BELLESIP_EXPORT char* belle_sip_uri_to_string(belle_sip_uri_t* uri) ;
BELLESIP_EXPORT char* belle_sip_uri_to_string(const belle_sip_uri_t* uri) ;
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, size_t *offset);
......@@ -238,7 +238,17 @@ BELLESIP_EXPORT int belle_sip_uri_check_components_from_request_uri(const belle_
BELLESIP_EXPORT int belle_sip_uri_check_components_from_context(const belle_sip_uri_t* uri,const char* method,const char* header_name);
BELLE_SIP_END_DECLS
#if defined(__cplusplus) && defined(BELLE_SIP_USE_STL)
#include <ostream>
inline ostream&
operator<<( ostream& __os, const belle_sip_uri_t* uri)
{
char* uri_as_string = belle_sip_uri_to_string(uri);
__os << uri_as_string;
belle_sip_free(uri_as_string);
return __os;
}
#endif
#endif /*BELLE_SIP_URI_H_*/
......@@ -130,7 +130,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_memory_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_file_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_user_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_multipart_body_handler_t)
BELLE_SIP_TYPE_ID(belle_sip_multipart_body_handler_t),
BELLE_SIP_TYPE_ID(belle_sip_header_event_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -1749,3 +1749,43 @@ belle_sip_header_privacy_t* belle_sip_header_privacy_create(const char* privacy)
belle_sip_header_privacy_add_privacy(privacy_header,privacy);
return privacy_header;
}
/**************************
* Event header object inherent from parameters
****************************
*/
struct _belle_sip_header_event {
belle_sip_parameters_t parameters;
const char* package_name;
};
static void belle_sip_header_event_destroy(belle_sip_header_event_t* event) {
DESTROY_STRING(event,package_name);
}
static void belle_sip_header_event_clone(belle_sip_header_event_t* event, const belle_sip_header_event_t *orig ) {
CLONE_STRING(belle_sip_header_event,package_name,event,orig)
}
belle_sip_error_code belle_sip_header_event_marshal(belle_sip_header_event_t* event, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(event), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",event->package_name);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(event), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
return error;
}
BELLE_SIP_NEW_HEADER(header_event,parameters,BELLE_SIP_EVENT)
BELLE_SIP_PARSE(header_event)
GET_SET_STRING(belle_sip_header_event,package_name);
GET_SET_STRING_PARAM(belle_sip_header_event,id);
belle_sip_header_event_t* belle_sip_header_event_create (const char* package_name) {
belle_sip_header_event_t* event=belle_sip_header_event_new();
belle_sip_header_event_set_package_name(event,package_name);
return event;
}
......@@ -204,6 +204,7 @@ BELLE_SIP_DECLARE_VPTR(belle_generic_uri_t);
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_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......
......@@ -179,7 +179,7 @@ belle_sip_uri_t* belle_sip_uri_create (const char* username,const char* host) {
}
char* belle_sip_uri_to_string(belle_sip_uri_t* uri) {
char* belle_sip_uri_to_string(const belle_sip_uri_t* uri) {
return belle_sip_object_to_string(BELLE_SIP_OBJECT(uri));
}
......
......@@ -45,7 +45,7 @@ options {
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused"
#pragma GCC diagnostic ignored "-Wtautological-compare"
#ifndef __clang__
#ifndef __CLANG__
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
}
......
......@@ -1278,6 +1278,21 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
$ret=NULL;
}
header_event returns [belle_sip_header_event_t* ret]
scope { belle_sip_header_event_t* current; }
@init { $header_event::current = belle_sip_header_event_new();$ret = $header_event::current; }
: {IS_TOKEN(Event)}? token /*"Event"*/
hcolon event_package {belle_sip_header_event_set_package_name($header_event::current,(const char*)$event_package.text->chars);}
(semi generic_param [BELLE_SIP_PARAMETERS($header_event::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_event::current);
$ret=NULL;
}
event_package
: token;
/*
Replaces = "Replaces" HCOLON replaces-values
*(COMMA replaces-values)
......
......@@ -481,6 +481,7 @@ static code_phrase_t well_known_codes[]={
{ 407 , "Proxy authentication required" },
{ 408 , "Request timeout" },
{ 410 , "Gone" },
{ 412 , "Conditional Request Failed" }, /*rfc3903*/
{ 413 , "Request entity too large" },
{ 414 , "Request-URI too long" },
{ 415 , "Unsupported media type" },
......@@ -497,6 +498,7 @@ static code_phrase_t well_known_codes[]={
{ 486 , "Busy here" },
{ 487 , "Request terminated" },
{ 488 , "Not acceptable here" },
{ 489 , "Bad Event" }, /*rfc3265*/
{ 491 , "Request pending" },
{ 493 , "Undecipherable" },
{ 500 , "Server internal error" },
......
......@@ -834,6 +834,22 @@ static void test_privacy_header() {
test_privacy("Privacy: id",value2,1);
}
static void test_event_header(void) {
belle_sip_header_event_t* L_tmp;
belle_sip_header_event_t* L_event = belle_sip_header_event_parse("Event: presence;id=blabla1");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_event));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_event));
L_tmp = belle_sip_header_event_parse(l_raw_header);
L_event = BELLE_SIP_HEADER_EVENT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
CU_ASSERT_STRING_EQUAL(belle_sip_header_event_get_package_name(L_event), "presence");
CU_ASSERT_STRING_EQUAL(belle_sip_header_event_get_id(L_event), "blabla1");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_event));
CU_ASSERT_PTR_NULL(belle_sip_header_event_parse("nimportequoi"));
}
test_t headers_tests[] = {
{ "Address", test_address_header },
{ "Header address (very long)", test_very_long_address_header },
......@@ -870,7 +886,8 @@ test_t headers_tests[] = {
{ "Via", test_via_header },
{ "WWW-Authenticate", test_www_authenticate_header },
{ "Header extension", test_header_extension_1 },
{ "Header extension 2", test_header_extension_2 }
{ "Header extension 2", test_header_extension_2 },
{ "Header event", test_event_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