sipaccount.h 25.6 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 4
 *
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
6
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
7 8
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
 *
yanmorin's avatar
 
yanmorin committed
9 10
 *  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
11
 *  the Free Software Foundation; either version 3 of the License, or
yanmorin's avatar
 
yanmorin committed
12
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
13
 *
yanmorin's avatar
 
yanmorin committed
14 15 16 17
 *  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
18
 *
yanmorin's avatar
 
yanmorin committed
19 20
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
22 23 24 25 26 27 28 29 30 31 32
 *
 *  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
33
 */
34

yanmorin's avatar
 
yanmorin committed
35 36 37
#ifndef SIPACCOUNT_H
#define SIPACCOUNT_H

38 39
#include <vector>
#include <map>
40

41
#include "pjsip/sip_transport_tls.h"
42
#include "pjsip/sip_types.h"
43
#include "pjsip-ua/sip_regc.h"
yanmorin's avatar
 
yanmorin committed
44

45 46
#include "noncopyable.h"
#include "account.h"
47

48 49
typedef std::vector<pj_ssl_cipher> CipherArray;

50
namespace Conf {
51 52 53
    class YamlEmitter;
    class MappingNode;
    // SIP specific configuration keys
54 55 56 57 58 59 60
    const char *const INTERFACE_KEY = "interface";
    const char *const PORT_KEY = "port";
    const char *const PUBLISH_ADDR_KEY = "publishAddr";
    const char *const PUBLISH_PORT_KEY = "publishPort";
    const char *const SAME_AS_LOCAL_KEY = "sameasLocal";
    const char *const DTMF_TYPE_KEY = "dtmfType";
    const char *const SERVICE_ROUTE_KEY = "serviceRoute";
61
    const char *const KEEP_ALIVE_ENABLED = "keepAlive";
62 63

    // TODO: write an object to store credential which implement serializable
64 65 66 67
    const char *const SRTP_KEY = "srtp";
    const char *const SRTP_ENABLE_KEY = "enable";
    const char *const KEY_EXCHANGE_KEY = "keyExchange";
    const char *const RTP_FALLBACK_KEY = "rtpFallback";
68 69

    // TODO: wirte an object to store zrtp params wich implement serializable
70 71 72 73 74
    const char *const ZRTP_KEY = "zrtp";
    const char *const DISPLAY_SAS_KEY = "displaySas";
    const char *const DISPLAY_SAS_ONCE_KEY = "displaySasOnce";
    const char *const HELLO_HASH_ENABLED_KEY = "helloHashEnabled";
    const char *const NOT_SUPP_WARNING_KEY = "notSuppWarning";
75 76

    // TODO: write an object to store tls params which implement serializable
77 78 79 80 81 82 83 84 85 86 87 88 89 90
    const char *const TLS_KEY = "tls";
    const char *const TLS_PORT_KEY = "tlsPort";
    const char *const CERTIFICATE_KEY = "certificate";
    const char *const CALIST_KEY = "calist";
    const char *const CIPHERS_KEY = "ciphers";
    const char *const TLS_ENABLE_KEY = "enable";
    const char *const METHOD_KEY = "method";
    const char *const TIMEOUT_KEY = "timeout";
    const char *const TLS_PASSWORD_KEY = "password";
    const char *const PRIVATE_KEY_KEY = "privateKey";
    const char *const REQUIRE_CERTIF_KEY = "requireCertif";
    const char *const SERVER_KEY = "server";
    const char *const VERIFY_CLIENT_KEY = "verifyClient";
    const char *const VERIFY_SERVER_KEY = "verifyServer";
91

92 93 94
    const char *const STUN_ENABLED_KEY = "stunEnabled";
    const char *const STUN_SERVER_KEY = "stunServer";
    const char *const CRED_KEY = "credential";
95 96 97 98 99 100
    const char *const AUDIO_PORT_MIN_KEY = "audioPortMin";
    const char *const AUDIO_PORT_MAX_KEY = "audioPortMax";
#ifdef SFL_VIDEO
    const char *const VIDEO_PORT_MIN_KEY = "videoPortMin";
    const char *const VIDEO_PORT_MAX_KEY = "videoPortMax";
#endif
101
}
102

