~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/sip/sipaccount.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *
4
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
5
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
35
35
#ifndef SIPACCOUNT_H
36
36
#define SIPACCOUNT_H
37
37
 
 
38
#ifdef HAVE_CONFIG_H
 
39
#include "config.h"
 
40
#endif
 
41
 
38
42
#include <vector>
39
43
#include <map>
40
 
#include "account.h"
 
44
 
41
45
#include "pjsip/sip_transport_tls.h"
42
46
#include "pjsip/sip_types.h"
43
47
#include "pjsip-ua/sip_regc.h"
 
48
 
44
49
#include "noncopyable.h"
 
50
#include "account.h"
45
51
 
46
52
typedef std::vector<pj_ssl_cipher> CipherArray;
47
53
 
57
63
    const char *const DTMF_TYPE_KEY = "dtmfType";
58
64
    const char *const SERVICE_ROUTE_KEY = "serviceRoute";
59
65
    const char *const KEEP_ALIVE_ENABLED = "keepAlive";
 
66
    const char *const PRESENCE_ENABLED_KEY = "presenceEnabled";
 
67
    const char *const PRESENCE_PUBLISH_SUPPORTED_KEY = "presencePublishSupported";
 
68
    const char *const PRESENCE_SUBSCRIBE_SUPPORTED_KEY = "presenceSubscribeSupported";
 
69
    const char *const PRESENCE_STATUS_KEY = "presenceStatus";
 
70
    const char *const PRESENCE_NOTE_KEY = "presenceNote";
60
71
 
61
72
    // TODO: write an object to store credential which implement serializable
62
73
    const char *const SRTP_KEY = "srtp";
90
101
    const char *const STUN_ENABLED_KEY = "stunEnabled";
91
102
    const char *const STUN_SERVER_KEY = "stunServer";
92
103
    const char *const CRED_KEY = "credential";
 
104
    const char *const AUDIO_PORT_MIN_KEY = "audioPortMin";
 
105
    const char *const AUDIO_PORT_MAX_KEY = "audioPortMax";
 
106
#ifdef SFL_VIDEO
 
107
    const char *const VIDEO_PORT_MIN_KEY = "videoPortMin";
 
108
    const char *const VIDEO_PORT_MAX_KEY = "videoPortMax";
 
109
#endif
93
110
}
94
111
 
95
112
class SIPVoIPLink;
 
113
class SIPPresence;
 
114
 
96
115
 
97
116
/**
98
117
 * @file sipaccount.h
99
118
 * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
100
119
 */
 
120
enum {MAX_PORT = 65536};
 
121
enum {HALF_MAX_PORT = MAX_PORT / 2};
 
122
enum class MatchRank {NONE, PARTIAL, FULL};
101
123
 
102
124
class SIPAccount : public Account {
103
125
    public:
110
132
         * Constructor
111
133
         * @param accountID The account identifier
112
134
         */
113
 
        SIPAccount(const std::string& accountID);
 
135
        SIPAccount(const std::string& accountID, bool presenceEnabled);
 
136
        ~SIPAccount();
114
137
 
115
138
        virtual VoIPLink* getVoIPLink();
116
139
 
 
140
        pjsip_host_port getHostPortFromSTUN(pj_pool_t *pool);
 
141
 
117
142
        std::string getUserAgentName() const;
118
143
        void setRegistrationStateDetailed(const std::pair<int, std::string> &details) {
119
144
            registrationStateDetailed_ = details;
120
145
        }
121
146
 
 
147
        void updateDialogViaSentBy(pjsip_dialog *dlg);
 
148
 
 
149
        void resetAutoRegistration();
 
150
        bool checkNATAddress(pjsip_regc_cbparam *param, pj_pool_t *pool);
 
151
 
122
152
        /**
123
153
         * Returns true if this is the IP2IP account
124
154
         */
125
155
        bool isIP2IP() const;
126
156
 
 
157
        static void
 
158
        releasePort(uint16_t port);
 
159
 
127
160
        /**
128
161
         * Serialize internal state of this account for configuration
129
162
         * @param YamlEmitter the configuration engine which generate the configuration file
137
170
        virtual void unserialize(const Conf::YamlNode &map);
138
171
 
139
172
        /**
140
 
         * Set the internal state for this account, mainly used to manage account details from the client application.
141
 
         * @param The map containing the account information.
142
 
         */
143
 
        virtual void setAccountDetails(std::map<std::string, std::string> details);
144
 
 
145
 
        /**
146
173
         * Return an map containing the internal state of this account. Client application can use this method to manage
147
174
         * account info.
148
175
         * @return A map containing the account information.
194
221
 
195
222
 
196
223
        const pjsip_cred_info* getCredInfo() const {
197
 
            return &(*cred_.begin());
 
224
            return cred_.data();
198
225
        }
199
226
 
200
227
        /**
283
310
            regc_ = regc;
284
311
        }
285
312
 
 
313
        void destroyRegistrationInfo();
 
314
 
286
315
        /**
287
316
         * @return pjsip_tls_setting structure, filled from the configuration
288
317
         * file, that can be used directly by PJSIP to initialize
368
397
         * Get the contact header for
369
398
         * @return pj_str_t The contact header based on account information
370
399
         */
371
 
