Commit 11de0db2 authored by Alexandre Bourget's avatar Alexandre Bourget

Fix the ACCOUNTS loading. Now has a new file format.

The account section as:
[SIP0]
Blah1=1
Blah2=2

It now looks like:
[Account:4jd82]
Blah1=1
Blah2=2
Account.type=IAX|SIP

etc..

Backup your ~/.sflphone/sflphonedrc file.
parent 92431fe9
......@@ -41,6 +41,7 @@ Account::~Account()
void
Account::initConfig(Conf::ConfigTree& config) {
/*
std::string section(_accountID);
std::string type_str("string");
std::string type_int("int");
......@@ -48,6 +49,7 @@ Account::initConfig(Conf::ConfigTree& config) {
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_ENABLE,"1", type_int));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_AUTO_REGISTER, "1", type_int));
config.addConfigTreeItem(section, Conf::ConfigTreeItem(CONFIG_ACCOUNT_ALIAS, _("My account"), type_str));
*/
}
......
......@@ -90,31 +90,6 @@ ConfigTree::addConfigTreeItem(const std::string& section, const ConfigTreeItem i
}
}
/**
* Add the config item only if it doesn't exist. Set the default value.
*/
void
ConfigTree::verifyConfigTreeItem(const std::string& section,
const std::string& itemName,
const std::string& defaultValue,
const std::string& type)
{
// Create section if it doesn't exist.
SectionMap::iterator iter = _sections.find(section);
if ( iter == _sections.end()) {
_sections[section] = new ItemMap;
iter = _sections.find(section);
}
// Check for the item, and add it if necessary (with default value).
ItemMap::iterator iterItem = iter->second->find(itemName);
if ( iterItem == iter->second->end()) {
// It's not there, create it.
addConfigTreeItem(section, ConfigTreeItem(itemName, defaultValue, type));
}
}
// throw a ConfigTreeItemException if not found
std::string
ConfigTree::getConfigTreeItemValue(const std::string& section, const std::string& itemName)
......@@ -123,7 +98,7 @@ ConfigTree::getConfigTreeItemValue(const std::string& section, const std::string
if (item != NULL) {
return item->getValue();
} else {
_debug("Unknown config option: [%s] %s\n", section.c_str(), itemName.c_str());
_debug("Option doesn't exist: [%s] %s\n", section.c_str(), itemName.c_str());
//throw ConfigTreeItemException();
}
return "";
......@@ -133,14 +108,7 @@ ConfigTree::getConfigTreeItemValue(const std::string& section, const std::string
int
ConfigTree::getConfigTreeItemIntValue(const std::string& section, const std::string& itemName)
{
ConfigTreeItem* item = getConfigTreeItem(section, itemName);
if (item != NULL && item->getType() == "int") {
return atoi(item->getValue().data());
} else {
_debug("Unknown config (int) option: [%s] %s\n", section.c_str(), itemName.c_str());
//throw ConfigTreeItemException();
}
return 0;
return atoi(getConfigTreeItemValue(section, itemName).data());
}
bool
......@@ -179,8 +147,6 @@ ConfigTree::getConfigTreeItem(const std::string& section, const std::string& ite
/**
* Set the configItem if found, if not, *CREATE IT*
*
* @todo Faudra démêler tout ça, le verifyConfigTreeItem et setConfigTree qui font
* la même chose, et qui, inutilement, y'a plein de restrictions.
* @todo Élimier les 45,000 classes qui servent à rien pour Conf.
*/
bool
......
......@@ -78,20 +78,36 @@ public:
void addConfigTreeItem(const std::string& section, const ConfigTreeItem item);
/**
* Verify an item is there. If it's not, add it with the provided
* default value
* Set a configuration value.
*
* @param section Section
* @param
* @param section Write to this [section] of the .ini file
* @param itemName The itemName= in the .ini file
* @param value The value to assign to that itemName
*/
void verifyConfigTreeItem(const std::string& section, const std::string& itemName,
const std::string& defaultValue, const std::string& type);
bool setConfigTreeItem(const std::string& section, const std::string& itemName, const std::string& value);
// throw a ConfigTreeItemException if not found
/**
* Get a value.
*
* This function does all the validity tests, so none are needed throughout
* the program.
*
* @param section The name of the [section] in the .ini file.
* @param itemName The name of the item= in the .ini file.
* @return The value of the corresponding item. The default value if the section exists
* but the item doesn't.
*/
std::string getConfigTreeItemValue(const std::string& section, const std::string& itemName);
int getConfigTreeItemIntValue(const std::string& section, const std::string& itemName);
/**
* Flush data to .ini file
*/
bool saveConfigTree(const std::string& fileName);
/**
* Load data (and fill ConfigTree) from disk
*/
int populateFromFile(const std::string& fileName);
bool getConfigTreeItemToken(const std::string& section, const std::string& itemName, TokenList& arg);
......@@ -99,6 +115,9 @@ public:
private:
ConfigTreeItem* getConfigTreeItem(const std::string& section, const std::string& itemName);
/**
* List of sections. Each sections has an ItemList as child
*/
SectionMap _sections;
friend class ConfigTreeIterator;
......
......@@ -42,9 +42,9 @@ IAXAccount::registerAccount()
IAXVoIPLink* tmplink = dynamic_cast<IAXVoIPLink*> (_link);
if (tmplink) {
// Stuff needed for IAX registration
tmplink->setHost(Manager::instance().getConfigString(_accountID,IAX_HOST));
tmplink->setUser(Manager::instance().getConfigString(_accountID,IAX_USER));
tmplink->setPass(Manager::instance().getConfigString(_accountID,IAX_PASS));
tmplink->setHost(Manager::instance().getConfigString(_accountID, IAX_HOST));
tmplink->setUser(Manager::instance().getConfigString(_accountID, IAX_USER));
tmplink->setPass(Manager::instance().getConfigString(_accountID, IAX_PASS));
}
_registered = _link->setRegister();
}
......@@ -85,6 +85,7 @@ IAXAccount::terminate()
void
IAXAccount::initConfig(Conf::ConfigTree& config)
{
/*
std::string section(_accountID);
std::string type_str("string");
std::string type_int("int");
......@@ -98,6 +99,7 @@ IAXAccount::initConfig(Conf::ConfigTree& config)
config.verifyConfigTreeItem(section, IAX_HOST, "", type_str);
config.verifyConfigTreeItem(section, IAX_USER, "", type_str);
config.verifyConfigTreeItem(section, IAX_PASS, "", type_str);
*/
}
void
......
......@@ -95,6 +95,7 @@ SIPAccount::terminate()
void
SIPAccount::initConfig(Conf::ConfigTree& config)
{
/*
std::string section(_accountID);
std::string type_str("string");
std::string type_int("int");
......@@ -112,6 +113,7 @@ SIPAccount::initConfig(Conf::ConfigTree& config)
config.verifyConfigTreeItem(section, SIP_PROXY, "", type_str);
config.verifyConfigTreeItem(section, SIP_STUN_SERVER, "stun.fwdnet.net:3478", type_str);
config.verifyConfigTreeItem(section, SIP_USE_STUN, "0", type_int);
*/
}
void
......
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