From 0c2b5a41bea59adbad1d11991e032ac3d03eaf81 Mon Sep 17 00:00:00 2001 From: Eloi BAIL <eloi.bail@savoirfairelinux.com> Date: Wed, 3 Jul 2013 11:45:30 -0400 Subject: [PATCH] Presence : Enabling of presence subscription This code enable presence subscription / notification based on Asterisk hint mechanism. The presence of a SIP account will be automatically pushed by Asterisk server. DBus interface in CallManager (subsribePresence) is added to subscribe the presence of a buddy uri for an accountID. Then presence notification are received in buddysip.cpp. Callback to UI must be there implemented. Lot of commented code is still in the code. Work must be done to clean it. --- daemon/src/dbus/callmanager-introspec.xml | 6 ++++++ daemon/src/dbus/callmanager.cpp | 6 ++++++ daemon/src/dbus/callmanager.h | 3 +++ daemon/src/managerimpl.cpp | 10 ++++++++++ daemon/src/managerimpl.h | 5 +++++ daemon/src/sip/Makefile.am | 6 +++++- daemon/src/sip/sipvoiplink.cpp | 23 +++++++++++++++++++++++ daemon/src/sip/sipvoiplink.h | 4 +++- 8 files changed, 61 insertions(+), 2 deletions(-) diff --git a/daemon/src/dbus/callmanager-introspec.xml b/daemon/src/dbus/callmanager-introspec.xml index 6551f36189..0b954e8945 100644 --- a/daemon/src/dbus/callmanager-introspec.xml +++ b/daemon/src/dbus/callmanager-introspec.xml @@ -814,5 +814,11 @@ <arg type="b" name="accepted" direction="in"/> </method> + <method name="subscribePresence" tp:name-for-bindings="subscribePresence"> + <tp:added version="0.9.7"/> + <arg type="s" name="accountID" direction="in"/> + <arg type="s" name="buddySipUri" direction="in"/> + </method> + </interface> </node> diff --git a/daemon/src/dbus/callmanager.cpp b/daemon/src/dbus/callmanager.cpp index 8afb4c2ae4..27c0a56321 100644 --- a/daemon/src/dbus/callmanager.cpp +++ b/daemon/src/dbus/callmanager.cpp @@ -403,3 +403,9 @@ CallManager::sendTextMessage(const std::string& callID, const std::string& messa ERROR("Could not send \"%s\" text message to %s since SFLphone daemon does not support it, please recompile with instant messaging support", message.c_str(), callID.c_str()); #endif } +void +CallManager::subscribePresence(const std::string& accountID, const std::string& buddySipUri) +{ + DEBUG("subscribePresence"); + Manager::instance().subscribePresence(accountID,buddySipUri); +} diff --git a/daemon/src/dbus/callmanager.h b/daemon/src/dbus/callmanager.h index e99a72b6b0..131772d30f 100644 --- a/daemon/src/dbus/callmanager.h +++ b/daemon/src/dbus/callmanager.h @@ -127,6 +127,9 @@ class CallManager /* Instant messaging */ void sendTextMessage(const std::string& callID, const std::string& message); + /* Presence subscription */ + void subscribePresence(const std::string& accountID, const std::string& buddySipUri); + private: #if HAVE_ZRTP diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 92258800f7..131cd82cd4 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -85,6 +85,8 @@ #include <sys/types.h> // mkdir(2) #include <sys/stat.h> // mkdir(2) +#include "sip/sipbuddy.h" + ManagerImpl::ManagerImpl() : preferences(), voipPreferences(), hookPreference(), audioPreference(), shortcutPreferences(), @@ -2893,3 +2895,11 @@ void ManagerImpl::startAudioDriverStream() sfl::ScopedLock lock(audioLayerMutex_); audiodriver_->startStream(); } + +void ManagerImpl::subscribePresence(const std::string& accountID, const std::string& buddySipUri) +{ + DEBUG("SubscribePresence "); + SIPAccount *account = Manager::instance().getSipAccount(accountID); + SIPBuddy *b = new SIPBuddy(buddySipUri, account); + b->subscribe(); +} diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 2313256a21..bee04718c7 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -1041,6 +1041,11 @@ class ManagerImpl { void checkAudio(); + /** + * Subscribe to buddySipUri for an accountID + */ + void subscribePresence(const std::string& accountID, const std::string& buddySipUri); + private: NON_COPYABLE(ManagerImpl); diff --git a/daemon/src/sip/Makefile.am b/daemon/src/sip/Makefile.am index b960ace4a0..0e681ebfe7 100644 --- a/daemon/src/sip/Makefile.am +++ b/daemon/src/sip/Makefile.am @@ -14,7 +14,11 @@ libsiplink_la_SOURCES = \ sipvoiplink.h \ siptransport.h \ sip_utils.cpp \ - sip_utils.h + sip_utils.h \ + sipbuddy.cpp \ + sipbuddy.h \ + sipvoip_pres.cpp \ + sipvoip_pres.h if BUILD_SDES libsiplink_la_SOURCES+= sdes_negotiator.cpp \ diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 7e07835578..98a6fb8bb4 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -78,6 +78,8 @@ #include <istream> #include <utility> // for std::pair #include <algorithm> +#include "sipvoip_pres.h" +#include"pjsip-simple/presence.h" using namespace sfl; @@ -442,6 +444,13 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) } // end anonymous namespace /*************************************************************************************************/ +pjsip_endpoint * SIPVoIPLink::getEndpoint() { + return endpt_; +} + +pjsip_module * SIPVoIPLink::getMod() { + return &mod_ua_; +} SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), sipAccountMap_(), sipCallMapMutex_(), sipCallMap_(), evThread_(this) @@ -500,6 +509,11 @@ SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), sipAccountMap_(), TRY(pjsip_evsub_init_module(endpt_)); TRY(pjsip_xfer_init_module(endpt_)); +// aol changes + TRY(pjsip_pres_init_module(endpt_, pjsip_evsub_instance())); + TRY(pjsip_endpt_register_module(endpt_, &my_mod_pres)); +// aol changes end + static const pjsip_inv_callback inv_cb = { invite_session_state_changed_cb, outgoing_request_forked_cb, @@ -1539,6 +1553,12 @@ SIPVoIPLink::SIPStartCall(SIPCall *call) "calling %s", toUri.c_str()); return false; } +// aol + pj_str_t subj_hdr_name = pj_str("Subject"); + pjsip_hdr* subj_hdr = (pjsip_hdr*) pjsip_parse_hdr(dialog->pool, &subj_hdr_name, "Phone call", 10, NULL); + + pj_list_push_back(&dialog->inv_hdr, subj_hdr); +// aol if (pjsip_inv_create_uac(dialog, call->getLocalSDP()->getLocalSdpSession(), 0, &call->inv) != PJ_SUCCESS) { ERROR("Unable to create invite session for user agent client"); @@ -2315,3 +2335,6 @@ void setCallMediaLocal(SIPCall* call, const std::string &localIP) #endif } } // end anonymous namespace +int SIPVoIPLink::getModId() { + return mod_ua_.id; +} diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index b37c05f4c3..414f26861e 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -294,7 +294,9 @@ class SIPVoIPLink : public VoIPLink { std::string getAccountIdFromNameAndServer(const std::string &userName, const std::string &server) const; - + int getModId(); + pjsip_endpoint * getEndpoint(); + pjsip_module * getMod(); private: NON_COPYABLE(SIPVoIPLink); -- GitLab