diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index 357ff0f4b..f4487a7ea 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -361,6 +361,7 @@ static LinphoneFriendList * linphone_friend_list_new(void) { LinphoneFriendList *list = belle_sip_object_new(LinphoneFriendList); list->cbs = linphone_friend_list_cbs_new(); list->enable_subscriptions = TRUE; + list->friends_map = bctbx_mmap_cchar_new(); return list; } @@ -532,6 +533,8 @@ LinphoneFriendListStatus linphone_friend_list_import_friend(LinphoneFriendList * lf->friend_list = list; lf->lc = list->lc; list->friends = bctbx_list_append(list->friends, linphone_friend_ref(lf)); + bctbx_pair_t *pair = (bctbx_pair_t*) bctbx_pair_cchar_new(lf->refkey, linphone_friend_ref(lf)); + bctbx_map_cchar_insert_and_delete(list->friends_map, pair); if (synchronize) { list->dirty_friends_to_update = bctbx_list_append(list->dirty_friends_to_update, linphone_friend_ref(lf)); } @@ -574,6 +577,8 @@ static LinphoneFriendListStatus _linphone_friend_list_remove_friend(LinphoneFrie lf->friend_list = NULL; linphone_friend_unref(lf); list->friends = bctbx_list_erase_link(list->friends, elem); + bctbx_iterator_t * it = bctbx_map_cchar_find_key(list->friends_map, lf->refkey); + bctbx_map_cchar_erase(list->friends_map, it); return LinphoneFriendListOK; } @@ -704,14 +709,12 @@ LinphoneFriend * linphone_friend_list_find_friend_by_uri(const LinphoneFriendLis } LinphoneFriend * linphone_friend_list_find_friend_by_ref_key(const LinphoneFriendList *list, const char *ref_key) { - const bctbx_list_t *elem; - if (ref_key == NULL) return NULL; - if (list == NULL) return NULL; - for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) { - LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem); - if ((lf->refkey != NULL) && (strcmp(lf->refkey, ref_key) == 0)) return lf; + bctbx_iterator_t* it = bctbx_map_cchar_find_key(list->friends_map, (void*)ref_key); + if (it == bctbx_map_cchar_end(list->friends_map)) { + return NULL; } - return NULL; + bctbx_pair_t *pair = bctbx_iterator_cchar_get_pair(it); + return (LinphoneFriend *)bctbx_pair_cchar_get_second(pair); } LinphoneFriend * linphone_friend_list_find_friend_by_inc_subscribe(const LinphoneFriendList *list, SalOp *op) { diff --git a/coreapi/private.h b/coreapi/private.h index fe3fea062..6170f6ba9 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -39,6 +39,7 @@ #include "carddav.h" #include "bctoolbox/port.h" +#include "bctoolbox/map.h" #include "bctoolbox/vfs.h" #include "belle-sip/belle-sip.h" /*we need this include for all http operations*/ @@ -779,6 +780,7 @@ struct _LinphoneFriendList { char *rls_uri; /*this field is take in sync with rls_addr*/ LinphoneAddress *rls_addr; MSList *friends; + bctbx_map_t *friends_map; unsigned char *content_digest; int expected_notification_version; unsigned int storage_id; diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index b65567a02..22eb3142f 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -793,6 +793,28 @@ static void carddav_server_to_client_and_client_to_sever_sync(void) { linphone_core_manager_destroy(manager); } +static void find_friend_by_ref_key_test(void) { + LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); + LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc); + LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "sip:toto@sip.linphone.org"); + LinphoneFriend *lf2 = NULL; + const LinphoneAddress *addr = NULL; + linphone_friend_set_ref_key(lf, "totorefkey"); + linphone_friend_list_add_friend(lfl, lf); + lf2 = linphone_friend_list_find_friend_by_ref_key(lfl, "totorefkey"); + BC_ASSERT_PTR_NOT_NULL(lf2); + if (!lf2) { + goto end; + } + addr = linphone_friend_get_address(lf2); + BC_ASSERT_STRING_EQUAL(linphone_address_as_string_uri_only(addr), "sip:toto@sip.linphone.org"); + BC_ASSERT_EQUAL(lf2, lf, void*, "%p"); + linphone_friend_unref(lf2); +end: + linphone_friend_unref(lf); + linphone_core_manager_destroy(manager); +} + test_t vcard_tests[] = { TEST_NO_TAG("Import / Export friends from vCards", linphone_vcard_import_export_friends_test), TEST_NO_TAG("Import a lot of friends from vCards", linphone_vcard_import_a_lot_of_friends_test), @@ -803,6 +825,7 @@ test_t vcard_tests[] = { TEST_NO_TAG("Friends storage migration from rc to db", friends_migration), TEST_NO_TAG("Friends storage in sqlite database", friends_sqlite_storage), #endif +<<<<<<< Updated upstream TEST_ONE_TAG("CardDAV clean", carddav_clean, "CardDAV"), // This is to ensure the content of the test addressbook is in the correct state for the following tests TEST_ONE_TAG("CardDAV synchronization", carddav_sync, "CardDAV"), TEST_ONE_TAG("CardDAV synchronization 2", carddav_sync_2, "CardDAV"), @@ -811,6 +834,17 @@ test_t vcard_tests[] = { TEST_ONE_TAG("CardDAV integration", carddav_integration, "CardDAV"), TEST_ONE_TAG("CardDAV multiple synchronizations", carddav_multiple_sync, "CardDAV"), TEST_ONE_TAG("CardDAV client to server and server to client sync", carddav_server_to_client_and_client_to_sever_sync, "CardDAV") +======= + TEST_NO_TAG("CardDAV clean", carddav_clean), // This is to ensure the content of the test addressbook is in the correct state for the following tests + TEST_NO_TAG("CardDAV synchronization", carddav_sync), + TEST_NO_TAG("CardDAV synchronization 2", carddav_sync_2), + TEST_NO_TAG("CardDAV synchronization 3", carddav_sync_3), + TEST_NO_TAG("CardDAV synchronization 4", carddav_sync_4), + TEST_NO_TAG("CardDAV integration", carddav_integration), + TEST_NO_TAG("CardDAV multiple synchronizations", carddav_multiple_sync), + TEST_NO_TAG("CardDAV client to server and server to client sync", carddav_server_to_client_and_client_to_sever_sync), + TEST_NO_TAG("Find friend by ref key", find_friend_by_ref_key_test) +>>>>>>> Stashed changes }; test_suite_t vcard_test_suite = {