diff --git a/coreapi/exevents.c b/coreapi/exevents.c index af4b4e89c..357a96b36 100644 --- a/coreapi/exevents.c +++ b/coreapi/exevents.c @@ -970,7 +970,7 @@ void linphone_registration_faillure(LinphoneCore *lc, eXosip_event_t *ev){ updated contact first, just in case the faillure is due to incorrect contact */ if (linphone_proxy_config_register_again_with_updated_contact(cfg,ev->request,ev->response)) return; /*we are retrying with an updated contact*/ - if (status_code==403) linphone_proxy_config_process_authentication_failure(lc,ev); + linphone_proxy_config_process_authentication_failure(lc,status_code,ev); osip_uri_to_str(requri,&ru); msg=ortp_strdup_printf(_("Registration on %s failed: %s"),ru,(reason!=NULL) ? reason : _("no response timeout")); lc->vtable.display_status(lc,msg); @@ -990,12 +990,13 @@ void linphone_registration_success(LinphoneCore *lc,eXosip_event_t *ev){ cfg=linphone_core_get_proxy_config_from_rid(lc,ev->rid); ms_return_if_fail(cfg!=NULL); - gstate_new_state(lc, GSTATE_REG_OK, NULL); osip_message_get_expires(ev->request,0,&h); if (h!=NULL && atoi(h->hvalue)!=0){ cfg->registered=TRUE; linphone_proxy_config_register_again_with_updated_contact(cfg,ev->request,ev->response); }else cfg->registered=FALSE; + + gstate_new_state(lc, GSTATE_REG_OK, NULL); osip_uri_to_str(requri,&ru); if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),ru); diff --git a/coreapi/private.h b/coreapi/private.h index e9809dc83..93b1c77be 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -163,7 +163,7 @@ void linphone_authentication_ok(LinphoneCore *lc, eXosip_event_t *ev); void linphone_subscription_new(LinphoneCore *lc, eXosip_event_t *ev); void linphone_notify_recv(LinphoneCore *lc,eXosip_event_t *ev); LinphoneProxyConfig *linphone_core_get_proxy_config_from_rid(LinphoneCore *lc, int rid); -void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, eXosip_event_t *ev); +void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, int code, eXosip_event_t *ev); void linphone_subscription_answered(LinphoneCore *lc, eXosip_event_t *ev); void linphone_subscription_closed(LinphoneCore *lc, eXosip_event_t *ev); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index b836feb53..437c85e60 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -760,17 +760,43 @@ const MSList *linphone_core_get_proxy_config_list(const LinphoneCore *lc){ } -void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, eXosip_event_t *ev){ - LinphoneProxyConfig *cfg=linphone_core_get_proxy_config_from_rid(lc, ev->rid); - if (cfg){ - cfg->auth_failures++; - if (strcmp(ev->request->sip_method,"REGISTER")==0) { - gstate_new_state(lc, GSTATE_REG_FAILED, "Authentication failed."); +void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, int code, eXosip_event_t *ev){ + if (code==403) { + LinphoneProxyConfig *cfg=linphone_core_get_proxy_config_from_rid(lc, ev->rid); + if (cfg){ + cfg->auth_failures++; + /*restart a new register so that the user gets a chance to be prompted for a password*/ + if (cfg->auth_failures==1){ + linphone_proxy_config_register(cfg); + } } - /*restart a new register so that the user gets a chance to be prompted for a password*/ - if (cfg->auth_failures==1){ - linphone_proxy_config_register(cfg); + } else { + //unknown error (possibly timeout) + char *prx_realm=NULL,*www_realm=NULL; + osip_proxy_authenticate_t *prx_auth; + osip_www_authenticate_t *www_auth; + osip_message_t *req=ev->request; + char *username; + username=osip_uri_get_username(req->from->url); + prx_auth=(osip_proxy_authenticate_t*)osip_list_get(&req->proxy_authenticates,0); + www_auth=(osip_proxy_authenticate_t*)osip_list_get(&req->www_authenticates,0); + if (prx_auth!=NULL) + prx_realm=osip_proxy_authenticate_get_realm(prx_auth); + if (www_auth!=NULL) + www_realm=osip_www_authenticate_get_realm(www_auth); + + if (prx_realm==NULL && www_realm==NULL){ + ms_warning("No realm in the client request."); + return; } + LinphoneAuthInfo *as=NULL; + /* see if we already have this auth information , not to ask it everytime to the user */ + if (prx_realm!=NULL) + as=linphone_core_find_auth_info(lc,prx_realm,username); + if (www_realm!=NULL) + as=linphone_core_find_auth_info(lc,www_realm,username); + + if (as) as->first_time=TRUE; } }