From 06f9d69a78f62ae3f3a4fb7294962844ee7b3cfc Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 1 Feb 2016 15:42:02 +0100 Subject: [PATCH] Added vtable callbacks for friend list created / removed + tests --- coreapi/friend.c | 2 ++ coreapi/linphonecore.c | 8 +++--- coreapi/linphonecore.h | 16 +++++++++++ coreapi/private.h | 2 ++ coreapi/vtables.c | 10 +++++++ tester/vcard_tester.c | 60 +++++++++++++++++++++++++++++++----------- 6 files changed, 80 insertions(+), 18 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index ca5a3a13b..4f245f6a7 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -918,6 +918,7 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char * #ifndef VCARD_ENABLED ms_error("vCard support wasn't enabled at compilation time"); + return -1; #endif if (!vcards) { ms_error("Failed to parse the file %s", vcard_file); @@ -948,6 +949,7 @@ int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char #ifndef VCARD_ENABLED ms_error("vCard support wasn't enabled at compilation time"); + return -1; #endif if (!vcards) { ms_error("Failed to parse the buffer"); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 54303df26..93791eafe 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1937,12 +1937,13 @@ LinphoneFriendList* linphone_core_get_default_friend_list(const LinphoneCore *lc void linphone_core_remove_friend_list(LinphoneCore *lc, LinphoneFriendList *list) { MSList *elem = ms_list_find(lc->friends_lists, list); if (elem == NULL) return; - list->lc = NULL; - linphone_friend_list_unref(list); - lc->friends_lists = ms_list_remove_link(lc->friends_lists, elem); #ifdef FRIENDS_SQL_STORAGE_ENABLED linphone_core_remove_friends_list_from_db(lc, list); #endif + linphone_core_notify_friend_list_removed(lc, list); + list->lc = NULL; + linphone_friend_list_unref(list); + lc->friends_lists = ms_list_remove_link(lc->friends_lists, elem); } void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) { @@ -1954,6 +1955,7 @@ void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) { #ifdef FRIENDS_SQL_STORAGE_ENABLED linphone_core_store_friends_list_in_db(lc, list); #endif + linphone_core_notify_friend_list_created(lc, list); } else { const char *rls_uri = lp_config_get_string(lc->config, "sip", "rls_uri", NULL); list = linphone_core_create_friend_list(lc); diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index a68ba9556..a0f069657 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -2068,6 +2068,20 @@ typedef void (*LinphoneCoreLogCollectionUploadStateChangedCb)(LinphoneCore *lc, */ typedef void (*LinphoneCoreLogCollectionUploadProgressIndicationCb)(LinphoneCore *lc, size_t offset, size_t total); +/** + * Callback prototype for reporting when a friend list has been added to the core friends list. + * @param[in] lc LinphoneCore object + * @param[in] list LinphoneFriendList object + */ +typedef void (*LinphoneCoreFriendListCreatedCb) (LinphoneCore *lc, LinphoneFriendList *list); + +/** + * Callback prototype for reporting when a friend list has been removed from the core friends list. + * @param[in] lc LinphoneCore object + * @param[in] list LinphoneFriendList object + */ +typedef void (*LinphoneCoreFriendListRemovedCb) (LinphoneCore *lc, LinphoneFriendList *list); + /** * This structure holds all callbacks that the application should implement. * None is mandatory. @@ -2105,6 +2119,8 @@ typedef struct _LinphoneCoreVTable{ LinphoneCoreNetworkReachableCb network_reachable; /**< Callback to report IP network status (I.E up/down )*/ LinphoneCoreLogCollectionUploadStateChangedCb log_collection_upload_state_changed; /**< Callback to upload collected logs */ LinphoneCoreLogCollectionUploadProgressIndicationCb log_collection_upload_progress_indication; /**< Callback to indicate log collection upload progress */ + LinphoneCoreFriendListCreatedCb friend_list_created; + LinphoneCoreFriendListRemovedCb friend_list_removed; void *user_data; /**valid=1; diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index b06d7e9f1..7fb0272a4 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -133,22 +133,46 @@ end: linphone_core_manager_destroy(manager); } +typedef struct _LinphoneFriendListStats { + int new_list_count; + int removed_list_count; +} 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++; +} + +static void friend_list_removed_cb(LinphoneCore *lc, LinphoneFriendList *list) { + LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list); + stats->removed_list_count++; +} + static void friends_sqlite_storage(void) { - LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); - LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); - LinphoneVCard *lvc = linphone_vcard_new(); + LinphoneCoreVTable *v_table = linphone_core_v_table_new(); + LinphoneCore* lc = NULL; + LinphoneFriendList *lfl = NULL; LinphoneFriend *lf = NULL; LinphoneFriend *lf2 = NULL; + LinphoneVCard *lvc = linphone_vcard_new(); LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org"); - const MSList *friends = linphone_core_get_friend_list(manager->lc); + const MSList *friends = NULL; MSList *friends_from_db = NULL; MSList *friends_lists_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); + LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); + + v_table->friend_list_created = friend_list_created_cb; + v_table->friend_list_removed = friend_list_removed_cb; + lc = linphone_core_new(v_table, NULL, NULL, NULL); + friends = linphone_core_get_friend_list(lc); + lfl = linphone_core_create_friend_list(lc); + linphone_friend_list_set_user_data(lfl, stats); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); unlink(friends_db); - linphone_core_set_friends_database_path(manager->lc, friends_db); - friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, linphone_core_get_default_friend_list(manager->lc)); + linphone_core_set_friends_database_path(lc, friends_db); + friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); linphone_vcard_set_etag(lvc, "\"123-456789\""); @@ -157,7 +181,9 @@ static void friends_sqlite_storage(void) { linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); - linphone_core_add_friend_list(manager->lc, lfl); + linphone_core_add_friend_list(lc, lfl); + wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000); + BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i"); linphone_friend_list_unref(lfl); linphone_friend_list_set_display_name(lfl, "Test"); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i"); @@ -165,10 +191,10 @@ static void friends_sqlite_storage(void) { BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d"); BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d"); - friends = linphone_core_get_friend_list(manager->lc); + friends = linphone_core_get_friend_list(lc); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); - friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(manager->lc); + friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc); BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d"); friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends; BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); @@ -177,7 +203,7 @@ static void friends_sqlite_storage(void) { BC_ASSERT_PTR_NOT_NULL(lf2->friend_list); friends_lists_from_db = ms_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref); - friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); + friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; @@ -193,7 +219,7 @@ static void friends_sqlite_storage(void) { linphone_friend_set_name(lf, "Margaux"); linphone_friend_done(lf); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); - friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); + friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; @@ -202,17 +228,21 @@ static void friends_sqlite_storage(void) { BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); - linphone_core_remove_friend(manager->lc, lf); - friends = linphone_core_get_friend_list(manager->lc); + linphone_core_remove_friend(lc, lf); + friends = linphone_core_get_friend_list(lc); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); - friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); + friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); + + linphone_core_remove_friend_list(lc, lfl); + wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000); + BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i"); end: unlink(friends_db); ms_free(friends_db); linphone_address_unref(addr); - linphone_core_manager_destroy(manager); + linphone_core_destroy(lc); } #endif