LCOV - code coverage report
Current view: top level - foo/src/sip - sipaccountbase_config.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 58 78 74.4 %
Date: 2025-10-16 08:11:43 Functions: 4 6 66.7 %

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

Generated by: LCOV version 1.14