        std::string getContactHeader() const;
 
400
        pj_str_t getContactHeader();
372
401
 
373
402
        /**
374
403
         * Get the local interface name on which this account is bound.
513
542
        pjsip_transport* transport_;
514
543
 
515
544
        /* Returns true if the username and/or hostname match this account */
516
 
        bool matches(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
 
545
        MatchRank matches(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
 
546
 
 
547
#ifdef SFL_PRESENCE
 
548
        /**
 
549
         * Presence management
 
550
         */
 
551
        SIPPresence * getPresence() const;
 
552
 
 
553
        /**
 
554
         * Activate the module.
 
555
         * @param function Publish or subscribe to enable
 
556
         * @param enable Flag
 
557
         */
 
558
        void enablePresence(const bool& enable);
 
559
        /**
 
560
         * Activate the publish/subscribe.
 
561
         * @param enable Flag
 
562
         */
 
563
        void supportPresence(int function, bool enable);
 
564
#endif
 
565
 
 
566
//        unsigned generateAudioPort() const;
 
567
        uint16_t generateAudioPort() const;
 
568
#ifdef SFL_VIDEO
 
569
        uint16_t generateVideoPort() const;
 
570
#endif
 
571
 
 
572
        void scheduleReregistration(pjsip_endpoint *endpt);
517
573
 
518
574
    private:
 
575
        /**
 
576
         * Set the internal state for this account, mainly used to manage account details from the client application.
 
577
         * @param The map containing the account information.
 
578
         */
 
579
        void setAccountDetails(const std::map<std::string, std::string> &details);
 
580
 
519
581
        NON_COPYABLE(SIPAccount);
520
582
 
 
583
        void usePublishedAddressPortInVIA();
521
584
        bool fullMatch(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
522
585
        bool userMatch(const std::string &username) const;
523
586
        bool hostnameMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
524
587
        bool proxyMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
525
588
 
 
589
        struct {
 
590
            pj_bool_t    active;    /**< Flag of reregister status. */
 
591
            pj_timer_entry   timer;     /**< Timer for reregistration.  */
 
592
            void        *reg_tp;    /**< Transport for registration.    */
 
593
            unsigned     attempt_cnt; /**< Attempt counter.     */
 
594
        } auto_rereg_;           /**< Reregister/reconnect data. */
 
595
 
 
596
        static void autoReregTimerCb(pj_timer_heap_t *th, pj_timer_entry *te);
 
597
 
526
598
        /**
527
599
         * Map of credential for this account
528
600
         */
529
601
        std::vector< std::map<std::string, std::string > > credentials_;
530
602
 
 
603
#if HAVE_TLS
531
604
        /**
532
605
         * Maps a string description of the SSL method
533
606
         * to the corresponding enum value in pjsip_ssl_method.
542
615
        void initTlsConfiguration();
543
616
 
544
617
        /**
545
 
         * Display the list of ciphers currently supported on the
 
618
         * PJSIP aborts if the string length of our cipher list is too
 
619
         * great, so this function forces our cipher list to fit this constraint.
546
620
         */
547
 
        void displayCipherSuite();
 
621
        void trimCiphers();
 
622
#endif
548
623
 
549
624
        /**
550
625
         * Initializes STUN config from the config file
630
705
        pjsip_tls_setting tlsSetting_;
631
706
 
632
707
        /**
633
 
         * Allocate a static array to be used by pjsip to store the supported ciphers on this system.
 
708
         * Allocate a vector to be used by pjsip to store the supported ciphers on this system.
634
709
         */
635
 
        CipherArray ciphers;
 
710
        CipherArray ciphers_;
636
711
 
637
712
        /**
638
713
         * The STUN server name (hostname)
653
728
         * Determine if TLS is enabled for this account. TLS provides a secured channel for
654
729
         * SIP signalization. It is independant than the media encription provided by SRTP or ZRTP.
655
730
         */
656
 
        std::string tlsEnable_;
 
731
        bool tlsEnable_;
657
732
 
658
733
        /**
659
734
         * Certificate autority file
759
834
         * Optional: via_addr construct from received parameters
760
835
         */
761
836
        pjsip_host_port via_addr_;
 
837
 
 
838
        char contactBuffer_[PJSIP_MAX_URL_SIZE];
 
839
        pj_str_t contact_;
 
840
        int contactRewriteMethod_;
 
841
        bool allowViaRewrite_;
 
842
        /* Undocumented feature in pjsip, this can == 2 */
 
843
        int allowContactRewrite_;
 
844
        pjsip_transport *via_tp_;
 
845
 
 
846
        /*
 
847
         * Port range for audio RTP ports
 
848
         */
 
849
        std::pair<uint16_t, uint16_t> audioPortRange_;
 
850
 
 
851
#ifdef SFL_VIDEO
 
852
        /**
 
853
         * Port range for video RTP ports
 
854
         */
 
855
        std::pair<uint16_t, uint16_t> videoPortRange_;
 
856
#endif
 
857
 
 
858
#ifdef SFL_PRESENCE
 
859
        /**
 
860
         * Presence data structure
 
861
         */
 
862
        SIPPresence * presence_;
 
863
#endif
 
864
 
 
865
        static bool portsInUse_[HALF_MAX_PORT];
 
866
        static uint16_t getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range);
762
867
};
763
868
 
764
869
#endif