~ubuntu-branches/ubuntu/oneiric/sflphone/oneiric

« back to all changes in this revision

Viewing changes to sflphone-common/src/account.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
5
 
 *                                                                              
 
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
8
8
 *  the Free Software Foundation; either version 3 of the License, or
9
9
 *  (at your option) any later version.
10
 
 *                                                                                
 
10
 *
11
11
 *  This program is distributed in the hope that it will be useful,
12
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 *  GNU General Public License for more details.
15
 
 *                                                                              
 
15
 *
16
16
 *  You should have received a copy of the GNU General Public License
17
17
 *  along with this program; if not, write to the Free Software
18
18
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37
37
 
38
38
#include "config/config.h"
39
39
#include "voiplink.h"
 
40
#include "config/serializable.h"
40
41
 
41
42
class VoIPLink;
42
43
 
51
52
 
52
53
/** Contains all the state an Voip can be in */
53
54
typedef enum RegistrationState {
54
 
        Unregistered, 
55
 
        Trying, 
56
 
        Registered, 
57
 
        Error, 
58
 
        ErrorAuth , 
59
 
        ErrorNetwork , 
60
 
        ErrorHost, 
61
 
        ErrorExistStun, 
62
 
        ErrorConfStun,
63
 
        NumberOfState
 
55
    Unregistered,
 
56
    Trying,
 
57
    Registered,
 
58
    Error,
 
59
    ErrorAuth ,
 
60
    ErrorNetwork ,
 
61
    ErrorHost,
 
62
    ErrorExistStun,
 
63
    ErrorConfStun,
 
64
    NumberOfState
64
65
} RegistrationState;
65
66
 
66
67
#define AccountNULL ""
67
68
 
68
 
// Account identifier                       
 
69
// Account identifier
69
70
#define ACCOUNT_ID                          "Account.id"
70
71
 
71
72
// Common account parameters
72
 
#define CONFIG_ACCOUNT_TYPE                 "Account.type"  
 
73
#define CONFIG_ACCOUNT_TYPE                 "Account.type"
73
74
#define CONFIG_ACCOUNT_ALIAS                "Account.alias"
74
75
#define CONFIG_ACCOUNT_MAILBOX              "Account.mailbox"
75
76
#define CONFIG_ACCOUNT_ENABLE               "Account.enable"
77
78
#define CONFIG_ACCOUNT_REGISTRATION_EXPIRE  "Account.expire"
78
79
#define CONFIG_CREDENTIAL_NUMBER            "Credential.count"
79
80
#define ACCOUNT_DTMF_TYPE                   "Account.dtmfType"
 
81
#define CONFIG_RINGTONE_PATH                "Account.ringtonePath"
 
82
#define CONFIG_RINGTONE_ENABLED             "Account.ringtoneEnabled"
80
83
 
81
84
#define HOSTNAME                            "hostname"
82
85
#define USERNAME                            "username"
122
125
#define TLS_SERVER_NAME                     "TLS.serverName"
123
126
#define TLS_VERIFY_SERVER                   "TLS.verifyServer"
124
127
#define TLS_VERIFY_CLIENT                   "TLS.verifyClient"
125
 
#define TLS_REQUIRE_CLIENT_CERTIFICATE      "TLS.requireClientCertificate"  
 
128
#define TLS_REQUIRE_CLIENT_CERTIFICATE      "TLS.requireClientCertificate"
126
129
#define TLS_NEGOTIATION_TIMEOUT_SEC         "TLS.negotiationTimeoutSec"
127
130
#define TLS_NEGOTIATION_TIMEOUT_MSEC        "TLS.negotiationTimemoutMsec"
128
131
 
129
132
#define REGISTRATION_STATUS                 "Status"
130
 
#define REGISTRATION_STATE_CODE             "Registration.code" 
 
133
#define REGISTRATION_STATE_CODE             "Registration.code"
131
134
#define REGISTRATION_STATE_DESCRIPTION      "Registration.description"
132
135
 
133
136
 
134
 
