Commit 18110440 authored by jehan's avatar jehan

first http ready parser

parent d5ba53a7
......@@ -20,7 +20,7 @@
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.688348245" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.1183422670" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder arguments="-j4 CFLAGS=&quot;-g -Wall&quot;" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.1706103106" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<builder arguments="-j4 CFLAGS=&quot;-g -Wall -Werror&quot; V=1" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.1706103106" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.2093869426" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.c.linker.input.451088761" superClass="cdt.managedbuild.tool.macosx.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
......
......@@ -135,6 +135,7 @@ BELLESIP_EXPORT void belle_generic_uri_set_user_password(belle_generic_uri_t* ur
*/
BELLESIP_EXPORT char* belle_generic_uri_to_string(belle_generic_uri_t* uri) ;
BELLESIP_EXPORT belle_sip_error_code belle_generic_uri_marshal(const belle_generic_uri_t* uri, char* buff, size_t buff_size, size_t *offset);
#define BELLE_GENERIC_URI(obj) BELLE_SIP_CAST(obj,belle_generic_uri_t)
......
......@@ -24,7 +24,30 @@
BELLE_SIP_BEGIN_DECLS
belle_http_url_t *belle_http_request_get_url(belle_http_request_t *req);
/***
* http request
*/
BELLESIP_EXPORT belle_http_request_t* belle_http_request_new();
BELLESIP_EXPORT belle_http_request_t* belle_http_request_parse(const char* raw);
BELLESIP_EXPORT belle_generic_uri_t* belle_http_request_get_uri(const belle_http_request_t* request);
BELLESIP_EXPORT void belle_http_request_set_uri(belle_http_request_t* request, belle_generic_uri_t* uri);
BELLESIP_EXPORT const char* belle_http_request_get_method(const belle_http_request_t* request);
BELLESIP_EXPORT void belle_http_request_set_method(belle_http_request_t* request,const char* method);
/**
* http response
* */
BELLESIP_EXPORT int belle_http_response_get_status_code(const belle_http_response_t *response);
BELLESIP_EXPORT void belle_http_response_set_status_code(belle_http_response_t *response,int status);
BELLESIP_EXPORT const char* belle_http_response_get_reason_phrase(const belle_http_response_t *response);
BELLESIP_EXPORT void belle_http_response_set_reason_phrase(belle_http_response_t *response,const char* reason_phrase);
BELLESIP_EXPORT belle_http_response_t *belle_http_response_new(void);
BELLE_SIP_END_DECLS
......
......@@ -23,8 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageLexer.h"
#include "belle_sip_messageParser.h"
#include "belle_sip_lexer.h"
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
......@@ -932,12 +933,13 @@ 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_lexer lex;
pbelle_sip_messageLexer lex;
pANTLR3_COMMON_TOKEN_STREAM tokens;
pbelle_sip_messageParser parser;
belle_sip_message_sip_header_extension_return l_parsed_object;
/*belle_sip_message_sip_header_extension_return*/ belle_sip_messageParser_header_extension_return l_parsed_object;
input = ANTLR_STREAM_NEW("header_extension",value,strlen(value));
lex = belle_sip_lexerNew (input);
lex = belle_sip_messageLexerNew (input);
tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens);
l_parsed_object = parser->header_extension(parser,FALSE);
......
......@@ -384,12 +384,12 @@ 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; \
pbelle_sip_lexer lex; \
pbelle_sip_messageLexer lex; \
pANTLR3_COMMON_TOKEN_STREAM tokens; \
p##parser_name parser; \
object_type_prefix##object_type##_t* l_parsed_object; \
input = ANTLR_STREAM_NEW(object_type,value,strlen(value));\
lex = belle_sip_lexerNew (input);\
lex = belle_sip_messageLexerNew (input);\
tokens = antlr3CommonTokenStreamSourceNew (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
parser = parser_name##New (tokens);\
l_parsed_object = parser->object_type(parser);\
......@@ -941,4 +941,6 @@ void belle_sip_request_set_dialog(belle_sip_request_t *req, belle_sip_dialog_t *
void belle_sip_request_set_rfc2543_branch(belle_sip_request_t *req, const char *rfc2543branch);
void belle_sip_dialog_update_request(belle_sip_dialog_t *dialog, belle_sip_request_t *req);
belle_sip_error_code belle_sip_headers_marshal(belle_sip_message_t *message, char* buff, size_t buff_size, size_t *offset);
#endif
......@@ -22,7 +22,7 @@
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_lexer.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
......
......@@ -163,10 +163,11 @@ static int get_message_start_pos(char *buff, size_t bufflen) {
saved_char1=buff[saved_char1_index]; /*make sure buff is null terminated*/
buff[saved_char1_index]='\0';
res=sscanf(buff+i,"SIP/2.0 %d ",&status_code);
if (res!=1) res=sscanf(buff+i,"HTTP/1.%*i %d ",&status_code); /*might be HTTP ?*/
if (res!=1) {
res= sscanf(buff+i,"%16s %*s %9s\r\n",method,sip_version)==2
&& is_token(method,sizeof(method))
&& strcmp("SIP/2.0",sip_version)==0 ;
&& (strcmp("SIP/2.0",sip_version)==0 || strncmp("HTTP/1.",sip_version,strlen("HTTP/1."))==0) ;
}
buff[saved_char1_index]=saved_char1;
if (res==1) return i;
......
......@@ -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_sip_lexer.h"
#include "belle_sip_message_http.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_messageParser.h"
#include "belle-sip/generic-uri.h"
#include "belle-sip/parameters.h"
......@@ -95,8 +95,6 @@ belle_sip_error_code belle_generic_uri_marshal(const belle_generic_uri_t* uri, c
error=belle_sip_snprintf(buff,buff_size,offset,"%s",uri->host);
}
if (error!=BELLE_SIP_OK) return error;
} else {
belle_sip_warning("no host found in this uri [%p]",uri);
}
if (uri->port>0) {
......
......@@ -6,28 +6,19 @@ 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_sip_messageLexer.c belle_sip_messageLexer.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) $<
belle_sdpLexer.c belle_sdpLexer.h
.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
$(builddir)/belle_sip_messageLexer.c $(builddir)/belle_sip_messageLexer.h : belle_sip_message.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) $<
$(ANTLR) -make -Xmultithreaded -fo $(builddir) $<
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src
......
/*
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 : . ;
This diff is collapsed.
/*
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
/*
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 http;
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;
}
}
/*
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 | PLUS | DASH | DOT )*;
generic_uri returns [belle_generic_uri_t* ret=NULL]
scope { belle_generic_uri_t* 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($generic_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] )
(QMARK 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 | AT | AND | EQUAL | PLUS | DOLLARD | COMMA;
query: uric+;
uric: reserved | unreserved | escaped;
authority[belle_generic_uri_t* uri]
: (
(authority_userinfo[NULL])=>(authority_userinfo[uri] authority_hostport[uri])
| authority_hostport[uri] );
authority_userinfo[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
@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($authority_userinfo::current,unescaped_username);
belle_sip_free(unescaped_username);
};
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($authority_userinfo::current,unescaped_userpasswd);
belle_sip_free(unescaped_userpasswd);
};
authority_hostport[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
@init {$authority_hostport::current=uri;}
: host ( COLON port {belle_generic_uri_set_port($authority_hostport::current,$port.ret);})? {belle_generic_uri_set_host($authority_hostport::current,$host.ret);};
......@@ -15,41 +15,60 @@
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_messageLexer.h"
#include "belle_sip_messageParser.h"
#include "belle_sip_internal.h"
/**request**/
struct belle_http_request{
belle_sip_message_t base;
belle_http_url_t *req_url;
belle_generic_uri_t *req_uri;
char* method;
belle_http_request_listener_t *listener;
};
static void belle_http_request_init(belle_http_request_t *req){
/*nop*/
}
static void belle_http_request_listener_destroyed(belle_http_request_t *req){
req->listener=NULL;
}
static void belle_http_request_destroy(belle_http_request_t *req){
if (req->req_url) belle_sip_object_unref(req->req_url);
if (req->req_uri) belle_sip_object_unref(req->req_uri);
DESTROY_STRING(req,method)
belle_http_request_set_listener(req,NULL);
}
static void belle_http_request_clone(belle_http_request_t *obj, const belle_http_request_t *orig){
if (orig->req_url) obj->req_url=(belle_http_url_t*)belle_sip_object_clone((belle_sip_object_t*)orig->req_url);
if (orig->req_uri) obj->req_uri=(belle_generic_uri_t*)belle_sip_object_clone((belle_sip_object_t*)orig->req_uri);
CLONE_STRING(belle_http_request,method,obj,orig)
}
static belle_sip_error_code belle_http_request_marshal(const belle_http_request_t* request, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_snprintf(buff,buff_size,offset,"%s ",belle_http_request_get_method(request));
if (error!=BELLE_SIP_OK) return error;
error=belle_generic_uri_marshal(belle_http_request_get_uri(request),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset," %s","HTTP/1.0\r\n");
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_headers_marshal(BELLE_SIP_MESSAGE(request),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
if (BELLE_SIP_MESSAGE(request)->body) {
error=belle_sip_snprintf(buff,buff_size,offset, "%s",BELLE_SIP_MESSAGE(request)->body);
if (error!=BELLE_SIP_OK) return error;
}
return error;
}
GET_SET_STRING(belle_http_request,method);
BELLE_NEW(belle_http_request,belle_sip_message)
BELLE_PARSE(belle_sip_messageParser,belle_,http_request)
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_http_request_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_http_request_t,belle_sip_message_t,belle_http_request_destroy,belle_http_request_clone,NULL,TRUE);
belle_http_request_t *belle_http_request_new(){
belle_http_request_t *obj=belle_sip_object_new(belle_http_request_t);
belle_sip_message_init((belle_sip_message_t*)obj);
return obj;
}
belle_http_request_t *belle_http_request_create(belle_http_url_t *url){
belle_http_request_t *belle_http_request_create(belle_generic_uri_t *url){
belle_http_request_t *obj=belle_http_request_new();
obj->req_url=(belle_http_url_t*)belle_sip_object_ref(url);
obj->req_uri=(belle_generic_uri_t*)belle_sip_object_ref(url);
return obj;
}
......@@ -62,6 +81,62 @@ void belle_http_request_set_listener(belle_http_request_t *req, belle_http_reque
belle_sip_object_weak_ref(l,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
}
belle_http_url_t *belle_http_request_get_url(belle_http_request_t *req){
return req->req_url;
belle_generic_uri_t *belle_http_request_get_uri(const belle_http_request_t *req){
return req->req_uri;
}
void belle_http_request_set_uri(belle_http_request_t* request, belle_generic_uri_t* uri) {
if (uri) belle_sip_object_ref(uri);
if (request->req_uri) belle_sip_object_unref(request->req_uri);
request->req_uri=uri;
}
/*response*/
struct belle_http_response{
belle_sip_message_t base;
char *http_version;
int status_code;
char *reason_phrase;
};
void belle_http_response_destroy(belle_http_response_t *resp){
if (resp->http_version) belle_sip_free(resp->http_version);
if (resp->reason_phrase) belle_sip_free(resp->reason_phrase);
}
static void belle_http_response_init(belle_http_response_t *resp){
}
static void belle_http_response_clone(belle_http_response_t *resp, const belle_http_response_t *orig){
if (orig->http_version) resp->http_version=belle_sip_strdup(orig->http_version);
resp->status_code=orig->status_code;
if (orig->reason_phrase) resp->reason_phrase=belle_sip_strdup(orig->reason_phrase);
}
belle_sip_error_code belle_http_response_marshal(belle_http_response_t *resp, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_snprintf( buff
,buff_size
,offset
,"HTTP/1.1 %i %s\r\n"
,belle_http_response_get_status_code(resp)
,belle_http_response_get_reason_phrase(resp));
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_headers_marshal(BELLE_SIP_MESSAGE(resp),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
if (BELLE_SIP_MESSAGE(resp)->body) {
error=belle_sip_snprintf(buff,buff_size,offset, "%s",BELLE_SIP_MESSAGE(resp)->body);
if (error!=BELLE_SIP_OK) return error;
}
return error;
}
BELLE_NEW(belle_http_response,belle_sip_message)
BELLE_PARSE(belle_sip_messageParser,belle_,http_response)
GET_SET_STRING(belle_http_response,reason_phrase);
GET_SET_INT(belle_http_response,status_code,int)
......@@ -15,8 +15,9 @@
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_messageLexer.h"
#include "belle_sip_messageParser.h"
#include "belle_sip_lexer.h"
#include "belle_sip_internal.h"
......@@ -68,12 +69,12 @@ belle_sip_message_t* belle_sip_message_parse (const char* value) {
belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_length,size_t* message_length ) { \
pANTLR3_INPUT_STREAM input;
pbelle_sip_lexer lex;
pbelle_sip_messageLexer lex;
pANTLR3_COMMON_TOKEN_STREAM tokens;
pbelle_sip_messageParser parser;
belle_sip_message_t* l_parsed_object;
input = ANTLR_STREAM_NEW("message",buff,buff_length);
lex = belle_sip_lexerNew (input);
lex = belle_sip_messageLexerNew (input);
tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens);
l_parsed_object = parser->message_raw(parser,message_length);
......
......@@ -60,11 +60,26 @@ static void test_complex_uri() {
belle_sip_object_unref(uri);
}
static void test_abs_path() {