account.h 7.34 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
/****************************************************************************
Sébastien Blin's avatar
Sébastien Blin committed
2
 *    Copyright (C) 2017-2019 Savoir-faire Linux Inc.                             *
Nicolas Jager's avatar
Nicolas Jager committed
3
4
 *   Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com>             *
 *   Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>           *
Nicolas Jager's avatar
Nicolas Jager committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 of the License, or (at your option) any later version.     *
 *                                                                          *
 *   This library is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#pragma once

Nicolas Jager's avatar
Nicolas Jager committed
21
// Std
Nicolas Jager's avatar
Nicolas Jager committed
22
23
24
#include <string>
#include <memory>

Nicolas Jager's avatar
Nicolas Jager committed
25
26
27
// Data
#include "profile.h"

28
29
30
// old LRC
#include "typedefs.h"

Nicolas Jager's avatar
Nicolas Jager committed
31
32
33
34
35
36
37
38
namespace lrc
{

namespace api
{

class ContactModel;
class ConversationModel;
Sébastien Blin's avatar
Sébastien Blin committed
39
class NewCallModel;
Nicolas Jager's avatar
Nicolas Jager committed
40
class NewAccountModel;
41
class NewDeviceModel;
42
class NewCodecModel;
43
class PeerDiscoveryModel;
Nicolas Jager's avatar
Nicolas Jager committed
44
45
46
47
48
49
50
51
52
53

namespace account
{

enum class Type {
    INVALID,
    RING,
    SIP
};

54
55
56
#pragma push_macro("REGISTERED")
#undef REGISTERED

Nicolas Jager's avatar
Nicolas Jager committed
57
58
enum class Status {
    INVALID,
59
    ERROR_NEED_MIGRATION,
Nicolas Jager's avatar
Nicolas Jager committed
60
61
62
63
64
65
    INITIALIZING,
    UNREGISTERED,
    TRYING,
    REGISTERED
};

66
static inline account::Status
Nicolas Jager's avatar
Nicolas Jager committed
67
68
69
70
71
72
73
74
to_status(const std::string& type)
{
    if (type == "INITIALIZING")
        return account::Status::INITIALIZING;
    else if (type == "UNREGISTERED")
        return account::Status::UNREGISTERED;
    else if (type == "TRYING")
        return account::Status::TRYING;
Sébastien Blin's avatar
Sébastien Blin committed
75
    else if (type == "REGISTERED" || type == "READY")
Nicolas Jager's avatar
Nicolas Jager committed
76
        return account::Status::REGISTERED;
77
78
    else if (type == "ERROR_NEED_MIGRATION")
        return account::Status::ERROR_NEED_MIGRATION;
Nicolas Jager's avatar
Nicolas Jager committed
79
80
81
82
    else
        return account::Status::INVALID;
}

83
84
#pragma pop_macro("REGISTERED")

85
86
87
88
89
90
91
92
93
94
95
96
enum class KeyExchangeProtocol {
    NONE,
    SDES
};

enum class TlsMethod {
    DEFAULT,
    TLSv1,
    TLSv1_1,
    TLSv1_2
};

97
98
99
100
101
102
103
104
105
106
107
struct ConfProperties_t {
    std::string             mailbox;
    std::string             dtmfType;
    bool                    autoAnswer;
    int                     activeCallLimit;
    std::string             hostname;
    std::string             username;
    std::string             routeset;
    std::string             password;
    std::string             realm;
    std::string             localInterface;
108
109
    std::string             deviceId;
    std::string             deviceName;
110
    std::string             managerUri;
111
    std::string             managerUsername;
112
113
114
115
116
117
118
    bool                    publishedSameAsLocal;
    int                     localPort;
    int                     publishedPort;
    std::string             publishedAddress;
    std::string             userAgent;
    bool                    upnpEnabled;
    bool                    hasCustomUserAgent;
119
    bool                    allowIncoming;
120
121
122
123
124
125
126
    std::string             archivePassword;
    bool                    archiveHasPassword;
    std::string             archivePath;
    std::string             archivePin;
    bool                    proxyEnabled;
    std::string             proxyServer;
    std::string             proxyPushToken;
127
    bool                    peerDiscovery;
128
129
    bool                    accountDiscovery;
    bool                    accountPublish;
130
    int                     registrationExpire;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    struct Audio_t {
        int                 audioPortMax;
        int                 audioPortMin;
    } Audio;
    struct Video_t {
        bool                videoEnabled;
        int                 videoPortMax;
        int                 videoPortMin;
    } Video;
    struct STUN_t {
        std::string         server;
        bool                enable;
    } STUN;
    struct TURN_t {
        std::string         server;
        bool                enable;
        std::string         username;
        std::string         password;
        std::string         realm;
    } TURN;
    struct Presence_t {
        bool                presencePublishSupported;
        bool                presenceSubscribeSupported;
        bool                presenceEnabled;
    } Presence;
    struct Ringtone_t {
        std::string         ringtonePath;
        bool                ringtoneEnabled;
    } Ringtone;
    struct SRTP_t {
161
        KeyExchangeProtocol keyExchange;
162
163
164
165
166
167
168
169
170
171
172
        bool                enable;
        bool                rtpFallback;
    } SRTP;
    struct TLS_t {
        int                 listenerPort;
        bool                enable;
        int                 port;
        std::string         certificateListFile;
        std::string         certificateFile;
        std::string         privateKeyFile;
        std::string         password;
173
        TlsMethod           method;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        std::string         ciphers;
        std::string         serverName;
        bool                verifyServer;
        bool                verifyClient;
        bool                requireClientCertificate;
        int                 negotiationTimeoutSec;
    } TLS;
    struct DHT_t {
        int                 port;
        bool                PublicInCalls;
        bool                AllowFromTrusted;
    } DHT;
    struct RingNS_t {
        std::string         uri;
        std::string         account;
    } RingNS;
190
191
192
    struct Registration_t {
        int                 expire;
    } Registration;
193
194
195
196

    MapStringString         toDetails() const;
};

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Possible account export status
enum class ExportOnRingStatus {
    SUCCESS = 0,
    WRONG_PASSWORD = 1 ,
    NETWORK_ERROR = 2,
    INVALID
};

enum class RegisterNameStatus {
    SUCCESS = 0,
    WRONG_PASSWORD = 1,
    INVALID_NAME = 2,
    ALREADY_TAKEN = 3,
    NETWORK_ERROR = 4,
    INVALID
};

enum class LookupStatus {
    SUCCESS = 0,
    INVALID_NAME = 1,
    NOT_FOUND = 2,
    ERROR = 3,
    INVALID
};

Nicolas Jager's avatar
Nicolas Jager committed
222
223
struct Info
{
224
225
    bool freeable = false;
    bool valid = true;
226
    std::string registeredName;
Nicolas Jager's avatar
Nicolas Jager committed
227
    Status status = account::Status::INVALID;
Nicolas Jager's avatar
Nicolas Jager committed
228
229
    std::unique_ptr<lrc::api::ContactModel> contactModel;
    std::unique_ptr<lrc::api::ConversationModel> conversationModel;
Sébastien Blin's avatar
Sébastien Blin committed
230
    std::unique_ptr<lrc::api::NewCallModel> callModel;
231
    std::unique_ptr<lrc::api::NewDeviceModel> deviceModel;
232
    std::unique_ptr<lrc::api::NewCodecModel> codecModel;
233
    std::unique_ptr<lrc::api::PeerDiscoveryModel> peerDiscoveryModel;
Nicolas Jager's avatar
Nicolas Jager committed
234
    NewAccountModel* accountModel {nullptr};
235
236
237
238
239
240
241
242
243

    // daemon config
    std::string             id;
    profile::Info           profileInfo; // contains: type, alias
    bool                    enabled;
    ConfProperties_t        confProperties;

    // load/save
    void                    fromDetails(const MapStringString& details);
Nicolas Jager's avatar
Nicolas Jager committed
244
245
246
247
248
};

} // namespace account
} // namespace api
} // namespace lrc