From fbc239661b9273ca593c672e7dbe9431fe25444a Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 13 Nov 2017 16:01:22 +0100 Subject: [PATCH] Add API to get the remote contact of a SIP event. --- coreapi/event.c | 14 ++++++++++++++ coreapi/private.h | 1 + include/linphone/event.h | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/coreapi/event.c b/coreapi/event.c index a8fe6a043..d4e8541da 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -442,6 +442,7 @@ static void linphone_event_destroy(LinphoneEvent *lev){ if (lev->send_custom_headers) sal_custom_header_free(lev->send_custom_headers); if (lev->to_address) linphone_address_unref(lev->to_address); if (lev->from_address) linphone_address_unref(lev->from_address); + if (lev->remote_contact_address) linphone_address_unref(lev->remote_contact_address); ms_free(lev->name); } @@ -480,6 +481,15 @@ static const LinphoneAddress *_linphone_event_cache_from (const LinphoneEvent *l return lev->from_address; } +static const LinphoneAddress *_linphone_event_cache_remote_contact (const LinphoneEvent *lev) { + if (lev->remote_contact_address) + linphone_address_unref(lev->remote_contact_address); + char *buf = sal_address_as_string(lev->op->get_remote_contact_address()); + ((LinphoneEvent *)lev)->remote_contact_address = linphone_address_new(buf); + ms_free(buf); + return lev->remote_contact_address; +} + const LinphoneAddress *linphone_event_get_from (const LinphoneEvent *lev) { if (lev->is_out_of_dialog_op && lev->dir == LinphoneSubscriptionOutgoing) return _linphone_event_cache_to(lev); @@ -492,6 +502,10 @@ const LinphoneAddress *linphone_event_get_resource(const LinphoneEvent *lev){ return _linphone_event_cache_to(lev); } +const LinphoneAddress *linphone_event_get_remote_contact (const LinphoneEvent *lev) { + return _linphone_event_cache_remote_contact(lev); +} + LinphoneCore *linphone_event_get_core(const LinphoneEvent *lev){ return lev->lc; } diff --git a/coreapi/private.h b/coreapi/private.h index 630e1cdc3..2e57f4a93 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -972,6 +972,7 @@ struct _LinphoneEvent{ // Cache. LinphoneAddress *to_address; LinphoneAddress *from_address; + LinphoneAddress *remote_contact_address; }; BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneEvent); diff --git a/include/linphone/event.h b/include/linphone/event.h index b9b34686f..c49ab0167 100644 --- a/include/linphone/event.h +++ b/include/linphone/event.h @@ -191,6 +191,13 @@ LINPHONE_PUBLIC const LinphoneAddress *linphone_event_get_from(const LinphoneEve **/ LINPHONE_PUBLIC const LinphoneAddress *linphone_event_get_resource(const LinphoneEvent *lev); +/** + * Get the "contact" address of the subscription. + * @param[in] lev LinphoneEvent object + * @return The "contact" address of the subscription + */ +LINPHONE_PUBLIC const LinphoneAddress *linphone_event_get_remote_contact (const LinphoneEvent *lev); + /** * Returns back pointer to the LinphoneCore that created this LinphoneEvent **/