account.h 13.4 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
5
 *
yanmorin's avatar
 
yanmorin committed
6
7
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
yanmorin's avatar
 
yanmorin committed
9
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
10
 *
yanmorin's avatar
 
yanmorin committed
11
12
13
14
 *  This program 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 General Public License for more details.
Julien Bonjean's avatar
Julien Bonjean committed
15
 *
yanmorin's avatar
 
yanmorin committed
16
17
18
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21
22
23
24
25
26
27
28
29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
yanmorin's avatar
 
yanmorin committed
30
 */
31

yanmorin's avatar
 
yanmorin committed
32
33
34
35
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <string>
36
#include <vector>
37

38
#include "global.h"
yanmorin's avatar
   
yanmorin committed
39
#include "config/config.h"
40
#include "config/serializable.h"
yanmorin's avatar
 
yanmorin committed
41
42

class VoIPLink;
yanmorin's avatar
   
yanmorin committed
43

44
45
46
47
48
49
50
/**
 * @file account.h
 * @brief Interface to protocol account (SIPAccount, IAXAccount)
 * It can be enable on loading or activate after.
 * It contains account, configuration, VoIP Link and Calls (inside the VoIPLink)
 */

51
/** Contains all the state an Voip can be in */
52
enum RegistrationState {
Julien Bonjean's avatar
Julien Bonjean committed
53
54
55
56
57
58
59
60
61
    Unregistered,
    Trying,
    Registered,
    Error,
    ErrorAuth ,
    ErrorNetwork ,
    ErrorHost,
    ErrorExistStun,
    ErrorConfStun,
62
    NumberOfStates
63
};
64

Julien Bonjean's avatar
Julien Bonjean committed
65
// Account identifier
66
static const char *const ACCOUNT_ID                          = "Account.id";
67

68
// Common account parameters
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
static const char *const CONFIG_ACCOUNT_TYPE                 = "Account.type";
static const char *const CONFIG_ACCOUNT_ALIAS                = "Account.alias";
static const char *const CONFIG_ACCOUNT_MAILBOX	             = "Account.mailbox";
static const char *const CONFIG_ACCOUNT_ENABLE               = "Account.enable";
static const char *const CONFIG_ACCOUNT_REGISTRATION_EXPIRE  = "Account.expire";
static const char *const CONFIG_CREDENTIAL_NUMBER            = "Credential.count";
static const char *const ACCOUNT_DTMF_TYPE                   = "Account.dtmfType";
static const char *const CONFIG_RINGTONE_PATH                = "Account.ringtonePath";
static const char *const CONFIG_RINGTONE_ENABLED             = "Account.ringtoneEnabled";

static const char *const HOSTNAME                            = "hostname";
static const char *const USERNAME                            = "username";
static const char *const ROUTESET                            = "routeset";
static const char *const PASSWORD                            = "password";
static const char *const REALM                               = "realm";
static const char *const DEFAULT_REALM                       = "*";
static const char *const USERAGENT							 = "useragent";

static const char *const LOCAL_INTERFACE                     = "Account.localInterface";
static const char *const PUBLISHED_SAMEAS_LOCAL              = "Account.publishedSameAsLocal";
static const char *const LOCAL_PORT                          = "Account.localPort";
static const char *const PUBLISHED_PORT                      = "Account.publishedPort";
static const char *const PUBLISHED_ADDRESS                   = "Account.publishedAddress";

static const char *const DISPLAY_NAME                        = "Account.displayName";
static const char *const DEFAULT_ADDRESS                     = "0.0.0.0";
95

96
// SIP specific parameters
97
98
99
static const char *const SIP_PROXY                           = "SIP.proxy";
static const char *const STUN_SERVER						 = "STUN.server";
static const char *const STUN_ENABLE						 = "STUN.enable";
100
101

