Changeset 8b89aba in nscp


Ignore:
Timestamp:
03/22/06 06:45:44 (7 years ago)
Author:
Michael Medin <michael@…>
Children:
c8ebdec
Parents:
99bb030
Message:

Nya settingssysmetet kompilerar

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/NSC.dist

    r99bb030 r8b89aba  
    3535;  If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password). 
    3636;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. 
     40use_file=1 
    3741 
    3842[log] 
  • trunk/include/Settings.h

    r99bb030 r8b89aba  
    66#include <windows.h> 
    77#include <INISettings.h> 
     8#include <REGSettings.h> 
    89#define BUFF_LEN 4096 
     10 
     11class SettingsException { 
     12public: 
     13  SettingsException(std::string str) {} 
     14 
     15}; 
    916 
    1017class SettingsT 
     
    2128  saveSectionList data_; 
    2229  bool bHasInternalData; 
    23   INISettings iniManager; 
     30  TSettings *settingsManager; 
     31 
    2432public: 
    2533  typedef std::list<std::string> sectionList; 
    26   SettingsT(void) : bHasInternalData(false) 
     34  SettingsT(void) : bHasInternalData(false), settingsManager(NULL) 
    2735  { 
    2836  } 
     
    3038  virtual ~SettingsT(void) 
    3139  { 
     40    if (settingsManager) 
     41      delete settingsManager; 
    3242  } 
    3343 
     
    3646   * @param file A INI-file to use as settings repository 
    3747   */ 
    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    } 
    4066  } 
    4167 
    42 #define UNLIKELY_VALUE -1234 
     68#define UNLIKELY_VALUE_1 -1234 
     69#define UNLIKELY_VALUE_2 -4321 
    4370  void read() { 
    4471    sectionList sections = getSections(); 
     
    4673      sectionList section = getSection(*it); 
    4774      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); 
    5191        } 
    5292      } 
     
    5595 
    5696  sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 
     97    if (!settingsManager) 
     98      throw SettingsException("No settings manager found have you configured."); 
    5799    sectionList ret; 
    58     ret = iniManager.getSections(); 
     100    ret = settingsManager->getSections(); 
    59101    if (bHasInternalData) { 
    60102      for (saveSectionList::const_iterator kit = data_.begin(); kit != data_.end(); ++kit) { 
     
    73115   */ 
    74116  sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 
     117    if (!settingsManager) 
     118      throw SettingsException("No settings manager found have you configured."); 
    75119    sectionList ret; 
    76     ret = iniManager.getSection(section); 
     120    ret = settingsManager->getSection(section); 
    77121    if (bHasInternalData) { 
    78122      saveSectionList::const_iterator it = data_.find(section); 
     
    95139   */ 
    96140  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."); 
    97143    if (bHasInternalData) { 
    98144      saveSectionList::const_iterator it = data_.find(section); 
     
    103149            return kit->second.sVal; 
    104150          else 
    105             throw "whoops"; 
     151            return strEx::itos(kit->second.iVal); 
    106152        } 
    107153      } 
    108154    } 
    109     std::string ret = iniManager.getString(section, key, defaultValue); 
     155    std::string ret = settingsManager->getString(section, key, defaultValue); 
    110156    return ret; 
    111157  } 
     
    125171   */ 
    126172  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); 
    128188  } 
    129189  void setInt(std::string section, std::string key, int value) { 
  • trunk/include/config.h

    r99bb030 r8b89aba  
    9595// Main Settings 
    9696#define MAIN_SECTION_TITLE "Settings" 
     97#define MAIN_USEFILE "use_file" 
     98#define MAIN_USEFILE_DEFAULT 0 
    9799#define MAIN_MASTERKEY "master_key"  
    98100#define MAIN_MASTERKEY_DEFAULT "This is a secret key that you should change" 
  • trunk/modules/CheckSystem/PDHCollector.cpp

    r9bc31a8 r8b89aba  
    6565    std::string prefix; 
    6666    std::string section; 
    67     settings.setFile(NSCModuleHelper::getBasePath() + "\\counters.defs"); 
     67    settings.setFile(NSCModuleHelper::getBasePath() + "\\counters.defs", true); 
    6868 
    6969 
  • trunk/modules/NSClientListener/NSClientListener.cpp

    r99bb030 r8b89aba  
    3333} 
    3434std::string getAllowedHosts() { 
    35   std::string ret = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS, ""); 
     35  std::string ret = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, MAIN_ALLOWED_HOSTS, ""); 
    3636  if (ret.empty()) 
    3737    ret = NSCModuleHelper::getSettingsString(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS, MAIN_ALLOWED_HOSTS_DEFAULT); 
     
    4141bool NSClientListener::loadModule() { 
    4242  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
    43   unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 
    44   std::string host = NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT); 
    45   unsigned int backLog = NSCModuleHelper::getSettingsInt(NRPE_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); 
    4646  try { 
    4747    socket.setHandler(this); 
Note: See TracChangeset for help on using the changeset viewer.