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

Generated by: LCOV version 1.14