diff --git a/src/dbus/configurationmanager.cpp b/src/dbus/configurationmanager.cpp index 6337e970c9af34b3515d724fbbf113a51bcc3da6..1de8988827eb7c80f2bd9c976e3c0db488677146 100644 --- a/src/dbus/configurationmanager.cpp +++ b/src/dbus/configurationmanager.cpp @@ -50,9 +50,7 @@ void ConfigurationManager::addAccount( const std::map< ::DBus::String, ::DBus::String >& details ) { _debug("ConfigurationManager::addAccount received\n"); - std::stringstream accountID; - accountID << "Account:" << time(NULL); - Manager::instance().setAccountDetails(accountID.str(), details); + Manager::instance().addAccount(details); } diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 447970126e633f6ed1981393462a4d26eb18fb0c..38f74bb47663dcbfe649f7cd3f8f9ee494867227 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1684,7 +1684,7 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, const std::map< ::DBus::String, ::DBus::String >& details ) { std::string accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; - + setConfig(accountID, CONFIG_ACCOUNT_ALIAS, (*details.find(CONFIG_ACCOUNT_ALIAS)).second); //setConfig(accountID, CONFIG_ACCOUNT_AUTO_REGISTER, // (*details.find(CONFIG_ACCOUNT_AUTO_REGISTER)).second == "TRUE" ? "1": "0" ); @@ -1717,10 +1717,57 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); } + +void +ManagerImpl::addAccount(const std::map< ::DBus::String, ::DBus::String >& details) +{ + /** @todo Deal with both the _accountMap and the Configuration */ + std::string accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; + Account* newAccount; + std::stringstream accountID; + accountID << "Account:" << time(NULL); + AccountID newAccountID = accountID.str(); + /** @todo Verify the uniqueness, in case a program adds accounts, two in a row. */ + + setAccountDetails(accountID.str(), details); + + saveConfig(); + + if (accountType == "SIP") { + newAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, newAccountID); + } + else if (accountType == "IAX") { + newAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, newAccountID); + } + else { + _debug("Unknown %s param when calling addAccount(): %s\n", CONFIG_ACCOUNT_TYPE, accountType.c_str()); + return; + } + _accountMap[newAccountID] = newAccount; + + // Get it up and running... + newAccount->loadConfig(); + if (newAccount->isEnabled()) { + if (newAccount->init()) { + newAccount->registerVoIPLink(); + } + } +} + void ManagerImpl::removeAccount(const AccountID& accountID) { + // Get it down and dying + Account* remAccount = getAccount(accountID); + + if (remAccount) { + remAccount->unregisterVoIPLink(); + _accountMap.erase(accountID); + delete remAccount; + } + _config.removeSection(accountID); + saveConfig(); } diff --git a/src/managerimpl.h b/src/managerimpl.h index 3abd7462e0ca79d5ce561f48d7b32e11cd986201..e097bc70d84cb8e30cb25d35c63926851adb1efc 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -220,15 +220,35 @@ public: bool attachZeroconfEvents(const std::string& sequenceId, Pattern::Observer& observer); bool detachZeroconfEvents(Pattern::Observer& observer); bool getCallStatus(const std::string& sequenceId); + /** * Get account list * @return A list of accoundIDs */ std::vector< std::string > getAccountList(); + + /** + * Retrieve details about a given account + */ std::map< std::string, std::string > getAccountDetails(const AccountID& accountID); + + /** + * Save the details of an existing account, given the account ID + */ void setAccountDetails( const ::DBus::String& accountID, const std::map< ::DBus::String, ::DBus::String >& details ); + + /** + * Add a new account, and give it a new account ID automatically + */ + void addAccount(const std::map< ::DBus::String, ::DBus::String >& details); + + /** + * Delete an existing account, unregister VoIPLink associated, and + * purge from configuration. + */ void removeAccount(const AccountID& accountID); + bool getConfigAll(const std::string& sequenceId); bool getConfig(const std::string& section, const std::string& name, TokenList& arg); bool setConfig(const std::string& section, const std::string& name, const std::string& value);