Yun Liu's avatar
Yun Liu committed
103
class SIPVoIPLink;
104 105
class SIPPresence;

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
106

yanmorin's avatar
 
yanmorin committed
107
/**
108
 * @file sipaccount.h
109
 * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
110
 */
111
enum {MAX_PORT = 65536};
112
enum {HALF_MAX_PORT = MAX_PORT / 2};
113

114
class SIPAccount : public Account {
115
    public:
116
        static const char * const IP2IP_PROFILE;
117 118
        static const char * const OVERRTP_STR;
        static const char * const SIPINFO_STR;
119
        static const char * const ACCOUNT_TYPE;
120

121 122 123 124
        /**
         * Constructor
         * @param accountID The account identifier
         */
125
        SIPAccount(const std::string& accountID);
126
        ~SIPAccount();
Yun Liu's avatar
Yun Liu committed
127

128 129
        virtual VoIPLink* getVoIPLink();

130
        std::string getUserAgentName() const;
131 132 133
        void setRegistrationStateDetailed(const std::pair<int, std::string> &details) {
            registrationStateDetailed_ = details;
        }
134

135 136 137 138 139
        /**
         * Returns true if this is the IP2IP account
         */
        bool isIP2IP() const;

140 141 142
        static void
        releasePort(uint16_t port);

143 144 145 146
        /**
         * Serialize internal state of this account for configuration
         * @param YamlEmitter the configuration engine which generate the configuration file
         */
147
        virtual void serialize(Conf::YamlEmitter &emitter);
148

149 150 151 152
        /**
         * Populate the internal state for this account based on info stored in the configuration file
         * @param The configuration node for this account
         */
153
        virtual void unserialize(const Conf::YamlNode &map);
154

155 156 157 158
        /**
         * Set the internal state for this account, mainly used to manage account details from the client application.
         * @param The map containing the account information.
         */
159
        virtual void setAccountDetails(std::map<std::string, std::string> details);
160

161 162 163 164 165
        /**
         * Return an map containing the internal state of this account. Client application can use this method to manage
         * account info.
         * @return A map containing the account information.
         */
166
        virtual std::map<std::string, std::string> getAccountDetails() const;
167 168 169 170

        /**
         * Return the information for the default IP to IP account
         */
171
        std::map<std::string, std::string> getIp2IpDetails() const;
172 173 174 175 176

        /**
         * Return the TLS settings, mainly used to return security information to
         * a client application
         */
177
        std::map<std::string, std::string> getTlsSettings() const;
178 179 180 181

        /**
         * Manage the TLS settings from a client application
         */
182
        void setTlsSettings(const std::map<std::string, std::string>& details);
183

Julien Bonjean's avatar
Julien Bonjean committed
184 185
        /**
         * Actually useless, since config loading is done in init()
186 187
         */
        void loadConfig();
yanmorin's avatar
 
yanmorin committed
188

189 190
        /**
         * Initialize the SIP voip link with the account parameters and send registration
Julien Bonjean's avatar
Julien Bonjean committed
191
         */
192
        void registerVoIPLink();
193

194 195 196
        /**
         * Send unregistration and clean all related stuff ( calls , thread )
         */
197
        void unregisterVoIPLink();
198

199 200 201 202 203 204 205 206 207 208 209
        /**
         * Start the keep alive function, once started, the account will be registered periodically
         * a new REGISTER request is sent bey the client application. The account must be initially
         * registered for this call to be effective.
         */
        void startKeepAliveTimer();

        /**
         * Stop the keep alive timer. Once canceled, no further registration will be scheduled
         */
        void stopKeepAliveTimer();
210

211

212
        const pjsip_cred_info* getCredInfo() const {
213
            return cred_.data();
Julien Bonjean's avatar
Julien Bonjean committed
214 215
        }

216 217 218 219 220 221
        /**
         * Get the number of credentials defined for
         * this account.
         * @param none
         * @return int The number of credentials set for this account.
         */
222
        unsigned getCredentialCount() const {
223 224 225
            return credentials_.size();
        }

226 227 228 229
        bool hasCredentials() const {
            return not credentials_.empty();
        }

230
        void setCredentials(const std::vector<std::map<std::string, std::string> >& details);
231 232 233

        const std::vector<std::map<std::string, std::string> > &
        getCredentials() const;
234

Julien Bonjean's avatar
Julien Bonjean committed
235 236 237 238 239
        /**
         * A client sendings a REGISTER request MAY suggest an expiration
         * interval that indicates how long the client would like the
         * registration to be valid.
         *
Rafaël Carré's avatar
Rafaël Carré committed
240
         * @return the expiration value.
Julien Bonjean's avatar
Julien Bonjean committed
241
         */
242
        unsigned getRegistrationExpire() const {
243 244 245 246
            if (registrationExpire_ == 0)
                return PJSIP_REGC_EXPIRATION_NOT_SPECIFIED;

            return registrationExpire_;
Julien Bonjean's avatar
Julien Bonjean committed
247 248
        }

249
        /**
250
         * Set the expiration for this account as found in
251
         * the "Expire" sip header or the CONTACT's "expire" param.
252 253
         */
        void setRegistrationExpire(int expire) {
254
            if (expire > 0)
255 256 257
                registrationExpire_ = expire;
        }

Julien Bonjean's avatar
Julien Bonjean committed
258
        /**
259
         * Doubles the Expiration Interval sepecified for registration.
Julien Bonjean's avatar
Julien Bonjean committed
260
         */
261
        void doubleRegistrationExpire() {
262 263 264 265
            registrationExpire_ *= 2;

            if (registrationExpire_ < 0)
                registrationExpire_ = 0;
Julien Bonjean's avatar
Julien Bonjean committed
266 267
        }

268 269
        /**
         * Registration flag
270 271
	 */
        bool isRegistered() const {
272
            return bRegister_;
Julien Bonjean's avatar
Julien Bonjean committed
273
        }
274 275 276 277

	/**
         * Set registration flag
         */
278
        void setRegister(bool result) {
279
            bRegister_ = result;
Julien Bonjean's avatar
Julien Bonjean committed
280 281
        }

282 283 284 285 286 287
        /**
         * Get the registration stucture that is used
         * for PJSIP in the registration process.
         * Settings are loaded from configuration file.
         * @return pjsip_regc* A pointer to the registration structure
         */
288
        pjsip_regc* getRegistrationInfo() {
289
            return regc_;
290 291 292 293 294 295 296 297
        }

        /**
         * Set the registration structure that is used
         * for PJSIP in the registration process;
         * @pram A pointer to the new registration structure
         * @return void
         */
298
        void setRegistrationInfo(pjsip_regc *regc) {
299
            regc_ = regc;
300 301
        }

302 303
        /**
         * @return pjsip_tls_setting structure, filled from the configuration
Julien Bonjean's avatar
Julien Bonjean committed
304
         * file, that can be used directly by PJSIP to initialize
305 306
         * TLS transport.
         */
307
        pjsip_tls_setting * getTlsSetting() {
308
            return &tlsSetting_;
Julien Bonjean's avatar
Julien Bonjean committed
309 310 311
        }

        /**
312
         * @return pj_str_t , filled from the configuration
Julien Bonjean's avatar
Julien Bonjean committed
313
         * file, that can be used directly by PJSIP to initialize
314 315
         * an alternate UDP transport.
         */
316
        std::string getStunServer() const {
317
            return stunServer_;
Julien Bonjean's avatar
Julien Bonjean committed
318
        }
319
        void setStunServer(const std::string &srv) {
320
            stunServer_ = srv;
Julien Bonjean's avatar
Julien Bonjean committed
321
        }
322

323
        pj_str_t getStunServerName() const {
324
            return stunServerName_;
Julien Bonjean's avatar
Julien Bonjean committed
325
        }
326

Julien Bonjean's avatar
Julien Bonjean committed
327
        /**
328
         * @return pj_uint8_t structure, filled from the configuration
Julien Bonjean's avatar
Julien Bonjean committed
329
         * file, that can be used directly by PJSIP to initialize
330 331
         * an alternate UDP transport.
         */
332
        pj_uint16_t getStunPort() const {
333
            return stunPort_;
Julien Bonjean's avatar
Julien Bonjean committed
334 335
        }

336
        /**
Julien Bonjean's avatar
Julien Bonjean committed
337
         * @return bool Tells if current transport for that
338 339
         * account is set to TLS.
         */
340
        bool isTlsEnabled() const {
341
            return transportType_ == PJSIP_TRANSPORT_TLS;
Julien Bonjean's avatar
Julien Bonjean committed
342 343 344
        }

