account.cpp 19.3 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2019 Savoir-faire Linux Inc.
3 4
 *
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
6
 *  Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
7 8 9
 *
 *  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
10
 *  the Free Software Foundation; either version 3 of the License, or
11 12 13 14 15 16 17 18 19
 *  (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
20
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
21
 */
22

23 24 25
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
26
#include "account.h"
27

28
#include <algorithm>
29
#include <iterator>
30
#include <mutex>
31

Adrien Béraud's avatar
Adrien Béraud committed
32
#ifdef ENABLE_VIDEO
33
#include "libav_utils.h"
34
#endif
35

36
#include "logger.h"
37 38
#include "manager.h"

39 40 41
#include <opendht/rng.h>
using random_device = dht::crypto::random_device;

42
#include "client/ring_signal.h"
43
#include "account_schema.h"
44
#include "dring/account_const.h"
45
#include "string_utils.h"
46
#include "fileutils.h"
47
#include "config/yamlparser.h"
48
#include "system_codec_container.h"
49
#include "ice_transport.h"
50

51 52
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
53
#include <yaml-cpp/yaml.h>
54
#pragma GCC diagnostic pop
55

56
#include "upnp/upnp_control.h"
57
#include "ip_utils.h"
58
#include "compiler_intrinsics.h"
59
#include "dring/account_const.h"
60

Adrien Béraud's avatar
Adrien Béraud committed
61
namespace jami {
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
const char * const Account::ALL_CODECS_KEY                = "allCodecs";
const char * const Account::VIDEO_CODEC_ENABLED           = "enabled";
const char * const Account::VIDEO_CODEC_NAME              = "name";
const char * const Account::VIDEO_CODEC_PARAMETERS        = "parameters";
const char * const Account::VIDEO_CODEC_BITRATE           = "bitrate";
const char * const Account::RINGTONE_PATH_KEY             = "ringtonePath";
const char * const Account::RINGTONE_ENABLED_KEY          = "ringtoneEnabled";
const char * const Account::VIDEO_ENABLED_KEY             = "videoEnabled";
const char * const Account::DISPLAY_NAME_KEY              = "displayName";
const char * const Account::ALIAS_KEY                     = "alias";
const char * const Account::TYPE_KEY                      = "type";
const char * const Account::ID_KEY                        = "id";
const char * const Account::USERNAME_KEY                  = "username";
const char * const Account::AUTHENTICATION_USERNAME_KEY   = "authenticationUsername";
const char * const Account::PASSWORD_KEY                  = "password";
const char * const Account::HOSTNAME_KEY                  = "hostname";
const char * const Account::ACCOUNT_ENABLE_KEY            = "enable";
const char * const Account::ACCOUNT_AUTOANSWER_KEY        = "autoAnswer";
const char * const Account::ACCOUNT_ACTIVE_CALL_LIMIT_KEY = "activeCallLimit";
const char * const Account::MAILBOX_KEY                   = "mailbox";
83
const char * const Account::DEFAULT_USER_AGENT            = PACKAGE_NAME;
84 85 86 87
const char * const Account::USER_AGENT_KEY                = "useragent";
const char * const Account::HAS_CUSTOM_USER_AGENT_KEY     = "hasCustomUserAgent";
const char * const Account::PRESENCE_MODULE_ENABLED_KEY   = "presenceModuleEnabled";
const char * const Account::UPNP_ENABLED_KEY              = "upnpEnabled";
88

89
#ifdef __ANDROID__
90
constexpr const char * const DEFAULT_RINGTONE_PATH = "/data/data/cx.ring/files/ringtones/default.opus";
91
#else
92
constexpr const char * const DEFAULT_RINGTONE_PATH = "/usr/share/ring/ringtones/default.opus";
93 94
#endif

95
Account::Account(const std::string &accountID)
96
    : accountID_(accountID)
97 98 99
    , username_()
    , hostname_()
    , alias_()
100
    , enabled_(true)
101
    , autoAnswerEnabled_(false)
102
    , registrationState_(RegistrationState::UNREGISTERED)
103 104
    , systemCodecContainer_(getSystemCodecContainer())
    , accountCodecInfoList_()
105
    , ringtonePath_("")
106 107
    , ringtoneEnabled_(true)
    , displayName_("")
108
    , userAgent_(DEFAULT_USER_AGENT)
109
    , hasCustomUserAgent_(false)
110
    , mailBox_()
Julien Bonjean's avatar
Julien Bonjean committed
111
{
112
    random_device rdev;
113
    std::seed_seq seed {rdev(), rdev()};
114
    rand.seed(seed);
115

116
    // Initialize the codec order, used when creating a new account
117
    loadDefaultCodecs();
118
    ringtonePath_ = DEFAULT_RINGTONE_PATH;
119 120
}

Julien Bonjean's avatar
Julien Bonjean committed
121
Account::~Account()
122
{}
123

124
void
125
Account::attachCall(const std::string& id)
126 127 128 129 130
{
    callIDSet_.insert(id);
}

void
131
Account::detachCall(const std::string& id)
132 133 134 135
{
    callIDSet_.erase(id);
}

136 137 138
void
Account::freeAccount()
{
139 140
    for (const auto& id : callIDSet_)
        Manager::instance().hangupCall(id);
141 142
}

143 144 145 146 147 148 149 150 151 152 153
void
Account::enableUpnp(bool state)
{
    std::lock_guard<std::mutex> lk {upnp_mtx};

    if (state and !upnp_)
        upnp_.reset(new upnp::Controller());
    else if (!state and upnp_)
        upnp_.reset();
}

154
void
155
Account::setRegistrationState(RegistrationState state, unsigned detail_code, const std::string& detail_str)
Julien Bonjean's avatar
Julien Bonjean committed
156
{
157 158
    if (state != registrationState_) {
        registrationState_ = state;
Emmanuel Milou's avatar
Emmanuel Milou committed
159
        // Notify the client
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
        runOnMainThread([
                accountId = accountID_,
                state = mapStateNumberToString(registrationState_),
                detail_code,
                detail_str,
                details = getVolatileAccountDetails()
        ]{
            emitSignal<DRing::ConfigurationSignal::RegistrationStateChanged>(
                accountId,
                state,
                detail_code,
                detail_str);

            emitSignal<DRing::ConfigurationSignal::VolatileDetailsChanged>(accountId, details);
        });
Emmanuel Milou's avatar
Emmanuel Milou committed
175
    }
176
}
177

178 179
void
Account::loadDefaultCodecs()
Julien Bonjean's avatar
Julien Bonjean committed
180
{
181 182 183 184
    // default codec are system codecs
    auto systemCodecList = systemCodecContainer_->getSystemCodecInfoList();

    for (const auto& systemCodec: systemCodecList) {
185 186
        // As defined in SDP RFC, only select a codec if he can encode and decode
        if ((systemCodec->codecType & CODEC_ENCODER_DECODER) != CODEC_ENCODER_DECODER)
187 188 189 190 191 192 193 194 195
            continue;

        if (systemCodec->mediaType & MEDIA_AUDIO) {
            // we are sure of our downcast type : use static_pointer_cast
            auto audioCodec = std::static_pointer_cast<SystemAudioCodecInfo>(systemCodec);
            // instantiate AccountAudioCodecInfo initialized with our system codec
            auto codec = std::make_shared <AccountAudioCodecInfo>(*audioCodec);
            accountCodecInfoList_.push_back(codec);
        }
196

197 198 199 200 201 202 203 204
        if (systemCodec->mediaType & MEDIA_VIDEO) {
            // we are sure of our downcast type : use static_pointer_cast
            auto videoCodec = std::static_pointer_cast<SystemVideoCodecInfo>(systemCodec);
            // instantiate AccountVideoCodecInfo initialized with our system codec
            auto codec = std::make_shared<AccountVideoCodecInfo>(*videoCodec);
            accountCodecInfoList_.push_back(codec);
        }
    }
205
}
206

207 208 209 210 211 212 213 214 215 216 217
// Convert a list of payloads in a special format, readable by the server.
// Required format: payloads separated by slashes.
// @return std::string The serializable string
static std::string
join_string(const std::vector<unsigned> &v)
{
    std::ostringstream os;
    std::copy(std::begin(v), std::end(v), std::ostream_iterator<unsigned>(os, "/"));
    return os.str();
}

218
void
219
Account::serialize(YAML::Emitter& out) const
220
{
221
    const auto& activeCodecs = join_string(getActiveCodecs(MEDIA_ALL));
222

223 224 225 226
    out << YAML::Key << ID_KEY << YAML::Value << accountID_;
    out << YAML::Key << ALIAS_KEY << YAML::Value << alias_;
    out << YAML::Key << ACCOUNT_ENABLE_KEY << YAML::Value << enabled_;
    out << YAML::Key << TYPE_KEY << YAML::Value << getAccountType();
227
    out << YAML::Key << ALL_CODECS_KEY << YAML::Value << activeCodecs;
228 229
    out << YAML::Key << MAILBOX_KEY << YAML::Value << mailBox_;
    out << YAML::Key << ACCOUNT_AUTOANSWER_KEY << YAML::Value << autoAnswerEnabled_;
230
    out << YAML::Key << ACCOUNT_ACTIVE_CALL_LIMIT_KEY << YAML::Value << activeCallLimit_;
231 232 233 234 235 236
    out << YAML::Key << RINGTONE_ENABLED_KEY << YAML::Value << ringtoneEnabled_;
    out << YAML::Key << RINGTONE_PATH_KEY << YAML::Value << ringtonePath_;
    out << YAML::Key << HAS_CUSTOM_USER_AGENT_KEY << YAML::Value << hasCustomUserAgent_;
    out << YAML::Key << USER_AGENT_KEY << YAML::Value << userAgent_;
    out << YAML::Key << DISPLAY_NAME_KEY << YAML::Value << displayName_;
    out << YAML::Key << HOSTNAME_KEY << YAML::Value << hostname_;
237
    out << YAML::Key << UPNP_ENABLED_KEY << YAML::Value << bool(upnp_);
238 239
}

240
void
241
Account::unserialize(const YAML::Node& node)
242
{
243 244
    using yaml_utils::parseValue;

245 246 247
    parseValue(node, ALIAS_KEY, alias_);
    parseValue(node, ACCOUNT_ENABLE_KEY, enabled_);
    parseValue(node, ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled_);
248
    parseValue(node, ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit_);
249 250 251 252
    //parseValue(node, PASSWORD_KEY, password_);

    parseValue(node, MAILBOX_KEY, mailBox_);

253 254 255 256
    std::string activeCodecs;
    parseValue(node, ALL_CODECS_KEY, activeCodecs);
    setActiveCodecs(split_string_to_unsigned(activeCodecs, '/'));

257 258 259 260 261 262 263
    parseValue(node, DISPLAY_NAME_KEY, displayName_);
    parseValue(node, HOSTNAME_KEY, hostname_);

    parseValue(node, HAS_CUSTOM_USER_AGENT_KEY, hasCustomUserAgent_);
    parseValue(node, USER_AGENT_KEY, userAgent_);
    parseValue(node, RINGTONE_PATH_KEY, ringtonePath_);
    parseValue(node, RINGTONE_ENABLED_KEY, ringtoneEnabled_);
264 265 266
    if (ringtonePath_.empty()) {
        ringtonePath_ = DEFAULT_RINGTONE_PATH;
    }
267

268 269
    bool enabled;
    parseValue(node, UPNP_ENABLED_KEY, enabled);
270
    enableUpnp(enabled);
271 272
}

273 274
void
Account::setAccountDetails(const std::map<std::string, std::string> &details)
275
{
276
    // Account setting common to any account type
277
    parseString(details, Conf::CONFIG_ACCOUNT_ALIAS, alias_);
278
    parseString(details, Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName_);
279 280 281 282 283
    parseBool(details, Conf::CONFIG_ACCOUNT_ENABLE, enabled_);
    parseString(details, Conf::CONFIG_ACCOUNT_HOSTNAME, hostname_);
    parseString(details, Conf::CONFIG_ACCOUNT_MAILBOX, mailBox_);
    parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, userAgent_);
    parseBool(details, Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled_);
284
    parseInt(details, DRing::Account::ConfProperties::ACTIVE_CALL_LIMIT, activeCallLimit_);
285 286
    parseBool(details, Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled_);
    parseString(details, Conf::CONFIG_RINGTONE_PATH, ringtonePath_);
287 288 289
    if (ringtonePath_.empty()) {
        ringtonePath_ = DEFAULT_RINGTONE_PATH;
    }
290
    parseBool(details, Conf::CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT, hasCustomUserAgent_);
291
    if (hasCustomUserAgent_)
292
        parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, userAgent_);
293 294
    else
        userAgent_ = DEFAULT_USER_AGENT;
295 296
    bool enabled;
    parseBool(details, Conf::CONFIG_UPNP_ENABLED, enabled);
297
    enableUpnp(enabled);
298 299
}

