Commit 64ca9e82 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improved import friends from vcards feature + set bctoolbox logger in linphone tester

parent 71125c17
...@@ -768,24 +768,28 @@ LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list) { ...@@ -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) { 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; int count = 0;
#ifndef VCARD_ENABLED #ifndef VCARD_ENABLED
ms_error("vCard support wasn't enabled at compilation time"); ms_error("vCard support wasn't enabled at compilation time");
return -1; return -1;
#endif #endif
if (!vcards) {
ms_error("Failed to parse the file %s", vcard_file);
return -1;
}
if (!list) { if (!list) {
ms_error("Can't import into a NULL list"); ms_error("Can't import into a NULL list");
return -1; 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) { while (vcards_iterator != NULL && vcards_iterator->data != NULL) {
LinphoneVcard *vcard = (LinphoneVcard *)vcards->data; LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data;
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
if (lf) { if (lf) {
if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { 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 ...@@ -795,31 +799,36 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis
} else { } else {
linphone_vcard_free(vcard); 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); linphone_core_store_friends_list_in_db(list->lc, list);
return count; return count;
} }
int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer) { 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; int count = 0;
#ifndef VCARD_ENABLED #ifndef VCARD_ENABLED
ms_error("vCard support wasn't enabled at compilation time"); ms_error("vCard support wasn't enabled at compilation time");
return -1; return -1;
#endif #endif
if (!vcards) {
ms_error("Failed to parse the buffer");
return -1;
}
if (!list) { if (!list) {
ms_error("Can't import into a NULL list"); ms_error("Can't import into a NULL list");
return -1; 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) { while (vcards_iterator != NULL && vcards_iterator->data != NULL) {
LinphoneVcard *vcard = (LinphoneVcard *)vcards->data; LinphoneVcard *vcard = (LinphoneVcard *)vcards_iterator->data;
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
if (lf) { if (lf) {
if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) { 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 ...@@ -829,8 +838,9 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l
} else { } else {
linphone_vcard_free(vcard); 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); linphone_core_store_friends_list_in_db(list->lc, list);
return count; return count;
} }
......
...@@ -176,6 +176,7 @@ int liblinphone_tester_set_log_file(const char *filename) { ...@@ -176,6 +176,7 @@ int liblinphone_tester_set_log_file(const char *filename) {
return -1; return -1;
} }
ms_message("Redirecting traces to file [%s]", filename); ms_message("Redirecting traces to file [%s]", filename);
bctbx_set_log_file(log_file);
ortp_set_log_file(log_file); ortp_set_log_file(log_file);
return 0; return 0;
} }
...@@ -212,8 +213,10 @@ int main (int argc, char *argv[]) ...@@ -212,8 +213,10 @@ int main (int argc, char *argv[])
for(i = 1; i < argc; ++i) { for(i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--verbose") == 0) { if (strcmp(argv[i], "--verbose") == 0) {
bctbx_set_log_level(NULL, BCTBX_LOG_MESSAGE);
linphone_core_set_log_level(ORTP_MESSAGE); linphone_core_set_log_level(ORTP_MESSAGE);
} else if (strcmp(argv[i], "--silent") == 0) { } else if (strcmp(argv[i], "--silent") == 0) {
bctbx_set_log_level(NULL, BCTBX_LOG_FATAL);
linphone_core_set_log_level(ORTP_FATAL); linphone_core_set_log_level(ORTP_FATAL);
} else if (strcmp(argv[i],"--log-file")==0){ } else if (strcmp(argv[i],"--log-file")==0){
CHECK_ARG("--log-file", ++i, argc); CHECK_ARG("--log-file", ++i, argc);
......
...@@ -35,7 +35,7 @@ static void linphone_vcard_import_export_friends_test(void) { ...@@ -35,7 +35,7 @@ static void linphone_vcard_import_export_friends_test(void) {
char *export_filepath = bc_tester_file("export_vcards.vcf"); char *export_filepath = bc_tester_file("export_vcards.vcf");
int count = 0; int count = 0;
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath); count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
BC_ASSERT_EQUAL(count, 3, int, "%d"); BC_ASSERT_EQUAL(count, 3, int, "%d");
friends = linphone_friend_list_get_friends(lfl); friends = linphone_friend_list_get_friends(lfl);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment