]> sjero.net Git - linphone/blobdiff - coreapi/authentication.c
Aac-eld add missing header according to RFC3640 3.3.6
[linphone] / coreapi / authentication.c
index 24bed1c437dd22f3d9057d4c01e3879b97a6e949..8ab1c21ffdb406ecba2ebc1f8e82f5a4677dc687 100644 (file)
@@ -80,6 +80,13 @@ const char *linphone_auth_info_get_userid(const LinphoneAuthInfo *i){
        return i->userid;
 }
 
+const char *linphone_auth_info_get_realm(const LinphoneAuthInfo *i){
+       return i->realm;
+}
+const char *linphone_auth_info_get_ha1(const LinphoneAuthInfo *i){
+       return i->ha1;
+}
+
 /**
  * Sets the password.
 **/
@@ -113,6 +120,27 @@ void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid){
        if (userid && strlen(userid)>0) info->userid=ms_strdup(userid);
 }
 
+/**
+ * Sets realm.
+**/
+void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm){
+       if (info->realm){
+               ms_free(info->realm);
+               info->realm=NULL;
+       }
+       if (realm && strlen(realm)>0) info->realm=ms_strdup(realm);
+}
+/**
+ * Sets ha1.
+**/
+void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1){
+       if (info->ha1){
+               ms_free(info->ha1);
+               info->ha1=NULL;
+       }
+       if (ha1 && strlen(ha1)>0) info->ha1=ms_strdup(ha1);
+}
+
 /**
  * Destroys a LinphoneAuthInfo object.
 **/
@@ -131,7 +159,7 @@ void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, in
        sprintf(key,"auth_info_%i",pos);
        lp_config_clean_section(config,key);
        
-       if (obj==NULL){
+       if (obj==NULL || lp_config_get_int(config, "sip", "store_auth_info", 1) == 0){
                return;
        }               
        if (obj->username!=NULL){
@@ -237,6 +265,18 @@ const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const cha
        return ret;
 }
 
+static void write_auth_infos(LinphoneCore *lc){
+       MSList *elem;
+       int i;
+
+       if (!linphone_core_ready(lc)) return;
+       for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
+               LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
+               linphone_auth_info_write_config(lc->config,ai,i);
+       }
+       linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
+}
+
 /**
  * Adds authentication information to the LinphoneCore.
  * 
@@ -246,6 +286,7 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
 {
        LinphoneAuthInfo *ai;
        MSList *elem;
+       MSList *l;
        
        /* find if we are attempting to modify an existing auth info */
        ai=(LinphoneAuthInfo*)linphone_core_find_auth_info(lc,info->realm,info->username);
@@ -255,7 +296,7 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
        }
        lc->auth_info=ms_list_append(lc->auth_info,linphone_auth_info_clone(info));
        /* retry pending authentication operations */
-       for(elem=sal_get_pending_auths(lc->sal);elem!=NULL;elem=elem->next){
+       for(l=elem=sal_get_pending_auths(lc->sal);elem!=NULL;elem=elem->next){
                const char *username,*realm;
                SalOp *op=(SalOp*)elem->data;
                LinphoneAuthInfo *ai;
@@ -271,6 +312,8 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
                        ai->usecount++;
                }
        }
+       ms_list_free(l);
+       write_auth_infos(lc);
 }
 
 
@@ -285,18 +328,13 @@ void linphone_core_abort_authentication(LinphoneCore *lc,  LinphoneAuthInfo *inf
  * Removes an authentication information object.
 **/
 void linphone_core_remove_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info){
-       int i;
-       MSList *elem;
        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);
+               write_auth_infos(lc);
        }
 }