Commit bff19b27 authored by jehan's avatar jehan

-Add reason header

-start fast uri implementation
parent 8d447058
......@@ -753,6 +753,23 @@ BELLESIP_EXPORT void belle_sip_header_accept_set_subtype(belle_sip_header_accept
#define BELLE_SIP_HEADER_ACCEPT(t) BELLE_SIP_CAST(t,belle_sip_header_accept_t)
#define BELLE_SIP_ACCEPT "Accept"
/******************************
* Reason header object inherent from parameters
*
******************************/
typedef struct _belle_sip_header_reason belle_sip_header_reason_t;
BELLESIP_EXPORT belle_sip_header_reason_t* belle_sip_header_reason_new(void);
BELLESIP_EXPORT belle_sip_header_reason_t* belle_sip_header_reason_parse (const char* reason) ;
BELLESIP_EXPORT const char* belle_sip_header_reason_get_protocol(const belle_sip_header_reason_t* reason);
BELLESIP_EXPORT void belle_sip_header_reason_set_protocol(belle_sip_header_reason_t* reason,const char* protocol);
BELLESIP_EXPORT int belle_sip_header_reason_get_cause(const belle_sip_header_reason_t* reason);
BELLESIP_EXPORT void belle_sip_header_reason_set_cause(belle_sip_header_reason_t* reason,int cause);
BELLESIP_EXPORT void belle_sip_header_reason_set_text(belle_sip_header_reason_t* reason,const char* text);
BELLESIP_EXPORT const char* belle_sip_header_reason_get_text(const belle_sip_header_reason_t* reason);
#define BELLE_SIP_HEADER_REASON(t) BELLE_SIP_CAST(t,belle_sip_header_reason_t)
#define BELLE_SIP_REASON "Reason"
BELLE_SIP_END_DECLS
......
......@@ -35,6 +35,10 @@ BELLESIP_EXPORT belle_sip_uri_t* belle_sip_uri_new(void);
*
*/
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_uri_parse (const char* uri) ;
/**
* same as belle_sip_uri_parse but with much less checks
*/
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_fast_uri_parse (const char* uri) ;
/**
*
*/
......
......@@ -143,7 +143,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_header_event_t),
BELLE_SIP_TYPE_ID(belle_sip_header_supported_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_disposition_t),
BELLE_SIP_TYPE_ID(belle_sip_header_accept_t)
BELLE_SIP_TYPE_ID(belle_sip_header_accept_t),
BELLE_SIP_TYPE_ID(belle_sip_header_reason_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -83,6 +83,7 @@ static struct header_name_func_pair header_table[] = {
,{PROTO_SIP, "k", (header_parse_func)belle_sip_header_supported_parse}
,{PROTO_SIP, BELLE_SIP_CONTENT_DISPOSITION, (header_parse_func)belle_sip_header_content_disposition_parse}
,{PROTO_SIP, BELLE_SIP_ACCEPT, (header_parse_func)belle_sip_header_accept_parse}
,{PROTO_SIP, BELLE_SIP_REASON, (header_parse_func)belle_sip_header_reason_parse}
};
static belle_sip_header_t* belle_header_create(const char* name,const char* value,int protocol) {
......@@ -2021,4 +2022,61 @@ belle_sip_header_accept_t* belle_sip_header_accept_create (const char* type,cons
GET_SET_STRING(belle_sip_header_accept,type);
GET_SET_STRING(belle_sip_header_accept,subtype);
/******************************
* Reason header object inherent from parameters
*
******************************/
struct _belle_sip_header_reason {
belle_sip_parameters_t params_list;
const char* protocol;
const char* unquoted_text;
};
static void belle_sip_header_reason_destroy(belle_sip_header_reason_t* reason) {
DESTROY_STRING(reason,protocol);
DESTROY_STRING(reason,unquoted_text);
}
static void belle_sip_header_reason_clone(belle_sip_header_reason_t* reason, const belle_sip_header_reason_t* orig){
CLONE_STRING(belle_sip_header_reason,protocol,reason,orig)
}
belle_sip_error_code belle_sip_header_reason_marshal(belle_sip_header_reason_t* reason, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(reason), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s ",reason->protocol);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(reason), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
if (reason->unquoted_text)
error=belle_sip_snprintf(buff,buff_size,offset,"; text=\"%s\"",reason->unquoted_text);
if (error!=BELLE_SIP_OK) return error;
return error;
}
GET_SET_STRING(belle_sip_header_reason,unquoted_text);
void belle_sip_header_reason_set_text(belle_sip_header_reason_t* reason,const char* text) {
belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(reason),"text"); /*just in case*/
belle_sip_header_reason_set_unquoted_text((belle_sip_header_reason_t*)reason, text);
}
BELLESIP_EXPORT const char* belle_sip_header_reason_get_text(const belle_sip_header_reason_t* reason) {
if (!reason->unquoted_text) {
/*try from params*/
const char * quoted = belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(reason), "text");
if (quoted) {
char* unquoted = _belle_sip_str_dup_and_unquote_string(quoted);
belle_sip_header_reason_set_unquoted_text((belle_sip_header_reason_t*)reason, unquoted); /*change internal param, ,even if reason is const*/
belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(reason),"text");
belle_sip_free(unquoted);
}
}
return reason->unquoted_text;
}
GET_SET_STRING_PARAM(belle_sip_header_reason,protocol);
GET_SET_INT_PARAM(belle_sip_header_reason,cause,int);
BELLE_SIP_PARSE(header_reason)
BELLE_SIP_NEW_HEADER(header_reason,parameters,BELLE_SIP_REASON)
......@@ -212,6 +212,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_event_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_supported_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_content_disposition_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_accept_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_reason_t);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......
......@@ -1508,7 +1508,45 @@ accept_sub_media_type {belle_sip_header_accept_set_subtype($header_accept::curre
accept_main_media_type: token;
accept_sub_media_type: token;
//****************************Reason***********************************//
/*
Reason = "Reason" HCOLON reason-value *(COMMA reason-value)
reason-value = protocol *(SEMI reason-params)
protocol = "SIP" / "Q.850" / token
reason-params = protocol-cause / reason-text
/ reason-extension
protocol-cause = "cause" EQUAL cause
cause = 1*DIGIT
reason-text = "text" EQUAL quoted-string
reason-extension = generic-param
*/
header_reason returns [belle_sip_header_reason_t* ret=NULL]
scope { belle_sip_header_reason_t* current;belle_sip_header_reason_t* first; }
@init { $header_reason::current = NULL; $header_reason::first =NULL;}
: {IS_TOKEN(Reason)}? token /*'Reason'*/ hcolon header_reason_param ( comma header_reason_param)* {$ret = $header_reason::first; };
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
$ret = $header_reason::first;
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
header_reason_param
scope { belle_sip_header_reason_t* prev;}
@init { if ($header_reason::current == NULL) {
$header_reason::first = $header_reason::current = belle_sip_header_reason_new();
$header_reason_param::prev=NULL;
} else {
belle_sip_header_t* header = BELLE_SIP_HEADER($header_reason::current);
$header_reason_param::prev=$header_reason::current;
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_reason::current = belle_sip_header_reason_new()));
}
}
:header_reason_protocol {belle_sip_header_reason_set_protocol($header_reason::current,(const char*)$header_reason_protocol.text->chars);}
(semi generic_param [BELLE_SIP_PARAMETERS($header_reason::current)])*;
header_reason_protocol
: token;
//*********************************************//
header returns [belle_sip_header_t* ret=NULL]
: header_extension_base[FALSE] {$ret=$header_extension_base.ret;};
......@@ -1604,6 +1642,12 @@ 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,$host.ret);};
fast_hostport[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$fast_hostport::current=uri;}
: fast_host ( COLON port {belle_sip_uri_set_port($fast_hostport::current,$port.ret);})? {belle_sip_uri_set_host($fast_hostport::current,$fast_host.ret);};
uri_parameters[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
@init {$uri_parameters::current=uri;}
......@@ -1660,9 +1704,19 @@ hvalue : ( hnv_unreserved | unreserved | escaped )+;
hnv_unreserved : LSBRAQUET | RSBRAQUET | SLASH | QMARK | COLON | PLUS | DOLLARD ;
//****************SIP end**********************/
fast_host returns [const char* ret]
scope { const char* current; }
@init {$fast_host::current=$ret=NULL;}
: (fast_hostname {$fast_host::current=(const char *)$fast_hostname.text->chars;}
| ipv4address {$fast_host::current=(const char *)$ipv4address.text->chars;}
| ipv6reference {$fast_host::current=(const char *)$ipv6reference.ret;}) {$ret=$fast_host::current;};
fast_hostname: ( alphanum | DASH )*;
//*************************common tokens*******************************/
user_unreserved : AND | EQUAL | PLUS | DOLLARD | COMMA | SEMI | QMARK | SLASH;
......@@ -1671,14 +1725,16 @@ scope { const char* current; }
@init {$host::current=$ret=NULL;}
: (hostname {$host::current=(const char *)$hostname.text->chars;}
| ipv4address {$host::current=(const char *)$ipv4address.text->chars;}
| ipv6reference ) {$ret=$host::current;};
| ipv6reference {$host::current=(const char *)$ipv6reference.ret;}) {$ret=$host::current;};
hostname : ( domainlabel DOT )* (toplabel)=>toplabel DOT? ;
domainlabel : alphanum | (alphanum ( alphanum | DASH )* alphanum) ;
toplabel : alpha | (alpha ( DASH? alphanum)+) ;
ipv4address : three_digit DOT three_digit DOT three_digit DOT three_digit ;
ipv6reference : LSBRAQUET ipv6address RSBRAQUET {$host::current=(const char *)$ipv6address.text->chars;};
ipv6reference returns [const char* ret]
@init {$ret=NULL;}
: LSBRAQUET ipv6address RSBRAQUET {$ret=(const char *)$ipv6address.text->chars;};
ipv6address : hexpart ( COLON ipv4address )? ;
hexpart : hexseq | hexseq COLON COLON ( hexseq )? | COLON COLON ( hexseq )?;
hexseq : hex4 ( COLON hex4)*;
......
......@@ -41,6 +41,7 @@ set(SOURCE_FILES_C
belle_sip_tester.c
belle_sip_tester.h
belle_sip_uri_tester.c
belle_sip_fast_uri_tester.c
cast_test.c
register_tester.h
)
......
This diff is collapsed.
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"
#include "belle_sip_internal.h"
#define belle_sip_uri_parse belle_sip_fast_uri_parse
/*test body*/
#include "belle_sip_base_uri_tester.c"
#undef belle_sip_uri_parse
extern belle_sip_uri_t* belle_sip_uri_parse (const char* uri);
belle_sip_uri_t* belle_sip_fast_uri_parse (const char* uri) {
return belle_sip_uri_parse(uri);
}
test_suite_t fast_sip_uri_test_suite = {"FAST SIP URI", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
sizeof(uri_tests) / sizeof(uri_tests[0]), uri_tests};
......@@ -1133,7 +1133,33 @@ static void test_accept_header(void) {
BC_ASSERT_PTR_NULL(belle_sip_header_accept_parse("nimportequoi"));
}
static void test_reason_header(void) {
belle_sip_header_reason_t *L_tmp, *l_next;
belle_sip_header_reason_t* L_reason = BELLE_SIP_HEADER_REASON(belle_sip_header_create("Reason", "Q.850 ;cause=16 ;text=\"Busy Everywhere\""));
BC_ASSERT_STRING_EQUAL(belle_sip_header_reason_get_text(L_reason),"Busy Everywhere");
belle_sip_header_reason_set_text(L_reason, "Terminated");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_reason));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_reason));
L_tmp = belle_sip_header_reason_parse(l_raw_header);
L_reason = BELLE_SIP_HEADER_REASON(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
BC_ASSERT_STRING_EQUAL(belle_sip_header_reason_get_text(L_reason),"Terminated");
BC_ASSERT_STRING_EQUAL(belle_sip_header_reason_get_protocol(L_reason),"Q.850");
BC_ASSERT_EQUAL(belle_sip_header_reason_get_cause(L_reason),16 , int,"%d");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_reason));
belle_sip_free(l_raw_header);
L_reason = belle_sip_header_reason_parse("Reason: SIP ;cause=600 ;text=\"Busy Everywhere\", SIP ;cause=580 ;text=\"Precondition Failure\"");
l_next =BELLE_SIP_HEADER_REASON(belle_sip_header_get_next(BELLE_SIP_HEADER(L_reason)));
BC_ASSERT_PTR_NOT_NULL(l_next);
BC_ASSERT_EQUAL(belle_sip_header_reason_get_cause(l_next),580 , int,"%d");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_reason));
BC_ASSERT_PTR_NULL(belle_sip_header_reason_parse("nimportequoi"));
}
test_t headers_tests[] = {
TEST_NO_TAG("Address", test_address_header),
TEST_NO_TAG("Address tel uri", test_address_header_with_tel_uri),
......@@ -1175,7 +1201,8 @@ test_t headers_tests[] = {
TEST_NO_TAG("Header event", test_event_header),
TEST_NO_TAG("Header Supported", test_supported_header),
TEST_NO_TAG("Header Content-Disposition", test_content_disposition_header),
TEST_NO_TAG("Header Accept", test_accept_header)
TEST_NO_TAG("Header Accept", test_accept_header),
TEST_NO_TAG("Header Reason", test_reason_header)
};
test_suite_t headers_test_suite = {"Headers", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
......
......@@ -94,6 +94,7 @@ void belle_sip_tester_init(void(*ftester_printf)(int level, const char *fmt, va_
ipv6_available=_belle_sip_tester_ipv6_available();
bc_tester_add_suite(&cast_test_suite);
bc_tester_add_suite(&sip_uri_test_suite);
bc_tester_add_suite(&fast_sip_uri_test_suite);
bc_tester_add_suite(&generic_uri_test_suite);
bc_tester_add_suite(&headers_test_suite);
bc_tester_add_suite(&core_test_suite);
......
......@@ -32,6 +32,7 @@ extern "C" {
extern test_suite_t cast_test_suite;
extern test_suite_t generic_uri_test_suite;
extern test_suite_t sip_uri_test_suite;
extern test_suite_t fast_sip_uri_test_suite;
extern test_suite_t headers_test_suite;
extern test_suite_t core_test_suite;
extern test_suite_t sdp_test_suite;
......
This diff is collapsed.
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