Commit de094f1e authored by jehan's avatar jehan

implement request parser

parent af550943
......@@ -52,6 +52,7 @@
<option id="gnu.cpp.compiler.macosx.exe.debug.option.debugging.level.1587258294" name="Debug Level" superClass="gnu.cpp.compiler.macosx.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1778710346" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.797856581" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
......@@ -66,29 +67,26 @@
</tool>
</toolChain>
</folderInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.1205048807" name="belle_sip_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1850485661">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1850485661" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.939495352" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.1422516973" name="belle_sip_headers_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_headers_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.476090798">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.476090798" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.1874152018" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/include}&quot;"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1598375635" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1419900147" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</fileInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.1422516973" name="belle_sip_headers_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_headers_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.476090798">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.476090798" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.1874152018" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.1205048807" name="belle_sip_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1850485661">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1850485661" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.939495352" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/include}&quot;"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1419900147" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1598375635" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</fileInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.66827395" name="cast_test.c" rcbsApplicability="disable" resourcePath="tester/cast_test.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1522599976">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.1522599976" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201"/>
</fileInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.789517118" name="parser-antlr.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_uri_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.75619886">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.75619886" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.246079056" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
......@@ -99,6 +97,16 @@
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.170614653" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</fileInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.569616755" name="belle_sip_message_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_message_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.156963690">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.156963690" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.1281017285" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/include}&quot;"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1005505490" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</fileInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
......
......@@ -60,7 +60,11 @@ void belle_sip_header_address_set_displayname(belle_sip_header_address_t* addres
**************************************************************************************/
typedef struct _belle_sip_header belle_sip_header_t;
const char* belle_sip_header_get_name (belle_sip_header_t* obj);
void belle_sip_header_set_name (belle_sip_header_t* obj,const char* value);
#define BELLE_SIP_HEADER(t) BELLE_SIP_CAST(t,belle_sip_header_t)
/***********************
* Contact header object
************************/
......
......@@ -49,7 +49,7 @@ belle_sip_header_t *belle_sip_message_get_header_last(belle_sip_message_t *msg,
* @param msg
* @param header to add, must be one of header type
*/
void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_object_t* header);
void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_header_t* header);
char *belle_sip_message_to_string(belle_sip_message_t *msg);
......
......@@ -30,16 +30,13 @@
/************************
* header
***********************/
struct _belle_sip_header {
belle_sip_object_t base;
const char* name;
};
GET_SET_STRING(belle_sip_header,name);
void belle_sip_header_init(belle_sip_header_t *header) {
belle_sip_object_init_type(header,belle_sip_header_t);
belle_sip_object_init((belle_sip_object_t*)header); /*super*/
}
static void belle_sip_header_destroy(belle_sip_header_t *header){
void belle_sip_header_destroy(belle_sip_header_t *header){
if (header->name) belle_sip_free((void*)header->name);
}
......
......@@ -345,10 +345,16 @@ void belle_sip_param_pair_unref(belle_sip_param_pair_t* obj);
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value);
/*calss header*/
struct _belle_sip_header {
belle_sip_object_t base;
const char* name;
};
void belle_sip_header_destroy(belle_sip_header_t *header);
void belle_sip_header_init(belle_sip_header_t* obj);
/*class parameters*/
struct _belle_sip_parameters {
belle_sip_object_t base;
belle_sip_header_t base;
belle_sip_list_t* param_list;
belle_sip_list_t* paramnames_list;
};
......
......@@ -47,7 +47,7 @@ request_line
CRLF ;
sip_version
: 'SIP/' DIGIT '.' DIGIT;
: token;//'SIP/' DIGIT '.' DIGIT;
message_header [belle_sip_message_t* message]
......@@ -58,19 +58,19 @@ message_header [belle_sip_message_t* message]
| allow
| authentication_info
| authorization
|*/ header_call_id {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_call_id.ret));}/*
|*/ header_call_id {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_call_id.ret));}/*
| call_info
| contact
| content_disposition
| content_encoding
| content_language*/
| header_content_length {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_content_length.ret));}
| header_content_type {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_content_type.ret));}
| header_cseq {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_cseq.ret));}/*
| 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_header_add(message,BELLE_SIP_OBJECT($header_from.ret));}/*
| header_from {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_from.ret));}/*
| in_reply_to
| max_forwards
| mime_version
......@@ -80,19 +80,19 @@ message_header [belle_sip_message_t* message]
| proxy_authenticate
| proxy_authorization
| proxy_require*/
| header_record_route {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_record_route.ret));}/*
| 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_header_add(message,BELLE_SIP_OBJECT($header_route.ret));}/*
| header_route {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_route.ret));}/*
| server
| subject
| supported
| timestamp*/
| header_to {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_to.ret));}/*
| header_to {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_to.ret));}/*
| unsupported
| user_agent*/
| header_via {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_via.ret));}/*
| header_via {belle_sip_message_add_header(message,BELLE_SIP_HEADER($header_via.ret));}/*
| warning
| www_authenticate*/
| header_extension_header
......
......@@ -18,20 +18,21 @@
#include "belle-sip/belle-sip.h"
#include "belle-sip/parameters.h"
#include "belle_sip_internal.h"
#include "belle-sip/headers.h"
void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
if (params->param_list) belle_sip_list_free (params->param_list);
if (params->paramnames_list) belle_sip_list_free (params->paramnames_list);
belle_sip_header_destroy(BELLE_SIP_HEADER(params));
}
void belle_sip_parameters_init(belle_sip_parameters_t *obj) {
belle_sip_object_init_type(obj,belle_sip_parameters_t);
belle_sip_object_init((belle_sip_object_t*)obj);
belle_sip_header_init((belle_sip_header_t*)obj);
}
belle_sip_parameters_t* belle_sip_parameters_new() {
belle_sip_parameters_t* l_object = (belle_sip_parameters_t*)belle_sip_object_new(belle_sip_parameters_t,(belle_sip_object_destroy_t)belle_sip_parameters_destroy);
belle_sip_object_init((belle_sip_object_t*)l_object);
belle_sip_header_init((belle_sip_header_t*)l_object);
return l_object;
}
......
......@@ -42,6 +42,7 @@ static int belle_sip_headers_container_comp_func(const headers_container_t *a, c
}
static void belle_sip_message_init(belle_sip_message_t *message){
belle_sip_object_init_type(message,belle_sip_message_t);
belle_sip_object_init((belle_sip_object_t*)message);
}
headers_container_t* belle_sip_headers_container_get(belle_sip_message_t* message,const char* header_name) {
......@@ -50,11 +51,11 @@ headers_container_t* belle_sip_headers_container_get(belle_sip_message_t* messag
, header_name);
return result?(headers_container_t*)(result->data):NULL;
}
void belle_sip_message_header_add(belle_sip_message_t *message,belle_sip_object_t* header) {
void belle_sip_message_add_header(belle_sip_message_t *message,belle_sip_header_t* header) {
// first check if already exist
headers_container_t* headers_container = belle_sip_headers_container_get(message,belle_sip_object_get_name(header));
headers_container_t* headers_container = belle_sip_headers_container_get(message,belle_sip_header_get_name(header));
if (headers_container == NULL) {
headers_container = belle_sip_message_headers_container_new(belle_sip_object_get_name(header));
headers_container = belle_sip_message_headers_container_new(belle_sip_header_get_name(header));
belle_sip_list_append(message->header_list,headers_container);
}
belle_sip_list_append(headers_container->header_list,header);
......@@ -66,20 +67,20 @@ const belle_sip_list_t* belle_sip_message_get_headers(belle_sip_message_t *messa
}
struct _belle_sip_request {
belle_sip_message_t message;
const char* method;
};
static void belle_sip_request_destroy(belle_sip_request_t* request) {
if (request->method) belle_sip_free((void*)(request->method));
}
BELLE_SIP_NEW(request,message)
BELLE_SIP_PARSE(request)
GET_SET_STRING(belle_sip_request,method);
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;
}
......
/*
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/>.
*/
#include "belle-sip/belle-sip.h"
#include <stdio.h>
#include "CUnit/Basic.h"
static int init_suite_message(void) {
return 0;
}
static int clean_suite_message(void) {
return 0;
}
static void testMessage(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\n\r"\
"Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\n\r"\
"From: <sip:jehan-mac@sip.linphone.org>;tag=465687829\n\r"\
"To: <sip:jehan-mac@sip.linphone.org>\n\rCall-ID: 1053183492\n\r"\
"CSeq: 1 REGISTER\n\r"\
"Contact: <sip:jehan-mac@192.168.1.8:5062>\n\r"\
"Max-Forwards: 70\n\r"\
"User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\n\r"
"Expires: 3600\n\r"\
"Content-Length: 0\n\r\n\r";
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER");
}
int belle_sip_message_test_suite () {
CU_pSuite pSuite = NULL;
/* add a suite to the registry */
pSuite = CU_add_suite("message suite", init_suite_message, clean_suite_message);
if (NULL == pSuite) {
return CU_get_error();
}
/* add the tests to the suite */
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
if ((NULL == CU_add_test(pSuite, "test of simple messgae", testMessage))
)
{
return CU_get_error();
}
return CU_get_error();
}
......@@ -32,6 +32,7 @@ int main (int argc, char *argv[]) {
belle_sip_headers_test_suite ();
belle_sip_message_test_suite();
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_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