LCOV - code coverage report
Current view: top level - src/sip - sipaccountbase_config.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 73.7 % 76 56
Test Date: 2026-06-13 09:18:46 Functions: 66.7 % 6 4

            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 "sipaccountbase_config.h"
      18              : #include "account_schema.h"
      19              : #include "config/account_config_utils.h"
      20              : 
      21              : namespace jami {
      22              : 
      23              : namespace Conf {
      24              : // SIP specific configuration keys
      25              : const char* const INTERFACE_KEY = "interface";
      26              : const char* const PUBLISH_ADDR_KEY = "publishAddr";
      27              : const char* const SAME_AS_LOCAL_KEY = "sameasLocal";
      28              : const char* const DTMF_TYPE_KEY = "dtmfType";
      29              : const char* const TURN_ENABLED_KEY = "turnEnabled";
      30              : const char* const TURN_SERVER_KEY = "turnServer";
      31              : const char* const TURN_SERVER_UNAME_KEY = "turnServerUserName";
      32              : const char* const TURN_SERVER_PWD_KEY = "turnServerPassword";
      33              : const char* const TURN_SERVER_REALM_KEY = "turnServerRealm";
      34              : const char* const AUDIO_PORT_MIN_KEY = "audioPortMin";
      35              : const char* const AUDIO_PORT_MAX_KEY = "audioPortMax";
      36              : const char* const VIDEO_PORT_MIN_KEY = "videoPortMin";
      37              : const char* const VIDEO_PORT_MAX_KEY = "videoPortMax";
      38              : } // namespace Conf
      39              : 
      40              : using yaml_utils::parseValueOptional;
      41              : 
      42              : static void
      43            0 : unserializeRange(const YAML::Node& node, const char* minKey, const char* maxKey, std::pair<uint16_t, uint16_t>& range)
      44              : {
      45            0 :     int tmpMin = yaml_utils::parseValueOptional(node, minKey, tmpMin);
      46            0 :     int tmpMax = yaml_utils::parseValueOptional(node, maxKey, tmpMax);
      47            0 :     updateRange(tmpMin, tmpMax, range);
      48            0 : }
      49              : 
      50              : static void
      51         1310 : addRangeToDetails(std::map<std::string, std::string>& a,
      52              :                   const char* minKey,
      53              :                   const char* maxKey,
      54              :                   const std::pair<uint16_t, uint16_t>& range)
      55              : {
      56         1310 :     a.emplace(minKey, std::to_string(range.first));
      57         1310 :     a.emplace(maxKey, std::to_string(range.second));
      58         1310 : }
      59              : 
      60              : void
      61         2744 : SipAccountBaseConfig::serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& DEFAULT_CONFIG) const
      62              : {
      63         2744 :     AccountConfig::serializeDiff(out, DEFAULT_CONFIG);
      64         2744 :     SERIALIZE_CONFIG(Conf::DTMF_TYPE_KEY, dtmfType);
      65         2744 :     SERIALIZE_CONFIG(Conf::INTERFACE_KEY, interface);
      66         2744 :     SERIALIZE_CONFIG(Conf::PUBLISH_ADDR_KEY, publishedIp);
      67         2744 :     SERIALIZE_CONFIG(Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
      68         2744 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.second);
      69         2744 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.first);
      70         2744 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MAX_KEY, videoPortRange.second);
      71         2744 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MIN_KEY, videoPortRange.first);
      72         2744 :     SERIALIZE_CONFIG(Conf::TURN_ENABLED_KEY, turnEnabled);
      73         2744 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_KEY, turnServer);
      74         2744 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
      75         2744 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
      76         2744 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
      77         2744 : }
      78              : 
      79              : void
      80            0 : SipAccountBaseConfig::unserialize(const YAML::Node& node)
      81              : {
      82            0 :     AccountConfig::unserialize(node);
      83            0 :     parseValueOptional(node, Conf::INTERFACE_KEY, interface);
      84            0 :     parseValueOptional(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
      85            0 :     parseValueOptional(node, Conf::PUBLISH_ADDR_KEY, publishedIp);
      86            0 :     parseValueOptional(node, Conf::DTMF_TYPE_KEY, dtmfType);
      87            0 :     unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange);
      88            0 :     unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange);
      89              : 
      90              :     // ICE - STUN/TURN
      91            0 :     parseValueOptional(node, Conf::TURN_ENABLED_KEY, turnEnabled);
      92            0 :     parseValueOptional(node, Conf::TURN_SERVER_KEY, turnServer);
      93            0 :     parseValueOptional(node, Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
      94            0 :     parseValueOptional(node, Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
      95            0 :     parseValueOptional(node, Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
      96            0 : }
      97              : 
      98              : std::map<std::string, std::string>
      99          655 : SipAccountBaseConfig::toMap() const
     100              : {
     101          655 :     auto a = AccountConfig::toMap();
     102              : 
     103          655 :     addRangeToDetails(a, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, audioPortRange);
     104          655 :     addRangeToDetails(a, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, videoPortRange);
     105              : 
     106          655 :     a.emplace(Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     107          655 :     a.emplace(Conf::CONFIG_LOCAL_INTERFACE, interface);
     108          655 :     a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal ? TRUE_STR : FALSE_STR);
     109          655 :     a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     110              : 
     111          655 :     a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled ? TRUE_STR : FALSE_STR);
     112          655 :     a.emplace(Conf::CONFIG_TURN_SERVER, turnServer);
     113          655 :     a.emplace(Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     114          655 :     a.emplace(Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     115          655 :     a.emplace(Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     116          655 :     return a;
     117            0 : }
     118              : 
     119              : void
     120         1592 : SipAccountBaseConfig::fromMap(const std::map<std::string, std::string>& details)
     121              : {
     122         1592 :     AccountConfig::fromMap(details);
     123              : 
     124              :     // general sip settings
     125         1592 :     parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface);
     126         1592 :     parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal);
     127         1592 :     parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     128         1592 :     parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     129              : 
     130         1592 :     int tmpMin = -1;
     131         1592 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin);
     132         1592 :     int tmpMax = -1;
     133         1592 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax);
     134         1592 :     updateRange(tmpMin, tmpMax, audioPortRange);
     135         1592 :     tmpMin = -1;
     136         1592 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin);
     137         1592 :     tmpMax = -1;
     138         1592 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax);
     139         1592 :     updateRange(tmpMin, tmpMax, videoPortRange);
     140              : 
     141              :     // ICE - STUN
     142              :     // parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled);
     143              :     // parseString(details, Conf::CONFIG_STUN_SERVER, stunServer);
     144              : 
     145              :     // ICE - TURN
     146         1592 :     parseBool(details, Conf::CONFIG_TURN_ENABLE, turnEnabled);
     147         1592 :     parseString(details, Conf::CONFIG_TURN_SERVER, turnServer);
     148         1592 :     parseString(details, Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     149         1592 :     parseString(details, Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     150         1592 :     parseString(details, Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     151         1592 : }
     152              : 
     153              : } // namespace jami
        

Generated by: LCOV version 2.0-1