300 301
std::map<std::string, std::string>
Account::getAccountDetails() const
302
{
303 304
    return {
        {Conf::CONFIG_ACCOUNT_ALIAS,        alias_},
305
        {Conf::CONFIG_ACCOUNT_DISPLAYNAME,  displayName_},
306 307 308 309 310 311 312 313
        {Conf::CONFIG_ACCOUNT_ENABLE,       enabled_ ? TRUE_STR : FALSE_STR},
        {Conf::CONFIG_ACCOUNT_TYPE,         getAccountType()},
        {Conf::CONFIG_ACCOUNT_HOSTNAME,     hostname_},
        {Conf::CONFIG_ACCOUNT_USERNAME,     username_},
        {Conf::CONFIG_ACCOUNT_MAILBOX,      mailBox_},
        {Conf::CONFIG_ACCOUNT_USERAGENT,    hasCustomUserAgent_ ? userAgent_ : DEFAULT_USER_AGENT},
        {Conf::CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT, hasCustomUserAgent_ ? userAgent_ : DEFAULT_USER_AGENT},
        {Conf::CONFIG_ACCOUNT_AUTOANSWER,   autoAnswerEnabled_ ? TRUE_STR : FALSE_STR},
314
        {DRing::Account::ConfProperties::ACTIVE_CALL_LIMIT,   std::to_string(activeCallLimit_)},
315 316
        {Conf::CONFIG_RINGTONE_ENABLED,     ringtoneEnabled_ ? TRUE_STR : FALSE_STR},
        {Conf::CONFIG_RINGTONE_PATH,        ringtonePath_},
317
        {Conf::CONFIG_UPNP_ENABLED,         upnp_ ? TRUE_STR : FALSE_STR}
318
    };
319 320
}

