From fe1cddbfaac5b9d671c730a98baa3b7914265129 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 4 Jun 2013 21:25:52 +0200 Subject: [PATCH] no longuer return registration failure in case of first retry --- coreapi/bellesip_sal/sal_op_impl.c | 13 ++++++++++++- coreapi/bellesip_sal/sal_op_registration.c | 4 ---- coreapi/callbacks.c | 9 ++++++++- coreapi/proxy.c | 16 +++++++++++++--- coreapi/sal.c | 1 + include/sal/sal.h | 3 ++- tester/liblinphone_tester.c | 2 +- tester/register_tester.c | 11 +++++++---- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index 78957f2af..ffd2b3b86 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -40,7 +40,10 @@ void sal_op_release(SalOp *op){ void sal_op_release_impl(SalOp *op){ ms_message("Destroying op [%p] of type [%s]",op,sal_op_type_to_string(op->type)); if (op->pending_auth_transaction) belle_sip_object_unref(op->pending_auth_transaction); - if (op->auth_info) sal_auth_info_delete(op->auth_info); + if (op->auth_info) { + sal_remove_pending_auth(op->base.root,op); + sal_auth_info_delete(op->auth_info); + } if (op->sdp_answer) belle_sip_object_unref(op->sdp_answer); if (op->refresher) { belle_sip_object_unref(op->refresher); @@ -259,6 +262,10 @@ void sal_compute_sal_errors_from_code(int code ,SalError* sal_err,SalReason* sal case 400: *sal_err=SalErrorUnknown; break; + case 403: + *sal_err=SalErrorFailure; + *sal_reason=SalReasonForbidden; + break; case 404: *sal_err=SalErrorFailure; *sal_reason=SalReasonNotFound; @@ -280,6 +287,10 @@ void sal_compute_sal_errors_from_code(int code ,SalError* sal_err,SalReason* sal break; case 487: break; + case 503: + *sal_err=SalErrorFailure; + *sal_reason=SalReasonServiceUnavailable; + break; case 600: *sal_err=SalErrorFailure; *sal_reason=SalReasonDoNotDisturb; diff --git a/coreapi/bellesip_sal/sal_op_registration.c b/coreapi/bellesip_sal/sal_op_registration.c index d4226ef3f..7c70bf18f 100644 --- a/coreapi/bellesip_sal/sal_op_registration.c +++ b/coreapi/bellesip_sal/sal_op_registration.c @@ -68,10 +68,6 @@ static void register_refresher_listener ( const belle_sip_refresher_t* refresher if (op->auth_info) { /*add pending auth*/ sal_add_pending_auth(op->base.root,op); - if (status_code == 403 || status_code == 401 || status_code == 407) { /*in case of 401 or 407, auth requested already invoked previously but maybe*/ - /*auth previouly pending, probably wrong pasword, give a chance to authenticate again*/ - op->base.root->callbacks.auth_failure(op,op->auth_info); /*fixme*/ - } } } } diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 08e7cf550..35ae87a24 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -779,7 +779,14 @@ static void register_failure(SalOp *op, SalError error, SalReason reason, const } else if (error == SalErrorNoResponse) { linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse); } - linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details); + if (error== SalErrorFailure + && reason == SalReasonServiceUnavailable + && linphone_proxy_config_get_state(cfg) == LinphoneRegistrationOk) { + linphone_proxy_config_set_state(cfg,LinphoneRegistrationProgress,_("Service unavailable, retrying")); + + } else { + linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details); + } if (error== SalErrorFailure && reason == SalReasonForbidden) { const char *realm=NULL,*username=NULL; if (sal_op_get_auth_requested(op,&realm,&username)==0){ diff --git a/coreapi/proxy.c b/coreapi/proxy.c index c3770d87e..253922713 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -1310,9 +1310,19 @@ void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr) { void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const char *message){ LinphoneCore *lc=cfg->lc; - cfg->state=state; - if (lc && lc->vtable.registration_state_changed){ - lc->vtable.registration_state_changed(lc,cfg,state,message); + + + ms_message("Proxy config [%p] for identity [%s] moving from state [%s] to [%s]" , cfg + , linphone_proxy_config_get_identity(cfg) + , linphone_registration_state_to_string(cfg->state) + , linphone_registration_state_to_string(state)); + if (cfg->state!=state || state==LinphoneRegistrationOk) { /*allow multiple notification of LinphoneRegistrationOk for refreshing*/ + cfg->state=state; + if (lc && lc->vtable.registration_state_changed){ + lc->vtable.registration_state_changed(lc,cfg,state,message); + } + } else { + /*state already reported*/ } } diff --git a/coreapi/sal.c b/coreapi/sal.c index d47c5d2fa..6c4db977b 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -525,6 +525,7 @@ const char* sal_reason_to_string(const SalReason reason) { case SalReasonMedia: return "SalReasonMedia"; case SalReasonForbidden: return "SalReasonForbidden"; case SalReasonUnknown: return "SalReasonUnknown"; + case SalReasonServiceUnavailable: return "SalReasonServiceUnavailable"; default: return "Unkown reason"; } } diff --git a/include/sal/sal.h b/include/sal/sal.h index 051f06482..9759f2931 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -270,7 +270,8 @@ typedef enum SalReason{ SalReasonDoNotDisturb, SalReasonMedia, SalReasonForbidden, - SalReasonUnknown + SalReasonUnknown, + SalReasonServiceUnavailable }SalReason; const char* sal_reason_to_string(const SalReason reason); diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 1bd9e0ff7..40cf3df09 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -44,7 +44,7 @@ const char* test_route="sip2.linphone.org"; #if WINAPI_FAMILY_PHONE_APP const char *liblinphone_tester_file_prefix="Assets"; #else -const char *liblinphone_tester_file_prefix="./tester"; +const char *liblinphone_tester_file_prefix="."; #endif const char *userhostsfile = "tester_hosts"; diff --git a/tester/register_tester.c b/tester/register_tester.c index d079a3930..1b47bf343 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -126,11 +126,12 @@ static void register_with_refresh_with_send_error() { register_with_refresh_base(lc,TRUE,auth_domain,route); /*simultate a network error*/ sal_set_send_error(lc->sal, -1); - while (counters->number_of_LinphoneRegistrationFailed<1 && retry++ <20) { + while (counters->number_of_LinphoneRegistrationProgress<2 && retry++ <20) { linphone_core_iterate(lc); ms_usleep(100000); } - CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,1); + CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,0); + CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationProgress,2); linphone_core_destroy(lc); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationCleared,0); @@ -348,7 +349,7 @@ static void transport_change(){ linphone_core_set_sip_transports(lc,&sip_tr); CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,register_ok+number_of_udp_proxy)); - CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok+(total_number_of_proxies-number_of_udp_proxy))); + CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,total_number_of_proxies-number_of_udp_proxy)); linphone_core_destroy(lc); } @@ -368,7 +369,9 @@ static void io_recv_error(){ number_of_udp_proxy=get_number_of_udp_proxy(lc); sal_set_recv_error(lc->sal, 0); - CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationFailed,register_ok-number_of_udp_proxy /*because 1 udp*/)); + CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationProgress,2*(register_ok-number_of_udp_proxy) /*because 1 udp*/)); + CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,0) + sal_set_recv_error(lc->sal, 1); /*reset*/ linphone_core_destroy(lc);