From f5f80c92bd4545881279014b0151e2092b07759e Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 22 Apr 2016 10:51:52 +0200 Subject: [PATCH] Few fixes for when using friends without the database storage --- coreapi/friend.c | 8 ++++++-- coreapi/friendlist.c | 13 ++++--------- coreapi/linphonefriend.h | 7 +++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index 5abe5896e..fe8ed3c09 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -601,8 +601,13 @@ void linphone_friend_update_subscribes(LinphoneFriend *fr, LinphoneProxyConfig * } void linphone_friend_save(LinphoneFriend *fr, LinphoneCore *lc) { + if (!lc) return; #ifdef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_store_friend_in_db(lc, fr); + if (lc->friends_db_file) { + linphone_core_store_friend_in_db(lc, fr); + } else { + linphone_core_write_friends_config(lc); + } #else linphone_core_write_friends_config(lc); #endif @@ -690,7 +695,6 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) { } if (linphone_core_ready(lc)) linphone_friend_apply(lf, lc); else lf->commit = TRUE; - linphone_friend_save(lf, lc); } void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend *lf) { diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index ec299cd29..a317ab1c8 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -431,9 +431,7 @@ LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList * if (synchronize) { list->dirty_friends_to_update = ms_list_append(list->dirty_friends_to_update, linphone_friend_ref(lf)); } -#ifdef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_store_friend_in_db(lf->lc, lf); -#endif + linphone_friend_save(lf, lf->lc); return LinphoneFriendListOK; } @@ -466,6 +464,9 @@ static LinphoneFriendListStatus _linphone_friend_list_remove_friend(LinphoneFrie } } } + if (!list->lc->friends_db_file) { + linphone_core_write_friends_config(list->lc); + } lf->friend_list = NULL; linphone_friend_unref(lf); @@ -785,9 +786,6 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis } vcards = ms_list_next(vcards); } -#ifndef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_write_friends_config(list->lc); -#endif return count; } @@ -821,9 +819,6 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l } vcards = ms_list_next(vcards); } -#ifndef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_write_friends_config(list->lc); -#endif return count; } diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index 693ee90f1..80192471a 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -519,6 +519,13 @@ LINPHONE_PUBLIC void linphone_core_set_friends_database_path(LinphoneCore *lc, c **/ LINPHONE_PUBLIC void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc); +/** + * Saves a friend either in database if configured, otherwise in linphonerc + * @param fr the linphone friend to save + * @param lc the linphone core + */ +void linphone_friend_save(LinphoneFriend *fr, LinphoneCore *lc); + /** * @} */