LCOV - code coverage report
Current view: top level - src - account_config.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 20 20 100.0 %
Date: 2024-11-15 09:04:49 Functions: 6 6 100.0 %

          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 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             : #pragma once
      18             : #include "connectivity/sip_utils.h"
      19             : #include "config/serializable.h"
      20             : #include "string_utils.h"
      21             : 
      22             : #include <string>
      23             : #include <string_view>
      24             : #include <utility>
      25             : #include <map>
      26             : #include <filesystem>
      27             : 
      28             : using namespace std::literals;
      29             : 
      30             : namespace jami {
      31             : constexpr const char* const DEFAULT_RINGTONE_PATH = "default.opus";
      32             : 
      33             : struct AccountConfig : public Serializable
      34             : {
      35        1212 :     AccountConfig(const std::string& type_, const std::string& id_, const std::filesystem::path& path_ = {})
      36        2424 :         : type(type_)
      37        1212 :         , id(id_)
      38        2424 :         , path(path_)
      39        1212 :     {}
      40             : 
      41             :     void serializeDiff(YAML::Emitter& out, const AccountConfig& def) const;
      42             : 
      43             :     virtual void serialize(YAML::Emitter& out) const = 0;
      44             :     virtual void unserialize(const YAML::Node& node);
      45             : 
      46             :     virtual std::map<std::string, std::string> toMap() const;
      47             :     virtual void fromMap(const std::map<std::string, std::string>&);
      48             : 
      49             :     /** Account type */
      50             :     const std::string type;
      51             : 
      52             :     /** Account id */
      53             :     const std::string id;
      54             : 
      55             :     /** Path where the configuration file is stored.
      56             :      * Part of the context but not stored in the configuration
      57             :      * Used to compute relative paths for configuraton fields */
      58             :     const std::filesystem::path path;
      59             : 
      60             :     /** A user-defined name for this account */
      61             :     std::string alias {};
      62             : 
      63             :     std::string username {};
      64             : 
      65             :     /** SIP hostname (SIP account) or DHT bootstrap nodes (Jami account) */
      66             :     std::string hostname {};
      67             : 
      68             :     /** True if the account is enabled. */
      69             :     bool enabled {true};
      70             : 
      71             :     /** If true, automatically answer calls to this account */
      72             :     bool autoAnswerEnabled {false};
      73             : 
      74             :     /** If true, send displayed status (and emit to the client) */
      75             :     bool sendReadReceipt {true};
      76             : 
      77             :     /** If true, send composing status (and emit to the client) */
      78             :     bool sendComposing {true};
      79             : 
      80             :     /** If true mix calls into a conference */
      81             :     bool isRendezVous {false};
      82             : 
      83             :     /**
      84             :      * The number of concurrent calls for the account
      85             :      * -1: Unlimited
      86             :      *  0: Do not disturb
      87             :      *  1: Single call
      88             :      *  +: Multi line
      89             :      */
      90             :     int activeCallLimit {-1};
      91             : 
      92             :     std::vector<unsigned> activeCodecs {};
      93             : 
      94             :     /**
      95             :      * Play ringtone when receiving a call
      96             :      */
      97             :     bool ringtoneEnabled {true};
      98             : 
      99             :     /**
     100             :      * Ringtone file used for this account
     101             :      */
     102             :     std::string ringtonePath {DEFAULT_RINGTONE_PATH};
     103             : 
     104             :     /**
     105             :      * Allows user to temporarily disable video calling
     106             :      */
     107             :     bool videoEnabled {true};
     108             : 
     109             :     /**
     110             :      * Display name when calling
     111             :      */
     112             :     std::string displayName {};
     113             : 
     114             :     /**
     115             :      * User-agent used for registration
     116             :      */
     117             :     std::string customUserAgent {};
     118             : 
     119             :     /**
     120             :      * Account mail box
     121             :      */
     122             :     std::string mailbox {};
     123             : 
     124             :     /**
     125             :      * UPnP IGD controller and the mutex to access it
     126             :      */
     127             :     bool upnpEnabled {true};
     128             : 
     129             :     std::set<std::string> defaultModerators {};
     130             :     bool localModeratorsEnabled {true};
     131             :     bool allModeratorsEnabled {true};
     132             : 
     133             :     /**
     134             :      * Device push notification token.
     135             :      */
     136             :     std::string deviceKey {};
     137             :     /**
     138             :      * Device push notification platform.
     139             :      */
     140             :     std::string platform {};
     141             : 
     142             :     /**
     143             :      * Push notification topic.
     144             :      */
     145             :     std::string notificationTopic {};
     146             : 
     147             :     /**
     148             :      * information about the customization of ui
     149             :      */
     150             :     std::string uiCustomization {};
     151             : };
     152             : 
     153             : inline void
     154       49762 : parseString(const std::map<std::string, std::string>& details, const char* key, std::string& s)
     155             : {
     156       49762 :     auto it = details.find(key);
     157       49762 :     if (it != details.end())
     158       21814 :         s = it->second;
     159       49762 : }
     160             : 
     161             : inline void
     162       35356 : parseBool(const std::map<std::string, std::string>& details, const char* key, bool& s)
     163             : {
     164       35356 :     auto it = details.find(key);
     165       35356 :     if (it != details.end())
     166       18643 :         s = it->second == TRUE_STR;
     167       35356 : }
     168             : 
     169             : template<class T>
     170             : inline void
     171        9732 : parseInt(const std::map<std::string, std::string>& details, const char* key, T& s)
     172             : {
     173        9732 :     auto it = details.find(key);
     174        9732 :     if (it != details.end())
     175        5156 :         s = to_int<T>(it->second);
     176        9732 : }
     177             : 
     178             : void parsePath(const std::map<std::string, std::string>& details,
     179             :                const char* key,
     180             :                std::string& s,
     181             :                const std::filesystem::path& base);
     182             : 
     183             : } // namespace jami

Generated by: LCOV version 1.14