Commit b0a05007 authored by Tristan Matthews's avatar Tristan Matthews

* #6699: cleanup account

parent f079c6f2
......@@ -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);
}
......@@ -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_;
};
......
......@@ -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
}
......@@ -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
This diff is collapsed.
......@@ -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, &registration_cb, &regc);
status = pjsip_regc_create (_endpt, (void *) &account->getAccountID(), &registration_cb, &regc);
status = pjsip_regc_create (_endpt, (void *) account, &registration_cb, &regc);
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.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment