From b88693f4f464e30ba55e2d909c2e25c844a8ae3c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 9 Mar 2016 17:04:51 +0100 Subject: [PATCH] Fix contacts migration from rc to db --- coreapi/friend.c | 7 +++++++ coreapi/friendlist.c | 4 +++- tester/vcard_tester.c | 14 +++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index b4adc6f8f..1a749bbd9 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -1366,6 +1366,13 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) { return; } + if (ms_list_size(linphone_friend_list_get_friends(lfl)) > 0) { + linphone_core_remove_friend_list(lc, lfl); + lfl = linphone_core_create_friend_list(lc); + linphone_core_add_friend_list(lc, lfl); + linphone_friend_list_unref(lfl); + } + for (i = 0; (lf = linphone_friend_new_from_config_file(lc, i)) != NULL; i++) { char friend_section[32]; diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index c3d46815f..f2edbff46 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -445,7 +445,9 @@ static LinphoneFriendListStatus _linphone_friend_list_remove_friend(LinphoneFrie if (elem == NULL) return LinphoneFriendListNonExistentFriend; #ifdef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_remove_friend_from_db(lf->lc, lf); + if (lf && lf->lc && lf->lc->friends_db) { + linphone_core_remove_friend_from_db(lf->lc, lf); + } #endif if (remove_from_server) { LinphoneVcard *lvc = linphone_friend_get_vcard(lf); diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 9ffc0887f..52eaa8f25 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -155,18 +155,22 @@ static void friends_if_no_db_set(void) { #ifdef FRIENDS_SQL_STORAGE_ENABLED static void friends_migration(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE); + LpConfig *lpc = linphone_core_get_config(manager->lc); LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc); const MSList *friends = linphone_friend_list_get_friends(lfl); MSList *friends_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); - BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); + BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); + BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 0, int, "%i"); unlink(friends_db); linphone_core_set_friends_database_path(manager->lc, friends_db); + lfl = linphone_core_get_default_friend_list(manager->lc); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d"); + BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 1, int, "%i"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); unlink(friends_db); @@ -181,12 +185,16 @@ typedef struct _LinphoneFriendListStats { static void friend_list_created_cb(LinphoneCore *lc, LinphoneFriendList *list) { LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list); - stats->new_list_count++; + if (stats) { + stats->new_list_count++; + } } static void friend_list_removed_cb(LinphoneCore *lc, LinphoneFriendList *list) { LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list); - stats->removed_list_count++; + if (stats) { + stats->removed_list_count++; + } } static void friends_sqlite_storage(void) {