static void simple(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); LinphonePresenceModel *pauline_presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL); LinphoneFriend* f = linphone_core_create_friend_with_address(marie->lc, get_identity(pauline)); LinphonePresenceActivity *activity = NULL; lp_config_set_int(marie->lc->config, "sip", "subscribe_expires", 40); linphone_core_set_user_agent(pauline->lc, "full-presence-support", NULL); linphone_core_set_user_agent(marie->lc, "full-presence-support", NULL); enable_publish(pauline, TRUE); linphone_friend_enable_subscribes(f, TRUE); linphone_friend_set_inc_subscribe_policy(f,LinphoneSPAccept); /* Accept incoming subscription request for this friend*/ linphone_core_add_friend(marie->lc, f); linphone_core_set_presence_model(pauline->lc, pauline_presence); BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityDinner,1)); activity = linphone_presence_model_get_activity(linphone_friend_get_presence_model(f)); if (BC_ASSERT_PTR_NOT_NULL(activity)) { BC_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityDinner, int, "%d"); } linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){ LinphoneOnlineStatus online_status = LinphoneStatusOffline; LinphonePresenceBasicStatus basic_status = LinphonePresenceBasicStatusClosed; LinphonePresenceActivity *activity = NULL; const char *description = NULL; unsigned int nb_activities = 0; if (lf->presence != NULL) { basic_status = linphone_presence_model_get_basic_status(lf->presence); nb_activities = linphone_presence_model_get_nb_activities(lf->presence); online_status = (basic_status == LinphonePresenceBasicStatusOpen) ? LinphoneStatusOnline : LinphoneStatusOffline; if (nb_activities > 1) { char *tmp = NULL; const LinphoneAddress *addr = linphone_friend_get_address(lf); if (addr) tmp = linphone_address_as_string(addr); ms_warning("Friend %s has several activities, get status from the first one", tmp ? tmp : "unknown"); if (tmp) ms_free(tmp); nb_activities = 1; } if (nb_activities == 1) { activity = linphone_presence_model_get_activity(lf->presence); description = linphone_presence_activity_get_description(activity); switch (linphone_presence_activity_get_type(activity)) { case LinphonePresenceActivityBreakfast: case LinphonePresenceActivityDinner: case LinphonePresenceActivityLunch: case LinphonePresenceActivityMeal: online_status = LinphoneStatusOutToLunch; break; case LinphonePresenceActivityAppointment: case LinphonePresenceActivityMeeting: case LinphonePresenceActivityPerformance: case LinphonePresenceActivityPresentation: case LinphonePresenceActivitySpectator: case LinphonePresenceActivityWorking: case LinphonePresenceActivityWorship: online_status = LinphoneStatusDoNotDisturb; break; case LinphonePresenceActivityAway: case LinphonePresenceActivitySleeping: online_status = LinphoneStatusAway; break; case LinphonePresenceActivityHoliday: case LinphonePresenceActivityTravel: case LinphonePresenceActivityVacation: online_status = LinphoneStatusVacation; break; case LinphonePresenceActivityBusy: if (description && strcmp(description, "Do not disturb") == 0) { // See linphonecore.c linphone_core_set_presence_info() method online_status = LinphoneStatusDoNotDisturb; } else { online_status = LinphoneStatusBusy; } break; case LinphonePresenceActivityLookingForWork: case LinphonePresenceActivityPlaying: case LinphonePresenceActivityShopping: case LinphonePresenceActivityTV: online_status = LinphoneStatusBusy; break; case LinphonePresenceActivityInTransit: case LinphonePresenceActivitySteering: online_status = LinphoneStatusBeRightBack; break; case LinphonePresenceActivityOnThePhone: online_status = LinphoneStatusOnThePhone; break; case LinphonePresenceActivityOther: case LinphonePresenceActivityPermanentAbsence: online_status = LinphoneStatusMoved; break; case LinphonePresenceActivityUnknown: /* Rely on the basic status information. */ break; case LinphonePresenceActivityOnline: /* Should not happen! */ /*ms_warning("LinphonePresenceActivityOnline should not happen here!");*/ break; case LinphonePresenceActivityOffline: online_status = LinphoneStatusOffline; break; } } } return online_status; }
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { stats* counters; LinphonePresenceActivity *activity = NULL; char* from=linphone_address_as_string(linphone_friend_get_address(lf)); ms_message("New Notify request from [%s] ",from); ms_free(from); counters = get_stats(lc); counters->number_of_NotifyReceived++; counters->last_received_presence = linphone_friend_get_presence_model(lf); activity = linphone_presence_model_get_activity(counters->last_received_presence); switch (linphone_presence_activity_get_type(activity)) { case LinphonePresenceActivityOffline: counters->number_of_LinphonePresenceActivityOffline++; break; case LinphonePresenceActivityOnline: counters->number_of_LinphonePresenceActivityOnline++; break; case LinphonePresenceActivityAppointment: counters->number_of_LinphonePresenceActivityAppointment++; break; case LinphonePresenceActivityAway: counters->number_of_LinphonePresenceActivityAway++; break; case LinphonePresenceActivityBreakfast: counters->number_of_LinphonePresenceActivityBreakfast++; break; case LinphonePresenceActivityBusy: counters->number_of_LinphonePresenceActivityBusy++; break; case LinphonePresenceActivityDinner: counters->number_of_LinphonePresenceActivityDinner++; break; case LinphonePresenceActivityHoliday: counters->number_of_LinphonePresenceActivityHoliday++; break; case LinphonePresenceActivityInTransit: counters->number_of_LinphonePresenceActivityInTransit++; break; case LinphonePresenceActivityLookingForWork: counters->number_of_LinphonePresenceActivityLookingForWork++; break; case LinphonePresenceActivityLunch: counters->number_of_LinphonePresenceActivityLunch++; break; case LinphonePresenceActivityMeal: counters->number_of_LinphonePresenceActivityMeal++; break; case LinphonePresenceActivityMeeting: counters->number_of_LinphonePresenceActivityMeeting++; break; case LinphonePresenceActivityOnThePhone: counters->number_of_LinphonePresenceActivityOnThePhone++; break; case LinphonePresenceActivityOther: counters->number_of_LinphonePresenceActivityOther++; break; case LinphonePresenceActivityPerformance: counters->number_of_LinphonePresenceActivityPerformance++; break; case LinphonePresenceActivityPermanentAbsence: counters->number_of_LinphonePresenceActivityPermanentAbsence++; break; case LinphonePresenceActivityPlaying: counters->number_of_LinphonePresenceActivityPlaying++; break; case LinphonePresenceActivityPresentation: counters->number_of_LinphonePresenceActivityPresentation++; break; case LinphonePresenceActivityShopping: counters->number_of_LinphonePresenceActivityShopping++; break; case LinphonePresenceActivitySleeping: counters->number_of_LinphonePresenceActivitySleeping++; break; case LinphonePresenceActivitySpectator: counters->number_of_LinphonePresenceActivitySpectator++; break; case LinphonePresenceActivitySteering: counters->number_of_LinphonePresenceActivitySteering++; break; case LinphonePresenceActivityTravel: counters->number_of_LinphonePresenceActivityTravel++; break; case LinphonePresenceActivityTV: counters->number_of_LinphonePresenceActivityTV++; break; case LinphonePresenceActivityUnknown: counters->number_of_LinphonePresenceActivityUnknown++; break; case LinphonePresenceActivityVacation: counters->number_of_LinphonePresenceActivityVacation++; break; case LinphonePresenceActivityWorking: counters->number_of_LinphonePresenceActivityWorking++; break; case LinphonePresenceActivityWorship: counters->number_of_LinphonePresenceActivityWorship++; break; } }
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); }
#include <signal.h> static bool_t running=TRUE; static void stop(int signum){ running=FALSE; } /** * presence state change notification callback */ static void notify_presence_recv_updated (LinphoneCore *lc, LinphoneFriend *friend) { const LinphonePresenceModel* model = linphone_friend_get_presence_model(friend); const LinphoneAddress* friend_address = linphone_friend_get_address(friend); LinphonePresenceActivity *activity = linphone_presence_model_get_activity(model); char *activity_str = linphone_presence_activity_to_string(activity); printf("New state state [%s] for user id [%s] \n" ,activity_str ,linphone_address_as_string (friend_address)); } static void new_subscription_requested (LinphoneCore *lc, LinphoneFriend *friend, const char* url) { const LinphoneAddress* friend_address = linphone_friend_get_address(friend); printf(" [%s] wants to see your status, accepting\n" ,linphone_address_as_string (friend_address)); linphone_friend_edit(friend); /* start editing friend */ linphone_friend_set_inc_subscribe_policy(friend,LinphoneSPAccept); /* Accept incoming subscription request for this friend*/ linphone_friend_done(friend); /*commit change*/ linphone_core_add_friend(lc,friend); /* add this new friend to the buddy list*/ }