// SRTP specific parameters
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
static const char *const SRTP_ENABLE                         = "SRTP.enable";
static const char *const SRTP_KEY_EXCHANGE                   = "SRTP.keyExchange";
static const char *const SRTP_ENCRYPTION_ALGO                = "SRTP.encryptionAlgorithm";  // Provided by ccRTP,0=NULL,1=AESCM,2=AESF8
static const char *const SRTP_RTP_FALLBACK                   = "SRTP.rtpFallback";
static const char *const ZRTP_HELLO_HASH                     = "ZRTP.helloHashEnable";
static const char *const ZRTP_DISPLAY_SAS                    = "ZRTP.displaySAS";
static const char *const ZRTP_NOT_SUPP_WARNING               = "ZRTP.notSuppWarning";
static const char *const ZRTP_DISPLAY_SAS_ONCE               = "ZRTP.displaySasOnce";

static const char *const TLS_LISTENER_PORT                   = "TLS.listenerPort";
static const char *const TLS_ENABLE                          = "TLS.enable";
static const char *const TLS_CA_LIST_FILE                    = "TLS.certificateListFile";
static const char *const TLS_CERTIFICATE_FILE                = "TLS.certificateFile";
static const char *const TLS_PRIVATE_KEY_FILE                = "TLS.privateKeyFile";
static const char *const TLS_PASSWORD                        = "TLS.password";
static const char *const TLS_METHOD                          = "TLS.method";
static const char *const TLS_CIPHERS                         = "TLS.ciphers";
static const char *const TLS_SERVER_NAME                     = "TLS.serverName";
static const char *const TLS_VERIFY_SERVER                   = "TLS.verifyServer";
static const char *const TLS_VERIFY_CLIENT                   = "TLS.verifyClient";
static const char *const TLS_REQUIRE_CLIENT_CERTIFICATE      = "TLS.requireClientCertificate";
static const char *const TLS_NEGOTIATION_TIMEOUT_SEC         = "TLS.negotiationTimeoutSec";
static const char *const TLS_NEGOTIATION_TIMEOUT_MSEC        = "TLS.negotiationTimemoutMsec";

static const char *const REGISTRATION_STATUS                 = "Status";
static const char *const REGISTRATION_STATE_CODE             = "Registration.code";
static const char *const REGISTRATION_STATE_DESCRIPTION      = "Registration.description";
129

130
// General configuration keys for accounts
Tristan Matthews's avatar
Tristan Matthews committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
static const char * const aliasKey = "alias";
static const char * const typeKey = "type";
static const char * const idKey = "id";
static const char * const usernameKey = "username";
static const char * const authenticationUsernameKey = "authenticationUsername";
static const char * const passwordKey = "password";
static const char * const hostnameKey = "hostname";
static const char * const accountEnableKey = "enable";
static const char * const mailboxKey = "mailbox";

static const char * const codecsKey = "codecs";  // 0/9/110/111/112/
static const char * const ringtonePathKey = "ringtonePath";
static const char * const ringtoneEnabledKey = "ringtoneEnabled";
static const char * const displayNameKey = "displayName";
145

146
class Account : public Serializable {
147
148
149

    public:

150
        Account(const std::string& accountID, const std::string &type);
151
152
153
154
155
156

        /**
         * Virtual destructor
         */
        virtual ~Account();

157
158
159
160
        /**
         * Method called by the configuration engine to serialize instance's information
         * into configuration file.
         */
161
        virtual void serialize(Conf::YamlEmitter *emitter) = 0;
162

163
164
165
166
        /**
         * Method called by the configuration engine to restore instance internal state
         * from configuration file.
         */
167
        virtual void unserialize(Conf::MappingNode *map) = 0;
168

169
        virtual void setAccountDetails(std::map<std::string, std::string> details) = 0;
Julien Bonjean's avatar
Julien Bonjean committed
170

171
        virtual std::map<std::string, std::string> getAccountDetails() const = 0;
172

173
174
175
        /**
         * Load the settings for this account.
         */
176
        virtual void loadConfig() = 0;
177
178
179
180
181

        /**
         * Get the account ID
         * @return constant account id
         */
Tristan Matthews's avatar
Tristan Matthews committed
182
183
        std::string getAccountID() const {
            return accountID_;
Julien Bonjean's avatar
Julien Bonjean committed
184
        }
185
186
187
188
189

