Commit a6a62138 authored by jehan's avatar jehan
Browse files

some fixes around dialogs

parent 0d432ae3
......@@ -97,7 +97,7 @@ void belle_sip_main_loop_sleep(belle_sip_main_loop_t *ml, int milliseconds);
/**
* Break out the main loop.
**/
void belle_sip_main_loop_quit(belle_sip_main_loop_t *ml);
int belle_sip_main_loop_quit(belle_sip_main_loop_t *ml);
/**
* Cancel (removes) a source. It is not freed.
......
......@@ -282,14 +282,17 @@ void belle_sip_main_loop_run(belle_sip_main_loop_t *ml){
}
}
void belle_sip_main_loop_quit(belle_sip_main_loop_t *ml){
int belle_sip_main_loop_quit(belle_sip_main_loop_t *ml){
ml->run=0;
//if (write(ml->control_fds[1],"a",1)==-1){
// belle_sip_error("Fail to write to main loop control fd.");
//}
return 0;
}
void belle_sip_main_loop_sleep(belle_sip_main_loop_t *ml, int milliseconds){
belle_sip_main_loop_add_timeout(ml,(belle_sip_source_func_t)belle_sip_main_loop_quit,ml,milliseconds);
unsigned long timer_id = belle_sip_main_loop_add_timeout(ml,(belle_sip_source_func_t)belle_sip_main_loop_quit,ml,milliseconds);
belle_sip_main_loop_run(ml);
belle_sip_main_loop_cancel_source(ml,timer_id);
}
......@@ -244,7 +244,7 @@ int belle_sip_dialog_update(belle_sip_dialog_t *obj,belle_sip_request_t *req, be
obj->remote_target=(belle_sip_header_address_t*)belle_sip_object_ref(ct);
}
obj->needs_ack=TRUE;
}else if (strcmp(belle_sip_request_get_method(req),"INVITE")==0 && code>=200 && code<300){
}else if (strcmp(belle_sip_request_get_method(req),"BYE")==0 && code>=200 && code<300){
if (obj->terminate_on_bye) belle_sip_dialog_delete(obj);
}
break;
......
......@@ -84,10 +84,11 @@ static void belle_sip_provider_dispatch_request(belle_sip_provider_t* prov, bell
belle_sip_object_unref(t);
}else{
ev.dialog=NULL;
/* Should we limit to ACK ? if (strcmp("ACK",belle_sip_request_get_method(req))==0) */
/* Should we limit to ACK ? */
/*Search for a dialog if exist */
ev.dialog=belle_sip_provider_find_dialog(prov,req,1/*request=uas*/);
ev.dialog=belle_sip_provider_find_dialog(prov,req,1/*request=uas*/);
if (strcmp("ACK",belle_sip_request_get_method(req))==0 && ev.dialog) belle_sip_dialog_handle_ack(ev.dialog,req);
ev.source=prov;
ev.server_transaction=NULL;
ev.request=req;
......
......@@ -171,6 +171,8 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
/*time to send bye*/
belle_sip_client_transaction_t* client_transaction = belle_sip_provider_create_client_transaction(prov,belle_sip_dialog_create_request(dialog,"BYE"));
belle_sip_client_transaction_send_request(client_transaction);
} else {
belle_sip_warning("Unexpected state [%s] for dialog [%p]",belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)),dialog );
}
}
......@@ -205,14 +207,23 @@ static void caller_process_response_event(void *user_ctx, const belle_sip_respon
}
static void callee_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
/*belle_sip_client_transaction_t* server_transaction = belle_sip_response_event_get_client_transaction(event);*/
belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
belle_sip_header_from_t* from=belle_sip_message_get_header_by_type(belle_sip_response_event_get_response(event),belle_sip_header_from_t);
int status = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event));
if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from)))) {
return; /*not for the callee*/
}
belle_sip_message("callee_process_response_event [%i]",status);
CU_ASSERT_PTR_NOT_NULL_FATAL(client_transaction);
belle_sip_dialog_t* dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction));
CU_ASSERT_PTR_NOT_NULL_FATAL(dialog);
CU_ASSERT_PTR_EQUAL(callee_dialog,dialog);
if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_TERMINATED) {
call_endeed=1;
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
}
belle_sip_message("callee_process_response_event [%i] on dialog [%p] for state [%s]",status
,dialog
,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)));
}
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
......@@ -298,9 +309,11 @@ static void simple_call(void) {
//belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),op);
call_endeed=0;
belle_sip_client_transaction_send_request(client_transaction);
int i=0;
for(i=0;i<10 &&!call_endeed;i++)
belle_sip_stack_sleep(stack,3000);
//int i=0;
//for(i=0;i<10 &&!call_endeed;i++)
belle_sip_stack_sleep(stack,30000);
CU_ASSERT_EQUAL(call_endeed,1);
belle_sip_provider_remove_sip_listener(prov,caller_listener);
belle_sip_provider_remove_sip_listener(prov,callee_listener);
......@@ -311,7 +324,7 @@ static void simple_call(void) {
int belle_sip_dialog_test_suite(){
CU_pSuite pSuite = CU_add_suite("Dialog", init, uninit);
if (NULL == CU_add_test(pSuite, "simple call", simple_call)) {
if (NULL == CU_add_test(pSuite, "simple-call", simple_call)) {
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