diff options
author | Jonathan Sieber <mail@strfry.org> | 2017-07-06 13:25:00 +0200 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-07-06 13:25:00 +0200 |
commit | 5747d81d959ce156fcfc8ca4ebe0b89f72d6b9d5 (patch) | |
tree | a46da4d5a425111651d7249bf8f7c5e0bb7679dd /modules/presence | |
parent | eb6b93a8820041ec0bf587eece7c281c40c1da14 (diff) |
Presence: Handle contacts added at run-time (#276)
* Add contact_presence getter
* Add contact_remove() function
* presence: Handle contacts added at runtime
Diffstat (limited to 'modules/presence')
-rw-r--r-- | modules/presence/subscriber.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/presence/subscriber.c b/modules/presence/subscriber.c index 596e592..914f74d 100644 --- a/modules/presence/subscriber.c +++ b/modules/presence/subscriber.c @@ -280,6 +280,43 @@ static int presence_alloc(struct contact *contact) return 0; } +static void contact_handler(struct contact *contact, + bool removed, void *arg) +{ + struct le *le; + struct pl val; + struct presence *pres = NULL; + struct sip_addr *addr = contact_addr(contact); + (void)arg; + + if (0 == msg_param_decode(&addr->params, "presence", &val) && + 0 == pl_strcasecmp(&val, "p2p")) { + if (!removed) { + if (presence_alloc(contact) != 0) { + error("presence: presence_alloc failed\n"); + return; + } + } + else { + /* Find matching presence element for contact */ + for (le = list_head(&presencel); le; le = le->next) { + pres = (struct presence*)le->data; + if (pres->contact == contact) { + break; + } + pres = NULL; + } + + if (pres) { + mem_deref(pres); + } + else { + error("presence: No contact to remove\n"); + } + } + } +} + int subscriber_init(void) { @@ -302,12 +339,15 @@ int subscriber_init(void) info("Subscribing to %u contacts\n", list_count(&presencel)); + contact_set_update_handler(contacts, contact_handler, NULL); + return err; } void subscriber_close(void) { + contact_set_update_handler(baresip_contacts(), NULL, NULL); list_flush(&presencel); } @@ -319,6 +359,8 @@ void subscriber_close_all(void) info("presence: subscriber: closing %u subs\n", list_count(&presencel)); + contact_set_update_handler(baresip_contacts(), NULL, NULL); + le = presencel.head; while (le) { |