diff --git a/coreapi/friend.c b/coreapi/friend.c index 44a764718..bc0341f15 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -200,34 +200,44 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){ LinphoneAddress *fr = linphone_address_clone(addr); + LinphoneVCard *vcard = NULL; linphone_address_clean(fr); if (lf->uri != NULL) linphone_address_destroy(lf->uri); lf->uri = fr; + vcard = linphone_friend_get_vcard(lf); + if (vcard) { + linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); + } + return 0; } int linphone_friend_set_name(LinphoneFriend *lf, const char *name){ LinphoneAddress *fr = lf->uri; LinphoneVCard *vcard = NULL; - - if (fr == NULL) { - ms_error("linphone_friend_set_address() must be called before linphone_friend_set_name()."); - return -1; - } - linphone_address_set_display_name(fr, name); + bool_t vcard_created = FALSE; vcard = linphone_friend_get_vcard(lf); if (!vcard) { linphone_friend_create_vcard(lf, name); vcard = linphone_friend_get_vcard(lf); - } + vcard_created = TRUE; + } if (vcard) { linphone_vcard_set_full_name(vcard, name); - linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); + if (fr && vcard_created) { // SIP address wasn't set yet, let's do it + linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); + } } + if (!fr) { + ms_warning("linphone_friend_set_address() must be called before linphone_friend_set_name() to be able to set display name."); + return -1; + } + linphone_address_set_display_name(fr, name); + return 0; } @@ -531,6 +541,10 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) { } void linphone_core_import_friend(LinphoneCore *lc, LinphoneFriend *lf) { + if (!lf->uri) { + return; // Do not abort if friend doesn't have a SIP URI + } + lf->lc = lc; lc->friends = ms_list_append(lc->friends, linphone_friend_ref(lf)); if (linphone_core_ready(lc)) linphone_friend_apply(lf, lc); else lf->commit = TRUE; @@ -833,7 +847,8 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char * LinphoneVCard *vcard = (LinphoneVCard *)vcards->data; LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { - linphone_core_add_friend(lc, lf); + linphone_core_import_friend(lc, lf); + linphone_friend_unref(lf); count++; } vcards = ms_list_next(vcards); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 34a5f6717..271570951 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6424,6 +6424,7 @@ static void linphone_core_uninit(LinphoneCore *lc) if (lc->chat_db_file){ ms_free(lc->chat_db_file); } + linphone_core_free_payload_types(lc); if (lc->supported_formats) ms_free(lc->supported_formats); linphone_core_message_storage_close(lc); diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 81686c230..46efdc0f2 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -59,14 +59,16 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { char *import_filepath = bc_tester_res("common/thousand_vcards.vcf"); clock_t start, end; double elapsed = 0; + const MSList *friends = NULL; start = clock(); linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath); end = clock(); + friends = linphone_core_get_friend_list(manager->lc); elapsed = (double)(end - start); - ms_error("Imported a thousand of friends in %f seconds", elapsed / CLOCKS_PER_SEC); - BC_ASSERT_TRUE(elapsed < 2500000); // 2.5 seconds + ms_error("Imported a thousand of vCards (only %i friends with SIP address found) in %f seconds", ms_list_size(friends), elapsed / CLOCKS_PER_SEC); + BC_ASSERT_TRUE(elapsed < 5000000); // 5 seconds linphone_core_manager_destroy(manager); }