Managing Buddies and buddy list and presence

Buddies and buddy list

Each buddy is represented by a LinphoneFriend object created by function linphone_friend_new().

Buddy configuration parameters like sip uri or status publication policy for this friend are configurable for each buddy.

Here under a typical buddy creation:

LinphoneFriend* my_friend=linphone_friend_new_with_addr(""); /*creates friend object for buddy joe*/
linphone_friend_enable_subscribes(my_friend,TRUE); /*configure this friend to emit SUBSCRIBE message after being added to LinphoneCore*/
linphone_friend_set_inc_subscribe_policy(my_friend,LinphoneSPAccept); /* accept Incoming subscription request for this friend*/

Friends status changes are reported by callback LinphoneCoreVTable.notify_presence_recv

static void notify_presence_recv_updated (struct _LinphoneCore *lc,  LinphoneFriend *friend) {
        const LinphoneAddress* friend_address = linphone_friend_get_address(friend);
        printf("New state state [%s] for user id [%s] \n"
                                ,linphone_address_as_string (friend_address));

Once created a buddy can be added to the buddy list using function linphone_core_add_friend(). Added friends will be notified about local status changes.

Any subsequente modifications to LinphoneFriend must be first started by a call to function linphone_friend_edit() and validated by function linphone_friend_done().

linphone_friend_edit(my_friend); /* start editing friend */
linphone_friend_enable_subscribes(my_friend,FALSE); /*disable subscription for this friend*/
linphone_friend_done(my_friend); /*commit changes triggering an UNSUBSCRIBE message*/

Publishing presence status

Local presence status can be changed using function linphone_core_set_presence_model(). New status is propagated to all friends previously added to LinphoneCore.

Handling incoming subscription request

New incoming subscription requests are process according to the incoming subscription policy state for subscription initiated by members of the buddy list.

For incoming request comming from an unknown buddy, the call back LinphoneCoreVTable.new_subscription_request is invoked.

A complete tutorial can be found at : ref buddy_tutorials “Registration tutorial”