Commit a911e438 authored by jehan's avatar jehan
Browse files

Merge branch 'master' of git.linphone.org:belle-sip

parents b5c38504 587cac86
......@@ -135,6 +135,13 @@ void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, con
char* belle_sip_object_to_string(belle_sip_object_t* obj);
unsigned int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t id);
void *belle_sip_malloc(size_t size);
void *belle_sip_malloc0(size_t size);
void *belle_sip_realloc(void *ptr, size_t size);
void belle_sip_free(void *ptr);
char * belle_sip_strdup(const char *s);
BELLE_SIP_END_DECLS
#define BELLE_SIP_CAST(obj,_type) ((_type*)belle_sip_object_cast((belle_sip_object_t *)(obj), _type##_id, #_type, __FILE__, __LINE__))
......
......@@ -25,6 +25,7 @@ typedef struct belle_sip_server_transaction belle_sip_server_transaction_t;
typedef struct belle_sip_client_transaction belle_sip_client_transaction_t;
typedef enum belle_sip_transaction_state{
BELLE_SIP_TRANSACTION_INIT,
BELLE_SIP_TRANSACTION_CALLING,
BELLE_SIP_TRANSACTION_COMPLETED,
BELLE_SIP_TRANSACTION_CONFIRMED,
......
ANTLR=antlr3
grammar_files= \
$(srcdir)/belle_sip_uri.g \
$(srcdir)/belle_sip_message.g
$(srcdir)/belle_sdp.g
generated_src= \
belle_sip_uriParser.c belle_sip_uriParser.h \
......
......@@ -134,11 +134,7 @@ void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t fun
extern "C"{
#endif
void *belle_sip_malloc(size_t size);
void *belle_sip_malloc0(size_t size);
void *belle_sip_realloc(void *ptr, size_t size);
void belle_sip_free(void *ptr);
char * belle_sip_strdup(const char *s);
#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
......@@ -520,7 +516,7 @@ void belle_sip_response_get_return_hop(belle_sip_response_t *msg, belle_sip_hop_
#define IS_TOKEN(token) \
(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
strcmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
char* _belle_sip_str_dup_and_unquote_string(char* quoted_string);
char* _belle_sip_str_dup_and_unquote_string(const char* quoted_string);
/*********************************************************
* SDP
......
......@@ -253,7 +253,9 @@ void belle_sip_main_loop_run(belle_sip_main_loop_t *ml){
void belle_sip_main_loop_quit(belle_sip_main_loop_t *ml){
ml->run=0;
write(ml->control_fds[1],"a",1);
if (write(ml->control_fds[1],"a",1)==-1){
belle_sip_error("Fail to write to main loop control fd.");
}
}
void belle_sip_main_loop_sleep(belle_sip_main_loop_t *ml, int milliseconds){
......
......@@ -132,8 +132,8 @@ scope { belle_sip_response_t* current; }
status_line
: 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);}
LWS status_code {belle_sip_response_set_status_code($response::current,atoi((char*)$status_code.text->chars));}
LWS reason_phrase {belle_sip_response_set_reason_phrase($response::current,(char*)$reason_phrase.text->chars);}
CRLF ;
status_code
......@@ -238,39 +238,39 @@ dig_resp [belle_sip_header_authorization_t* header_authorization_base]
: username { belle_sip_header_authorization_set_username(header_authorization_base,$username.ret);
belle_sip_free($username.ret);
}
| realm { belle_sip_header_authorization_set_realm(header_authorization_base,$realm.ret);
| realm { belle_sip_header_authorization_set_realm(header_authorization_base,(char*)$realm.ret);
belle_sip_free($realm.ret);
}
| nonce { belle_sip_header_authorization_set_nonce(header_authorization_base,$nonce.ret);
| nonce { belle_sip_header_authorization_set_nonce(header_authorization_base,(char*)$nonce.ret);
belle_sip_free($nonce.ret);
}
| digest_uri[header_authorization_base]
| dresponse { belle_sip_header_authorization_set_response(header_authorization_base,$dresponse.ret);
| dresponse { belle_sip_header_authorization_set_response(header_authorization_base,(char*)$dresponse.ret);
belle_sip_free($dresponse.ret);
}
| algorithm {
belle_sip_header_authorization_set_algorithm(header_authorization_base,$algorithm.ret);
belle_sip_header_authorization_set_algorithm(header_authorization_base,(char*)$algorithm.ret);
}
| cnonce{
belle_sip_header_authorization_set_cnonce(header_authorization_base,$cnonce.ret);
belle_sip_header_authorization_set_cnonce(header_authorization_base,(char*)$cnonce.ret);
belle_sip_free($cnonce.ret);
}
| opaque {
belle_sip_header_authorization_set_opaque(header_authorization_base,$opaque.ret);
belle_sip_header_authorization_set_opaque(header_authorization_base,(char*)$opaque.ret);
belle_sip_free($opaque.ret);
}
| message_qop{
belle_sip_header_authorization_set_qop(header_authorization_base,$message_qop.ret);
belle_sip_header_authorization_set_qop(header_authorization_base,(char*)$message_qop.ret);
}
| nonce_count{
belle_sip_header_authorization_set_nonce_count(header_authorization_base,atoi($nonce_count.ret));
belle_sip_header_authorization_set_nonce_count(header_authorization_base,atoi((char*)$nonce_count.ret));
}
| auth_param[header_authorization_base]
;
username_token: {IS_TOKEN(username)}? token;
username returns [char* ret]
: username_token /*'username'*/ equal username_value {
$ret = _belle_sip_str_dup_and_unquote_string($username_value.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$username_value.text->chars);
};
username_value : quoted_string;
......@@ -295,17 +295,17 @@ qop_value
cnonce returns [char* ret]
: {IS_TOKEN(cnonce)}? token /*'cnonce'*/ equal cnonce_value {
$ret = _belle_sip_str_dup_and_unquote_string($cnonce_value.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$cnonce_value.text->chars);
};
cnonce_value
: nonce_value;
nonce_count returns [const char* ret]
: {IS_TOKEN(nc)}? token /*'nc'*/ equal nc_value {$ret=$nc_value.text->chars;};
: {IS_TOKEN(nc)}? token /*'nc'*/ equal nc_value {$ret=(char*)$nc_value.text->chars;};
nc_value
: huit_lhex;
dresponse returns [char* ret]
: {IS_TOKEN(response)}? token /*'response'*/ equal request_digest{
$ret = _belle_sip_str_dup_and_unquote_string($request_digest.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$request_digest.text->chars);
};
request_digest
: quoted_string ;/*sp_laquot_sp huit_lhex huit_lhex huit_lhex huit_lhex sp_raquot_sp;
......@@ -316,8 +316,8 @@ huit_lhex
auth_param [belle_sip_header_authorization_t* header_authorization_base]
: auth_param_name equal
auth_param_value {belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(header_authorization_base)
,$auth_param_name.text->chars
,$auth_param_value.text->chars);
,(char*)$auth_param_name.text->chars
,(char*)$auth_param_value.text->chars);
}
;
auth_param_value : token | quoted_string ;
......@@ -380,8 +380,8 @@ contact_param
$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));
belle_sip_header_set_next(BELLE_SIP_HEADER($header_contact::current),(belle_sip_header_t*)belle_sip_header_contact_new());
$header_contact::current = (belle_sip_header_contact_t*)belle_sip_header_get_next(BELLE_SIP_HEADER($header_contact::current));
}
}
: (name_addr[BELLE_SIP_HEADER_ADDRESS($header_contact::current)]
......@@ -580,14 +580,14 @@ challenge [belle_sip_header_www_authenticate_t* www_authenticate]
LWS digest_cln[www_authenticate] (comma digest_cln[www_authenticate])*)
| other_challenge [www_authenticate];
other_challenge [belle_sip_header_www_authenticate_t* www_authenticate]
: auth_scheme {belle_sip_header_www_authenticate_set_scheme(www_authenticate,$auth_scheme.text->chars);}
: auth_scheme {belle_sip_header_www_authenticate_set_scheme(www_authenticate,(char*)$auth_scheme.text->chars);}
LWS auth_param[NULL]
(comma auth_param[NULL])*;
digest_cln [belle_sip_header_www_authenticate_t* www_authenticate]
:
| realm {belle_sip_header_www_authenticate_set_realm(www_authenticate,$realm.ret);
| realm {belle_sip_header_www_authenticate_set_realm(www_authenticate,(char*)$realm.ret);
belle_sip_free($realm.ret);}
| nonce {belle_sip_header_www_authenticate_set_nonce(www_authenticate,$nonce.ret);
| nonce {belle_sip_header_www_authenticate_set_nonce(www_authenticate,(char*)$nonce.ret);
belle_sip_free($nonce.ret);}
| algorithm {belle_sip_header_www_authenticate_set_algorithm(www_authenticate,$algorithm.ret);}
| opaque {belle_sip_header_www_authenticate_set_opaque(www_authenticate,$opaque.ret);
......@@ -600,18 +600,19 @@ digest_cln [belle_sip_header_www_authenticate_t* www_authenticate]
belle_sip_header_www_authenticate_set_stale(www_authenticate,1);
}
}
| auth_param[www_authenticate];
| auth_param[(belle_sip_header_authorization_t*)www_authenticate];
/* the cast above is very BAD, but auth_param works on fields common to the two structures*/
realm returns [char* ret]
: {IS_TOKEN(realm)}? token /*'realm'*/ equal realm_value {
$ret = _belle_sip_str_dup_and_unquote_string($realm_value.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$realm_value.text->chars);
};
realm_value
: quoted_string ;
domain returns [char* ret]
: {IS_TOKEN(domain)}? token /*'domain'*/ equal quoted_string {
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);};
$ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);};
/* LDQUOT uri
( SP+ uri )* RDQUOT;
uri
......@@ -619,26 +620,26 @@ uri
*/
nonce returns [char* ret]
: {IS_TOKEN(nonce)}? token /*'nonce'*/ equal nonce_value{
$ret = _belle_sip_str_dup_and_unquote_string($nonce_value.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$nonce_value.text->chars);
};
opaque returns [char* ret]
: {IS_TOKEN(opaque)}? token /*'opaque'*/ equal quoted_string{
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);
};
stale returns [const char* ret]
: {IS_TOKEN(stale)}? token /*'stale'*/ equal stale_value {$ret=$stale_value.text->chars;} /* ( 'true' | 'false' )*/;
: {IS_TOKEN(stale)}? token /*'stale'*/ equal stale_value {$ret=(char*)$stale_value.text->chars;} /* ( 'true' | 'false' )*/;
stale_value:token;
algorithm returns [const char* ret]
: {IS_TOKEN(algorithm)}? token /*'algorithm'*/ equal /* ( 'MD5' | 'MD5-sess'
|*/ alg_value=token {$ret=$alg_value.text->chars;}/*)*/
|*/ alg_value=token {$ret=(char*)$alg_value.text->chars;}/*)*/
;
qop_opts returns [char* ret]
: {IS_TOKEN(qop)}? token /*'qop'*/ equal quoted_string {
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);
$ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);
};/*LDQUOT qop_value
(COMMA qop_value)* RDQUOT:*/
/*qop_value
......@@ -647,7 +648,7 @@ qop_opts returns [char* ret]
header_proxy_authorization returns [belle_sip_header_proxy_authorization_t* ret]
scope { belle_sip_header_proxy_authorization_t* current; }
@init { $header_proxy_authorization::current = belle_sip_header_proxy_authorization_new();$ret = $header_proxy_authorization::current; }
: {IS_TOKEN(Proxy-Authorization)}? token /*'Proxy-Authorization'*/ hcolon credentials[$header_proxy_authorization::current];
: {IS_TOKEN(Proxy-Authorization)}? token /*'Proxy-Authorization'*/ hcolon credentials[(belle_sip_header_authorization_t*)$header_proxy_authorization::current];
/*
proxy_require
: 'Proxy-Require' HCOLON option_tag
......@@ -665,7 +666,7 @@ rec_route
$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());
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_record_route::current = belle_sip_header_record_route_new()));
}
}
: name_addr[BELLE_SIP_HEADER_ADDRESS($header_record_route::current)] ( semi rr_param )*;
......@@ -703,7 +704,7 @@ route_param
$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());
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_route::current = belle_sip_header_route_new()));
}
}
: name_addr[BELLE_SIP_HEADER_ADDRESS($header_route::current)] ( semi r_param )*;
......@@ -765,7 +766,7 @@ via_parm
$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());
belle_sip_header_set_next(header,(belle_sip_header_t*)($header_via::current = belle_sip_header_via_new()));
}
}
: sent_protocol LWS sent_by ( semi via_params )*;
......@@ -853,7 +854,7 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_max_forwards_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_extension_set_value((belle_sip_header_extension_t*)$ret,(const char*)$header_value.text->chars);
belle_sip_header_set_name($ret,(const char*)$header_name.text->chars);
}
} ;
......
......@@ -470,7 +470,7 @@ int belle_sip_param_pair_comp_func(const belle_sip_param_pair_t *a, const char*b
return strcmp(a->name,b);
}
char* _belle_sip_str_dup_and_unquote_string(char* quoted_string) {
char* _belle_sip_str_dup_and_unquote_string(const char* quoted_string) {
size_t value_size = strlen(quoted_string);
char* unquoted_string = belle_sip_malloc0(value_size-2+1);
strncpy(unquoted_string,quoted_string+1,value_size-2);
......
......@@ -94,19 +94,50 @@ struct belle_sip_server_transaction{
static void server_transaction_send_cb(belle_sip_sender_task_t *st, void *data, int retcode){
belle_sip_server_transaction_t *t=(belle_sip_server_transaction_t *)data;
if (retcode==0){
t->base.is_reliable=belle_sip_sender_task_is_reliable(st);
}else{
/*the provider is notified of the error by the sender_task, we just need to terminate the transaction*/
belle_sip_transaction_terminate(&t->base);
}
}
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t, belle_sip_response_t *resp){
static void server_transaction_send_response(belle_sip_server_transaction_t *t, belle_sip_response_t *resp){
if (t->base.stask==NULL){
t->base.stask=belle_sip_sender_task_new(t->base.provider,server_transaction_send_cb,t);
}
belle_sip_sender_task_send(t->base.stask,BELLE_SIP_MESSAGE(resp));
}
/* called when a request retransmission is received for that transaction:*/
void belle_sip_server_transaction_retransmit(belle_sip_server_transaction_t *t){
if (t->base.final_response!=NULL){
server_transaction_send_response (t,t->base.final_response);
}else if (t->base.prov_response!=NULL){
server_transaction_send_response (t,t->base.prov_response);
}
}
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t, belle_sip_response_t *resp){
int status_code=belle_sip_response_get_status_code(resp);
server_transaction_send_response(t,resp);
if (status_code<200){
if (t->base.prov_response!=NULL){
belle_sip_object_unref(t->base.prov_response);
}
t->base.prov_response=(belle_sip_response_t*)belle_sip_object_ref(resp);
t->base.state=BELLE_SIP_TRANSACTION_PROCEEDING;
}else if (status_code<300){
t->base.state=BELLE_SIP_TRANSACTION_TERMINATED;
belle_sip_transaction_terminate((belle_sip_transaction_t*)t);
}else{
t->base.state=BELLE_SIP_TRANSACTION_COMPLETED;
}
}
static void server_transaction_destroy(belle_sip_server_transaction_t *t){
}
......@@ -183,19 +214,21 @@ static void client_transaction_cb(belle_sip_sender_task_t *task, void *data, int
belle_sip_client_transaction_t *t=(belle_sip_client_transaction_t*)data;
const belle_sip_timer_config_t *tc=belle_sip_stack_get_timer_config (belle_sip_provider_get_sip_stack (t->base.provider));
if (retcode==0){
t->base.is_reliable=belle_sip_sender_task_is_reliable(task);
if (t->base.is_invite){
t->base.state=BELLE_SIP_TRANSACTION_CALLING;
}else{
t->base.state=BELLE_SIP_TRANSACTION_TRYING;
}
t->base.start_time=belle_sip_time_ms();
t->timer_F=t->base.start_time+(tc->T1*64);
if (!t->base.is_reliable){
t->base.interval=tc->T1;
t->base.timer=transaction_create_timer(&t->base,on_client_transaction_timer,tc->T1);
}else{
t->base.timer=transaction_create_timer(&t->base,on_client_transaction_timer,tc->T1*64);
if (t->base.state==BELLE_SIP_TRANSACTION_INIT){
t->base.is_reliable=belle_sip_sender_task_is_reliable(task);
if (t->base.is_invite){
t->base.state=BELLE_SIP_TRANSACTION_CALLING;
}else{
t->base.state=BELLE_SIP_TRANSACTION_TRYING;
}
t->base.start_time=belle_sip_time_ms();
t->timer_F=t->base.start_time+(tc->T1*64);
if (!t->base.is_reliable){
t->base.interval=tc->T1;
t->base.timer=transaction_create_timer(&t->base,on_client_transaction_timer,tc->T1);
}else{
t->base.timer=transaction_create_timer(&t->base,on_client_transaction_timer,tc->T1*64);
}
}
}else{
/* transport layer error*/
......
......@@ -9,7 +9,7 @@ belle_sip_tester_SOURCES= belle_sip_tester.c \
cast_test_SOURCES=cast_test.c
INCLUDES=-I$(top_srcdir)/include
INCLUDES=-I$(top_srcdir)/include -I$(top_srcdir)/src
LDADD=$(top_builddir)/src/libbellesip.la -lcunit
......
......@@ -37,23 +37,23 @@ static void check_uri_and_headers(belle_sip_message_t* message) {
BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_message_get_header(message,"Max-Forwards"));
}
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_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_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_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_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_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_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(message,"Content-Length")));
......@@ -152,9 +152,10 @@ static void testRegisterRaw(void) {
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));
CU_ASSERT_STRING_EQUAL(belle_sip_message_get_body(request),"123456789");
CU_ASSERT_STRING_EQUAL(belle_sip_message_get_body(message),"123456789");
}
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"\
......@@ -193,6 +194,10 @@ int belle_sip_message_test_suite () {
if (NULL == CU_add_test(pSuite, "test of invite message", testInviteMessage)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of options message", testOptionMessage)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of register raw message", testRegisterRaw)) {
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