diff --git a/src/settings.cpp b/src/settings.cpp index 89ec2a7..3a610ff 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -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); diff --git a/src/settings.hpp b/src/settings.hpp index 7eff80b..7193849 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -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* getMap (); private: diff --git a/src/udpTracker.cpp b/src/udpTracker.cpp index 2e130a9..3b860bb 100644 --- a/src/udpTracker.cpp +++ b/src/udpTracker.cpp @@ -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);