        /**
         * Get the voiplink pointer
         * @return VoIPLink* the pointer or 0
         */
190
        VoIPLink* getVoIPLink() {
Tristan Matthews's avatar
Tristan Matthews committed
191
            return link_;
Julien Bonjean's avatar
Julien Bonjean committed
192
        }
193
194
195
196
197

        /**
         * Register the underlying VoIPLink. Launch the event listener.
         * This should update the getRegistrationState() return value.
         */
198
        virtual void registerVoIPLink() = 0;
199
200
201
202
203

        /**
         * Unregister the underlying VoIPLink. Stop the event listener.
         * This should update the getRegistrationState() return value.
         */
204
        virtual void unregisterVoIPLink() = 0;
205
206

        /**
Julien Bonjean's avatar
Julien Bonjean committed
207
         * Tell if the account is enable or not.
208
209
210
         * @return true if enabled
         *	     false otherwise
         */
211
        bool isEnabled() const {
Tristan Matthews's avatar
Tristan Matthews committed
212
            return enabled_;
Julien Bonjean's avatar
Julien Bonjean committed
213
        }
214

215
        void setEnabled(bool enable) {
Tristan Matthews's avatar
Tristan Matthews committed
216
            enabled_ = enable;
Julien Bonjean's avatar
Julien Bonjean committed
217
        }
218

219
220
221
222
        /**
         * Set the registration state of the specified link
         * @param state	The registration state of underlying VoIPLink
         */
223
        void setRegistrationState(const RegistrationState &state);
Julien Bonjean's avatar
Julien Bonjean committed
224

225
        /* They should be treated like macro definitions by the C++ compiler */
226
        std::string getUsername(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
227
            return username_;
Julien Bonjean's avatar
Julien Bonjean committed
228
        }
229

230
        std::string getHostname(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
231
            return hostname_;
Julien Bonjean's avatar
Julien Bonjean committed
232
        }
233
        void setHostname(const std::string &hostname) {
Tristan Matthews's avatar
Tristan Matthews committed
234
            hostname_ = hostname;
Julien Bonjean's avatar
Julien Bonjean committed
235
236
        }

237
        std::string getAlias(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
238
            return alias_;
Julien Bonjean's avatar
Julien Bonjean committed
239
        }
240
        void setAlias(const std::string &alias) {
Tristan Matthews's avatar
Tristan Matthews committed
241
            alias_ = alias;
Julien Bonjean's avatar
Julien Bonjean committed
242
243
        }

244
        std::string getType(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
245
            return type_;
Julien Bonjean's avatar
Julien Bonjean committed
246
        }
247
        void setType(const std::string &type) {
Tristan Matthews's avatar
Tristan Matthews committed
248
            type_ = type;
Julien Bonjean's avatar
Julien Bonjean committed
249
        }
250

Julien Bonjean's avatar
Julien Bonjean committed
251
252
253
254
        /**
         * Accessor to data structures
         * @return CodecOrder& The list that reflects the user's choice
         */
255
        const CodecOrder& getActiveCodecs(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
256
            return codecOrder_;
Julien Bonjean's avatar
Julien Bonjean committed
257
        }
258
259
260
261
262

        /**
         * Update both the codec order structure and the codec string used for
         * SDP offer and configuration respectively
         */
263
        void setActiveCodecs(const std::vector <std::string>& list);
Julien Bonjean's avatar
Julien Bonjean committed
264

265
        std::string getRingtonePath(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
266
            return ringtonePath_;
Julien Bonjean's avatar
Julien Bonjean committed
267
        }
268
        void setRingtonePath(const std::string &path) {
Tristan Matthews's avatar
Tristan Matthews committed
269
            ringtonePath_ = path;
Julien Bonjean's avatar
Julien Bonjean committed
270
271
        }

272
        bool getRingtoneEnabled(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
273
            return ringtoneEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
274
        }
275
        void setRingtoneEnabled(bool enable) {
Tristan Matthews's avatar
Tristan Matthews committed
276
            ringtoneEnabled_ = enable;
Julien Bonjean's avatar
Julien Bonjean committed
277
278
        }

279
        std::string getDisplayName(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
280
            return displayName_;
Julien Bonjean's avatar
Julien Bonjean committed
281
        }
282
        void setDisplayName(const std::string &name) {
Tristan Matthews's avatar
Tristan Matthews committed
283
            displayName_ = name;
Julien Bonjean's avatar
Julien Bonjean committed
284
285
        }

286
        std::string getMailBox(void) const {
Tristan Matthews's avatar
Tristan Matthews committed
287
            return mailBox_;
288
289
        }

290
        void setMailBox(const std::string &mb) {
Tristan Matthews's avatar
Tristan Matthews committed
291
            mailBox_ = mb;
292
293
        }

294
    private:
295
        // copy constructor
296
        Account(const Account& rh);
297
298

