LCOV - code coverage report
Current view: top level - src - account_config.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 65.8 % 114 75
Test Date: 2026-06-13 09:18:46 Functions: 88.9 % 9 8

            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              : #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* USERNAME_KEY = "username";
      36              : constexpr const char* HOSTNAME_KEY = "hostname";
      37              : constexpr const char* ACCOUNT_ENABLE_KEY = "enable";
      38              : constexpr const char* ACCOUNT_AUTOANSWER_KEY = "autoAnswer";
      39              : constexpr const char* DENY_SECOND_CALL_KEY = "denySecondCall";
      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* UPNP_ENABLED_KEY = "upnpEnabled";
      47              : constexpr const char* ACTIVE_CODEC_KEY = "activeCodecs";
      48              : constexpr const char* DEFAULT_MODERATORS_KEY = "defaultModerators";
      49              : constexpr const char* LOCAL_MODERATORS_ENABLED_KEY = "localModeratorsEnabled";
      50              : constexpr const char* ALL_MODERATORS_ENABLED_KEY = "allModeratorsEnabled";
      51              : constexpr const char* PROXY_PUSH_TOKEN_KEY = "proxyPushToken";
      52              : constexpr const char* PROXY_PUSH_PLATFORM_KEY = "proxyPushPlatform";
      53              : constexpr const char* PROXY_PUSH_TOPIC_KEY = "proxyPushiOSTopic";
      54              : constexpr const char* UI_CUSTOMIZATION = "uiCustomization";
      55              : 
      56              : using yaml_utils::parseValueOptional;
      57              : 
      58              : void
      59         2744 : AccountConfig::serializeDiff(YAML::Emitter& out, const AccountConfig& DEFAULT_CONFIG) const
      60              : {
      61         2744 :     SERIALIZE_CONFIG(ACCOUNT_ENABLE_KEY, enabled);
      62         2744 :     SERIALIZE_CONFIG(TYPE_KEY, type);
      63         2744 :     SERIALIZE_CONFIG(ALIAS_KEY, alias);
      64         2744 :     SERIALIZE_CONFIG(HOSTNAME_KEY, hostname);
      65         2744 :     SERIALIZE_CONFIG(USERNAME_KEY, username);
      66         2744 :     SERIALIZE_CONFIG(MAILBOX_KEY, mailbox);
      67        13720 :     out << YAML::Key << ACTIVE_CODEC_KEY << YAML::Value << fmt::format(FMT_COMPILE("{}"), fmt::join(activeCodecs, "/"));
      68         2744 :     SERIALIZE_CONFIG(ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
      69         2744 :     SERIALIZE_CONFIG(DENY_SECOND_CALL_KEY, denySecondCallEnabled);
      70         2744 :     SERIALIZE_CONFIG(ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
      71         2744 :     SERIALIZE_CONFIG(ACCOUNT_COMPOSING_KEY, sendComposing);
      72         2744 :     SERIALIZE_CONFIG(ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
      73         2744 :     SERIALIZE_CONFIG(ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
      74         2744 :     SERIALIZE_CONFIG(RINGTONE_ENABLED_KEY, ringtoneEnabled);
      75         2744 :     SERIALIZE_CONFIG(RINGTONE_PATH_KEY, ringtonePath);
      76         2744 :     SERIALIZE_CONFIG(USER_AGENT_KEY, customUserAgent);
      77         2744 :     SERIALIZE_CONFIG(DISPLAY_NAME_KEY, displayName);
      78         2744 :     SERIALIZE_CONFIG(UPNP_ENABLED_KEY, upnpEnabled);
      79              :     out << YAML::Key << DEFAULT_MODERATORS_KEY << YAML::Value
      80        13720 :         << fmt::format(FMT_COMPILE("{}"), fmt::join(defaultModerators, "/"));
      81         2744 :     SERIALIZE_CONFIG(LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
      82         2744 :     SERIALIZE_CONFIG(ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
      83         2744 :     SERIALIZE_CONFIG(PROXY_PUSH_TOKEN_KEY, deviceKey);
      84         2744 :     SERIALIZE_CONFIG(PROXY_PUSH_PLATFORM_KEY, platform);
      85         2744 :     SERIALIZE_CONFIG(PROXY_PUSH_TOPIC_KEY, notificationTopic);
      86         2744 :     SERIALIZE_CONFIG(VIDEO_ENABLED_KEY, videoEnabled);
      87         2744 :     SERIALIZE_CONFIG(UI_CUSTOMIZATION, uiCustomization);
      88         2744 : }
      89              : 
      90              : void
      91            0 : AccountConfig::unserialize(const YAML::Node& node)
      92              : {
      93            0 :     parseValueOptional(node, ALIAS_KEY, alias);
      94              :     // parseValueOptional(node, TYPE_KEY, type);
      95            0 :     parseValueOptional(node, ACCOUNT_ENABLE_KEY, enabled);
      96            0 :     parseValueOptional(node, HOSTNAME_KEY, hostname);
      97            0 :     parseValueOptional(node, ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
      98            0 :     parseValueOptional(node, DENY_SECOND_CALL_KEY, denySecondCallEnabled);
      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          655 : AccountConfig::toMap() const
     131              : {
     132          655 :     return {{Conf::CONFIG_ACCOUNT_ALIAS, alias},
     133          655 :             {Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName},
     134            0 :             {Conf::CONFIG_ACCOUNT_ENABLE, enabled ? TRUE_STR : FALSE_STR},
     135          655 :             {Conf::CONFIG_ACCOUNT_TYPE, type},
     136          655 :             {Conf::CONFIG_ACCOUNT_USERNAME, username},
     137          655 :             {Conf::CONFIG_ACCOUNT_HOSTNAME, hostname},
     138          655 :             {Conf::CONFIG_ACCOUNT_MAILBOX, mailbox},
     139          655 :             {Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent},
     140          655 :             {Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled ? TRUE_STR : FALSE_STR},
     141            0 :             {Conf::CONFIG_ACCOUNT_DENY_SECOND_CALL, denySecondCallEnabled ? TRUE_STR : FALSE_STR},
     142            0 :             {Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt ? TRUE_STR : FALSE_STR},
     143            0 :             {Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing ? TRUE_STR : FALSE_STR},
     144            0 :             {Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous ? TRUE_STR : FALSE_STR},
     145            0 :             {libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, std::to_string(activeCallLimit)},
     146            0 :             {Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled ? TRUE_STR : FALSE_STR},
     147          655 :             {Conf::CONFIG_RINGTONE_PATH, ringtonePath},
     148          655 :             {Conf::CONFIG_VIDEO_ENABLED, videoEnabled ? TRUE_STR : FALSE_STR},
     149          655 :             {Conf::CONFIG_UPNP_ENABLED, upnpEnabled ? TRUE_STR : FALSE_STR},
     150         1310 :             {Conf::CONFIG_DEFAULT_MODERATORS, string_join(defaultModerators)},
     151            0 :             {Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled ? TRUE_STR : FALSE_STR},
     152            0 :             {Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled ? TRUE_STR : FALSE_STR},
     153        16375 :             {Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization}};
     154         8515 : }
     155              : 
     156              : void
     157         1592 : AccountConfig::fromMap(const std::map<std::string, std::string>& details)
     158              : {
     159         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_ALIAS, alias);
     160         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName);
     161         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_ENABLE, enabled);
     162         1592 :     parseBool(details, Conf::CONFIG_VIDEO_ENABLED, videoEnabled);
     163         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_HOSTNAME, hostname);
     164         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_MAILBOX, mailbox);
     165         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled);
     166         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_DENY_SECOND_CALL, denySecondCallEnabled);
     167         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt);
     168         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing);
     169         1592 :     parseBool(details, Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous);
     170         1592 :     parseInt(details, libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, activeCallLimit);
     171         1592 :     parseBool(details, Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled);
     172         1592 :     parseString(details, Conf::CONFIG_RINGTONE_PATH, ringtonePath);
     173         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent);
     174         1592 :     parseBool(details, Conf::CONFIG_UPNP_ENABLED, upnpEnabled);
     175         1592 :     std::string defMod;
     176         1592 :     parseString(details, Conf::CONFIG_DEFAULT_MODERATORS, defMod);
     177         1592 :     defaultModerators = string_split_set(defMod);
     178         1592 :     parseBool(details, Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled);
     179         1592 :     parseBool(details, Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled);
     180              : 
     181         1592 :     parseString(details, libjami::Account::ConfProperties::PROXY_PUSH_TOKEN, deviceKey);
     182         1592 :     parseString(details, PROXY_PUSH_PLATFORM_KEY, platform);
     183         1592 :     parseString(details, PROXY_PUSH_TOPIC_KEY, notificationTopic);
     184              : 
     185         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization);
     186         1592 : }
     187              : 
     188              : void
     189         4776 : parsePath(const std::map<std::string, std::string>& details,
     190              :           const char* key,
     191              :           std::string& s,
     192              :           const std::filesystem::path& base)
     193              : {
     194         4776 :     auto it = details.find(key);
     195         4776 :     if (it != details.end())
     196         2412 :         s = fileutils::getFullPath(base, it->second).string();
     197         4776 : }
     198              : 
     199              : } // namespace jami
        

Generated by: LCOV version 2.0-1