        /**
345 346 347
         * @return bool Tells if current transport for that
         * account is set to OTHER.
         */
348
        bool isStunEnabled() const {
349
            return stunEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
350
        }
351

352 353 354 355 356 357 358 359 360
        /*
         * @return pj_str_t "From" uri based on account information.
         * From RFC3261: "The To header field first and foremost specifies the desired
         * logical" recipient of the request, or the address-of-record of the
         * user or resource that is the target of this request. [...]  As such, it is
         * very important that the From URI not contain IP addresses or the FQDN
         * of the host on which the UA is running, since these are not logical
         * names."
         */
361
        std::string getFromUri() const;
Julien Bonjean's avatar
Julien Bonjean committed
362

363 364 365
        /*
         * This method adds the correct scheme, hostname and append
         * the ;transport= parameter at the end of the uri, in accordance with RFC3261.
366
         * It is expected that "port" is present in the internal hostname_.
367 368 369 370
         *
         * @return pj_str_t "To" uri based on @param username
         * @param username A string formatted as : "username"
         */
371
        std::string getToUri(const std::string& username) const;
372 373

        /*
Julien Bonjean's avatar
Julien Bonjean committed
374
         * In the current version of SFLPhone, "srv" uri is obtained in the preformated
375 376 377 378 379 380
         * way: hostname:port. This method adds the correct scheme and append
         * the ;transport= parameter at the end of the uri, in accordance with RFC3261.
         *
         * @return pj_str_t "server" uri based on @param hostPort
         * @param hostPort A string formatted as : "hostname:port"
         */
381
        std::string getServerUri() const;
Julien Bonjean's avatar
Julien Bonjean committed
382

383
        /**
384
         * Get the contact header for
385 386
         * @return pj_str_t The contact header based on account information
         */
387
        std::string getContactHeader() const;
388

Julien Bonjean's avatar
Julien Bonjean committed
389 390 391
        /**
         * Get the local interface name on which this account is bound.
         */
392
        std::string getLocalInterface() const {
393
            return interface_;
Julien Bonjean's avatar
Julien Bonjean committed
394
        }
395

Julien Bonjean's avatar
Julien Bonjean committed
396 397
        /**
         * Get a flag which determine the usage in sip headers of either the local
398 399
         * IP address and port (_localAddress and localPort_) or to an address set
         * manually (_publishedAddress and publishedPort_).
Julien Bonjean's avatar
Julien Bonjean committed
400
         */
401
        bool getPublishedSameasLocal() const {
402
            return publishedSameasLocal_;
Julien Bonjean's avatar
Julien Bonjean committed
403
        }
404

405 406 407 408
        /**
         * Get the port on which the transport/listener should use, or is
         * actually using.
         * @return pj_uint16 The port used for that account
Julien Bonjean's avatar
Julien Bonjean committed
409
         */
410
        pj_uint16_t getLocalPort() const {
411
            return localPort_;
Julien Bonjean's avatar
Julien Bonjean committed
412 413 414
        }

        /**
415 416 417
         * Set the new port on which this account is running over.
         * @pram port The port used by this account.
         */
418
        void setLocalPort(pj_uint16_t port) {
419
            localPort_ = port;
Julien Bonjean's avatar
Julien Bonjean committed
420 421
        }

422 423 424 425
        /**
         * Get the published port, which is the port to be advertised as the port
         * for the chosen SIP transport.
         * @return pj_uint16 The port used for that account
Julien Bonjean's avatar
Julien Bonjean committed
426
         */
427
        pj_uint16_t getPublishedPort() const {
428
            return (pj_uint16_t) publishedPort_;
Julien Bonjean's avatar
Julien Bonjean committed
429 430 431
        }

