Commit 40b65a77 authored by jehan's avatar jehan
Browse files

better op management to avoid transaction to refference a freed op

parent 73722ac3
......@@ -313,6 +313,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
}
case 401:
case 407:{
/*belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*//*remove op from trans*/
if (op->state == SalOpStateTerminating && strcmp("BYE",belle_sip_request_get_method(request))!=0) {
/*only bye are completed*/
belle_sip_message("Op is in state terminating, nothing else to do ");
......@@ -356,6 +357,7 @@ static void process_transaction_terminated(void *user_ctx, const belle_sip_trans
} else {
ms_error("Unhandled transaction terminated [%p]",trans);
}
if (op) sal_op_unref(op); /*no longuer need to ref op*/
}
static void process_auth_requested(void *sal, belle_sip_auth_event_t *auth_event) {
SalAuthInfo auth_info;
......
......@@ -36,6 +36,7 @@ struct Sal{
unsigned int keep_alive;
bool_t use_tcp_tls_keep_alive;
bool_t nat_helper_enabled;
};
typedef enum SalOpSate {
......@@ -70,6 +71,8 @@ struct SalOp{
SalOpSate_t state;
SalOpDir_t dir;
belle_sip_refresher_t* refresher;
unsigned int call_released_timer;
unsigned int ref;
};
belle_sdp_session_description_t * media_description_to_sdp(const SalMediaDescription *sal);
......@@ -80,6 +83,12 @@ belle_sip_request_t* sal_op_build_request(SalOp *op,const char* method);
void sal_op_call_fill_cbs(SalOp*op);
void set_or_update_dialog(SalOp* op, belle_sip_dialog_t* dialog);
/*return reffed op*/
SalOp* sal_op_ref(SalOp* op);
/*return null, destroy op if ref count =0*/
void* sal_op_unref(SalOp* op);
void sal_op_release_impl(SalOp *op);
void sal_op_set_remote_ua(SalOp*op,belle_sip_message_t* message);
int sal_op_send_request(SalOp* op, belle_sip_request_t* request);
......
......@@ -236,6 +236,13 @@ static void call_process_timeout(void *user_ctx, const belle_sip_timeout_event_t
/*dialog will terminated shortly, nothing to do*/
}
}
static int call_released(void *user_ctx, unsigned int events) {
SalOp* op = (SalOp*)user_ctx;
op->base.root->callbacks.call_released(op);
op->state=SalOpStateTerminated;
op->call_released_timer=0;
return BELLE_SIP_STOP;
}
static void call_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
SalOp* op = (SalOp*)user_ctx;
belle_sip_client_transaction_t *client_transaction=belle_sip_transaction_terminated_event_get_client_transaction(event);
......@@ -252,8 +259,11 @@ static void call_process_transaction_terminated(void *user_ctx, const belle_sip_
if (strcmp("BYE",belle_sip_request_get_method(req))==0
&& belle_sip_response_get_status_code(resp) !=401
&& belle_sip_response_get_status_code(resp) !=407) {
op->base.root->callbacks.call_released(op);
op->state=SalOpStateTerminated;
op->call_released_timer = belle_sip_main_loop_add_timeout(belle_sip_stack_get_main_loop(op->base.root->stack)
, call_released
, op
, 32000/*FIXME, should be T1*64*/);
}
}
......@@ -285,15 +295,19 @@ static void process_sdp_for_invite(SalOp* op,belle_sip_request_t* invite) {
static void process_request_event(void *op_base, const belle_sip_request_event_t *event) {
SalOp* op = (SalOp*)op_base;
belle_sip_server_transaction_t* server_transaction = belle_sip_provider_create_server_transaction(op->base.root->prov,belle_sip_request_event_get_request(event));
if (server_transaction) belle_sip_object_ref(server_transaction); /*ACK does'nt create srv transaction*/
if (op->pending_server_trans) belle_sip_object_unref(op->pending_server_trans);
op->pending_server_trans=server_transaction;
belle_sdp_session_description_t* sdp;
belle_sip_request_t* req = belle_sip_request_event_get_request(event);
belle_sip_dialog_state_t dialog_state;
belle_sip_response_t* resp;
belle_sip_header_t* call_info;
if (server_transaction) belle_sip_object_ref(server_transaction); /*ACK does'nt create srv transaction*/
if (strcmp("INVITE",belle_sip_request_get_method(req))==0) {
if (op->pending_server_trans)belle_sip_object_unref(op->pending_server_trans);
/*updating pending invite transaction*/
op->pending_server_trans=server_transaction;
}
if (!op->dialog) {
set_or_update_dialog(op,belle_sip_provider_create_dialog(op->base.root->prov,BELLE_SIP_TRANSACTION(op->pending_server_trans)));
ms_message("new incoming call from [%s] to [%s]",sal_op_get_from(op),sal_op_get_to(op));
......@@ -330,10 +344,10 @@ static void process_request_event(void *op_base, const belle_sip_request_event_t
/*first answer 200 ok to cancel*/
belle_sip_server_transaction_send_response(server_transaction
,belle_sip_response_create_from_request(req,200));
/*terminate invite request*/
/*terminate invite transaction*/
call_terminated(op
,belle_sip_request_event_get_server_transaction(event)
,belle_sip_request_event_get_request(event),487);
,op->pending_server_trans
,belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(op->pending_server_trans)),487);
} else {
......
......@@ -23,10 +23,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
SalOp * sal_op_new(Sal *sal){
SalOp *op=ms_new0(SalOp,1);
__sal_op_init(op,sal);
sal_op_ref(op);
return op;
}
void sal_op_release(SalOp *op){
op->state=SalOpStateTerminated;
sal_op_unref(op);
}
void sal_op_release_impl(SalOp *op){
ms_message("Destroying op [%p]",op);
if (op->request) belle_sip_object_unref(op->request);
if (op->auth_info) sal_auth_info_delete(op->auth_info);
if (op->sdp_answer) belle_sip_object_unref(op->sdp_answer);
......@@ -38,6 +43,7 @@ void sal_op_release(SalOp *op){
if(op->referred_by) belle_sip_object_unref(op->referred_by);
if (op->pending_inv_client_trans) belle_sip_object_unref(op->pending_inv_client_trans);
if (op->call_released_timer) belle_sip_main_loop_cancel_source(belle_sip_stack_get_main_loop(op->base.root->stack),op->call_released_timer);
__sal_op_free(op);
return ;
}
......@@ -143,7 +149,7 @@ static int _sal_op_send_request_with_contact(SalOp* op, belle_sip_request_t* req
}
client_transaction = belle_sip_provider_create_client_transaction(prov,request);
belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),op);
belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),sal_op_ref(op));
if ( strcmp("INVITE",belle_sip_request_get_method(request))==0) {
if (op->pending_inv_client_trans) belle_sip_object_unref(op->pending_inv_client_trans);
op->pending_inv_client_trans=client_transaction; /*update pending inv for being able to cancel*/
......@@ -256,3 +262,15 @@ void set_or_update_dialog(SalOp* op, belle_sip_dialog_t* dialog) {
belle_sip_object_ref(op->dialog);
}
}
/*return reffed op*/
SalOp* sal_op_ref(SalOp* op) {
op->ref++;
return op;
}
/*return null, destroy op if ref count =0*/
void* sal_op_unref(SalOp* op) {
if (--op->ref <=0) {
sal_op_release_impl(op);
}
return NULL;
}
......@@ -30,14 +30,29 @@ static void process_error( SalOp* op) {
static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
SalOp* op = (SalOp*)user_ctx;
// belle_sip_object_t* source = belle_sip_io_error_event_get_source(event);
// if (BELLE_SIP_IS_INSTANCE_OF(source,belle_sip_transaction_t)) {
// /*reset op to make sure transaction terminated does not need op*/
// belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(source),NULL);
// }
process_error(op);
}
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
SalOp* op=(SalOp*)user_ctx;
// belle_sip_client_transaction_t *client_transaction=belle_sip_timeout_event_get_client_transaction(event);
// belle_sip_server_transaction_t *server_transaction=belle_sip_timeout_event_get_server_transaction(event);
// /*reset op to make sure transaction terminated does not need op*/
// if (client_transaction) {
// belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);
// } else {
// belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(server_transaction),NULL);
// }
process_error(op);
}
static void process_response_event(void *op_base, const belle_sip_response_event_t *event){
SalOp* op = (SalOp*)op_base;
/*belle_sip_client_transaction_t *client_transaction=belle_sip_response_event_get_client_transaction(event);*/
int code = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event));
SalTextDeliveryStatus status;
if (code>=100 && code <200)
......@@ -46,7 +61,10 @@ static void process_response_event(void *op_base, const belle_sip_response_event
status=SalTextDeliveryDone;
else
status=SalTextDeliveryFailed;
if (status != SalTextDeliveryInProgress) {
/*reset op to make sure transaction terminated does not need op
belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*/
}
op->base.root->callbacks.text_delivery_update(op,status);
}
......
......@@ -618,10 +618,6 @@ int sal_subscribe_decline(SalOp *op){
}
int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message){
belle_sip_request_t* notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY");
/* belle_sip_header_address_t* identity=sal_op_get_contact_address(op);
if (identity==NULL) identity=sal_op_get_to_address(op);
_osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free);
osip_message_set_contact(msg,identity);*/
add_presence_info(BELLE_SIP_MESSAGE(notify),status); /*FIXME, what about expires ??*/
belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify)
,BELLE_SIP_HEADER(belle_sip_header_subscription_state_create(BELLE_SIP_SUBSCRIPTION_STATE_ACTIVE,600)));
......
......@@ -106,7 +106,7 @@ static void register_process_timeout(void *user_ctx, const belle_sip_timeout_eve
}
}
static void register_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
ms_error("process_transaction_terminated not implemented yet");
/*ms_error("register_process_transaction_terminated not implemented yet");*/
}
......
mediastreamer2 @ 7a11d31f
Subproject commit 4ed2e518cf79c62fe8df7f23ce99e0fbfe2e799d
Subproject commit 7a11d31f5cab97ff0de373d617720bb651d19b7d
......@@ -48,7 +48,7 @@ void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *c
static void register_with_refresh_base_2(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route,bool_t late_auth_info) {
int retry=0;
LCSipTransports transport = {5070,5070,0,5071};
char* addr;
CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
stats* counters = (stats*)linphone_core_get_user_data(lc);
reset_counters(counters);
......@@ -59,7 +59,8 @@ static void register_with_refresh_base_2(LinphoneCore* lc, bool_t refresh,const
LinphoneAddress *from = create_linphone_address(domain);
linphone_proxy_config_set_identity(proxy_cfg,linphone_address_as_string(from));
linphone_proxy_config_set_identity(proxy_cfg,addr=linphone_address_as_string(from));
ms_free(addr);
const char* server_addr = linphone_address_get_domain(from);
linphone_proxy_config_enable_register(proxy_cfg,TRUE);
......@@ -284,7 +285,7 @@ static void io_recv_error(){
int register_test_suite () {
CU_pSuite pSuite = CU_add_suite("Register", NULL, NULL);
if (NULL == CU_add_test(pSuite, "simple_register_tester", simple_register)) {
if (NULL == CU_add_test(pSuite, "simple_register", simple_register)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "tcp register tester", simple_tcp_register)) {
......@@ -293,7 +294,7 @@ int register_test_suite () {
if (NULL == CU_add_test(pSuite, "tls register tester", simple_tls_register)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple register with digest auth tester", simple_authenticated_register)) {
if (NULL == CU_add_test(pSuite, "simple_authenticated_register", simple_authenticated_register)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "register with digest auth tester without initial credentials", authenticated_register_with_no_initial_credentials)) {
......
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