~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/sip/sipaccount.cpp

  • 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:
34
34
#include "manager.h"
35
35
#include "user_cfg.h"
36
36
#include <pwd.h>
 
37
#include <sstream>
 
38
 
 
39
Credentials::Credentials() : credentialCount (0) {}
 
40
 
 
41
Credentials::~Credentials() {}
 
42
 
 
43
void Credentials::setNewCredential (std::string username, std::string password, std::string realm)
 
44
{
 
45
    credentialArray[credentialCount].username = username;
 
46
    credentialArray[credentialCount].password = password;
 
47
    credentialArray[credentialCount].realm = realm;
 
48
 
 
49
}
 
50
 
 
51
CredentialItem *Credentials::getCredential (int index)
 
52
{
 
53
    if ( (index >= 0) && (index < credentialCount))
 
54
        return & (credentialArray[index]);
 
55
    else
 
56
        return NULL;
 
57
}
 
58
 
 
59
void Credentials::serialize (Conf::YamlEmitter *emitter UNUSED)
 
60
{
 
61
 
 
62
}
 
63
 
 
64
void Credentials::unserialize (Conf::MappingNode *map)
 
65
{
 
66
 
 
67
    Conf::ScalarNode *val = NULL;
 
68
 
 
69
    _debug ("SipAccount: Unserialize credentials");
 
70
 
 
71
    val = (Conf::ScalarNode *) (map->getValue (credentialCountKey));
 
72
 
 
73
    if (val) {
 
74
        credentialCount = atoi (val->getValue().data());
 
75
        val = NULL;
 
76
    }
 
77
}
 
78
 
 
79
 
37
80
 
38
81
SIPAccount::SIPAccount (const AccountID& accountID)
39
 
        : Account (accountID, "sip")
40
 
        , _routeSet("")
41
 
        , _regc (NULL)
42
 
        , _bRegister (false)
43
 
        , _registrationExpire ("")
44
 
        , _publishedSameasLocal (true)
45
 
        , _publishedIpAddress ("")
46
 
        , _localPort (atoi (DEFAULT_SIP_PORT))
47
 
        , _publishedPort (atoi (DEFAULT_SIP_PORT))
48
 
        , _tlsListenerPort (atoi (DEFAULT_SIP_TLS_PORT))
49
 
        , _transportType (PJSIP_TRANSPORT_UNSPECIFIED)
50
 
        , _transport (NULL)
51
 
        , _resolveOnce (false)
52
 
        , _credentialCount (0)
53
 
        , _cred (NULL)
54
 
        , _realm (DEFAULT_REALM)
55
 
        , _authenticationUsername ("")
56
 
        , _tlsSetting (NULL)
57
 
        , _dtmfType(OVERRTP)
58
 
        , _displayName ("")
 
82
    : Account (accountID, "SIP")
 
83
    , _routeSet ("")
 
84
    , _regc (NULL)
 
85
    , _bRegister (false)
 
86
    , _registrationExpire ("")
 
87
    , _interface ("default")
 
88
    , _publishedSameasLocal (true)
 
89
    , _publishedIpAddress ("")
 
90
    , _localPort (atoi (DEFAULT_SIP_PORT))
 
91
    , _publishedPort (atoi (DEFAULT_SIP_PORT))
 
92
    , _serviceRoute ("")
 
93
    , _tlsListenerPort (atoi (DEFAULT_SIP_TLS_PORT))
 
94
    , _transportType (PJSIP_TRANSPORT_UNSPECIFIED)
 
95
    , _transport (NULL)
 
96
    , _resolveOnce (false)
 
97
    , _cred (NULL)
 
98
    , _realm (DEFAULT_REALM)
 
99
    , _authenticationUsername ("")
 
100
    , _tlsSetting (NULL)
 
101
    , _dtmfType (SIPINFO)
 
102
    , _tlsEnable ("false")
 
103
    , _tlsPortStr (DEFAULT_SIP_TLS_PORT)
 
104
    , _tlsCaListFile ("")
 
105
    , _tlsCertificateFile ("")
 
106
    , _tlsPrivateKeyFile ("")
 
107
    , _tlsPassword ("")
 
108
    , _tlsMethod ("TLSv1")
 
109
    , _tlsCiphers ("")
 
110
    , _tlsServerName ("")
 
111
    , _tlsVerifyServer (true)
 
112
    , _tlsVerifyClient (true)
 
113
    , _tlsRequireClientCertificate (true)
 
114
    , _tlsNegotiationTimeoutSec ("2")
 
115
    , _tlsNegotiationTimeoutMsec ("0")
 
116
    , _stunServer (DFT_STUN_SERVER)
 
117
    , _stunEnabled (false)
 
118
    , _srtpEnabled (false)
 
119
    , _srtpKeyExchange ("sdes")
 
120
    , _srtpFallback (false)
 
121
    , _zrtpDisplaySas (true)
 
122
    , _zrtpDisplaySasOnce (false)
 
123
    , _zrtpHelloHash (true)
 
124
    , _zrtpNotSuppWarning (true)
