Commit 5aa22d39 authored by jehan's avatar jehan

add Service-route header

fix param less address spec (I.E header like From: sip:toto@titi.com:tag=asdad )
parent 89ee87a8
......@@ -105,6 +105,7 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_callbacks_t),
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_DECLARE_TYPES_END
......
......@@ -320,6 +320,17 @@ belle_sip_header_expires_t* belle_sip_header_expires_create(int expires);
#define BELLE_SIP_HEADER_RECORD_ROUTE(t) BELLE_SIP_CAST(t,belle_sip_header_record_route_t)
#define BELLE_SIP_RECORD_ROUTE "Record-route"
/******************************
* Service route header object inherent from header_address
*
******************************/
typedef struct _belle_sip_header_service_route belle_sip_header_service_route_t;
belle_sip_header_service_route_t* belle_sip_header_service_route_new();
belle_sip_header_service_route_t* belle_sip_header_service_route_parse (const char* route) ;
#define BELLE_SIP_HEADER_SERVICE_ROUTE(t) BELLE_SIP_CAST(t,belle_sip_header_service_route_t)
#define BELLE_SIP_SERVICE_ROUTE "Service-route"
/******************************
*
* user-Agent header inherit from header
......
......@@ -670,9 +670,28 @@ static void belle_sip_header_record_route_clone(belle_sip_header_record_route_t*
int belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(record_route)
}
BELLE_SIP_NEW_HEADER(header_record_route,header_address,"Record-Route")
BELLE_SIP_NEW_HEADER(header_record_route,header_address,BELLE_SIP_RECORD_ROUTE)
BELLE_SIP_PARSE(header_record_route)
/**************************
* Service route header object inherent from header_address
****************************
*/
struct _belle_sip_header_service_route {
belle_sip_header_address_t address;
};
static void belle_sip_header_service_route_destroy(belle_sip_header_service_route_t* service_route) {
}
static void belle_sip_header_service_route_clone(belle_sip_header_service_route_t* service_route,
const belle_sip_header_service_route_t* orig ) {
}
int belle_sip_header_service_route_marshal(belle_sip_header_service_route_t* service_route, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(service_route)
}
BELLE_SIP_NEW_HEADER(header_service_route,header_address,BELLE_SIP_SERVICE_ROUTE)
BELLE_SIP_PARSE(header_service_route)
/**************************
* content length header object inherent from object
****************************
*/
......
......@@ -207,6 +207,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sdp_base_description_t);
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);
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
......
......@@ -447,7 +447,7 @@ scope { belle_sip_header_contact_t* prev;}
}
}
: (name_addr[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]
| addr_spec[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]) (semi contact_params)*;
| paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]) (semi contact_params)*;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
......@@ -477,7 +477,10 @@ name_addr[belle_sip_header_address_t* object]
addr_spec[belle_sip_header_address_t* object]
: uri {belle_sip_header_address_set_uri(object,$uri.ret);};//| absoluteURI;
display_name[belle_sip_header_address_t* object]
paramless_addr_spec[belle_sip_header_address_t* object]
: paramless_uri {belle_sip_header_address_set_uri(object,$paramless_uri.ret);};//| absoluteURI;
display_name[belle_sip_header_address_t* object]
: token {belle_sip_header_address_set_displayname(object,(const char*)($token.text->chars));}
| quoted_string {belle_sip_header_address_set_quoted_displayname(object,(const char*)($quoted_string.text->chars));}
;
......@@ -650,7 +653,7 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
}
from_spec
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_from::current)] | addr_spec[BELLE_SIP_HEADER_ADDRESS($header_from::current)] )
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_from::current)] | paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_from::current)] )
( SEMI from_param )*;
from_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_from::current)];
......@@ -801,6 +804,45 @@ proxy_require
option_tag
: token;
*/
/*FIXME service-route = recorde-route = route, too many copy/past*/
service_route_token: {IS_TOKEN(Service-Route)}? token;
header_service_route returns [belle_sip_header_service_route_t* ret]
scope { belle_sip_header_service_route_t* current; belle_sip_header_service_route_t* first;}
@init { $header_service_route::current = NULL;}
: service_route_token /*'Service-Route'*/ hcolon srv_route (comma srv_route)* {$ret = $header_service_route::first;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($header_service_route::current);
$ret=NULL;
}
srv_route
scope { belle_sip_header_service_route_t* prev;}
@init { if ($header_service_route::current == NULL) {
$header_service_route::first = $header_service_route::current = belle_sip_header_service_route_new();
$srv_route::prev=NULL;
} else {
belle_sip_header_t* header = BELLE_SIP_HEADER($header_service_route::current);
$srv_route::prev=$header_service_route::current;
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_service_route::current = belle_sip_header_service_route_new()));
}
}
: name_addr[BELLE_SIP_HEADER_ADDRESS($header_service_route::current)] ( semi sr_param )*;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
if ( $srv_route::prev == NULL) {
$header_service_route::first==NULL;
} else {
belle_sip_header_set_next(BELLE_SIP_HEADER($srv_route::prev),NULL);
}
belle_sip_object_unref($header_service_route::current);
$header_service_route::current=$srv_route::prev;
}
sr_param
: generic_param[BELLE_SIP_PARAMETERS($header_service_route::current)];
record_route_token: {IS_TOKEN(Record-Route)}? token;
header_record_route returns [belle_sip_header_record_route_t* ret]
scope { belle_sip_header_record_route_t* current; belle_sip_header_record_route_t* first;}
......@@ -926,7 +968,7 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
$ret=NULL;
}
to_spec
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_to::current)] | addr_spec[BELLE_SIP_HEADER_ADDRESS($header_to::current)] )
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_to::current)] | paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_to::current)] )
( semi to_param )*;
to_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_to::current)];
......@@ -1095,6 +1137,8 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_allow_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcasecmp(BELLE_SIP_SUBSCRIPTION_STATE,(const char*)$header_name.text->chars) == 0) {
$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 {
$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);
......@@ -1111,10 +1155,24 @@ message_body
options { greedy = false; }
: OCTET+;
paramless_uri returns [belle_sip_uri_t* ret]
scope { belle_sip_uri_t* current; }
@init { $paramless_uri::current = belle_sip_uri_new(); }
: sip_schema[$paramless_uri::current] ((userinfo[$paramless_uri::current] hostport[$paramless_uri::current]) | hostport[$paramless_uri::current] )
headers[$paramless_uri::current]? {$ret = $paramless_uri::current;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($paramless_uri::current);
$ret=NULL;
}
uri returns [belle_sip_uri_t* ret]
scope { belle_sip_uri_t* current; }
@init { $uri::current = belle_sip_uri_new(); }
: sip_schema ((userinfo hostport) | hostport ) uri_parameters? headers? {$ret = $uri::current;};
: sip_schema[$uri::current] ((userinfo[$uri::current] hostport[$uri::current]) | hostport[$uri::current] )
uri_parameters[$uri::current]?
headers[$uri::current]? {$ret = $uri::current;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
......@@ -1125,13 +1183,19 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
sip_token: {IS_TOKEN(sip)}? token;
sips_token: {IS_TOKEN(sips)}? token;
sip_schema : (sips_token {belle_sip_uri_set_secure($uri::current,1);}
sip_schema[belle_sip_uri_t* uri] : (sips_token {belle_sip_uri_set_secure(uri,1);}
| sip_token) COLON ;
userinfo : user ( COLON password )? '@' ;
user : ( unreserved | escaped | user_unreserved )+ {belle_sip_uri_set_user($uri::current,(const char *)$text->chars);};
userinfo[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$userinfo::current=uri;}
: user ( COLON password )? '@' ;
user : ( unreserved | escaped | user_unreserved )+ {belle_sip_uri_set_user($userinfo::current,(const char *)$text->chars);};
user_unreserved : '&' | EQUAL | '+' | '$' | COMMA | SEMI | '?' | SLASH;
password : ( unreserved |'&' | EQUAL | '+' | '$' | COMMA )*;
hostport : host ( COLON port {belle_sip_uri_set_port($uri::current,$port.ret);})? {belle_sip_uri_set_host($uri::current,(const char *)$host.text->chars);};
hostport[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$hostport::current=uri;}
: host ( COLON port {belle_sip_uri_set_port($hostport::current,$port.ret);})? {belle_sip_uri_set_host($hostport::current,(const char *)$host.text->chars);};
host : (hostname | ipv4address | ipv6reference) ;
hostname : ( domainlabel '.' )* toplabel '.'? ;
......@@ -1148,17 +1212,19 @@ hex4 : hexdigit hexdigit hexdigit hexdigit ;
port returns [int ret]: DIGIT+ { $ret=atoi((const char *)$text->chars); };
uri_parameters
uri_parameters[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$uri_parameters::current=uri;}
: ( semi uri_parameter )+;
uri_parameter //all parameters are considered as other
: other_param ;
other_param
: pname { belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS($uri::current)
: pname { belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS($uri_parameters::current)
,(const char *)$pname.text->chars
,NULL);}
|
(pname EQUAL pvalue) {
belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS($uri::current)
belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS($uri_parameters::current)
,(const char *)$pname.text->chars
,(const char *)$pvalue.text->chars);}
;
......@@ -1172,8 +1238,11 @@ paramchar
param_unreserved
: '[' | ']' | SLASH | COLON | '&' | PLUS | '$' | '.';
headers : '?' header ( '&' header )* ;
header : hname EQUAL hvalue? {belle_sip_uri_set_header($uri::current,(const char *)$hname.text->chars,(const char *)$hvalue.text->chars);};
headers[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$headers::current=uri;}
: '?' header ( '&' header )* ;
header : hname EQUAL hvalue? {belle_sip_uri_set_header($headers::current,(const char *)$hname.text->chars,(const char *)$hvalue.text->chars);};
hname : ( hnv_unreserved | unreserved | escaped )+;
hvalue : ( hnv_unreserved | unreserved | escaped )+;
......
......@@ -112,6 +112,24 @@ void test_simple_header_from(void) {
belle_sip_object_unref(L_from);
}
void test_header_from_with_paramless_address_spec(void) {
belle_sip_header_from_t* L_from = belle_sip_header_from_parse("From: sip:bob@titi.com;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
belle_sip_object_unref(L_from);
}
void test_header_to_with_paramless_address_spec(void) {
belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To: sip:bob@titi.com;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
belle_sip_object_unref(L_to);
}
void test_header_contact_with_paramless_address_spec(void) {
belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: sip:bob@titi.com;expires=60");
CU_ASSERT_EQUAL(belle_sip_header_contact_get_expires(L_contact),60);
belle_sip_object_unref(L_contact);
}
void test_simple_header_to(void) {
belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To : < sip:titi.com;transport=tcp> ; tag = dlfjklcn6545614XX");
......@@ -272,6 +290,18 @@ void test_header_route(void) {
CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
}
void test_header_service_route(void) {
belle_sip_header_service_route_t* L_service_route = belle_sip_header_service_route_parse("Service-Route: <sip:orig@scscf.ims.linphone.com:6060;lr>");
CU_ASSERT_PTR_NOT_NULL_FATAL(L_service_route);
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_service_route));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
L_service_route = belle_sip_header_service_route_parse(l_raw_header);
belle_sip_free(l_raw_header);
belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_service_route));
CU_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 6060);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_service_route));
}
void test_header_content_length(void) {
belle_sip_header_content_length_t* L_tmp;
belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
......@@ -580,5 +610,17 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test_header_subscription_state",test_header_subscription_state )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_header_service_route",test_header_service_route )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_header_from_with_paramless_address_spec",test_header_from_with_paramless_address_spec )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_header_to_with_paramless_address_spec",test_header_to_with_paramless_address_spec )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_header_contact_with_paramless_address_spec",test_header_contact_with_paramless_address_spec )) {
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