        // assignment operator
Julien Bonjean's avatar
Julien Bonjean committed
299
        Account& operator= (const Account& rh);
300

301
302
        /**
         * Helper function used to load the default codec order from the codec factory
303
         * setActiveCodecs is called to sync both codecOrder_ and codecStr_
304
         */
305
        void loadDefaultCodecs(void);
306

307
    protected:
308
        static std::string mapStateNumberToString(RegistrationState state);
309

310
311
312
        /**
         * Account ID are assign in constructor and shall not changed
         */
Tristan Matthews's avatar
Tristan Matthews committed
313
        const std::string accountID_;
314

315
316
317
        /**
         * Account login information: username
         */
Tristan Matthews's avatar
Tristan Matthews committed
318
        std::string username_;
319
320
321
322

        /**
         * Account login information: hostname
         */
Tristan Matthews's avatar
Tristan Matthews committed
323
        std::string hostname_;
324
325
326
327

        /**
         * Account login information: Alias
         */
Tristan Matthews's avatar
Tristan Matthews committed
328
        std::string alias_;
329

330
331
332
        /**
         * Voice over IP Link contains a listener thread and calls
         */
Tristan Matthews's avatar
Tristan Matthews committed
333
        VoIPLink* link_;
334
335
336
337
338
339

        /**
         * Tells if the link is enabled, active.
         * This implies the link will be initialized on startup.
         * Modified by the configuration (key: ENABLED)
         */
Tristan Matthews's avatar
Tristan Matthews committed
340
        bool enabled_;
341

342
343
344
345
        /*
         * The account type
         * IAX2 or SIP
         */
Tristan Matthews's avatar
Tristan Matthews committed
346
        std::string type_;
347

348
        /*
Julien Bonjean's avatar
Julien Bonjean committed
349
         * The general, protocol neutral registration
350
         * state of the account
351
         */
Tristan Matthews's avatar
Tristan Matthews committed
352
        RegistrationState registrationState_;
Julien Bonjean's avatar
Julien Bonjean committed
353
354
355
356

        /**
         * Vector containing the order of the codecs
         */
Tristan Matthews's avatar
Tristan Matthews committed
357
        CodecOrder codecOrder_;
Julien Bonjean's avatar
Julien Bonjean committed
358
359
360
361
362

        /**
         * List of codec obtained when parsing configuration and used
         * to generate codec order list
         */
Tristan Matthews's avatar
Tristan Matthews committed
363
        std::string codecStr_;
Julien Bonjean's avatar
Julien Bonjean committed
364
365
366
367

        /**
         * Ringtone .au file used for this account
         */
Tristan Matthews's avatar
Tristan Matthews committed
368
        std::string ringtonePath_;
Julien Bonjean's avatar
Julien Bonjean committed
369
370
371
372

        /**
         * Play ringtone when receiving a call
         */
Tristan Matthews's avatar
Tristan Matthews committed
373
        bool ringtoneEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
374
375
376
377

        /**
         * Display name when calling
         */
Tristan Matthews's avatar
Tristan Matthews committed
378
        std::string displayName_;
379

Julien Bonjean's avatar
Julien Bonjean committed
380
381
382
        /**
         * Useragent used for registration
         */
Tristan Matthews's avatar
Tristan Matthews committed
383
        std::string userAgent_;
384

385
386
387
        /**
             * Account mail box
         */
Tristan Matthews's avatar
Tristan Matthews committed
388
        std::string mailBox_;
389

yanmorin's avatar
 
yanmorin committed
390
391
392
};

#endif