better wrong password management

This commit is contained in:
Jehan Monnier 2013-05-16 08:59:19 +02:00
parent 2f10fbdde7
commit cc0b90e9a4
4 changed files with 33 additions and 12 deletions

View file

@ -422,8 +422,13 @@ void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs){
ctx->callbacks.call_updating=(SalOnCallUpdating)unimplemented_stub;
if (ctx->callbacks.auth_requested_legacy==NULL)
ctx->callbacks.auth_requested_legacy=(SalOnAuthRequestedLegacy)unimplemented_stub;
#ifdef USE_BELLESIP
if (ctx->callbacks.auth_failure==NULL)
ctx->callbacks.auth_failure=(SalOnAuthFailure)unimplemented_stub;
#else
if (ctx->callbacks.auth_success==NULL)
ctx->callbacks.auth_success=(SalOnAuthSuccess)unimplemented_stub;
#endif
if (ctx->callbacks.register_success==NULL)
ctx->callbacks.register_success=(SalOnRegisterSuccess)unimplemented_stub;
if (ctx->callbacks.register_failure==NULL)

View file

@ -50,7 +50,6 @@ static void register_refresher_listener ( const belle_sip_refresher_t* refresher
if (service_route_address) belle_sip_object_unref(service_route_address);
sal_remove_pending_auth(op->base.root,op); /*just in case*/
if (op->auth_info) op->base.root->callbacks.auth_success(op,op->auth_info->realm,op->auth_info->username);
op->base.root->callbacks.register_success(op,belle_sip_refresher_get_expires(op->refresher)>0);
} else if (status_code>=400) {
/* from rfc3608, 6.1.
@ -65,13 +64,13 @@ static void register_refresher_listener ( const belle_sip_refresher_t* refresher
sal_op_set_service_route(op,NULL);
sal_compute_sal_errors_from_code(status_code,&sal_err,&sal_reason);
op->base.root->callbacks.register_failure(op,sal_err,sal_reason,reason_phrase);
if (op->auth_info) {
/*add pending auth*/
sal_add_pending_auth(op->base.root,op);
op->base.root->callbacks.register_failure(op,sal_err,sal_reason,reason_phrase);
if (status_code == 403) { /*in sase of 401 or 407, auth requested already invoked previouly*/
/*auth previouly pending, probably wrong pasword, give a chance to authenticate again*/
op->base.root->callbacks.auth_requested(op->base.root,op->auth_info);
op->base.root->callbacks.auth_failure(op,op->auth_info);
}
}
} else {

View file

@ -712,7 +712,18 @@ static void auth_requested_legacy(SalOp *h, const char *realm, const char *usern
lc->vtable.auth_info_requested(lc,realm,username);
}
}
#ifdef USE_BELLESIP
static void auth_failure(SalOp *op, SalAuthInfo* info) {
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username);
if (ai){
ms_message("%s/%s authentication fails.",info->realm,info->username);
}
if (lc->vtable.auth_info_requested) {
lc->vtable.auth_info_requested(lc,info->realm,info->username);
}
}
#else
static void auth_success(SalOp *h, const char *realm, const char *username){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
@ -721,7 +732,7 @@ static void auth_success(SalOp *h, const char *realm, const char *username){
ai->works=TRUE;
}
}
#endif
static void register_success(SalOp *op, bool_t registered){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op);
@ -894,13 +905,7 @@ static void ping_reply(SalOp *op){
static bool_t fill_auth_info(LinphoneCore *lc, SalAuthInfo* sai) {
LinphoneAuthInfo *ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,sai->realm,sai->username);
if (ai && ai->works==FALSE && ai->usecount>=1){
/*Better is to stop (implemeted below in else statement), and retry later*/
if (ms_time(NULL)-ai->last_use_time>30){
ai->usecount=0; /*so that we can allow to retry */
}
}
if (ai && (ai->works || ai->usecount<1)){
if (ai) {
sai->userid=ai->userid?ai->userid:ai->username;
sai->password=ai->passwd;
sai->ha1=ai->ha1;
@ -1000,7 +1005,11 @@ SalCallbacks linphone_sal_callbacks={
call_failure,
call_released,
auth_requested_legacy,
#ifdef USE_BELLESIP
auth_failure,
#else
auth_success,
#endif
register_success,
register_failure,
vfu_request,

View file

@ -325,7 +325,11 @@ typedef void (*SalOnCallFailure)(SalOp *op, SalError error, SalReason reason, co
typedef void (*SalOnCallReleased)(SalOp *salop);
typedef void (*SalOnAuthRequestedLegacy)(SalOp *op, const char *realm, const char *username);
typedef bool_t (*SalOnAuthRequested)(Sal *sal,SalAuthInfo* info);
#ifndef USE_BELLESIP
typedef void (*SalOnAuthSuccess)(SalOp *op, const char *realm, const char *username);
#else
typedef void (*SalOnAuthFailure)(SalOp *op, SalAuthInfo* info);
#endif
typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
typedef void (*SalOnRegisterFailure)(SalOp *op, SalError error, SalReason reason, const char *details);
typedef void (*SalOnVfuRequest)(SalOp *op);
@ -353,7 +357,11 @@ typedef struct SalCallbacks{
SalOnCallFailure call_failure;
SalOnCallReleased call_released;
SalOnAuthRequestedLegacy auth_requested_legacy;
#ifdef USE_BELLESIP
SalOnAuthFailure auth_failure;
#else
SalOnAuthSuccess auth_success;
#endif
SalOnRegisterSuccess register_success;
SalOnRegisterFailure register_failure;
SalOnVfuRequest vfu_request;