Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
belle-sip
Commits
c04f17a3
Commit
c04f17a3
authored
Dec 13, 2013
by
jehan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add generic uri parser as defined in rfc2396
parent
644c537c
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
912 additions
and
79 deletions
+912
-79
include/belle-sip/Makefile.am
include/belle-sip/Makefile.am
+3
-2
include/belle-sip/belle-sip.h
include/belle-sip/belle-sip.h
+4
-2
include/belle-sip/generic-uri.h
include/belle-sip/generic-uri.h
+150
-0
include/belle-sip/headers.h
include/belle-sip/headers.h
+1
-1
include/belle-sip/sip-uri.h
include/belle-sip/sip-uri.h
+16
-5
src/Makefile.am
src/Makefile.am
+23
-9
src/belle_http_message.g
src/belle_http_message.g
+304
-0
src/belle_sdp.g
src/belle_sdp.g
+27
-1
src/belle_sip_internal.h
src/belle_sip_internal.h
+26
-19
src/belle_sip_message.g
src/belle_sip_message.g
+51
-26
src/belle_sip_uri_impl.c
src/belle_sip_uri_impl.c
+1
-1
src/belle_sip_utils.c
src/belle_sip_utils.c
+85
-8
src/generic-uri.c
src/generic-uri.c
+137
-0
tester/Makefile.am
tester/Makefile.am
+1
-0
tester/belle_generic_uri_tester.c
tester/belle_generic_uri_tester.c
+76
-0
tester/belle_sip_tester.c
tester/belle_sip_tester.c
+2
-1
tester/belle_sip_tester.h
tester/belle_sip_tester.h
+2
-1
tester/belle_sip_uri_tester.c
tester/belle_sip_uri_tester.c
+3
-3
No files found.
include/belle-sip/Makefile.am
View file @
c04f17a3
...
...
@@ -2,7 +2,7 @@ bellesipdir=$(includedir)/belle-sip
bellesip_HEADERS
=
\
object.h
\
uri.h
\
sip-
uri.h
\
list.h
\
headers.h
\
parameters.h
\
...
...
@@ -24,6 +24,7 @@ bellesip_HEADERS=\
dict.h
\
http-provider.h
\
http-message.h
\
http-listener.h
http-listener.h
\
generic-uri.h
EXTRA_DIST
=
$(bellesip_HEADERS)
include/belle-sip/belle-sip.h
View file @
c04f17a3
...
...
@@ -119,7 +119,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID
(
belle_http_provider_t
),
BELLE_SIP_TYPE_ID
(
belle_http_request_t
),
BELLE_SIP_TYPE_ID
(
belle_http_response_t
),
BELLE_SIP_TYPE_ID
(
belle_http_channel_context_t
)
BELLE_SIP_TYPE_ID
(
belle_http_channel_context_t
),
BELLE_SIP_TYPE_ID
(
belle_generic_uri_t
)
BELLE_SIP_DECLARE_TYPES_END
...
...
@@ -163,7 +164,7 @@ typedef struct belle_http_url belle_http_url_t;
#include "belle-sip/list.h"
#include "belle-sip/listener.h"
#include "belle-sip/mainloop.h"
#include "belle-sip/uri.h"
#include "belle-sip/
sip-
uri.h"
#include "belle-sip/headers.h"
#include "belle-sip/parameters.h"
#include "belle-sip/message.h"
...
...
@@ -175,6 +176,7 @@ typedef struct belle_http_url belle_http_url_t;
#include "belle-sip/listeningpoint.h"
#include "belle-sip/provider.h"
#include "belle-sip/auth-helper.h"
#include "belle-sip/generic-uri.h"
#include "belle-sip/http-listener.h"
#include "belle-sip/http-provider.h"
#include "belle-sip/http-message.h"
...
...
include/belle-sip/generic-uri.h
0 → 100644
View file @
c04f17a3
/*
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/>.
*/
#ifndef BELLE_GENERIC_URI_H_
#define BELLE_GENERIC_URI_H_
#include "belle-sip/defs.h"
#include "belle-sip/list.h"
#include "belle-sip/utils.h"
typedef
struct
_belle_generic_uri
belle_generic_uri_t
;
BELLE_SIP_BEGIN_DECLS
/**
*
*/
BELLESIP_EXPORT
belle_generic_uri_t
*
belle_generic_uri_new
();
/**
*
*/
BELLESIP_EXPORT
belle_generic_uri_t
*
belle_generic_uri_parse
(
const
char
*
uri
)
;
/*
* Returns the host part of this uri.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_host
(
const
belle_generic_uri_t
*
uri
)
;
/**
* Returns the value of the maddr parameter, or null if this is not set.
*
*/
BELLESIP_EXPORT
int
belle_generic_uri_get_port
(
const
belle_generic_uri_t
*
uri
)
;
/**
* Returns the port of the uri, if not specified in the uri returns the well known port according to the transport.
**/
BELLESIP_EXPORT
int
belle_generic_uri_get_listening_port
(
const
belle_generic_uri_t
*
uri
);
/**
* Returns the user part of this URI.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_user
(
const
belle_generic_uri_t
*
uri
)
;
/**
* Gets user password of uri, or null if it is not set.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_user_password
(
const
belle_generic_uri_t
*
uri
)
;
/**
*
* Returns uri scheme.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_scheme
(
const
belle_generic_uri_t
*
uri
)
;
/**
*
* Returns uri path.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_path
(
const
belle_generic_uri_t
*
uri
)
;
/**
*
* Returns uri query.
*
*/
BELLESIP_EXPORT
const
char
*
belle_generic_uri_get_query
(
const
belle_generic_uri_t
*
uri
)
;
/**
* Removes the port part of this uri.
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_remove_port
(
belle_generic_uri_t
*
uri
)
;
/**
* Set the host part of this uri to the newly supplied host parameter.
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_host
(
belle_generic_uri_t
*
uri
,
const
char
*
host
)
;
/**
* Set the port part of this uri to the newly supplied port parameter.
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_port
(
belle_generic_uri_t
*
uri
,
int
port
)
;
/**
* Sets the scheme of this URI .
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_scheme
(
belle_generic_uri_t
*
uri
,
const
char
*
scheme
)
;
/**
* Sets the path of this URI .
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_path
(
belle_generic_uri_t
*
uri
,
const
char
*
scheme
)
;
/**
* Sets the query of this URI .
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_query
(
belle_generic_uri_t
*
uri
,
const
char
*
scheme
)
;
/**
* Sets the user of uri.
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_user
(
belle_generic_uri_t
*
uri
,
const
char
*
user
)
;
/**
* Sets the user password associated with the user of uri.
*
*/
BELLESIP_EXPORT
void
belle_generic_uri_set_user_password
(
belle_generic_uri_t
*
uri
,
const
char
*
userPassword
)
;
/**
* This method returns the URI as a string.
*
*/
BELLESIP_EXPORT
char
*
belle_generic_uri_to_string
(
belle_generic_uri_t
*
uri
)
;
#define BELLE_GENERIC_URI(obj) BELLE_SIP_CAST(obj,belle_generic_uri_t)
BELLE_SIP_END_DECLS
#endif
/* belle_generic_uri_H_ */
include/belle-sip/headers.h
View file @
c04f17a3
...
...
@@ -20,7 +20,7 @@
#define HEADERS_H_
#include "belle-sip/defs.h"
#include "belle-sip/uri.h"
#include "belle-sip/
sip-
uri.h"
#include "belle-sip/utils.h"
#include <time.h>
...
...
include/belle-sip/uri.h
→
include/belle-sip/
sip-
uri.h
View file @
c04f17a3
/*
* SipUri.h
*
* Created on: 18 sept. 2010
* Author: jehanmonnier
*/
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/>.
*/
#ifndef BELLE_SIP_URI_H_
#define BELLE_SIP_URI_H_
...
...
src/Makefile.am
View file @
c04f17a3
grammar_files
=
\
$(srcdir)
/belle_sip_message.g
\
$(srcdir)
/belle_sdp.g
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_sdpLexer.c belle_sdpLexer.h
\
belle_http_messageParser.c belle_http_messageParser.h
\
belle_http_messageLexer.c belle_http_messageLexer.h
.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)
$<
$(builddir)/generated_src_stamp
:
$(grammar_files)
$(ANTLR)
-make
-fo
$(builddir)
$(grammar_files)
touch
$(builddir)
/generated_src_stamp
$(generated_src)
:
$(builddir)/generated_src_stamp
BUILT_SOURCES
=
$(generated_src)
...
...
@@ -64,6 +77,7 @@ libbellesip_la_SOURCES= \
refresher.c
\
dns.c dns.h
\
belle_sip_dict.c
\
generic-uri.c
\
http-provider.c
\
http-message.c
...
...
src/belle_http_message.g
0 → 100644
View file @
c04f17a3
/*
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/>.
*/
grammar belle_http_message;
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.
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"
}
@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;
}
}
/*
absoluteURI = scheme ":" ( hier_part | opaque_part )
hier_part = ( net_path | abs_path ) [ "?" query ]
net_path = "//" authority [ abs_path ]
abs_path = "/" path_segments
*/
scheme: alpha ( alpha | DIGIT | '+' | '-' | '.' )*;
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] ;
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);
$ret=NULL;
}
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
{
char* unescaped_query;
unescaped_query=belle_sip_to_unescaped_string((const char *)$query.text->chars);
belle_generic_uri_set_query(uri,(const char*)unescaped_query);
belle_sip_free(unescaped_query);
}) ?;
path_segments[belle_generic_uri_t* uri]
: (segment ( SLASH segment )*)
{
char* unescaped_path;
unescaped_path=belle_sip_to_unescaped_string((const char *)$path_segments.text->chars);
belle_generic_uri_set_path(uri,(const char*)unescaped_path);
belle_sip_free(unescaped_path);
};
segment: pchar* ( SEMI param )*;
param: pchar*;
pchar: unreserved | escaped | COLON | '@' | '&' | EQUAL | '+' | '$' | COMMA;
query: uric+;
uric: reserved | unreserved | escaped;
authority[belle_generic_uri_t* uri]
: (
(userinfo[NULL])=>(userinfo[uri] hostport[uri])
| hostport[uri] );
userinfo[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
@init {$userinfo::current=uri;}
: user ( COLON password )? '@' ;
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_sip_free(unescaped_username);
};
user_unreserved : '&' | EQUAL | '+' | '$' | COMMA | SEMI | '?' | SLASH;
password : ( unreserved | escaped |'&' | EQUAL | '+' | '$' | 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);
belle_sip_free(unescaped_userpasswd);
};
hostport[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
@init {$hostport::current=uri;}
: host ( COLON port {belle_generic_uri_set_port($hostport::current,$port.ret);})? {belle_generic_uri_set_host($hostport::current,$host.ret);};
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 '.' )* toplabel '.'? ;
domainlabel : alphanum | (alphanum ( alphanum | '-' )* alphanum) ;
toplabel : alpha | (alpha ( '-'? alphanum)+) ;
ipv4address : three_digit '.' three_digit '.' three_digit '.' three_digit ;
ipv6reference : '[' ipv6address ']'{$host::current=(const char *)$ipv6address.text->chars;};
ipv6address : hexpart ( COLON ipv4address )? ;
hexpart : hexseq | hexseq '::' ( hexseq )? | '::' ( hexseq )?;
hexseq : hex4 ( COLON hex4)*;
hex4 : hexdigit+;/* hexdigit hexdigit hexdigit ;*/
port returns [int ret]: DIGIT+ { $ret=atoi((const char *)$text->chars); };
escaped : '%' hexdigit hexdigit;
ttl : three_digit;
three_digit: (DIGIT) => DIGIT
|
(DIGIT DIGIT) => (DIGIT DIGIT)
|
(DIGIT DIGIT DIGIT) =>(DIGIT DIGIT DIGIT) ;
token
: (alphanum | mark | '%' | PLUS | '`' )+;
reserved
: SEMI | SLASH | '?' | COLON | '@' | '&' | EQUAL | PLUS
| '$' | COMMA;
unreserved : alphanum |mark;
alphanum : alpha | DIGIT ;
hexdigit
: HEX_CHAR|DIGIT;
alpha : HEX_CHAR | COMMON_CHAR;
word
: (alphanum | mark | '%'
| PLUS | '`' |
LAQUOT | RAQUOT |
COLON | '\\' | DQUOTE | SLASH | '[' | ']' | '?' | '{' | '}' )+;
COMMON_CHAR
: 'g'..'z' | 'G'..'Z' ;
mark : '-' | '_' | '.' | '!' | '~' | STAR | '\'' | LPAREN | RPAREN ;
HEX_CHAR: 'a'..'f' |'A'..'F';
DIGIT : '0'..'9' ;
CRLF : '\r\n' { USER1 = (int)((char*)ctx->pLexer->input->currentLine - (char*)ctx->pLexer->input->data); /*GETCHARINDEX()*/;};
hcolon : ( LWS | HTAB )* COLON LWS? //SWS;
;//|( SP | HTAB )* COLON LWS+;
HTAB : ' ';
ldquot : LWS? DQUOTE ;
rdquot : DQUOTE LWS?;
DQUOTE : '"';
// open double quotation mark
//SWS : LWS? ;
LWS : (SP* CRLF)? SP+ ; //linear whitespace
PLUS: '+';
COLON
: ':'
;
semi: LWS? SEMI LWS?;
SEMI
: ';'
;
comma : LWS? COMMA LWS?;
COMMA
: ','
;
sp_laquot_sp
: LWS? LAQUOT LWS?;
sp_raquot_sp
: LWS? RAQUOT LWS?;
LAQUOT
: '<'
;
RAQUOT
: '>'
;
RPAREN
: ')'
;
LPAREN
: '('
;
equal:
LWS? EQUAL LWS?;
EQUAL
: '='
;
slash : LWS? SLASH LWS?;
SLASH
: '/'
;
STAR
: '*'
;
fragment
SP
: ' '
;
OCTET : . ;
src/belle_sdp.g
View file @
c04f17a3
...
...
@@ -23,7 +23,7 @@ options {
output=AST;
}
@header {
@
lexer::
header {
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
...
...
@@ -41,6 +41,32 @@ options {
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.
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"
}
@includes {
#include "belle-sip/belle-sdp.h"
...
...
src/belle_sip_internal.h
View file @
c04f17a3
...
...
@@ -195,6 +195,7 @@ BELLE_SIP_DECLARE_VPTR(belle_http_provider_t);
BELLE_SIP_DECLARE_VPTR
(
belle_http_channel_context_t
);
BELLE_SIP_DECLARE_VPTR
(
belle_http_request_t
);
BELLE_SIP_DECLARE_VPTR
(
belle_http_response_t
);
BELLE_SIP_DECLARE_VPTR
(
belle_generic_uri_t
);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN
(
belle_sip_resolver_context_t
,
belle_sip_source_t
)
void
(
*
cancel
)(
belle_sip_resolver_context_t
*
);
...
...
@@ -377,17 +378,17 @@ antlr3NewAsciiStringCopyStream((pANTLR3_UINT8)value,(ANTLR3_UINT32)length,NULL)
#endif
/*HAVE_ANTLR_STRING_STREAM_NEW*/
#define BELLE_
SIP_
PARSE(object_type) \
belle_sip_
##object_type##_t*
belle_sip_
##object_type##_parse (const char* value) { \
#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; \