59
125
{
60
 
    
61
 
    // IP2IP settings must be loaded before singleton instanciation, cannot call it here... 
 
126
 
 
127
    _debug ("Sip account constructor called");
 
128
 
 
129
    _stunServerName.ptr = NULL;
 
130
    _stunServerName.slen = 0;
 
131
    _stunPort = 0;
 
132
 
 
133
    // IP2IP settings must be loaded before singleton instanciation, cannot call it here...
62
134
 
63
135
    // _link = SIPVoIPLink::instance ("");
64
136
 
70
142
SIPAccount::~SIPAccount()
71
143
{
72
144
    /* One SIP account less connected to the sip voiplink */
73
 
    dynamic_cast<SIPVoIPLink*> (_link)->decrementClients();
 
145
    if (_accountID != "default")
 
146
        dynamic_cast<SIPVoIPLink*> (_link)->decrementClients();
74
147
 
75
148
    /* Delete accounts-related information */
76
149
    _regc = NULL;
78
151
    free (_tlsSetting);
79
152
}
80
153
 
 
154
void SIPAccount::serialize (Conf::YamlEmitter *emitter)
 
155
{
 
156
 
 
157
    _debug ("SipAccount: serialize %s", _accountID.c_str());
 
158
 
 
159
 
 
160
    Conf::MappingNode accountmap (NULL);
 
161
    Conf::MappingNode credentialmap (NULL);
 
162
    Conf::MappingNode srtpmap (NULL);
 
163
    Conf::MappingNode zrtpmap (NULL);
 
164
    Conf::MappingNode tlsmap (NULL);
 
165
 
 
166
    Conf::ScalarNode id (Account::_accountID);
 
167
    Conf::ScalarNode username (Account::_username);
 
168
    Conf::ScalarNode password (Account::_password);
 
169
    Conf::ScalarNode alias (Account::_alias);
 
170
    Conf::ScalarNode hostname (Account::_hostname);
 
171
    Conf::ScalarNode enable (_enabled ? "true" : "false");
 
172
    Conf::ScalarNode type (Account::_type);
 
173
    Conf::ScalarNode expire (_registrationExpire);
 
174
    Conf::ScalarNode interface (_interface);
 
175
    std::stringstream portstr;
 
176
    portstr << _localPort;
 
177
    Conf::ScalarNode port (portstr.str());
 
178
    Conf::ScalarNode serviceRoute (_serviceRoute);
 
179
 
 
180
    Conf::ScalarNode mailbox (_mailBox);
 
181
    Conf::ScalarNode publishAddr (_publishedIpAddress);
 
182
    std::stringstream publicportstr;
 
183
    publicportstr << _publishedPort;
 
184
    Conf::ScalarNode publishPort (publicportstr.str());
 
185
    Conf::ScalarNode sameasLocal (_publishedSameasLocal ? "true" : "false");
 
186
    Conf::ScalarNode resolveOnce (_resolveOnce ? "true" : "false");
 
187
    Conf::ScalarNode codecs (_codecStr);
 
188
    Conf::ScalarNode ringtonePath (_ringtonePath);
 
189
    Conf::ScalarNode ringtoneEnabled (_ringtoneEnabled ? "true" : "false");
 
190
    Conf::ScalarNode stunServer (_stunServer);
 
191
    Conf::ScalarNode stunEnabled (_stunEnabled ? "true" : "false");
 
192
    Conf::ScalarNode displayName (_displayName);
 
193
    Conf::ScalarNode dtmfType (_dtmfType==OVERRTP ? "overrtp" : "sipinfo");
 
194
 
 
195
    std::stringstream countstr;
 
196
    countstr << 0;
 
197
    Conf::ScalarNode count (countstr.str());
 
198
 
 
199
    Conf::ScalarNode srtpenabled (_srtpEnabled ? "true" : "false");
 
200
    Conf::ScalarNode keyExchange (_srtpKeyExchange);
 
201
    Conf::ScalarNode rtpFallback (_srtpFallback ? "true" : "false");
 
202
 
 
203
    Conf::ScalarNode displaySas (_zrtpDisplaySas ? "true" : "false");
 
204
    Conf::ScalarNode displaySasOnce (_zrtpDisplaySasOnce ? "true" : "false");
 
205
    Conf::ScalarNode helloHashEnabled (_zrtpHelloHash ? "true" : "false");
 
206
    Conf::ScalarNode notSuppWarning (_zrtpNotSuppWarning ? "true" : "false");
 
207
 
 
208
    Conf::ScalarNode tlsport (_tlsPortStr);
 
209
    Conf::ScalarNode certificate (_tlsCertificateFile);
 
210
    Conf::ScalarNode calist (_tlsCaListFile);
 
211
    Conf::ScalarNode ciphers (_tlsCiphers);
 
212
    Conf::ScalarNode tlsenabled (_tlsEnable);
 
213
    Conf::ScalarNode tlsmethod (_tlsMethod);
 
214
    Conf::ScalarNode timeout (_tlsNegotiationTimeoutSec);
 
215
    Conf::ScalarNode tlspassword (_tlsPassword);
 
216
    Conf::ScalarNode privatekey (_tlsPrivateKeyFile);
 
217
    Conf::ScalarNode requirecertif (_tlsRequireClientCertificate ? "true" : "false");
 
218
    Conf::ScalarNode server (_tlsServerName);
 
219
    Conf::ScalarNode verifyclient (_tlsVerifyServer ? "true" : "false");
 
220
    Conf::ScalarNode verifyserver (_tlsVerifyClient ? "true" : "false");
 
221
 
 
222
    accountmap.setKeyValue (aliasKey, &alias);
 
223
    accountmap.setKeyValue (typeKey, &type);
 
224
    accountmap.setKeyValue (idKey, &id);
 
225
    accountmap.setKeyValue (usernameKey, &username);
 
226
    accountmap.setKeyValue (passwordKey, &password);
 
227
    accountmap.setKeyValue (hostnameKey, &hostname);
 
228
    accountmap.setKeyValue (accountEnableKey, &enable);
 
229
    accountmap.setKeyValue (mailboxKey, &mailbox);
 
230
    accountmap.setKeyValue (expireKey, &expire);
 
231
    accountmap.setKeyValue (interfaceKey, &interface);
 
232
    accountmap.setKeyValue (portKey, &port);
 
233
    accountmap.setKeyValue (stunServerKey, &stunServer);
 
234
    accountmap.setKeyValue (stunEnabledKey, &stunEnabled);
 
235
    accountmap.setKeyValue (publishAddrKey, &publishAddr);
 
236
    accountmap.setKeyValue (publishPortKey, &publishPort);
 
237
    accountmap.setKeyValue (sameasLocalKey, &sameasLocal);
 
238
    accountmap.setKeyValue (resolveOnceKey, &resolveOnce);
 
239
    accountmap.setKeyValue (serviceRouteKey, &serviceRoute);
 
240
    accountmap.setKeyValue (dtmfTypeKey, &dtmfType);
 
241
    accountmap.setKeyValue (displayNameKey, &displayName);
 
242
    accountmap.setKeyValue (codecsKey, &codecs);
 
243
    accountmap.setKeyValue (ringtonePathKey, &ringtonePath);
 
244
    accountmap.setKeyValue (ringtoneEnabledKey, &ringtoneEnabled);
 
245
 
 
246
    accountmap.setKeyValue (srtpKey, &srtpmap);
 
247
    srtpmap.setKeyValue (srtpEnableKey, &srtpenabled);
 
248
    srtpmap.setKeyValue (keyExchangeKey, &keyExchange);
 
249
    srtpmap.setKeyValue (rtpFallbackKey, &rtpFallback);
 
250
 
 
251
    accountmap.setKeyValue (zrtpKey, &zrtpmap);
 
252
    zrtpmap.setKeyValue (displaySasKey, &displaySas);
 
253
    zrtpmap.setKeyValue (displaySasOnceKey, &displaySasOnce);
 
254
    zrtpmap.setKeyValue (helloHashEnabledKey, &helloHashEnabled);
 
255
    zrtpmap.setKeyValue (notSuppWarningKey, &notSuppWarning);
 
256
 
 
257
    accountmap.setKeyValue (credKey, &credentialmap);
 
258
    credentialmap.setKeyValue (credentialCountKey, &count);
 
259
 
 
260
    accountmap.setKeyValue (tlsKey, &tlsmap);
 
261
    tlsmap.setKeyValue (tlsPortKey, &tlsport);
 
262
    tlsmap.setKeyValue (certificateKey, &certificate);
 
263
    tlsmap.setKeyValue (calistKey, &calist);
 
264
    tlsmap.setKeyValue (ciphersKey, &ciphers);
 
265
    tlsmap.setKeyValue (tlsEnableKey, &tlsenabled);
 
266
    tlsmap.setKeyValue (methodKey, &tlsmethod);
 
267
    tlsmap.setKeyValue (timeoutKey, &timeout);
 
268
    tlsmap.setKeyValue (tlsPasswordKey, &tlspassword);
 
269
    tlsmap.setKeyValue (privateKeyKey, &privatekey);
 
270
    tlsmap.setKeyValue (requireCertifKey, &requirecertif);
 
271
    tlsmap.setKeyValue (serverKey, &server);
 
272
    tlsmap.setKeyValue (verifyClientKey, &verifyclient);
 
273
    tlsmap.setKeyValue (verifyServerKey, &verifyserver);
 
274
 
 
275
    try {
 
276
        emitter->serializeAccount (&accountmap);
 
277
    } catch (Conf::YamlEmitterException &e) {
 
278
        _error ("ConfigTree: %s", e.what());
 
279
    }
 
280
}
 
281
 
 
282
 
 
283
void SIPAccount::unserialize (Conf::MappingNode *map)
 
284
{
 
285
    Conf::ScalarNode *val;
 
286
    Conf::MappingNode *srtpMap;
 
287
    Conf::MappingNode *tlsMap;
 
288
    Conf::MappingNode *zrtpMap;
 
289
    Conf::MappingNode *credMap;
 
290
 
 
291
    _debug ("SipAccount: Unserialize %s", _accountID.c_str());
 
292
 
 
293
    val = (Conf::ScalarNode *) (map->getValue (aliasKey));
 
294
 
 
295
    if (val) {
 
296
        _alias = val->getValue();
 
297
        val = NULL;
 
298
    }
 
299
 
 
300
    val = (Conf::ScalarNode *) (map->getValue (typeKey));
 
301
 
 
302
    if (val) {
 
303
        _type = val->getValue();
 
304
        val = NULL;
 
305
    }
 
306
 
 
307
    val = (Conf::ScalarNode *) (map->getValue (idKey));
 
308
 
 
309
    if (val) {
 
310
        _accountID = val->getValue();
 
311
        val = NULL;
 
312
    }
 
313
 
 
314
    val = (Conf::ScalarNode *) (map->getValue (usernameKey));
 
315
 
 
316
    if (val) {
 
317
        _username = val->getValue();
 
318
        val = NULL;
 
319
    }
 
320
 
 
321
    val = (Conf::ScalarNode *) (map->getValue (passwordKey));
 
322
 
 
323
    if (val) {
 
324
        _password = val->getValue();
 
325
        val = NULL;
 
326
    }
 
327
 
 
328
    val = (Conf::ScalarNode *) (map->getValue (hostnameKey));
 
329
 
 
330
    if (val) {
 
331
        _hostname = val->getValue();
 
332
        val = NULL;
 
333
    }
 
334
 
 
335
    val = (Conf::ScalarNode *) (map->getValue (accountEnableKey));
 
336
 
 
337
    if (val) {
 
338
        _enabled = (val->getValue() == "false") ? false : true;
 
339
        val = NULL;
 
340
    }
 
341
 
 
342
    val = (Conf::ScalarNode *) (map->getValue (mailboxKey));
 
343
 
 
344
    if (val) {
 
345
        _mailBox = val->getValue();
 
346
        val = NULL;
 
347
    }
 
348
 
 
349
    val = (Conf::ScalarNode *) (map->getValue (codecsKey));
 
350
 
 
351
    if (val) {
 
352
        _codecStr = val->getValue();
 
353
        val = NULL;
 
354
    }
 
355
 
 
356
    val = (Conf::ScalarNode *) (map->getValue (ringtonePathKey));
 
357
 
 
358
    if (val) {
 
359
        _ringtonePath = val->getValue();
 
360
        val = NULL;
 
361
    }
 
362
 
 
363
    val = (Conf::ScalarNode *) (map->getValue (ringtoneEnabledKey));
 
364
 
 
365
    if (val) {
 
366
        _ringtoneEnabled = (val->getValue() == "true") ? true : false;
 
367
        val = NULL;
 
368
    }
 
369
 
 
370
    val = (Conf::ScalarNode *) (map->getValue (expireKey));
 
371
 
 
372
    if (val) {
 
373
        _registrationExpire = val->getValue();
 
374
        val = NULL;
 
375
    }
 
376
 
 
377
    val = (Conf::ScalarNode *) (map->getValue (interfaceKey));
 
378
 
 
379
    if (val) {
 
380
        _interface = val->getValue();
 
381
        val = NULL;
 
382
    }
 
383
 
 
384
    val = (Conf::ScalarNode *) (map->getValue (portKey));
 
385
 
 
386
    if (val) {
 
387
        _localPort = atoi (val->getValue().data());
 
388
        val = NULL;
 
389
    }
 
390
 
 
391
    val = (Conf::ScalarNode *) (map->getValue (publishAddrKey));
 
392
 
 
393
    if (val) {
 
394
        _publishedIpAddress = val->getValue();
 
395
        val = NULL;
 
396
    }
 
397
 
 
398
    val = (Conf::ScalarNode *) (map->getValue (publishPortKey));
 
399
 
 
400
    if (val) {
 
401
        _publishedPort = atoi (val->getValue().data());
 
402
        val = NULL;
 
403
    }
 
404
 
 
405
    val = (Conf::ScalarNode *) (map->getValue (sameasLocalKey));
 
406
 
 
407
    if (val) {
 
408
        _publishedSameasLocal = (val->getValue().compare ("true") == 0) ? true : false;
 
409
        val = NULL;
 
410
    }
 
411
 
 
412
    val = (Conf::ScalarNode *) (map->getValue (resolveOnceKey));
 
413
 
 
414
    if (val) {
 
415
        _resolveOnce = (val->getValue().compare ("true") == 0) ? true : false;
 
416
        val = NULL;
 
417
    }
 
418
 
 
419
    val = (Conf::ScalarNode *) (map->getValue (dtmfTypeKey));
 
420
 
 
421
    if (val) {
 
422
        _dtmfType = (val->getValue() == "overrtp") ? OVERRTP : SIPINFO;
 
423
        val = NULL;
 
424
    }
 
425
 
 
426
    // _dtmfType = atoi(val->getValue();
 
427
    val = (Conf::ScalarNode *) (map->getValue (serviceRouteKey));
 
428
 
 
429
    if (val) {
 
430
        _serviceRoute = val->getValue();
 
431
        val = NULL;
 
432
    }
 
433
 
 
434
    // stun enabled
 
435
    val = (Conf::ScalarNode *) (map->getValue (stunEnabledKey));
 
436
 
 
437
    if (val) {
 
438
        _stunEnabled = (val->getValue().compare ("true") == 0) ? true : false;
 
439
        val = NULL;
 
440
    }
 
441
 
 
442
    val = (Conf::ScalarNode *) (map->getValue (stunServerKey));
 
443
 
 
444
    if (val) {
 
445
        _stunServer = val->getValue();
 
446
        val = NULL;
 
447
    }
 
448
 
 
449
    // Init stun server name with default server name
 
450
    _stunServerName = pj_str ( (char*) _stunServer.data());
 
451
 
 
452
    credMap = (Conf::MappingNode *) (map->getValue (credKey));
 
453
 
 
454
    if (credMap)
 
455
        credentials.unserialize (credMap);
 
456
 
 
457
    val = (Conf::ScalarNode *) (map->getValue (displayNameKey));
 
458
 
 
459
    if (val) {
 
460
        _displayName = val->getValue();
 
461
        val = NULL;
 
462
    }
 
463
 
 
464
    // get srtp submap
 
465
    srtpMap = (Conf::MappingNode *) (map->getValue (srtpKey));
 
466
 
 
467
    if (!srtpMap)
 
468
        throw SipAccountException (" did not found srtp map");
 
469
 
 
470
    val = (Conf::ScalarNode *) (srtpMap->getValue (srtpEnableKey));
 
471
 
 
472
    if (val) {
 
473
        _srtpEnabled = (val->getValue().compare ("true") == 0) ? true : false;
 
474
        val = NULL;
 
475
    }
 
476
 
 
477
    val = (Conf::ScalarNode *) (srtpMap->getValue (keyExchangeKey));
 
478
 
 
479
    if (val) {
 
480
        _srtpKeyExchange = val->getValue();
 
481
        val = NULL;
 
482
    }
 
483
 
 
484
    val = (Conf::ScalarNode *) (srtpMap->getValue (rtpFallbackKey));
 
485
 
 
486
    if (val) {
 
487
        _srtpFallback = (val->getValue().compare ("true") == 0) ? true : false;
 
488
        val = NULL;
 
489
    }
 
490
 
 
491
    // get zrtp submap
 
492
    zrtpMap = (Conf::MappingNode *) (map->getValue (zrtpKey));
 
493
 
 
494
    if (!zrtpMap)
 
495
        throw SipAccountException (" did not found zrtp map");
 
496
 
 
497
    val = (Conf::ScalarNode *) (zrtpMap->getValue (displaySasKey));
 
498
 
 
499
    if (val) {
 
500
        _zrtpDisplaySas = (val->getValue().compare ("true") == 0) ? true : false;
 
501
        val = NULL;
 
502
    }
 
503
 
 
504
    val = (Conf::ScalarNode *) (zrtpMap->getValue (displaySasOnceKey));
 
505
 
 
506
    if (val) {
 
507
        _zrtpDisplaySasOnce = (val->getValue().compare ("true") == 0) ? true : false;
 
508
        val = NULL;
 
509
    }
 
510
 
 
511
    val = (Conf::ScalarNode *) (zrtpMap->getValue (helloHashEnabledKey));
 
512
 
 
513
    if (val) {
 
514
        _zrtpHelloHash = (val->getValue().compare ("true") == 0) ? true : false;
 
515
        val = NULL;
 
516
    }
 
517
 
 
518
    val = (Conf::ScalarNode *) (zrtpMap->getValue (notSuppWarningKey));
 
519
 
 
520
    if (val) {
 
521
        _zrtpNotSuppWarning = (val->getValue().compare ("true") == 0) ? true : false;
 
522
        val = NULL;
 
523
    }
 
524
 
 
525
    // get tls submap
 
526
    tlsMap = (Conf::MappingNode *) (map->getValue (tlsKey));
 
527
 
 
528
    if (!tlsMap)
 
529
        throw SipAccountException (" did not found tls map");
 
530
 
 
531
    val = (Conf::ScalarNode *) (tlsMap->getValue (tlsEnableKey));
 
532
 
 
533
    if (val) {
 
534
        _tlsEnable = val->getValue();
 
535
        val = NULL;
 
536
    }
 
537
 
 
538
    val = (Conf::ScalarNode *) (tlsMap->getValue (tlsPortKey));
 
539
 
 
540
    if (val) {
 
541
        _tlsPortStr = val->getValue();
 
542
        val = NULL;
 
543
    }
 
544
 
 
545
    val = (Conf::ScalarNode *) (tlsMap->getValue (certificateKey));
 
546
 
 
547
    if (val) {
 
548
        _tlsCertificateFile = val->getValue();
 
549
        val = NULL;
 
550
    }
 
551
 
 
552
    val = (Conf::ScalarNode *) (tlsMap->getValue (calistKey));
 
553
 
 
554
    if (val) {
 
555
        _tlsCaListFile = val->getValue();
 
556
        val = NULL;
 
557
    }
 
558
 
 
559
    val = (Conf::ScalarNode *) (tlsMap->getValue (ciphersKey));
 
560
 
 
561
    if (val) {
 
562
        _tlsCiphers = val->getValue();
 
563
        val = NULL;
 
564
    }
 
565
 
 
566
    val = (Conf::ScalarNode *) (tlsMap->getValue (methodKey));
 
567
 
 
568
    if (val) {
 
569
        _tlsMethod = val->getValue();
 
570
        val = NULL;
 
571
    }
 
572
 
 
573
    val = (Conf::ScalarNode *) (tlsMap->getValue (timeoutKey));
 
574
 
 
575
    if (val) _tlsNegotiationTimeoutSec = val->getValue();
 
576
 
 
577
    if (val) {
 
578
        _tlsNegotiationTimeoutMsec = val->getValue();
 
579
        val=NULL;
 
580
    }
 
581
 
 
582
    val = (Conf::ScalarNode *) (tlsMap->getValue (tlsPasswordKey));
 
583
 
 
584
    if (val) {
 
585
        _tlsPassword = val->getValue();
 
586
        val = NULL;
 
587
    }
 
588
 
 
589
    val = (Conf::ScalarNode *) (tlsMap->getValue (privateKeyKey));
 
590
 
 
591
    if (val) {
 
592
        _tlsPrivateKeyFile = val->getValue();
 
593
        val = NULL;
 
594
    }
 
595
 
 
596
    val = (Conf::ScalarNode *) (tlsMap->getValue (requireCertifKey));
 
597
 
 
598
    if (val) {
 
599
        _tlsRequireClientCertificate = (val->getValue().compare ("true") == 0) ? true : false;
 
600
        val = NULL;
 
601
    }
 
602
 
 
603
    val = (Conf::ScalarNode *) (tlsMap->getValue (serverKey));
 
604
 
 
605
    if (val) {
 
606
        _tlsServerName = val->getValue();
 
607
        val = NULL;
 
608
    }
 
609
 
 
610
    val = (Conf::ScalarNode *) (tlsMap->getValue (verifyClientKey));
 
611
 
 
612
    if (val) {
 
613
        _tlsVerifyServer = (val->getValue().compare ("true") == 0) ? true : false;
 
614
        val = NULL;
 
615
    }
 
616
 
 
617
    val = (Conf::ScalarNode *) (tlsMap->getValue (verifyServerKey));
 
618
 
 
619
    if (val) {
 
620
        _tlsVerifyClient = (val->getValue().compare ("true") == 0) ? true : false;
 
621
        val = NULL;
 
622
    }
 
623
 
 
624
    Account::loadAudioCodecs();
 
625
 
 
626
}
 
627
 
 
628
 
 
629
void SIPAccount::setAccountDetails (const std::map<std::string, std::string>& details)
 
630
{
 
631
 
 
632
    std::map<std::string, std::string> map_cpy;
 
633
    std::map<std::string, std::string>::iterator iter;
 
634
 
 
635
    _debug ("SipAccount: set account details %s", _accountID.c_str());
 
636
 
 
637
    // Work on a copy
 
638
    map_cpy = details;
 
639
 
 
640
    std::string alias;
 
641
    std::string type;
 
642
    std::string hostname;
 
643
    std::string username;
 
644
    std::string password;
 
645
    std::string mailbox;
 
646
    std::string accountEnable;
 
647
    std::string ringtonePath;
 
648
    std::string ringtoneEnabled;
 
649
 
 
650
    // Account setting common to SIP and IAX
 
651
    find_in_map (CONFIG_ACCOUNT_ALIAS, alias)
 
652
    find_in_map (CONFIG_ACCOUNT_TYPE, type)
 
653
    find_in_map (HOSTNAME, hostname)
 
654
    find_in_map (USERNAME, username)
 
655
    find_in_map (PASSWORD, password)
 
656
    find_in_map (CONFIG_ACCOUNT_MAILBOX, mailbox);
 
657
    find_in_map (CONFIG_ACCOUNT_ENABLE, accountEnable);
 
658
    find_in_map (CONFIG_RINGTONE_PATH, ringtonePath);
 
659
    find_in_map (CONFIG_RINGTONE_ENABLED, ringtoneEnabled);
 
660
 
 
661
    setAlias (alias);
 
662
    setType (type);
 
663
    setUsername (username);
 
664
    setHostname (hostname);
 
665
    setPassword (password);
 
666
    setEnabled ( (accountEnable == "true"));
 
667
    setRingtonePath (ringtonePath);
 
668
    setRingtoneEnabled ( (ringtoneEnabled == "true"));
 
669
    setMailBox (mailbox);
 
670
 
 
671
    // SIP specific account settings
 
672
    if (getType() == "SIP") {
 
673
 
 
674
        std::string ua_name;
 
675
        std::string realm;
 
676
        std::string routeset;
 
677
        std::string authenticationName;
 
678
 
 
679
        std::string resolveOnce;
 
680
        std::string registrationExpire;
 
681
 
 
682
        std::string displayName;
 
683
        std::string localInterface;
 
684
        std::string publishedSameasLocal;
 
685
        std::string localAddress;
 
686
        std::string publishedAddress;
 
687
        std::string localPort;
 
688
        std::string publishedPort;
 
689
        std::string stunEnable;
 
690
        std::string stunServer;
 
691
        std::string dtmfType;
 
692
        std::string srtpEnable;
 
693
        std::string srtpRtpFallback;
 
694
        std::string zrtpDisplaySas;
 
695
        std::string zrtpDisplaySasOnce;
 
696
        std::string zrtpNotSuppWarning;
 
697
        std::string zrtpHelloHash;
 
698
        std::string srtpKeyExchange;
 
699
 
 
700
        std::string tlsListenerPort;
 
701
        std::string tlsEnable;
 
702
        std::string tlsCaListFile;
 
703
        std::string tlsCertificateFile;
 
704
        std::string tlsPrivateKeyFile;
 
705
        std::string tlsPassword;
 
706
        std::string tlsMethod;
 
707
        std::string tlsCiphers;
 
708
        std::string tlsServerName;
 
709
        std::string tlsVerifyServer;
 
710
        std::string tlsVerifyClient;
 
711
        std::string tlsRequireClientCertificate;
 
712
        std::string tlsNegotiationTimeoutSec;
 
713
        std::string tlsNegotiationTimeoutMsec;
 
714
 
 
715
        // general sip settings
 
716
        find_in_map (DISPLAY_NAME, displayName)
 
717
        find_in_map (ROUTESET, routeset)
 
718
        find_in_map (LOCAL_INTERFACE, localInterface)
 
719
        find_in_map (PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal)
 
720
        find_in_map (PUBLISHED_ADDRESS, publishedAddress)
 
721
        find_in_map (LOCAL_PORT, localPort)
 
722
        find_in_map (PUBLISHED_PORT, publishedPort)
 
723
        find_in_map (STUN_ENABLE, stunEnable)
 
724
        find_in_map (STUN_SERVER, stunServer)
 
725
        find_in_map (ACCOUNT_DTMF_TYPE, dtmfType)
 
726
        find_in_map (CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce)
 
727
        find_in_map (CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire)
 
728
 
 
729
        setDisplayName (displayName);
 
730
        setServiceRoute (routeset);
 
731
        setLocalInterface (localInterface);
 
732
        setPublishedSameasLocal ( (publishedSameasLocal.compare ("true") == 0) ? true : false);
 
733
        setPublishedAddress (publishedAddress);
 
734
        setLocalPort (atoi (localPort.data()));
 
735
        setPublishedPort (atoi (publishedPort.data()));
 
736
        setStunServer (stunServer);
 
737
        setStunEnabled ( (stunEnable == "true"));
 
738
        setDtmfType ( (dtmfType == "overrtp") ? OVERRTP : SIPINFO);
 
739
 
 
740
        setResolveOnce ( (resolveOnce.compare ("true") ==0) ? true : false);
 
741
        setRegistrationExpire (registrationExpire);
 
742
 
 
743
        // sip credential
 
744
        find_in_map (REALM, realm)
 
745
        find_in_map (AUTHENTICATION_USERNAME, authenticationName)
 
746
        find_in_map (USERAGENT, ua_name)
 
747
 
 
748
        setUseragent (ua_name);
 
749
 
 
750
        // srtp settings
 
751
        find_in_map (SRTP_ENABLE, srtpEnable)
 
752
        find_in_map (SRTP_RTP_FALLBACK, srtpRtpFallback)
 
753
        find_in_map (ZRTP_DISPLAY_SAS, zrtpDisplaySas)
 
754
        find_in_map (ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce)
 
755
        find_in_map (ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning)
 
756
        find_in_map (ZRTP_HELLO_HASH, zrtpHelloHash)
 
757
        find_in_map (SRTP_KEY_EXCHANGE, srtpKeyExchange)
 
758
 
 
759
        setSrtpEnable ( (srtpEnable.compare ("true") == 0) ? true : false);
 
760
        setSrtpFallback ( (srtpRtpFallback.compare ("true") == 0) ? true : false);
 
761
        setZrtpDisplaySas ( (zrtpDisplaySas.compare ("true") == 0) ? true : false);
 
762
        setZrtpDiaplaySasOnce ( (zrtpDisplaySasOnce.compare ("true") == 0) ? true : false);
 
763
        setZrtpNotSuppWarning ( (zrtpNotSuppWarning.compare ("true") == 0) ? true : false);
 
764
        setZrtpHelloHash ( (zrtpHelloHash.compare ("true") == 0) ? true : false);
 
765
        // sipaccount->setSrtpKeyExchange((srtpKeyExchange.compare("true") == 0) ? true : false);
 
766
        setSrtpKeyExchange (srtpKeyExchange);
 
767
 
 
768
        // TLS settings
 
769
        // The TLS listener is unique and globally defined through IP2IP_PROFILE
 
770
        if (_accountID == IP2IP_PROFILE) {
 
771
            find_in_map (TLS_LISTENER_PORT, tlsListenerPort)
 
772
        }
 
773
 
 
774
        find_in_map (TLS_ENABLE, tlsEnable)
 
775
        find_in_map (TLS_CA_LIST_FILE, tlsCaListFile)
 
776
        find_in_map (TLS_CERTIFICATE_FILE, tlsCertificateFile)
 
777
        find_in_map (TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile)
 
778
        find_in_map (TLS_PASSWORD, tlsPassword)
 
779
        find_in_map (TLS_METHOD, tlsMethod)
 
780
        find_in_map (TLS_CIPHERS, tlsCiphers)
 
781
        find_in_map (TLS_SERVER_NAME, tlsServerName)
 
782
        find_in_map (TLS_VERIFY_SERVER, tlsVerifyServer)
 
783
        find_in_map (TLS_VERIFY_CLIENT, tlsVerifyClient)
 
784
        find_in_map (TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate)
 
785
        find_in_map (TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec)
 
786
        find_in_map (TLS_NEGOTIATION_TIMEOUT_MSEC, tlsNegotiationTimeoutMsec)
 
787
 
 
788
        if (_accountID == IP2IP_PROFILE) {
 
789
            setTlsListenerPort (atoi (tlsListenerPort.data()));
 
790
        }
 
791
 
 
792
        setTlsEnable (tlsEnable);
 
793
        setTlsCaListFile (tlsCaListFile);
 
794
        setTlsCertificateFile (tlsCertificateFile);
 
795
        setTlsPrivateKeyFile (tlsPrivateKeyFile);
 
796
        setTlsPassword (tlsPassword);
 
797
        setTlsMethod (tlsMethod);
 
798
        setTlsCiphers (tlsCiphers);
 
799
        setTlsServerName (tlsServerName);
 
800
        setTlsVerifyServer (tlsVerifyServer.compare ("true") ? true : false);
 
801
        setTlsVerifyClient (tlsVerifyServer.compare ("true") ? true : false);
 
802
        setTlsRequireClientCertificate (tlsRequireClientCertificate.compare ("true") ? true : false);
 
803
        setTlsNegotiationTimeoutSec (tlsNegotiationTimeoutSec);
 
804
        setTlsNegotiationTimeoutMsec (tlsNegotiationTimeoutMsec);
 
805
 
 
806
        if (!Manager::instance().preferences.getMd5Hash()) {
 
807
            setPassword (password);
 
808
        } else {
 
809
            // Make sure not to re-hash the password field if
 
810
            // it is already saved as a MD5 Hash.
 
811
            // TODO: This test is weak. Fix this.
 
812
            if ( (password.compare (getPassword()) != 0)) {
 
813
                _debug ("SipAccount: Password sent and password from config are different. Re-hashing");
 
814
                std::string hash;
 
815
 
 
816
                if (authenticationName.empty()) {
 
817
                    hash = Manager::instance().computeMd5HashFromCredential (username, password, realm);
 
818
                } else {
 
819
                    hash = Manager::instance().computeMd5HashFromCredential (authenticationName, password, realm);
 
820
                }
 
821
 
 
822
                setPassword (hash);
 
823
            }
 
824
        }
 
825
    }
 
826
}
 
827
 
 
828
std::map<std::string, std::string> SIPAccount::getAccountDetails()
 
829
{
 
830
    _debug ("SipAccount: get account details %s", _accountID.c_str());
 
831
 
 
832
    std::map<std::string, std::string> a;
 
833
 
 
834
    a.insert (std::pair<std::string, std::string> (ACCOUNT_ID, _accountID));
 
835
    // The IP profile does not allow to set an alias
 
836
    (_accountID == IP2IP_PROFILE) ?
 
837
    a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, IP2IP_PROFILE)) :
 
