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: 56 76 73.7 %
Date: 2025-12-18 10:07: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, const char* minKey, const char* maxKey, std::pair<uint16_t, uint16_t>& range)
      46             : {
      47           0 :     int tmpMin = yaml_utils::parseValueOptional(node, minKey, tmpMin);
      48           0 :     int tmpMax = yaml_utils::parseValueOptional(node, maxKey, tmpMax);
      49           0 :     updateRange(tmpMin, tmpMax, range);
      50           0 : }
      51             : 
      52             : static void
      53        1300 : addRangeToDetails(std::map<std::string, std::string>& a,
      54             :                   const char* minKey,
      55             :                   const char* maxKey,
      56             :                   const std::pair<uint16_t, uint16_t>& range)
      57             : {
      58        1300 :     a.emplace(minKey, std::to_string(range.first));
      59        1300 :     a.emplace(maxKey, std::to_string(range.second));
      60        1300 : }
      61             : 
      62             : void
      63        2779 : SipAccountBaseConfig::serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& DEFAULT_CONFIG) const
      64             : {
      65        2779 :     AccountConfig::serializeDiff(out, DEFAULT_CONFIG);
      66        2779 :     SERIALIZE_CONFIG(Conf::DTMF_TYPE_KEY, dtmfType);
      67        2779 :     SERIALIZE_CONFIG(Conf::INTERFACE_KEY, interface);
      68        2779 :     SERIALIZE_CONFIG(Conf::PUBLISH_ADDR_KEY, publishedIp);
      69        2779 :     SERIALIZE_CONFIG(Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
      70        2779 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.second);
      71        2779 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.first);
      72        2779 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MAX_KEY, videoPortRange.second);
      73        2779 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MIN_KEY, videoPortRange.first);
      74        2779 :     SERIALIZE_CONFIG(Conf::TURN_ENABLED_KEY, turnEnabled);
      75        2779 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_KEY, turnServer);
      76        2779 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
      77        2779 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
      78        2779 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
      79        2779 : }
      80             : 
      81             : void
      82           0 : SipAccountBaseConfig::unserialize(const YAML::Node& node)
      83             : {
      84           0 :     AccountConfig::unserialize(node);
      85           0 :     parseValueOptional(node, Conf::INTERFACE_KEY, interface);
      86           0 :     parseValueOptional(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
      87           0 :     parseValueOptional(node, Conf::PUBLISH_ADDR_KEY, publishedIp);
      88           0 :     parseValueOptional(node, Conf::DTMF_TYPE_KEY, dtmfType);
      89           0 :     unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange);
      90           0 :     unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange);
      91             : 
      92             :     // ICE - STUN/TURN
      93           0 :     parseValueOptional(node, Conf::TURN_ENABLED_KEY, turnEnabled);
      94           0 :     parseValueOptional(node, Conf::TURN_SERVER_KEY, turnServer);
      95           0 :     parseValueOptional(node, Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
      96           0 :     parseValueOptional(node, Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
      97           0 :     parseValueOptional(node, Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
      98           0 : }
      99             : 
     100             : std::map<std::string, std::string>
     101         650 : SipAccountBaseConfig::toMap() const
     102             : {
     103         650 :     auto a = AccountConfig::toMap();
     104             : 
     105         650 :     addRangeToDetails(a, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, audioPortRange);
     106         650 :     addRangeToDetails(a, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, videoPortRange);
     107             : 
     108         650 :     a.emplace(Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     109         650 :     a.emplace(Conf::CONFIG_LOCAL_INTERFACE, interface);
     110         650 :     a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal ? TRUE_STR : FALSE_STR);
     111         650 :     a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     112             : 
     113         650 :     a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled ? TRUE_STR : FALSE_STR);
     114         650 :     a.emplace(Conf::CONFIG_TURN_SERVER, turnServer);
     115         650 :     a.emplace(Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     116         650 :     a.emplace(Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     117         650 :     a.emplace(Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     118         650 :     return a;
     119           0 : }
     120             : 
     121             : void
     122        1588 : SipAccountBaseConfig::fromMap(const std::map<std::string, std::string>& details)
     123             : {
     124        1588 :     AccountConfig::fromMap(details);
     125             : 
     126             :     // general sip settings
     127        1588 :     parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface);
     128        1588 :     parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal);
     129        1588 :     parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     130        1588 :     parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     131             : 
     132        1588 :     int tmpMin = -1;
     133        1588 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin);
     134        1588 :     int tmpMax = -1;
     135        1588 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax);
     136        1588 :     updateRange(tmpMin, tmpMax, audioPortRange);
     137        1588 :     tmpMin = -1;
     138        1588 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin);
     139        1588 :     tmpMax = -1;
     140        1588 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax);
     141        1588 :     updateRange(tmpMin, tmpMax, videoPortRange);
     142             : 
     143             :     // ICE - STUN
     144             :     // parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled);
     145             :     // parseString(details, Conf::CONFIG_STUN_SERVER, stunServer);
     146             : 
     147             :     // ICE - TURN
     148        1588 :     parseBool(details, Conf::CONFIG_TURN_ENABLE, turnEnabled);
     149        1588 :     parseString(details, Conf::CONFIG_TURN_SERVER, turnServer);
     150        1588 :     parseString(details, Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     151        1588 :     parseString(details, Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     152        1588 :     parseString(details, Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     153        1588 : }
     154             : 
     155             : } // namespace jami

Generated by: LCOV version 1.14