int linphone_friend_set_name(LinphoneFriend *lf, const char *name){ LinphoneAddress *fr = lf->uri; LinphoneVcard *vcard = NULL; 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); 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 && !vcard) { ms_warning("linphone_friend_set_address() must be called before linphone_friend_set_name() to be able to set display name."); return -1; } else if (fr) { linphone_address_set_display_name(fr, name); } return 0; }
static void linphone_vcard_update_existing_friends_test(void) { LinphoneFriend *lf = linphone_friend_new_with_addr("sip:[email protected]"); BC_ASSERT_PTR_NOT_NULL_FATAL(lf); BC_ASSERT_PTR_NULL(linphone_friend_get_vcard(lf)); linphone_friend_edit(lf); linphone_friend_set_name(lf, "Old Friend"); linphone_friend_done(lf); BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_vcard(lf)); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_full_name(linphone_friend_get_vcard(lf)), "Old Friend"); linphone_friend_unref(lf); lf = NULL; }
void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) { LpConfig *lpc = NULL; LinphoneFriend *lf = NULL; LinphoneFriendList *lfl = linphone_core_get_default_friend_list(lc); int i; #ifndef SQLITE_STORAGE_ENABLED ms_warning("linphone has been compiled without sqlite, can't migrate friends"); return; #endif if (!lc) { return; } lpc = linphone_core_get_config(lc); if (!lpc) { ms_warning("this core has been started without a rc file, nothing to migrate"); return; } if (lp_config_get_int(lpc, "misc", "friends_migration_done", 0) == 1) { ms_warning("the friends migration has already been done, skipping..."); return; } if (bctbx_list_size(linphone_friend_list_get_friends(lfl)) > 0 && lfl->storage_id == 0) { linphone_core_remove_friend_list(lc, lfl); lfl = linphone_core_create_friend_list(lc); linphone_core_add_friend_list(lc, lfl); linphone_friend_list_unref(lfl); } for (i = 0; (lf = linphone_friend_new_from_config_file(lc, i)) != NULL; i++) { char friend_section[32]; const LinphoneAddress *addr = linphone_friend_get_address(lf); if (addr) { const char *displayName = linphone_address_get_display_name(addr); char *address = NULL; if (!displayName) { displayName = linphone_address_get_username(addr); } address = linphone_address_as_string(addr); if (!linphone_friend_create_vcard(lf, displayName)) { ms_warning("Couldn't create vCard for friend %s", address); } else { linphone_vcard_add_sip_address(linphone_friend_get_vcard(lf), address); } ms_free(address); linphone_friend_list_add_friend(lfl, lf); linphone_friend_unref(lf); snprintf(friend_section, sizeof(friend_section), "friend_%i", i); lp_config_clean_section(lpc, friend_section); } } ms_debug("friends migration successful: %i friends migrated", i); lp_config_set_int(lpc, "misc", "friends_migration_done", 1); }
void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file) { FILE *file = NULL; const bctbx_list_t *friends = linphone_friend_list_get_friends(list); file = fopen(vcard_file, "wb"); if (file == NULL) { ms_warning("Could not write %s ! Maybe it is read-only. Contacts will not be saved.", vcard_file); return; } #ifndef VCARD_ENABLED ms_error("vCard support wasn't enabled at compilation time"); #endif while (friends != NULL && friends->data != NULL) { LinphoneFriend *lf = (LinphoneFriend *)friends->data; LinphoneVcard *vcard = linphone_friend_get_vcard(lf); if (vcard) { const char *vcard_text = linphone_vcard_as_vcard4_string(vcard); fprintf(file, "%s", vcard_text); } else { ms_warning("Couldn't export friend %s because it doesn't have a vCard attached", linphone_address_as_string(linphone_friend_get_address(lf))); } friends = bctbx_list_next(friends); } fclose(file); }
static LinphoneFriendListStatus _linphone_friend_list_remove_friend(LinphoneFriendList *list, LinphoneFriend *lf, bool_t remove_from_server) { bctbx_list_t *elem = bctbx_list_find(list->friends, lf); if (elem == NULL) return LinphoneFriendListNonExistentFriend; #ifdef SQLITE_STORAGE_ENABLED if (lf && lf->lc && lf->lc->friends_db) { linphone_core_remove_friend_from_db(lf->lc, lf); } #endif if (remove_from_server) { LinphoneVcard *lvc = linphone_friend_get_vcard(lf); if (lvc && linphone_vcard_get_uid(lvc)) { LinphoneCardDavContext *cdc = linphone_carddav_context_new(list); if (cdc) { cdc->sync_done_cb = carddav_done; if (cdc->friend_list->cbs->sync_state_changed_cb) { cdc->friend_list->cbs->sync_state_changed_cb(cdc->friend_list, LinphoneFriendListSyncStarted, NULL); } linphone_carddav_delete_vcard(cdc, lf); } } } if (!list->lc->friends_db_file) { linphone_core_write_friends_config(list->lc); } lf->friend_list = NULL; linphone_friend_unref(lf); list->friends = bctbx_list_remove_link(list->friends, elem); return LinphoneFriendListOK; }
MSList* linphone_friend_get_addresses(LinphoneFriend *lf) { LinphoneVcard *vcard = NULL; MSList *sipAddresses = NULL; MSList *addresses = NULL; MSList *iterator = NULL; if (!lf) { return NULL; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return NULL; } sipAddresses = linphone_vcard_get_sip_addresses(vcard); iterator = sipAddresses; while (iterator) { const char *sipAddress = (const char *)iterator->data; LinphoneAddress *addr = linphone_address_new(sipAddress); if (addr) { addresses = ms_list_append(addresses, addr); } iterator = ms_list_next(iterator); } if (sipAddresses) ms_list_free(sipAddresses); return addresses; }
void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) { if (lc && lc->friends_db) { char *buf; int store_friends = lp_config_get_int(lc->config, "misc", "store_friends", 1); LinphoneVcard *vcard = linphone_friend_get_vcard(lf); char *address = NULL; if (!store_friends) { return; } if (!lf || !lf->friend_list) { ms_warning("Either the friend or the friend list is null, skipping..."); return; } if (lf->friend_list->storage_id == 0) { ms_warning("Trying to add a friend in db, but friend list isn't, let's do that first"); linphone_core_store_friends_list_in_db(lc, lf->friend_list); } address = linphone_address_as_string(linphone_friend_get_address(lf)); if (lf->storage_id > 0) { buf = sqlite3_mprintf("UPDATE friends SET friend_list_id=%u,sip_uri=%Q,subscribe_policy=%i,send_subscribe=%i,ref_key=%Q,vCard=%Q,vCard_etag=%Q,vCard_url=%Q,presence_received=%i WHERE (id = %u);", lf->friend_list->storage_id, address, lf->pol, lf->subscribe, lf->refkey, linphone_vcard_as_vcard4_string(vcard), linphone_vcard_get_etag(vcard), linphone_vcard_get_url(vcard), lf->presence_received, lf->storage_id ); } else { buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%u,%Q,%i,%i,%Q,%Q,%Q,%Q,%i);", lf->friend_list->storage_id, address, lf->pol, lf->subscribe, lf->refkey, linphone_vcard_as_vcard4_string(vcard), linphone_vcard_get_etag(vcard), linphone_vcard_get_url(vcard), lf->presence_received ); } ms_free(address); linphone_sql_request_generic(lc->friends_db, buf); sqlite3_free(buf); if (lf->storage_id == 0) { lf->storage_id = (unsigned int)sqlite3_last_insert_rowid(lc->friends_db); } } }
void linphone_friend_remove_phone_number(LinphoneFriend *lf, const char *phone) { LinphoneVcard *vcard = NULL; if (!lf || !phone) { return; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_remove_phone_number(vcard, phone); }
void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; if (!lf || !addr) { return; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_remove_sip_address(vcard, linphone_address_as_string_uri_only(addr)); }
MSList* linphone_friend_get_phone_numbers(LinphoneFriend *lf) { LinphoneVcard *vcard = NULL; if (!lf) { return NULL; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return NULL; } return linphone_vcard_get_phone_numbers(vcard); }
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_unref(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; }
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; if (!lf || !addr) { return; } if (lf->uri == NULL) { LinphoneAddress *fr = linphone_address_clone(addr); linphone_address_clean(fr); lf->uri = fr; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_add_sip_address(vcard, linphone_address_as_string_uri_only(addr)); }
static void carddav_contact_updated(LinphoneFriendList *list, LinphoneFriend *new_friend, LinphoneFriend *old_friend) { LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_full_name(linphone_friend_get_vcard(new_friend)), linphone_vcard_get_full_name(linphone_friend_get_vcard(old_friend))); stats->updated_contact_count++; }
static void friends_sqlite_storage(void) { LinphoneCoreVTable *v_table = linphone_core_v_table_new(); LinphoneCore* lc = NULL; LinphoneFriendList *lfl = NULL; LinphoneFriend *lf = NULL; LinphoneFriend *lf2 = NULL; LinphoneVcard *lvc = linphone_vcard_new(); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const bctbx_list_t *friends = NULL; bctbx_list_t *friends_from_db = NULL; bctbx_list_t *friends_lists_from_db = NULL; char *friends_db = bc_tester_file("friends.db"); LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); LinphoneAddress *laddress = NULL, *laddress2 = NULL; char *address = NULL, *address2 = NULL; v_table->friend_list_created = friend_list_created_cb; v_table->friend_list_removed = friend_list_removed_cb; lc = linphone_core_new(v_table, NULL, NULL, NULL); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); lfl = linphone_core_create_friend_list(lc); linphone_friend_list_set_user_data(lfl, stats); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); unlink(friends_db); linphone_core_set_friends_database_path(lc, friends_db); friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 0, int, "%d"); linphone_vcard_set_etag(lvc, "\"123-456789\""); linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf"); lf = linphone_friend_new_from_vcard(lvc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_core_add_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i"); linphone_friend_list_unref(lfl); linphone_friend_list_set_display_name(lfl, "Test"); BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i"); linphone_friend_unref(lf); BC_ASSERT_EQUAL(lfl->storage_id, 1, unsigned int, "%u"); BC_ASSERT_EQUAL(lf->storage_id, 1, unsigned int, "%u"); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc); BC_ASSERT_EQUAL(bctbx_list_size(friends_lists_from_db), 1, int, "%d"); friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends; BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_PTR_NOT_NULL(lf2->lc); BC_ASSERT_PTR_NOT_NULL(lf2->friend_list); friends_lists_from_db = bctbx_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); if (bctbx_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf)); BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, unsigned int, "%u"); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf))); laddress = linphone_friend_get_address(lf); address = linphone_address_as_string(laddress); laddress2 = linphone_friend_get_address(lf2); address2 = linphone_address_as_string(laddress2); BC_ASSERT_STRING_EQUAL(address2, address); linphone_address_unref(laddress); linphone_address_unref(laddress2); ms_free(address); ms_free(address2); linphone_friend_edit(lf); linphone_friend_set_name(lf, "Margaux"); linphone_friend_done(lf); friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); if (bctbx_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux"); friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); linphone_friend_list_remove_friend(lfl, lf); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 0, int, "%d"); linphone_core_remove_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i"); end: ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_address_unref(addr); linphone_core_destroy(lc); linphone_core_v_table_destroy(v_table); }