838
    a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, getAlias()));
 
839
 
 
840
    a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, isEnabled() ? "true" : "false"));
 
841
    a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, getType()));
 
842
    a.insert (std::pair<std::string, std::string> (HOSTNAME, getHostname()));
 
843
    a.insert (std::pair<std::string, std::string> (USERNAME, getUsername()));
 
844
    a.insert (std::pair<std::string, std::string> (PASSWORD, getPassword()));
 
845
 
 
846
    a.insert (std::pair<std::string, std::string> (CONFIG_RINGTONE_PATH, getRingtonePath()));
 
847
    a.insert (std::pair<std::string, std::string> (CONFIG_RINGTONE_ENABLED, getRingtoneEnabled() ? "true" : "false"));
 
848
 
 
849
    a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_MAILBOX, getMailBox()));
 
850
 
 
851
 
 
852
    RegistrationState state = Unregistered;
 
853
    std::string registrationStateCode;
 
854
    std::string registrationStateDescription;
 
855
 
 
856
 
 
857
    if (_accountID == IP2IP_PROFILE) {
 
858
        registrationStateCode = EMPTY_FIELD;
 
859
        registrationStateDescription = "Direct IP call";
 
860
    } else {
 
861
        state = getRegistrationState();
 
862
        int code = getRegistrationStateDetailed().first;
 
863
        std::stringstream out;
 
864
        out << code;
 
865
        registrationStateCode = out.str();
 
866
        registrationStateDescription = getRegistrationStateDetailed().second;
 
867
    }
 
