diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 62449007855df20161487cedf00b0e1d02446897..95f82c493818264855cc16b5f3280d6ffb26a433 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -34,17 +34,17 @@ #include "manager.h" Account::Account (const std::string& accountID, const std::string &type) : - _accountID (accountID) - , _link (NULL) - , _enabled (true) - , _type (type) - , _registrationState (Unregistered) - , _codecOrder () - , _codecStr ("") - , _ringtonePath ("/usr/share/sflphone/ringtones/konga.ul") - , _ringtoneEnabled (true) - , _displayName ("") - , _useragent ("SFLphone") + accountID_ (accountID) + , link_ (NULL) + , enabled_ (true) + , type_ (type) + , registrationState_ (Unregistered) + , codecOrder_ () + , codecStr_ ("") + , ringtonePath_ ("/usr/share/sflphone/ringtones/konga.ul") + , ringtoneEnabled_ (true) + , displayName_ ("") + , userAgent_ ("SFLphone") { // Initialize the codec order, used when creating a new account loadDefaultCodecs(); @@ -54,10 +54,10 @@ Account::~Account() { } -void Account::setRegistrationState (RegistrationState state) +void Account::setRegistrationState (const RegistrationState &state) { - if (state != _registrationState) { - _registrationState = state; + if (state != registrationState_) { + registrationState_ = state; // Notify the client Manager::instance().connectionStatusNotification(); @@ -87,16 +87,16 @@ void Account::loadDefaultCodecs() void Account::setActiveCodecs (const std::vector <std::string> &list) { // first clear the previously stored codecs - _codecOrder.clear(); + codecOrder_.clear(); // list contains the ordered payload of active codecs picked by the user for this account // we used the CodecOrder vector to save the order. - size_t i, size = list.size(); - for (i = 0; i < size; i++) { - int payload = std::atoi (list[i].data()); - _codecOrder.push_back ( (AudioCodecType) payload); + for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end(); + ++iter) { + int payload = std::atoi (iter->c_str()); + codecOrder_.push_back ( (AudioCodecType) payload); } // update the codec string according to new codec selection - _codecStr = ManagerImpl::serialize (list); + codecStr_ = ManagerImpl::serialize (list); } diff --git a/daemon/src/account.h b/daemon/src/account.h index ba7e916224b2043bf9b24f796fd5846d10e15ee7..e8b357259c5eac061dd14af91072a26a1dd398ec 100644 --- a/daemon/src/account.h +++ b/daemon/src/account.h @@ -130,20 +130,20 @@ typedef enum RegistrationState { // General configuration keys for accounts -const std::string aliasKey ("alias"); -const std::string typeKey ("type"); -const std::string idKey ("id"); -const std::string usernameKey ("username"); -const std::string authenticationUsernameKey ("authenticationUsername"); -const std::string passwordKey ("password"); -const std::string hostnameKey ("hostname"); -const std::string accountEnableKey ("enable"); -const std::string mailboxKey ("mailbox"); - -const std::string codecsKey ("codecs"); // 0/9/110/111/112/ -const std::string ringtonePathKey ("ringtonePath"); -const std::string ringtoneEnabledKey ("ringtoneEnabled"); -const std::string displayNameKey ("displayName"); +static const char * const aliasKey = "alias"; +static const char * const typeKey = "type"; +static const char * const idKey = "id"; +static const char * const usernameKey = "username"; +static const char * const authenticationUsernameKey = "authenticationUsername"; +static const char * const passwordKey = "password"; +static const char * const hostnameKey = "hostname"; +static const char * const accountEnableKey = "enable"; +static const char * const mailboxKey = "mailbox"; + +static const char * const codecsKey = "codecs"; // 0/9/110/111/112/ +static const char * const ringtonePathKey = "ringtonePath"; +static const char * const ringtoneEnabledKey = "ringtoneEnabled"; +static const char * const displayNameKey = "displayName"; class Account : public Serializable { @@ -182,8 +182,8 @@ class Account : public Serializable * Get the account ID * @return constant account id */ - const std::string& getAccountID() const { - return _accountID; + std::string getAccountID() const { + return accountID_; } /** @@ -191,7 +191,7 @@ class Account : public Serializable * @return VoIPLink* the pointer or 0 */ VoIPLink* getVoIPLink() const { - return _link; + return link_; } virtual void setVoIPLink () = 0; @@ -214,11 +214,11 @@ class Account : public Serializable * false otherwise */ bool isEnabled() const { - return _enabled; + return enabled_; } - void setEnabled (bool enabl) { - _enabled = enabl; + void setEnabled (bool enable) { + enabled_ = enable; } /** @@ -226,14 +226,14 @@ class Account : public Serializable * @return RegistrationState The registration state of underlying VoIPLink */ RegistrationState getRegistrationState() const { - return _registrationState; + return registrationState_; } /** * Set the registration state of the specified link * @param state The registration state of underlying VoIPLink */ - void setRegistrationState (RegistrationState state); + void setRegistrationState (const RegistrationState &state); /** * Set the latest up-to-date state code @@ -243,7 +243,7 @@ class Account : public Serializable * @return void */ void setRegistrationStateDetailed (std::pair<int, std::string> state) { - _registrationStateDetailed = state; + registrationStateDetailed_ = state; } /** @@ -254,37 +254,37 @@ class Account : public Serializable * @return std::pair<int, std::string> A Code:Description state */ std::pair<int, std::string> getRegistrationStateDetailed (void) const { - return _registrationStateDetailed; + return registrationStateDetailed_; } /* They should be treated like macro definitions by the C++ compiler */ std::string getUsername (void) const { - return _username; + return username_; } void setUsername (const std::string &username) { - _username = username; + username_ = username; } std::string getHostname (void) const { - return _hostname; + return hostname_; } void setHostname (const std::string &hostname) { - _hostname = hostname; + hostname_ = hostname; } std::string getAlias (void) const { - return _alias; + return alias_; } void setAlias (const std::string &alias) { - _alias = alias; + alias_ = alias; } std::string getType (void) const { - return _type; + return type_; } void setType (const std::string &type) { - _type = type; + type_ = type; } /** @@ -292,7 +292,7 @@ class Account : public Serializable * @return CodecOrder& The list that reflects the user's choice */ const CodecOrder& getActiveCodecs (void) const { - return _codecOrder; + return codecOrder_; } /** @@ -302,39 +302,39 @@ class Account : public Serializable void setActiveCodecs (const std::vector <std::string>& list); std::string getRingtonePath (void) const { - return _ringtonePath; + return ringtonePath_; } void setRingtonePath (const std::string &path) { - _ringtonePath = path; + ringtonePath_ = path; } bool getRingtoneEnabled (void) const { - return _ringtoneEnabled; + return ringtoneEnabled_; } - void setRingtoneEnabled (bool enabl) { - _ringtoneEnabled = enabl; + void setRingtoneEnabled (bool enable) { + ringtoneEnabled_ = enable; } std::string getDisplayName (void) const { - return _displayName; + return displayName_; } void setDisplayName (const std::string &name) { - _displayName = name; + displayName_ = name; } - std::string getUseragent (void) const { - return _useragent; + std::string getUserAgent (void) const { + return userAgent_; } void setUseragent (const std::string &ua) { - _useragent = ua; + userAgent_ = ua; } std::string getMailBox (void) const { - return _mailBox; + return mailBox_; } void setMailBox (const std::string &mb) { - _mailBox = mb; + mailBox_ = mb; } private: @@ -352,93 +352,92 @@ class Account : public Serializable protected: - /** * Account ID are assign in constructor and shall not changed */ - const std::string _accountID; + const std::string accountID_; /** * Account login information: username */ - std::string _username; + std::string username_; /** * Account login information: hostname */ - std::string _hostname; + std::string hostname_; /** * Account login information: Alias */ - std::string _alias; + std::string alias_; /** * Voice over IP Link contains a listener thread and calls */ - VoIPLink* _link; + VoIPLink* link_; /** * Tells if the link is enabled, active. * This implies the link will be initialized on startup. * Modified by the configuration (key: ENABLED) */ - bool _enabled; + bool enabled_; /* * The account type * IAX2 or SIP */ - std::string _type; + std::string type_; /* * The general, protocol neutral registration * state of the account */ - RegistrationState _registrationState; + RegistrationState registrationState_; /* * Details about the registration state. * This is a protocol Code:Description pair. */ - std::pair<int, std::string> _registrationStateDetailed; + std::pair<int, std::string> registrationStateDetailed_; /** * Vector containing the order of the codecs */ - CodecOrder _codecOrder; + CodecOrder codecOrder_; /** * List of codec obtained when parsing configuration and used * to generate codec order list */ - std::string _codecStr; + std::string codecStr_; /** * Ringtone .au file used for this account */ - std::string _ringtonePath; + std::string ringtonePath_; /** * Play ringtone when receiving a call */ - bool _ringtoneEnabled; + bool ringtoneEnabled_; /** * Display name when calling */ - std::string _displayName; + std::string displayName_; /** * Useragent used for registration */ - std::string _useragent; + std::string userAgent_; /** * Account mail box */ - std::string _mailBox; + std::string mailBox_; }; diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index d4a216848216f867ce018752773c28d2bc10ba4f..a704421bc5a83017155ada8e687dddaf9c91b192 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -38,35 +38,35 @@ IAXAccount::IAXAccount (const std::string& accountID) : Account (accountID, "iax2") { - _link = new IAXVoIPLink (accountID); + link_ = new IAXVoIPLink (accountID); } IAXAccount::~IAXAccount() { - delete _link; + delete link_; } void IAXAccount::serialize (Conf::YamlEmitter *emitter) { - if(emitter == NULL) { + if (emitter == NULL) { _error("IAXAccount: Error: emitter is NULL in serialize"); return; } Conf::MappingNode accountmap (NULL); - Conf::ScalarNode id (Account::_accountID); - Conf::ScalarNode username (Account::_username); - Conf::ScalarNode password (_password); - Conf::ScalarNode alias (Account::_alias); - Conf::ScalarNode hostname (Account::_hostname); - Conf::ScalarNode enable (_enabled); - Conf::ScalarNode type (Account::_type); - Conf::ScalarNode mailbox (_mailBox); + Conf::ScalarNode id (accountID_); + Conf::ScalarNode username (username_); + Conf::ScalarNode password (password_); + Conf::ScalarNode alias (alias_); + Conf::ScalarNode hostname (hostname_); + Conf::ScalarNode enable (enabled_); + Conf::ScalarNode type (type_); + Conf::ScalarNode mailbox (mailBox_); - Conf::ScalarNode codecs (_codecStr); - Conf::ScalarNode displayName (_displayName); + Conf::ScalarNode codecs (codecStr_); + Conf::ScalarNode displayName (displayName_); accountmap.setKeyValue (aliasKey, &alias); accountmap.setKeyValue (typeKey, &type); @@ -89,68 +89,66 @@ void IAXAccount::serialize (Conf::YamlEmitter *emitter) void IAXAccount::unserialize (Conf::MappingNode *map) { - if(map == NULL) { + if (map == NULL) { _error("IAXAccount: Error: Map is NULL in unserialize"); return; } - map->getValue(aliasKey, &_alias); - map->getValue(typeKey, &_type); - map->getValue(usernameKey, &_username); - map->getValue(passwordKey, &_password); - map->getValue(hostnameKey, &_hostname); - map->getValue(accountEnableKey, &_enabled); - map->getValue(mailboxKey, &_mailBox); - map->getValue (codecsKey, &_codecStr); + map->getValue(aliasKey, &alias_); + map->getValue(typeKey, &type_); + map->getValue(usernameKey, &username_); + map->getValue(passwordKey, &password_); + map->getValue(hostnameKey, &hostname_); + map->getValue(accountEnableKey, &enabled_); + map->getValue(mailboxKey, &mailBox_); + map->getValue (codecsKey, &codecStr_); // Update codec list which one is used for SDP offer - setActiveCodecs (ManagerImpl::unserialize (_codecStr)); - map->getValue (displayNameKey, &_displayName); + setActiveCodecs (ManagerImpl::unserialize (codecStr_)); + map->getValue (displayNameKey, &displayName_); } void IAXAccount::setAccountDetails (std::map<std::string, std::string> details) { // Account setting common to SIP and IAX - setAlias (details[CONFIG_ACCOUNT_ALIAS]); - setType (details[CONFIG_ACCOUNT_TYPE]); - setUsername (details[USERNAME]); - setHostname (details[HOSTNAME]); - _password = (details[PASSWORD]); - setEnabled ( (details[CONFIG_ACCOUNT_ENABLE].compare ("true") == 0)); - setMailBox (details[CONFIG_ACCOUNT_MAILBOX]); - - setDisplayName (details[DISPLAY_NAME]); - setUseragent (details[USERAGENT]); + alias_ = details[CONFIG_ACCOUNT_ALIAS]; + type_ = details[CONFIG_ACCOUNT_TYPE]; + username_ = details[USERNAME]; + hostname_ = details[HOSTNAME]; + password_ = details[PASSWORD]; + enabled_ = details[CONFIG_ACCOUNT_ENABLE] == "true"; + mailBox_ = details[CONFIG_ACCOUNT_MAILBOX]; + displayName_ = details[DISPLAY_NAME]; + userAgent_ = details[USERAGENT]; } std::map<std::string, std::string> IAXAccount::getAccountDetails() const { std::map<std::string, std::string> a; - a.insert (std::pair<std::string, std::string> (ACCOUNT_ID, _accountID)); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, getAlias())); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, isEnabled() ? "true" : "false")); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, getType())); - a.insert (std::pair<std::string, std::string> (HOSTNAME, getHostname())); - a.insert (std::pair<std::string, std::string> (USERNAME, getUsername())); - a.insert (std::pair<std::string, std::string> (PASSWORD, getPassword())); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_MAILBOX, getMailBox())); + a[ACCOUNT_ID] = accountID_; + a[CONFIG_ACCOUNT_ALIAS] = alias_; + a[CONFIG_ACCOUNT_ENABLE] = enabled_ ? "true" : "false"; + a[CONFIG_ACCOUNT_TYPE] = type_; + a[HOSTNAME] = hostname_; + a[USERNAME] = username_; + a[PASSWORD] = password_; + a[CONFIG_ACCOUNT_MAILBOX] = mailBox_; - RegistrationState state = Unregistered; std::string registrationStateCode; std::string registrationStateDescription; - state = getRegistrationState(); + RegistrationState state(registrationState_); int code = getRegistrationStateDetailed().first; std::stringstream out; out << code; registrationStateCode = out.str(); registrationStateDescription = getRegistrationStateDetailed().second; - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATUS, Manager::instance().mapStateNumberToString (state))); - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_CODE, registrationStateCode)); - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_DESCRIPTION, registrationStateDescription)); - a.insert (std::pair<std::string, std::string> (USERAGENT, getUseragent())); + a[REGISTRATION_STATUS] = Manager::instance().mapStateNumberToString (state); + a[REGISTRATION_STATE_CODE] = registrationStateCode; + a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription; + a[USERAGENT] = userAgent_; return a; } @@ -158,22 +156,16 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const void IAXAccount::setVoIPLink() { - } int IAXAccount::registerVoIPLink() { try { + link_->init(); - _link->init(); - - // Stuff needed for IAX registration - setHostname (_hostname); - setUsername (_username); - - _link->sendRegister (this); + link_->sendRegister (this); } - catch(VoipLinkException &e) { + catch (const VoipLinkException &e) { _error("IAXAccount: %s", e.what()); } @@ -184,12 +176,11 @@ int IAXAccount::unregisterVoIPLink() { try { - _link->sendUnregister (this); - _link->terminate(); - + link_->sendUnregister (this); + link_->terminate(); return 0; } - catch(VoipLinkException &e) { + catch (const VoipLinkException &e) { _error("IAXAccount: %s", e.what()); } @@ -201,6 +192,6 @@ IAXAccount::loadConfig() { // If IAX is not supported, do not register this account #if !HAVE_IAX - _enabled = false; + enabled_ = false; #endif } diff --git a/daemon/src/iax/iaxaccount.h b/daemon/src/iax/iaxaccount.h index b417c0d67602b99ef546eeaf7c1b6ca3dbed3309..b3121d948a98fc20c204295eea0253c03e07bc13 100644 --- a/daemon/src/iax/iaxaccount.h +++ b/daemon/src/iax/iaxaccount.h @@ -69,8 +69,8 @@ class IAXAccount : public Account */ int unregisterVoIPLink(); - const std::string &getPassword (void) const { - return _password; + std::string getPassword (void) const { + return password_; } private: @@ -78,7 +78,7 @@ class IAXAccount : public Account /** * Account login information: password */ - std::string _password; + std::string password_; }; #endif diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 372265398a10b1348c9bb8b1f1dd849aeae3e9ed..4101ec5931389b67efa40124534d137921a57cbb 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -93,8 +93,8 @@ SIPAccount::SIPAccount (const std::string& accountID) SIPAccount::~SIPAccount() { /* One SIP account less connected to the sip voiplink */ - if (_accountID != "default") - dynamic_cast<SIPVoIPLink*> (_link)->decrementClients(); + if (accountID_ != "default") + dynamic_cast<SIPVoIPLink*> (link_)->decrementClients(); /* Delete accounts-related information */ _regc = NULL; @@ -114,12 +114,12 @@ void SIPAccount::serialize (Conf::YamlEmitter *emitter) Conf::MappingNode zrtpmap (NULL); Conf::MappingNode tlsmap (NULL); - Conf::ScalarNode id (Account::_accountID); - Conf::ScalarNode username (Account::_username); - Conf::ScalarNode alias (Account::_alias); - Conf::ScalarNode hostname (Account::_hostname); - Conf::ScalarNode enable (_enabled); - Conf::ScalarNode type (Account::_type); + Conf::ScalarNode id (Account::accountID_); + Conf::ScalarNode username (Account::username_); + Conf::ScalarNode alias (Account::alias_); + Conf::ScalarNode hostname (Account::hostname_); + Conf::ScalarNode enable (enabled_); + Conf::ScalarNode type (Account::type_); Conf::ScalarNode expire (_registrationExpire); Conf::ScalarNode interface (_interface); std::stringstream portstr; @@ -127,19 +127,19 @@ void SIPAccount::serialize (Conf::YamlEmitter *emitter) Conf::ScalarNode port (portstr.str()); Conf::ScalarNode serviceRoute (_serviceRoute); - Conf::ScalarNode mailbox (_mailBox); + Conf::ScalarNode mailbox (mailBox_); Conf::ScalarNode publishAddr (_publishedIpAddress); std::stringstream publicportstr; publicportstr << _publishedPort; Conf::ScalarNode publishPort (publicportstr.str()); Conf::ScalarNode sameasLocal (_publishedSameasLocal); Conf::ScalarNode resolveOnce (_resolveOnce); - Conf::ScalarNode codecs (_codecStr); - Conf::ScalarNode ringtonePath (_ringtonePath); - Conf::ScalarNode ringtoneEnabled (_ringtoneEnabled); + Conf::ScalarNode codecs (codecStr_); + Conf::ScalarNode ringtonePath (ringtonePath_); + Conf::ScalarNode ringtoneEnabled (ringtoneEnabled_); Conf::ScalarNode stunServer (_stunServer); Conf::ScalarNode stunEnabled (_stunEnabled); - Conf::ScalarNode displayName (_displayName); + Conf::ScalarNode displayName (displayName_); Conf::ScalarNode dtmfType (_dtmfType==OVERRTP ? "overrtp" : "sipinfo"); std::stringstream countstr; @@ -235,7 +235,7 @@ void SIPAccount::serialize (Conf::YamlEmitter *emitter) try { emitter->serializeAccount (&accountmap); - } catch (Conf::YamlEmitterException &e) { + } catch (const Conf::YamlEmitterException &e) { _error ("ConfigTree: %s", e.what()); } @@ -260,18 +260,18 @@ void SIPAccount::unserialize (Conf::MappingNode *map) assert(map); - map->getValue(aliasKey, &_alias); - map->getValue(typeKey, &_type); - map->getValue(usernameKey, &_username); - map->getValue(hostnameKey, &_hostname); - map->getValue(accountEnableKey, &_enabled); - map->getValue(mailboxKey, &_mailBox); - map->getValue(codecsKey, &_codecStr); + map->getValue(aliasKey, &alias_); + map->getValue(typeKey, &type_); + map->getValue(usernameKey, &username_); + map->getValue(hostnameKey, &hostname_); + map->getValue(accountEnableKey, &enabled_); + map->getValue(mailboxKey, &mailBox_); + map->getValue(codecsKey, &codecStr_); // Update codec list which one is used for SDP offer - setActiveCodecs (ManagerImpl::unserialize (_codecStr)); + setActiveCodecs (ManagerImpl::unserialize (codecStr_)); - map->getValue(ringtonePathKey, &_ringtonePath); - map->getValue(ringtoneEnabledKey, &_ringtoneEnabled); + map->getValue(ringtonePathKey, &ringtonePath_); + map->getValue(ringtoneEnabledKey, &ringtoneEnabled_); map->getValue(expireKey, &_registrationExpire); map->getValue(interfaceKey, &_interface); int port; @@ -295,7 +295,7 @@ void SIPAccount::unserialize (Conf::MappingNode *map) // Init stun server name with default server name _stunServerName = pj_str ( (char*) _stunServer.data()); - map->getValue(displayNameKey, &_displayName); + map->getValue(displayNameKey, &displayName_); std::vector<std::map<std::string, std::string> > creds; @@ -330,7 +330,7 @@ void SIPAccount::unserialize (Conf::MappingNode *map) std::string password; map->getValue(passwordKey, &password); - credmap[USERNAME] = _username; + credmap[USERNAME] = username_; credmap[PASSWORD] = password; credmap[REALM] = "*"; creds.push_back(credmap); @@ -418,7 +418,7 @@ void SIPAccount::setAccountDetails (std::map<std::string, std::string> details) // TLS settings // The TLS listener is unique and globally defined through IP2IP_PROFILE - if (_accountID == IP2IP_PROFILE) + if (accountID_ == IP2IP_PROFILE) setTlsListenerPort (atoi (details[TLS_LISTENER_PORT].c_str())); setTlsEnable (details[TLS_ENABLE]); @@ -450,9 +450,9 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const { std::map<std::string, std::string> a; - a[ACCOUNT_ID] = _accountID; + a[ACCOUNT_ID] = accountID_; // The IP profile does not allow to set an alias - a[CONFIG_ACCOUNT_ALIAS] = (_accountID == IP2IP_PROFILE) ? IP2IP_PROFILE : getAlias(); + a[CONFIG_ACCOUNT_ALIAS] = (accountID_ == IP2IP_PROFILE) ? IP2IP_PROFILE : getAlias(); a[CONFIG_ACCOUNT_ENABLE] = isEnabled() ? "true" : "false"; a[CONFIG_ACCOUNT_TYPE] = getType(); @@ -467,7 +467,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const std::string registrationStateCode; std::string registrationStateDescription; - if (_accountID == IP2IP_PROFILE) { + if (accountID_ == IP2IP_PROFILE) { registrationStateCode = ""; // emtpy field registrationStateDescription = "Direct IP call"; } else { @@ -479,14 +479,14 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const registrationStateDescription = getRegistrationStateDetailed().second; } - a[REGISTRATION_STATUS] = (_accountID == IP2IP_PROFILE) ? "READY": Manager::instance().mapStateNumberToString (state); + a[REGISTRATION_STATUS] = (accountID_ == IP2IP_PROFILE) ? "READY": Manager::instance().mapStateNumberToString (state); a[REGISTRATION_STATE_CODE] = registrationStateCode; a[REGISTRATION_STATE_DESCRIPTION] = registrationStateDescription; // Add sip specific details a[ROUTESET] = getServiceRoute(); a[CONFIG_ACCOUNT_RESOLVE_ONCE] = isResolveOnce() ? "true" : "false"; - a[USERAGENT] = getUseragent(); + a[USERAGENT] = getUserAgent(); a[CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = getRegistrationExpire(); a[LOCAL_INTERFACE] = getLocalInterface(); @@ -536,14 +536,14 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const void SIPAccount::setVoIPLink() { - _link = SIPVoIPLink::instance (); - dynamic_cast<SIPVoIPLink*> (_link)->incrementClients(); + link_ = SIPVoIPLink::instance (); + dynamic_cast<SIPVoIPLink*> (link_)->incrementClients(); } int SIPAccount::registerVoIPLink() { - if (_hostname.length() >= PJ_MAX_HOSTNAME) { + if (hostname_.length() >= PJ_MAX_HOSTNAME) { return 1; } @@ -565,11 +565,10 @@ int SIPAccount::registerVoIPLink() try { // In our definition of the ip2ip profile (aka Direct IP Calls), // no registration should be performed - if (_accountID != IP2IP_PROFILE) { - _link->sendRegister (this); - } + if (accountID_ != IP2IP_PROFILE) + link_->sendRegister (this); } - catch(VoipLinkException &e) { + catch (const VoipLinkException &e) { _error("SIPAccount: %s", e.what()); } @@ -578,15 +577,15 @@ int SIPAccount::registerVoIPLink() int SIPAccount::unregisterVoIPLink() { - if (_accountID == IP2IP_PROFILE) { + if (accountID_ == IP2IP_PROFILE) { return true; } try { - _link->sendUnregister (this); + link_->sendUnregister (this); setRegistrationInfo (NULL); } - catch(VoipLinkException &e) { + catch (const VoipLinkException &e) { _error("SIPAccount: %s", e.what()); return false; } @@ -714,8 +713,8 @@ std::string SIPAccount::getFromUri (void) const std::string scheme; std::string transport; - std::string username = _username; - std::string hostname = _hostname; + std::string username = username_; + std::string hostname = hostname_; // UDP does not require the transport specification @@ -728,19 +727,14 @@ std::string SIPAccount::getFromUri (void) const } // Get login name if username is not specified - if (_username.empty()) { + if (username_.empty()) username = getLoginName(); - } - // Get machine hostname if not provided - if (_hostname.empty()) { + if (hostname_.empty()) hostname = getMachineName(); - } - int len = pj_ansi_snprintf (uri, PJSIP_MAX_URL_SIZE, - "<%s%s@%s%s>", scheme.c_str(), username.c_str(), @@ -775,7 +769,7 @@ std::string SIPAccount::getToUri (const std::string& username) const // Check if hostname is already specified if (username.find ("@") == std::string::npos) { // hostname not specified - hostname = _hostname; + hostname = hostname_; } int len = pj_ansi_snprintf (uri, PJSIP_MAX_URL_SIZE, @@ -796,7 +790,7 @@ std::string SIPAccount::getServerUri (void) const std::string scheme; std::string transport; - std::string hostname = _hostname; + std::string hostname = hostname_; // UDP does not require the transport specification @@ -838,16 +832,16 @@ std::string SIPAccount::getContactHeader (const std::string& address, const std: transport = ""; } - _debug ("Display Name: %s", _displayName.c_str()); + _debug ("Display Name: %s", displayName_.c_str()); int len = pj_ansi_snprintf (contact, PJSIP_MAX_URL_SIZE, "%s%s<%s%s%s%s%s%s:%d%s>", - _displayName.c_str(), - (_displayName.empty() ? "" : " "), + displayName_.c_str(), + (displayName_.empty() ? "" : " "), scheme.c_str(), - _username.c_str(), - (_username.empty() ? "":"@"), + username_.c_str(), + (username_.empty() ? "":"@"), beginquote, address.c_str(), endquote, diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 2545f07b790c43be0249f46ef9ecf4d85bef7982..3b85b9b6c6eed83627d091ccebea8122226b3101 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -442,8 +442,7 @@ void SIPVoIPLink::sendRegister (Account *a) throw(VoipLinkException) account->setRegistrationState (Trying); // Create the registration according to the account ID - // status = pjsip_regc_create (_endpt, (void*) account, ®istration_cb, ®c); - status = pjsip_regc_create (_endpt, (void *) &account->getAccountID(), ®istration_cb, ®c); + status = pjsip_regc_create (_endpt, (void *) account, ®istration_cb, ®c); if (status != PJ_SUCCESS) { _mutexSIP.leaveMutex(); @@ -1157,7 +1156,7 @@ std::string SIPVoIPLink::getUseragentName (SIPAccount *account) { std::ostringstream useragent; - useragent << account->getUseragent(); + useragent << account->getUserAgent(); if (useragent.str() == "sflphone" || useragent.str() == "") useragent << "/" << PACKAGE_VERSION; @@ -2932,8 +2931,7 @@ void transaction_state_changed_cb (pjsip_inv_session *inv UNUSED, pjsip_transact void registration_cb (struct pjsip_regc_cbparam *param) { - std::string *accountid = static_cast<std::string *>(param->token); - SIPAccount * account = static_cast<SIPAccount *> (Manager::instance().getAccount(*accountid)); + SIPAccount *account = static_cast<SIPAccount *>(param->token); if (account == NULL) { _error("Account is NULL in registration_cb.");