From 3d1c5e7ce121d0b9f66aee607ba038339c65f026 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 5 Feb 2013 15:02:03 +0100 Subject: [PATCH] fix call error reporting when dialog is not established yet --- coreapi/bellesip_sal/sal_impl.c | 6 +-- coreapi/bellesip_sal/sal_op_call.c | 63 +++++++--------------- coreapi/bellesip_sal/sal_op_impl.c | 4 +- coreapi/bellesip_sal/sal_op_registration.c | 8 ++- 4 files changed, 31 insertions(+), 50 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 49ce7f649..a0f5fe947 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -350,11 +350,11 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even } static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) { -/* belle_sip_client_transaction_t* client_transaction = belle_sip_timeout_event_get_client_transaction(event); + belle_sip_client_transaction_t* client_transaction = belle_sip_timeout_event_get_client_transaction(event); SalOp* op = (SalOp*)belle_sip_transaction_get_application_data(BELLE_SIP_TRANSACTION(client_transaction)); - if (op->callbacks.process_timeout) { + if (op && op->callbacks.process_timeout) { op->callbacks.process_timeout(op,event); - } else*/ { + } else { ms_error("Unhandled event timeout [%p]",event); } } diff --git a/coreapi/bellesip_sal/sal_op_call.c b/coreapi/bellesip_sal/sal_op_call.c index a39cc3dbb..9a2f90790 100644 --- a/coreapi/bellesip_sal/sal_op_call.c +++ b/coreapi/bellesip_sal/sal_op_call.c @@ -86,9 +86,16 @@ static void call_process_io_error(void *user_ctx, const belle_sip_io_error_event } static void process_dialog_terminated(void *ctx, const belle_sip_dialog_terminated_event_t *event) { SalOp* op=(SalOp*)ctx; + if (op->dialog) { - op->base.root->callbacks.call_terminated(op,op->dir==SalOpDirIncoming?sal_op_get_from(op):sal_op_get_to(op)); - op->state=SalOpStateTerminated; + if (belle_sip_dialog_get_previous_state(op->dialog) == BELLE_SIP_DIALOG_CONFIRMED) { + /*this is probably a "normal termination from a BYE*/ + op->base.root->callbacks.call_terminated(op,op->dir==SalOpDirIncoming?sal_op_get_from(op):sal_op_get_to(op)); + op->state=SalOpStateTerminated; + } else { + /*let the process response handle this case*/ + } + belle_sip_object_unref(op->dialog); op->dialog=NULL; } @@ -124,48 +131,9 @@ static void call_response_event(void *op_base, const belle_sip_response_event_t reason = ms_strdup_printf("%s %s",reason,belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(reason_header))); } if (code >=400) { - switch(code) { - case 400: - error=SalErrorUnknown; - break; - case 404: - error=SalErrorFailure; - sr=SalReasonNotFound; - break; - case 415: - error=SalErrorFailure; - sr=SalReasonMedia; - break; - case 422: - ms_error ("422 not implemented yet");; - break; - case 480: - error=SalErrorFailure; - sr=SalReasonTemporarilyUnavailable; - break; - case 486: - error=SalErrorFailure; - sr=SalReasonBusy; - break; - case 487: - break; - case 600: - error=SalErrorFailure; - sr=SalReasonDoNotDisturb; - break; - case 603: - error=SalErrorFailure; - sr=SalReasonDeclined; - break; - default: - if (code>0){ - error=SalErrorFailure; - sr=SalReasonUnknown; - }else error=SalErrorNoResponse; - /* no break */ - } - + sal_compute_sal_errors_from_code(code,&error,&sr); op->base.root->callbacks.call_failure(op,error,sr,reason,code); + op->state=SalOpStateTerminated; if (reason_header != NULL){ ms_free(reason); } @@ -246,7 +214,14 @@ static void call_response_event(void *op_base, const belle_sip_response_event_t } static void call_process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) { - ms_error("process_timeout not implemented yet"); + SalOp* op=(SalOp*)user_ctx; + if (!op->dialog) { + /*call terminated very early*/ + op->base.root->callbacks.call_failure(op,SalErrorNoResponse,SalReasonUnknown,"Request Timeout",408); + op->state=SalOpStateTerminated; + } else { + /*dialog will terminated shortly, nothing to do*/ + } } static void call_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) { ms_error("process_transaction_terminated not implemented yet"); diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index a22c5392a..d779249f2 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -119,8 +119,8 @@ int sal_op_send_request(SalOp* op, belle_sip_request_t* request) { belle_sip_header_route_t* route_header; belle_sip_uri_t* outbound_proxy=NULL; MSList* iterator; - if (!op->dialog) { - /*don't put route header if dialog is in confirmed state*/ + if (!op->dialog || belle_sip_dialog_get_state(op->dialog) == BELLE_SIP_DIALOG_NULL) { + /*don't put route header if dialog is in confirmed state*/ for(iterator=(MSList*)sal_op_get_route_addresses(op);iterator!=NULL;iterator=iterator->next) { if(!outbound_proxy) { /*first toute is outbound proxy*/ diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index df137d614..a8ac7e874 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -97,7 +97,13 @@ static void register_response_event(void *user_ctx, const belle_sip_response_eve } } static void register_process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) { - ms_error("process_timeout not implemented yet"); + SalOp* op = (SalOp*)user_ctx; + ms_error("register_process_timeout timeout error reported for [%s]",sal_op_get_proxy(op)); + if (!op->registration_refresher) { + op->base.root->callbacks.register_failure(op,SalErrorNoResponse,SalReasonUnknown,"Request Timeout"); + } else { + /*refresher will report error*/ + } } 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");