mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-29 17:29:20 +00:00
Improved import friends from vcards feature + set bctoolbox logger in linphone tester
This commit is contained in:
parent
71125c17d5
commit
64ca9e82e5
3 changed files with 30 additions and 17 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue