Commit 5df364f6 authored by jehan's avatar jehan

start request implementation

parent c0be4ce3
......@@ -56,12 +56,13 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_response_t),
BELLE_SIP_TYPE_ID(belle_sip_object_t),
BELLE_SIP_TYPE_ID(belle_sip_parameters_t),
BELLE_SIP_TYPE_ID(belle_sip_header_callid_t),
BELLE_SIP_TYPE_ID(belle_sip_header_call_id_t),
BELLE_SIP_TYPE_ID(belle_sip_header_cseq_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_type_t),
BELLE_SIP_TYPE_ID(belle_sip_sender_task_t),
BELLE_SIP_TYPE_ID(belle_sip_header_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_record_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_length_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......
......@@ -174,14 +174,14 @@ int belle_sip_header_via_set_ttl(belle_sip_header_via_t* via, int ttl);
* Call id object inherent from object
*
******************************/
typedef struct _belle_sip_header_callid belle_sip_header_callid_t;
typedef struct _belle_sip_header_call_id belle_sip_header_call_id_t;
belle_sip_header_callid_t* belle_sip_header_callid_new();
belle_sip_header_call_id_t* belle_sip_header_call_id_new();
belle_sip_header_callid_t* belle_sip_header_callid_parse (const char* callid) ;
const char* belle_sip_header_callid_get_callid(belle_sip_header_callid_t* callid);
void belle_sip_header_callid_set_callid(belle_sip_header_callid_t* via,const char* callid);
#define BELLE_SIP_HEADER_CALLID(t) BELLE_SIP_CAST(t,belle_sip_header_callid_t)
belle_sip_header_call_id_t* belle_sip_header_call_id_parse (const char* call_id) ;
const char* belle_sip_header_call_id_get_call_id(belle_sip_header_call_id_t* call_id);
void belle_sip_header_call_id_set_call_id(belle_sip_header_call_id_t* via,const char* call_id);
#define BELLE_SIP_HEADER_CALL_ID(t) BELLE_SIP_CAST(t,belle_sip_header_call_id_t)
/******************************
* cseq object inherent from object
*
......@@ -229,6 +229,18 @@ void belle_sip_header_content_type_set_subtype(belle_sip_header_content_type_t*
belle_sip_header_record_route_t* belle_sip_header_record_route_new();
belle_sip_header_record_route_t* belle_sip_header_record_route_parse (const char* route) ;
#define BELLE_SIP_HEADER_RECORD_ROUTE(t) BELLE_SIP_CAST(t,belle_sip_header_record_route_t)
#define BELLE_SIP_HEADER_RECORD_ROUTE(t) BELLE_SIP_CAST(t,belle_sip_header_record_route_t)
/******************************
* Content length inherent from object
*
******************************/
typedef struct _belle_sip_header_content_length belle_sip_header_content_length_t;
belle_sip_header_content_length_t* belle_sip_header_content_length_new();
belle_sip_header_content_length_t* belle_sip_header_content_length_parse (const char* content_length) ;
unsigned int belle_sip_header_content_length_get_content_length(belle_sip_header_content_length_t* content_length);
void belle_sip_header_content_length_set_content_length(belle_sip_header_content_length_t* content_length,unsigned int length);
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
#endif /* HEADERS_H_ */
......@@ -18,15 +18,26 @@
#ifndef BELLE_SIP_MESSAGE_H
#define BELLE_SIP_MESSAGE_H
typedef struct belle_sip_message belle_sip_message_t;
typedef struct belle_sip_request belle_sip_request_t;
typedef struct belle_sip_response belle_sip_response_t;
typedef struct _belle_sip_message belle_sip_message_t;
typedef struct _belle_sip_request belle_sip_request_t;
typedef struct _belle_sip_response belle_sip_response_t;
#define BELLE_SIP_MESSAGE(obj) BELLE_SIP_CAST(obj,belle_sip_message_t)
#define BELLE_SIP_REQUEST(obj) BELLE_SIP_CAST(obj,belle_sip_request_t)
#define BELLE_SIP_RESPONSE(obj) BELLE_SIP_CAST(obj,belle_sip_response_t)
int belle_sip_message_is_request(belle_sip_message_t *msg);
belle_sip_request_t* belle_sip_request_new();
belle_sip_request_t* belle_sip_request_parse(const char* raw);
belle_sip_uri_t* belle_sip_request_get_uri(belle_sip_request_t* request);
void belle_sip_request_set_uri(belle_sip_request_t* request,belle_sip_uri_t* uri);
const char* belle_sip_request_get_method(belle_sip_request_t* request);
void belle_sip_request_set_method(belle_sip_request_t* request,const char* method);
int belle_sip_message_is_response(belle_sip_message_t *msg);
......
......@@ -195,23 +195,23 @@ int belle_sip_header_via_set_port (belle_sip_header_via_t* obj,int value) {
}
}
/**************************
* callid header object inherent from object
* call_id header object inherent from object
****************************
*/
struct _belle_sip_header_callid {
struct _belle_sip_header_call_id {
belle_sip_object_t base;
const char* callid;
const char* call_id;
};
static void belle_sip_header_callid_destroy(belle_sip_header_callid_t* callid) {
belle_sip_object_destroy(BELLE_SIP_OBJECT(callid));
if (callid->callid) belle_sip_free((void*)callid->callid);
static void belle_sip_header_call_id_destroy(belle_sip_header_call_id_t* call_id) {
belle_sip_object_destroy(BELLE_SIP_OBJECT(call_id));
if (call_id->call_id) belle_sip_free((void*)call_id->call_id);
}
BELLE_SIP_NEW(header_callid,object)
BELLE_SIP_PARSE(header_callid)
GET_SET_STRING(belle_sip_header_callid,callid);
BELLE_SIP_NEW(header_call_id,object)
BELLE_SIP_PARSE(header_call_id)
GET_SET_STRING(belle_sip_header_call_id,call_id);
/**************************
* cseq header object inherent from object
****************************
......@@ -280,4 +280,19 @@ static void belle_sip_header_record_route_destroy(belle_sip_header_record_route_
BELLE_SIP_NEW(header_record_route,header_address)
BELLE_SIP_PARSE(header_record_route)
/**************************
* content length header object inherent from object
****************************
*/
struct _belle_sip_header_content_length {
belle_sip_object_t base;
unsigned int content_length;
};
static void belle_sip_header_content_length_destroy(belle_sip_header_content_length_t* content_length) {
belle_sip_object_destroy(BELLE_SIP_OBJECT(content_length));
}
BELLE_SIP_NEW(header_content_length,object)
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
......@@ -28,42 +28,47 @@ options {
}
/*
message
: request | response ;
request
: request_line | message_header* CRLF message_body ;
: request /*| response*/ ;
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+ CRLF message_body ? ;
request_line
: method SP request_uri SP sip_version CRLF ;
: method {belle_sip_request_set_method($request::current,(const char*)($method.text->chars));}
SP
uri {belle_sip_request_set_uri($request::current,$uri.ret);}
SP
sip_version
CRLF ;
request_uri
: an_sip_uri ;
sip_version
: 'SIP/' DIGIT '.' DIGIT;
message_header
: (accept
: (/*accept
| accept_encoding
| accept_language
| alert_info
| allow
| authentication_info
| authorization
| call_id
|*/ header_call_id/*
| call_info
| contact
| content_disposition
| content_encoding
| content_language
| content_length
| content_type
| cseq
| content_language*/
| header_content_length
| header_content_type
| header_cseq/*
| date
| error_info
| expires
| from
| expires*/
| header_from /*
| in_reply_to
| max_forwards
| mime_version
......@@ -72,24 +77,24 @@ message_header
| priority
| proxy_authenticate
| proxy_authorization
| proxy_require
| record_route
| proxy_require*/
| header_record_route /*
| reply_to
| require
| retry_after
| route
| retry_after*/
| header_route /*
| server
| subject
| supported
| timestamp
| to
| timestamp*/
| header_to/*
| unsupported
| user_agent
| via
| user_agent*/
| header_via /*
| warning
| www_authenticate
| extension_header) CRLF;
| www_authenticate*/
| header_extension_header) CRLF;
/*
invitem
: 'INVITE' ; //INVITE in caps
ackm : 'ACK'; //ACK in caps
......@@ -269,14 +274,14 @@ response_digest
: LDQUOT hexdigit* RDQUOT;
*/
/*callid header*/
callid_token: {strcmp("Call-ID",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(7)))->chars) == 0}? token;
header_callid returns [belle_sip_header_callid_t* ret]
scope { belle_sip_header_callid_t* current; }
@init {$header_callid::current = belle_sip_header_callid_new(); $ret=$header_callid::current; }
: callid_token /*( 'Call-ID' | 'i' )*/ hcolon callid;
callid
: word ( '@' word )? {belle_sip_header_callid_set_callid($header_callid::current,(const char*) $text->chars); };
call_id_token: {strcmp("Call-ID",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(7)))->chars) == 0}? token;
header_call_id returns [belle_sip_header_call_id_t* ret]
scope { belle_sip_header_call_id_t* current; }
@init {$header_call_id::current = belle_sip_header_call_id_new(); $ret=$header_call_id::current; }
: call_id_token /*( 'Call-ID' | 'i' )*/ hcolon call_id;
call_id
: word ( '@' word )? {belle_sip_header_call_id_set_call_id($header_call_id::current,(const char*) $text->chars); };
/*
call_info
: 'Call-Info' HCOLON info (COMMA info)*;
......@@ -356,10 +361,16 @@ subtag
huit_alpha
: alpha+;
;
content_length
: ( 'Content-Length' | 'l' ) HCOLON DIGIT+;
*/
content_length_token : {strcmp("Content-Length",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(14)))->chars) == 0}? token;
header_content_length returns [belle_sip_header_content_length_t* ret]
scope { belle_sip_header_content_length_t* current; }
@init {$header_content_length::current = belle_sip_header_content_length_new(); $ret=$header_content_length::current; }
: content_length_token /*( 'Content-Length' | 'l' )*/
hcolon
content_length {belle_sip_header_content_length_set_content_length($header_content_length::current,atoi((const char*)$content_length.text->chars));};
content_length:DIGIT+;
content_type_token : {strcmp("Content-Type",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(12)))->chars) == 0}? token;
header_content_type returns [belle_sip_header_content_type_t* ret]
scope { belle_sip_header_content_type_t* current;}
......@@ -661,16 +672,18 @@ pseudonym
www_authenticate
: 'WWW-Authenticate' HCOLON challenge;
extension_header
: header_name HCOLON header_value;
*/
header_extension_header
: header_name hcolon header_value;
header_name
: token;
header_value
: .;
message_body
: OCTET*;
*/
: (~CRLF)*;
message_body
options { greedy = false; }
: OCTET+;
uri returns [belle_sip_uri_t* ret]
scope { belle_sip_uri_t* current; }
@init { $uri::current = belle_sip_uri_new(); }
......
......@@ -15,9 +15,49 @@
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_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"
typedef struct _header_container {
const char* name;
belle_sip_list_t* header_list;
} header_container_t;
/*
static header_container_t* belle_sip_message_header_container_new(const char* name) {
header_container_t* header_container = belle_sip_new0(header_container_t);
header_container->name= belle_sip_strdup(name);
}
*/
struct _belle_sip_message {
belle_sip_object_t base;
belle_sip_list_t* header_list;
belle_sip_list_t* headernames_list;
};
static void belle_sip_message_init(belle_sip_message_t *message){
belle_sip_object_init_type(message,belle_sip_message_t);
}
void belle_sip_message_add_header(belle_sip_message_t *message,belle_sip_header_t* header) {
}
struct _belle_sip_request {
belle_sip_message_t message;
};
static void belle_sip_request_destroy(belle_sip_request_t* request) {
}
BELLE_SIP_NEW(request,message)
BELLE_SIP_PARSE(request)
void belle_sip_request_set_uri(belle_sip_request_t* request,belle_sip_uri_t* uri) {
}
void belle_sip_request_set_method(belle_sip_request_t* request,const char* method) {
}
int belle_sip_message_is_request(belle_sip_message_t *msg){
return 0;
}
......
......@@ -98,11 +98,11 @@ void test_header_via(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_branch(L_via),"z9hG4bK368560724");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
}
void test_header_callid(void) {
void test_header_call_id(void) {
belle_sip_header_callid_t* L_callid = belle_sip_header_callid_parse("Call-ID: 1665237789@titi.com");
CU_ASSERT_STRING_EQUAL(belle_sip_header_callid_get_callid(L_callid), "1665237789@titi.com");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_callid));
belle_sip_header_call_id_t* L_call_id = belle_sip_header_call_id_parse("Call-ID: 1665237789@titi.com");
CU_ASSERT_STRING_EQUAL(belle_sip_header_call_id_get_call_id(L_call_id), "1665237789@titi.com");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_call_id));
}
void test_header_cseq(void) {
......@@ -137,6 +137,12 @@ void test_header_route(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_route),"charset"),"ISO-8859-4");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
}
void test_header_content_length(void) {
belle_sip_header_content_length_t* L_content_length = belle_sip_header_content_length_parse("Content-Length: 3495");
CU_ASSERT_EQUAL(belle_sip_header_content_length_get_content_length(L_content_length), 3495);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_length));
}
int belle_sip_headers_test_suite() {
......@@ -161,7 +167,7 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test of via header", test_header_via)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of callid header", test_header_callid)) {
if (NULL == CU_add_test(pSuite, "test of call_id header", test_header_call_id)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of cseq header", test_header_cseq)) {
......@@ -176,5 +182,8 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test of route header", test_header_route)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of content lenth", test_header_content_length)) {
return CU_get_error();
}
return 0;
}
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