From 64ca9e82e581ea8f947e69274109a50ff902782c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 14 Jun 2016 11:44:43 +0200 Subject: [PATCH] Improved import friends from vcards feature + set bctoolbox logger in linphone tester --- coreapi/friendlist.c | 42 +++++++++++++++++++++++-------------- tester/liblinphone_tester.c | 3 +++ tester/vcard_tester.c | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index d48283d9b..9aeeff24a 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -768,24 +768,28 @@ LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list) { } int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *list, const char *vcard_file) { - MSList *vcards = linphone_vcard_list_from_vcard4_file(vcard_file); + MSList *vcards = NULL; + MSList *vcards_iterator = NULL; int count = 0; #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); - return -1; - } if (!list) { ms_error("Can't import into a NULL list"); return -1; } + + vcards = linphone_vcard_list_from_vcard4_file(vcard_file); + vcards_iterator = vcards; + if (!vcards) { + ms_error("Failed to parse the file %s", vcard_file); + return -1; + } - while (vcards != NULL && vcards->data != NULL) { - LinphoneVcard *vcard = (LinphoneVcard *)vcards->data; + while (vcards_iterator != NULL && vcards_iterator->data != NULL) { + LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data; LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { @@ -795,31 +799,36 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis } else { linphone_vcard_free(vcard); } - vcards = ms_list_next(vcards); + vcards_iterator = ms_list_next(vcards_iterator); } + ms_list_free(vcards); linphone_core_store_friends_list_in_db(list->lc, list); return count; } int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer) { - MSList *vcards = linphone_vcard_list_from_vcard4_buffer(vcard_buffer); + MSList *vcards = NULL; + MSList *vcards_iterator = NULL; int count = 0; #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"); - return -1; - } if (!list) { ms_error("Can't import into a NULL list"); return -1; } + + vcards = linphone_vcard_list_from_vcard4_buffer(vcard_buffer); + vcards_iterator = vcards; + if (!vcards) { + ms_error("Failed to parse the buffer"); + return -1; + } - while (vcards != NULL && vcards->data != NULL) { - LinphoneVcard *vcard = (LinphoneVcard *)vcards->data; + while (vcards_iterator != NULL && vcards_iterator->data != NULL) { + LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data; LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { @@ -829,8 +838,9 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l } else { linphone_vcard_free(vcard); } - vcards = ms_list_next(vcards); + vcards_iterator = ms_list_next(vcards_iterator); } + ms_list_free(vcards); linphone_core_store_friends_list_in_db(list->lc, list); return count; } diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 927ac8303..185f814e6 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -176,6 +176,7 @@ int liblinphone_tester_set_log_file(const char *filename) { return -1; } ms_message("Redirecting traces to file [%s]", filename); + bctbx_set_log_file(log_file); ortp_set_log_file(log_file); return 0; } @@ -212,8 +213,10 @@ int main (int argc, char *argv[]) for(i = 1; i < argc; ++i) { if (strcmp(argv[i], "--verbose") == 0) { + bctbx_set_log_level(NULL, BCTBX_LOG_MESSAGE); linphone_core_set_log_level(ORTP_MESSAGE); } else if (strcmp(argv[i], "--silent") == 0) { + bctbx_set_log_level(NULL, BCTBX_LOG_FATAL); linphone_core_set_log_level(ORTP_FATAL); } else if (strcmp(argv[i],"--log-file")==0){ CHECK_ARG("--log-file", ++i, argc); diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 9ea80266f..bbe135e77 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -35,7 +35,7 @@ static void linphone_vcard_import_export_friends_test(void) { char *export_filepath = bc_tester_file("export_vcards.vcf"); int count = 0; BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); - + count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath); BC_ASSERT_EQUAL(count, 3, int, "%d"); friends = linphone_friend_list_get_friends(lfl);