868
 
 
869
 
 
870
    (_accountID == IP2IP_PROFILE) ?
 
871
    a.insert (std::pair<std::string, std::string> (REGISTRATION_STATUS, "READY")) :
 
872
    a.insert (std::pair<std::string, std::string> (REGISTRATION_STATUS, Manager::instance().mapStateNumberToString (state)));
 
873
 
 
874
    a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_CODE, registrationStateCode));
 
875
    a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_DESCRIPTION, registrationStateDescription));
 
876
 
 
877
 
 
878
    // Add sip specific details
 
879
    if (getType() == "SIP") {
 
880
 
 
881
        a.insert (std::pair<std::string, std::string> (ROUTESET, getServiceRoute()));
 
882
        a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_RESOLVE_ONCE, isResolveOnce() ? "true" : "false"));
 
883
        a.insert (std::pair<std::string, std::string> (REALM, _realm));
 
884
        a.insert (std::pair<std::string, std::string> (USERAGENT, getUseragent()));
 
885
 
 
886
        a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getRegistrationExpire()));
 
887
        a.insert (std::pair<std::string, std::string> (LOCAL_INTERFACE, getLocalInterface()));
 
888
        a.insert (std::pair<std::string, std::string> (PUBLISHED_SAMEAS_LOCAL, getPublishedSameasLocal() ? "true" : "false"));
 
