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";
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";
107
const char *const VIDEO_PORT_MIN_KEY = "videoPortMin";
108
const char *const VIDEO_PORT_MAX_KEY = "videoPortMax";
95
112
class SIPVoIPLink;
98
117
* @file sipaccount.h
99
118
* @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
120
enum {MAX_PORT = 65536};
121
enum {HALF_MAX_PORT = MAX_PORT / 2};
122
enum class MatchRank {NONE, PARTIAL, FULL};
102
124
class SIPAccount : public Account {
111
133
* @param accountID The account identifier
113
SIPAccount(const std::string& accountID);
135
SIPAccount(const std::string& accountID, bool presenceEnabled);
115
138
virtual VoIPLink* getVoIPLink();
140
pjsip_host_port getHostPortFromSTUN(pj_pool_t *pool);
117
142
std::string getUserAgentName() const;
118
143
void setRegistrationStateDetailed(const std::pair<int, std::string> &details) {
119
144
registrationStateDetailed_ = details;
147
void updateDialogViaSentBy(pjsip_dialog *dlg);
149
void resetAutoRegistration();
150
bool checkNATAddress(pjsip_regc_cbparam *param, pj_pool_t *pool);
123
153
* Returns true if this is the IP2IP account
125
155
bool isIP2IP() const;
158
releasePort(uint16_t port);
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);
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.
143
virtual void setAccountDetails(std::map<std::string, std::string> details);
146
173
* Return an map containing the internal state of this account. Client application can use this method to manage
148
175
* @return A map containing the account information.
368
397
* Get the contact header for
369
398
* @return pj_str_t The contact header based on account information
371
std::string getContactHeader() const;
400
pj_str_t getContactHeader();
374
403
* Get the local interface name on which this account is bound.
513
542
pjsip_transport* transport_;
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;
549
* Presence management
551
SIPPresence * getPresence() const;
554
* Activate the module.
555
* @param function Publish or subscribe to enable
558
void enablePresence(const bool& enable);
560
* Activate the publish/subscribe.
563
void supportPresence(int function, bool enable);
566
// unsigned generateAudioPort() const;
567
uint16_t generateAudioPort() const;
569
uint16_t generateVideoPort() const;
572
void scheduleReregistration(pjsip_endpoint *endpt);
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.
579
void setAccountDetails(const std::map<std::string, std::string> &details);
519
581
NON_COPYABLE(SIPAccount);
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;
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. */
596
static void autoReregTimerCb(pj_timer_heap_t *th, pj_timer_entry *te);
527
599
* Map of credential for this account
529
601
std::vector< std::map<std::string, std::string > > credentials_;
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();
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.
547
void displayCipherSuite();
550
625
* Initializes STUN config from the config file
759
834
* Optional: via_addr construct from received parameters
761
836
pjsip_host_port via_addr_;
838
char contactBuffer_[PJSIP_MAX_URL_SIZE];
840
int contactRewriteMethod_;
841
bool allowViaRewrite_;
842
/* Undocumented feature in pjsip, this can == 2 */
843
int allowContactRewrite_;
844
pjsip_transport *via_tp_;
847
* Port range for audio RTP ports
849
std::pair<uint16_t, uint16_t> audioPortRange_;
853
* Port range for video RTP ports
855
std::pair<uint16_t, uint16_t> videoPortRange_;
860
* Presence data structure
862
SIPPresence * presence_;
865
static bool portsInUse_[HALF_MAX_PORT];
866
static uint16_t getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range);