From d66602604284b36c605f42de826507cf7f7c26cd Mon Sep 17 00:00:00 2001 From: pierre-luc <pierre-luc.bacon@savoirfairelinux.com> Date: Fri, 14 Aug 2009 11:55:24 -0400 Subject: [PATCH] [#812] New dbus bindings added. Also, configuration compliance was enforced by providing default values when missing from request. This might have break some features however: boolean values are represented as "0/1", transformed into "true/false" strings, and converted back again ... We now simply use "true/false" strings. --- sflphone-client-gnome/src/accountlist.h | 1 + sflphone-client-gnome/src/actions.c | 4 + .../dbus/configurationmanager-introspec.xml | 12 + sflphone-client-gnome/src/dbus/dbus.c | 32 +- sflphone-client-gnome/src/dbus/dbus.h | 8 + sflphone-common/src/account.h | 1 + sflphone-common/src/config/config.cpp | 45 ++- sflphone-common/src/config/config.h | 23 +- .../dbus/configurationmanager-introspec.xml | 12 +- .../src/dbus/configurationmanager.cpp | 41 ++- .../src/dbus/configurationmanager.h | 3 + sflphone-common/src/managerimpl.cpp | 344 +++++++++--------- sflphone-common/src/managerimpl.h | 44 --- 13 files changed, 316 insertions(+), 254 deletions(-) diff --git a/sflphone-client-gnome/src/accountlist.h b/sflphone-client-gnome/src/accountlist.h index dd6dbb98a0..bb96970cb8 100644 --- a/sflphone-client-gnome/src/accountlist.h +++ b/sflphone-client-gnome/src/accountlist.h @@ -67,6 +67,7 @@ typedef struct { gchar * accountID; account_state_t state; GHashTable * properties; + GHashTable * tlsSettings; GPtrArray * credential_information; } account_t; diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c index e44ec57d6c..bcf56f7ca3 100644 --- a/sflphone-client-gnome/src/actions.c +++ b/sflphone-client-gnome/src/actions.c @@ -187,6 +187,10 @@ sflphone_fill_account_list(gboolean toolbarInitialized) break; a->properties = details; + GHashTable * tlsSettings = NULL; + tlsSettings = dbus_get_tls_settings(a->accountID); + a->tlsSettings = tlsSettings; + /* As this function might be called numberous time, we should free the * previously allocated space to avoid memory leaks. */ diff --git a/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml b/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml index 897e99c8c2..43dcceefd7 100644 --- a/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml @@ -375,6 +375,18 @@ <method name="getTlsSettingsDefault"> <arg type="a{ss}" name="details" direction="out"/> </method> + + <method name="getTlsSettings"> + <arg type="s" name="accountID" direction="in"/> + <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <arg type="a{ss}" name="details" direction="out"/> + </method> + + <method name="setTlsSettings"> + <annotation name="com.trolltech.QtDBus.QtTypeName.In1" value="MapStringString"/> + <arg type="s" name="accountID" direction="in"/> + <arg type="a{ss}" name="details" direction="in"/> + </method> </interface> </node> diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index 5f1b761bc3..ffbd21a6a7 100644 --- a/sflphone-client-gnome/src/dbus/dbus.c +++ b/sflphone-client-gnome/src/dbus/dbus.c @@ -699,7 +699,7 @@ dbus_set_credential(account_t *a, int index) } if (error) { - ERROR ("Failed to call set_account_details() on ConfigurationManager: %s", + ERROR ("Failed to call set_credential() on ConfigurationManager: %s", error->message); g_error_free (error); } @@ -713,7 +713,7 @@ dbus_set_number_of_credential(account_t *a, int number) org_sflphone_SFLphone_ConfigurationManager_set_number_of_credential( configurationManagerProxy, a->accountID, number, &error); if (error) { - ERROR ("Failed to call set_account_details() on ConfigurationManager: %s", + ERROR ("Failed to call set_number_of_credential() on ConfigurationManager: %s", error->message); g_error_free (error); } @@ -2129,3 +2129,31 @@ GHashTable* dbus_get_tls_settings_default(void) return results; } + +GHashTable* dbus_get_tls_settings(const gchar * accountID) +{ + GError *error = NULL; + GHashTable *results = NULL; + + org_sflphone_SFLphone_ConfigurationManager_get_tls_settings(configurationManagerProxy, accountID, &results, &error); + if (error != NULL){ + ERROR ("Error calling org_sflphone_SFLphone_ConfigurationManager_get_tls_settings_default"); + g_error_free (error); + } + return results; +} + +void dbus_set_tls_settings (account_t *a) +{ + GError *error = NULL; + org_sflphone_SFLphone_ConfigurationManager_set_tls_settings ( + configurationManagerProxy, + a->accountID, + a->tlsSettings, + &error); + if (error) { + ERROR ("Failed to call set_tls_settings() on ConfigurationManager: %s", + error->message); + g_error_free (error); + } +} diff --git a/sflphone-client-gnome/src/dbus/dbus.h b/sflphone-client-gnome/src/dbus/dbus.h index 4f25e763c5..cd5b9a9489 100644 --- a/sflphone-client-gnome/src/dbus/dbus.h +++ b/sflphone-client-gnome/src/dbus/dbus.h @@ -609,4 +609,12 @@ gchar** dbus_get_supported_tls_method(); */ GHashTable* dbus_get_tls_settings_default(void); +/** + * CallManager - Get TLS settings for that account + * @return a GHashTable object containing those default + * TLS settings. + * + */ +GHashTable* dbus_get_tls_settings(const gchar * accountID); + #endif diff --git a/sflphone-common/src/account.h b/sflphone-common/src/account.h index 2d61be20ab..44b06d5b99 100644 --- a/sflphone-common/src/account.h +++ b/sflphone-common/src/account.h @@ -68,6 +68,7 @@ typedef enum RegistrationState { #define AUTHENTICATION_USERNAME "authenticationUsername" #define PASSWORD "password" #define REALM "realm" +#define DEFAULT_REALM "*" // SIP specific parameters #define SIP_PROXY "SIP.proxy" diff --git a/sflphone-common/src/config/config.cpp b/sflphone-common/src/config/config.cpp index 2f6922afff..e08780a90a 100644 --- a/sflphone-common/src/config/config.cpp +++ b/sflphone-common/src/config/config.cpp @@ -47,6 +47,25 @@ ConfigTree::~ConfigTree() } } +void ConfigTree::addDefaultValue(const std::pair<std::string, std::string>& token, std::string section) +{ + _defaultValueMap.insert(token); + if (section.empty() == false) { + addConfigTreeItem(section, ConfigTreeItem(token.first, token.second, token.second, "string")); + } +} + +std::string ConfigTree::getDefaultValue(const std::string& key) +{ + std::map<std::string, std::string>::iterator it; + it = _defaultValueMap.find(key); + if (it == _defaultValueMap.end()) { + return std::string(""); + } + + return it->second; +} + /** * Create the section only if it doesn't exists */ @@ -90,7 +109,6 @@ ConfigTree::getSections() return sections; } - /** * Add the config item only if it exists.. * If the section doesn't exists, create it @@ -116,7 +134,6 @@ ConfigTree::addConfigTreeItem (const std::string& section, const ConfigTreeItem } } -// Return an empty string if not found std::string ConfigTree::getConfigTreeItemValue (const std::string& section, const std::string& itemName) { @@ -124,19 +141,11 @@ ConfigTree::getConfigTreeItemValue (const std::string& section, const std::strin if (item != NULL) { return item->getValue(); - } else { - _debug ("Option doesn't exist: [%s] %s\n", section.c_str(), itemName.c_str()); - /** @todo If item doesn't exist, we should check against the default values for those - * types of information, and return the default value. - * ... - * Maybe this should be implemented when called ? When we need a bit of configuration, - * we call the getConfig with a defaultValue as parameter, in that context we know best - * what would be the default value, rather than inside this generic configuration - * management class. - */ - } - - return ""; + } + + _debug ("Option doesn't exist: [%s] %s\n", section.c_str(), itemName.c_str()); + + return getDefaultValue(itemName); } // throw a ConfigTreeItemException if not found @@ -212,8 +221,10 @@ ConfigTree::setConfigTreeItem (const std::string& section, ItemMap::iterator iterItem = iter->second->find (itemName); if (iterItem == iter->second->end()) { - // Item not found, create it, defaults to type "string" - addConfigTreeItem (section, ConfigTreeItem (itemName, value, "string")); + // If not found, search in our default list to find + // something that would fit. + std::string defaultValue = getDefaultValue(itemName); + addConfigTreeItem (section, ConfigTreeItem (itemName, value, defaultValue)); return true; } diff --git a/sflphone-common/src/config/config.h b/sflphone-common/src/config/config.h index 0872889486..2e1de5e540 100644 --- a/sflphone-common/src/config/config.h +++ b/sflphone-common/src/config/config.h @@ -99,7 +99,20 @@ class ConfigTree public: ConfigTree(); ~ConfigTree(); - + /** + * Add a default value for a given key. + * It looks in a map of default values when + * the value for a given key cannot be found. + * + * @param section the section under which the given key/value pair + should go under. Note that this has no effect + when searching for a default value later on. Only + one possible value is actually supported as a default + value for a given key. + @param token A default key/value pair. + */ + void addDefaultValue(const std::pair<std::string, std::string>& token, std::string section = std::string("")); + void createSection (const std::string& section); void removeSection (const std::string& section); /** @@ -125,8 +138,9 @@ class ConfigTree /** * Get a value. * - * This function does all the validity tests, so none are needed throughout - * the program. + * If the key cannot be found in the actual file representation in + * memory, it check for a default value in the default value map. If it's + * not found there, it will return an empty string. * * @param section The name of the [section] in the .ini file. * @param itemName The name of the item= in the .ini file. @@ -149,6 +163,7 @@ class ConfigTree bool getConfigTreeItemToken (const std::string& section, const std::string& itemName, TokenList& arg); private: + std::string getDefaultValue(const std::string& key); ConfigTreeItem* getConfigTreeItem (const std::string& section, const std::string& itemName); /** @@ -156,6 +171,8 @@ class ConfigTree */ SectionMap _sections; + std::map<std::string, std::string> _defaultValueMap; + friend class ConfigTreeIterator; public: diff --git a/sflphone-common/src/dbus/configurationmanager-introspec.xml b/sflphone-common/src/dbus/configurationmanager-introspec.xml index 718bc2e58a..20700bd0bd 100644 --- a/sflphone-common/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-common/src/dbus/configurationmanager-introspec.xml @@ -378,6 +378,16 @@ <arg type="a{ss}" name="details" direction="out"/> </method> - + <method name="getTlsSettings"> + <arg type="s" name="accountID" direction="in"/> + <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <arg type="a{ss}" name="details" direction="out"/> + </method> + + <method name="setTlsSettings"> + <annotation name="com.trolltech.QtDBus.QtTypeName.In1" value="MapStringString"/> + <arg type="s" name="accountID" direction="in"/> + <arg type="a{ss}" name="details" direction="in"/> + </method> </interface> </node> diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp index 77aacd99b1..b109207f94 100644 --- a/sflphone-common/src/dbus/configurationmanager.cpp +++ b/sflphone-common/src/dbus/configurationmanager.cpp @@ -95,13 +95,30 @@ ConfigurationManager::getIp2IpDetails(void) void ConfigurationManager::setIp2IpDetails(const std::map< std::string, std::string >& details ) { - - Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, SRTP_ENABLE); - Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS); - Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING); - Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_HELLO_HASH); - Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE); - + std::map<std::string, std::string> map_cpy = details; + std::map<std::string, std::string>::iterator it; + + it = map_cpy.find(SRTP_ENABLE); + if (it != details.end()) { + Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); + } + it = map_cpy.find(ZRTP_DISPLAY_SAS); + if (it != details.end()) { + Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); + } + it = map_cpy.find(ZRTP_NOT_SUPP_WARNING); + if (it != details.end()) { + Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); + } + it = map_cpy.find(ZRTP_HELLO_HASH); + if (it != details.end()) { + Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); + } + it = map_cpy.find(ZRTP_DISPLAY_SAS_ONCE); + if (it != details.end()) { + Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); + } + std::string keyExchange(details.find(SRTP_KEY_EXCHANGE)->second); if(keyExchange.find("ZRTP") == 0) { @@ -117,6 +134,16 @@ ConfigurationManager::setIp2IpDetails(const std::map< std::string, std::string > } +std::map< std::string, std::string > +ConfigurationManager::getTlsSettings(const std::string& accountID) +{ +} + +void +ConfigurationManager::setTlsSettings(const std::string& accountID, const std::map< std::string, std::string >& details ) +{ +} + std::map< std::string, std::string > ConfigurationManager::getCredential (const std::string& accountID, const int32_t& index) { diff --git a/sflphone-common/src/dbus/configurationmanager.h b/sflphone-common/src/dbus/configurationmanager.h index af386bdf20..c680f5d70f 100644 --- a/sflphone-common/src/dbus/configurationmanager.h +++ b/sflphone-common/src/dbus/configurationmanager.h @@ -135,6 +135,9 @@ public: std::map <std::string, std::string> getHistory (void); void setHistory (const std::map <std::string, std::string>& entries); + std::map<std::string, std::string> getTlsSettings(const std::string& accountID); + void setTlsSettings(const std::string& accountID, const std::map< std::string, std::string >& details); + }; diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index b9af98ed83..60f06727e5 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1330,90 +1330,101 @@ ManagerImpl::createSettingsPath (void) void ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) { - std::string mes = gettext ("Init config file\n"); - _debug ("%s",mes.c_str()); - - std::string type_str ("string"); - std::string type_int ("int"); - - std::string section, path; - + _debug("ManagerImpl::InitConfigFile\n"); + // Default values, that will be overwritten by the call to - // 'populateFromFile' below. - section = IP2IP_PROFILE; - fill_config_int(SRTP_ENABLE, NO_STR); - fill_config_int(SRTP_KEY_EXCHANGE, YES_STR); - fill_config_int(ZRTP_HELLO_HASH, YES_STR); - fill_config_int(ZRTP_DISPLAY_SAS, YES_STR); - fill_config_int(ZRTP_DISPLAY_SAS_ONCE, NO_STR); - fill_config_int(ZRTP_NOT_SUPP_WARNING, YES_STR); - - section = SIGNALISATION; - fill_config_int (SYMMETRIC, YES_STR); - fill_config_int (PLAY_DTMF, YES_STR); - fill_config_int (PLAY_TONES, YES_STR); - fill_config_int (PULSE_LENGTH, DFT_PULSE_LENGTH_STR); - fill_config_int (SEND_DTMF_AS, SIP_INFO_STR); - fill_config_int (STUN_ENABLE, DFT_STUN_ENABLE); - fill_config_int (STUN_SERVER, DFT_STUN_SERVER); - fill_config_int (ZRTP_ZIDFILE, ZRTP_ZID_FILENAME); - - section = AUDIO; - fill_config_int (ALSA_CARD_ID_IN, ALSA_DFT_CARD); - fill_config_int (ALSA_CARD_ID_OUT, ALSA_DFT_CARD); - fill_config_int (ALSA_SAMPLE_RATE, DFT_SAMPLE_RATE); - fill_config_int (ALSA_FRAME_SIZE, DFT_FRAME_SIZE); - fill_config_str (ALSA_PLUGIN, PCM_DEFAULT); - fill_config_str (RING_CHOICE, DFT_RINGTONE); - fill_config_int (VOLUME_SPKR, DFT_VOL_SPKR_STR); - fill_config_int (VOLUME_MICRO, DFT_VOL_MICRO_STR); - fill_config_str (RECORD_PATH,DFT_RECORD_PATH); - - section = PREFERENCES; - fill_config_str (ZONE_TONE, DFT_ZONE); - fill_config_int (CONFIG_RINGTONE, YES_STR); - fill_config_int (CONFIG_DIALPAD, YES_STR); - fill_config_int (CONFIG_SEARCHBAR, YES_STR); - fill_config_int (CONFIG_START, NO_STR); - fill_config_int (CONFIG_POPUP, YES_STR); - fill_config_int (CONFIG_NOTIFY , YES_STR); - fill_config_int (CONFIG_MAIL_NOTIFY , NO_STR); - fill_config_int (CONFIG_VOLUME , YES_STR); - fill_config_int (CONFIG_HISTORY_LIMIT, DFT_HISTORY_LIMIT); - fill_config_int (CONFIG_HISTORY_ENABLED, YES_STR); - fill_config_int (CONFIG_AUDIO , DFT_AUDIO_MANAGER); - fill_config_int (CONFIG_PA_VOLUME_CTRL , YES_STR); - fill_config_int (CONFIG_SIP_PORT, DFT_SIP_PORT); - fill_config_str (CONFIG_ACCOUNTS_ORDER, ""); - fill_config_int (CONFIG_MD5HASH, NO_STR); - - section = ADDRESSBOOK; - fill_config_int (ADDRESSBOOK_ENABLE, YES_STR); - fill_config_int (ADDRESSBOOK_MAX_RESULTS, "25"); - fill_config_int (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, NO_STR); - fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, YES_STR); - fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_HOME, NO_STR); - fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_MOBILE, NO_STR); - - section = HOOKS; - fill_config_str (URLHOOK_SIP_FIELD, HOOK_DEFAULT_SIP_FIELD); - fill_config_str (URLHOOK_COMMAND, HOOK_DEFAULT_URL_COMMAND); - fill_config_str (URLHOOK_SIP_ENABLED, NO_STR); - fill_config_str (URLHOOK_IAX2_ENABLED, NO_STR); - fill_config_str (PHONE_NUMBER_HOOK_ENABLED, NO_STR); - fill_config_str (PHONE_NUMBER_HOOK_ADD_PREFIX, ""); - + // 'populateFromFile' below. + + // Peer to peer settings + _config.addDefaultValue(std::pair<std::string, std::string> (SRTP_ENABLE, NO_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (SRTP_KEY_EXCHANGE, YES_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_HELLO_HASH, YES_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS, YES_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, NO_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, YES_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_CA_LIST_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_CERTIFICATE_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_PRIVATE_KEY_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_PASSWORD, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_METHOD, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_CIPHERS, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_SERVER_NAME, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_VERIFY_SERVER, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_VERIFY_CLIENT, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_REQUIRE_CLIENT_CERTIFICATE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_SEC, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_MSEC, EMPTY_FIELD), IP2IP_PROFILE); + + // Signalisation settings + _config.addDefaultValue(std::pair<std::string, std::string> (SYMMETRIC, YES_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (PLAY_DTMF, YES_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (PLAY_TONES, YES_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (PULSE_LENGTH, DFT_PULSE_LENGTH_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (SEND_DTMF_AS, SIP_INFO_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (STUN_ENABLE, DFT_STUN_ENABLE), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (STUN_SERVER, DFT_STUN_SERVER), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_ZIDFILE, ZRTP_ZID_FILENAME), SIGNALISATION); + + // Audio settings + _config.addDefaultValue(std::pair<std::string, std::string> (ALSA_CARD_ID_IN, ALSA_DFT_CARD), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (ALSA_CARD_ID_OUT, ALSA_DFT_CARD), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (ALSA_SAMPLE_RATE, DFT_SAMPLE_RATE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (ALSA_FRAME_SIZE, DFT_FRAME_SIZE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (ALSA_PLUGIN, PCM_DEFAULT), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (RING_CHOICE, DFT_RINGTONE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (VOLUME_SPKR, DFT_VOL_SPKR_STR), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (VOLUME_MICRO, DFT_VOL_MICRO_STR), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string> (RECORD_PATH,DFT_RECORD_PATH), AUDIO); + + // General settings + _config.addDefaultValue(std::pair<std::string, std::string> (ZONE_TONE, DFT_ZONE), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_RINGTONE, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_DIALPAD, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_SEARCHBAR, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_START, NO_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_POPUP, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_NOTIFY, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_MAIL_NOTIFY, NO_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_VOLUME, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_HISTORY_LIMIT, DFT_HISTORY_LIMIT), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_HISTORY_ENABLED, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_AUDIO, DFT_AUDIO_MANAGER), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_PA_VOLUME_CTRL, YES_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_SIP_PORT, DFT_SIP_PORT), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_ACCOUNTS_ORDER, EMPTY_FIELD), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_MD5HASH, NO_STR), PREFERENCES); + + // Addressbook settings + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_ENABLE, YES_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_MAX_RESULTS, "25"), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, NO_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, YES_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_HOME, NO_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_MOBILE, NO_STR), ADDRESSBOOK); + + // Hooks settings + _config.addDefaultValue(std::pair<std::string, std::string> (URLHOOK_SIP_FIELD, HOOK_DEFAULT_SIP_FIELD), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string> (URLHOOK_COMMAND, HOOK_DEFAULT_URL_COMMAND), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string> (URLHOOK_SIP_ENABLED, NO_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string> (URLHOOK_IAX2_ENABLED, NO_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string> (PHONE_NUMBER_HOOK_ENABLED, NO_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string> (PHONE_NUMBER_HOOK_ADD_PREFIX, EMPTY_FIELD), HOOKS); + + std::string path; // Loads config from ~/.sflphone/sflphonedrc or so.. - if (createSettingsPath() == 1 && load_user_value) { - (alternate == "") ? path = _path : path = alternate; - std::cout << path << std::endl; - _exist = _config.populateFromFile (path); } - + + // Globally shared default values (not to be populated from file) + _config.addDefaultValue(std::pair<std::string, std::string> (HOSTNAME, EMPTY_FIELD)); + _config.addDefaultValue(std::pair<std::string, std::string> (AUTHENTICATION_USERNAME, EMPTY_FIELD)); + _config.addDefaultValue(std::pair<std::string, std::string> (USERNAME, EMPTY_FIELD)); + _config.addDefaultValue(std::pair<std::string, std::string> (PASSWORD, EMPTY_FIELD)); + _config.addDefaultValue(std::pair<std::string, std::string> (REALM, DEFAULT_REALM)); + _setupLoaded = (_exist == 2) ? false : true; } @@ -2400,33 +2411,6 @@ ManagerImpl::getConfigInt (const std::string& section, const std::string& name) return 0; } - -void ManagerImpl::getConfigStringFromFileOrDefaultValue(std::map<std::string, std::string>& details, const std::string& section, const std::string& field) -{ - getConfigStringFromFileOrDefaultValue(details, section, field, EMPTY_FIELD); -} - -void ManagerImpl::getConfigStringFromFileOrDefaultValue(std::map<std::string, std::string>& details, - const std::string& section, const std::string& field, const std::string& value) -{ - std::string setting = getConfigString(section, field); - - if (setting == "0") { - details.insert (std::pair<std::string, std::string>(field, "FALSE")); - return; - } - - if (setting == "1") { - details.insert (std::pair<std::string, std::string>(field, "TRUE")); - return; - } - - if (setting.empty()) { - details.insert (std::pair<std::string, std::string>(field, value)); - } else { - details.insert (std::pair<std::string, std::string>(field, setting)); - } -} //THREAD=Main std::string @@ -2458,32 +2442,6 @@ ManagerImpl::setConfig (const std::string& section, const std::string& name, int return _config.setConfigTreeItem (section, name, valueStream.str()); } -bool ManagerImpl::setConfigOrDefaultValue(const std::map<std::string, std::string>& details, const std::string& section, const std::string& field) -{ - return setConfigOrDefaultValue(details, section, field, EMPTY_FIELD); -} - -bool ManagerImpl::setConfigOrDefaultValue(const std::map<std::string, std::string>& details, const std::string& section, const std::string& field, const std::string& value) -{ - std::map<std::string, std::string>::iterator it; - std::map<std::string, std::string> detailsCpy = details; - - it = detailsCpy.find(field); - if (it == detailsCpy.end()) { - return setConfig(section, field, value); - } else { - if (it->second == "TRUE") { - return setConfig(section, field, "1"); - } - - if (it->second == "FALSE") { - return setConfig(section, field, "0"); - } - - return setConfig(section, field, it->second); - } -} - void ManagerImpl::setAccountsOrder (const std::string& order) { _debug ("Set accounts order : %s\n", order.c_str()); @@ -2538,7 +2496,6 @@ ManagerImpl::getAccountList() std::map< std::string, std::string > ManagerImpl::getAccountDetails (const AccountID& accountID) { - std::map<std::string, std::string> a; Account * account = _accountMap[accountID]; @@ -2546,29 +2503,28 @@ std::map< std::string, std::string > ManagerImpl::getAccountDetails (const Accou _debug("Cannot getAccountDetails on a non-existing accountID. Returning.\n"); return a; } - - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_ALIAS); - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_ENABLE, "FALSE"); - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, "FALSE"); - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_TYPE, DEFAULT_ACCOUNT_TYPE); - getConfigStringFromFileOrDefaultValue(a, accountID, HOSTNAME); - getConfigStringFromFileOrDefaultValue(a, accountID, USERNAME); - getConfigStringFromFileOrDefaultValue(a, accountID, PASSWORD); - getConfigStringFromFileOrDefaultValue(a, accountID, REALM, "*"); - getConfigStringFromFileOrDefaultValue(a, accountID, AUTHENTICATION_USERNAME); - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_MAILBOX); - getConfigStringFromFileOrDefaultValue(a, accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, DFT_EXPIRE_VALUE); + + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, getConfigString(accountID, CONFIG_ACCOUNT_ALIAS))); + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, getConfigString(accountID, CONFIG_ACCOUNT_ENABLE))); + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_RESOLVE_ONCE, getConfigString(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE))); + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, getConfigString(accountID, CONFIG_ACCOUNT_TYPE))); + a.insert(std::pair<std::string, std::string> (HOSTNAME, getConfigString(accountID, HOSTNAME))); + a.insert(std::pair<std::string, std::string> (USERNAME, getConfigString(accountID, USERNAME))); + a.insert(std::pair<std::string, std::string> (PASSWORD, getConfigString(accountID, PASSWORD))); + a.insert(std::pair<std::string, std::string> (REALM, getConfigString(accountID, REALM))); + a.insert(std::pair<std::string, std::string> (AUTHENTICATION_USERNAME, getConfigString(accountID, AUTHENTICATION_USERNAME))); + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_MAILBOX, getConfigString(accountID, CONFIG_ACCOUNT_MAILBOX))); + a.insert(std::pair<std::string, std::string> (CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getConfigString(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE))); RegistrationState state; state = account->getRegistrationState(); a.insert (std::pair<std::string, std::string> ("Status", mapStateNumberToString (state))); - a.insert( std::pair<std::string, std::string>( SRTP_KEY_EXCHANGE, getConfigString(accountID, SRTP_KEY_EXCHANGE) ) ); - - getConfigStringFromFileOrDefaultValue(a, accountID, SRTP_ENABLE, "FALSE"); - getConfigStringFromFileOrDefaultValue(a, accountID, ZRTP_DISPLAY_SAS, "TRUE"); - getConfigStringFromFileOrDefaultValue(a, accountID, ZRTP_DISPLAY_SAS_ONCE, "FALSE"); - getConfigStringFromFileOrDefaultValue(a, accountID, ZRTP_HELLO_HASH, "TRUE"); - getConfigStringFromFileOrDefaultValue(a, accountID, ZRTP_NOT_SUPP_WARNING, "FALSE"); + a.insert(std::pair<std::string, std::string> (SRTP_KEY_EXCHANGE, getConfigString(accountID, SRTP_KEY_EXCHANGE))); + a.insert(std::pair<std::string, std::string> (SRTP_ENABLE, getConfigString(accountID, SRTP_ENABLE))); + a.insert(std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS, getConfigString(accountID, ZRTP_DISPLAY_SAS))); + a.insert(std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, getConfigString(accountID, ZRTP_DISPLAY_SAS_ONCE))); + a.insert(std::pair<std::string, std::string> (ZRTP_HELLO_HASH, getConfigString(accountID, ZRTP_HELLO_HASH))); + a.insert(std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, getConfigString(accountID, ZRTP_NOT_SUPP_WARNING))); return a; } @@ -2690,23 +2646,23 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma // Work on a copy map_cpy = details; - - if(!getMd5CredentialHashing()) { - setConfigOrDefaultValue(map_cpy, accountID, REALM, "*"); - setConfigOrDefaultValue(map_cpy, accountID, USERNAME); - setConfigOrDefaultValue(map_cpy, accountID, PASSWORD); - setConfigOrDefaultValue (details, accountID, AUTHENTICATION_USERNAME); - } else { - std::string username; - std::string authenticationName; - std::string password; - std::string realm; - if((iter = map_cpy.find(AUTHENTICATION_USERNAME)) == map_cpy.end()) { authenticationName = EMPTY_FIELD; } else { authenticationName = iter->second; } - if((iter = map_cpy.find(USERNAME)) == map_cpy.end()) { username = EMPTY_FIELD; } else { username = iter->second; } - if((iter = map_cpy.find(PASSWORD)) == map_cpy.end()) { password = EMPTY_FIELD; } else { password = iter->second; } - if((iter = map_cpy.find(REALM)) == map_cpy.end()) { realm = EMPTY_FIELD; } else { realm = iter->second; } + std::string username; + std::string authenticationName; + std::string password; + std::string realm; + if((iter = map_cpy.find(AUTHENTICATION_USERNAME)) == map_cpy.end()) { authenticationName = EMPTY_FIELD; } else { authenticationName = iter->second; } + if((iter = map_cpy.find(USERNAME)) == map_cpy.end()) { username = EMPTY_FIELD; } else { username = iter->second; } + if((iter = map_cpy.find(PASSWORD)) == map_cpy.end()) { password = EMPTY_FIELD; } else { password = iter->second; } + if((iter = map_cpy.find(REALM)) == map_cpy.end()) { realm = EMPTY_FIELD; } else { realm = iter->second; } + + if(!getMd5CredentialHashing()) { + setConfig(accountID, REALM, realm); + setConfig(accountID, USERNAME, username); + setConfig(accountID, PASSWORD, password); + setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName); + } else { // Make sure not to re-hash the password field if // it is already saved as a MD5 Hash. // TODO: This test is weak. Fix this. @@ -2721,21 +2677,49 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma setConfig(accountID, PASSWORD, hash); } } - - setConfigOrDefaultValue(map_cpy, accountID, HOSTNAME); - setConfigOrDefaultValue(map_cpy, accountID, SRTP_ENABLE, "0"); - setConfigOrDefaultValue(map_cpy, accountID, ZRTP_DISPLAY_SAS, "1"); - setConfigOrDefaultValue(map_cpy, accountID, ZRTP_DISPLAY_SAS_ONCE, "0"); - setConfigOrDefaultValue(map_cpy, accountID, ZRTP_NOT_SUPP_WARNING, "0"); - setConfigOrDefaultValue(map_cpy, accountID, ZRTP_HELLO_HASH, "1"); - setConfigOrDefaultValue(map_cpy, accountID, SRTP_KEY_EXCHANGE, "0"); - - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_ALIAS); - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_MAILBOX); - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_ENABLE, "0"); - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_TYPE, DEFAULT_ACCOUNT_TYPE); - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, DFT_RESOLVE_ONCE); - setConfigOrDefaultValue(map_cpy, accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, DFT_EXPIRE_VALUE); + std::string hostname; + std::string srtpEnable; + std::string zrtpDisplaySas; + std::string zrtpDisplaySasOnce; + std::string zrtpNotSuppWarning; + std::string zrtpHelloHash; + std::string srtpKeyExchange; + std::string alias; + std::string mailbox; + std::string accountEnable; + std::string type; + std::string resolveOnce; + std::string registrationExpire; + + if((iter = map_cpy.find(HOSTNAME)) != map_cpy.end()) { hostname = iter->second; } + if((iter = map_cpy.find(SRTP_ENABLE)) != map_cpy.end()) { srtpEnable = iter->second; } + if((iter = map_cpy.find(ZRTP_DISPLAY_SAS)) != map_cpy.end()) { zrtpDisplaySas = iter->second; } + if((iter = map_cpy.find(ZRTP_DISPLAY_SAS_ONCE)) != map_cpy.end()) { zrtpDisplaySasOnce = iter->second; } + if((iter = map_cpy.find(ZRTP_NOT_SUPP_WARNING)) != map_cpy.end()) { zrtpNotSuppWarning = iter->second; } + if((iter = map_cpy.find(ZRTP_HELLO_HASH)) != map_cpy.end()) { zrtpHelloHash = iter->second; } + if((iter = map_cpy.find(SRTP_KEY_EXCHANGE)) != map_cpy.end()) { srtpKeyExchange = iter->second; } + + if((iter = map_cpy.find(CONFIG_ACCOUNT_ALIAS)) != map_cpy.end()) { alias = iter->second; } + if((iter = map_cpy.find(CONFIG_ACCOUNT_MAILBOX)) != map_cpy.end()) { mailbox = iter->second; } + if((iter = map_cpy.find(CONFIG_ACCOUNT_ENABLE)) != map_cpy.end()) { accountEnable = iter->second; } + if((iter = map_cpy.find(CONFIG_ACCOUNT_TYPE)) != map_cpy.end()) { type = iter->second; } + if((iter = map_cpy.find(CONFIG_ACCOUNT_RESOLVE_ONCE)) != map_cpy.end()) { resolveOnce = iter->second; } + if((iter = map_cpy.find(CONFIG_ACCOUNT_REGISTRATION_EXPIRE)) != map_cpy.end()) { registrationExpire = iter->second; } + + setConfig(accountID, HOSTNAME, hostname); + setConfig(accountID, SRTP_ENABLE, srtpEnable); + setConfig(accountID, ZRTP_DISPLAY_SAS, zrtpDisplaySas); + setConfig(accountID, ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce); + setConfig(accountID, ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning); + setConfig(accountID, ZRTP_HELLO_HASH, zrtpHelloHash); + setConfig(accountID, SRTP_KEY_EXCHANGE, srtpKeyExchange); + + setConfig(accountID, CONFIG_ACCOUNT_ALIAS, alias); + setConfig(accountID, CONFIG_ACCOUNT_MAILBOX, mailbox); + setConfig(accountID, CONFIG_ACCOUNT_ENABLE, accountEnable); + setConfig(accountID, CONFIG_ACCOUNT_TYPE, type); + setConfig(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce); + setConfig(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire); saveConfig(); diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index ca20005d0b..0374116391 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -737,26 +737,6 @@ class ManagerImpl { * false otherwise */ bool setConfig(const std::string& section, const std::string& name, int value); - - /** - * Set a field in the configuration file to the value - * found in the map, otherwise, it is set to - * EMPTY_FIELD. - * @param details The map containing the field:value association - * @param section The ini style section in the configuration file - * @param field The field under that section to set the value to. - */ - bool setConfigOrDefaultValue(const std::map<std::string, std::string>& details, const std::string& section, const std::string& field); - - /** - * Set a field in the configuration file to the value - * found in the map, otherwise, it is set to value. - * - * @param details The map containing the field:value association - * @param section The ini style section in the configuration file - * @param field The field under that section to set the value to. - */ - bool setConfigOrDefaultValue(const std::map<std::string, std::string>& details, const std::string& section, const std::string& field, const std::string& value); inline std::string mapStateNumberToString(RegistrationState state) { std::string stringRepresentation; @@ -778,30 +758,6 @@ class ManagerImpl { */ int getConfigInt(const std::string& section, const std::string& name); - - /** - * Helper method. - * Get a string from the configuration tree, and set - * its value in "details" if found, otherwise set to - * EMPTY_STRING. - * - * @param section The section name to look in - * @param field The parameter name - * @param value The default value if not found - */ - void getConfigStringFromFileOrDefaultValue(std::map<std::string, std::string>& details, const std::string& section, const std::string& field); - - /** - * Helper method. - * Get a string from the configuration tree, and set - * its value in "details" if found, otherwise set to - * "value". - * - * @param section The section name to look in - * @param field The parameter name - * @param value The default value if not found - */ - void getConfigStringFromFileOrDefaultValue(std::map<std::string, std::string>& details, const std::string& section, const std::string& field, const std::string& value); /** * Get a string from the configuration tree -- GitLab