Commit caf26c0b authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improved a few more things regarding friends and vcards

parent 9b6a6ca7
...@@ -200,33 +200,43 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char ...@@ -200,33 +200,43 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){ int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){
LinphoneAddress *fr = linphone_address_clone(addr); LinphoneAddress *fr = linphone_address_clone(addr);
LinphoneVCard *vcard = NULL;
linphone_address_clean(fr); linphone_address_clean(fr);
if (lf->uri != NULL) linphone_address_destroy(lf->uri); if (lf->uri != NULL) linphone_address_destroy(lf->uri);
lf->uri = fr; 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; return 0;
} }
int linphone_friend_set_name(LinphoneFriend *lf, const char *name){ int linphone_friend_set_name(LinphoneFriend *lf, const char *name){
LinphoneAddress *fr = lf->uri; LinphoneAddress *fr = lf->uri;
LinphoneVCard *vcard = NULL; LinphoneVCard *vcard = NULL;
bool_t vcard_created = FALSE;
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);
vcard = linphone_friend_get_vcard(lf); vcard = linphone_friend_get_vcard(lf);
if (!vcard) { if (!vcard) {
linphone_friend_create_vcard(lf, name); linphone_friend_create_vcard(lf, name);
vcard = linphone_friend_get_vcard(lf); vcard = linphone_friend_get_vcard(lf);
} vcard_created = TRUE;
}
if (vcard) { if (vcard) {
linphone_vcard_set_full_name(vcard, name); 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; return 0;
} }
...@@ -531,6 +541,10 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) { ...@@ -531,6 +541,10 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) {
} }
void linphone_core_import_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)); lc->friends = ms_list_append(lc->friends, linphone_friend_ref(lf));
if (linphone_core_ready(lc)) linphone_friend_apply(lf, lc); if (linphone_core_ready(lc)) linphone_friend_apply(lf, lc);
else lf->commit = TRUE; else lf->commit = TRUE;
...@@ -833,7 +847,8 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char * ...@@ -833,7 +847,8 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data; LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
if (lf) { if (lf) {
linphone_core_add_friend(lc, lf); linphone_core_import_friend(lc, lf);
linphone_friend_unref(lf);
count++; count++;
} }
vcards = ms_list_next(vcards); vcards = ms_list_next(vcards);
......
...@@ -6424,6 +6424,7 @@ static void linphone_core_uninit(LinphoneCore *lc) ...@@ -6424,6 +6424,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
if (lc->chat_db_file){ if (lc->chat_db_file){
ms_free(lc->chat_db_file); ms_free(lc->chat_db_file);
} }
linphone_core_free_payload_types(lc); linphone_core_free_payload_types(lc);
if (lc->supported_formats) ms_free(lc->supported_formats); if (lc->supported_formats) ms_free(lc->supported_formats);
linphone_core_message_storage_close(lc); linphone_core_message_storage_close(lc);
......
...@@ -59,14 +59,16 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { ...@@ -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"); char *import_filepath = bc_tester_res("common/thousand_vcards.vcf");
clock_t start, end; clock_t start, end;
double elapsed = 0; double elapsed = 0;
const MSList *friends = NULL;
start = clock(); start = clock();
linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath); linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath);
end = clock(); end = clock();
friends = linphone_core_get_friend_list(manager->lc);
elapsed = (double)(end - start); elapsed = (double)(end - start);
ms_error("Imported a thousand of friends in %f seconds", elapsed / CLOCKS_PER_SEC); 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 < 2500000); // 2.5 seconds BC_ASSERT_TRUE(elapsed < 5000000); // 5 seconds
linphone_core_manager_destroy(manager); linphone_core_manager_destroy(manager);
} }
......
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