static void subscribe_presence_expired(void){ LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline1 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); LinphoneFriend *lf; bctbx_list_t *lcs = NULL; lcs = bctbx_list_append(lcs, marie->lc); lcs = bctbx_list_append(lcs, pauline1->lc); lp_config_set_int(marie->lc->config, "sip", "subscribe_expires", 10); lf = linphone_core_create_friend(marie->lc); linphone_friend_set_address(lf, pauline1->identity); linphone_friend_enable_subscribes(lf, TRUE); linphone_core_add_friend(marie->lc, lf); linphone_friend_unref(lf); BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_NewSubscriptionRequest,1, 5000)); BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOnline,1, 2000)); lf = linphone_core_find_friend(pauline1->lc, marie->identity); BC_ASSERT_PTR_NOT_NULL(lf); if (lf) { BC_ASSERT_PTR_NOT_NULL(lf->insubs); /*marie comes offline suddenly*/ linphone_core_set_network_reachable(marie->lc, FALSE); /*after a certain time, pauline shall see the incoming SUBSCRIBE expired*/ wait_for_list(lcs,NULL, 0, 11000); BC_ASSERT_PTR_NULL(lf->insubs); /*just make network reachable so that marie can unregister properly*/ linphone_core_set_network_reachable(marie->lc, TRUE); BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneRegistrationOk,2, 10000)); } linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline1); bctbx_list_free(lcs); }
static void friends_if_no_db_set(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); LinphoneFriend *lf = linphone_core_create_friend(manager->lc); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const bctbx_list_t *friends = NULL; LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_friend_list_add_friend(lfl, lf); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends), 1, int, "%d"); linphone_friend_list_remove_friend(lfl, lf); linphone_friend_unref(lf); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); linphone_friend_list_unref(lfl); linphone_address_unref(addr); linphone_core_manager_destroy(manager); }
static void subscribe_presence_forked(void){ LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline1 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_tcp_rc" : "pauline_tcp_rc"); LinphoneCoreManager* pauline2 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_tcp_rc" : "pauline_tcp_rc"); LinphoneFriend *lf; bctbx_list_t *lcs = NULL; lcs = bctbx_list_append(lcs, marie->lc); lcs = bctbx_list_append(lcs, pauline1->lc); lcs = bctbx_list_append(lcs, pauline2->lc); lf = linphone_core_create_friend(marie->lc); linphone_friend_set_address(lf, pauline1->identity); linphone_friend_enable_subscribes(lf, TRUE); linphone_core_add_friend(marie->lc, lf); linphone_friend_unref(lf); BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_NewSubscriptionRequest,1, 10000)); BC_ASSERT_TRUE(wait_for_list(lcs,&pauline2->stat.number_of_NewSubscriptionRequest,1, 2000)); /*we should get only one notify*/ BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOnline,1, 10000)); BC_ASSERT_FALSE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOnline,2, 2000)); /*marie also shall receive two SUBSCRIBEs from the two paulines, but won't be notified to the app since Marie set Pauline as a friend.*/ BC_ASSERT_EQUAL(marie->stat.number_of_NewSubscriptionRequest, 0, int, "%d"); /*and the two paulines shall be notified of marie's presence*/ BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphonePresenceActivityOnline,1, 3000)); BC_ASSERT_TRUE(wait_for_list(lcs,&pauline2->stat.number_of_LinphonePresenceActivityOnline,1, 2000)); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline1); linphone_core_manager_destroy(pauline2); bctbx_list_free(lcs); }
static void linphone_ldap_contact_provider_handle_search_result( LinphoneLDAPContactProvider* obj, LinphoneLDAPContactSearch* req, LDAPMessage* message ) { int msgtype = ldap_msgtype(message); switch(msgtype){ case LDAP_RES_SEARCH_ENTRY: case LDAP_RES_EXTENDED: { LDAPMessage *entry = ldap_first_entry(obj->ld, message); LinphoneCore* lc = LINPHONE_CONTACT_PROVIDER(obj)->lc; while( entry != NULL ){ struct LDAPFriendData ldap_data = {0}; bool_t contact_complete = FALSE; BerElement* ber = NULL; char* attr = ldap_first_attribute(obj->ld, entry, &ber); while( attr ){ struct berval** values = ldap_get_values_len(obj->ld, entry, attr); struct berval** it = values; while( values && *it && (*it)->bv_val && (*it)->bv_len ) { contact_complete = linphone_ldap_contact_provider_complete_contact(obj, &ldap_data, attr, (*it)->bv_val); if( contact_complete ) break; it++; } if( values ) ldap_value_free_len(values); ldap_memfree(attr); if( contact_complete ) break; attr = ldap_next_attribute(obj->ld, entry, ber); } if( contact_complete ) { LinphoneAddress* la = linphone_core_interpret_url(lc, ldap_data.sip); if( la ){ LinphoneFriend* lf = linphone_core_create_friend(lc); linphone_friend_set_address(lf, la); linphone_friend_set_name(lf, ldap_data.name); req->found_entries = ms_list_append(req->found_entries, lf); req->found_count++; //ms_message("Added friend %s / %s", ldap_data.name, ldap_data.sip); ms_free(ldap_data.sip); ms_free(ldap_data.name); linphone_address_destroy(la); } } if( ber ) ber_free(ber, 0); entry = ldap_next_entry(obj->ld, entry); } } break; case LDAP_RES_SEARCH_RESULT: { // this one is received when a request is finished req->complete = TRUE; linphone_contact_search_invoke_cb(LINPHONE_CONTACT_SEARCH(req), req->found_entries); } break; default: ms_message("[LDAP] Unhandled message type %x", msgtype); break; } }
static void subscriber_no_longer_reachable(void){ LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline1 = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); LinphoneFriend *lf; MSList *lcs = NULL; LinphonePresenceModel * presence; int previous_number_of_LinphonePresenceActivityOnline=0; int previous_number_of_LinphonePresenceActivityOffline=0; lcs = ms_list_append(lcs, marie->lc); lcs = ms_list_append(lcs, pauline1->lc); lp_config_set_int(marie->lc->config, "sip", "subscribe_expires", 40); linphone_core_set_user_agent(marie->lc, "full-presence-support", NULL); linphone_core_set_user_agent(pauline1->lc, "full-presence-support", NULL); enable_publish(pauline1, TRUE); lf = linphone_core_create_friend(marie->lc); linphone_friend_set_address(lf, pauline1->identity); linphone_friend_enable_subscribes(lf, TRUE); linphone_core_add_friend(marie->lc, lf); linphone_friend_unref(lf); BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceBasicStatusOpen,1, 2000)); /*make sure marie subscribe is not reset by accident because of code below located in linphone_core_iterate if (lc->sip_network_reachable && lc->netup_time!=0 && (current_real_time-lc->netup_time)>3){ linphone_core_send_initial_subscribes(lc); } */ wait_for_until(pauline1->lc, marie->lc, 0, 0, 3000); presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityBusy,NULL); linphone_core_set_presence_model(pauline1->lc,presence); previous_number_of_LinphonePresenceActivityOnline=marie->stat.number_of_LinphonePresenceActivityOnline; /*don't schedule marie to simulate Notify timeout server side*/ wait_for_until(pauline1->lc, NULL, 0, 0, 35000); //sal_set_send_error(marie->lc->sal,0); /*because of notify timeout detected by server, so subscription is reset*/ previous_number_of_LinphonePresenceActivityOffline = marie->stat.number_of_LinphonePresenceBasicStatusClosed; BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOffline,previous_number_of_LinphonePresenceActivityOffline+1, 4000)); // now subscription is supposed to be dead because notify was not answered in time. presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityOnline,NULL); linphone_core_set_presence_model(pauline1->lc,presence); /*because subscription not is automatically restarted*/ BC_ASSERT_FALSE(wait_for_list(lcs,&marie->stat.number_of_LinphonePresenceActivityOnline,previous_number_of_LinphonePresenceActivityOnline+1, 4000)); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline1); ms_list_free(lcs); }