321 322
std::map<std::string, std::string>
Account::getVolatileAccountDetails() const
323
{
324
    return {
325
        {Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS, mapStateNumberToString(registrationState_)},
326
        {DRing::Account::VolatileProperties::ACTIVE, active_ ? TRUE_STR : FALSE_STR}
327
    };
328 329
}

330 331
bool
Account::hasActiveCodec(MediaType mediaType) const
332
{
333 334 335 336
    for (auto& codecIt: accountCodecInfoList_)
        if ((codecIt->systemCodecInfo.mediaType & mediaType) && codecIt->isActive)
            return true;
    return false;
337 338 339
}

void
340
Account::setActiveCodecs(const std::vector<unsigned>& list)
Julien Bonjean's avatar
Julien Bonjean committed
341
{
342
    // first clear the previously stored codecs
343
    // TODO: mutex to protect isActive
344
    setAllCodecsActive(MEDIA_ALL, false);
345

Emmanuel Milou's avatar
Emmanuel Milou committed
346
    // list contains the ordered payload of active codecs picked by the user for this account
347
    // we used the codec vector to save the order.
348 349
    uint16_t order = 1;
    for (const auto& item : list) {
350
        if (auto accCodec = searchCodecById(item, MEDIA_ALL)) {
351 352 353 354
            accCodec->isActive = true;
            accCodec->order = order;
            ++order;
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
355 356
    }

357 358
    std::sort(std::begin(accountCodecInfoList_),
              std::end  (accountCodecInfoList_),
359 360
              [](const std::shared_ptr<AccountCodecInfo>& a,
                 const std::shared_ptr<AccountCodecInfo>& b) {
361 362
                  return a->order < b->order;
              });
363 364

    if (!hasActiveCodec(MEDIA_AUDIO)) {
Adrien Béraud's avatar
Adrien Béraud committed
365
        JAMI_WARN("All audio codecs disabled, enabling all");
366 367 368
        setAllCodecsActive(MEDIA_AUDIO, true);
    }
    if (!hasActiveCodec(MEDIA_VIDEO)) {
Adrien Béraud's avatar
Adrien Béraud committed
369
        JAMI_WARN("All video codecs disabled, enabling all");
370 371
        setAllCodecsActive(MEDIA_VIDEO, true);
    }
372
}
373

374 375
std::string
Account::mapStateNumberToString(RegistrationState state)
376
{
377 378 379 380 381 382 383 384 385 386 387 388 389 390
#define CASE_STATE(X) case RegistrationState::X: \
                           return #X

    switch (state) {
        CASE_STATE(UNREGISTERED);
        CASE_STATE(TRYING);
        CASE_STATE(REGISTERED);
        CASE_STATE(ERROR_GENERIC);
        CASE_STATE(ERROR_AUTH);
        CASE_STATE(ERROR_NETWORK);
        CASE_STATE(ERROR_HOST);
        CASE_STATE(ERROR_SERVICE_UNAVAILABLE);
        CASE_STATE(ERROR_EXIST_STUN);
        CASE_STATE(ERROR_NOT_ACCEPTABLE);
391 392
        CASE_STATE(ERROR_NEED_MIGRATION);
        CASE_STATE(INITIALIZING);
393
        default:
394
            return DRing::Account::States::ERROR_GENERIC;
395
    }
396

397
#undef CASE_STATE
398
}
399

400
std::vector<unsigned>
401
Account::getDefaultCodecsId()
402
{
403
    return getSystemCodecContainer()->getSystemCodecInfoIdList(MEDIA_ALL);
404
}
405

406 407 408
std::map<std::string, std::string>
Account::getDefaultCodecDetails(const unsigned& codecId)
{
Adrien Béraud's avatar
Adrien Béraud committed
409
    auto codec = jami::getSystemCodecContainer()->searchCodecById(codecId, jami::MEDIA_ALL);
410
    if (codec) {
Adrien Béraud's avatar
Adrien Béraud committed
411 412
        if (codec->mediaType & jami::MEDIA_AUDIO) {
            auto audioCodec = std::static_pointer_cast<jami::SystemAudioCodecInfo>(codec);
413 414
            return audioCodec->getCodecSpecifications();
        }
Adrien Béraud's avatar
Adrien Béraud committed
415 416
        if (codec->mediaType & jami::MEDIA_VIDEO) {
            auto videoCodec = std::static_pointer_cast<jami::SystemVideoCodecInfo>(codec);
417 418 419
            return videoCodec->getCodecSpecifications();
        }
    }
420
    return {};
421 422
}

423 424 425
#define find_iter()                                    \
    const auto& iter = details.find(key);               \
    if (iter == details.end()) {                       \
Adrien Béraud's avatar
Adrien Béraud committed
426
        JAMI_ERR("Couldn't find key \"%s\"", key);     \
427 428
        return;                                        \
    }
429 430

void
431 432
Account::parseString(const std::map<std::string, std::string>& details,
                     const char* key, std::string& s)
433 434 435 436 437
{
    find_iter();
    s = iter->second;
}

438 439 440 441 442 443 444 445
void
Account::parsePath(const std::map<std::string, std::string>& details,
                   const char *key, std::string &s, const std::string& base)
{
    find_iter();
    s = fileutils::getCleanPath(base, iter->second);
}

446
void
447 448
Account::parseBool(const std::map<std::string, std::string>& details,
                   const char* key, bool &b)
449 450
{
    find_iter();
451
    b = iter->second == TRUE_STR;
452 453 454
}

#undef find_iter
455

456
/**
457 458
 * Get the UPnP IP (external router) address.
 * If use UPnP is set to false, the address will be empty.
459
 */
460
IpAddr
461 462
Account::getUPnPIpAddress() const
{
463
    std::lock_guard<std::mutex> lk(upnp_mtx);
464
    if (upnp_)
465 466
        return upnp_->getExternalIP();
    return {};
467 468
}

469
/**
470 471
 * returns whether or not UPnP is enabled and active_
 * ie: if it is able to make port mappings
472
 */
473
bool
474
Account::getUPnPActive() const
475
{
476
    std::lock_guard<std::mutex> lk(upnp_mtx);
477
    if (upnp_)
478
        return upnp_->hasValidIGD();
479 480 481 482 483 484 485 486 487 488
    return false;
}

/*
 * private account codec searching functions
 *
 * */
std::shared_ptr<AccountCodecInfo>
Account::searchCodecById(unsigned codecId, MediaType mediaType)
{
489 490 491 492
    if (mediaType != MEDIA_NONE) {
        for (auto& codecIt: accountCodecInfoList_) {
            if ((codecIt->systemCodecInfo.id == codecId) &&
                (codecIt->systemCodecInfo.mediaType & mediaType ))
493
                return codecIt;
494
        }
495 496 497 498 499
    }
    return {};
}

std::shared_ptr<AccountCodecInfo>
Adrien Béraud's avatar
Adrien Béraud committed
500
Account::searchCodecByName(const std::string& name, MediaType mediaType)
501
{
502 503
    if (mediaType != MEDIA_NONE) {
        for (auto& codecIt: accountCodecInfoList_) {
Adrien Béraud's avatar
Adrien Béraud committed
504
            if (codecIt->systemCodecInfo.name == name &&
505 506 507
                (codecIt->systemCodecInfo.mediaType & mediaType ))
                return codecIt;
        }
508 509 510 511 512 513 514
    }
    return {};
}

std::shared_ptr<AccountCodecInfo>
Account::searchCodecByPayload(unsigned payload, MediaType mediaType)
{
515 516 517 518 519 520
    if (mediaType != MEDIA_NONE) {
        for (auto& codecIt: accountCodecInfoList_) {
            if ((codecIt->payloadType == payload ) &&
                (codecIt->systemCodecInfo.mediaType & mediaType ))
                return codecIt;
        }
521 522 523
    }
    return {};
}
524

525
std::vector<unsigned>
526
Account::getActiveCodecs(MediaType mediaType) const
527
{
528 529 530
    if (mediaType == MEDIA_NONE)
        return {};

531 532 533 534 535 536 537 538 539 540 541 542
    std::vector<unsigned> idList;
    for (auto& codecIt: accountCodecInfoList_) {
        if ((codecIt->systemCodecInfo.mediaType & mediaType) &&
            (codecIt->isActive))
            idList.push_back(codecIt->systemCodecInfo.id);
    }
    return idList;
}

std::vector<unsigned>
Account::getAccountCodecInfoIdList(MediaType mediaType) const
{
543 544 545
    if (mediaType == MEDIA_NONE)
        return {};

546 547 548 549 550
    std::vector<unsigned> idList;
    for (auto& codecIt: accountCodecInfoList_) {
        if (codecIt->systemCodecInfo.mediaType & mediaType)
            idList.push_back(codecIt->systemCodecInfo.id);
    }
551

552 553 554 555
    return idList;
}

void
556
Account::setAllCodecsActive(MediaType mediaType, bool active)
557
{
558 559
    if (mediaType == MEDIA_NONE)
        return;
560 561
    for (auto& codecIt: accountCodecInfoList_) {
        if (codecIt->systemCodecInfo.mediaType & mediaType)
562
            codecIt->isActive = active;
563 564 565 566
    }
}

std::vector<std::shared_ptr<AccountCodecInfo>>
567
Account::getActiveAccountCodecInfoList(MediaType mediaType) const
568
{
569 570 571
    if (mediaType == MEDIA_NONE)
        return {};

572 573 574 575 576 577
    std::vector<std::shared_ptr<AccountCodecInfo>> accountCodecList;
    for (auto& codecIt: accountCodecInfoList_) {
        if ((codecIt->systemCodecInfo.mediaType & mediaType) &&
            (codecIt->isActive))
            accountCodecList.push_back(codecIt);
    }
578

579
    return accountCodecList;
580 581
}

582 583 584 585 586 587 588 589
const IceTransportOptions
Account::getIceOptions() const noexcept
{
    IceTransportOptions opts;
    opts.upnpEnable = getUPnPActive();
    return opts;
}

Adrien Béraud's avatar
Adrien Béraud committed
590
} // namespace jami