Commit 83bdf20b authored by Alexandre Savard's avatar Alexandre Savard

[#3649] Implement set/get account details and serialize/unserialize for IAX

parent e3b54d89
......@@ -40,6 +40,8 @@ Account::Account (const AccountID& accountID, std::string type) :
, _type (type)
, _codecOrder ()
, _startupCodecStr("")
, _displayName("")
, _useragent("SFLphone")
{
setRegistrationState (Unregistered);
}
......
......@@ -143,6 +143,7 @@ const Conf::Key accountEnableKey("enable");
const Conf::Key mailboxKey("mailbox");
const Conf::Key codecsKey("codecs"); // 0/9/110/111/112/
const Conf::Key displayNameKey("displayName");
#define find_in_map(X, Y) if((iter = map_cpy.find(X)) != map_cpy.end()) { Y = iter->second; }
......@@ -262,6 +263,12 @@ class Account : public Serializable{
void setActiveCodecs (const std::vector <std::string>& list);
inline std::string getDisplayName(void) { return _displayName; }
inline void setDisplayName(std::string name) { _displayName = name; }
std::string getUseragent(void) { return _useragent; }
void setUseragent(std::string ua) { _useragent = ua; }
private:
// copy constructor
Account(const Account& rh);
......@@ -338,6 +345,11 @@ class Account : public Serializable{
*/
std::string _startupCodecStr;
// Display Name that can be used in SIP URI.
std::string _displayName;
std::string _useragent;
};
#endif
......@@ -49,16 +49,113 @@ IAXAccount::~IAXAccount()
void IAXAccount::serialize(Conf::YamlEmitter *emitter)
{
_debug("IaxAccount: serialize %s", _accountID.c_str());
Conf::MappingNode accountmap(NULL);
Conf::ScalarNode id(Account::_accountID);
Conf::ScalarNode username(Account::_username);
Conf::ScalarNode password(Account::_password);
Conf::ScalarNode alias(Account::_alias);
Conf::ScalarNode hostname(Account::_hostname);
Conf::ScalarNode enable(_enabled ? "true" : "false");
Conf::ScalarNode type(Account::_type);
Conf::ScalarNode mailbox("97");
Conf::ScalarNode codecs(_startupCodecStr);
Conf::ScalarNode displayName(_displayName);
accountmap.setKeyValue(aliasKey, &alias);
accountmap.setKeyValue(typeKey, &type);
accountmap.setKeyValue(idKey, &id);
accountmap.setKeyValue(usernameKey, &username);
accountmap.setKeyValue(passwordKey, &password);
accountmap.setKeyValue(hostnameKey, &hostname);
accountmap.setKeyValue(accountEnableKey, &enable);
accountmap.setKeyValue(mailboxKey, &mailbox);
accountmap.setKeyValue(displayNameKey, &displayName);
accountmap.setKeyValue(codecsKey, &codecs);
try{
emitter->serializeAccount(&accountmap);
}
catch (Conf::YamlEmitterException &e) {
_error("ConfigTree: %s", e.what());
}
}
void IAXAccount::unserialize(Conf::MappingNode *map)
{
Conf::ScalarNode *val;
_debug("IaxAccount: Unserialize");
val = (Conf::ScalarNode *)(map->getValue(aliasKey));
if(val) { _alias = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(typeKey));
if(val) { _type = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(idKey));
if(val) { _accountID = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(usernameKey));
if(val) { _username = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(passwordKey));
if(val) { _password = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(hostnameKey));
if(val) { _hostname = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(accountEnableKey));
if(val) { _enabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
// val = (Conf::ScalarNode *)(map->getValue(mailboxKey));
val = (Conf::ScalarNode *)(map->getValue(codecsKey));
if(val) { _startupCodecStr = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(displayNameKey));
if(val) { _displayName = val->getValue(); val = NULL; }
}
void IAXAccount::setAccountDetails(const std::map<std::string, std::string>& details)
{
std::map<std::string, std::string> map_cpy;
std::map<std::string, std::string>::iterator iter;
_debug("IaxAccount: Set account details: %s", _accountID.c_str());
// Work on a copy
map_cpy = details;
std::string alias;
std::string type;
std::string hostname;
std::string username;
std::string password;
std::string mailbox;
std::string accountEnable;
std::string ua_name;
// Account setting common to SIP and IAX
find_in_map(CONFIG_ACCOUNT_ALIAS, alias)
find_in_map(CONFIG_ACCOUNT_TYPE, type)
find_in_map(HOSTNAME, hostname)
find_in_map(USERNAME, username)
find_in_map(PASSWORD, password)
find_in_map(CONFIG_ACCOUNT_MAILBOX, mailbox);
find_in_map(CONFIG_ACCOUNT_ENABLE, accountEnable);
setAlias(alias);
setType(type);
setUsername(username);
setHostname(hostname);
setPassword(password);
setEnabled((accountEnable.compare("true") == 0) ? true : false);
std::string displayName;
find_in_map(DISPLAY_NAME, displayName)
setDisplayName(displayName);
find_in_map(USERAGENT, ua_name)
setUseragent(ua_name);
}
......@@ -66,6 +163,31 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails()
{
std::map<std::string, std::string> a;
_debug("IaxAccount: get account details %s", _accountID.c_str());
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()));
RegistrationState state = Unregistered;
std::string registrationStateCode;
std::string registrationStateDescription;
state = getRegistrationState();
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()));
return a;
}
......
......@@ -97,7 +97,6 @@ SIPAccount::SIPAccount (const AccountID& accountID)
, _authenticationUsername ("")
, _tlsSetting (NULL)
, _dtmfType(OVERRTP)
, _displayName ("")
, _tlsEnable("")
, _tlsPortStr("")
, _tlsCaListFile("")
......@@ -125,7 +124,6 @@ SIPAccount::SIPAccount (const AccountID& accountID)
, _zrtpDisplaySasOnce(false)
, _zrtpHelloHash(false)
, _zrtpNotSuppWarning(false)
, _useragent("SFLphone")
{
_debug("Sip account constructor called");
......@@ -399,6 +397,8 @@ void SIPAccount::setAccountDetails(const std::map<std::string, std::string>& det
std::map<std::string, std::string> map_cpy;
std::map<std::string, std::string>::iterator iter;
_debug("SipAccount: set account details %s", _accountID.c_str());
// Work on a copy
map_cpy = details;
......
......@@ -96,8 +96,6 @@ const Conf::Key stunServerKey("stunServer");
const Conf::Key credKey("credential");
const Conf::Key credentialCountKey("count");
const Conf::Key displayNameKey("displayName");
class SIPVoIPLink;
/**
......@@ -448,9 +446,6 @@ class SIPAccount : public Account
DtmfType getDtmfType(void) { return _dtmfType; }
void setDtmfType(DtmfType type) { _dtmfType = type; }
std::string getDisplayName(void) { return _displayName; }
void setDisplayName(std::string name) { _displayName = name ;}
bool getSrtpEnable(void) { return _srtpEnabled; }
void setSrtpEnable(bool enabl) { _srtpEnabled = enabl; }
......@@ -515,9 +510,6 @@ class SIPAccount : public Account
std::string getTlsNegotiationTimeoutMsec(void) { return _tlsNegotiationTimeoutMsec; }
void setTlsNegotiationTimeoutMsec(std::string timeout) { _tlsNegotiationTimeoutMsec = timeout; }
std::string getUseragent(void) { return _useragent; }
void setUseragent(std::string ua) { _useragent = ua; }
private:
/* Maps a string description of the SSL method
......@@ -612,9 +604,6 @@ class SIPAccount : public Account
pj_uint16_t _stunPort;
DtmfType _dtmfType;
// Display Name that can be used in SIP URI.
std::string _displayName;
std::string _tlsEnable;
std::string _tlsPortStr;
......@@ -655,8 +644,6 @@ class SIPAccount : public Account
bool _zrtpHelloHash;
bool _zrtpNotSuppWarning;
std::string _useragent;
};
......
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