static void presence_information(void) { const char *bike_description = "Riding my bike"; const char *vacation_note = "I'm on vacation until July 4th"; const char *vacation_lang = "en"; const char *contact = "sip:[email protected]"; LinphoneCoreManager *marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager *pauline = presence_linphone_core_manager_new("pauline"); LinphonePresenceModel *presence; LinphonePresenceActivity *activity = NULL; LinphonePresenceNote *note = NULL; const char *description = NULL; const char *note_content = NULL; char *contact2; time_t current_timestamp, presence_timestamp; CU_ASSERT_TRUE(subscribe_to_callee_presence(marie, pauline)); /* Presence activity without description. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityDinner,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityDinner, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityDinner); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NULL(description); /* Presence activity with description. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivitySteering, bike_description); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivitySteering,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivitySteering, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivitySteering); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NOT_NULL(description); if (description != NULL) CU_ASSERT_EQUAL(strcmp(description, bike_description), 0); /* Presence activity with description and note. */ presence = linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityVacation, NULL, vacation_note, vacation_lang); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityVacation,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityVacation, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityVacation); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NULL(description); note = linphone_presence_model_get_note(marie->stat.last_received_presence, NULL); CU_ASSERT_PTR_NOT_NULL(note); if (note != NULL) { note_content = linphone_presence_note_get_content(note); CU_ASSERT_PTR_NOT_NULL(note_content); if (note_content != NULL) { CU_ASSERT_EQUAL(strcmp(note_content, vacation_note), 0); } } /* Presence contact. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL); linphone_presence_model_set_contact(presence, contact); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnThePhone,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityOnThePhone, 1); contact2 = linphone_presence_model_get_contact(presence); CU_ASSERT_PTR_NOT_NULL(contact2); if (contact2 != NULL) { CU_ASSERT_EQUAL(strcmp(contact, contact2), 0); ms_free(contact2); } /* Presence timestamp. */ current_timestamp = time(NULL); presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityShopping, NULL); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityShopping,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityShopping, 1); presence_timestamp = linphone_presence_model_get_timestamp(presence); CU_ASSERT_TRUE(presence_timestamp >= current_timestamp); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
static void call_received(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); LinphoneCall *call; const char *from,*to; char *alt_contact; LinphoneAddress *from_addr, *to_addr; bool_t prevent_colliding_calls=lp_config_get_int(lc->config,"sip","prevent_colliding_calls",TRUE); /* first check if we can answer successfully to this invite */ if (linphone_presence_model_get_basic_status(lc->presence_model) == LinphonePresenceBasicStatusClosed) { LinphonePresenceActivity *activity = linphone_presence_model_get_activity(lc->presence_model); switch (linphone_presence_activity_get_type(activity)) { case LinphonePresenceActivityBusy: sal_call_decline(h,SalReasonBusy,NULL); break; case LinphonePresenceActivityAppointment: case LinphonePresenceActivityMeeting: case LinphonePresenceActivityOffline: case LinphonePresenceActivityWorship: sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); break; case LinphonePresenceActivityPermanentAbsence: alt_contact = linphone_presence_model_get_contact(lc->presence_model); if (alt_contact != NULL) { sal_call_decline(h,SalReasonRedirect,alt_contact); ms_free(alt_contact); } break; default: break; } sal_op_release(h); return; } if (!linphone_core_can_we_add_call(lc)){/*busy*/ sal_call_decline(h,SalReasonBusy,NULL); sal_op_release(h); return; } from=sal_op_get_from(h); to=sal_op_get_to(h); from_addr=linphone_address_new(from); to_addr=linphone_address_new(to); if ((already_a_call_with_remote_address(lc,from_addr) && prevent_colliding_calls) || already_a_call_pending(lc)){ ms_warning("Receiving another call while one is ringing or initiated, refusing this one with busy message."); sal_call_decline(h,SalReasonBusy,NULL); sal_op_release(h); linphone_address_destroy(from_addr); linphone_address_destroy(to_addr); return; } call=linphone_call_new_incoming(lc,from_addr,to_addr,h); /* the call is acceptable so we can now add it to our list */ linphone_core_add_call(lc,call); linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */ if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)) { /* Defer ringing until the end of the ICE candidates gathering process. */ ms_message("Defer ringing to gather ICE candidates"); return; } #ifdef BUILD_UPNP if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseUpnp) && (call->upnp_session != NULL)) { /* Defer ringing until the end of the ICE candidates gathering process. */ ms_message("Defer ringing to gather uPnP candidates"); return; } #endif //BUILD_UPNP linphone_core_notify_incoming_call(lc,call); }