Commit c7b30f5a authored by Alexandre Bourget's avatar Alexandre Bourget

Correct support for add/remove Accounts.

parent 1093d618
......@@ -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);
}
......
......@@ -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();
}
......
......@@ -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);
......
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