LCOV - code coverage report
Current view: top level - src/sip - sipaccountbase_config.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 58 78 74.4 %
Date: 2024-05-02 09:40:27 Functions: 4 6 66.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 "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 BIND_ADDRESS_KEY = "bindAddress";
      27             : const char* const INTERFACE_KEY = "interface";
      28             : const char* const PORT_KEY = "port";
      29             : const char* const PUBLISH_ADDR_KEY = "publishAddr";
      30             : const char* const PUBLISH_PORT_KEY = "publishPort";
      31             : const char* const SAME_AS_LOCAL_KEY = "sameasLocal";
      32             : const char* const DTMF_TYPE_KEY = "dtmfType";
      33             : const char* const SERVICE_ROUTE_KEY = "serviceRoute";
      34             : const char* const ALLOW_IP_AUTO_REWRITE = "allowIPAutoRewrite";
      35             : const char* const PRESENCE_ENABLED_KEY = "presenceEnabled";
      36             : const char* const PRESENCE_PUBLISH_SUPPORTED_KEY = "presencePublishSupported";
      37             : const char* const PRESENCE_SUBSCRIBE_SUPPORTED_KEY = "presenceSubscribeSupported";
      38             : const char* const PRESENCE_STATUS_KEY = "presenceStatus";
      39             : const char* const PRESENCE_NOTE_KEY = "presenceNote";
      40             : const char* const STUN_ENABLED_KEY = "stunEnabled";
      41             : const char* const STUN_SERVER_KEY = "stunServer";
      42             : const char* const TURN_ENABLED_KEY = "turnEnabled";
      43             : const char* const TURN_SERVER_KEY = "turnServer";
      44             : const char* const TURN_SERVER_UNAME_KEY = "turnServerUserName";
      45             : const char* const TURN_SERVER_PWD_KEY = "turnServerPassword";
      46             : const char* const TURN_SERVER_REALM_KEY = "turnServerRealm";
      47             : const char* const CRED_KEY = "credential";
      48             : const char* const AUDIO_PORT_MIN_KEY = "audioPortMin";
      49             : const char* const AUDIO_PORT_MAX_KEY = "audioPortMax";
      50             : const char* const VIDEO_PORT_MIN_KEY = "videoPortMin";
      51             : const char* const VIDEO_PORT_MAX_KEY = "videoPortMax";
      52             : } // namespace Conf
      53             : 
      54             : using yaml_utils::parseValueOptional;
      55             : 
      56             : static void
      57           0 : unserializeRange(const YAML::Node& node,
      58             :                  const char* minKey,
      59             :                  const char* maxKey,
      60             :                  std::pair<uint16_t, uint16_t>& range)
      61             : {
      62           0 :     int tmpMin = yaml_utils::parseValueOptional(node, minKey, tmpMin);
      63           0 :     int tmpMax = yaml_utils::parseValueOptional(node, maxKey, tmpMax);
      64           0 :     updateRange(tmpMin, tmpMax, range);
      65           0 : }
      66             : 
      67             : static void
      68        1118 : addRangeToDetails(std::map<std::string, std::string>& a,
      69             :                   const char* minKey,
      70             :                   const char* maxKey,
      71             :                   const std::pair<uint16_t, uint16_t>& range)
      72             : {
      73        1118 :     a.emplace(minKey, std::to_string(range.first));
      74        1118 :     a.emplace(maxKey, std::to_string(range.second));
      75        1118 : }
      76             : 
      77             : void
      78        1685 : SipAccountBaseConfig::serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& DEFAULT_CONFIG) const
      79             : {
      80        1685 :     AccountConfig::serializeDiff(out, DEFAULT_CONFIG);
      81        1685 :     SERIALIZE_CONFIG(Conf::DTMF_TYPE_KEY, dtmfType);
      82        1685 :     SERIALIZE_CONFIG(Conf::INTERFACE_KEY, interface);
      83        1685 :     SERIALIZE_CONFIG(Conf::PUBLISH_ADDR_KEY, publishedIp);
      84        1685 :     SERIALIZE_CONFIG(Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
      85        1685 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.second);
      86        1685 :     SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.first);
      87        1685 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MAX_KEY, videoPortRange.second);
      88        1685 :     SERIALIZE_CONFIG(Conf::VIDEO_PORT_MIN_KEY, videoPortRange.first);
      89        1685 :     SERIALIZE_CONFIG(Conf::TURN_ENABLED_KEY, turnEnabled);
      90        1685 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_KEY, turnServer);
      91        1685 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
      92        1685 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
      93        1685 :     SERIALIZE_CONFIG(Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
      94        1685 : }
      95             : 
      96             : void
      97           0 : SipAccountBaseConfig::unserialize(const YAML::Node& node)
      98             : {
      99           0 :     AccountConfig::unserialize(node);
     100           0 :     parseValueOptional(node, Conf::INTERFACE_KEY, interface);
     101           0 :     parseValueOptional(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
     102           0 :     parseValueOptional(node, Conf::PUBLISH_ADDR_KEY, publishedIp);
     103           0 :     parseValueOptional(node, Conf::DTMF_TYPE_KEY, dtmfType);
     104           0 :     unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange);
     105           0 :     unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange);
     106             : 
     107             :     // ICE - STUN/TURN
     108             :     //parseValueOptional(node, Conf::STUN_ENABLED_KEY, stunEnabled);
     109             :     //parseValueOptional(node, Conf::STUN_SERVER_KEY, stunServer);
     110           0 :     parseValueOptional(node, Conf::TURN_ENABLED_KEY, turnEnabled);
     111           0 :     parseValueOptional(node, Conf::TURN_SERVER_KEY, turnServer);
     112           0 :     parseValueOptional(node, Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
     113           0 :     parseValueOptional(node, Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
     114           0 :     parseValueOptional(node, Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
     115           0 : }
     116             : 
     117             : std::map<std::string, std::string>
     118         559 : SipAccountBaseConfig::toMap() const
     119             : {
     120         559 :     auto a = AccountConfig::toMap();
     121             : 
     122         559 :     addRangeToDetails(a,
     123             :                       Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN,
     124             :                       Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX,
     125         559 :                       audioPortRange);
     126         559 :     addRangeToDetails(a,
     127             :                       Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN,
     128             :                       Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX,
     129         559 :                       videoPortRange);
     130             : 
     131         559 :     a.emplace(Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     132         559 :     a.emplace(Conf::CONFIG_LOCAL_INTERFACE, interface);
     133         559 :     a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal ? TRUE_STR : FALSE_STR);
     134         559 :     a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     135             : 
     136         559 :     a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled ? TRUE_STR : FALSE_STR);
     137         559 :     a.emplace(Conf::CONFIG_TURN_SERVER, turnServer);
     138         559 :     a.emplace(Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     139         559 :     a.emplace(Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     140         559 :     a.emplace(Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     141         559 :     return a;
     142           0 : }
     143             : 
     144             : void
     145         953 : SipAccountBaseConfig::fromMap(const std::map<std::string, std::string>& details)
     146             : {
     147         953 :     AccountConfig::fromMap(details);
     148             : 
     149             :     // general sip settings
     150         953 :     parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface);
     151         953 :     parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal);
     152         953 :     parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
     153         953 :     parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
     154             : 
     155         953 :     int tmpMin = -1;
     156         953 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin);
     157         953 :     int tmpMax = -1;
     158         953 :     parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax);
     159         953 :     updateRange(tmpMin, tmpMax, audioPortRange);
     160         953 :     tmpMin = -1;
     161         953 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin);
     162         953 :     tmpMax = -1;
     163         953 :     parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax);
     164         953 :     updateRange(tmpMin, tmpMax, videoPortRange);
     165             : 
     166             :     // ICE - STUN
     167             :     //parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled);
     168             :     //parseString(details, Conf::CONFIG_STUN_SERVER, stunServer);
     169             : 
     170             :     // ICE - TURN
     171         953 :     parseBool(details, Conf::CONFIG_TURN_ENABLE, turnEnabled);
     172         953 :     parseString(details, Conf::CONFIG_TURN_SERVER, turnServer);
     173         953 :     parseString(details, Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
     174         953 :     parseString(details, Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
     175         953 :     parseString(details, Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
     176         953 : }
     177             : 
     178             : }

Generated by: LCOV version 1.14