Changeset 8b89aba in nscp
- Timestamp:
- 03/22/06 06:45:44 (7 years ago)
- Children:
- c8ebdec
- Parents:
- 99bb030
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
-
NSC.dist (modified) (1 diff)
-
include/INISettings.h (added)
-
include/REGSettings.h (added)
-
include/Settings.h (modified) (10 diffs)
-
include/TSettings.h (added)
-
include/config.h (modified) (1 diff)
-
modules/CheckSystem/PDHCollector.cpp (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSC.dist
r99bb030 r8b89aba 35 35 ; If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password). 36 36 ;allowed_hosts=127.0.0.1 37 ; 38 ;# USE THIS FILE 39 ; Use the INI file as opposed to the registry if this is 0 the registry will be used instead. 40 use_file=1 37 41 38 42 [log] -
trunk/include/Settings.h
r99bb030 r8b89aba 6 6 #include <windows.h> 7 7 #include <INISettings.h> 8 #include <REGSettings.h> 8 9 #define BUFF_LEN 4096 10 11 class SettingsException { 12 public: 13 SettingsException(std::string str) {} 14 15 }; 9 16 10 17 class SettingsT … … 21 28 saveSectionList data_; 22 29 bool bHasInternalData; 23 INISettings iniManager; 30 TSettings *settingsManager; 31 24 32 public: 25 33 typedef std::list<std::string> sectionList; 26 SettingsT(void) : bHasInternalData(false) 34 SettingsT(void) : bHasInternalData(false), settingsManager(NULL) 27 35 { 28 36 } … … 30 38 virtual ~SettingsT(void) 31 39 { 40 if (settingsManager) 41 delete settingsManager; 32 42 } 33 43 … … 36 46 * @param file A INI-file to use as settings repository 37 47 */ 38 void setFile(std::string file) { 39 iniManager.setFile(file); 48 void setFile(std::string file, bool forceini = false) { 49 if (forceini) { 50 if (settingsManager) 51 delete settingsManager; 52 settingsManager = new INISettings(file); 53 return; 54 } 55 if (REGSettings::hasSettings()) { 56 if (settingsManager) 57 delete settingsManager; 58 settingsManager = new REGSettings(); 59 } else if (INISettings::hasSettings(file)) { 60 if (settingsManager) 61 delete settingsManager; 62 settingsManager = new INISettings(file); 63 } else { 64 throw SettingsException("No settings method specified, cannot start"); 65 } 40 66 } 41 67 42 #define UNLIKELY_VALUE -1234 68 #define UNLIKELY_VALUE_1 -1234 69 #define UNLIKELY_VALUE_2 -4321 43 70 void read() { 44 71 sectionList sections = getSections(); … … 46 73 sectionList section = getSection(*it); 47 74 for (sectionList::const_iterator it2=section.begin();it2!=section.end();++it2) { 48 int i = getInt((*it), (*it2), UNLIKELY_VALUE); 49 if (i == UNLIKELY_VALUE) { 50 getString((*it), (*it2)); 75 int i = getInt((*it), (*it2), UNLIKELY_VALUE_1); 76 if (i == UNLIKELY_VALUE_1) { 77 if (getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) 78 getString((*it), (*it2)); 79 } 80 } 81 } 82 } 83 void write() { 84 if (bHasInternalData) { 85 for (saveSectionList::const_iterator it=data_.begin();it!=data_.end();++it) { 86 for (saveKeyList::const_iterator kit = it->second.begin(); kit != it->second.end(); ++kit) { 87 if (kit->second.type == valueStruct::sType) 88 setString(it->first, kit->first, kit->second.sVal); 89 else 90 setInt(it->first, kit->first, kit->second.iVal); 51 91 } 52 92 } … … 55 95 56 96 sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 97 if (!settingsManager) 98 throw SettingsException("No settings manager found have you configured."); 57 99 sectionList ret; 58 ret = iniManager.getSections();100 ret = settingsManager->getSections(); 59 101 if (bHasInternalData) { 60 102 for (saveSectionList::const_iterator kit = data_.begin(); kit != data_.end(); ++kit) { … … 73 115 */ 74 116 sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 117 if (!settingsManager) 118 throw SettingsException("No settings manager found have you configured."); 75 119 sectionList ret; 76 ret = iniManager.getSection(section);120 ret = settingsManager->getSection(section); 77 121 if (bHasInternalData) { 78 122 saveSectionList::const_iterator it = data_.find(section); … … 95 139 */ 96 140 std::string getString(std::string section, std::string key, std::string defaultValue = "") const { 141 if (!settingsManager) 142 throw SettingsException("No settings manager found have you configured."); 97 143 if (bHasInternalData) { 98 144 saveSectionList::const_iterator it = data_.find(section); … … 103 149 return kit->second.sVal; 104 150 else 105 throw "whoops";151 return strEx::itos(kit->second.iVal); 106 152 } 107 153 } 108 154 } 109 std::string ret = iniManager.getString(section, key, defaultValue);155 std::string ret = settingsManager->getString(section, key, defaultValue); 110 156 return ret; 111 157 } … … 125 171 */ 126 172 int getInt(std::string section, std::string key, int defaultValue = 0) { 127 return iniManager.getInt(section, key, defaultValue); 173 if (!settingsManager) 174 throw SettingsException("No settings manager found have you configured."); 175 if (bHasInternalData) { 176 saveSectionList::const_iterator it = data_.find(section); 177 if (it != data_.end()) { 178 saveKeyList::const_iterator kit = it->second.find(key); 179 if (kit != it->second.end()) { 180 if (kit->second.type == valueStruct::sType) 181 return strEx::stoi(kit->second.sVal); 182 else 183 return kit->second.iVal; 184 } 185 } 186 } 187 return settingsManager->getInt(section, key, defaultValue); 128 188 } 129 189 void setInt(std::string section, std::string key, int value) { -
trunk/include/config.h
r99bb030 r8b89aba 95 95 // Main Settings 96 96 #define MAIN_SECTION_TITLE "Settings" 97 #define MAIN_USEFILE "use_file" 98 #define MAIN_USEFILE_DEFAULT 0 97 99 #define MAIN_MASTERKEY "master_key" 98 100 #define MAIN_MASTERKEY_DEFAULT "This is a secret key that you should change" -
trunk/modules/CheckSystem/PDHCollector.cpp
r9bc31a8 r8b89aba 65 65 std::string prefix; 66 66 std::string section; 67 settings.setFile(NSCModuleHelper::getBasePath() + "\\counters.defs" );67 settings.setFile(NSCModuleHelper::getBasePath() + "\\counters.defs", true); 68 68 69 69 -
trunk/modules/NSClientListener/NSClientListener.cpp
r99bb030 r8b89aba 33 33 } 34 34 std::string getAllowedHosts() { 35 std::string ret = NSCModuleHelper::getSettingsString(N RPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS, "");35 std::string ret = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, MAIN_ALLOWED_HOSTS, ""); 36 36 if (ret.empty()) 37 37 ret = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS, MAIN_ALLOWED_HOSTS_DEFAULT); … … 41 41 bool NSClientListener::loadModule() { 42 42 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 43 unsigned short port = NSCModuleHelper::getSettingsInt(N RPE_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT);44 std::string host = NSCModuleHelper::getSettingsString(N RPE_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT);45 unsigned int backLog = NSCModuleHelper::getSettingsInt(N RPE_SECTION_TITLE, NRPE_SETTINGS_LISTENQUE, NRPE_SETTINGS_LISTENQUE_DEFAULT);43 unsigned short port = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 44 std::string host = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT); 45 unsigned int backLog = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_LISTENQUE, NSCLIENT_SETTINGS_LISTENQUE_DEFAULT); 46 46 try { 47 47 socket.setHandler(this);
Note: See TracChangeset
for help on using the changeset viewer.








