Commit ba58d452 authored by Alexandre Savard's avatar Alexandre Savard

[#3649] Migrate hook configuration to new config

parent 7601339d
...@@ -3736,6 +3736,8 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, ...@@ -3736,6 +3736,8 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
sipaccount->setLocalPort(atoi(localPort.data())); sipaccount->setLocalPort(atoi(localPort.data()));
sipaccount->setPublishedPort(atoi(publishedPort.data())); sipaccount->setPublishedPort(atoi(publishedPort.data()));
// sipaccount->setStunServerName // sipaccount->setStunServerName
// sipaccount->setStunServer();
// sipaccount->setStunEnable();
sipaccount->setResolveOnce((resolveOnce.compare("true")==0) ? true : false); sipaccount->setResolveOnce((resolveOnce.compare("true")==0) ? true : false);
sipaccount->setRegistrationExpire(registrationExpire); sipaccount->setRegistrationExpire(registrationExpire);
...@@ -3746,8 +3748,8 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, ...@@ -3746,8 +3748,8 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
// setConfig(accountID, PUBLISHED_ADDRESS, publishedAddress); // setConfig(accountID, PUBLISHED_ADDRESS, publishedAddress);
// setConfig(accountID, LOCAL_PORT, localPort); // setConfig(accountID, LOCAL_PORT, localPort);
// setConfig(accountID, PUBLISHED_PORT, publishedPort); // setConfig(accountID, PUBLISHED_PORT, publishedPort);
setConfig(accountID, STUN_ENABLE, stunEnable); // setConfig(accountID, STUN_ENABLE, stunEnable);
setConfig(accountID, STUN_SERVER, stunServer); // setConfig(accountID, STUN_SERVER, stunServer);
// setConfig(accountID, ACCOUNT_DTMF_TYPE, dtmfType); // setConfig(accountID, ACCOUNT_DTMF_TYPE, dtmfType);
// setConfig(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce); // setConfig(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce);
// setConfig(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire); // setConfig(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire);
...@@ -3759,7 +3761,7 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, ...@@ -3759,7 +3761,7 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
setConfig(accountID, REALM, realm); setConfig(accountID, REALM, realm);
// setConfig(accountID, USERAGENT, ua_name); // setConfig(accountID, USERAGENT, ua_name);
setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName); // setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName);
sipaccount->setUseragent(ua_name); sipaccount->setUseragent(ua_name);
...@@ -3849,23 +3851,25 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, ...@@ -3849,23 +3851,25 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
// setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_MSEC,tlsNegotiationTimeoutMsec); // setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_MSEC,tlsNegotiationTimeoutMsec);
if (!getMd5CredentialHashing()) { if (!getMd5CredentialHashing()) {
setConfig(accountID, PASSWORD, password); // setConfig(accountID, PASSWORD, password);
sipaccount->setPassword(password);
} else { } else {
// Make sure not to re-hash the password field if // Make sure not to re-hash the password field if
// it is already saved as a MD5 Hash. // it is already saved as a MD5 Hash.
// TODO: This test is weak. Fix this. // TODO: This test is weak. Fix this.
if ((password.compare(getConfigString(accountID, PASSWORD)) != 0)) { // if ((password.compare(getConfig(accountID, PASSWORD)) != 0)) {
if ((password.compare(sipaccount->getPassword()) != 0)) {
_debug ("Password sent and password from config are different. Re-hashing"); _debug ("Password sent and password from config are different. Re-hashing");
std::string hash; std::string hash;
if (authenticationName.empty()) { if (authenticationName.empty()) {
hash = computeMd5HashFromCredential(username, password, realm); hash = computeMd5HashFromCredential(username, password, realm);
} else { } else {
hash = computeMd5HashFromCredential(authenticationName, hash = computeMd5HashFromCredential(authenticationName, password, realm);
password, realm);
} }
setConfig(accountID, PASSWORD, hash); // setConfig(accountID, PASSWORD, hash);
sipaccount->setPassword(hash);
} }
} }
...@@ -3876,9 +3880,7 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, ...@@ -3876,9 +3880,7 @@ void ManagerImpl::setAccountDetails (const std::string& accountID,
Account * acc = NULL; Account * acc = NULL;
acc = getAccount(accountID); acc = getAccount(accountID);
if (acc != NULL) { if (acc != NULL) {
// acc->loadConfig(); // acc->loadConfig();
if (acc->isEnabled()) { if (acc->isEnabled()) {
...@@ -3938,7 +3940,8 @@ std::string ManagerImpl::addAccount ( ...@@ -3938,7 +3940,8 @@ std::string ManagerImpl::addAccount (
newAccountID += "/"; newAccountID += "/";
// Prepend the new account // Prepend the new account
account_list.insert(0, newAccountID); account_list.insert(0, newAccountID);
setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list); // setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list);
preferences.setAccountOrder(account_list);
} }
saveConfig(); saveConfig();
...@@ -3950,11 +3953,17 @@ std::string ManagerImpl::addAccount ( ...@@ -3950,11 +3953,17 @@ std::string ManagerImpl::addAccount (
} }
void ManagerImpl::deleteAllCredential (const AccountID& accountID) { void ManagerImpl::deleteAllCredential (const AccountID& accountID) {
int numberOfCredential = getConfigInt(accountID, CONFIG_CREDENTIAL_NUMBER);
Account *account = getAccount(accountID);
if(account->getType() != "SIP")
return;
int i; SIPAccount *sipaccount = (SIPAccount *)account;
for (i = 0; i < numberOfCredential; i++) { int numberOfCredential = getConfigInt(accountID, CONFIG_CREDENTIAL_NUMBER);
for (int i = 0; i < numberOfCredential; i++) {
std::string credentialIndex; std::string credentialIndex;
std::stringstream streamOut; std::stringstream streamOut;
streamOut << i; streamOut << i;
...@@ -3966,7 +3975,8 @@ void ManagerImpl::deleteAllCredential (const AccountID& accountID) { ...@@ -3966,7 +3975,8 @@ void ManagerImpl::deleteAllCredential (const AccountID& accountID) {
} }
if (accountID.empty() == false) { if (accountID.empty() == false) {
setConfig(accountID, CONFIG_CREDENTIAL_NUMBER, 0); // setConfig(accountID, CONFIG_CREDENTIAL_NUMBER, 0);
} }
} }
...@@ -4456,6 +4466,15 @@ std::map<std::string, std::string> ManagerImpl::getHookSettings () { ...@@ -4456,6 +4466,15 @@ std::map<std::string, std::string> ManagerImpl::getHookSettings () {
std::map<std::string, std::string> settings; std::map<std::string, std::string> settings;
settings.insert(std::pair<std::string, std::string>("URLHOOK_IAX2_ENABLED", hookPreference.getIax2Enabled() ? "true" : "false"));
settings.insert(std::pair<std::string, std::string>("PHONE_NUMBER_HOOK_ADD_PREFIX", hookPreference.getNumberAddPrefix()));
settings.insert(std::pair<std::string, std::string>("PHONE_NUMBER_HOOK_ENABLED", hookPreference.getNumberEnabled() ? "true" : "false"));
settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_ENABLED", hookPreference.getSipEnabled() ? "true" : "false"));
settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND", hookPreference.getUrlCommand()));
settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD", hookPreference.getUrlSipField()));
/*
settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD", settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD",
getConfigString(HOOKS, URLHOOK_SIP_FIELD))); getConfigString(HOOKS, URLHOOK_SIP_FIELD)));
settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND", settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND",
...@@ -4471,12 +4490,21 @@ std::map<std::string, std::string> ManagerImpl::getHookSettings () { ...@@ -4471,12 +4490,21 @@ std::map<std::string, std::string> ManagerImpl::getHookSettings () {
"PHONE_NUMBER_HOOK_ADD_PREFIX", getConfigString(HOOKS, "PHONE_NUMBER_HOOK_ADD_PREFIX", getConfigString(HOOKS,
PHONE_NUMBER_HOOK_ADD_PREFIX))); PHONE_NUMBER_HOOK_ADD_PREFIX)));
*/
return settings; return settings;
} }
void ManagerImpl::setHookSettings ( void ManagerImpl::setHookSettings (const std::map<std::string, std::string>& settings) {
const std::map<std::string, std::string>& settings) {
hookPreference.setIax2Enabled((settings.find("URLHOOK_IAX2_ENABLED")->second == "true") ? true : false);
hookPreference.setNumberAddPrefix(settings.find("PHONE_NUMBER_HOOK_ADD_PREFIX")->second);
hookPreference.setNumberEnabled((settings.find("PHONE_NUMBER_HOOK_ENABLED")->second == "true") ? true : false);
hookPreference.setSipEnabled((settings.find("URLHOOK_SIP_ENABLED")->second == "true") ? true : false);
hookPreference.setUrlCommand(settings.find("URLHOOK_COMMAND")->second);
hookPreference.setUrlSipField(settings.find("URLHOOK_SIP_FIELD")->second);
/*
setConfig(HOOKS, URLHOOK_SIP_FIELD, setConfig(HOOKS, URLHOOK_SIP_FIELD,
(*settings.find("URLHOOK_SIP_FIELD")).second); (*settings.find("URLHOOK_SIP_FIELD")).second);
setConfig(HOOKS, URLHOOK_COMMAND, setConfig(HOOKS, URLHOOK_COMMAND,
...@@ -4489,6 +4517,7 @@ void ManagerImpl::setHookSettings ( ...@@ -4489,6 +4517,7 @@ void ManagerImpl::setHookSettings (
"PHONE_NUMBER_HOOK_ENABLED")).second); "PHONE_NUMBER_HOOK_ENABLED")).second);
setConfig(HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX, (*settings.find( setConfig(HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX, (*settings.find(
"PHONE_NUMBER_HOOK_ADD_PREFIX")).second); "PHONE_NUMBER_HOOK_ADD_PREFIX")).second);
*/
// Write it to the configuration file // Write it to the configuration file
saveConfig(); saveConfig();
......
...@@ -254,7 +254,7 @@ void AddressbookPreference::unserialize(Conf::MappingNode *map) ...@@ -254,7 +254,7 @@ void AddressbookPreference::unserialize(Conf::MappingNode *map)
HookPreference::HookPreference() : _iax2Enabled(false) HookPreference::HookPreference() : _iax2Enabled(false)
, _numberAddPrefix(false) , _numberAddPrefix("")
, _numberEnabled(false) , _numberEnabled(false)
, _sipEnabled(false) , _sipEnabled(false)
, _urlCommand("x-www-browser") , _urlCommand("x-www-browser")
...@@ -272,7 +272,7 @@ void HookPreference::serialize(Conf::YamlEmitter *emitter) ...@@ -272,7 +272,7 @@ void HookPreference::serialize(Conf::YamlEmitter *emitter)
Conf::MappingNode preferencemap(NULL); Conf::MappingNode preferencemap(NULL);
Conf::ScalarNode iax2Enabled(_iax2Enabled ? "true" : "false"); Conf::ScalarNode iax2Enabled(_iax2Enabled ? "true" : "false");
Conf::ScalarNode numberAddPrefix(_numberAddPrefix ? "true" : "false"); Conf::ScalarNode numberAddPrefix(_numberAddPrefix);
Conf::ScalarNode numberEnabled(_numberEnabled ? "true" : "false"); Conf::ScalarNode numberEnabled(_numberEnabled ? "true" : "false");
Conf::ScalarNode sipEnabled(_sipEnabled ? "true" : "false"); Conf::ScalarNode sipEnabled(_sipEnabled ? "true" : "false");
Conf::ScalarNode urlCommand(_urlCommand); Conf::ScalarNode urlCommand(_urlCommand);
...@@ -297,7 +297,7 @@ void HookPreference::unserialize(Conf::MappingNode *map) ...@@ -297,7 +297,7 @@ void HookPreference::unserialize(Conf::MappingNode *map)
val = (Conf::ScalarNode *)(map->getValue(iax2EnabledKey)); val = (Conf::ScalarNode *)(map->getValue(iax2EnabledKey));
if(val) { _iax2Enabled = (val->getValue() == "true") ? true : false; val = NULL; } if(val) { _iax2Enabled = (val->getValue() == "true") ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(numberAddPrefixKey)); val = (Conf::ScalarNode *)(map->getValue(numberAddPrefixKey));
if(val) { _numberAddPrefix = (val->getValue() == "true") ? true : false; val = NULL; } if(val) { _numberAddPrefix = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(numberEnabledKey)); val = (Conf::ScalarNode *)(map->getValue(numberEnabledKey));
if(val) { _numberEnabled = (val->getValue() == "true") ? true : false; val = NULL; } if(val) { _numberEnabled = (val->getValue() == "true") ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(sipEnabledKey)); val = (Conf::ScalarNode *)(map->getValue(sipEnabledKey));
......
...@@ -261,8 +261,8 @@ class HookPreference : public Serializable { ...@@ -261,8 +261,8 @@ class HookPreference : public Serializable {
bool getIax2Enabled(void) { return _iax2Enabled; } bool getIax2Enabled(void) { return _iax2Enabled; }
void setIax2Enabled( bool i) { _iax2Enabled = i; } void setIax2Enabled( bool i) { _iax2Enabled = i; }
bool getNumberAddPrefix(void) { return _numberAddPrefix; } std::string getNumberAddPrefix(void) { return _numberAddPrefix; }
void setNumberAddPrefix(bool n) { _numberAddPrefix = n; } void setNumberAddPrefix(std::string n) { _numberAddPrefix = n; }
bool getNumberEnabled(void) { return _numberEnabled; } bool getNumberEnabled(void) { return _numberEnabled; }
void setNumberEnabled(bool n) { _numberEnabled = n; } void setNumberEnabled(bool n) { _numberEnabled = n; }
...@@ -279,7 +279,7 @@ class HookPreference : public Serializable { ...@@ -279,7 +279,7 @@ class HookPreference : public Serializable {
private: private:
bool _iax2Enabled;// : false bool _iax2Enabled;// : false
bool _numberAddPrefix;//: false std::string _numberAddPrefix;//: false
bool _numberEnabled; //: false bool _numberEnabled; //: false
bool _sipEnabled; //: false bool _sipEnabled; //: false
std::string _urlCommand; //: x-www-browser std::string _urlCommand; //: x-www-browser
......
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