Skip to content
Snippets Groups Projects
Select Git revision
  • 49b81289f26e338442dd7e8aa07a15af4f684414
  • master default protected
  • release/beta-qt-202301101210
  • stable
  • release/beta-qt-202211182015
  • release/beta-qt-202211181752
  • release/beta-qt-202211171508
  • release/beta-qt-202211081754
  • release/beta-qt-202211071518
  • release/beta-qt-202210270957
  • release/beta-qt-202210071648
  • release/beta-qt-202209291549
  • release/beta-qt-202209011129
  • release/beta-qt-202208261640
  • release/beta-qt-202208241511
  • release/beta-qt-202208231849
  • release/beta-qt-202208091525
  • release/beta-qt-202207191241
  • release/beta-qt-202207181708
  • release/beta-qt-202207131914
  • release/beta-qt-202207131513
  • android/release_358
  • android/release_357
  • android/release_356
  • android/release_355
  • android/release_354
  • 20221220.0956.79e1207
  • android/release_353
  • android/release_352
  • android/release_350
  • android/release_349
  • android/release_348
  • android/release_347
  • 20221031.1308.130cc26
  • android/release_346
  • android/release_345
  • android/release_344
  • android/release_343
  • android/release_342
  • android/release_341
  • android/release_340
41 results

deploy-packages.sh

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    presencemanager.cpp 4.54 KiB
    /*
     *  Copyright (C) 2013 Savoir-Faire Linux Inc.
     *  Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
     *
     *  Additional permission under GNU GPL version 3 section 7:
     *
     *  If you modify this program, or any covered work, by linking or
     *  combining it with the OpenSSL project's OpenSSL library (or a
     *  modified version of that library), containing parts covered by the
     *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
     *  grants you additional permission to convey the resulting work.
     *  Corresponding Source for a non-source form of such a combination
     *  shall include the source code for the parts of OpenSSL used as well
     *  as that of the covered work.
     */
    
    #ifdef HAVE_CONFIG_H
    #include "config.h"
    #endif
    
    #include "presencemanager.h"
    
    #include <cerrno>
    #include <sstream>
    
    #include "logger.h"
    #include "sip/sipaccount.h"
    #include "manager.h"
    #include "sip/sippresence.h"
    #include "sip/pres_sub_client.h"
    
    namespace {
        constexpr static const char* SERVER_PATH    = "/org/sflphone/SFLphone/PresenceManager";
        constexpr static const char* STATUS_KEY     = "Status";
        constexpr static const char* LINESTATUS_KEY = "LineStatus";
        constexpr static const char* ONLINE_KEY     = "Online";
        constexpr static const char* OFFLINE_KEY    = "Offline";
    }
    
    PresenceManager::PresenceManager(DBus::Connection& connection) :
        DBus::ObjectAdaptor(connection, SERVER_PATH)
    {}
    
    /**
     * Un/subscribe to buddySipUri for an accountID
     */
    void
    PresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag)
    {
    
        SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
        if (!sipaccount)
            ERROR("Could not find account %s",accountID.c_str());
        else{
            DEBUG("%subscribePresence (acc:%s, buddy:%s)",flag? "S":"Uns", accountID.c_str(), uri.c_str());
            sipaccount->getPresence()->subscribeClient(uri,flag);
        }
    }
    
    /**
     * push a presence for a account
     * Notify for IP2IP account and publish for PBX account
     */
    void
    PresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note)
    {
        SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
        if (!sipaccount)
            ERROR("Could not find account %s.",accountID.c_str());
        else{
            DEBUG("Send Presence (acc:%s, status %s).",accountID.c_str(),status? "online":"offline");
            sipaccount->getPresence()->sendPresence(status, note);
        }
    }
    
    /**
     * Accept or not a PresSubServer request for IP2IP account
     */
    void
    PresenceManager::answerServerRequest(const std::string& uri, const bool& flag)
    {
        SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
        if (!sipaccount)
            ERROR("Could not find account IP2IP");
        else{
            DEBUG("Approve presence (acc:IP2IP, serv:%s, flag:%s)", uri.c_str(), flag? "true":"false");
            sipaccount->getPresence()->approvePresSubServer(uri, flag);
        }
    }
    
    /**
     * Get all active subscriptions for "accountID"
     */
    std::vector<std::map<std::string, std::string> >
    PresenceManager::getSubscriptions(const std::string& accountID)
    {
        std::vector<std::map<std::string, std::string> > ret;
        SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
        if (sipaccount) {
            for (auto s : sipaccount->getPresence()->getClientSubscriptions()) {
                std::map<std::string, std::string> sub;
                sub[ STATUS_KEY     ] = s->isPresent()?ONLINE_KEY:OFFLINE_KEY;
                sub[ LINESTATUS_KEY ] = s->getLineStatus();
                ret.push_back(sub);
            }
        }
        return ret;
    }
    
    /**
     * Batch subscribing of URIs
     */
    void
    PresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
    {
        SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
        for (const auto &u : uris)
            sipaccount->getPresence()->subscribeClient(u,true);
    }