Commit 29b600a7 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6699: refactoring, cleanup in accounts

parent 6f81029e
......@@ -220,14 +220,6 @@ class Account : public Serializable
enabled_ = enable;
}
/**
* Get the registration state of the specified link
* @return RegistrationState The registration state of underlying VoIPLink
*/
RegistrationState getRegistrationState() const {
return registrationState_;
}
/**
* Set the registration state of the specified link
* @param state The registration state of underlying VoIPLink
......@@ -239,10 +231,6 @@ class Account : public Serializable
return username_;
}
void setUsername (const std::string &username) {
username_ = username;
}
std::string getHostname (void) const {
return hostname_;
}
......@@ -299,13 +287,6 @@ class Account : public Serializable
displayName_ = name;
}
std::string getUserAgent (void) const {
return userAgent_;
}
void setUseragent (const std::string &ua) {
userAgent_ = ua;
}
std::string getMailBox (void) const {
return mailBox_;
}
......
......@@ -221,10 +221,6 @@ std::map<std::string, std::string> ConfigurationManager::getTlsSettings()
void ConfigurationManager::setTlsSettings (const std::map<std::string, std::string>& details)
{
std::map<std::string, std::string> map_cpy = details;
std::map<std::string, std::string>::iterator it;
SIPAccount * sipaccount = (SIPAccount *) Manager::instance().getAccount (IP2IP_PROFILE);
if (!sipaccount) {
......@@ -232,63 +228,64 @@ void ConfigurationManager::setTlsSettings (const std::map<std::string, std::stri
return;
}
it = map_cpy.find (TLS_LISTENER_PORT);
std::map<std::string, std::string>::const_iterator it;
it = details.find (TLS_LISTENER_PORT);
if (it != details.end()) sipaccount->setTlsListenerPort (atoi (it->second.data()));
it = map_cpy.find (TLS_ENABLE);
it = details.find (TLS_ENABLE);
if (it != details.end()) sipaccount->setTlsEnable (it->second);
it = map_cpy.find (TLS_CA_LIST_FILE);
it = details.find (TLS_CA_LIST_FILE);
if (it != map_cpy.end()) sipaccount->setTlsCaListFile (it->second);
if (it != details.end()) sipaccount->setTlsCaListFile (it->second);
it = map_cpy.find (TLS_CERTIFICATE_FILE);
it = details.find (TLS_CERTIFICATE_FILE);
if (it != map_cpy.end()) sipaccount->setTlsCertificateFile (it->second);
if (it != details.end()) sipaccount->setTlsCertificateFile (it->second);
it = map_cpy.find (TLS_PRIVATE_KEY_FILE);
it = details.find (TLS_PRIVATE_KEY_FILE);
if (it != map_cpy.end()) sipaccount->setTlsPrivateKeyFile (it->second);
if (it != details.end()) sipaccount->setTlsPrivateKeyFile (it->second);
it = map_cpy.find (TLS_PASSWORD);
it = details.find (TLS_PASSWORD);
if (it != map_cpy.end()) sipaccount->setTlsPassword (it->second);
if (it != details.end()) sipaccount->setTlsPassword (it->second);
it = map_cpy.find (TLS_METHOD);
it = details.find (TLS_METHOD);
if (it != map_cpy.end()) sipaccount->setTlsMethod (it->second);
if (it != details.end()) sipaccount->setTlsMethod (it->second);
it = map_cpy.find (TLS_CIPHERS);
it = details.find (TLS_CIPHERS);
if (it != map_cpy.end()) sipaccount->setTlsCiphers (it->second);
if (it != details.end()) sipaccount->setTlsCiphers (it->second);
it = map_cpy.find (TLS_SERVER_NAME);
it = details.find (TLS_SERVER_NAME);
if (it != map_cpy.end()) sipaccount->setTlsServerName (it->second);
if (it != details.end()) sipaccount->setTlsServerName (it->second);
it = map_cpy.find (TLS_VERIFY_CLIENT);
it = details.find (TLS_VERIFY_CLIENT);
if (it != map_cpy.end()) sipaccount->setTlsVerifyClient ( (it->second == "true") ? true : false);
if (it != details.end()) sipaccount->setTlsVerifyClient (it->second == "true");
it = map_cpy.find (TLS_REQUIRE_CLIENT_CERTIFICATE);
it = details.find (TLS_REQUIRE_CLIENT_CERTIFICATE);
if (it != map_cpy.end()) sipaccount->setTlsRequireClientCertificate ( (it->second == "true") ? true : false);
if (it != details.end()) sipaccount->setTlsRequireClientCertificate (it->second == "true");
it = map_cpy.find (TLS_NEGOTIATION_TIMEOUT_SEC);
it = details.find (TLS_NEGOTIATION_TIMEOUT_SEC);
if (it != map_cpy.end()) sipaccount->setTlsNegotiationTimeoutSec (it->second);
if (it != details.end()) sipaccount->setTlsNegotiationTimeoutSec (it->second);
it = map_cpy.find (TLS_NEGOTIATION_TIMEOUT_MSEC);
it = details.find (TLS_NEGOTIATION_TIMEOUT_MSEC);
if (it != map_cpy.end()) sipaccount->setTlsNegotiationTimeoutMsec (it->second);
if (it != details.end()) sipaccount->setTlsNegotiationTimeoutMsec (it->second);
Manager::instance().saveConfig();
// Update account details to the client side
accountsChanged();
}
std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials (
......@@ -619,31 +616,6 @@ void ConfigurationManager::setIsAlwaysRecording(const bool& rec)
{
Manager::instance().setIsAlwaysRecording(rec);
}
/*
int32_t ConfigurationManager::getDialpad(void) {
return Manager::instance().getDialpad();
}
void ConfigurationManager::setDialpad(const bool& display) {
Manager::instance().setDialpad(display);
}
int32_t ConfigurationManager::getSearchbar(void) {
return Manager::instance().getSearchbar();
}
void ConfigurationManager::setSearchbar(void) {
Manager::instance().setSearchbar();
}
int32_t ConfigurationManager::getVolumeControls(void) {
return Manager::instance().getVolumeControls();
}
void ConfigurationManager::setVolumeControls(const bool& display) {
Manager::instance().setVolumeControls(display);
}
*/
int32_t ConfigurationManager::getHistoryLimit (void)
{
......@@ -655,40 +627,6 @@ void ConfigurationManager::setHistoryLimit (const int32_t& days)
Manager::instance().setHistoryLimit (days);
}
/*
void ConfigurationManager::setHistoryEnabled(void) {
Manager::instance().setHistoryEnabled();
}
std::string ConfigurationManager::getHistoryEnabled(void) {
return Manager::instance().getHistoryEnabled();
}
void ConfigurationManager::startHidden(void) {
Manager::instance().startHidden();
}
int32_t ConfigurationManager::isStartHidden(void) {
return Manager::instance().isStartHidden();
}
void ConfigurationManager::switchPopupMode(void) {
Manager::instance().switchPopupMode();
}
int32_t ConfigurationManager::popupMode(void) {
return Manager::instance().popupMode();
}
void ConfigurationManager::setNotify(void) {
Manager::instance().setNotify();
}
int32_t ConfigurationManager::getNotify(void) {
return Manager::instance().getNotify();
}
*/
void ConfigurationManager::setAudioManager (const int32_t& api)
{
Manager::instance().setAudioManager (api);
......@@ -784,23 +722,7 @@ std::map<std::string, std::string> ConfigurationManager::getShortcuts()
void ConfigurationManager::setShortcuts (
const std::map<std::string, std::string>& shortcutsMap)
{
std::map<std::string, std::string> map_cpy = shortcutsMap;
/*
std::map<std::string, std::string> map_cpy = shortcutsMap;
std::map<std::string, std::string>::iterator it;
for (int i = 0; i < (int)shortcutsKeys.size(); i++) {
std::string key = shortcutsKeys.at(i);
it = map_cpy.find(key);
if (it != shortcutsMap.end()) {
Manager::instance().setConfig("Shortcuts", key, it->second);
}
}
*/
Manager::instance().shortcutPreferences.setShortcuts (map_cpy);
Manager::instance().shortcutPreferences.setShortcuts (shortcutsMap);
Manager::instance().saveConfig();
}
......@@ -300,7 +300,7 @@ IAXVoIPLink::getIAXCall (const std::string& id)
void
IAXVoIPLink::sendRegister (Account *a) throw(VoipLinkException)
IAXVoIPLink::sendRegister (Account *a)
{
_debug ("IAX: Sending registration");
......
......@@ -89,7 +89,7 @@ class IAXVoIPLink : public VoIPLink
/**
* Send out registration
*/
virtual void sendRegister (Account *a) throw(VoipLinkException);
virtual void sendRegister (Account *a);
/**
* Destroy registration session
......
......@@ -157,7 +157,7 @@ ManagerImpl::sendRegister (const std::string& accountID , const int32_t& enable)
// Update the active field
Account* acc = getAccount (accountID);
acc->setEnabled (!!enable);
acc->setEnabled (enable);
acc->loadConfig();
Manager::instance().saveConfig();
......
......@@ -32,6 +32,7 @@
#include "sipaccount.h"
#include "manager.h"
#include "config.h"
#include <pwd.h>
#include <sstream>
#include <cassert>
......@@ -379,33 +380,33 @@ void SIPAccount::unserialize (Conf::MappingNode *map)
void SIPAccount::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]);
setEnabled ( (details[CONFIG_ACCOUNT_ENABLE] == "true"));
setRingtonePath (details[CONFIG_RINGTONE_PATH]);
setRingtoneEnabled ( (details[CONFIG_RINGTONE_ENABLED] == "true"));
setMailBox (details[CONFIG_ACCOUNT_MAILBOX]);
alias_ = details[CONFIG_ACCOUNT_ALIAS];
type_ = details[CONFIG_ACCOUNT_TYPE];
username_ = details[USERNAME];
hostname_ = details[HOSTNAME];
enabled_ = details[CONFIG_ACCOUNT_ENABLE] == "true";
ringtonePath_ = details[CONFIG_RINGTONE_PATH];
ringtoneEnabled_ = details[CONFIG_RINGTONE_ENABLED] == "true";
mailBox_ = details[CONFIG_ACCOUNT_MAILBOX];
// SIP specific account settings
// general sip settings
setDisplayName (details[DISPLAY_NAME]);
setServiceRoute (details[ROUTESET]);
setLocalInterface (details[LOCAL_INTERFACE]);
setPublishedSameasLocal (details[PUBLISHED_SAMEAS_LOCAL] == "true");
setPublishedAddress (details[PUBLISHED_ADDRESS]);
setLocalPort (atoi (details[LOCAL_PORT].c_str()));
setPublishedPort (atoi (details[PUBLISHED_PORT].c_str()));
setStunServer (details[STUN_SERVER]);
setStunEnabled (details[STUN_ENABLE] == "true");
setDtmfType ( (details[ACCOUNT_DTMF_TYPE] == "overrtp") ? OVERRTP : SIPINFO);
setResolveOnce (details[CONFIG_ACCOUNT_RESOLVE_ONCE] == "true");
setRegistrationExpire (details[CONFIG_ACCOUNT_REGISTRATION_EXPIRE]);
setUseragent (details[USERAGENT]);
displayName_ = details[DISPLAY_NAME];
serviceRoute_ = details[ROUTESET];
interface_ = details[LOCAL_INTERFACE];
publishedSameasLocal_ = details[PUBLISHED_SAMEAS_LOCAL] == "true";
publishedIpAddress_ = details[PUBLISHED_ADDRESS];
localPort_ = atoi (details[LOCAL_PORT].c_str());
publishedPort_ = atoi (details[PUBLISHED_PORT].c_str());
stunServer_ = details[STUN_SERVER];
stunEnabled_ = details[STUN_ENABLE] == "true";
dtmfType_ = details[ACCOUNT_DTMF_TYPE] == "overrtp" ? OVERRTP : SIPINFO;
resolveOnce_ = details[CONFIG_ACCOUNT_RESOLVE_ONCE] == "true";
registrationExpire_ = details[CONFIG_ACCOUNT_REGISTRATION_EXPIRE];
userAgent_ = details[USERAGENT];
// srtp settings
setSrtpEnable (details[SRTP_ENABLE] == "true");
......@@ -435,10 +436,10 @@ void SIPAccount::setAccountDetails (std::map<std::string, std::string> details)
setTlsNegotiationTimeoutSec (details[TLS_NEGOTIATION_TIMEOUT_SEC]);
setTlsNegotiationTimeoutMsec (details[TLS_NEGOTIATION_TIMEOUT_MSEC]);
if (getCredentialCount() == 0) { // credentials not set, construct 1 entry
if (credentials_.empty()) { // credentials not set, construct 1 entry
std::vector<std::map<std::string, std::string> > v;
std::map<std::string, std::string> map;
map[USERNAME] = getUsername();
map[USERNAME] = username_;
map[PASSWORD] = details[PASSWORD];
map[REALM] = "*";
v.push_back(map);
......@@ -485,7 +486,7 @@ std::map<std::string, std::string> SIPAccount::getAccountDetails() const
// Add sip specific details
a[ROUTESET] = getServiceRoute();
a[CONFIG_ACCOUNT_RESOLVE_ONCE] = isResolveOnce() ? "true" : "false";
a[USERAGENT] = getUserAgent();
a[USERAGENT] = userAgent_;
a[CONFIG_ACCOUNT_REGISTRATION_EXPIRE] = getRegistrationExpire();
a[LOCAL_INTERFACE] = getLocalInterface();
......@@ -677,17 +678,17 @@ void SIPAccount::loadConfig()
bool SIPAccount::fullMatch (const std::string& username, const std::string& hostname) const
{
return userMatch (username) && hostnameMatch (hostname);
return userMatch (username) and hostnameMatch (hostname);
}
bool SIPAccount::userMatch (const std::string& username) const
{
return !username.empty() && username == getUsername();
return !username.empty() and username == username_;
}
bool SIPAccount::hostnameMatch (const std::string& hostname) const
{
return hostname == getHostname();
return hostname == hostname_;
}
std::string SIPAccount::getMachineName (void) const
......@@ -881,18 +882,24 @@ std::string computeMd5HashFromCredential (
void SIPAccount::setCredentials (const std::vector<std::map<std::string, std::string> >& creds)
{
using std::vector;
using std::string;
using std::map;
bool md5HashingEnabled = Manager::instance().preferences.getMd5Hash();
std::vector< std::map<std::string, std::string> >::iterator it;
assert(creds.size() > 0); // we can not authenticate without credentials
credentials_ = creds;
/* md5 hashing */
for(it = credentials_.begin(); it != credentials_.end(); ++it) {
std::string username = (*it)[USERNAME];
std::string realm = (*it)[REALM];
std::string password = (*it)[PASSWORD];
for (vector<map<string, string> >::iterator it = credentials_.begin(); it != credentials_.end(); ++it) {
map<string, string>::const_iterator val = (*it).find(USERNAME);
const std::string username = val != (*it).end() ? val->second : "";
val = (*it).find(REALM);
const std::string realm (val != (*it).end() ? val->second : "");
val = (*it).find(PASSWORD);
const std::string password (val != (*it).end() ? val->second : "");
if (md5HashingEnabled) {
// TODO: Fix this.
......@@ -904,32 +911,36 @@ void SIPAccount::setCredentials (const std::vector<std::map<std::string, std::st
// the configuration file. This is to avoid to
// re-hash a hashed password.
if (password.length() != 32) {
if (password.length() != 32)
(*it)[PASSWORD] = computeMd5HashFromCredential(username, password, realm);
}
}
}
std::string digest;
size_t n = getCredentialCount();
// Create the credential array
delete[] cred_;
cred_ = new pjsip_cred_info[n];
unsigned i;
for (i = 0; i < n; i++) {
const std::string &password = credentials_[i][PASSWORD];
int dataType = (md5HashingEnabled && password.length() == 32)
cred_ = new pjsip_cred_info[credentials_.size()];
size_t i = 0;
for (vector<map<string, string > >::const_iterator iter = credentials_.begin();
iter != credentials_.end(); ++iter) {
map<string, string>::const_iterator val = (*iter).find(PASSWORD);
const std::string password = val != (*iter).end() ? val->second : "";
int dataType = (md5HashingEnabled and password.length() == 32)
? PJSIP_CRED_DATA_DIGEST
: PJSIP_CRED_DATA_PLAIN_PASSWD;
cred_[i].username = pj_str ((char*)credentials_[i][USERNAME].c_str());
cred_[i].data = pj_str ((char*)password.c_str());
cred_[i].realm = pj_str ((char*)credentials_[i][REALM].c_str());
val = (*iter).find(USERNAME);
if (val != (*iter).end())
cred_[i].username = pj_str ((char*) val->second.c_str());
cred_[i].data = pj_str ((char*) password.c_str());
val = (*iter).find(REALM);
if (val != (*iter).end())
cred_[i].realm = pj_str ((char*) val->second.c_str());
cred_[i].data_type = dataType;
cred_[i].scheme = pj_str ( (char*) "digest");
++i;
}
}
......@@ -937,3 +948,13 @@ const std::vector<std::map<std::string, std::string> > &SIPAccount::getCredentia
{
return credentials_;
}
std::string SIPAccount::getUserAgentName() const
{
std::string result(userAgent_);
if (result == "sflphone" or result.empty())
result += "/" PACKAGE_VERSION;
return result;
}
......@@ -125,6 +125,7 @@ class SIPAccount : public Account
* Virtual destructor
*/
virtual ~SIPAccount();
std::string getUserAgentName() const;
void setRegistrationStateDetailed (const std::pair<int, std::string> &details) { registrationStateDetailed_ = details; }
virtual void serialize (Conf::YamlEmitter *emitter);
......@@ -190,9 +191,6 @@ class SIPAccount : public Account
bool isResolveOnce (void) const {
return resolveOnce_;
}
void setResolveOnce (bool reslv) {
resolveOnce_ = reslv;
}
/**
* A client sendings a REGISTER request MAY suggest an expiration
......
......@@ -361,13 +361,13 @@ SIPVoIPLink::getEvent()
}
void SIPVoIPLink::sendRegister (Account *a) throw(VoipLinkException)
void SIPVoIPLink::sendRegister (Account *a)
{
pj_status_t status;
pjsip_tx_data *tdata;
pjsip_hdr hdr_list;
SIPAccount *account = (SIPAccount*)a;
SIPAccount *account = static_cast<SIPAccount*>(a);
// Resolve hostname here and keep its
// IP address for the whole time the
......@@ -461,7 +461,7 @@ void SIPVoIPLink::sendRegister (Account *a) throw(VoipLinkException)
ss << port;
ss >> portStr;
std::string contactUri = account->getContactHeader (address, portStr);
std::string contactUri(account->getContactHeader (address, portStr));
_debug ("UserAgent: sendRegister: fromUri: %s serverUri: %s contactUri: %s",
fromUri.c_str(),
......@@ -497,7 +497,7 @@ void SIPVoIPLink::sendRegister (Account *a) throw(VoipLinkException)
// Add User-Agent Header
pj_list_init (&hdr_list);
const std::string &agent = getUseragentName (account);
const std::string agent(account->getUserAgentName());
pj_str_t useragent = pj_str ((char*)agent.c_str());
pjsip_generic_string_hdr *h = pjsip_generic_string_hdr_create (_pool, &STR_USER_AGENT, &useragent);
......@@ -1152,18 +1152,6 @@ SIPVoIPLink::getCurrentCodecName(Call *call)
return "";
}
std::string SIPVoIPLink::getUseragentName (SIPAccount *account)
{
std::ostringstream useragent;
useragent << account->getUserAgent();
if (useragent.str() == "sflphone" || useragent.str() == "")
useragent << "/" << PACKAGE_VERSION;
return useragent.str ();
}
bool
SIPVoIPLink::carryingDTMFdigits (const std::string& id, char code)
{
......@@ -1297,7 +1285,6 @@ SIPVoIPLink::SIPStartCall (SIPCall* call)
return false;
}
// Creates URI
std::string fromUri = account->getFromUri();
std::string toUri = call->getPeerNumber(); // expecting a fully well formed sip uri
......@@ -1310,7 +1297,7 @@ SIPVoIPLink::SIPStartCall (SIPCall* call)
ss << port;
ss >> portStr;
std::string contactUri = account->getContactHeader (address, portStr);
std::string contactUri(account->getContactHeader (address, portStr));
_debug ("UserAgent: FROM uri: %s, TO uri: %s, CONTACT uri: %s",
fromUri.c_str(), toUri.c_str(), contactUri.c_str());
......@@ -1559,7 +1546,7 @@ bool SIPVoIPLink::SIPNewIpToIpCall (const std::string& id, const std::string& to
ss << port;
ss >> portStr;
std::string contactUri = account->getContactHeader (address, portStr);
std::string contactUri(account->getContactHeader (address, portStr));
_debug ("UserAgent: FROM uri: %s, TO uri: %s, CONTACT uri: %s",
fromUri.c_str(), toUri.c_str(), contactUri.c_str());
......
......@@ -121,7 +121,7 @@ class SIPVoIPLink : public VoIPLink
/**
* Build and send SIP registration request
*/
virtual void sendRegister (Account *a) throw(VoipLinkException);
virtual void sendRegister (Account *a);
/**
* Build and send SIP unregistration request
......@@ -272,7 +272,7 @@ class SIPVoIPLink : public VoIPLink
/**
* Retrive useragent name from account
*/
std::string getUseragentName (SIPAccount *);
std::string getUseragentName (SIPAccount *) const;
/**
* List all the interfaces on the system and return
......
......@@ -93,7 +93,7 @@ class VoIPLink
* Virtual method
* Build and send account registration request
*/
virtual void sendRegister (Account *a) throw (VoipLinkException) = 0;
virtual void sendRegister (Account *a) = 0;
/**
* Virtual method
......
Supports Markdown
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