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 : #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 1008 : AccountConfig(const std::string& type_, const std::string& id_, const std::filesystem::path& path_ = {}) 36 2016 : : type(type_) 37 1008 : , id(id_) 38 2016 : , path(path_) 39 1008 : {} 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, automatically deny new calls when already in one call to this account */ 75 : bool denySecondCallEnabled {false}; 76 : 77 : /** If true, send displayed status (and emit to the client) */ 78 : bool sendReadReceipt {true}; 79 : 80 : /** If true, send composing status (and emit to the client) */ 81 : bool sendComposing {true}; 82 : 83 : /** If true mix calls into a conference */ 84 : bool isRendezVous {false}; 85 : 86 : /** 87 : * The number of concurrent calls for the account 88 : * -1: Unlimited 89 : * 0: Do not disturb 90 : * 1: Single call 91 : * +: Multi line 92 : */ 93 : int activeCallLimit {-1}; 94 : 95 : std::vector<unsigned> activeCodecs {}; 96 : 97 : /** 98 : * Play ringtone when receiving a call 99 : */ 100 : bool ringtoneEnabled {true}; 101 : 102 : /** 103 : * Ringtone file used for this account 104 : */ 105 : std::string ringtonePath {DEFAULT_RINGTONE_PATH}; 106 : 107 : /** 108 : * Allows user to temporarily disable video calling 109 : */ 110 : bool videoEnabled {true}; 111 : 112 : /** 113 : * Display name when calling 114 : */ 115 : std::string displayName {}; 116 : 117 : /** 118 : * User-agent used for registration 119 : */ 120 : std::string customUserAgent {}; 121 : 122 : /** 123 : * Account mail box 124 : */ 125 : std::string mailbox {}; 126 : 127 : /** 128 : * UPnP IGD controller and the mutex to access it 129 : */ 130 : bool upnpEnabled {true}; 131 : 132 : std::set<std::string> defaultModerators {}; 133 : bool localModeratorsEnabled {true}; 134 : bool allModeratorsEnabled {true}; 135 : 136 : /** 137 : * Device push notification token. 138 : */ 139 : std::string deviceKey {}; 140 : /** 141 : * Device push notification platform. 142 : */ 143 : std::string platform {}; 144 : 145 : /** 146 : * Push notification topic. 147 : */ 148 : std::string notificationTopic {}; 149 : 150 : /** 151 : * information about the customization of ui 152 : */ 153 : std::string uiCustomization {}; 154 : }; 155 : 156 : inline void 157 40307 : parseString(const std::map<std::string, std::string>& details, const char* key, std::string& s) 158 : { 159 40307 : auto it = details.find(key); 160 40307 : if (it != details.end()) 161 17129 : s = it->second; 162 40307 : } 163 : 164 : inline void 165 29947 : parseBool(const std::map<std::string, std::string>& details, const char* key, bool& s) 166 : { 167 29947 : auto it = details.find(key); 168 29947 : if (it != details.end()) 169 15875 : s = it->second == TRUE_STR; 170 29947 : } 171 : 172 : template<class T> 173 : inline void 174 7902 : parseInt(const std::map<std::string, std::string>& details, const char* key, T& s) 175 : { 176 7902 : auto it = details.find(key); 177 7902 : if (it != details.end()) 178 4216 : s = to_int<T>(it->second); 179 7902 : } 180 : 181 : void parsePath(const std::map<std::string, std::string>& details, 182 : const char* key, 183 : std::string& s, 184 : const std::filesystem::path& base); 185 : 186 : } // namespace jami