Commit f148f4e1 authored by jehan's avatar jehan

start fast uri implem

parent 00cd6d6f
......@@ -35,6 +35,12 @@ BELLESIP_EXPORT belle_sip_uri_t* belle_sip_uri_new(void);
*
*/
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_uri_parse (const char* uri) ;
/**
*
*/
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_fast_uri_parse (const char* uri) ;
/**
* same as belle_sip_uri_parse but with much less checks
*/
......
......@@ -501,3 +501,6 @@ int belle_sip_uri_check_components_from_context(const belle_sip_uri_t* uri,const
}
/*fast uri implemenation*/
typedef belle_sip_uri_t belle_sip_fast_uri_t;
BELLE_SIP_PARSE(fast_uri);
......@@ -668,24 +668,43 @@ header_address returns [belle_sip_header_address_t* ret]
header_address_base[belle_sip_header_address_t* obj] returns [belle_sip_header_address_t* ret]
@init { $ret=obj; }
: ( name_addr_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]
| addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]) { if (!belle_sip_header_address_get_uri($ret)
&&
!belle_sip_header_address_get_absolute_uri(($ret))) {
belle_sip_object_unref($ret);
$ret=NULL;
}
};
| addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]) { if (!belle_sip_header_address_get_uri($ret) && !belle_sip_header_address_get_absolute_uri(($ret))) {
belle_sip_object_unref($ret);
$ret=NULL;
}
};
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_object_unref($ret);
$ret=NULL;
}
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
fast_header_address returns [belle_sip_header_address_t* ret]
@init { $ret=belle_sip_header_address_new(); }
: ( fast_name_addr_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]
| fast_addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]) { if (!belle_sip_header_address_get_uri($ret) && !belle_sip_header_address_get_absolute_uri(($ret))) {
belle_sip_object_unref($ret);
$ret=NULL;
}
};
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
name_addr[belle_sip_header_address_t* object]
: (lws? display_name[object])? sp_laquot addr_spec[object] raquot_sp;
name_addr_with_generic_uri[belle_sip_header_address_t* object]
: (lws? display_name[object])? sp_laquot addr_spec_with_generic_uri[object] raquot_sp;
fast_name_addr_with_generic_uri[belle_sip_header_address_t* object]
: (lws? display_name[object])? sp_laquot fast_addr_spec_with_generic_uri[object] raquot_sp;
addr_spec[belle_sip_header_address_t* object]
: lws? uri {belle_sip_header_address_set_uri(object,$uri.ret);} lws?;//| absoluteURI;
......@@ -702,6 +721,18 @@ addr_spec_with_generic_uri[belle_sip_header_address_t* object]
}}
) lws?;
fast_addr_spec_with_generic_uri[belle_sip_header_address_t* object]
: lws? ( fast_uri {belle_sip_header_address_set_uri(object,$fast_uri.ret);}
|
generic_uri { if ( strcasecmp(belle_generic_uri_get_scheme($generic_uri.ret),"sip") != 0
&& strcasecmp(belle_generic_uri_get_scheme($generic_uri.ret),"sips") != 0 ) {
belle_sip_header_address_set_absolute_uri(object,$generic_uri.ret);
} else {
belle_sip_message("Cannot parse a sip/sips uri as a generic uri");
belle_sip_object_unref($generic_uri.ret);
}}
) lws?;
paramless_addr_spec[belle_sip_header_address_t* object]
: lws? paramless_uri {belle_sip_header_address_set_uri(object,$paramless_uri.ret);} lws? ;//| absoluteURI;
......@@ -1671,6 +1702,20 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
$ret=NULL;
}
fast_uri returns [belle_sip_uri_t* ret=NULL]
scope { belle_sip_uri_t* current; }
@init { $fast_uri::current = belle_sip_uri_new(); }
: sip_schema[$fast_uri::current] ( ((userinfo[NULL])=>userinfo[$fast_uri::current] fast_hostport[$fast_uri::current]) | fast_hostport[$fast_uri::current] )
uri_parameters[$fast_uri::current]?
headers[$fast_uri::current]? {$ret = $fast_uri::current;};
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($fast_uri::current);
$ret=NULL;
}
sip_token: {IS_TOKEN(sip)}? token;
sips_token: {IS_TOKEN(sips)}? token;
......@@ -1773,7 +1818,7 @@ scope { const char* current; }
| 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 )*;
fast_hostname: alpha ( alphanum | DASH | DOT )*;
//*************************common tokens*******************************/
......@@ -1783,16 +1828,14 @@ 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 {$host::current=(const char *)$ipv6reference.ret;}) {$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 returns [const char* ret]
@init {$ret=NULL;}
: LSBRAQUET ipv6address RSBRAQUET {$ret=(const char *)$ipv6address.text->chars;};
ipv6reference returns [const char* 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)*;
......
......@@ -19,10 +19,12 @@
#define belle_sip_parserutils_h
#include "port.h"
static inline int belle_sip_strcasecmp(const char*a,const char* b) {
if (!a || !b) return 0;
return strcasecmp(a,b) == 0;
}
#define IS_TOKEN(token) \
(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
strcasecmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
belle_sip_strcasecmp(#token,(const char*)INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)
#define IS_HEADER_NAMED(name,compressed_name) (IS_TOKEN(compressed_name) || IS_TOKEN(name))
......
......@@ -16,6 +16,9 @@
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"
static void testSIMPLEURI(void) {
......@@ -475,6 +478,7 @@ static void test_empty_password(void){
if (headerAddr) belle_sip_object_unref(headerAddr);
}
static test_t uri_tests[] = {
TEST_NO_TAG("Simple URI", testSIMPLEURI),
TEST_NO_TAG("Complex URI", testCOMPLEXURI),
......
......@@ -27,10 +27,33 @@
#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);
static void perf(void) {
uint64_t t1, t2, start=bctbx_get_cur_time_ms();
int i=0;
for (i=0;i<1000;i++) {
belle_sip_uri_t * uri = belle_sip_uri_parse("sip:+331231231231@sip.exmaple.org;user=phone");
belle_sip_object_unref(uri);
}
t1 = bctbx_get_cur_time_ms() - start;
start=bctbx_get_cur_time_ms();
belle_sip_message("t1 = %llu",t1);
for (i=0;i<1000;i++) {
belle_sip_uri_t * uri = belle_sip_fast_uri_parse("sip:+331231231231@sip.exmaple.org;user=phone");
belle_sip_object_unref(uri);
}
t2 = bctbx_get_cur_time_ms() - start;
belle_sip_message("t1 = %llu",t2);
BC_ASSERT_GREATER(((float)(t1-t2))/(float)(t1), 0.5, float, "%f");
}
static test_t tests[] ={TEST_NO_TAG("perf", perf)};
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};
test_suite_t perf_sip_uri_test_suite = {"FAST SIP URI 2", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
sizeof(tests) / sizeof(tests[0]), tests};
......@@ -95,6 +95,7 @@ void belle_sip_tester_init(void(*ftester_printf)(int level, const char *fmt, va_
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(&perf_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);
......@@ -207,7 +208,8 @@ int main (int argc, char *argv[]) {
if (env_domain) {
test_domain=env_domain;
}
bctbx_init_logger();
for(i=1;i<argc;++i){
if (strcmp(argv[i],"--verbose")==0){
belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG);
......@@ -243,6 +245,7 @@ int main (int argc, char *argv[]) {
ret = bc_tester_start(argv[0]);
belle_sip_tester_uninit();
bctbx_uninit_logger();
return ret;
}
......
......@@ -33,6 +33,7 @@ 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 perf_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;
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
Copyright (C) 2017 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
......@@ -25,5 +24,9 @@
/*test body*/
#include "belle_sip_base_uri_tester.c"
test_suite_t sip_uri_test_suite = {"SIP URI", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
sizeof(uri_tests) / sizeof(uri_tests[0]), uri_tests};
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