Commit 43ab5a03 authored by jehan's avatar jehan

test 401 response

parent 3d0603af
......@@ -72,6 +72,7 @@
<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="&quot;${workspace_loc:/belle-sip/src}&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"/>
......@@ -99,7 +100,7 @@
</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">
<option id="gnu.c.compiler.option.include.paths.1281017285" 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"/>
......
......@@ -39,6 +39,15 @@ void belle_sip_header_init(belle_sip_header_t *header) {
static void belle_sip_header_destroy(belle_sip_header_t *header){
if (header->name) belle_sip_free((void*)header->name);
if (header->next) belle_sip_object_unref(BELLE_SIP_OBJECT(header->next));
}
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next) {
if (header->next) belle_sip_object_unref(BELLE_SIP_OBJECT(header));
header->next = next;
belle_sip_object_ref(BELLE_SIP_OBJECT(next));
}
belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* header) {
return header->next;
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_header_t,belle_sip_object_t,belle_sip_header_destroy,NULL);
......@@ -494,7 +503,7 @@ static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authe
static void belle_sip_header_www_authenticate_clone(belle_sip_header_www_authenticate_t* www_authenticate,
const belle_sip_header_www_authenticate_t *orig ) {
}
BELLE_SIP_NEW_HEADER(header_www_authenticate,parameters,"WWW-Authenticdate")
BELLE_SIP_NEW_HEADER(header_www_authenticate,parameters,"WWW-Authenticate")
BELLE_SIP_PARSE(header_www_authenticate)
GET_SET_STRING(belle_sip_header_www_authenticate,scheme);
GET_SET_STRING(belle_sip_header_www_authenticate,realm);
......
......@@ -394,9 +394,13 @@ void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t*
/*calss header*/
struct _belle_sip_header {
belle_sip_object_t base;
belle_sip_header_t* next;
const char* name;
};
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next);
belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* headers);
void belle_sip_header_init(belle_sip_header_t* obj);
/*class parameters*/
struct _belle_sip_parameters {
......
......@@ -122,11 +122,14 @@ extension_method
response returns [belle_sip_response_t* ret]
scope { belle_sip_response_t* current; }
@init {$request::current = belle_sip_response_new(); $ret=$request::current; }
: status_line message_header[BELLE_SIP_MESSAGE($request::current)]+ last_crlf=CRLF {*($message_raw::message_length)=0;} /*message_body*/ ;
@init {$response::current = belle_sip_response_new(); $ret=$response::current; }
: status_line message_header[BELLE_SIP_MESSAGE($response::current)]+ last_crlf=CRLF {*($message_raw::message_length)=0;} /*message_body*/ ;
status_line
: sip_version LWS status_code LWS reason_phrase CRLF ;
: sip_version
LWS status_code {belle_sip_response_set_status_code($response::current,atoi($status_code.text->chars));}
LWS reason_phrase {belle_sip_response_set_reason_phrase($response::current,$reason_phrase.text->chars);}
CRLF ;
status_code
: extension_code;
......@@ -361,12 +364,21 @@ info_param
contact_token: {IS_TOKEN(Contact)}? token;
header_contact returns [belle_sip_header_contact_t* ret]
scope { belle_sip_header_contact_t* current; }
@init { $header_contact::current = belle_sip_header_contact_new(); }
scope { belle_sip_header_contact_t* current; belle_sip_header_contact_t* first; }
@init { $header_contact::current =NULL; }
: (contact_token /*'Contact'*/ /*| 'm'*/ ) hcolon
( STAR { belle_sip_header_contact_set_wildcard($header_contact::current,1);}
| (contact_param (COMMA contact_param)*)) {$ret = $header_contact::current;};
contact_param
( STAR { $header_contact::current = belle_sip_header_contact_new();
belle_sip_header_contact_set_wildcard($header_contact::current,1);}
| (contact_param (comma contact_param)*)) {$ret = $header_contact::first; };
contact_param
@init { if ($header_contact::current == NULL) {
$header_contact::current = belle_sip_header_contact_new();
$header_contact::first = $header_contact::current;
} else {
belle_sip_header_set_next(BELLE_SIP_HEADER($header_contact::current),belle_sip_header_contact_new());
$header_contact::current = belle_sip_header_get_next(BELLE_SIP_HEADER($header_contact::current));
}
}
: (name_addr[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]
| addr_spec[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]) (semi contact_params)*;
......@@ -635,12 +647,17 @@ option_tag
*/
record_route_token: {IS_TOKEN(Record-Route)}? token;
header_record_route returns [belle_sip_header_record_route_t* ret]
scope { belle_sip_header_record_route_t* current; }
@init { $header_record_route::current = belle_sip_header_record_route_new();$ret = $header_record_route::current; }
: record_route_token /*'Record-Route'*/ hcolon rec_route /*(COMMA rec_route)**/;
rec_route
scope { belle_sip_header_record_route_t* current; belle_sip_header_record_route_t* first;}
@init { $header_record_route::current = NULL;}
: record_route_token /*'Record-Route'*/ hcolon rec_route (comma rec_route)* {$ret = $header_record_route::first;};
rec_route
@init { if ($header_record_route::current == NULL) {
$header_record_route::first = $header_record_route::current = belle_sip_header_record_route_new();
} else {
belle_sip_header_t* header = BELLE_SIP_HEADER($header_record_route::current);
belle_sip_header_set_next(header,$header_record_route::current = belle_sip_header_record_route_new());
}
}
: name_addr[BELLE_SIP_HEADER_ADDRESS($header_record_route::current)] ( semi rr_param )*;
rr_param
: generic_param[BELLE_SIP_PARAMETERS($header_record_route::current)];
......@@ -668,10 +685,17 @@ retry_param
*/
route_token: {IS_TOKEN(Route)}? token;
header_route returns [belle_sip_header_route_t* ret]
scope { belle_sip_header_route_t* current; }
@init { $header_route::current = belle_sip_header_route_new();$ret = $header_route::current; }
: route_token /*'Route'*/ hcolon route_param /*(COMMA rec_route)**/;
route_param
scope { belle_sip_header_route_t* current;belle_sip_header_route_t* first; }
@init { $header_route::current = NULL; }
: route_token /*'Route'*/ hcolon route_param (comma route_param)*{$ret = $header_route::first;};
route_param
@init { if ($header_route::current == NULL) {
$header_route::first = $header_route::current = belle_sip_header_route_new();
} else {
belle_sip_header_t* header = BELLE_SIP_HEADER($header_route::current);
belle_sip_header_set_next(header,$header_route::current = belle_sip_header_route_new());
}
}
: name_addr[BELLE_SIP_HEADER_ADDRESS($header_route::current)] ( semi r_param )*;
r_param
: generic_param[BELLE_SIP_PARAMETERS($header_route::current)];
......@@ -721,12 +745,19 @@ user_agent
*/
via_token: {IS_TOKEN(Via)}? token;
header_via returns [belle_sip_header_via_t* ret]
scope { belle_sip_header_via_t* current; }
@init { $header_via::current = belle_sip_header_via_new(); }
scope { belle_sip_header_via_t* current; belle_sip_header_via_t* first; }
@init { $header_via::current = NULL;}
: via_token/* ( 'via' | 'v' )*/ hcolon via_parm (COMMA via_parm)* {$ret = $header_via::current;};
via_parm
: via_token/* ( 'via' | 'v' )*/ hcolon via_parm (comma via_parm)* {$ret = $header_via::first;};
via_parm
@init { if ($header_via::current == NULL) {
$header_via::first = $header_via::current = belle_sip_header_via_new();
} else {
belle_sip_header_t* header = BELLE_SIP_HEADER($header_via::current);
belle_sip_header_set_next(header,$header_via::current = belle_sip_header_via_new());
}
}
: sent_protocol LWS sent_by ( semi via_params )*;
via_params
: /*via_ttl | via_maddr
......@@ -802,7 +833,13 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_record_route_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Via",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_via_parse((const char*)$header_extension.text->chars));
} else {
} else if (check_for_known_header && strcmp("Authorization",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_authorization_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Proxy-Authorization",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_proxy_authorization_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("WWW-Authenticate",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_www_authenticate_parse((const char*)$header_extension.text->chars));
}else {
$ret = BELLE_SIP_HEADER(belle_sip_header_extension_new());
belle_sip_header_extension_set_value($ret,(const char*)$header_value.text->chars);
belle_sip_header_set_name($ret,(const char*)$header_name.text->chars);
......
......@@ -18,6 +18,7 @@
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
#include <stdio.h>
#include "CUnit/Basic.h"
......@@ -43,7 +44,7 @@ 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:sip.linphone.org>;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, sip:titi.com");
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);
......@@ -55,6 +56,11 @@ void test_complex_header_contact(void) {
float l_qvalue = belle_sip_header_contact_get_qvalue(L_contact);
CU_ASSERT_EQUAL(l_qvalue,0.7);
belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_contact));
belle_sip_header_contact_t* L_next_contact = BELLE_SIP_HEADER_CONTACT(l_next);
CU_ASSERT_PTR_NOT_NULL(L_next_contact);
CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_contact)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
L_contact = belle_sip_header_contact_parse("Contact: toto <sip:titi.com>;expires=3600; q=0.7");
......@@ -97,6 +103,15 @@ void test_header_via(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_received(L_via),"192.169.0.4");
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_branch(L_via),"z9hG4bK368560724");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;rport;received=192.169.0.4;branch=z9hG4bK368560724, SIP/2.0/UDP 192.168.0.19:5062");
belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_via));
belle_sip_header_via_t* L_next_via = BELLE_SIP_HEADER_VIA(l_next);
CU_ASSERT_PTR_NOT_NULL(L_next_via);
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_next_via),"192.168.0.19");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
}
void test_header_call_id(void) {
......@@ -136,6 +151,13 @@ void test_header_record_route(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "212.27.52.5");
CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_record_route),"charset"),"ISO-8859-4");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
L_record_route = belle_sip_header_record_route_parse("Record-Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:212.27.52.5:5060;transport=udp;lr>");
belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_record_route));
belle_sip_header_record_route_t* L_next_route = BELLE_SIP_HEADER_RECORD_ROUTE(l_next);
CU_ASSERT_PTR_NOT_NULL(L_next_route);
CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_record_route));
}
void test_header_route(void) {
......@@ -145,6 +167,13 @@ void test_header_route(void) {
CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060);
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));
L_route = belle_sip_header_route_parse("Route: <sip:212.27.52.5:5060;transport=udp;lr>;charset=ISO-8859-4, <sip:titi.com>");
belle_sip_header_t* l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_route));
belle_sip_header_route_t* L_next_route = BELLE_SIP_HEADER_ROUTE(l_next);
CU_ASSERT_PTR_NOT_NULL(L_next_route);
CU_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_route)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
}
void test_header_content_length(void) {
......
......@@ -30,8 +30,9 @@ 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)));
if (belle_sip_message_is_request(message)) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(BELLE_SIP_REQUEST(message)));
}
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"From"));
BELLE_SIP_HEADER_FROM(belle_sip_message_get_header(message,"From"));
......@@ -51,8 +52,7 @@ static void check_uri_and_headers(belle_sip_message_t* message) {
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) {
......@@ -66,11 +66,16 @@ static void testRegisterMessage(void) {
"Max-Forwards: 70\r\n"\
"User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\r\n"\
"Expires: 3600\r\n"\
"Proxy-Authorization: Digest username=\"8117396\", realm=\"Realm\", nonce=\"MTMwNDAwMjIxMjA4NzVkODY4ZmZhODMzMzU4ZDJkOTA1NzM2NTQ2NDZlNmIz"\
", uri=\"sip:linphone.net\", response=\"eed376ff7c963441255ec66594e470e7\", algorithm=MD5, cnonce=\"0a4f113b\", qop=auth, nc=00000001\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_message_get_header(message,"Expires"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Proxy-Authorization"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
check_uri_and_headers(message);
}
......@@ -86,11 +91,31 @@ static void testInviteMessage(void) {
"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n"\
"Content-Type: application/sdp\r\n"\
"Supported: replaces\r\n"\
"Authorization: Digest username=\"003332176\", realm=\"sip.ovh.net\", nonce=\"24212965507cde726e8bc37e04686459\", uri=\"sip:sip.ovh.net\", response=\"896e786e9c0525ca3085322c7f1bce7b\", algorithm=MD5, opaque=\"241b9fb347752f2\"\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");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Authorization"));
check_uri_and_headers(message);
}
static void test401Response(void) {
const char* raw_message = "SIP/2.0 401 Unauthorized\r\n"
"Call-ID: 577586163\r\n"
"CSeq: 21 REGISTER\r\n"
"From: <sip:0033532176@sip.ovh.net>;tag=1790643209\r\n"
"Server: Cirpack/v4.42x (gw_sip)\r\n"
"To: <sip:0033482176@sip.ovh.net>;tag=00-08075-24212984-22e348d97\r\n"
"Via: SIP/2.0/UDP 192.168.0.18:5062;received=81.56.113.2;rport=5062;branch=z9hG4bK1939354046\r\n"
"WWW-Authenticate: Digest realm=\"sip.ovh.net\",nonce=\"24212965507cde726e8bc37e04686459\",opaque=\"241b9fb347752f2\",stale=false,algorithm=MD5\r\n"
"Content-Length: 0\r\n\r\n";
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
belle_sip_response_t* response = BELLE_SIP_RESPONSE(message);
CU_ASSERT_EQUAL(belle_sip_response_get_status_code(response),401);
CU_ASSERT_STRING_EQUAL(belle_sip_response_get_reason_phrase(response),"Unauthorized");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"WWW-Authenticate"));
check_uri_and_headers(message);
}
static void testRegisterRaw(void) {
......@@ -154,6 +179,10 @@ int belle_sip_message_test_suite () {
if (NULL == CU_add_test(pSuite, "test of register raw message", testRegisterRaw)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of 401 response", test401Response)) {
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