LCOV - code coverage report
Current view: top level - foo/src/client - configurationmanager.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 55 554 9.9 %
Date: 2026-04-01 09:29:43 Functions: 15 142 10.6 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2026 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifdef HAVE_CONFIG_H
      19             : #include "config.h"
      20             : #endif
      21             : 
      22             : #include "configurationmanager_interface.h"
      23             : #include "manager.h"
      24             : #include "logger.h"
      25             : #include "fileutils.h"
      26             : #include "sip/sipaccount.h"
      27             : #include "jamidht/jamiaccount.h"
      28             : #include "sip/sipaccount_config.h"
      29             : #include "jamidht/jamiaccount_config.h"
      30             : #include "audio/audiolayer.h"
      31             : #include "system_codec_container.h"
      32             : #include "account_const.h"
      33             : #include "security_const.h"
      34             : #include "client/jami_signal.h"
      35             : #include "audio/ringbufferpool.h"
      36             : #include "connectivity/security/tlsvalidator.h"
      37             : 
      38             : #include <dhtnet/ip_utils.h>
      39             : #include <dhtnet/upnp/upnp_context.h>
      40             : #include <dhtnet/certstore.h>
      41             : 
      42             : #ifdef __APPLE__
      43             : #include <TargetConditionals.h>
      44             : #endif
      45             : 
      46             : #ifdef _MSC_VER
      47             : #include "windirent.h"
      48             : #else
      49             : #include <dirent.h>
      50             : #endif
      51             : 
      52             : #include <cerrno>
      53             : #include <cstring>
      54             : 
      55             : #ifdef _WIN32
      56             : #undef interface
      57             : #endif
      58             : 
      59             : namespace libjami {
      60             : 
      61             : constexpr unsigned CODECS_NOT_LOADED = 0x1000; /** Codecs not found */
      62             : 
      63             : using jami::SIPAccount;
      64             : using jami::JamiAccount;
      65             : using jami::tls::TlsValidator;
      66             : using jami::AudioDeviceType;
      67             : 
      68             : void
      69           0 : registerConfHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers)
      70             : {
      71           0 :     registerSignalHandlers(handlers);
      72           0 : }
      73             : 
      74             : std::map<std::string, std::string>
      75           0 : getAccountDetails(const std::string& accountId)
      76             : {
      77           0 :     return jami::Manager::instance().getAccountDetails(accountId);
      78             : }
      79             : 
      80             : std::map<std::string, std::string>
      81           0 : getVolatileAccountDetails(const std::string& accountId)
      82             : {
      83           0 :     return jami::Manager::instance().getVolatileAccountDetails(accountId);
      84             : }
      85             : 
      86             : std::map<std::string, std::string>
      87           0 : validateCertificate(const std::string& accountId, const std::string& certificate)
      88             : {
      89             :     try {
      90           0 :         if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
      91           0 :             return TlsValidator {acc->certStore(), acc->certStore().getCertificate(certificate)}.getSerializedChecks();
      92           0 :     } catch (const std::runtime_error& e) {
      93           0 :         JAMI_WARN("Certificate loading failed: %s", e.what());
      94           0 :     }
      95           0 :     return {{Certificate::ChecksNames::EXIST, Certificate::CheckValuesNames::FAILED}};
      96             : }
      97             : 
      98             : std::map<std::string, std::string>
      99           0 : validateCertificatePath(const std::string& accountId,
     100             :                         const std::string& certificate,
     101             :                         const std::string& privateKey,
     102             :                         const std::string& privateKeyPass,
     103             :                         const std::string& caList)
     104             : {
     105             :     try {
     106           0 :         if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     107           0 :             return TlsValidator {acc->certStore(), certificate, privateKey, privateKeyPass, caList}.getSerializedChecks();
     108           0 :     } catch (const std::runtime_error& e) {
     109           0 :         JAMI_WARN("Certificate loading failed: %s", e.what());
     110           0 :         return {{Certificate::ChecksNames::EXIST, Certificate::CheckValuesNames::FAILED}};
     111           0 :     }
     112           0 :     return {};
     113             : }
     114             : 
     115             : std::map<std::string, std::string>
     116           0 : getCertificateDetails(const std::string& accountId, const std::string& certificate)
     117             : {
     118             :     try {
     119           0 :         if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     120           0 :             return TlsValidator {acc->certStore(), acc->certStore().getCertificate(certificate)}.getSerializedDetails();
     121           0 :     } catch (const std::runtime_error& e) {
     122           0 :         JAMI_WARN("Certificate loading failed: %s", e.what());
     123           0 :     }
     124           0 :     return {};
     125             : }
     126             : 
     127             : std::map<std::string, std::string>
     128           0 : getCertificateDetailsPath(const std::string& accountId,
     129             :                           const std::string& certificate,
     130             :                           const std::string& privateKey,
     131             :                           const std::string& privateKeyPassword)
     132             : {
     133             :     try {
     134           0 :         auto crt = std::make_shared<dht::crypto::Certificate>(jami::fileutils::loadFile(certificate));
     135           0 :         if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     136           0 :             TlsValidator validator {acc->certStore(), certificate, privateKey, privateKeyPassword};
     137           0 :             acc->certStore().pinCertificate(validator.getCertificate(), false);
     138           0 :             return validator.getSerializedDetails();
     139           0 :         }
     140           0 :     } catch (const std::runtime_error& e) {
     141           0 :         JAMI_WARN("Certificate loading failed: %s", e.what());
     142           0 :     }
     143           0 :     return {};
     144             : }
     145             : 
     146             : std::vector<std::string>
     147           0 : getPinnedCertificates(const std::string& accountId)
     148             : {
     149           0 :     if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     150           0 :         return acc->certStore().getPinnedCertificates();
     151           0 :     return {};
     152             : }
     153             : 
     154             : std::vector<std::string>
     155           0 : pinCertificate(const std::string& accountId, const std::vector<uint8_t>& certificate, bool local)
     156             : {
     157           0 :     if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     158           0 :         return acc->certStore().pinCertificate(certificate, local);
     159           0 :     return {};
     160             : }
     161             : 
     162             : void
     163           0 : pinCertificatePath(const std::string& accountId, const std::string& path)
     164             : {
     165           0 :     if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     166           0 :         acc->certStore().pinCertificatePath(path);
     167           0 : }
     168             : 
     169             : bool
     170           0 : unpinCertificate(const std::string& accountId, const std::string& certId)
     171             : {
     172           0 :     if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     173           0 :         return acc->certStore().unpinCertificate(certId);
     174           0 :     return {};
     175             : }
     176             : 
     177             : unsigned
     178           0 : unpinCertificatePath(const std::string& accountId, const std::string& path)
     179             : {
     180           0 :     if (const auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     181           0 :         return acc->certStore().unpinCertificatePath(path);
     182           0 :     return {};
     183             : }
     184             : 
     185             : bool
     186           0 : pinRemoteCertificate(const std::string& accountId, const std::string& certId)
     187             : {
     188           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     189           0 :         acc->dht()->findCertificate(dht::InfoHash(certId),
     190           0 :                                     [](const std::shared_ptr<dht::crypto::Certificate>& /*crt*/) {});
     191           0 :         return true;
     192           0 :     }
     193           0 :     return false;
     194             : }
     195             : 
     196             : bool
     197           0 : setCertificateStatus(const std::string& accountId, const std::string& certId, const std::string& ststr)
     198             : {
     199             :     try {
     200           0 :         if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     201           0 :             auto status = dhtnet::tls::TrustStore::statusFromStr(ststr.c_str());
     202           0 :             return acc->setCertificateStatus(certId, status);
     203           0 :         }
     204           0 :     } catch (const std::out_of_range& e) {
     205           0 :         JAMI_WARNING("Argument out of range when setting certificate status: {}", e);
     206           0 :     }
     207           0 :     return false;
     208             : }
     209             : 
     210             : std::vector<std::string>
     211           0 : getCertificatesByStatus(const std::string& accountId, const std::string& ststr)
     212             : {
     213           0 :     auto status = dhtnet::tls::TrustStore::statusFromStr(ststr.c_str());
     214           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     215           0 :         return acc->getCertificatesByStatus(status);
     216           0 :     return {};
     217             : }
     218             : 
     219             : void
     220          16 : setAccountDetails(const std::string& accountId, const std::map<std::string, std::string>& details)
     221             : {
     222          16 :     jami::Manager::instance().setAccountDetails(accountId, details);
     223          16 : }
     224             : 
     225             : void
     226           0 : setAccountActive(const std::string& accountId, bool enable, bool shutdownConnections)
     227             : {
     228           0 :     jami::Manager::instance().setAccountActive(accountId, enable, shutdownConnections);
     229           0 : }
     230             : 
     231             : void
     232           0 : loadAccountAndConversation(const std::string& accountId, bool loadAll, const std::string& convId)
     233             : {
     234           0 :     jami::Manager::instance().loadAccountAndConversation(accountId, loadAll, convId);
     235           0 : }
     236             : 
     237             : void
     238           0 : sendRegister(const std::string& accountId, bool enable)
     239             : {
     240           0 :     jami::Manager::instance().sendRegister(accountId, enable);
     241           0 : }
     242             : 
     243             : bool
     244           0 : isPasswordValid(const std::string& accountId, const std::string& password)
     245             : {
     246           0 :     if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountId))
     247           0 :         return acc->isPasswordValid(password);
     248           0 :     return false;
     249             : }
     250             : 
     251             : std::vector<uint8_t>
     252           0 : getPasswordKey(const std::string& accountID, const std::string& password)
     253             : {
     254           0 :     if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(accountID))
     255           0 :         return acc->getPasswordKey(password);
     256           0 :     return {};
     257             : }
     258             : 
     259             : void
     260           0 : registerAllAccounts()
     261             : {
     262           0 :     jami::Manager::instance().registerAccounts();
     263           0 : }
     264             : 
     265             : uint64_t
     266           0 : sendAccountTextMessage(const std::string& accountId,
     267             :                        const std::string& to,
     268             :                        const std::map<std::string, std::string>& payloads,
     269             :                        int32_t flags)
     270             : {
     271           0 :     bool onlyConnected = flags & 0x1;
     272           0 :     return jami::Manager::instance().sendTextMessage(accountId, to, payloads, onlyConnected);
     273             : }
     274             : 
     275             : std::vector<Message>
     276           0 : getLastMessages(const std::string& accountId, const uint64_t& base_timestamp)
     277             : {
     278           0 :     if (const auto acc = jami::Manager::instance().getAccount(accountId))
     279           0 :         return acc->getLastMessages(base_timestamp);
     280           0 :     return {};
     281             : }
     282             : 
     283             : std::map<std::string, std::string>
     284           0 : getNearbyPeers(const std::string& accountId)
     285             : {
     286           0 :     return jami::Manager::instance().getNearbyPeers(accountId);
     287             : }
     288             : 
     289             : void
     290           0 : updateProfile(const std::string& accountId,
     291             :               const std::string& displayName,
     292             :               const std::string& avatar,
     293             :               const std::string& fileType,
     294             :               int32_t flag)
     295             : {
     296           0 :     if (const auto acc = jami::Manager::instance().getAccount(accountId)) {
     297           0 :         acc->updateProfile(displayName, avatar, fileType, flag);
     298           0 :     }
     299           0 : }
     300             : 
     301             : int
     302           0 : getMessageStatus(uint64_t messageId)
     303             : {
     304           0 :     return jami::Manager::instance().getMessageStatus(messageId);
     305             : }
     306             : 
     307             : int
     308           0 : getMessageStatus(const std::string& accountId, uint64_t messageId)
     309             : {
     310           0 :     return jami::Manager::instance().getMessageStatus(accountId, messageId);
     311             : }
     312             : 
     313             : void
     314           5 : setIsComposing(const std::string& accountId, const std::string& conversationUri, bool isWriting)
     315             : {
     316           5 :     if (const auto acc = jami::Manager::instance().getAccount(accountId))
     317           5 :         acc->setIsComposing(conversationUri, isWriting);
     318           5 : }
     319             : 
     320             : bool
     321           2 : setMessageDisplayed(const std::string& accountId,
     322             :                     const std::string& conversationUri,
     323             :                     const std::string& messageId,
     324             :                     int status)
     325             : {
     326           2 :     if (const auto acc = jami::Manager::instance().getAccount(accountId))
     327           2 :         return acc->setMessageDisplayed(conversationUri, messageId, status);
     328           0 :     return false;
     329             : }
     330             : 
     331             : int32_t
     332           5 : addDevice(const std::string& accountId, const std::string& uri)
     333             : {
     334          20 :     JAMI_DEBUG("[LinkDevice {}] exportToPeer called.", accountId);
     335           5 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     336           5 :         return account->addDevice(uri);
     337           5 :     }
     338           0 :     return static_cast<int32_t>(jami::AccountManager::AddDeviceError::GENERIC);
     339             : }
     340             : 
     341             : bool
     342           4 : confirmAddDevice(const std::string& accountId, uint32_t op_id)
     343             : {
     344           4 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     345           4 :         return account->confirmAddDevice(op_id);
     346           4 :     }
     347           0 :     return false;
     348             : }
     349             : 
     350             : bool
     351           0 : cancelAddDevice(const std::string& accountId, uint32_t op_id)
     352             : {
     353           0 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     354           0 :         return account->cancelAddDevice(op_id);
     355           0 :     }
     356           0 :     return false;
     357             : }
     358             : 
     359             : bool
     360           7 : provideAccountAuthentication(const std::string& accountId,
     361             :                              const std::string& credentialsFromUser,
     362             :                              const std::string& scheme)
     363             : {
     364           7 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     365             :         // send the password to the channel for communicationg with the old device
     366           7 :         account->provideAccountAuthentication(credentialsFromUser, scheme);
     367           7 :         return true;
     368           7 :     }
     369           0 :     return false;
     370             : }
     371             : 
     372             : bool
     373           0 : exportToFile(const std::string& accountId,
     374             :              const std::string& destinationPath,
     375             :              const std::string& scheme,
     376             :              const std::string& password)
     377             : {
     378           0 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     379           0 :         return account->exportArchive(destinationPath, scheme, password);
     380           0 :     }
     381           0 :     return false;
     382             : }
     383             : 
     384             : bool
     385           0 : revokeDevice(const std::string& accountId,
     386             :              const std::string& deviceId,
     387             :              const std::string& scheme,
     388             :              const std::string& password)
     389             : {
     390           0 :     if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
     391           0 :         return account->revokeDevice(deviceId, scheme, password);
     392           0 :     }
     393           0 :     return false;
     394             : }
     395             : 
     396             : std::map<std::string, std::string>
     397           0 : getKnownRingDevices(const std::string& accountId)
     398             : {
     399           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     400           0 :         return acc->getKnownDevices();
     401           0 :     return {};
     402             : }
     403             : 
     404             : bool
     405           4 : changeAccountPassword(const std::string& accountId, const std::string& password_old, const std::string& password_new)
     406             : {
     407           4 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     408           4 :         return acc->changeArchivePassword(password_old, password_new);
     409           0 :     return false;
     410             : }
     411             : 
     412             : /* contacts */
     413             : 
     414             : void
     415           0 : addContact(const std::string& accountId, const std::string& uri)
     416             : {
     417           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     418           0 :         return acc->addContact(uri);
     419             : }
     420             : 
     421             : void
     422           0 : removeContact(const std::string& accountId, const std::string& uri, bool ban)
     423             : {
     424           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     425           0 :         return acc->removeContact(uri, ban);
     426             : }
     427             : 
     428             : std::map<std::string, std::string>
     429           0 : getContactDetails(const std::string& accountId, const std::string& uri)
     430             : {
     431           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     432           0 :         return acc->getContactDetails(uri);
     433           0 :     return {};
     434             : }
     435             : 
     436             : std::vector<std::map<std::string, std::string>>
     437           1 : getContacts(const std::string& accountId)
     438             : {
     439           1 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     440           1 :         return acc->getContacts();
     441           0 :     return {};
     442             : }
     443             : 
     444             : /* contact requests */
     445             : std::vector<std::map<std::string, std::string>>
     446           6 : getTrustRequests(const std::string& accountId)
     447             : {
     448           6 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     449           6 :         return acc->getTrustRequests();
     450           0 :     return {};
     451             : }
     452             : 
     453             : bool
     454           0 : acceptTrustRequest(const std::string& accountId, const std::string& from)
     455             : {
     456           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     457           0 :         return acc->acceptTrustRequest(from);
     458           0 :     return false;
     459             : }
     460             : 
     461             : bool
     462           0 : discardTrustRequest(const std::string& accountId, const std::string& from)
     463             : {
     464           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     465           0 :         return acc->discardTrustRequest(from);
     466           0 :     return false;
     467             : }
     468             : 
     469             : void
     470           0 : sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload)
     471             : {
     472           0 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
     473           0 :         acc->sendTrustRequest(to, payload);
     474           0 : }
     475             : 
     476             : /// This function is used as a base for new accounts for clients that support it
     477             : std::map<std::string, std::string>
     478         321 : getAccountTemplate(const std::string& accountType)
     479             : {
     480         321 :     if (accountType == Account::ProtocolNames::RING)
     481         596 :         return jami::JamiAccountConfig().toMap();
     482          23 :     else if (accountType == Account::ProtocolNames::SIP)
     483          46 :         return jami::SipAccountConfig().toMap();
     484           0 :     return {};
     485             : }
     486             : 
     487             : std::string
     488           0 : addAccount(const std::map<std::string, std::string>& details, const std::string& accountId)
     489             : {
     490           0 :     return jami::Manager::instance().addAccount(details, accountId);
     491             : }
     492             : 
     493             : void
     494           0 : monitor(bool continuous)
     495             : {
     496           0 :     return jami::Manager::instance().monitor(continuous);
     497             : }
     498             : 
     499             : std::vector<std::map<std::string, std::string>>
     500           0 : getConnectionList(const std::string& accountId, const std::string& conversationId)
     501             : {
     502           0 :     return jami::Manager::instance().getConnectionList(accountId, conversationId);
     503             : }
     504             : 
     505             : std::vector<std::map<std::string, std::string>>
     506           0 : getChannelList(const std::string& accountId, const std::string& connectionId)
     507             : {
     508           0 :     return jami::Manager::instance().getChannelList(accountId, connectionId);
     509             : }
     510             : 
     511             : void
     512           0 : removeAccount(const std::string& accountId)
     513             : {
     514           0 :     return jami::Manager::instance().removeAccount(accountId, true); // with 'flush' enabled
     515             : }
     516             : 
     517             : std::vector<std::string>
     518           0 : getAccountList()
     519             : {
     520           0 :     return jami::Manager::instance().getAccountList();
     521             : }
     522             : 
     523             : /**
     524             :  * Send the list of all codecs loaded to the client through DBus.
     525             :  * Can stay global, as only the active codecs will be set per accounts
     526             :  */
     527             : std::vector<unsigned>
     528           0 : getCodecList()
     529             : {
     530           0 :     std::vector<unsigned> list {jami::getSystemCodecContainer()->getSystemCodecInfoIdList(jami::MEDIA_ALL)};
     531           0 :     if (list.empty())
     532           0 :         jami::emitSignal<ConfigurationSignal::Error>(CODECS_NOT_LOADED);
     533           0 :     return list;
     534           0 : }
     535             : 
     536             : std::vector<std::string>
     537           0 : getSupportedTlsMethod()
     538             : {
     539           0 :     return SIPAccount::getSupportedTlsProtocols();
     540             : }
     541             : 
     542             : std::vector<std::string>
     543           0 : getSupportedCiphers(const std::string& accountId)
     544             : {
     545           0 :     if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId))
     546           0 :         return SIPAccount::getSupportedTlsCiphers();
     547           0 :     JAMI_ERR("SIP account %s doesn't exist", accountId.c_str());
     548           0 :     return {};
     549             : }
     550             : 
     551             : bool
     552           0 : setCodecDetails(const std::string& accountId, const unsigned& codecId, const std::map<std::string, std::string>& details)
     553             : {
     554           0 :     auto acc = jami::Manager::instance().getAccount(accountId);
     555           0 :     if (!acc) {
     556           0 :         JAMI_ERR("Unable to find account %s. Unable to set codec details", accountId.c_str());
     557           0 :         return false;
     558             :     }
     559             : 
     560           0 :     auto codec = acc->searchCodecById(codecId, jami::MEDIA_ALL);
     561           0 :     if (!codec) {
     562           0 :         JAMI_ERR("Unable to find codec %d", codecId);
     563           0 :         return false;
     564             :     }
     565             :     try {
     566           0 :         if (codec->mediaType & jami::MEDIA_AUDIO) {
     567           0 :             if (auto foundCodec = std::static_pointer_cast<jami::SystemAudioCodecInfo>(codec)) {
     568           0 :                 foundCodec->setCodecSpecifications(details);
     569           0 :                 jami::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountId);
     570           0 :                 return true;
     571           0 :             }
     572             :         }
     573             : 
     574           0 :         if (codec->mediaType & jami::MEDIA_VIDEO) {
     575           0 :             if (auto foundCodec = std::static_pointer_cast<jami::SystemVideoCodecInfo>(codec)) {
     576           0 :                 foundCodec->setCodecSpecifications(details);
     577           0 :                 JAMI_WARN("parameters for %s changed ", foundCodec->name.c_str());
     578           0 :                 if (auto call = jami::Manager::instance().getCurrentCall()) {
     579           0 :                     if (call->getVideoCodec() == foundCodec) {
     580           0 :                         JAMI_WARN("%s running. Need to restart encoding", foundCodec->name.c_str());
     581           0 :                         call->restartMediaSender();
     582             :                     }
     583           0 :                 }
     584           0 :                 jami::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountId);
     585           0 :                 return true;
     586           0 :             }
     587             :         }
     588           0 :     } catch (const std::exception& e) {
     589           0 :         JAMI_ERR("Unable to set codec specifications: %s", e.what());
     590           0 :     }
     591             : 
     592           0 :     return false;
     593           0 : }
     594             : 
     595             : std::map<std::string, std::string>
     596           0 : getCodecDetails(const std::string& accountId, const unsigned& codecId)
     597             : {
     598           0 :     auto acc = jami::Manager::instance().getAccount(accountId);
     599           0 :     if (!acc) {
     600           0 :         JAMI_ERR("Unable to find account %s return default codec details", accountId.c_str());
     601           0 :         return jami::Account::getDefaultCodecDetails(codecId);
     602             :     }
     603             : 
     604           0 :     auto codec = acc->searchCodecById(codecId, jami::MEDIA_ALL);
     605           0 :     if (!codec) {
     606           0 :         jami::emitSignal<ConfigurationSignal::Error>(CODECS_NOT_LOADED);
     607           0 :         return {};
     608             :     }
     609             : 
     610           0 :     if (codec->mediaType & jami::MEDIA_AUDIO)
     611           0 :         if (auto foundCodec = std::static_pointer_cast<jami::SystemAudioCodecInfo>(codec))
     612           0 :             return foundCodec->getCodecSpecifications();
     613             : 
     614           0 :     if (codec->mediaType & jami::MEDIA_VIDEO)
     615           0 :         if (auto foundCodec = std::static_pointer_cast<jami::SystemVideoCodecInfo>(codec))
     616           0 :             return foundCodec->getCodecSpecifications();
     617             : 
     618           0 :     jami::emitSignal<ConfigurationSignal::Error>(CODECS_NOT_LOADED);
     619           0 :     return {};
     620           0 : }
     621             : 
     622             : std::vector<unsigned>
     623           0 : getActiveCodecList(const std::string& accountId)
     624             : {
     625           0 :     if (auto acc = jami::Manager::instance().getAccount(accountId))
     626           0 :         return acc->getActiveCodecs();
     627           0 :     JAMI_ERR("Unable to find account %s, returning default", accountId.c_str());
     628           0 :     return jami::Account::getDefaultCodecsId();
     629             : }
     630             : 
     631             : void
     632           0 : setActiveCodecList(const std::string& accountId, const std::vector<unsigned>& list)
     633             : {
     634           0 :     if (auto acc = jami::Manager::instance().getAccount(accountId)) {
     635           0 :         acc->setActiveCodecs(list);
     636           0 :         jami::Manager::instance().saveConfig(acc);
     637             :     } else {
     638           0 :         JAMI_ERR("Unable to find account %s", accountId.c_str());
     639           0 :     }
     640           0 : }
     641             : 
     642             : std::vector<std::string>
     643           0 : getAudioPluginList()
     644             : {
     645           0 :     return {PCM_DEFAULT, PCM_DMIX_DSNOOP};
     646             : }
     647             : 
     648             : void
     649           0 : setAudioPlugin(const std::string& audioPlugin)
     650             : {
     651           0 :     return jami::Manager::instance().setAudioPlugin(audioPlugin);
     652             : }
     653             : 
     654             : std::vector<std::string>
     655           0 : getAudioOutputDeviceList()
     656             : {
     657           0 :     return jami::Manager::instance().getAudioOutputDeviceList();
     658             : }
     659             : 
     660             : std::vector<std::string>
     661           0 : getAudioInputDeviceList()
     662             : {
     663           0 :     return jami::Manager::instance().getAudioInputDeviceList();
     664             : }
     665             : 
     666             : void
     667           0 : setAudioOutputDevice(int32_t index)
     668             : {
     669           0 :     return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::PLAYBACK);
     670             : }
     671             : 
     672             : void
     673           0 : setAudioInputDevice(int32_t index)
     674             : {
     675           0 :     return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::CAPTURE);
     676             : }
     677             : 
     678             : void
     679           0 : setAudioRingtoneDevice(int32_t index)
     680             : {
     681           0 :     return jami::Manager::instance().setAudioDevice(index, AudioDeviceType::RINGTONE);
     682             : }
     683             : 
     684             : std::vector<std::string>
     685           0 : getCurrentAudioDevicesIndex()
     686             : {
     687           0 :     return jami::Manager::instance().getCurrentAudioDevicesIndex();
     688             : }
     689             : 
     690             : int32_t
     691           0 : getAudioInputDeviceIndex(const std::string& name)
     692             : {
     693           0 :     return jami::Manager::instance().getAudioInputDeviceIndex(name);
     694             : }
     695             : 
     696             : int32_t
     697           0 : getAudioOutputDeviceIndex(const std::string& name)
     698             : {
     699           0 :     return jami::Manager::instance().getAudioOutputDeviceIndex(name);
     700             : }
     701             : 
     702             : std::string
     703           0 : getCurrentAudioOutputPlugin()
     704             : {
     705           0 :     auto plugin = jami::Manager::instance().getCurrentAudioOutputPlugin();
     706           0 :     JAMI_DBG("Get audio plugin %s", plugin.c_str());
     707           0 :     return plugin;
     708           0 : }
     709             : 
     710             : std::string
     711           0 : getNoiseSuppressState()
     712             : {
     713           0 :     return jami::Manager::instance().getNoiseSuppressState();
     714             : }
     715             : 
     716             : void
     717           0 : setNoiseSuppressState(const std::string& state)
     718             : {
     719           0 :     jami::Manager::instance().setNoiseSuppressState(state);
     720           0 : }
     721             : 
     722             : std::string
     723           0 : getEchoCancellationState()
     724             : {
     725           0 :     return jami::Manager::instance().getEchoCancellationState();
     726             : }
     727             : 
     728             : void
     729           0 : setEchoCancellationState(const std::string& state)
     730             : {
     731           0 :     jami::Manager::instance().setEchoCancellationState(state);
     732           0 : }
     733             : 
     734             : bool
     735           0 : getVoiceActivityDetectionState()
     736             : {
     737           0 :     return jami::Manager::instance().getVoiceActivityDetectionState();
     738             : }
     739             : 
     740             : void
     741           0 : setVoiceActivityDetectionState(bool state)
     742             : {
     743           0 :     jami::Manager::instance().setVoiceActivityDetectionState(state);
     744           0 : }
     745             : 
     746             : bool
     747           0 : isAgcEnabled()
     748             : {
     749           0 :     return jami::Manager::instance().isAGCEnabled();
     750             : }
     751             : 
     752             : void
     753           0 : setAgcState(bool enabled)
     754             : {
     755           0 :     jami::Manager::instance().setAGCState(enabled);
     756           0 : }
     757             : 
     758             : std::string
     759           0 : getRecordPath()
     760             : {
     761           0 :     return jami::Manager::instance().audioPreference.getRecordPath();
     762             : }
     763             : 
     764             : void
     765           0 : setRecordPath(const std::string& recPath)
     766             : {
     767           0 :     jami::Manager::instance().audioPreference.setRecordPath(recPath);
     768           0 : }
     769             : 
     770             : bool
     771           0 : getIsAlwaysRecording()
     772             : {
     773           0 :     return jami::Manager::instance().getIsAlwaysRecording();
     774             : }
     775             : 
     776             : void
     777           0 : setIsAlwaysRecording(bool rec)
     778             : {
     779           0 :     jami::Manager::instance().setIsAlwaysRecording(rec);
     780           0 : }
     781             : 
     782             : bool
     783           0 : getRecordPreview()
     784             : {
     785             : #ifdef ENABLE_VIDEO
     786           0 :     return jami::Manager::instance().videoPreferences.getRecordPreview();
     787             : #else
     788             :     return false;
     789             : #endif
     790             : }
     791             : 
     792             : void
     793           0 : setRecordPreview(bool rec)
     794             : {
     795             : #ifdef ENABLE_VIDEO
     796           0 :     jami::Manager::instance().videoPreferences.setRecordPreview(rec);
     797           0 :     jami::Manager::instance().saveConfig();
     798             : #endif
     799           0 : }
     800             : 
     801             : int32_t
     802           0 : getRecordQuality()
     803             : {
     804             : #ifdef ENABLE_VIDEO
     805           0 :     return jami::Manager::instance().videoPreferences.getRecordQuality();
     806             : #else
     807             :     return 0;
     808             : #endif
     809             : }
     810             : 
     811             : void
     812           0 : setRecordQuality(int32_t quality)
     813             : {
     814             : #ifdef ENABLE_VIDEO
     815           0 :     jami::Manager::instance().videoPreferences.setRecordQuality(quality);
     816           0 :     jami::Manager::instance().saveConfig();
     817             : #endif
     818           0 : }
     819             : 
     820             : int32_t
     821           0 : getHistoryLimit()
     822             : {
     823           0 :     return jami::Manager::instance().getHistoryLimit();
     824             : }
     825             : 
     826             : void
     827           0 : setHistoryLimit(int32_t days)
     828             : {
     829           0 :     jami::Manager::instance().setHistoryLimit(days);
     830           0 : }
     831             : 
     832             : int32_t
     833           0 : getRingingTimeout()
     834             : {
     835           0 :     return static_cast<int32_t>(jami::Manager::instance().getRingingTimeout().count());
     836             : }
     837             : 
     838             : void
     839           0 : setRingingTimeout(int32_t timeout)
     840             : {
     841           0 :     jami::Manager::instance().setRingingTimeout(std::chrono::seconds(timeout));
     842           0 : }
     843             : 
     844             : std::vector<std::string>
     845           0 : getSupportedAudioManagers()
     846             : {
     847           0 :     return jami::AudioPreference::getSupportedAudioManagers();
     848             : }
     849             : 
     850             : bool
     851           0 : setAudioManager(const std::string& api)
     852             : {
     853           0 :     return jami::Manager::instance().setAudioManager(api);
     854             : }
     855             : 
     856             : std::string
     857           0 : getAudioManager()
     858             : {
     859           0 :     return jami::Manager::instance().getAudioManager();
     860             : }
     861             : 
     862             : void
     863           0 : setVolume(const std::string& device, double value)
     864             : {
     865           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver()) {
     866           0 :         JAMI_DBG("set volume for %s: %f", device.c_str(), value);
     867             : 
     868           0 :         if (device == "speaker")
     869           0 :             audiolayer->setPlaybackGain(value);
     870           0 :         else if (device == "mic")
     871           0 :             audiolayer->setCaptureGain(value);
     872             : 
     873           0 :         jami::emitSignal<ConfigurationSignal::VolumeChanged>(device, value);
     874             :     } else {
     875           0 :         JAMI_ERR("Audio layer not valid while updating volume");
     876           0 :     }
     877           0 : }
     878             : 
     879             : double
     880           0 : getVolume(const std::string& device)
     881             : {
     882           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver()) {
     883           0 :         if (device == "speaker")
     884           0 :             return audiolayer->getPlaybackGain();
     885           0 :         if (device == "mic")
     886           0 :             return audiolayer->getCaptureGain();
     887           0 :     }
     888             : 
     889           0 :     JAMI_ERR("Audio layer not valid while updating volume");
     890           0 :     return 0.0;
     891             : }
     892             : 
     893             : // FIXME: we should store "muteDtmf" instead of "playDtmf"
     894             : // in config and avoid negating like this
     895             : bool
     896           0 : isDtmfMuted()
     897             : {
     898           0 :     return not jami::Manager::instance().voipPreferences.getPlayDtmf();
     899             : }
     900             : 
     901             : void
     902           0 : muteDtmf(bool mute)
     903             : {
     904           0 :     jami::Manager::instance().voipPreferences.setPlayDtmf(not mute);
     905           0 : }
     906             : 
     907             : bool
     908           0 : isCaptureMuted()
     909             : {
     910           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     911           0 :         return audiolayer->isCaptureMuted();
     912             : 
     913           0 :     JAMI_ERR("Audio layer not valid");
     914           0 :     return false;
     915             : }
     916             : 
     917             : void
     918           0 : muteCapture(bool mute)
     919             : {
     920           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     921           0 :         return audiolayer->muteCapture(mute);
     922             : 
     923           0 :     JAMI_ERR("Audio layer not valid");
     924           0 :     return;
     925             : }
     926             : 
     927             : bool
     928           0 : isPlaybackMuted()
     929             : {
     930           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     931           0 :         return audiolayer->isPlaybackMuted();
     932             : 
     933           0 :     JAMI_ERR("Audio layer not valid");
     934           0 :     return false;
     935             : }
     936             : 
     937             : void
     938           0 : mutePlayback(bool mute)
     939             : {
     940           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     941           0 :         return audiolayer->mutePlayback(mute);
     942             : 
     943           0 :     JAMI_ERR("Audio layer not valid");
     944           0 :     return;
     945             : }
     946             : 
     947             : bool
     948           0 : isRingtoneMuted()
     949             : {
     950           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     951           0 :         return audiolayer->isRingtoneMuted();
     952             : 
     953           0 :     JAMI_ERR("Audio layer not valid");
     954           0 :     return false;
     955             : }
     956             : 
     957             : void
     958           0 : muteRingtone(bool mute)
     959             : {
     960           0 :     if (auto audiolayer = jami::Manager::instance().getAudioDriver())
     961           0 :         return audiolayer->muteRingtone(mute);
     962             : 
     963           0 :     JAMI_ERR("Audio layer not valid");
     964           0 :     return;
     965             : }
     966             : 
     967             : void
     968           0 : setAccountsOrder(const std::string& order)
     969             : {
     970           0 :     jami::Manager::instance().setAccountsOrder(order);
     971           0 : }
     972             : 
     973             : std::string
     974           0 : getAddrFromInterfaceName(const std::string& interface)
     975             : {
     976           0 :     return dhtnet::ip_utils::getInterfaceAddr(interface, AF_INET);
     977             : }
     978             : 
     979             : std::vector<std::string>
     980           0 : getAllIpInterface()
     981             : {
     982           0 :     return dhtnet::ip_utils::getAllIpInterface();
     983             : }
     984             : 
     985             : std::vector<std::string>
     986           0 : getAllIpInterfaceByName()
     987             : {
     988           0 :     return dhtnet::ip_utils::getAllIpInterfaceByName();
     989             : }
     990             : 
     991             : std::vector<std::map<std::string, std::string>>
     992           0 : getCredentials(const std::string& accountId)
     993             : {
     994           0 :     if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId))
     995           0 :         return sipaccount->getCredentials();
     996           0 :     return {};
     997             : }
     998             : 
     999             : void
    1000           0 : setCredentials(const std::string& accountId, const std::vector<std::map<std::string, std::string>>& details)
    1001             : {
    1002           0 :     if (auto sipaccount = jami::Manager::instance().getAccount<SIPAccount>(accountId)) {
    1003           0 :         sipaccount->doUnregister();
    1004           0 :         sipaccount->editConfig([&](jami::SipAccountConfig& config) { config.setCredentials(details); });
    1005           0 :         sipaccount->loadConfig();
    1006           0 :         if (sipaccount->isEnabled())
    1007           0 :             sipaccount->doRegister();
    1008           0 :         jami::Manager::instance().saveConfig(sipaccount);
    1009           0 :     }
    1010           0 : }
    1011             : 
    1012             : void
    1013           0 : connectivityChanged()
    1014             : {
    1015           0 :     JAMI_WARN("received connectivity changed - attempting to re-connect enabled accounts");
    1016             : 
    1017             :     // reset the UPnP context
    1018             : #if !(defined(TARGET_OS_IOS) && TARGET_OS_IOS)
    1019             :     try {
    1020           0 :         jami::Manager::instance().upnpContext()->connectivityChanged();
    1021           0 :     } catch (std::runtime_error& e) {
    1022           0 :         JAMI_ERR("UPnP context error: %s", e.what());
    1023           0 :     }
    1024             : #endif
    1025             : 
    1026           0 :     for (const auto& account : jami::Manager::instance().getAllAccounts()) {
    1027           0 :         account->connectivityChanged();
    1028           0 :     }
    1029           0 : }
    1030             : 
    1031             : bool
    1032           3 : lookupName(const std::string& account, const std::string& nameserver, const std::string& name)
    1033             : {
    1034           3 :     if (account.empty()) {
    1035             :         auto cb =
    1036           0 :             [name](const std::string& regName, const std::string& address, jami::NameDirectory::Response response) {
    1037           0 :                 jami::emitSignal<libjami::ConfigurationSignal::RegisteredNameFound>("",
    1038           0 :                                                                                     name,
    1039             :                                                                                     (int) response,
    1040             :                                                                                     address,
    1041             :                                                                                     regName);
    1042           0 :             };
    1043           0 :         if (nameserver.empty())
    1044           0 :             jami::NameDirectory::lookupUri(name, "", cb);
    1045             :         else
    1046           0 :             jami::NameDirectory::instance(nameserver).lookupName(name, cb);
    1047           0 :         return true;
    1048           3 :     } else if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
    1049           3 :         acc->lookupName(name);
    1050           3 :         return true;
    1051           3 :     }
    1052           0 :     JAMI_ERROR("lookupName: Unknown account: {}", account);
    1053           0 :     return false;
    1054             : }
    1055             : 
    1056             : bool
    1057           3 : lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address)
    1058             : {
    1059           3 :     if (account.empty()) {
    1060           0 :         jami::NameDirectory::instance(nameserver)
    1061           0 :             .lookupAddress(address,
    1062           0 :                            [address](const std::string& regName,
    1063             :                                      const std::string& addr,
    1064             :                                      jami::NameDirectory::Response response) {
    1065           0 :                                jami::emitSignal<libjami::ConfigurationSignal::RegisteredNameFound>("",
    1066           0 :                                                                                                    address,
    1067             :                                                                                                    (int) response,
    1068             :                                                                                                    addr,
    1069             :                                                                                                    regName);
    1070           0 :                            });
    1071           0 :         return true;
    1072           3 :     } else if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
    1073           3 :         acc->lookupAddress(address);
    1074           3 :         return true;
    1075           3 :     }
    1076           0 :     JAMI_ERROR("lookupAddress: Unknown account: {}", account);
    1077           0 :     return false;
    1078             : }
    1079             : 
    1080             : bool
    1081           0 : searchUser(const std::string& account, const std::string& query)
    1082             : {
    1083           0 :     if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
    1084           0 :         return acc->searchUser(query);
    1085           0 :     }
    1086           0 :     return false;
    1087             : }
    1088             : 
    1089             : bool
    1090           1 : registerName(const std::string& account, const std::string& name, const std::string& scheme, const std::string& password)
    1091             : {
    1092           1 :     if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
    1093           1 :         acc->registerName(name, scheme, password);
    1094           1 :         return true;
    1095           1 :     }
    1096           0 :     JAMI_ERROR("registerName: Unknown account: {}", account);
    1097           0 :     return false;
    1098             : }
    1099             : 
    1100             : void
    1101           0 : setPushNotificationToken(const std::string& token)
    1102             : {
    1103           0 :     for (const auto& account : jami::Manager::instance().getAllAccounts()) {
    1104           0 :         account->setPushNotificationToken(token);
    1105           0 :     }
    1106           0 : }
    1107             : 
    1108             : void
    1109           0 : setPushNotificationTopic(const std::string& topic)
    1110             : {
    1111           0 :     for (const auto& account : jami::Manager::instance().getAllAccounts()) {
    1112           0 :         account->setPushNotificationTopic(topic);
    1113           0 :     }
    1114           0 : }
    1115             : 
    1116             : void
    1117           0 : setPushNotificationConfig(const std::map<std::string, std::string>& data)
    1118             : {
    1119           0 :     for (const auto& account : jami::Manager::instance().getAllAccounts()) {
    1120           0 :         account->setPushNotificationConfig(data);
    1121           0 :     }
    1122           0 : }
    1123             : 
    1124             : void
    1125           0 : pushNotificationReceived(const std::string& from, const std::map<std::string, std::string>& data)
    1126             : {
    1127             :     try {
    1128           0 :         auto it = data.find("to");
    1129           0 :         if (it != data.end()) {
    1130           0 :             if (auto account = jami::Manager::instance().getAccount<JamiAccount>(it->second))
    1131           0 :                 account->pushNotificationReceived(from, data);
    1132             :         }
    1133             : #if defined(__ANDROID__) || defined(ANDROID) || defined(__Apple__)
    1134             :         else {
    1135             :             for (const auto& sipAccount : jami::Manager::instance().getAllAccounts<SIPAccount>()) {
    1136             :                 sipAccount->pushNotificationReceived(from, data);
    1137             :             }
    1138             :         }
    1139             : #endif
    1140           0 :     } catch (const std::exception& e) {
    1141           0 :         JAMI_ERR("Error processing push notification: %s", e.what());
    1142           0 :     }
    1143           0 : }
    1144             : 
    1145             : bool
    1146           0 : isAudioMeterActive(const std::string& id)
    1147             : {
    1148           0 :     return jami::Manager::instance().getRingBufferPool().isAudioMeterActive(id);
    1149             : }
    1150             : 
    1151             : void
    1152           0 : setAudioMeterState(const std::string& id, bool state)
    1153             : {
    1154           0 :     jami::Manager::instance().getRingBufferPool().setAudioMeterState(id, state);
    1155           0 : }
    1156             : 
    1157             : void
    1158           0 : setDefaultModerator(const std::string& accountId, const std::string& peerURI, bool state)
    1159             : {
    1160           0 :     jami::Manager::instance().setDefaultModerator(accountId, peerURI, state);
    1161           0 : }
    1162             : 
    1163             : std::vector<std::string>
    1164           0 : getDefaultModerators(const std::string& accountId)
    1165             : {
    1166           0 :     return jami::Manager::instance().getDefaultModerators(accountId);
    1167             : }
    1168             : 
    1169             : void
    1170           0 : enableLocalModerators(const std::string& accountId, bool isModEnabled)
    1171             : {
    1172           0 :     jami::Manager::instance().enableLocalModerators(accountId, isModEnabled);
    1173           0 : }
    1174             : 
    1175             : bool
    1176           0 : isLocalModeratorsEnabled(const std::string& accountId)
    1177             : {
    1178           0 :     return jami::Manager::instance().isLocalModeratorsEnabled(accountId);
    1179             : }
    1180             : 
    1181             : void
    1182           0 : setAllModerators(const std::string& accountId, bool allModerators)
    1183             : {
    1184           0 :     jami::Manager::instance().setAllModerators(accountId, allModerators);
    1185           0 : }
    1186             : 
    1187             : bool
    1188           0 : isAllModerators(const std::string& accountId)
    1189             : {
    1190           0 :     return jami::Manager::instance().isAllModerators(accountId);
    1191             : }
    1192             : 
    1193             : void
    1194           0 : setResourceDirPath(const std::string& resourceDir)
    1195             : {
    1196           0 :     jami::fileutils::set_resource_dir_path(resourceDir);
    1197           0 : }
    1198             : 
    1199             : } // namespace libjami

Generated by: LCOV version 1.14