diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index c7ced7384..cedd2b83f 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -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; diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index dc72545a0..a4125f17f 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -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,7 @@ struct SalOp{ SalOpSate_t state; SalOpDir_t dir; belle_sip_refresher_t* refresher; + unsigned int ref; }; belle_sdp_session_description_t * media_description_to_sdp(const SalMediaDescription *sal); @@ -80,6 +82,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); diff --git a/coreapi/bellesip_sal/sal_op_call.c b/coreapi/bellesip_sal/sal_op_call.c index d21c2fa24..88f6d7457 100644 --- a/coreapi/bellesip_sal/sal_op_call.c +++ b/coreapi/bellesip_sal/sal_op_call.c @@ -285,15 +285,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 +334,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 { diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index 8f3254460..c33feb7d4 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -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); @@ -143,7 +148,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 +261,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; +} diff --git a/coreapi/bellesip_sal/sal_op_message.c b/coreapi/bellesip_sal/sal_op_message.c index 46492f63a..9949c03ce 100644 --- a/coreapi/bellesip_sal/sal_op_message.c +++ b/coreapi/bellesip_sal/sal_op_message.c @@ -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); } diff --git a/coreapi/bellesip_sal/sal_op_presence.c b/coreapi/bellesip_sal/sal_op_presence.c index 9da9e1080..18775a6c0 100644 --- a/coreapi/bellesip_sal/sal_op_presence.c +++ b/coreapi/bellesip_sal/sal_op_presence.c @@ -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))); diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index a8ac7e874..609fb2b03 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -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");*/ } diff --git a/tester/register_tester.c b/tester/register_tester.c index 1a6d7eaf8..a6b4b920a 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -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)) {