]> sjero.net Git - linphone/commitdiff
modify the way LinphoneAuthInfo are managed.
authorSimon Morlat <simon.morlat@linphone.org>
Fri, 12 Feb 2010 10:29:27 +0000 (11:29 +0100)
committerSimon Morlat <simon.morlat@linphone.org>
Fri, 12 Feb 2010 10:29:27 +0000 (11:29 +0100)
coreapi/authentication.c
coreapi/linphonecore.h
coreapi/proxy.c
gtk-glade/loginframe.c

index ee360ecfe0f966a86415f4f813a0771a87a04432..6185048849e5bc8baa79f5df6b2724ded46fcb98 100644 (file)
@@ -55,6 +55,18 @@ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *useri
        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.
 **/
@@ -180,7 +192,7 @@ static int realm_match(const char *realm1, const char *realm2){
 /**
  * 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;
        LinphoneAuthInfo *ret=NULL,*candidate=NULL;
@@ -232,24 +244,18 @@ static void refresh_exosip_auth_info(LinphoneCore *lc){
  * 
  * 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;
        
        /* 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){
-               elem=ms_list_find(lc->auth_info,ai);
-               if (elem==NULL){
-                       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_remove(lc->auth_info,ai);
+               linphone_auth_info_destroy(ai);
        }
+       lc->auth_info=ms_list_append(lc->auth_info,linphone_auth_info_clone(info));
+
        refresh_exosip_auth_info(lc);
        /* if the user was prompted, re-allow automatic_action */
        if (lc->automatic_action>0) lc->automatic_action--;
@@ -267,23 +273,21 @@ void linphone_core_abort_authentication(LinphoneCore *lc,  LinphoneAuthInfo *inf
 /**
  * Removes an authentication information object.
 **/
-void linphone_core_remove_auth_info(LinphoneCore *lc, LinphoneAuthInfo *info){
-       int len=ms_list_size(lc->auth_info);
-       int newlen;
+void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
        int i;
        MSList *elem;
-       lc->auth_info=ms_list_remove(lc->auth_info,info);
-       newlen=ms_list_size(lc->auth_info);
-       /*printf("len=%i newlen=%i\n",len,newlen);*/
-       linphone_auth_info_destroy(info);
-       for (i=0;i<len;i++){
+       LinphoneAuthInfo *r;
+       r=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username);
+       if (r){
+               lc->auth_info=ms_list_remove(lc->auth_info,r);
+               /*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);
+               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){
        }
        /* 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);
+               as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,prx_realm,username);
        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){
                ms_message("Authentication for user=%s realm=%s is working.",username,prx_realm ? prx_realm : www_realm);
                as->works=TRUE;
@@ -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)
 {
-       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 (lc->vtable.auth_info_requested!=NULL){
                        lc->vtable.auth_info_requested(lc,realm,username);
index f8d505058859c00fc9b4c5c6b54e90078c6a4c1e..795d91c971f1235aaffb0fdac9d2ba0b5b2e994b 100644 (file)
@@ -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);
 
-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);
 
-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);
 
index 437c85e60eac472a9254f0074cbab57cd6a5efa6..4a9720a35a58d42602a0aa96939c1f1aee2ebe7d 100644 (file)
@@ -792,9 +792,9 @@ void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, int
                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);
+                       as=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,prx_realm,username);
                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;
        }
index d4ed36974b9fdcf6631706a3777f06162f7bdcfb..c6f310b4e24a2199823e7d4ca6c57ae5825f1edd 100644 (file)
@@ -55,7 +55,7 @@ static gboolean do_login_noprompt(LinphoneProxyConfig *cfg){
 void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg){
        GtkWidget *mw=linphone_gtk_get_main_window();
        GtkWidget *label=linphone_gtk_get_widget(mw,"login_label");
-       LinphoneAuthInfo *ai;
+       const LinphoneAuthInfo *ai;
        gchar *str;
        LinphoneAddress *from;
        LinphoneCore *lc=linphone_gtk_get_core();