class Account{
 
137
// General configuration keys for accounts
 
138
const Conf::Key aliasKey ("alias");
 
139
const Conf::Key typeKey ("type");
 
140
const Conf::Key idKey ("id");
 
141
const Conf::Key usernameKey ("username");
 
142
const Conf::Key passwordKey ("password");
 
143
const Conf::Key hostnameKey ("hostname");
 
144
const Conf::Key accountEnableKey ("enable");
 
145
const Conf::Key mailboxKey ("mailbox");
 
146
 
 
147
const Conf::Key codecsKey ("codecs");  // 0/9/110/111/112/
 
148
const Conf::Key ringtonePathKey ("ringtonePath");
 
149
const Conf::Key ringtoneEnabledKey ("ringtoneEnabled");
 
150
const Conf::Key displayNameKey ("displayName");
 
151
 
 
152
#define find_in_map(X, Y)  if((iter = map_cpy.find(X)) != map_cpy.end()) { Y = iter->second; }
 
153
 
 
154
class Account : public Serializable
 
155
{
135
156
 
136
157
    public:
137
158
 
138
 
        Account(const AccountID& accountID, std::string type);
 
159
        Account (const AccountID& accountID, std::string type);
139
160
 
140
161
        /**
141
162
         * Virtual destructor
143
164
        virtual ~Account();
144
165
 
145
166
        /**
 
167
         * Method called by the configuration engine to serialize instance's information
 
168
         * into configuration file.
 
169
         */
 
170
        virtual void serialize (Conf::YamlEmitter *emitter) = 0;
 
171
 
 
172
        /**
 
173
         * Method called by the configuration engine to restore instance internal state
 
174
         * from configuration file.
 
175
         */
 
176
        virtual void unserialize (Conf::MappingNode *map) = 0;
 
177
 
 
178
        virtual void setAccountDetails (const std::map<std::string, std::string>& details) = 0;
 
179
 
 
180
        virtual std::map<std::string, std::string> getAccountDetails() = 0;
 
181
 
 
182
 
 
183
        /**
146
184
         * Load the settings for this account.
147
185
         */
148
186
        virtual void loadConfig();
151
189
         * Get the account ID
152
190
         * @return constant account id
153
191
         */
154
 
        inline const AccountID& getAccountID() { return _accountID; }
 
192
        inline const AccountID& getAccountID() {
 
193
            return _accountID;
 
194
        }
155
195
 
156
196
        /**
157
197
         * Get the voiplink pointer
158
198
         * @return VoIPLink* the pointer or 0
159
199
         */
160
 
        inline VoIPLink* getVoIPLink() { return _link; }
 
200
        inline VoIPLink* getVoIPLink() {
 
201
            return _link;
 
202
        }
161
203
 
162
204
        virtual void setVoIPLink () = 0;
163
205
 
174
216
        virtual int unregisterVoIPLink() = 0;
175
217
 
176
218
        /**
177
 
         * Tell if the account is enable or not. 
 
219
         * Tell if the account is enable or not.
178
220
         * @return true if enabled
179
221
         *           false otherwise
180
222
         */
181
 
        bool isEnabled() { return _enabled; }
 
223
        bool isEnabled() {
 
224
            return _enabled;
 
225
        }
 
226
 
 
227
        void setEnabled (bool enabl) {
 
228
            _enabled = enabl;
 
229
        }
182
230
 
183
231
        /**
184
232
         * Get the registration state of the specified link
185
233
         * @return RegistrationState    The registration state of underlying VoIPLink
186
234
         */
187
 
        inline RegistrationState getRegistrationState() { return _registrationState; }
 
235
        inline RegistrationState getRegistrationState() {
 
236
            return _registrationState;
 
237
        }
188
238
 
189
239
        /**
190
240
         * Set the registration state of the specified link
191
241
         * @param state The registration state of underlying VoIPLink
192
242
         */
193
 
        void setRegistrationState( RegistrationState state );
194
 
        
 
243
        void setRegistrationState (RegistrationState state);
 
244
 
195
245
        /**
196
246
         * Set the latest up-to-date state code
197
 
         * for that account. These codes are 
 
247
         * for that account. These codes are
198
248
         * those used in SIP and IAX (eg. 200, 500 ...)
199
249
         * @param state The Code:Description state
200
250
         * @return void
201
251
         */
202
 
        void setRegistrationStateDetailed(std::pair<int, std::string> state) { _registrationStateDetailed = state; }
203
 
        
 
252
        void setRegistrationStateDetailed (std::pair<int, std::string> state) {
 
253
            _registrationStateDetailed = state;
 
254
        }
 
255
 
204
256
        /**
205
257
         * Get the latest up-to-date state code
206
 
         * for that account. These codes are 
 
258
         * for that account. These codes are
207
259
         * those used in SIP and IAX (eg. 200, 500 ...)
208
260
         * @param void
209
261
         * @return std::pair<int, std::string> A Code:Description state
210
262
         */
211
 
        std::pair<int, std::string> getRegistrationStateDetailed(void) { return _registrationStateDetailed; }
212
 
                        
 
263
        std::pair<int, std::string> getRegistrationStateDetailed (void) {
 
264
            return _registrationStateDetailed;
 
265
        }
 
266
 
213
267
 
214
268
        /* inline functions */
215
269
        /* They should be treated like macro definitions by the C++ compiler */
216
 
        inline std::string getUsername( void ) { return _username; }
217
 
        inline void setUsername( std::string username) { _username = username; }
218
 
 
219
 
        inline std::string getHostname( void ) { return _hostname; }
220
 
        inline void setHostname( std::string hostname) { _hostname = hostname; }
221
 
 
222
 
        inline std::string getPassword( void ) { return _password; }
223
 
        inline void setPassword( std::string password ) { _password = password; }
224
 
 
225
 
        inline std::string getAlias( void ) { return _alias; }
226
 
        inline void setAlias( std::string alias ) { _alias = alias; }
227
 
 
228
 
        inline std::string getType( void ) { return _type; }
229
 
        inline void setType( std::string type ) { _type = type; }
230
 
        
231
 
                /**
232
 
                 * Accessor to data structures
233
 
                 * @return CodecOrder& The list that reflects the user's choice
234
 
                 */
235
 
                inline CodecOrder& getActiveCodecs() { return _codecOrder; }
236
 
 
237
 
                void setActiveCodecs (const std::vector <std::string>& list);
 
270
        inline std::string getUsername (void) {
 
271
            return _username;
 
272
        }
 
273
        inline void setUsername (std::string username) {
 
274
            _username = username;
 
275
        }
 
276
 
 
277
        inline std::string getHostname (void) {
 
278
            return _hostname;
 
279
        }
 
280
        inline void setHostname (std::string hostname) {
 
281
            _hostname = hostname;
 
282
        }
 
283
 
 
284
        inline std::string getPassword (void) {
 
285
            return _password;
 
286
        }
 
287
        inline void setPassword (std::string password) {
 
288
            _password = password;
 
289
        }
 
290
 
 
291
        inline std::string getAlias (void) {
 
292
            return _alias;
 
293
        }
 
294
        inline void setAlias (std::string alias) {
 
295
            _alias = alias;
 
296
        }
 
297
 
 
298
        inline std::string getType (void) {
 
299
            return _type;
 
300
        }
 
301
        inline void setType (std::string type) {
 
302
            _type = type;
 
303
        }
 
304
 
 
305
        /**
 
306
         * Accessor to data structures
 
307
         * @return CodecOrder& The list that reflects the user's choice
 
308
         */
 
309
        inline CodecOrder& getActiveCodecs (void) {
 
310
            return _codecOrder;
 
311
        }
 
312
        void setActiveCodecs (const std::vector <std::string>& list);
 
313
 
 
314
        inline std::string getRingtonePath (void) {
 
315
            return _ringtonePath;
 
316
        }
 
317
        inline void setRingtonePath (std::string path) {
 
318
            _ringtonePath = path;
 
319
        }
 
320
 
 
321
        inline bool getRingtoneEnabled (void) {
 
322
            return _ringtoneEnabled;
 
323
        }
 
324
        inline void setRingtoneEnabled (bool enabl) {
 
325
            _ringtoneEnabled = enabl;
 
326
        }
 
327
 
 
328
        inline std::string getDisplayName (void) {
 
329
            return _displayName;
 
330
        }
 
331
        inline void setDisplayName (std::string name) {
 
332
            _displayName = name;
 
333
        }
 
334
 
 
335
        std::string getUseragent (void) {
 
336
            return _useragent;
 
337
        }
 
338
        void setUseragent (std::string ua) {
 
339
            _useragent = ua;
 
340
        }
 
341
 
 
342
        std::string getMailBox (void) {
 
343
            return _mailBox;
 
344
        }
 
345
 
 
346
        void setMailBox (std::string mb) {
 
347
            _mailBox = mb;
 
348
        }
238
349
 
239
350
    private:
240
351
        // copy constructor
241
 
        Account(const Account& rh);
 
352
        Account (const Account& rh);
242
353
 
243
354
        // assignment operator
244
 
        Account& operator=(const Account& rh);
245
 
 
246
 
                void loadAudioCodecs (void);
 
355
        Account& operator= (const Account& rh);
247
356
 
248
357
    protected:
 
358
 
 
359
        void loadAudioCodecs (void);
 
360
 
249
361
        /**
250
362
         * Account ID are assign in constructor and shall not changed
251
363
         */
290
402
        std::string _type;
291
403
 
292
404
        /*
293
 
         * The general, protocol neutral registration 
 
405
         * The general, protocol neutral registration
294
406
         * state of the account
295
407
         */
296
408
        RegistrationState _registrationState;
297
 
        
 
409
 
298
410
        /*
299
411
         * Details about the registration state.
300
 
         * This is a protocol Code:Description pair. 
 
412
         * This is a protocol Code:Description pair.
301
413
         */
302
414
        std::pair<int, std::string> _registrationStateDetailed;
303
415
 
304
 
                /**
305
 
                 * Vector containing the order of the codecs
306
 
                 */
307
 
                CodecOrder _codecOrder;
 
416
        /**
 
417
         * Vector containing the order of the codecs
 
418
         */
 
419
        CodecOrder _codecOrder;
 
420
 
 
421
        /**
 
422
         * List of codec obtained when parsing configuration and used
 
423
         * to generate codec order list
 
424
         */
 
425
        std::string _codecStr;
 
426
 
 
427
        /**
 
428
         * Ringtone .au file used for this account
 
429
         */
 
430
        std::string _ringtonePath;
 
431
 
 
432
        /**
 
433
         * Play ringtone when receiving a call
 
434
         */
 
435
        bool _ringtoneEnabled;
 
436
 
 
437
        /**
 
438
         * Display name when calling
 
439
         */
 
440
        std::string _displayName;
 
441
 
 
442
        /**
 
443
         * Useragent used for registration
 
444
         */
 
445
        std::string _useragent;
 
446
 
 
447
 
 
448
        /**
 
449
             * Account mail box
 
450
         */
 
451
        std::string _mailBox;
308
452
 
309
453
};
310
454