889
        a.insert (std::pair<std::string, std::string> (PUBLISHED_ADDRESS, getPublishedAddress()));
 
890
 
 
891
        std::stringstream localport;
 
892
        localport << getLocalPort();
 
893
        a.insert (std::pair<std::string, std::string> (LOCAL_PORT, localport.str()));
 
894
        std::stringstream publishedport;
 
895
        publishedport << getPublishedPort();
 
896
        a.insert (std::pair<std::string, std::string> (PUBLISHED_PORT, publishedport.str()));
 
897
        a.insert (std::pair<std::string, std::string> (STUN_ENABLE, isStunEnabled() ? "true" : "false"));
 
898
        a.insert (std::pair<std::string, std::string> (STUN_SERVER, getStunServer()));
 
899
        a.insert (std::pair<std::string, std::string> (ACCOUNT_DTMF_TYPE, (getDtmfType() == OVERRTP) ? "overrtp" : "sipinfo"));
 
900
 
 
901
        a.insert (std::pair<std::string, std::string> (SRTP_KEY_EXCHANGE, getSrtpKeyExchange()));
 
902
        a.insert (std::pair<std::string, std::string> (SRTP_ENABLE, getSrtpEnable() ? "true" : "false"));
 
903
        a.insert (std::pair<std::string, std::string> (SRTP_RTP_FALLBACK, getSrtpFallback() ? "true" : "false"));
 
