static void subscribe_failure_handle_by_app(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new("pauline_rc"); LinphoneProxyConfig* config; LinphoneFriend* lf; char* lf_identity=linphone_address_as_string_uri_only(pauline->identity); linphone_core_get_default_proxy(marie->lc,&config); CU_ASSERT_TRUE(subscribe_to_callee_presence(marie,pauline)); wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,1); /*just to wait for unsubscription even if not notified*/ sal_set_recv_error(marie->lc->sal, 0); /*simulate an error*/ CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneRegistrationProgress,2)); CU_ASSERT_EQUAL(linphone_proxy_config_get_error(config),LinphoneReasonIOError); sal_set_recv_error(marie->lc->sal, 1); lf = linphone_core_get_friend_by_address(marie->lc,lf_identity); linphone_friend_edit(lf); linphone_friend_enable_subscribes(lf,FALSE); /*disable subscription*/ linphone_friend_done(lf); CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneRegistrationOk,2)); /*wait for register ok*/ linphone_friend_edit(lf); linphone_friend_enable_subscribes(lf,TRUE); linphone_friend_done(lf); CU_ASSERT_FALSE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,2)); /*just to wait for unsubscription even if not notified*/ linphone_core_manager_destroy(marie); CU_ASSERT_FALSE(wait_for(NULL,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,3)); /*just to wait for unsubscription even if not notified*/ linphone_core_manager_destroy(pauline); }
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; }
static void simple_subscribe_with_early_notify(void) { LinphoneCoreManager* marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager* pauline = presence_linphone_core_manager_new("pauline"); LinphoneAddress *marie_identity_addr = linphone_address_clone(marie->identity); LpConfig *pauline_lp; char* pauline_identity=linphone_address_as_string_uri_only(pauline->identity); char* marie_identity; LinphoneFriend* pauline_s_friend; LinphoneFriend* marie_s_friend=linphone_core_create_friend_with_address(marie->lc,pauline_identity); pauline_lp = linphone_core_get_config(pauline->lc); lp_config_set_int(pauline_lp,"sip","notify_pending_state",1); linphone_friend_edit(marie_s_friend); linphone_friend_enable_subscribes(marie_s_friend,TRUE); linphone_friend_done(marie_s_friend); linphone_core_add_friend(marie->lc,marie_s_friend); ms_free(pauline_identity); /*to simulate pending state.*/ linphone_address_set_port(marie_identity_addr,0); marie_identity=linphone_address_as_string_uri_only(marie_identity_addr); pauline_s_friend=linphone_core_create_friend_with_address(pauline->lc,marie_identity); linphone_core_add_friend(pauline->lc,pauline_s_friend); ms_free(marie_identity); BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_NotifyPresenceReceived,1)); BC_ASSERT_EQUAL(linphone_friend_get_subscription_state(marie_s_friend), LinphoneSubscriptionPending,int, "%d"); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnline,marie->stat.number_of_LinphonePresenceActivityOnline+1); BC_ASSERT_EQUAL(marie->stat.number_of_NotifyPresenceReceived,2, int, "%d"); linphone_friend_unref(marie_s_friend); linphone_friend_unref(pauline_s_friend); linphone_address_unref(marie_identity_addr); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
GtkWidget * contact_edit(LinphoneFriend *lf, GtkWidget *ab){ GtkWidget *w=create_contact_box(); gchar *tmpstr; contact_draw(w,lf->proxy); g_object_set_data(G_OBJECT(w),"friend_ref",(gpointer)lf); linphone_friend_edit(lf); tmpstr=linphone_friend_get_name(lf); if (tmpstr!=NULL) { gtk_entry_set_text(GTK_ENTRY(lookup_widget(w,"name")),tmpstr); g_free(tmpstr); } tmpstr=linphone_friend_get_addr(lf); gtk_entry_set_text(GTK_ENTRY(lookup_widget(w,"sipaddr")),tmpstr); g_free(tmpstr); gtk_combo_box_set_active(GTK_COMBO_BOX(lookup_widget(w,"pol")),lf->pol); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(w,"send_subscribe")),lf->subscribe); gtk_widget_show(w); if (ab!=NULL) g_object_set_data(G_OBJECT(w),"address_book",(gpointer)ab); return w; }
static void carddav_integration(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:[email protected]\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); LinphoneVcard *lvc2 = NULL; LinphoneFriend *lf2 = NULL; LinphoneFriendListCbs *cbs = NULL; LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); const char *refkey = "toto"; char *address = NULL; LinphoneAddress *addr; linphone_friend_list_set_uri(lfl, CARDDAV_SERVER); cbs = linphone_friend_list_get_callbacks(lfl); linphone_friend_list_cbs_set_user_data(cbs, stats); linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created); linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted); linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated); linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed); linphone_core_add_friend_list(manager->lc, lfl); BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc)); BC_ASSERT_EQUAL(bctbx_list_size(lfl->dirty_friends_to_update), 0, int, "%d"); BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); BC_ASSERT_EQUAL(bctbx_list_size(lfl->dirty_friends_to_update), 1, int, "%d"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i"); BC_ASSERT_EQUAL(bctbx_list_size(lfl->dirty_friends_to_update), 0, int, "%d"); BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc)); linphone_friend_list_remove_friend(lfl, lf); BC_ASSERT_EQUAL(bctbx_list_size(lfl->friends), 0, int, "%d"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i"); linphone_friend_unref(lf); lf = NULL; lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:[email protected]\r\nEND:VCARD\r\n"); lf = linphone_friend_new_from_vcard(lvc); BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); linphone_friend_unref(lf); lvc2 = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:[email protected]\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); linphone_vcard_set_url(lvc2, "/card.php/addressbooks/tester/default/me.vcf"); lf2 = linphone_friend_new_from_vcard(lvc2); linphone_friend_set_ref_key(lf2, refkey); BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf2), LinphoneFriendListOK, int, "%d"); BC_ASSERT_EQUAL(lfl->revision, 0, int, "%i"); linphone_friend_list_synchronize_friends_from_server(lfl); wait_for_until(manager->lc, NULL, &stats->new_contact_count, 0, 5000); BC_ASSERT_EQUAL(stats->new_contact_count, 0, int, "%i"); wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i"); wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i"); BC_ASSERT_NOT_EQUAL(lfl->revision, 0, int, "%i"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i"); BC_ASSERT_EQUAL(bctbx_list_size(lfl->friends), 1, int, "%i"); lf = (LinphoneFriend *)lfl->friends->data; BC_ASSERT_STRING_EQUAL(lf->refkey, refkey); BC_ASSERT_EQUAL(lf->storage_id, lf2->storage_id, unsigned int, "%u"); linphone_friend_unref(lf2); addr = linphone_friend_get_address(lf); address = linphone_address_as_string_uri_only(addr); BC_ASSERT_STRING_EQUAL(address, "sip:[email protected]"); ms_free(address); linphone_address_unref(addr); linphone_friend_edit(lf); linphone_friend_done(lf); BC_ASSERT_EQUAL(bctbx_list_size(lf->friend_list->dirty_friends_to_update), 0, int, "%i"); linphone_core_set_network_reachable(manager->lc, FALSE); //To prevent the CardDAV update linphone_friend_edit(lf); linphone_friend_set_name(lf, "François Grisez"); linphone_friend_done(lf); BC_ASSERT_EQUAL(bctbx_list_size(lf->friend_list->dirty_friends_to_update), 1, int, "%i"); ms_free(stats); linphone_friend_list_unref(lfl); linphone_core_manager_destroy(manager); }
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); }
void FriendAPI::edit() { CORE_MUTEX FBLOG_DEBUG("FriendAPI::edit", "this=" << this); linphone_friend_edit(mFriend); }