Commit fd8e77db authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3650] Add configuration preferences

parent 064d0bfa
......@@ -203,22 +203,28 @@ void sflphone_fill_account_list (void) {
gchar** array;
gchar** accountID;
unsigned int i;
int count;
GQueue *codeclist;
DEBUG("SFLphone: Fill account list");
int count;
GQueue *codeclist;
count = current_account_get_message_number ();
DEBUG("SFLphone: Fill account list");
count = current_account_get_message_number ();
account_list_clear ();
array = (gchar **)dbus_account_list();
if(array)
{
/*
if(!(*accountID))
DEBUG("hhhhhhhhhmmmmmmmmmmmm");
*/
for (accountID = array; *accountID; accountID++)
{
account_t * a = g_new0(account_t,1);
a->accountID = g_strdup(*accountID);
DEBUG("------------------- Account ID %s", a->accountID);
a->credential_information = NULL;
// TODO Clean codec list QUEUE
account_list_add(a);
......
......@@ -893,6 +893,8 @@ dbus_account_details(gchar * accountID)
GError *error = NULL;
GHashTable * details;
DEBUG("Dbus: Get account detail accountid %s", accountID);
if (!org_sflphone_SFLphone_ConfigurationManager_get_account_details(
configurationManagerProxy, accountID, &details, &error))
{
......
accounts:
- id: IP2IP
alias:
alias: ip2ip
username:
password:
hostname:
......@@ -27,6 +27,7 @@ accounts:
helloHashEnabled: false
notSuppWarning: false
tls:
tlsPort: 5061
certificate:
calist:
ciphers:
......@@ -40,27 +41,61 @@ accounts:
verifyClient: false
verifyServer: false
- id: 1234
- id: Account:1278342101
alias: sfl-181
username: 181
password: sfl-181pw
hostname: sflphone.org
hostname: 192.168.50.3
enable: true
type: SIP
expire: 3600
interface: default
port: 5060
mailbox: 97
publishAddr: 192.168.50.182
publishPort: 5060
sameasLocal: true
resolveOnce: false
codecs: 0/9/110/111/112/
credential:
count: 0
srtp:
enable: true
keyExchange: sdes
rtpFallback: true
zrtp:
displaySas: false
displaySasOnce: false
helloHashEnabled: false
notSuppWarning: false
tls:
tlsPort: 5061
certificate: /home/msavard/Development/sflphone/sflphone-client-gnome/config.guess
calist: /home/msavard/Development/sflphone/sflphone-client-gnome/aclocal.m4
ciphers:
enable: true
method: TLSv1
timeout: 0
password:
privateKey: /home/msavard/Development/sflphone/sflphone-client-gnome/config.log
requireCertif: true
server:
verifyClient: true
verifyServer: true
- id: 2345
- id: Account:1278343345
alias: sfl-431
username: 431
password: alexandre
hostname: 192.168.50.3
enable: true
enable: false
type: SIP
expire: 3600
interface: lo
port: 5065
port: 5060
mailbox: 97
publishAddr: 127.0.0.1
publishPort: 5065
publishAddr: 192.168.50.182
publishPort: 5060
sameasLocal: true
resolveOnce: false
codecs: 0/9/110/111/112/
......@@ -71,23 +106,24 @@ accounts:
keyExchange: sdes
rtpFallback: true
zrtp:
displaySas: true
displaySas: false
displaySasOnce: false
helloHashEnabled: true
notSuppWarning: true
helloHashEnabled: false
notSuppWarning: false
tls:
tlsPort: 5061
certificate: /home/msavard/Development/sflphone/sflphone-client-gnome/config.guess
calist: /home/msavard/Development/sflphone/sflphone-client-gnome/aclocal.m4
ciphers:
enable: true
enable: false
method: TLSv1
timeout: 0
password:
privateKey: /home/msavard/Development/sflphone/sflphone-client-gnome/config.log
requireCertif: true
server:
verifyClient: true
verifyServer: true
verifyClient: false
verifyServer: false
addressbook:
photo: false
......@@ -124,27 +160,26 @@ hooks:
urlSipField: X-sflphone-url
preferences:
order: 1234/2345
audioapi: 0
dialpaddisplay: 0
historyenabled: 1
historylimit: 30
historymaxCalls: 20
notifyall: true
notifymails: false
order: 1234/2345/
audioApi: 0
dialpadDisplay: 0
historyEnabled: 1
historyLimit: 30
historyMaxCalls: 20
notifyAll: true
notifyMails: false
zoneToneChoice: North America
registrationexpire: 180
ringtonesenable: true
portnum: 5060
searchbardisplay: true
starthidden: 0
volumedisplay: 0
windowheight: 332
windowpopup: 0
windowposition: 0
windowposition: 24
windowwidth: 240
zeroconfenable: false
registrationExpire: 180
ringtoneEnabled: true
portNum: 5060
searchBarDisplay: true
startHidden: 0
volumeDisplay: 0
windowHeight: 332
windowPopup: 0
windowPosition: 0
windowWidth: 240
zeroConfenable: false
md5Hash: false
voiplink:
......
......@@ -10,6 +10,7 @@ sflphoned_SOURCES = \
conference.cpp \
voiplink.cpp \
main.cpp \
preferences.cpp \
managerimpl.cpp \
managerimpl_registration.cpp \
observer.cpp \
......@@ -47,6 +48,7 @@ noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = \
conference.h \
voiplink.h \
preferences.h \
managerimpl.h \
manager.h \
global.h \
......
......@@ -432,19 +432,23 @@ void YamlParser::mainNativeDataMapping(MappingNode *map) {
// _debug("Iterating: %s", iter->first.c_str());
if(accounts.compare(iter->first) == 0) {
// buildAccounts((SequenceNode *)(iter->second));
accountSequence = (SequenceNode *)(iter->second);
}
else if(addressbook.compare(iter->first) == 0);
// _debug("ok");
else if(audio.compare(iter->first) == 0);
// _debug("ok");
else if(hooks.compare(iter->first) == 0);
// _debug("ok");
else if(preferences.compare(iter->first) == 0);
// _debug("ok");
else if(voiplink.compare(iter->first) == 0);
// _debug("ok");
else if(addressbook.compare(iter->first) == 0) {
addressbookSequence = (SequenceNode *)(iter->second);
}
else if(audio.compare(iter->first) == 0) {
audioSequence = (SequenceNode *)(iter->second);
}
else if(hooks.compare(iter->first) == 0) {
hooksSequence = (SequenceNode *)(iter->second);
}
else if(preferences.compare(iter->first) == 0) {
preferenceSequence = (SequenceNode *)(iter->second);
}
else if(voiplink.compare(iter->first) == 0) {
voiplinkSequence = (SequenceNode *)(iter->second);
}
else
throw YamlParserException("Unknow map key in configuration");
......
......@@ -80,6 +80,16 @@ class YamlParser {
SequenceNode *getAccountSequence(void) { return accountSequence; };
SequenceNode *getPreferenceSequence(void) { return preferenceSequence; }
SequenceNode *getAddressbookSequence(void) { return preferenceSequence; }
SequenceNode *getAudioSequence(void) { return preferenceSequence; }
SequenceNode *getHooksSequence(void) { return preferenceSequence; }
SequenceNode *getVoiplinkSequence(void) { return preferenceSequence; }
private:
/**
......@@ -131,6 +141,16 @@ class YamlParser {
SequenceNode *accountSequence;
SequenceNode *preferenceSequence;
SequenceNode *addressbookSequence;
SequenceNode *audioSequence;
SequenceNode *hooksSequence;
SequenceNode *voiplinkSequence;
};
}
......
......@@ -50,7 +50,9 @@ ConfigurationManager::ConfigurationManager(DBus::Connection& connection) :
std::map<std::string, std::string> ConfigurationManager::getAccountDetails(
const std::string& accountID) {
return Manager::instance().getAccountDetails(accountID);
_debug("ConfigurationManager: get account details %s", accountID.c_str());
return Manager::instance().getAccountDetails(accountID);
}
std::map<std::string, std::string> ConfigurationManager::getTlsSettingsDefault(
......
......@@ -3281,25 +3281,35 @@ std::vector<std::string> ManagerImpl::getAccountList () {
std::vector<std::string> account_order;
unsigned int i;
_debug("Manager: Get account list");
account_order = loadAccountOrder();
AccountMap::iterator iter;
// The IP2IP profile is always available, and first in the list
iter = _accountMap.find(IP2IP_PROFILE);
if (iter->second != NULL)
v.push_back(iter->first.data());
if (iter->second != NULL) {
_debug("PUSHING BACK %s", iter->first.c_str());
// v.push_back(iter->first.data());
v.push_back(iter->second->getAccountID());
}
else {
_error("Manager: could not find IP2IP profile in getAccount list");
}
// If no order has been set, load the default one
// ie according to the creation date.
if (account_order.size() == 0) {
_debug("Manager: account order is empty");
iter = _accountMap.begin();
while (iter != _accountMap.end()) {
if (iter->second != NULL && iter->first != IP2IP_PROFILE) {
//_debug("PUSHING BACK %s\n", iter->first.c_str());
v.push_back(iter->first.data());
_debug("PUSHING BACK %s", iter->first.c_str());
// v.push_back(iter->first.data());
v.push_back(iter->second->getAccountID());
}
iter++;
......@@ -3309,14 +3319,16 @@ std::vector<std::string> ManagerImpl::getAccountList () {
// Otherelse, load the custom one
// ie according to the saved order
else {
_debug("Manager: Load account list according to preferences");
for (i = 0; i < account_order.size(); i++) {
// This account has not been loaded, so we ignore it
if ((iter = _accountMap.find(account_order[i]))
!= _accountMap.end()) {
// If the account is valid
if (iter->second != NULL && iter->first != IP2IP_PROFILE) {
v.push_back(iter->first.data());
_debug("PUSHING BACK %s\n", iter->first.c_str());
// v.push_back(iter->first.data());
v.push_back(iter->second->getAccountID());
}
}
}
......@@ -3329,10 +3341,12 @@ std::map<std::string, std::string> ManagerImpl::getAccountDetails (
const AccountID& accountID) {
std::map<std::string, std::string> a;
_debug("getAccountDetails %s", accountID.c_str());
Account * account = _accountMap[accountID];
if (account == NULL) {
_debug ("Cannot getAccountDetails on a non-existing accountID %s. Defaults will be used.", accountID.c_str());
_debug ("Cannot getAccountDetails on a non-existing accountID %s. Defaults will be used.", accountID.c_str());
}
a.insert(std::pair<std::string, std::string>(ACCOUNT_ID, accountID));
......@@ -3981,7 +3995,11 @@ std::vector<std::string> ManagerImpl::loadAccountOrder (void) {
std::string account_list;
std::vector<std::string> account_vect;
account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER);
Conf::Key accountOrder("order");
// account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER);
account_list = preferences.getAccountOrder();
return unserialize(account_list);
}
......@@ -3989,8 +4007,7 @@ short ManagerImpl::loadAccountMap () {
_debug ("Manager: Loading account map");
int nbAccount = buildAccounts();
int nbAccount = buildConfiguration();
/*
short nbAccount = 0;
......@@ -4072,11 +4089,11 @@ short ManagerImpl::loadAccountMap () {
return nbAccount;
}
short ManagerImpl::buildAccounts() {
short ManagerImpl::buildConfiguration() {
_debug("Manager: Build Accounts");
Conf::YamlParser *parser;
// Conf::YamlParser *parser;
Account *tmpAccount = NULL;
int nbAccount = 0;
......@@ -4092,9 +4109,12 @@ short ManagerImpl::buildAccounts() {
}
catch (Conf::YamlParserException &e) {
_error("ConfigTree: %s", e.what());
_error("Manager: %s", e.what());
}
// build preferences
preferences.unserialize((Conf::MappingNode *)(parser->getAccountSequence()));
Conf::SequenceNode *seq = parser->getAccountSequence();
// Each element in sequence is a new account to create
......@@ -4164,9 +4184,17 @@ short ManagerImpl::buildAccounts() {
tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountid);
}
tmpAccount->unserialize(map);
_debug("ok");
if (tmpAccount != NULL) {
try {
tmpAccount->unserialize(map);
}
catch(SipAccountException &e) {
_error("Manager: %s", e.what());
}
_debug ("Manager: Loading account %s ", accountid.c_str());
_accountMap[accountid] = tmpAccount;
// tmpAccount->setVoIPLink(SIPVoIPLink::instance (""));
......
......@@ -56,6 +56,7 @@
#include "audio/mainbuffer.h"
#include "yamlparser.h"
#include "preferences.h"
class AudioLayer;
class GuiFramework;
......@@ -113,7 +114,7 @@ class ManagerImpl {
~ManagerImpl (void);
short buildAccounts();
short buildConfiguration();
/**
* Initialisation of thread (sound) and map.
......@@ -1344,6 +1345,10 @@ private:
*/
void check_call_configuration (const CallID& id, const std::string& to, Call::CallConfiguration *callConfig);
Conf::YamlParser *parser;
Preferences preferences;
#ifdef TEST
bool testCallAccountMap();
bool testAccountMap();
......
......@@ -126,96 +126,107 @@ void SIPAccount::unserialize(Conf::MappingNode *map)
_debug("SipAccount: Unserialize");
val = (Conf::ScalarNode *)(map->getValue(aliasKey));
_alias = val->getValue();
if(val) { _alias = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(typeKey));
_type = val->getValue();
if(val) { _type = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(idKey));
_accountID = val->getValue();
if(val) { _accountID = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(usernameKey));
_username = val->getValue();
if(val) { _username = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(passwordKey));
_password = val->getValue();
if(val) { _password = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(hostnameKey));
_hostname = val->getValue();
_debug("------------------------------------- hostname from config: %s, %s", _accountID.c_str(), val->getValue().c_str());
if(val) { _hostname = val->getValue(); val = NULL; }
_debug("------------------------------------- hostname from config: %s, %s", _accountID.c_str(), _hostname.c_str());
val = (Conf::ScalarNode *)(map->getValue(accountEnableKey));
_enabled = (val->getValue().compare("true") == 0) ? true : false;
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) { val = NULL; }
// _codecOrder = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(expireKey));
_registrationExpire = val->getValue();
if(val) { _registrationExpire = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(interfaceKey));
_interface = val->getValue();
if(val) { _interface = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(portKey));
_localPort = atoi(val->getValue().data());
if(val) { _localPort = atoi(val->getValue().data()); val = NULL; }
// val = (Conf::ScalarNode *)(map->getValue(mailboxKey));
val = (Conf::ScalarNode *)(map->getValue(publishAddrKey));
_publishedIpAddress = val->getValue();
if(val) { _publishedIpAddress = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(publishPortKey));
_publishedPort = atoi(val->getValue().data());
if(val) { _publishedPort = atoi(val->getValue().data()); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(sameasLocalKey));
_publishedSameasLocal = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _publishedSameasLocal = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(resolveOnceKey));
_resolveOnce = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _resolveOnce = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(dtmfTypeKey));
if(val) { val = NULL; }
// _dtmfType = atoi(val->getValue();
// stun enabled
// get srtp submap
srtpMap = (Conf::MappingNode *)(map->getValue(srtpKey));
if(!srtpMap)
throw SipAccountException(" did not found srtp map");
val = (Conf::ScalarNode *)(srtpMap->getValue(srtpEnableKey));
_srtpEnabled = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _srtpEnabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(srtpMap->getValue(keyExchangeKey));
_srtpKeyExchange = val->getValue();
if(val) { _srtpKeyExchange = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(srtpMap->getValue(rtpFallbackKey));
_srtpFallback = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _srtpFallback = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
// get zrtp submap
zrtpMap = (Conf::MappingNode *)(map->getValue(zrtpKey));
if(!zrtpMap)
throw SipAccountException(" did not found zrtp map");
val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasKey));
_zrtpDisplaySas = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _zrtpDisplaySas = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasOnceKey));
_zrtpDisplaySasOnce = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _zrtpDisplaySasOnce = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(zrtpMap->getValue(helloHashEnabledKey));
_zrtpHelloHash = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _zrtpHelloHash = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(zrtpMap->getValue(notSuppWarningKey));
_zrtpNotSuppWarning = (val->getValue().compare("true") == 0) ? true : false;
if(val) { _zrtpNotSuppWarning = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
// get tls submap
tlsMap = (Conf::MappingNode *)(map->getValue(tlsKey));
if(!tlsMap)
throw SipAccountException(" did not found tls map");
val = (Conf::ScalarNode *)(tlsMap->getValue(tlsEnableKey));
_tlsEnable = val->getValue();
if(val) { _tlsEnable = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(tlsMap->getValue(tlsPortKey));
_tlsPortStr = val->getValue();
if(val) { _tlsPortStr = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(tlsMap->getValue(certificateKey));
_tlsCertificateFile = val->getValue();
if(val) { _tlsCertificateFile = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(tlsMap->getValue(calistKey));
_tlsCaListFile = val->getValue();
if(val) { _tlsCaListFile = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(tlsMap->getValue(ciphersKey));
_tlsCiphers = val->getValue();
if(val) { _tlsCiphers = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(tlsMap->getValue(methodKey));
_tlsMethod = val->getValue();