Fixes for issue #5
This commit is contained in:
parent
622ad93872
commit
db74edbb51
|
@ -102,7 +102,7 @@ void _settings_clean_string (char **str)
|
|||
cil = 0;
|
||||
continue;
|
||||
}
|
||||
if (cil == 0 && c == ';')
|
||||
if (cil == 0 && (c == ';' || c == '#'))
|
||||
{
|
||||
while (i < len)
|
||||
{
|
||||
|
@ -259,7 +259,7 @@ void _settings_clean_string (char **str)
|
|||
{
|
||||
SettingClass *c;
|
||||
|
||||
if (classN == "" || name == "")
|
||||
if (classN == "" || name == "" || value == "")
|
||||
return false;
|
||||
|
||||
c = this->getClass (classN);
|
||||
|
@ -321,9 +321,20 @@ void _settings_clean_string (char **str)
|
|||
int r = _isTrue(v);
|
||||
if (r == 0 || r == 1)
|
||||
return (bool)r;
|
||||
throw exception();
|
||||
throw SettingsException("Invalid boolean value.");
|
||||
}
|
||||
|
||||
bool Settings::SettingClass::getBool (const string& key, bool defaultValue)
|
||||
{
|
||||
try {
|
||||
return this->getBool(key);
|
||||
} catch (SettingsException &e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Settings::SettingClass::getInt (const string& key, int def)
|
||||
{
|
||||
string v = this->get (key);
|
||||
|
|
|
@ -30,6 +30,23 @@ namespace UDPT
|
|||
class Settings
|
||||
{
|
||||
public:
|
||||
class SettingsException : public std::exception
|
||||
{
|
||||
public:
|
||||
SettingsException (const char *str)
|
||||
{
|
||||
this->str = str;
|
||||
}
|
||||
|
||||
const char * what ()
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
const char *str;
|
||||
};
|
||||
|
||||
class SettingClass
|
||||
{
|
||||
public:
|
||||
|
@ -37,6 +54,7 @@ namespace UDPT
|
|||
bool set (const string key, const string value);
|
||||
string get (const string& key);
|
||||
bool getBool (const string& key);
|
||||
bool getBool (const string& key, bool defaultValue);
|
||||
int getInt (const string& key, int def = -1);
|
||||
map<string, string>* getMap ();
|
||||
private:
|
||||
|
|
|
@ -42,9 +42,9 @@ namespace UDPT
|
|||
|
||||
sc_tracker = settings->getClass("tracker");
|
||||
|
||||
this->allowRemotes = sc_tracker->getBool("allow_remotes");
|
||||
this->allowIANA_IPs = sc_tracker->getBool("allow_iana_ips");
|
||||
this->isDynamic = sc_tracker->getBool("is_dynamic");
|
||||
this->allowRemotes = sc_tracker->getBool("allow_remotes", true);
|
||||
this->allowIANA_IPs = sc_tracker->getBool("allow_iana_ips", false);
|
||||
this->isDynamic = sc_tracker->getBool("is_dynamic", true);
|
||||
|
||||
this->announce_interval = sc_tracker->getInt("announce_interval", 1800);
|
||||
this->cleanup_interval = sc_tracker->getInt("cleanup_interval", 120);
|
||||
|
|
Loading…
Reference in a new issue