904
 
 
905
        a.insert (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS, getZrtpDisplaySas() ? "true" : "false"));
 
906
        a.insert (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, getZrtpDiaplaySasOnce() ? "true" : "false"));
 
907
        a.insert (std::pair<std::string, std::string> (ZRTP_HELLO_HASH, getZrtpHelloHash() ? "true" : "false"));
 
908
        a.insert (std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, getZrtpNotSuppWarning() ? "true" : "false"));
 
909
 
 
910
        // TLS listener is unique and parameters are modified through IP2IP_PROFILE
 
911
        std::stringstream tlslistenerport;
 
912
        tlslistenerport << getTlsListenerPort();
 
913
        a.insert (std::pair<std::string, std::string> (TLS_LISTENER_PORT, tlslistenerport.str()));
 
914
        a.insert (std::pair<std::string, std::string> (TLS_ENABLE, getTlsEnable()));
 
915
        a.insert (std::pair<std::string, std::string> (TLS_CA_LIST_FILE, getTlsCaListFile()));
 
916
        a.insert (std::pair<std::string, std::string> (TLS_CERTIFICATE_FILE, getTlsCertificateFile()));
 
917
        a.insert (std::pair<std::string, std::string> (TLS_PRIVATE_KEY_FILE, getTlsPrivateKeyFile()));
 
918
        a.insert (std::pair<std::string, std::string> (TLS_PASSWORD, getTlsPassword()));
 
919
        a.insert (std::pair<std::string, std::string> (TLS_METHOD, getTlsMethod()));
 
920
        a.insert (std::pair<std::string, std::string> (TLS_CIPHERS, getTlsCiphers()));
 
921
        a.insert (std::pair<std::string, std::string> (TLS_SERVER_NAME, getTlsServerName()));
 
922
        a.insert (std::pair<std::string, std::string> (TLS_VERIFY_SERVER, getTlsVerifyServer() ? "true" : "false"));
 
923
        a.insert (std::pair<std::string, std::string> (TLS_VERIFY_CLIENT, getTlsVerifyClient() ? "true" : "false"));
 
924
        a.insert (std::pair<std::string, std::string> (TLS_REQUIRE_CLIENT_CERTIFICATE, getTlsRequireClientCertificate() ? "true" : "false"));
 
925
        a.insert (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_SEC, getTlsNegotiationTimeoutSec()));
 
926
        a.insert (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_MSEC, getTlsNegotiationTimeoutMsec()));
 
927
 
 
928
    }
 
929
 
 
930
    return a;
 
931
 
 
932
}
 
933
 
81
934
 
82
935
// void SIPAccount::setVoIPLink(VoIPLink *link) {
83
 
