Commit 1884e97a authored by jehan's avatar jehan

test basic invite + basic register

parent bb3fbc74
......@@ -64,6 +64,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_header_record_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_length_t),
BELLE_SIP_TYPE_ID(belle_sip_header_t),
BELLE_SIP_TYPE_ID(belle_sip_header_extension_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......
......@@ -250,4 +250,17 @@ unsigned int belle_sip_header_content_length_get_content_length(const belle_sip_
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)
/******************************
* Extension header hinerite from header
*
******************************/
typedef struct _belle_sip_header_extension belle_sip_header_extension_t;
belle_sip_header_extension_t* belle_sip_header_extension_new();
belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* extension) ;
const char* belle_sip_header_extension_length_get_value(const belle_sip_header_extension_t* extension);
void belle_sip_header_extension_length_set_value(belle_sip_header_extension_t* extension,const char* value);
#define BELLE_SIP_HEADER_EXTENSION(t) BELLE_SIP_CAST(t,belle_sip_header_extension_t)
#endif /* HEADERS_H_ */
......@@ -98,7 +98,7 @@ void belle_sip_header_contact_destroy(belle_sip_header_contact_t* contact) {
void belle_sip_header_contact_clone(belle_sip_header_contact_t *contact, const belle_sip_header_contact_t *orig){
}
BELLE_SIP_NEW_WITH_NAME(header_contact,header_address,"Contact")
BELLE_SIP_NEW_HEADER(header_contact,header_address,"Contact")
BELLE_SIP_PARSE(header_contact)
GET_SET_INT_PARAM_PRIVATE(belle_sip_header_contact,expires,int,_)
......@@ -140,7 +140,7 @@ static void belle_sip_header_from_clone(belle_sip_header_from_t* from, const bel
}
BELLE_SIP_NEW_WITH_NAME(header_from,header_address,"From")
BELLE_SIP_NEW_HEADER(header_from,header_address,"From")
BELLE_SIP_PARSE(header_from)
GET_SET_STRING_PARAM(belle_sip_header_from,tag);
......@@ -158,7 +158,7 @@ static void belle_sip_header_to_destroy(belle_sip_header_to_t* to) {
void belle_sip_header_to_clone(belle_sip_header_to_t *contact, const belle_sip_header_to_t *orig){
}
BELLE_SIP_NEW_WITH_NAME(header_to,header_address,"To")
BELLE_SIP_NEW_HEADER(header_to,header_address,"To")
BELLE_SIP_PARSE(header_to)
GET_SET_STRING_PARAM(belle_sip_header_to,tag);
......@@ -182,7 +182,7 @@ static void belle_sip_header_via_destroy(belle_sip_header_via_t* via) {
static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_sip_header_via_t*orig){
}
BELLE_SIP_NEW_WITH_NAME(header_via,header_address,"Via")
BELLE_SIP_NEW_HEADER(header_via,header_address,"Via")
BELLE_SIP_PARSE(header_via)
GET_SET_STRING(belle_sip_header_via,protocol);
GET_SET_STRING(belle_sip_header_via,transport);
......@@ -236,7 +236,7 @@ int belle_sip_header_via_get_listening_port(const belle_sip_header_via_t *via){
****************************
*/
struct _belle_sip_header_call_id {
belle_sip_object_t base;
belle_sip_header_t header;
const char* call_id;
};
......@@ -247,7 +247,7 @@ static void belle_sip_header_call_id_destroy(belle_sip_header_call_id_t* call_id
static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,const belle_sip_header_call_id_t *orig){
}
BELLE_SIP_NEW_WITH_NAME(header_call_id,header,"Call-ID")
BELLE_SIP_NEW_HEADER(header_call_id,header,"Call-ID")
BELLE_SIP_PARSE(header_call_id)
GET_SET_STRING(belle_sip_header_call_id,call_id);
/**************************
......@@ -255,7 +255,7 @@ GET_SET_STRING(belle_sip_header_call_id,call_id);
****************************
*/
struct _belle_sip_header_cseq {
belle_sip_object_t base;
belle_sip_header_t header;
const char* method;
unsigned int seq_number;
};
......@@ -268,7 +268,7 @@ static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const bel
if (cseq->method) belle_sip_free((void*)cseq->method);
}
BELLE_SIP_NEW_WITH_NAME(header_cseq,header,"Cseq")
BELLE_SIP_NEW_HEADER(header_cseq,header,"CSeq")
BELLE_SIP_PARSE(header_cseq)
GET_SET_STRING(belle_sip_header_cseq,method);
GET_SET_INT(belle_sip_header_cseq,seq_number,unsigned int)
......@@ -290,7 +290,7 @@ static void belle_sip_header_content_type_destroy(belle_sip_header_content_type_
static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t* content_type, const belle_sip_header_content_type_t* orig){
}
BELLE_SIP_NEW_WITH_NAME(header_content_type,parameters,"Content-Type")
BELLE_SIP_NEW_HEADER(header_content_type,parameters,"Content-Type")
BELLE_SIP_PARSE(header_content_type)
GET_SET_STRING(belle_sip_header_content_type,type);
GET_SET_STRING(belle_sip_header_content_type,subtype);
......@@ -308,7 +308,7 @@ static void belle_sip_header_route_destroy(belle_sip_header_route_t* route) {
static void belle_sip_header_route_clone(belle_sip_header_route_t* route, const belle_sip_header_route_t* orig) {
}
BELLE_SIP_NEW_WITH_NAME(header_route,header_address,"Route")
BELLE_SIP_NEW_HEADER(header_route,header_address,"Route")
BELLE_SIP_PARSE(header_route)
/**************************
* Record route header object inherent from header_address
......@@ -325,14 +325,14 @@ static void belle_sip_header_record_route_clone(belle_sip_header_record_route_t*
const belle_sip_header_record_route_t* orig ) {
}
BELLE_SIP_NEW_WITH_NAME(header_record_route,header_address,"Record-Route")
BELLE_SIP_NEW_HEADER(header_record_route,header_address,"Record-Route")
BELLE_SIP_PARSE(header_record_route)
/**************************
* content length header object inherent from object
****************************
*/
struct _belle_sip_header_content_length {
belle_sip_object_t base;
belle_sip_header_t header;
unsigned int content_length;
};
......@@ -344,6 +344,49 @@ static void belle_sip_header_content_length_clone(belle_sip_header_content_lengt
}
BELLE_SIP_NEW_WITH_NAME(header_content_length,header,"Content-Length")
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
/******************************
* Extension header hinerite from header
*
******************************/
struct _belle_sip_header_extension {
belle_sip_header_t header;
const char* value;
};
static void belle_sip_header_extension_destroy(belle_sip_header_extension_t* extension) {
if (extension->value) belle_sip_free((void*)extension->value);
}
static void belle_sip_header_extension_clone(belle_sip_header_extension_t* extension, const belle_sip_header_extension_t* orig){
}
BELLE_SIP_NEW_HEADER(header_extension,header,NULL)
/**
* special case for this header. I don't know why
*/
belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* value) {
pANTLR3_INPUT_STREAM input;
pbelle_sip_messageLexer lex;
pANTLR3_COMMON_TOKEN_STREAM tokens;
pbelle_sip_messageParser parser;
input = antlr3NewAsciiStringCopyStream (
(pANTLR3_UINT8)value,
(ANTLR3_UINT32)strlen(value),
((void *)0));
lex = belle_sip_messageLexerNew (input);
tokens = antlr3CommonTokenStreamSourceNew (1025, lex->pLexer->rec->state->tokSource);
parser = belle_sip_messageParserNew (tokens);
belle_sip_messageParser_header_extension_return l_parsed_object = parser->header_extension(parser,FALSE);
parser ->free(parser);
tokens ->free(tokens);
lex ->free(lex);
input ->close(input);
if (l_parsed_object.ret == NULL) belle_sip_error("Parser error for [%s]",value);\
return BELLE_SIP_HEADER_EXTENSION(l_parsed_object.ret);
}
GET_SET_STRING(belle_sip_header_extension,value);
......@@ -357,17 +357,18 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
tokens ->free(tokens);\
lex ->free(lex);\
input ->close(input);\
if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
return l_parsed_object;\
}
#define BELLE_SIP_NEW(object_type,super_type) BELLE_SIP_NEW_WITH_NAME(object_type,super_type,NULL)
#define BELLE_SIP_NEW(object_type,super_type) BELLE_SIP_NEW_HEADER(object_type,super_type,NULL)
#define BELLE_SIP_NEW_WITH_NAME(object_type,super_type,name) \
#define BELLE_SIP_NEW_HEADER(object_type,super_type,name) \
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_##object_type##_t,belle_sip_##super_type##_t , belle_sip_##object_type##_destroy, belle_sip_##object_type##_clone); \
belle_sip_##object_type##_t* belle_sip_##object_type##_new () { \
belle_sip_##object_type##_t* l_object = belle_sip_object_new(belle_sip_##object_type##_t);\
belle_sip_##super_type##_init((belle_sip_##super_type##_t*)l_object); \
belle_sip_object_set_name(BELLE_SIP_OBJECT(l_object),name);\
if (name) belle_sip_header_set_name(BELLE_SIP_HEADER(l_object),name);\
return l_object;\
}
typedef struct belle_sip_param_pair_t {
......
This diff is collapsed.
......@@ -59,7 +59,7 @@ void belle_sip_uri_destroy(belle_sip_uri_t* uri) {
BELLE_SIP_PARSE(uri);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_uri_t,belle_sip_object_t,belle_sip_uri_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_uri_t,belle_sip_parameters_t,belle_sip_uri_destroy,NULL);
belle_sip_uri_t* belle_sip_uri_new () {
......
......@@ -28,7 +28,7 @@ typedef struct _headers_container {
static headers_container_t* belle_sip_message_headers_container_new(const char* name) {
headers_container_t* headers_container = belle_sip_new0(headers_container_t);
headers_container->name= belle_sip_strdup(name);
return NULL; /*FIXME*/
return headers_container;
}
static void belle_sip_headers_container_delete(headers_container_t *obj){
......@@ -70,14 +70,14 @@ headers_container_t * get_or_create_container(belle_sip_message_t *message, cons
headers_container_t* headers_container = belle_sip_headers_container_get(message,header_name);
if (headers_container == NULL) {
headers_container = belle_sip_message_headers_container_new(header_name);
belle_sip_list_append(message->header_list,headers_container);
message->header_list=belle_sip_list_append(message->header_list,headers_container);
}
return headers_container;
}
void belle_sip_message_add_header(belle_sip_message_t *message,belle_sip_header_t* header) {
headers_container_t *headers_container=get_or_create_container(message,belle_sip_header_get_name(header));
belle_sip_list_append(headers_container->header_list,belle_sip_object_ref(header));
headers_container->header_list=belle_sip_list_append(headers_container->header_list,belle_sip_object_ref(header));
}
void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip_list_t *header_list){
......@@ -89,7 +89,7 @@ void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip
belle_sip_fatal("Bad use of belle_sip_message_add_headers(): all headers of the list must be of the same type.");
return ;
}
belle_sip_list_append(headers_container->header_list,belle_sip_object_ref(h));
headers_container->header_list=belle_sip_list_append(headers_container->header_list,belle_sip_object_ref(h));
}
}
......@@ -101,6 +101,7 @@ 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;
belle_sip_uri_t* uri;
};
static void belle_sip_request_destroy(belle_sip_request_t* request) {
......@@ -116,11 +117,14 @@ 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) {
if (request->uri) {
belle_sip_object_unref(request->uri);
}
request->uri=BELLE_SIP_URI(belle_sip_object_ref(uri));
}
belle_sip_uri_t * belle_sip_request_get_uri(belle_sip_request_t *request){
return NULL;
return request->uri;
}
int belle_sip_message_is_request(belle_sip_message_t *msg){
......
......@@ -43,11 +43,11 @@ void test_simple_header_contact(void) {
void test_complex_header_contact(void) {
belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: \"jremis\" <sip:titi.com>;expires=3600;q=0.7");
belle_sip_header_contact_t* L_contact = belle_sip_header_contact_parse("Contact: \"jremis\" <sip:sip.linphone.org>;expires=3600;q=0.7");
belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)L_contact);
CU_ASSERT_PTR_NOT_NULL(L_uri);
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org");
CU_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "jremis");
......@@ -118,6 +118,15 @@ void test_header_content_type(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"html");
CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_content_type),"charset"),"ISO-8859-4");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
L_content_type = belle_sip_header_content_type_parse("Content-Type: application/sdp");
CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_type(L_content_type),"application");
CU_ASSERT_STRING_EQUAL(belle_sip_header_content_type_get_subtype(L_content_type),"sdp");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
L_content_type = belle_sip_header_content_type_parse("Content-Type: application/pkcs7-mime; smime-type=enveloped-data; \r\n name=smime.p7m");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_content_type));
}
void test_header_record_route(void) {
......
......@@ -29,8 +29,33 @@ static int clean_suite_message(void) {
}
static void check_uri_and_headers(belle_sip_message_t* message) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(BELLE_SIP_REQUEST(message)));
static void testMessage(void) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"From"));
BELLE_SIP_HEADER_FROM(belle_sip_message_get_header(message,"From"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"To"));
BELLE_SIP_HEADER_TO(belle_sip_message_get_header(message,"To"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"CSeq"));
BELLE_SIP_HEADER_CSEQ(belle_sip_message_get_header(message,"CSeq"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Via"));
BELLE_SIP_HEADER_VIA(belle_sip_message_get_header(message,"Via"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Call-ID"));
BELLE_SIP_HEADER_CALL_ID(belle_sip_message_get_header(message,"Call-ID"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Content-Length"));
BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(message,"Content-Length"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
BELLE_SIP_HEADER_CONTACT(belle_sip_message_get_header(message,"Contact"));
}
static void testRegisterMessage(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\
"From: <sip:jehan-mac@sip.linphone.org>;tag=465687829\r\n"\
......@@ -45,8 +70,63 @@ static void testMessage(void) {
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");
}
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Expires"));
check_uri_and_headers(message);
}
static void testInviteMessage(void) {
const char* raw_message = "INVITE sip:becheong@sip.linphone.org SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 10.23.17.117:22600;branch=z9hG4bK-d8754z-4d7620d2feccbfac-1---d8754z-;rport=4820;received=202.165.193.129\r\n"\
"Max-Forwards: 70\r\n"\
"Contact: <sip:bcheong@202.165.193.129:4820>\r\n"\
"To: \"becheong\" <sip:becheong@sip.linphone.org>\r\n"\
"From: \"Benjamin Cheong\" <sip:bcheong@sip.linphone.org>;tag=7326e5f6\r\n"\
"Call-ID: Y2NlNzg0ODc0ZGIxODU1MWI5MzhkNDVkNDZhOTQ4YWU.\r\n"\
"CSeq: 1 INVITE\r\n"\
"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n"\
"Content-Type: application/sdp\r\n"\
"Supported: replaces\r\n"\
"User-Agent: X-Lite 4 release 4.0 stamp 58832\r\n"\
"Content-Length: 230\r\n\r\n";
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),"INVITE");
check_uri_and_headers(message);
}
static void testByeMessage(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\
"From: <sip:jehan-mac@sip.linphone.org>;tag=465687829\r\n"\
"To: <sip:jehan-mac@sip.linphone.org>\r\n"\
"Call-ID: 1053183492\r\n"\
"CSeq: 1 REGISTER\r\n"\
"Contact: <sip:jehan-mac@192.168.1.8:5062>\r\n"\
"Max-Forwards: 70\r\n"\
"User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\r\n"\
"Expires: 3600\r\n"\
"Content-Length: 0\r\n\r\n";
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");
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(request));
}
static void testOptionMessage(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\
"From: <sip:jehan-mac@sip.linphone.org>;tag=465687829\r\n"\
"To: <sip:jehan-mac@sip.linphone.org>\r\n"\
"Call-ID: 1053183492\r\n"\
"CSeq: 1 REGISTER\r\n"\
"Contact: <sip:jehan-mac@192.168.1.8:5062>\r\n"\
"Max-Forwards: 70\r\n"\
"User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\r\n"\
"Expires: 3600\r\n"\
"Content-Length: 0\r\n\r\n";
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");
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(request));
}
int belle_sip_message_test_suite () {
......@@ -62,11 +142,13 @@ int belle_sip_message_test_suite () {
/* 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))
)
{
if (NULL == CU_add_test(pSuite, "test of register message", testRegisterMessage)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of invite message", testInviteMessage)) {
return CU_get_error();
}
return CU_get_error();
}
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