2
* Copyright (C) 2013 Savoir-Faire Linux Inc.
3
* Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Additional permission under GNU GPL version 3 section 7:
21
* If you modify this program, or any covered work, by linking or
22
* combining it with the OpenSSL project's OpenSSL library (or a
23
* modified version of that library), containing parts covered by the
24
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25
* grants you additional permission to convey the resulting work.
26
* Corresponding Source for a non-source form of such a combination
27
* shall include the source code for the parts of OpenSSL used as well
28
* as that of the covered work.
35
#include "presencemanager.h"
41
#include "sip/sipaccount.h"
43
#include "sip/sippresence.h"
44
#include "sip/pres_sub_client.h"
47
constexpr static const char* STATUS_KEY = "Status";
48
constexpr static const char* LINESTATUS_KEY = "LineStatus";
49
constexpr static const char* ONLINE_KEY = "Online";
50
constexpr static const char* OFFLINE_KEY = "Offline";
54
* Un/subscribe to buddySipUri for an accountID
57
PresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag)
59
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
61
ERROR("Could not find account %s",accountID.c_str());
65
SIPPresence *pres = sipaccount->getPresence();
66
if (pres and pres->isEnabled() and pres->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)) {
67
DEBUG("%subscribePresence (acc:%s, buddy:%s)", flag ? "S" : "Uns",
68
accountID.c_str(), uri.c_str());
69
pres->subscribeClient(uri, flag);
74
* push a presence for a account
75
* Notify for IP2IP account and publish for PBX account
78
PresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note)
80
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
82
ERROR("Could not find account %s.",accountID.c_str());
86
SIPPresence *pres = sipaccount->getPresence();
87
if (pres and pres->isEnabled() and pres->isSupported(PRESENCE_FUNCTION_PUBLISH)) {
88
DEBUG("Send Presence (acc:%s, status %s).", accountID.c_str(),
89
status ? "online" : "offline");
90
pres->sendPresence(status, note);
95
* Accept or not a PresSubServer request for IP2IP account
98
PresenceManager::answerServerRequest(const std::string& uri, const bool& flag)
100
SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
102
ERROR("Could not find account IP2IP");
106
DEBUG("Approve presence (acc:IP2IP, serv:%s, flag:%s)", uri.c_str(),
107
flag ? "true" : "false");
108
sipaccount->getPresence()->approvePresSubServer(uri, flag);
112
* Get all active subscriptions for "accountID"
114
std::vector<std::map<std::string, std::string> >
115
PresenceManager::getSubscriptions(const std::string& accountID)
117
std::vector<std::map<std::string, std::string> > ret;
118
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
120
for (auto s : sipaccount->getPresence()->getClientSubscriptions()) {
121
std::map<std::string, std::string> sub;
122
sub[ STATUS_KEY ] = s->isPresent() ? ONLINE_KEY : OFFLINE_KEY;
123
sub[ LINESTATUS_KEY ] = s->getLineStatus();
131
* Batch subscribing of URIs
134
PresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
136
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
140
for (const auto &u : uris)
141
sipaccount->getPresence()->subscribeClient(u, true);