        /**
432 433 434 435
         * Set the published port, which is the port to be advertised as the port
         * for the chosen SIP transport.
         * @pram port The port used by this account.
         */
436
        void setPublishedPort(pj_uint16_t port) {
437
            publishedPort_ = port;
Julien Bonjean's avatar
Julien Bonjean committed
438
        }
439

Julien Bonjean's avatar
Julien Bonjean committed
440 441 442 443
        /**
             * Get the local port for TLS listener.
             * @return pj_uint16 The port used for that account
             */
444
        pj_uint16_t getTlsListenerPort() const {
445
            return tlsListenerPort_;
446 447
        }

448 449 450 451 452 453
        /**
         * Get the public IP address set by the user for this account.
         * If this setting is not provided, the local bound adddress
         * will be used.
         * @return std::string The public IPV4 address formatted in the standard dot notation.
         */
454
        std::string getPublishedAddress() const {
455
            return publishedIpAddress_;
Julien Bonjean's avatar
Julien Bonjean committed
456 457
        }

458 459 460 461 462
        void setPublishedAddress(const std::string &ip_addr) {
            publishedIpAddress_ = ip_addr;
        }


463
        std::string getServiceRoute() const {
464
            return serviceRoute_;
Julien Bonjean's avatar
Julien Bonjean committed
465
        }
466

467 468
        bool hasServiceRoute() const { return not serviceRoute_.empty(); }

469
        std::string getDtmfType() const {
470
            return dtmfType_;
Julien Bonjean's avatar
Julien Bonjean committed
471 472
        }

473
        bool getSrtpEnabled() const {
474
            return srtpEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
475 476
        }

477
        std::string getSrtpKeyExchange() const {
478
            return srtpKeyExchange_;
Julien Bonjean's avatar
Julien Bonjean committed
479 480
        }

481
        bool getSrtpFallback() const {
482
            return srtpFallback_;
Julien Bonjean's avatar
Julien Bonjean committed
483 484
        }

485
        bool getZrtpHelloHash() const {
486
            return zrtpHelloHash_;
Julien Bonjean's avatar
Julien Bonjean committed
487 488
        }

Tristan Matthews's avatar
Tristan Matthews committed
489
        void setReceivedParameter(const std::string &received) {
490
            receivedParameter_ = received;
491 492
            via_addr_.host.ptr = (char *) receivedParameter_.c_str();
            via_addr_.host.slen = receivedParameter_.size();
493 494
        }

Tristan Matthews's avatar
Tristan Matthews committed
495
        std::string getReceivedParameter() const {
496 497 498
            return receivedParameter_;
        }

499 500 501 502 503
        pjsip_host_port *
        getViaAddr() {
            return &via_addr_;
        }

504 505 506 507 508 509 510
        int getRPort() const {
            if (rPort_ == -1)
                return localPort_;
            else
                return rPort_;
        }

511 512 513 514
        void setRPort(int rPort) {
            rPort_ = rPort;
            via_addr_.port = rPort;
        }
515

516 517 518 519 520 521
        /**
         * Timer used to periodically send re-register request based
         * on the "Expire" sip header (or the "expire" Contact parameter)
         */
        static void keepAliveRegistrationCb(pj_timer_heap_t *th, pj_timer_entry *te);

522 523 524 525
        bool isKeepAliveEnabled() const {
            return keepAliveEnabled_;
        }

526 527 528
        /**
         * Pointer to the transport used by this acccount
         */
529
        pjsip_transport* transport_;
530

531
        /* Returns true if the username and/or hostname match this account */
532
        bool matches(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
533

534 535 536
        /**
         * Presence management
         */
537 538 539
        SIPPresence * getPresence() const;

        void enablePresence(const bool& flag);
540

541
//        unsigned generateAudioPort() const;
542
        uint16_t generateAudioPort() const;
543
#ifdef SFL_VIDEO
544
        uint16_t generateVideoPort() const;
545 546
#endif

Julien Bonjean's avatar
Julien Bonjean committed
547
    private:
548
        NON_COPYABLE(SIPAccount);
Julien Bonjean's avatar
Julien Bonjean committed
549

550
        void usePublishedAddressPortInVIA();
551
        bool fullMatch(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
552
        bool userMatch(const std::string &username) const;
553 554
        bool hostnameMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
        bool proxyMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
555

556
        /**
Tristan Matthews's avatar
Tristan Matthews committed
557
         * Map of credential for this account
558
         */
559 560
        std::vector< std::map<std::string, std::string > > credentials_;

561
#if HAVE_TLS
Tristan Matthews's avatar
Tristan Matthews committed
562
        /**
563
         * Maps a string description of the SSL method
564
         * to the corresponding enum value in pjsip_ssl_method.
Julien Bonjean's avatar
Julien Bonjean committed
565
         * @param method The string representation
566 567
         * @return pjsip_ssl_method The corresponding value in the enum
         */
568
        static pjsip_ssl_method sslMethodStringToPjEnum(const std::string& method);
Julien Bonjean's avatar
Julien Bonjean committed
569

570
        /**
571
         * Initializes tls settings from configuration file.
Julien Bonjean's avatar
Julien Bonjean committed
572
         */
573
        void initTlsConfiguration();
Julien Bonjean's avatar
Julien Bonjean committed
574

575
        /**
576 577
         * PJSIP aborts if the string length of our cipher list is too
         * great, so this function forces our cipher list to fit this constraint.
578
         */
579
        void trimCiphers();
580
#endif
581

582
        /**
Julien Bonjean's avatar
Julien Bonjean committed
583 584
         * Initializes STUN config from the config file
         */
585
        void initStunConfiguration();
Julien Bonjean's avatar
Julien Bonjean committed
586

587
        /**
Julien Bonjean's avatar
Julien Bonjean committed
588 589 590
         * If username is not provided, as it happens for Direct ip calls,
         * fetch the Real Name field of the user that is currently
         * running this program.
591
         * @return std::string The login name under which SFLPhone is running.
Julien Bonjean's avatar
Julien Bonjean committed
592
         */
593
        static std::string getLoginName();
Julien Bonjean's avatar
Julien Bonjean committed
594

595 596 597
        /**
         * The pjsip client registration information
	 */
598
        pjsip_regc *regc_;
599 600 601 602

        /**
	 * To check if the account is registered
         */
603
        bool bRegister_;
604

Tristan Matthews's avatar
Tristan Matthews committed
605
        /**
606 607
         * Network settings
         */
Rafaël Carré's avatar
Rafaël Carré committed
608
        int registrationExpire_;
609

Tristan Matthews's avatar
Tristan Matthews committed
610
        /**
611 612
         * interface name on which this account is bound
         */
613
        std::string interface_;
614

615 616 617 618
        /**
         * Flag which determine if localIpAddress_ or publishedIpAddress_ is used in
         * sip headers
         */
619
        bool publishedSameasLocal_;
Julien Bonjean's avatar
Julien Bonjean committed
620

621 622 623 624
        /**
         * Published IP address, ued only if defined by the user in account
         * configuration
         */
625
        std::string publishedIpAddress_;
Julien Bonjean's avatar
Julien Bonjean committed
626

627 628 629
        /**
         * Local port to whih this account is bound
         */
630
        pj_uint16_t localPort_;
631 632 633 634

        /**
         * Published port, used only if defined by the user
         */
635
        pj_uint16_t publishedPort_;
636

637
        /**
Tristan Matthews's avatar
Tristan Matthews committed
638
         * Optional list of SIP service this
639
         */
640
        std::string serviceRoute_;
641

642 643 644
        /**
         * The global TLS listener port which can be configured through the IP2IP_PROFILE
         */
645
        pj_uint16_t tlsListenerPort_;
Julien Bonjean's avatar
Julien Bonjean committed
646

647
        /**
648
         * Transport type used for this sip account. Currently supported types:
649 650 651
         *    PJSIP_TRANSPORT_UNSPECIFIED
         *    PJSIP_TRANSPORT_UDP
         *    PJSIP_TRANSPORT_TLS
652
         */
653
        pjsip_transport_type_e transportType_;
654

655
        /**
656
         * Credential information stored for further registration.
657
         */
658
        std::vector<pjsip_cred_info> cred_;
659

660 661 662
        /**
         * The TLS settings, used only if tls is chosen as a sip transport.
         */
663
        pjsip_tls_setting tlsSetting_;
664

665
        /**
Tristan Matthews's avatar
Tristan Matthews committed
666
         * Allocate a vector to be used by pjsip to store the supported ciphers on this system.
667
         */
Tristan Matthews's avatar
Tristan Matthews committed
668
        CipherArray ciphers_;
669

670 671 672
        /**
         * The STUN server name (hostname)
         */
673
        pj_str_t stunServerName_;
674

675 676 677
        /**
         * The STUN server port
         */
678 679
        pj_uint16_t stunPort_;

680 681 682
        /**
         * DTMF type used for this account SIPINFO or RTP
         */
683
        std::string dtmfType_;
684

685 686 687 688
        /**
         * Determine if TLS is enabled for this account. TLS provides a secured channel for
         * SIP signalization. It is independant than the media encription provided by SRTP or ZRTP.
         */
689
        std::string tlsEnable_;
690 691 692 693

        /**
         * Certificate autority file
         */
694 695 696 697 698 699 700 701 702 703 704 705 706
        std::string tlsCaListFile_;
        std::string tlsCertificateFile_;
        std::string tlsPrivateKeyFile_;
        std::string tlsPassword_;
        std::string tlsMethod_;
        std::string tlsCiphers_;
        std::string tlsServerName_;
        bool tlsVerifyServer_;
        bool tlsVerifyClient_;
        bool tlsRequireClientCertificate_;
        std::string tlsNegotiationTimeoutSec_;
        std::string tlsNegotiationTimeoutMsec_;

707
        /**
708
         * The stun server hostname (optional), used to provide the public IP address in case the softphone
709 710
         * stay behind a NAT.
         */
711
        std::string stunServer_;
712 713 714 715 716

        /**
         * Determine if STUN public address resolution is required to register this account. In this case a
         * STUN server hostname must be specified.
         */
717 718
        bool stunEnabled_;

719 720
        /**
         * Determine if SRTP is enabled for this account, SRTP and ZRTP are mutually exclusive
721
         * This only determine if the media channel is secured. One could only enable TLS
722
         * with no secured media channel.
723
         */
724
        bool srtpEnabled_;
725 726 727

        /**
         * Specifies the type of key exchange usd for SRTP (sdes/zrtp)
728
         */
729
        std::string srtpKeyExchange_;
730 731 732 733 734 735

        /**
         * Determine if the softphone should fallback on non secured media channel if SRTP negotiation fails.
         * Make sure other SIP endpoints share the same behavior since it could result in encrypted data to be
         * played through the audio device.
         */
736 737
        bool srtpFallback_;

738 739 740 741
        /**
         * Determine if the SAS sould be displayed on client side. SAS is a 4-charcter string
         * that end users should verbaly validate to ensure the channel is secured. Used especially
         * to prevent man-in-the-middle attack.
742
         */
743
        bool zrtpDisplaySas_;
744 745 746 747

        /**
         * Only display SAS 4-character string once at the begining of the call.
         */
748
        bool zrtpDisplaySasOnce_;
749

750 751
        bool zrtpHelloHash_;
        bool zrtpNotSuppWarning_;
752 753 754 755 756

        /**
         * Details about the registration state.
         * This is a protocol Code:Description pair.
         */
757
        std::pair<int, std::string> registrationStateDetailed_;
758

759 760 761 762 763
        /**
         * Determine if the keep alive timer will be activated or not
         */
        bool keepAliveEnabled_;

764 765 766
        /**
         * Timer used to regularrly send re-register request based
         * on the "Expire" sip header (or the "expire" Contact parameter)
767
         */
768 769
        pj_timer_entry keepAliveTimer_;

770 771 772 773 774
        /**
         * Once enabled, this variable tells if the keepalive timer is activated
         * for this accout
         */
        bool keepAliveTimerActive_;
775 776 777 778 779

        /**
         * Voice over IP Link contains a listener thread and calls
         */
        SIPVoIPLink* link_;
780 781

        /**
782
         * Optional: "received" parameter from VIA header
783 784
         */
        std::string receivedParameter_;
785 786 787 788 789

        /**
         * Optional: "rport" parameter from VIA header
         */
        int rPort_;
790 791 792 793 794

        /**
         * Optional: via_addr construct from received parameters
         */
        pjsip_host_port via_addr_;
795 796

        /**
797
         * Presence data structure
798
         */
799
        SIPPresence * presence_;
800

801
        /*
</