Commit 6d52275b authored by Simon Morlat's avatar Simon Morlat

modify the way LinphoneAuthInfo are managed.

parent 39d67546
...@@ -55,6 +55,18 @@ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *useri ...@@ -55,6 +55,18 @@ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *useri
return obj; return obj;
} }
static LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *ai){
LinphoneAuthInfo *obj=ms_new0(LinphoneAuthInfo,1);
if (ai->username) obj->username=ms_strdup(ai->username);
if (ai->userid) obj->userid=ms_strdup(ai->userid);
if (ai->passwd) obj->passwd=ms_strdup(ai->passwd);
if (ai->ha1) obj->ha1=ms_strdup(ai->ha1);
if (ai->realm) obj->realm=ms_strdup(ai->realm);
obj->works=FALSE;
obj->first_time=TRUE;
return obj;
}
/** /**
* Sets the password. * Sets the password.
**/ **/
...@@ -180,7 +192,7 @@ static int realm_match(const char *realm1, const char *realm2){ ...@@ -180,7 +192,7 @@ static int realm_match(const char *realm1, const char *realm2){
/** /**
* Retrieves a LinphoneAuthInfo previously entered into the LinphoneCore. * Retrieves a LinphoneAuthInfo previously entered into the LinphoneCore.
**/ **/
LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username) const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username)
{ {
MSList *elem; MSList *elem;
LinphoneAuthInfo *ret=NULL,*candidate=NULL; LinphoneAuthInfo *ret=NULL,*candidate=NULL;
...@@ -232,24 +244,18 @@ static void refresh_exosip_auth_info(LinphoneCore *lc){ ...@@ -232,24 +244,18 @@ static void refresh_exosip_auth_info(LinphoneCore *lc){
* *
* This information will be used during all SIP transacations that require authentication. * This information will be used during all SIP transacations that require authentication.
**/ **/
void linphone_core_add_auth_info(LinphoneCore *lc, LinphoneAuthInfo *info) void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
{ {
MSList *elem;
LinphoneAuthInfo *ai; LinphoneAuthInfo *ai;
/* find if we are attempting to modify an existing auth info */ /* find if we are attempting to modify an existing auth info */
ai=linphone_core_find_auth_info(lc,info->realm,info->username); ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username);
if (ai!=NULL){ if (ai!=NULL){
elem=ms_list_find(lc->auth_info,ai); lc->auth_info=ms_list_remove(lc->auth_info,ai);
if (elem==NULL){ linphone_auth_info_destroy(ai);
ms_error("AuthInfo list corruption ?");
return;
}
linphone_auth_info_destroy((LinphoneAuthInfo*)elem->data);
elem->data=(void *)info;
}else {
lc->auth_info=ms_list_append(lc->auth_info,(void *)info);
} }
lc->auth_info=ms_list_append(lc->auth_info,linphone_auth_info_clone(info));
refresh_exosip_auth_info(lc); refresh_exosip_auth_info(lc);
/* if the user was prompted, re-allow automatic_action */ /* if the user was prompted, re-allow automatic_action */
if (lc->automatic_action>0) lc->automatic_action--; if (lc->automatic_action>0) lc->automatic_action--;
...@@ -267,23 +273,21 @@ void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *inf ...@@ -267,23 +273,21 @@ void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *inf
/** /**
* Removes an authentication information object. * Removes an authentication information object.
**/ **/
void linphone_core_remove_auth_info(LinphoneCore *lc, LinphoneAuthInfo *info){ void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
int len=ms_list_size(lc->auth_info);
int newlen;
int i; int i;
MSList *elem; MSList *elem;
lc->auth_info=ms_list_remove(lc->auth_info,info); LinphoneAuthInfo *r;
newlen=ms_list_size(lc->auth_info); r=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username);
/*printf("len=%i newlen=%i\n",len,newlen);*/ if (r){
linphone_auth_info_destroy(info); lc->auth_info=ms_list_remove(lc->auth_info,r);
for (i=0;i<len;i++){ /*printf("len=%i newlen=%i\n",len,newlen);*/
linphone_auth_info_destroy(r);
for (elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
linphone_auth_info_write_config(lc->config,(LinphoneAuthInfo*)elem->data,i);
}
linphone_auth_info_write_config(lc->config,NULL,i); linphone_auth_info_write_config(lc->config,NULL,i);
refresh_exosip_auth_info(lc);
} }
for (elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
linphone_auth_info_write_config(lc->config,(LinphoneAuthInfo*)elem->data,i);
}
refresh_exosip_auth_info(lc);
} }
/** /**
...@@ -333,9 +337,9 @@ void linphone_authentication_ok(LinphoneCore *lc, eXosip_event_t *ev){ ...@@ -333,9 +337,9 @@ void linphone_authentication_ok(LinphoneCore *lc, eXosip_event_t *ev){
} }
/* see if we already have this auth information , not to ask it everytime to the user */ /* see if we already have this auth information , not to ask it everytime to the user */
if (prx_realm!=NULL) if (prx_realm!=NULL)
as=linphone_core_find_auth_info(lc,prx_realm,username); as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,prx_realm,username);
if (www_realm!=NULL) if (www_realm!=NULL)
as=linphone_core_find_auth_info(lc,www_realm,username); as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,www_realm,username);
if (as){ if (as){
ms_message("Authentication for user=%s realm=%s is working.",username,prx_realm ? prx_realm : www_realm); ms_message("Authentication for user=%s realm=%s is working.",username,prx_realm ? prx_realm : www_realm);
as->works=TRUE; as->works=TRUE;
...@@ -345,7 +349,7 @@ void linphone_authentication_ok(LinphoneCore *lc, eXosip_event_t *ev){ ...@@ -345,7 +349,7 @@ void linphone_authentication_ok(LinphoneCore *lc, eXosip_event_t *ev){
void linphone_core_find_or_ask_for_auth_info(LinphoneCore *lc,const char *username,const char* realm, int tid) void linphone_core_find_or_ask_for_auth_info(LinphoneCore *lc,const char *username,const char* realm, int tid)
{ {
LinphoneAuthInfo *as=linphone_core_find_auth_info(lc,realm,username); LinphoneAuthInfo *as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,realm,username);
if ( as==NULL || (as!=NULL && as->works==FALSE && as->first_time==FALSE)){ if ( as==NULL || (as!=NULL && as->works==FALSE && as->first_time==FALSE)){
if (lc->vtable.auth_info_requested!=NULL){ if (lc->vtable.auth_info_requested!=NULL){
lc->vtable.auth_info_requested(lc,realm,username); lc->vtable.auth_info_requested(lc,realm,username);
......
...@@ -738,13 +738,13 @@ void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index); ...@@ -738,13 +738,13 @@ void linphone_core_set_default_proxy_index(LinphoneCore *lc, int index);
int linphone_core_get_default_proxy(LinphoneCore *lc, LinphoneProxyConfig **config); int linphone_core_get_default_proxy(LinphoneCore *lc, LinphoneProxyConfig **config);
void linphone_core_add_auth_info(LinphoneCore *lc, LinphoneAuthInfo *info); void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info);
void linphone_core_remove_auth_info(LinphoneCore *lc, LinphoneAuthInfo *info); void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info);
const MSList *linphone_core_get_auth_info_list(const LinphoneCore *lc); const MSList *linphone_core_get_auth_info_list(const LinphoneCore *lc);
LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username); const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username);
void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *info); void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *info);
......
...@@ -792,9 +792,9 @@ void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, int ...@@ -792,9 +792,9 @@ void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, int
LinphoneAuthInfo *as=NULL; LinphoneAuthInfo *as=NULL;
/* see if we already have this auth information , not to ask it everytime to the user */ /* see if we already have this auth information , not to ask it everytime to the user */
if (prx_realm!=NULL) if (prx_realm!=NULL)
as=linphone_core_find_auth_info(lc,prx_realm,username); as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,prx_realm,username);
if (www_realm!=NULL) if (www_realm!=NULL)
as=linphone_core_find_auth_info(lc,www_realm,username); as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,www_realm,username);
if (as) as->first_time=TRUE; if (as) as->first_time=TRUE;
} }
......
...@@ -55,7 +55,7 @@ static gboolean do_login_noprompt(LinphoneProxyConfig *cfg){ ...@@ -55,7 +55,7 @@ static gboolean do_login_noprompt(LinphoneProxyConfig *cfg){
void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg){ void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg){
GtkWidget *mw=linphone_gtk_get_main_window(); GtkWidget *mw=linphone_gtk_get_main_window();
GtkWidget *label=linphone_gtk_get_widget(mw,"login_label"); GtkWidget *label=linphone_gtk_get_widget(mw,"login_label");
LinphoneAuthInfo *ai; const LinphoneAuthInfo *ai;
gchar *str; gchar *str;
LinphoneAddress *from; LinphoneAddress *from;
LinphoneCore *lc=linphone_gtk_get_core(); LinphoneCore *lc=linphone_gtk_get_core();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment