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 /src | |
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 'src')
-rw-r--r-- | src/contact.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/contact.c b/src/contact.c index 1fe308b..7d0d621 100644 --- a/src/contact.c +++ b/src/contact.c @@ -92,6 +92,9 @@ int contact_add(struct contacts *contacts, list_append(&contacts->cl, &c->le, c); hash_append(contacts->cht, hash_joaat_pl(&c->addr.auri), &c->he, c); + if (contacts->handler) + contacts->handler(c, false, contacts->handler_arg); + out: if (err) mem_deref(c); @@ -103,6 +106,38 @@ int contact_add(struct contacts *contacts, /** + * Remove a contact + * + * @param contacts Contacts container + * @param contactp Pointer to the contact to be removed + */ +void contact_remove(struct contacts *contacts, struct contact *contact) +{ + if (!contacts || !contact) + return; + + if (contacts->handler) + contacts->handler(contact, true, contacts->handler_arg); + + hash_unlink(&contact->he); + list_unlink(&contact->le); + + mem_deref(contact); +} + +void contact_set_update_handler(struct contacts *contacts, + contact_update_h *updateh, void *arg) +{ + if (!contacts) { + return; + } + + contacts->handler = updateh; + contacts->handler_arg = arg; +} + + +/** * Get the SIP address of a contact * * @param c Contact @@ -159,6 +194,13 @@ void contact_set_presence(struct contact *c, enum presence_status status) c->status = status; } +enum presence_status contact_presence(const struct contact *c) +{ + if (!c) + return PRESENCE_UNKNOWN; + + return c->status; +} const char *contact_presence_str(enum presence_status status) { |