void SIPAccount::setVoIPLink() {
 
936
void SIPAccount::setVoIPLink()
 
937
{
84
938
 
85
939
    _link = SIPVoIPLink::instance ("");
86
940
    dynamic_cast<SIPVoIPLink*> (_link)->incrementClients();
90
944
 
91
945
int SIPAccount::initCredential (void)
92
946
{
93
 
    int credentialCount = 0;
94
 
    credentialCount = Manager::instance().getConfigInt (_accountID, CONFIG_CREDENTIAL_NUMBER);
95
 
    credentialCount += 1;
 
947
    _debug ("SipAccount: Init credential");
96
948
 
97
949
    bool md5HashingEnabled = false;
98
950
    int dataType = 0;
99
 
    md5HashingEnabled = Manager::instance().getConfigBool (PREFERENCES, CONFIG_MD5HASH);
 
951
    md5HashingEnabled = Manager::instance().preferences.getMd5Hash();
100
952
    std::string digest;
101
953
 
102
954
    // Create the credential array
103
 
    pjsip_cred_info * cred_info = (pjsip_cred_info *) malloc (sizeof (pjsip_cred_info) * (credentialCount));
 
955
    pjsip_cred_info * cred_info = (pjsip_cred_info *) malloc (sizeof (pjsip_cred_info) * (getCredentialCount()));
104
956
 
105
957
    if (cred_info == NULL) {
106
958
        _error ("SipAccount: Error: Failed to set cred_info for account %s", _accountID.c_str());
107
959
        return !SUCCESS;
108
960
    }
109
961
 
110
 
    pj_bzero (cred_info, sizeof (pjsip_cred_info) *credentialCount);
 
962
    pj_bzero (cred_info, sizeof (pjsip_cred_info) * getCredentialCount());
111
963
 
112
964
    // Use authentication username if provided
113
 
    if (!_authenticationUsername.empty()) {
 
965
    if (!_authenticationUsername.empty())
114
966
        cred_info[0].username = pj_str (strdup (_authenticationUsername.c_str()));
115
 
    } else {
 
967
    else
116
968
        cred_info[0].username = pj_str (strdup (_username.c_str()));
117
 
    }
118
969
 
119
970
    // Set password
120
971
    cred_info[0].data =  pj_str (strdup (_password.c_str()));
134
985
 
135
986
    // Set the datatype
136
987
    cred_info[0].data_type = dataType;
137
 
    
 
988
 
138
989
    // Set the secheme
139
990
    cred_info[0].scheme = pj_str ( (char*) "digest");
140
991
 
141
992
    int i;
142
993
 
143
 
    for (i = 1; i < credentialCount; i++) {
144
 
        std::string credentialIndex;
145
 
        std::stringstream streamOut;
146
 
        streamOut << i - 1;
147
 
        credentialIndex = streamOut.str();
148
 
 
149
 
        std::string section = std::string ("Credential") + std::string (":") + _accountID + std::string (":") + credentialIndex;
150
 
 
151
 
        std::string username = Manager::instance().getConfigString (section, USERNAME);
152
 
        std::string password = Manager::instance().getConfigString (section, PASSWORD);
153
 
        std::string realm = Manager::instance().getConfigString (section, REALM);
 
994
    // Default credential already initialized, use credentials.getCredentialCount()
 
995
    for (i = 0; i < credentials.getCredentialCount(); i++) {
 
996
 
 
997
        std::string username = _username;
 
998
        std::string password = _password;
 
999
        std::string realm = _realm;
154
1000
 
155
1001
        cred_info[i].username = pj_str (strdup (username.c_str()));
156
1002
        cred_info[i].data = pj_str (strdup (password.c_str()));
174
1020
        _debug ("Setting credential %d realm = %s passwd = %s username = %s data_type = %d", i, realm.c_str(), password.c_str(), username.c_str(), cred_info[i].data_type);
175
1021
    }
176
1022
 
177
 
    _credentialCount = credentialCount;
178
 
 
179
1023
    _cred = cred_info;
180
1024
 
181
1025
    return SUCCESS;
184
1028
 
185
1029
int SIPAccount::registerVoIPLink()
186
1030
{
187
 
    _debug ("Register account %s", getAccountID().c_str());
 
1031
    _debug ("Account: Register account %s", getAccountID().c_str());
188
1032
 
189
1033
    // Init general settings
190
 
    loadConfig();
 
1034
    // loadConfig();
191
1035
 
192
1036
    if (_hostname.length() >= PJ_MAX_HOSTNAME) {
193
1037
        return !SUCCESS;
197
1041
    initCredential();
198
1042
 
199
1043
    // Init TLS settings if the user wants to use TLS
200
 
    bool tlsEnabled = Manager::instance().getConfigBool (_accountID, TLS_ENABLE);
201
 
 
202
 
    if (tlsEnabled) {
 
1044
    if (_tlsEnable == "true") {
 
1045
        _debug ("Account: TLS is ennabled for accounr %s", getAccountID().c_str());
203
1046
        _transportType = PJSIP_TRANSPORT_TLS;
204
1047
        initTlsConfiguration();
205
1048
    }
206
1049
 
207
1050
    // Init STUN settings for this account if the user selected it
208
 
    bool stunEnabled = Manager::instance().getConfigBool (_accountID, STUN_ENABLE);
209
1051
 
210
 
    if (stunEnabled) {
 
1052
    if (_stunEnabled) {
211
1053
        _transportType = PJSIP_TRANSPORT_START_OTHER;
212
1054
        initStunConfiguration ();
 
1055
    } else {
 
1056
        _stunServerName = pj_str ( (char*) _stunServer.data());
213
1057
    }
214
1058
 
215
1059
    // In our definition of the
266
1110
 
267
1111
void SIPAccount::initTlsConfiguration (void)
268
1112
{
 
1113
    _debug ("SipAccount: Init TLS configuration");
 
1114
 
269
1115
    /*
270
1116
     * Initialize structure to zero
271
1117
     */
275
1121
    }
276
1122
 
277
1123
    // TLS listener is unique and should be only modified through IP2IP_PROFILE
278
 
    std::string tlsPortStr = Manager::instance().getConfigString(_accountID, TLS_LISTENER_PORT);
279
 
    setTlsListenerPort(atoi(tlsPortStr.c_str()));
280
 
    
 
1124
 
 
1125
    // setTlsListenerPort(atoi(tlsPortStr.c_str()));
 
1126
    setTlsListenerPort (atoi (_tlsPortStr.c_str()));
 
1127
 
281
1128
    _tlsSetting = (pjsip_tls_setting *) malloc (sizeof (pjsip_tls_setting));
282
1129
 
283
1130
    assert (_tlsSetting);
284
1131
 
285
1132
    pjsip_tls_setting_default (_tlsSetting);
286
1133
 
287
 
    std::string tlsCaListFile = Manager::instance().getConfigString (_accountID, TLS_CA_LIST_FILE);
288
 
    std::string tlsCertificateFile = Manager::instance().getConfigString (_accountID, TLS_CERTIFICATE_FILE);
289
 
    std::string tlsPrivateKeyFile = Manager::instance().getConfigString (_accountID, TLS_PRIVATE_KEY_FILE);
290
 
    std::string tlsPassword = Manager::instance().getConfigString (_accountID, TLS_PASSWORD);
291
 
    std::string tlsMethod = Manager::instance().getConfigString (_accountID, TLS_METHOD);
292
 
    std::string tlsCiphers = Manager::instance().getConfigString (_accountID, TLS_CIPHERS);
293
 
    std::string tlsServerName = Manager::instance().getConfigString (_accountID, TLS_SERVER_NAME);
294
 
    bool tlsVerifyServer = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_SERVER);
295
 
    bool tlsVerifyClient = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_CLIENT);
296
 
    bool tlsRequireClientCertificate = Manager::instance().getConfigBool (_accountID, TLS_REQUIRE_CLIENT_CERTIFICATE);
297
 
    std::string tlsNegotiationTimeoutSec = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_SEC);
298
 
    std::string tlsNegotiationTimeoutMsec = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_MSEC);
299
 
 
300
 
    pj_cstr (&_tlsSetting->ca_list_file, tlsCaListFile.c_str());
301
 
    pj_cstr (&_tlsSetting->cert_file, tlsCertificateFile.c_str());
302
 
    pj_cstr (&_tlsSetting->privkey_file, tlsPrivateKeyFile.c_str());
303
 
    pj_cstr (&_tlsSetting->password, tlsPassword.c_str());
304
 
    _tlsSetting->method = sslMethodStringToPjEnum (tlsMethod);
305
 
    pj_cstr (&_tlsSetting->ciphers, tlsCiphers.c_str());
306
 
    pj_cstr (&_tlsSetting->server_name, tlsServerName.c_str());
307
 
 
308
 
    _tlsSetting->verify_server = (tlsVerifyServer == true) ? PJ_TRUE: PJ_FALSE;
309
 
    _tlsSetting->verify_client = (tlsVerifyClient == true) ? PJ_TRUE: PJ_FALSE;
310
 
    _tlsSetting->require_client_cert = (tlsRequireClientCertificate == true) ? PJ_TRUE: PJ_FALSE;
311
 
 
312
 
    _tlsSetting->timeout.sec = atol (tlsNegotiationTimeoutSec.c_str());
313
 
    _tlsSetting->timeout.msec = atol (tlsNegotiationTimeoutMsec.c_str());
 
1134
    pj_cstr (&_tlsSetting->ca_list_file, _tlsCaListFile.c_str());
 
1135
    pj_cstr (&_tlsSetting->cert_file, _tlsCertificateFile.c_str());
 
1136
    pj_cstr (&_tlsSetting->privkey_file, _tlsPrivateKeyFile.c_str());
 
1137
    pj_cstr (&_tlsSetting->password, _tlsPassword.c_str());
 
1138
    _tlsSetting->method = sslMethodStringToPjEnum (_tlsMethod);
 
1139
    pj_cstr (&_tlsSetting->ciphers, _tlsCiphers.c_str());
 
1140
    pj_cstr (&_tlsSetting->server_name, _tlsServerName.c_str());
 
1141
 
 
1142
    _tlsSetting->verify_server = (_tlsVerifyServer == true) ? PJ_TRUE: PJ_FALSE;
 
1143
    _tlsSetting->verify_client = (_tlsVerifyClient == true) ? PJ_TRUE: PJ_FALSE;
 
1144
    _tlsSetting->require_client_cert = (_tlsRequireClientCertificate == true) ? PJ_TRUE: PJ_FALSE;
 
1145
 
 
1146
    _tlsSetting->timeout.sec = atol (_tlsNegotiationTimeoutSec.c_str());
 
1147
    _tlsSetting->timeout.msec = atol (_tlsNegotiationTimeoutMsec.c_str());
314
1148
 
315
1149
}
316
1150
 
319
1153
    size_t pos;
320
1154
    std::string stunServer, serverName, serverPort;
321
1155
 
322
 
    stunServer = Manager::instance().getConfigString (_accountID, STUN_SERVER);
323
 
 
 
1156
    stunServer = _stunServer;
324
1157
    // Init STUN socket
325
1158
    pos = stunServer.find (':');
326
1159
 
339
1172
 
340
1173
void SIPAccount::loadConfig()
341
1174
{
342
 
    // Load primary credential
343
 
    setUsername (Manager::instance().getConfigString (_accountID, USERNAME));
344
 
    setRouteSet(Manager::instance().getConfigString(_accountID, ROUTESET));
345
 
    setPassword (Manager::instance().getConfigString (_accountID, PASSWORD));
346
 
    _authenticationUsername = Manager::instance().getConfigString (_accountID, AUTHENTICATION_USERNAME);
347
 
    _realm = Manager::instance().getConfigString (_accountID, REALM);
348
 
    _resolveOnce = Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_RESOLVE_ONCE) == "1" ? true : false;
349
 
 
350
 
    // Load general account settings
351
 
    setHostname (Manager::instance().getConfigString (_accountID, HOSTNAME));
352
 
 
353
 
    if (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE).empty()) {
 
1175
    if (_registrationExpire.empty())
354
1176
        _registrationExpire = DFT_EXPIRE_VALUE;
355
 
    } else {
356
 
        _registrationExpire = Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE);
357
 
    }
358
 
 
359
 
    // Load network settings
360
 
    // Local parameters
361
 
 
362
 
    // Load local interface
363
 
    setLocalInterface(Manager::instance().getConfigString (_accountID, LOCAL_INTERFACE));
364
 
 
365
 
    std::string localPort = Manager::instance().getConfigString (_accountID, LOCAL_PORT);
366
 
    setLocalPort (atoi (localPort.c_str()));
367
 
 
368
 
 
369
 
    // Published parameters
370
 
    setPublishedSameasLocal (Manager::instance().getConfigString (_accountID, PUBLISHED_SAMEAS_LOCAL) == TRUE_STR ? true : false);
371
 
 
372
 
    std::string publishedPort = Manager::instance().getConfigString (_accountID, PUBLISHED_PORT);
373
 
 
374
 
    setPublishedPort (atoi (publishedPort.c_str()));
375
 
 
376
 
    setPublishedAddress (Manager::instance().getConfigString (_accountID, PUBLISHED_ADDRESS));
377
 
 
378
 
    if(Manager::instance().getConfigString (_accountID, ACCOUNT_DTMF_TYPE) == OVERRTPSTR)
379
 
        _dtmfType = OVERRTP;
380
 
        else
381
 
                _dtmfType = SIPINFO;
382
 
 
383
 
    // Init TLS settings if the user wants to use TLS
384
 
    bool tlsEnabled = Manager::instance().getConfigBool (_accountID, TLS_ENABLE);
385
 
 
386
 
    if (tlsEnabled) {
 
1177
 
 
1178
    if (_tlsEnable == "true") {
387
1179
        initTlsConfiguration();
388
1180
        _transportType = PJSIP_TRANSPORT_TLS;
389
1181
    } else {
436
1228
    return username;
437
1229
}
438
1230
 
439
 
std::string SIPAccount::getTransportMapKey(void)
 
1231
std::string SIPAccount::getTransportMapKey (void)
440
1232
{
441
 
    
 
1233
 
442
1234
    std::stringstream out;
443
1235
    out << getLocalPort();
444
1236
    std::string localPort = out.str();
474
1266
 
475
1267
    // Get machine hostname if not provided
476
1268
    if (_hostname.empty()) {
477
 
      hostname = getMachineName();
 
1269
        hostname = getMachineName();
478
1270
    }
479
1271
 
480
1272
 
515
1307
    // Check if hostname is already specified
516
1308
    if (username.find ("@") == std::string::npos) {
517
1309
        // hostname not specified
518
 
        hostname = _hostname;
 
1310
        hostname = _hostname;
519
1311
    }
520
1312
 
521
1313
    int len = pj_ansi_snprintf (uri, PJSIP_MAX_URL_SIZE,
578
1370
        transport = "";
579
1371
    }
580
1372
 
581
 
    _displayName = Manager::instance().getConfigString (_accountID, DISPLAY_NAME);
582
 
 
583
1373
    _debug ("Display Name: %s", _displayName.c_str());
584
1374
 
585
1375
    int len = pj_ansi_snprintf (contact, PJSIP_MAX_URL_SIZE,