Commit 7a65fccc authored by jehan's avatar jehan

rework antlr grammars to simplify grammars's code structurs

parent c04f17a3
......@@ -29,17 +29,11 @@ belle-sip.anjuta
.kdev4/
belle-sip.kdev4
config.h
*Lexer.h
*Lexer.c
*Parser.h
*Parser.c
*.tokens
src/specs.c
belle-sip.pc
belle-sip.spec
html/
*.orig
src/generated_src_stamp
tester/belle_sip_object_describe
tester/belle_sip_parse
tester/belle_sip_tester
......
......@@ -272,6 +272,7 @@ Makefile
include/Makefile
include/belle-sip/Makefile
src/Makefile
src/grammars/Makefile
tester/Makefile
belle-sip.pc
belle-sip.spec
......
SUBDIRS=grammars
generated_src= \
belle_sip_messageParser.c belle_sip_messageParser.h \
belle_sip_messageLexer.c belle_sip_messageLexer.h \
belle_sdpParser.c belle_sdpParser.h \
belle_sdpLexer.c belle_sdpLexer.h \
belle_http_messageParser.c belle_http_messageParser.h \
belle_http_messageLexer.c belle_http_messageLexer.h
noinst_LTLIBRARIES=libbellesip_tls.la
.NOTPARALLEL $(builddir)/belle_sip_messageLexer.c \
$(builddir)/belle_sip_messageParser.c\
$(builddir)/belle_sip_messageLexer.h \
$(builddir)/belle_sip_messageParser.h : $(srcdir)/belle_sip_message.g
$(ANTLR) -make -fo $(builddir) $<
.NOTPARALLEL $(builddir)/belle_sdpLexer.c \
$(builddir)/belle_sdpParser.c \
$(builddir)/belle_sdpLexer.h \
$(builddir)/belle_sdpParser.h : $(srcdir)/belle_sdp.g
$(ANTLR) -make -fo $(builddir) $<
.NOTPARALLEL $(builddir)/belle_http_messageLexer.c \
$(builddir)/belle_http_messageParser.c \
$(builddir)/belle_http_messageLexer.h \
$(builddir)/belle_http_messageParser.h: $(srcdir)/belle_http_message.g
$(ANTLR) -make -fo $(builddir) $<
BUILT_SOURCES=$(generated_src)
noinst_LTLIBRARIES=libbellesip_generated.la libbellesip_tls.la
nodist_libbellesip_generated_la_SOURCES=$(generated_src)
libbellesip_generated_la_CFLAGS=$(LESS_STRICT_OPTIONS) $(ANTLR_CFLAGS)
#to disbale warning introduced by compatibility between polar 1.2 and 1.3
#to disable warning introduced by compatibility between polar 1.2 and 1.3
libbellesip_tls_la_SOURCES= transports/tls_listeningpoint_polarssl.c transports/tls_channel_polarssl.c
libbellesip_tls_la_CFLAGS=$(LESS_STRICT_OPTIONS) $(TLS_CFLAGS) $(LIBBELLESIP_CFLAGS)
......@@ -82,7 +50,7 @@ libbellesip_la_SOURCES= \
http-message.c
if BUILD_TUNNEL
libbellesip_la_SOURCES+= transports/tunnel_listeningpoint.c \
libbellesip_la_SOURCES+= transports/tunnel_listeningpoint.c \
transports/tunnel_channel.c \
transports/tunnel_wrapper.cc
endif
......@@ -91,16 +59,12 @@ endif
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS) $(TLS_CFLAGS) $(TUNNEL_CFLAGS) $(LIBBELLESIP_CFLAGS)
libbellesip_la_CXXFLAGS=$(STRICT_OPTIONS) $(TLS_CFLAGS) $(TUNNEL_CFLAGS) $(LIBBELLESIP_CFLAGS)
libbellesip_la_LIBADD=libbellesip_generated.la libbellesip_tls.la $(ANTLR_LIBS) $(TLS_LIBS) $(TUNNEL_LIBS)
libbellesip_la_LIBADD=grammars/libbellesip_generated.la libbellesip_tls.la $(ANTLR_LIBS) $(TLS_LIBS) $(TUNNEL_LIBS)
libbellesip_la_LDFLAGS=-no-undefined $(LDFLAGS)
AM_CPPFLAGS=-I$(top_srcdir)/include
EXTRA_DIST=$(grammar_files)
CLEANFILES=$(generated_src) *.tokens generated_src_stamp
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(builddir)/grammars
discovery:
touch specs.c
......
......@@ -24,7 +24,7 @@
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_lexer.h"
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
......@@ -932,12 +932,12 @@ belle_sip_header_extension_t* belle_sip_header_extension_create (const char* nam
*/
belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* value) {
pANTLR3_INPUT_STREAM input;
pbelle_sip_messageLexer lex;
pbelle_sip_lexer lex;
pANTLR3_COMMON_TOKEN_STREAM tokens;
pbelle_sip_messageParser parser;
belle_sip_messageParser_header_extension_return l_parsed_object;
belle_sip_message_sip_header_extension_return l_parsed_object;
input = ANTLR_STREAM_NEW("header_extension",value,strlen(value));
lex = belle_sip_messageLexerNew (input);
lex = belle_sip_lexerNew (input);
tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens);
l_parsed_object = parser->header_extension(parser,FALSE);
......
......@@ -381,14 +381,14 @@ antlr3NewAsciiStringCopyStream((pANTLR3_UINT8)value,(ANTLR3_UINT32)length,NULL)
#define BELLE_PARSE(parser_name, object_type_prefix, object_type) \
object_type_prefix##object_type##_t* object_type_prefix##object_type##_parse (const char* value) { \
pANTLR3_INPUT_STREAM input; \
p##parser_name##Lexer lex; \
pbelle_sip_lexer lex; \
pANTLR3_COMMON_TOKEN_STREAM tokens; \
p##parser_name##Parser parser; \
p##parser_name parser; \
object_type_prefix##object_type##_t* l_parsed_object; \
input = ANTLR_STREAM_NEW(object_type,value,strlen(value));\
lex = parser_name##LexerNew (input);\
lex = belle_sip_lexerNew (input);\
tokens = antlr3CommonTokenStreamSourceNew (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
parser = parser_name##ParserNew (tokens);\
parser = parser_name##New (tokens);\
l_parsed_object = parser->object_type(parser);\
parser ->free(parser);\
tokens ->free(tokens);\
......@@ -397,7 +397,7 @@ antlr3NewAsciiStringCopyStream((pANTLR3_UINT8)value,(ANTLR3_UINT32)length,NULL)
if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
return l_parsed_object;\
}
#define BELLE_SIP_PARSE(object_type) BELLE_PARSE(belle_sip_message,belle_sip_,object_type)
#define BELLE_SIP_PARSE(object_type) BELLE_PARSE(belle_sip_messageParser,belle_sip_,object_type)
#define BELLE_NEW(object_type,super_type) \
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(object_type##_t); \
......
......@@ -22,7 +22,7 @@
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_lexer.h"
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
......
......@@ -15,8 +15,8 @@
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_http_messageLexer.h"
#include "belle_http_messageParser.h"
#include "belle_sip_lexer.h"
#include "belle_sip_message_http.h"
#include "belle-sip/generic-uri.h"
#include "belle-sip/parameters.h"
......@@ -129,7 +129,7 @@ GET_SET_STRING(belle_generic_uri,path);
GET_SET_STRING(belle_generic_uri,query);
GET_SET_INT(belle_generic_uri,port,int)
BELLE_NEW(belle_generic_uri,belle_sip_object)
BELLE_PARSE(belle_http_message,belle_generic_,uri)
BELLE_PARSE(belle_sip_messageParser,belle_,generic_uri)
char* belle_generic_uri_to_string(belle_generic_uri_t* uri) {
......
noinst_LTLIBRARIES=libbellesip_generated.la
libbellesip_generated_la_CFLAGS=$(ANTLR_CFLAGS)
nodist_libbellesip_generated_la_SOURCES= \
belle_sip_messageParser.c belle_sip_messageParser.h \
belle_sip_lexer.c belle_sip_lexer.h \
belle_sdpParser.c belle_sdpParser.h \
belle_sdpLexer.c belle_sdpLexer.h \
belle_sip_message_http.c belle_sip_message_http.h \
belle_sip_message_sip.c belle_sip_message_sip.h \
belle_sip_message_common.c belle_sip_message_common.h
.NOTPARALLEL $(builddir)/belle_sip_lexer.c \
$(builddir)/ belle_sip_lexer.h : $(srcdir)/belle_sip_lexer.g
$(ANTLR) -make -fo $(builddir) $<
.NOTPARALLEL $(builddir)/belle_sip_messageParser.c $(builddir)/belle_sip_messageParser.h \
$(builddir)/belle_sip_message_http.c $(builddir)/belle_sip_message_http.h \
$(builddir)/belle_sip_message_sip.c $(builddir)/belle_sip_message_sip.h \
$(builddir)/belle_sip_message_common.c $(builddir)/belle_sip_message_common.h : belle_sip_message.g sip.g http.g common.g
$(ANTLR) -make -fo $(builddir) $(srcdir)/belle_sip_message.g
.NOTPARALLEL $(builddir)/belle_sdpLexer.c \
$(builddir)/belle_sdpParser.c \
$(builddir)/belle_sdpLexer.h \
$(builddir)/belle_sdpParser.h : $(srcdir)/belle_sdp.g
$(ANTLR) -make -fo $(builddir) $<
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src
EXTRA_DIST= belle_sip_lexer.g belle_sdp.g belle_sip_message.g sip.g http.g common.g
CLEANFILES=$(nodist_libbellesip_generated_la_SOURCES) *.tokens
......@@ -44,6 +44,7 @@ options {
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused"
#pragma GCC diagnostic ignored "-Wtautological-compare"
}
@parser::header {
......
/*
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 3 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/>.
*/
lexer grammar belle_sip_lexer;
options {
language = C;
}
@lexer::header {
/*
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 3 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/>.
*/
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused"
}
@lexer::includes {
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
}
COMMON_CHAR
: 'g'..'z' | 'G'..'Z' ;
HEX_CHAR: 'a'..'f' |'A'..'F';
DIGIT : '0'..'9' ;
AT: '@';
AND: '&';
DOLLARD: '$';
QMARK: '?';
EMARK: '!';
DASH: '-';
CRLF : '\r\n' { USER1 = (int)((char*)ctx->pLexer->input->currentLine - (char*)ctx->pLexer->input->data); /*GETCHARINDEX()*/;};
HTAB : ' ';
OR : '|';
PERCENT: '%';
DQUOTE : '"';
SQUOTE : '\'';
BQUOTE: '`';
BSLASH: '\\';
LBRACE: '{';
RBRACE: '}';
USCORE: '_';
TILDE: '~';
DOT: '.';
LWS : (SP* CRLF)? SP+ ; //linear whitespace
PLUS: '+';
COLON
: ':'
;
SEMI
: ';'
;
COMMA
: ','
;
LAQUOT
: '<'
;
RAQUOT
: '>'
;
RPAREN
: ')'
;
LPAREN
: '('
;
RSBRAQUET
: ']'
;
LSBRAQUET
: '['
;
EQUAL
: '='
;
SLASH
: '/'
;
STAR
: '*'
;
fragment
SP
: ' '
;
OCTET : . ;
/*
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 3 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/>.
*/
grammar belle_sip_message;
options {
language = C;
}
import belle_sip_lexer, common, sip, http ;
@includes {
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
}
@rulecatch
{
if (HASEXCEPTION())
{
// This is ugly. We set the exception type to ANTLR3_RECOGNITION_EXCEPTION so we can always
// catch them.
//PREPORTERROR();
EXCEPTION->type = ANTLR3_RECOGNITION_EXCEPTION;
}
}
message returns [belle_sip_message_t* ret]
scope { size_t message_length; }
@init {$ret=NULL;}
: message_raw[&($message::message_length)] {$ret=$message_raw.ret;};
message_raw [size_t* length] returns [belle_sip_message_t* ret]
scope { size_t* message_length; }
@init {$message_raw::message_length=length;$ret=NULL;}
: request {$ret = BELLE_SIP_MESSAGE($request.ret);}
| response {$ret = BELLE_SIP_MESSAGE($response.ret);} ;
request returns [belle_sip_request_t* ret]
scope { belle_sip_request_t* current; }
@init {$request::current = belle_sip_request_new(); $ret=$request::current; }
: request_line message_header[BELLE_SIP_MESSAGE($request::current)]+ last_crlf=CRLF {*($message_raw::message_length)=$last_crlf->user1;} /*message_body ?*/ ;
request_line
: method {belle_sip_request_set_method($request::current,(const char*)($method.text->chars));}
(SP)=>LWS
uri {belle_sip_request_set_uri($request::current,$uri.ret);}
LWS
sip_version
CRLF ;
sip_version
: word;// 'SIP/' DIGIT '.' DIGIT;
message_header [belle_sip_message_t* message]
: (/*accept
// | accept_encoding
// | accept_language
// | alert_info
// | allow
// | authentication_info
// | authorization
// | header_call_id {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_call_id.ret));}/*
// | call_info
// | header_contact {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_contact.ret));}
// | content_disposition
// | content_encoding
// | content_language*/
// | header_content_length {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_content_length.ret));}
// | header_content_type {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_content_type.ret));}
// | header_cseq {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_cseq.ret));}/*
// | date
// | error_info
// | expires*/
// | header_from {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_from.ret));}/*
// | in_reply_to
// | max_forwards
// | mime_version
// | min_expires
// | organization
// | priority
// | proxy_authenticate
// | proxy_authorization
// | proxy_require*/
// | header_record_route {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_record_route.ret));}/*
// | reply_to
// | require
// | retry_after*/
// | header_route {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_route.ret));}/*
// | server
// | subject
// | supported
// | timestamp*/
// | header_to {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_to.ret));}/*
// | unsupported
// | user_agent*/
// | header_via {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_via.ret));}/*
// | warning
// | www_authenticate*/
header_extension[TRUE] {
belle_sip_header_t* lheader = BELLE_SIP_HEADER($header_extension.ret);
do {
if (lheader == NULL) break; /*sanity check*/
belle_sip_message_add_header(message,lheader);
}
while((lheader=belle_sip_header_get_next(lheader)) != NULL); }
) CRLF
;
/*
invitem
: 'INVITE' ; //INVITE in caps
ackm : 'ACK'; //ACK in caps
optionsm: 'OPTION'; //OPTIONS in caps
byem : 'BYE' ; //BYE in caps
cancelm : 'CANCEL' ; //CANCEL in caps
registerm
: 'REGISTER' ; //REGISTER in caps
optionm : 'OPTION';
*/
method : /* invitem | ackm | optionm | byem | cancelm | registerm |*/extension_method ;
extension_method
: token;
response returns [belle_sip_response_t* ret]
scope { belle_sip_response_t* current; }
@init {$response::current = belle_sip_response_new(); $ret=$response::current; }
: status_line (message_header[BELLE_SIP_MESSAGE($response::current)]+ last_crlf=CRLF {*($message_raw::message_length)=$last_crlf->user1;} /*message_body*/)? ;
status_line
: sip_version
LWS status_code {belle_sip_response_set_status_code($response::current,atoi((char*)$status_code.text->chars));}
LWS reason_phrase {belle_sip_response_set_reason_phrase($response::current,(char*)$reason_phrase.text->chars);}
CRLF ;
status_code
: extension_code;
extension_code
: DIGIT DIGIT DIGIT;
reason_phrase
: ~(CRLF)*;
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2013 Belledonne Communications SARL, Grenoble, France
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 3 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/>.
*/
parser grammar common;
options {
language = C;
}
@parser::header {
/*
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 3 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/>.
*/
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused"
}
@parser::includes {
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
}
@rulecatch
{
if (HASEXCEPTION())
{
// This is ugly. We set the exception type to ANTLR3_RECOGNITION_EXCEPTION so we can always
// catch them.
//PREPORTERROR();
EXCEPTION->type = ANTLR3_RECOGNITION_EXCEPTION;
}
}
user_unreserved : AND | EQUAL | PLUS | DOLLARD | COMMA | SEMI | QMARK | SLASH;
host returns [const char* ret]
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;};
hostname : ( domainlabel DOT )* 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;};
ipv6address : hexpart ( COLON ipv4address )? ;
hexpart : hexseq | hexseq COLON COLON ( hexseq )? | COLON COLON ( hexseq )?;
hexseq : hex4 ( COLON hex4)*;
hex4 : hexdigit+;/* hexdigit hexdigit hexdigit ;*/
port returns [int ret]: DIGIT+ { $ret=atoi((const char *)$text->chars); };
escaped : PERCENT hexdigit hexdigit;
ttl : three_digit;
three_digit: (DIGIT) => DIGIT
|
(DIGIT DIGIT) => (DIGIT DIGIT)
|
(DIGIT DIGIT DIGIT) =>(DIGIT DIGIT DIGIT) ;
token
: (alphanum | mark | PERCENT | PLUS | BQUOTE )+;
reserved
: SEMI | SLASH | QMARK | COLON | AT | AND | EQUAL | PLUS
| DOLLARD | COMMA;
unreserved : alphanum |mark;
alphanum : alpha | DIGIT ;
hexdigit
: HEX_CHAR|DIGIT;
alpha : HEX_CHAR | COMMON_CHAR;
word
: (alphanum | mark | PERCENT
| PLUS | BQUOTE |
LAQUOT | RAQUOT |
COLON | BSLASH | DQUOTE | SLASH | LSBRAQUET | RSBRAQUET | QMARK | LBRACE | RBRACE )+;
mark : DASH | USCORE | DOT | EMARK | TILDE | STAR | SQUOTE | LPAREN | RPAREN ;
hcolon : ( LWS | HTAB )* COLON LWS? //SWS;
;//|( SP | HTAB )* COLON LWS+;
ldquot : LWS? DQUOTE ;
rdquot : DQUOTE LWS?;
semi: LWS? SEMI LWS?;
comma : LWS? COMMA LWS?;
sp_laquot_sp
: LWS? LAQUOT LWS?;
sp_raquot_sp
: LWS? RAQUOT LWS?;
equal:
LWS? EQUAL LWS?;
slash : LWS? SLASH LWS?;
\ No newline at end of file
......@@ -15,36 +15,14 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
grammar belle_http_message;
parser grammar http;
options {
language = C;
}
@lexer::header {
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2013 Belledonne Communications SARL, Grenoble, France
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 3 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/>.
*/
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused"
}
@parser::header {
/*
belle-sip - SIP (RFC3261) library.
......@@ -68,7 +46,7 @@ options {
#pragma GCC diagnostic ignored "-Wunused"
}
@includes {
@parser::includes {
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
......@@ -93,16 +71,16 @@ options {
abs_path = "/" path_segments
*/
scheme: alpha ( alpha | DIGIT | '+' | '-' | '.' )*;
scheme: alpha ( alpha | DIGIT | PLUS | DASH | DOT )*;
uri returns [belle_generic_uri_t* ret=NULL]
generic_uri returns [belle_generic_uri_t* ret=NULL]
scope { belle_generic_uri_t* current; }
@init { $uri::current = $ret = belle_generic_uri_new(); }
: scheme {belle_generic_uri_set_scheme($uri::current,(const char*)$scheme.text->chars);} COLON hier_part[$uri::current] ;
@init { $generic_uri::current = $ret = belle_generic_uri_new(); }
: scheme {belle_generic_uri_set_scheme($generic_uri::current,(const char*)$scheme.text->chars);} COLON hier_part[$generic_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($uri::current);
belle_sip_object_unref($generic_uri::current);
$ret=NULL;
}
......@@ -112,7 +90,7 @@ hier_part[belle_generic_uri_t* uri] returns [belle_generic_uri_t* ret=NULL]
(SLASH SLASH)=>( SLASH SLASH authority[uri] (SLASH path_segments[uri])?)
|
(SLASH)=>SLASH path_segments[uri] )
('?' query
(QMARK query
{
char* unescaped_query;
unescaped_query=belle_sip_to_unescaped_string((const char *)$query.text->chars);
......@@ -130,175 +108,35 @@ path_segments[belle_generic_uri_t* uri]
};
segment: pchar* ( SEMI param )*;
param: pchar*;
pchar: unreserved | escaped | COLON | '@' | '&' | EQUAL | '+' | '$' | COMMA;
pchar: unreserved | escaped | COLON | AT | AND | EQUAL | PLUS | DOLLARD | COMMA;
query: uric+;
uric: reserved | unreserved | escaped;
authority[belle_generic_uri_t* uri]
: (
(userinfo[NULL])=>(userinfo[uri] hostport[uri])
| hostport[uri] );
(authority_userinfo[NULL])=>(authority_userinfo[uri] authority_hostport[uri])
| authority_hostport[uri] );
userinfo[belle_generic_uri_t* uri]
authority_userinfo[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
@init {$userinfo::current=uri;}
: user ( COLON password )? '@' ;
user : ( unreserved | escaped | user_unreserved )+ {
@init {$authority_userinfo::current=uri;}
: authority_user ( COLON authority_password )? AT ;
authority_user : ( unreserved | escaped | user_unreserved )+ {
char* unescaped_username;
unescaped_username=belle_sip_to_unescaped_string((const char *)$text->chars);
belle_generic_uri_set_user($userinfo::current,unescaped_username);
belle_generic_uri_set_user($authority_userinfo::current,unescaped_username);
belle_sip_free(unescaped_username);
};
user_unreserved : '&' | EQUAL | '+' | '$' | COMMA | SEMI | '?' | SLASH;
password : ( unreserved | escaped |'&' | EQUAL | '+' | '$' | COMMA )* {
authority_password : ( unreserved | escaped | AND | EQUAL | PLUS | DOLLARD | COMMA )* {
char* unescaped_userpasswd;
unescaped_userpasswd=belle_sip_to_unescaped_string((const char *)$text->chars);
belle_generic_uri_set_user_password($userinfo::current,unescaped_userpasswd);