LCOV - code coverage report
Current view: top level - src - account_config.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 80 109 73.4 %
Date: 2024-12-21 08:56:24 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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             : #include "account_config.h"
      18             : #include "account_const.h"
      19             : #include "account_schema.h"
      20             : #include "string_utils.h"
      21             : #include "fileutils.h"
      22             : #include "config/account_config_utils.h"
      23             : 
      24             : #include <fmt/compile.h>
      25             : #include <fmt/ranges.h>
      26             : 
      27             : namespace jami {
      28             : 
      29             : constexpr const char* RINGTONE_PATH_KEY = "ringtonePath";
      30             : constexpr const char* RINGTONE_ENABLED_KEY = "ringtoneEnabled";
      31             : constexpr const char* VIDEO_ENABLED_KEY = "videoEnabled";
      32             : constexpr const char* DISPLAY_NAME_KEY = "displayName";
      33             : constexpr const char* ALIAS_KEY = "alias";
      34             : constexpr const char* TYPE_KEY = "type";
      35             : constexpr const char* AUTHENTICATION_USERNAME_KEY = "authenticationUsername";
      36             : constexpr const char* USERNAME_KEY = "username";
      37             : constexpr const char* PASSWORD_KEY = "password";
      38             : constexpr const char* HOSTNAME_KEY = "hostname";
      39             : constexpr const char* ACCOUNT_ENABLE_KEY = "enable";
      40             : constexpr const char* ACCOUNT_AUTOANSWER_KEY = "autoAnswer";
      41             : constexpr const char* ACCOUNT_READRECEIPT_KEY = "sendReadReceipt";
      42             : constexpr const char* ACCOUNT_COMPOSING_KEY = "sendComposing";
      43             : constexpr const char* ACCOUNT_ISRENDEZVOUS_KEY = "rendezVous";
      44             : constexpr const char* ACCOUNT_ACTIVE_CALL_LIMIT_KEY = "activeCallLimit";
      45             : constexpr const char* MAILBOX_KEY = "mailbox";
      46             : constexpr const char* USER_AGENT_KEY = "useragent";
      47             : constexpr const char* HAS_CUSTOM_USER_AGENT_KEY = "hasCustomUserAgent";
      48             : constexpr const char* UPNP_ENABLED_KEY = "upnpEnabled";
      49             : constexpr const char* ACTIVE_CODEC_KEY = "activeCodecs";
      50             : constexpr const char* DEFAULT_MODERATORS_KEY = "defaultModerators";
      51             : constexpr const char* LOCAL_MODERATORS_ENABLED_KEY = "localModeratorsEnabled";
      52             : constexpr const char* ALL_MODERATORS_ENABLED_KEY = "allModeratorsEnabled";
      53             : constexpr const char* PROXY_PUSH_TOKEN_KEY = "proxyPushToken";
      54             : constexpr const char* PROXY_PUSH_PLATFORM_KEY = "proxyPushPlatform";
      55             : constexpr const char* PROXY_PUSH_TOPIC_KEY = "proxyPushiOSTopic";
      56             : constexpr const char* UI_CUSTOMIZATION = "uiCustomization";
      57             : 
      58             : using yaml_utils::parseValueOptional;
      59             : 
      60             : void
      61        2803 : AccountConfig::serializeDiff(YAML::Emitter& out, const AccountConfig& DEFAULT_CONFIG) const
      62             : {
      63        2803 :     SERIALIZE_CONFIG(ACCOUNT_ENABLE_KEY, enabled);
      64        2803 :     SERIALIZE_CONFIG(TYPE_KEY, type);
      65        2803 :     SERIALIZE_CONFIG(ALIAS_KEY, alias);
      66        2803 :     SERIALIZE_CONFIG(HOSTNAME_KEY, hostname);
      67        2803 :     SERIALIZE_CONFIG(USERNAME_KEY, username);
      68        2803 :     SERIALIZE_CONFIG(MAILBOX_KEY, mailbox);
      69             :     out << YAML::Key << ACTIVE_CODEC_KEY << YAML::Value
      70       11212 :         << fmt::format(FMT_COMPILE("{}"), fmt::join(activeCodecs, "/"));
      71        2803 :     SERIALIZE_CONFIG(ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
      72        2803 :     SERIALIZE_CONFIG(ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
      73        2803 :     SERIALIZE_CONFIG(ACCOUNT_COMPOSING_KEY, sendComposing);
      74        2803 :     SERIALIZE_CONFIG(ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
      75        2803 :     SERIALIZE_CONFIG(ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
      76        2803 :     SERIALIZE_CONFIG(RINGTONE_ENABLED_KEY, ringtoneEnabled);
      77        2803 :     SERIALIZE_CONFIG(RINGTONE_PATH_KEY, ringtonePath);
      78        2803 :     SERIALIZE_CONFIG(USER_AGENT_KEY, customUserAgent);
      79        2803 :     SERIALIZE_CONFIG(DISPLAY_NAME_KEY, displayName);
      80        2803 :     SERIALIZE_CONFIG(UPNP_ENABLED_KEY, upnpEnabled);
      81             :     out << YAML::Key << DEFAULT_MODERATORS_KEY << YAML::Value
      82       11212 :         << fmt::format(FMT_COMPILE("{}"), fmt::join(defaultModerators, "/"));
      83        2803 :     SERIALIZE_CONFIG(LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
      84        2803 :     SERIALIZE_CONFIG(ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
      85        2803 :     SERIALIZE_CONFIG(PROXY_PUSH_TOKEN_KEY, deviceKey);
      86        2803 :     SERIALIZE_CONFIG(PROXY_PUSH_PLATFORM_KEY, platform);
      87        2803 :     SERIALIZE_CONFIG(PROXY_PUSH_TOPIC_KEY, notificationTopic);
      88        2803 :     SERIALIZE_CONFIG(VIDEO_ENABLED_KEY, videoEnabled);
      89        2803 :     SERIALIZE_CONFIG(UI_CUSTOMIZATION, uiCustomization);
      90        2803 : }
      91             : 
      92             : void
      93           0 : AccountConfig::unserialize(const YAML::Node& node)
      94             : {
      95           0 :     parseValueOptional(node, ALIAS_KEY, alias);
      96             :     // parseValueOptional(node, TYPE_KEY, type);
      97           0 :     parseValueOptional(node, ACCOUNT_ENABLE_KEY, enabled);
      98           0 :     parseValueOptional(node, HOSTNAME_KEY, hostname);
      99           0 :     parseValueOptional(node, ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
     100           0 :     parseValueOptional(node, ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
     101           0 :     parseValueOptional(node, ACCOUNT_COMPOSING_KEY, sendComposing);
     102           0 :     parseValueOptional(node, ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
     103           0 :     parseValueOptional(node, ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
     104           0 :     parseValueOptional(node, MAILBOX_KEY, mailbox);
     105             : 
     106           0 :     std::string codecs;
     107           0 :     if (parseValueOptional(node, ACTIVE_CODEC_KEY, codecs))
     108           0 :         activeCodecs = split_string_to_unsigned(codecs, '/');
     109             : 
     110           0 :     parseValueOptional(node, DISPLAY_NAME_KEY, displayName);
     111             : 
     112           0 :     parseValueOptional(node, USER_AGENT_KEY, customUserAgent);
     113           0 :     parseValueOptional(node, RINGTONE_PATH_KEY, ringtonePath);
     114           0 :     parseValueOptional(node, RINGTONE_ENABLED_KEY, ringtoneEnabled);
     115           0 :     parseValueOptional(node, VIDEO_ENABLED_KEY, videoEnabled);
     116             : 
     117           0 :     parseValueOptional(node, UPNP_ENABLED_KEY, upnpEnabled);
     118             : 
     119           0 :     std::string defMod;
     120           0 :     parseValueOptional(node, DEFAULT_MODERATORS_KEY, defMod);
     121           0 :     defaultModerators = string_split_set(defMod);
     122           0 :     parseValueOptional(node, LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
     123           0 :     parseValueOptional(node, ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
     124           0 :     parseValueOptional(node, PROXY_PUSH_TOKEN_KEY, deviceKey);
     125           0 :     parseValueOptional(node, PROXY_PUSH_PLATFORM_KEY, platform);
     126           0 :     parseValueOptional(node, PROXY_PUSH_TOPIC_KEY, notificationTopic);
     127           0 :     parseValueOptional(node, UI_CUSTOMIZATION, uiCustomization);
     128           0 : }
     129             : 
     130             : std::map<std::string, std::string>
     131         690 : AccountConfig::toMap() const
     132             : {
     133         690 :     return {{Conf::CONFIG_ACCOUNT_ALIAS, alias},
     134         690 :             {Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName},
     135         690 :             {Conf::CONFIG_ACCOUNT_ENABLE, enabled ? TRUE_STR : FALSE_STR},
     136         690 :             {Conf::CONFIG_ACCOUNT_TYPE, type},
     137         690 :             {Conf::CONFIG_ACCOUNT_USERNAME, username},
     138         690 :             {Conf::CONFIG_ACCOUNT_HOSTNAME, hostname},
     139         690 :             {Conf::CONFIG_ACCOUNT_MAILBOX, mailbox},
     140         690 :             {Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent},
     141         690 :             {Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled ? TRUE_STR : FALSE_STR},
     142         690 :             {Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt ? TRUE_STR : FALSE_STR},
     143         690 :             {Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing ? TRUE_STR : FALSE_STR},
     144         690 :             {Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous ? TRUE_STR : FALSE_STR},
     145        1380 :             {libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, std::to_string(activeCallLimit)},
     146         690 :             {Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled ? TRUE_STR : FALSE_STR},
     147         690 :             {Conf::CONFIG_RINGTONE_PATH, ringtonePath},
     148         690 :             {Conf::CONFIG_VIDEO_ENABLED, videoEnabled ? TRUE_STR : FALSE_STR},
     149         690 :             {Conf::CONFIG_UPNP_ENABLED, upnpEnabled ? TRUE_STR : FALSE_STR},
     150        1380 :             {Conf::CONFIG_DEFAULT_MODERATORS, string_join(defaultModerators)},
     151         690 :             {Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled ? TRUE_STR : FALSE_STR},
     152         690 :             {Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled ? TRUE_STR : FALSE_STR},
     153       24150 :             {Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization}};
     154             : }
     155             : 
     156             : void
     157        1606 : AccountConfig::fromMap(const std::map<std::string, std::string>& details)
     158             : {
     159        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_ALIAS, alias);
     160        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName);
     161        1606 :     parseBool(details, Conf::CONFIG_ACCOUNT_ENABLE, enabled);
     162        1606 :     parseBool(details, Conf::CONFIG_VIDEO_ENABLED, videoEnabled);
     163        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_HOSTNAME, hostname);
     164        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_MAILBOX, mailbox);
     165        1606 :     parseBool(details, Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled);
     166        1606 :     parseBool(details, Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt);
     167        1606 :     parseBool(details, Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing);
     168        1606 :     parseBool(details, Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous);
     169        1606 :     parseInt(details, libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, activeCallLimit);
     170        1606 :     parseBool(details, Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled);
     171        1606 :     parseString(details, Conf::CONFIG_RINGTONE_PATH, ringtonePath);
     172        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent);
     173        1606 :     parseBool(details, Conf::CONFIG_UPNP_ENABLED, upnpEnabled);
     174        1606 :     std::string defMod;
     175        1606 :     parseString(details, Conf::CONFIG_DEFAULT_MODERATORS, defMod);
     176        1606 :     defaultModerators = string_split_set(defMod);
     177        1606 :     parseBool(details, Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled);
     178        1606 :     parseBool(details, Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled);
     179             : 
     180        1606 :     parseString(details, libjami::Account::ConfProperties::PROXY_PUSH_TOKEN, deviceKey);
     181        1606 :     parseString(details, PROXY_PUSH_PLATFORM_KEY, platform);
     182        1606 :     parseString(details, PROXY_PUSH_TOPIC_KEY, notificationTopic);
     183             : 
     184        1606 :     parseString(details, Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization);
     185        1606 : }
     186             : 
     187             : void
     188        4818 : parsePath(const std::map<std::string, std::string>& details,
     189             :           const char* key,
     190             :           std::string& s,
     191             :           const std::filesystem::path& base)
     192             : {
     193        4818 :     auto it = details.find(key);
     194        4818 :     if (it != details.end())
     195        2428 :         s = fileutils::getFullPath(base, it->second).string();
     196        4818 : }
     197             : 
     198             : } // namespace jami

Generated by: LCOV version 1.14