~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/src/client/presencemanager.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2013 Savoir-Faire Linux Inc.
 
3
 *  Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
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.
 
29
 */
 
30
 
 
31
#ifdef HAVE_CONFIG_H
 
32
#include "config.h"
 
33
#endif
 
34
 
 
35
#include "presencemanager.h"
 
36
 
 
37
#include <cerrno>
 
38
#include <sstream>
 
39
 
 
40
#include "logger.h"
 
41
#include "sip/sipaccount.h"
 
42
#include "manager.h"
 
43
#include "sip/sippresence.h"
 
44
#include "sip/pres_sub_client.h"
 
45
 
 
46
namespace {
 
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";
 
51
}
 
52
 
 
53
/**
 
54
 * Un/subscribe to buddySipUri for an accountID
 
55
 */
 
56
void
 
57
PresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag)
 
58
{
 
59
    SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
 
60
    if (!sipaccount) {
 
61
        ERROR("Could not find account %s",accountID.c_str());
 
62
        return;
 
63
    }
 
64
 
 
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);
 
70
    }
 
71
}
 
72
 
 
73
/**
 
74
 * push a presence for a account
 
75
 * Notify for IP2IP account and publish for PBX account
 
76
 */
 
77
void
 
78
PresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note)
 
79
{
 
80
    SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
 
81
    if (!sipaccount) {
 
82
        ERROR("Could not find account %s.",accountID.c_str());
 
83
        return;
 
84
    }
 
85
 
 
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);
 
91
    }
 
92
}
 
93
 
 
94
/**
 
95
 * Accept or not a PresSubServer request for IP2IP account
 
96
 */
 
97
void
 
98
PresenceManager::answerServerRequest(const std::string& uri, const bool& flag)
 
99
{
 
100
    SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
 
101
    if (!sipaccount) {
 
102
        ERROR("Could not find account IP2IP");
 
103
        return;
 
104
    }
 
105
 
 
106
    DEBUG("Approve presence (acc:IP2IP, serv:%s, flag:%s)", uri.c_str(),
 
107
          flag ? "true" : "false");
 
108
    sipaccount->getPresence()->approvePresSubServer(uri, flag);
 
109
}
 
110
 
 
111
/**
 
112
 * Get all active subscriptions for "accountID"
 
113
 */
 
114
std::vector<std::map<std::string, std::string> >
 
115
PresenceManager::getSubscriptions(const std::string& accountID)
 
116
{
 
117
    std::vector<std::map<std::string, std::string> > ret;
 
118
    SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
 
119
    if (sipaccount) {
 
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();
 
124
            ret.push_back(sub);
 
125
        }
 
126
    }
 
127
    return ret;
 
128
}
 
129
 
 
130
/**
 
131
 * Batch subscribing of URIs
 
132
 */
 
133
void
 
134
PresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
 
135
{
 
136
    SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
 
137
    if (!sipaccount)
 
138
        return;
 
139
 
 
140
    for (const auto &u : uris)
 
141
        sipaccount->getPresence()->subscribeClient(u, true);
 
142
}