Changeset e11d494 in nscp for helpers


Ignore:
Timestamp:
07/25/11 23:16:48 (22 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
04ef932
Parents:
7ec3dd1
Message:

2011-07-25

  • merged in all 0.3.9 changes into 0.4.0
  • refactored where filter to be "non template" to drastically reduce compile time (as well as potentially size if I ever go dll instead of static link)
  • streamlined checkeventlog toi be same as "the other" where filters as well as dropped support of "old" syntax.
Location:
helpers
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • helpers/installer-dlls/main_dll/main_dll.cpp

    r3bdaf18 re11d494  
    114114class installer_logger : public settings::logger_interface { 
    115115public: 
    116   msi_helper &h; 
     116  msi_helper *h; 
    117117  std::wstring error; 
    118  
    119   installer_logger(msi_helper &h) : h(h) {} 
     118  std::list<std::wstring> debug_log; 
     119 
     120  installer_logger(msi_helper *h) : h(h) {} 
    120121 
    121122  virtual void err(std::string file, int line, std::wstring message) { 
    122123    error = message; 
    123     h.logMessage(_T("ERROR: ") + message); 
     124    h->logMessage(_T("ERROR: ") + message); 
     125    debug_log.push_back(_T("ERROR: ") + message); 
    124126  } 
    125127  virtual void warn(std::string file, int line, std::wstring message) { 
    126     h.logMessage(_T("WARN: ") + message); 
     128    h->logMessage(_T("WARN: ") + message); 
     129    debug_log.push_back(_T("WARN: ") + message); 
    127130  } 
    128131  virtual void info(std::string file, int line, std::wstring message) { 
    129     h.logMessage(_T("INFO: ") + message); 
    130   } 
    131   virtual void debug(std::string file, int line, std::wstring message) {} 
     132    h->logMessage(_T("INFO: ") + message); 
     133    debug_log.push_back(_T("INFO: ") + message); 
     134  } 
     135  virtual void debug(std::string file, int line, std::wstring message) { 
     136    debug_log.push_back(_T("DEBUG: ") + message); 
     137  } 
     138  std::list<std::wstring> get_debug() { 
     139    return debug_log; 
     140  } 
    132141}; 
    133142 
    134143struct installer_settings_provider : public settings_manager::provider_interface { 
    135144 
    136   msi_helper &h; 
     145  msi_helper *h; 
    137146  std::wstring basepath; 
    138147  installer_logger logger; 
    139148 
    140   installer_settings_provider(msi_helper &h, std::wstring basepath) : h(h), logger(h), basepath(basepath) {} 
     149  installer_settings_provider(msi_helper *h, std::wstring basepath) : h(h), logger(h), basepath(basepath) {} 
    141150 
    142151  virtual std::wstring expand_path(std::wstring file) { 
     
    157166  std::wstring get_error() { 
    158167    return logger.error; 
     168  } 
     169  std::list<std::wstring> get_debug() { 
     170    return logger.get_debug(); 
    159171  } 
    160172}; 
     
    199211    } 
    200212 
    201     installer_settings_provider provider(h, target); 
     213    installer_settings_provider provider(&h, target); 
    202214    if (!settings_manager::init_settings(&provider, _T(""))) { 
     215      h.logMessage(_T("Settings context had fatal errors")); 
    203216      h.setProperty(_T("CONF_OLD_ERROR"), provider.get_error()); 
    204217      h.setProperty(_T("CONF_CAN_CHANGE"), _T("0")); 
    205218      h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 
    206219      h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); 
    207       return ERROR_SUCCESS; 
    208220    } 
    209221    if (provider.has_error()) { 
    210       h.setProperty(_T("CONF_OLD_ERROR"), provider.get_error()); 
    211       h.setProperty(_T("CONF_CAN_CHANGE"), _T("0")); 
    212       h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 
    213       h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); 
    214       return ERROR_SUCCESS; 
    215     } 
     222      h.logMessage(_T("Settings context reported errors (debug log end)")); 
     223      BOOST_FOREACH(std::wstring l, provider.get_debug()) { 
     224        h.logMessage(l); 
     225      } 
     226      h.logMessage(_T("Settings context reported errors (debug log end)")); 
     227      if (!settings_manager::has_boot_conf()) { 
     228        h.logMessage(_T("boot.conf was NOT found (so no new configuration)")); 
     229        if (settings_manager::context_exists(DEFAULT_CONF_OLD_LOCATION)) { 
     230          h.logMessage(std::wstring(_T("Old configuration found: ")) + DEFAULT_CONF_OLD_LOCATION); 
     231          h.setProperty(_T("CONF_OLD_ERROR"), std::wstring(_T("Old configuration (")) + DEFAULT_CONF_OLD_LOCATION + _T(") was found but we got errors accessing it: ") + provider.get_error()); 
     232          h.setProperty(_T("CONF_CAN_CHANGE"), _T("0")); 
     233          h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 
     234          h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); 
     235          return ERROR_SUCCESS; 
     236        } else { 
     237          h.logMessage(_T("Failed to read configuration but no configuration was found (so we are assuming there is no configuration).")); 
     238          h.setProperty(_T("CONF_CAN_CHANGE"), _T("1")); 
     239          h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 
     240          h.setProperty(_T("CONF_HAS_ERRORS"), _T("0")); 
     241          return ERROR_SUCCESS; 
     242        } 
     243      } else { 
     244        h.logMessage(_T("boot.conf was found but we got errors booting it...")); 
     245        h.setProperty(_T("CONF_OLD_ERROR"), provider.get_error()); 
     246        h.setProperty(_T("CONF_CAN_CHANGE"), _T("0")); 
     247        h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 
     248        h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); 
     249        return ERROR_SUCCESS; 
     250      } 
     251    } 
     252 
     253 
    216254    h.setProperty(_T("CONFIGURATION_TYPE"), settings_manager::get_settings()->get_context()); 
    217255    h.setProperty(_T("CONF_CAN_CHANGE"), _T("1")); 
    218     h.setProperty(_T("CONF_OLD_FOUND"), _T("1")); 
    219256    h.setProperty(_T("CONF_HAS_ERRORS"), _T("0")); 
    220257 
     
    341378    int add_defaults = data.get_next_int(); 
    342379 
    343     installer_settings_provider provider(h, target); 
    344     if (!settings_manager::init_settings(&provider, _T(""))) { 
     380    installer_settings_provider provider(&h, target); 
     381    if (!settings_manager::init_settings(&provider, context)) { 
    345382      h.errorMessage(_T("Failed to boot settings: ") + provider.get_error()); 
    346383      return ERROR_INSTALL_FAILURE; 
    347384    } 
     385    h.logMessage(_T("Switching to: ") + context); 
    348386    settings_manager::change_context(context); 
    349387 
  • helpers/installers/installer/Product.wxs

    r7ec3dd1 re11d494  
    5151              Description="Monitoring agent for nagios (and others) used to respond to status queries" 
    5252              Arguments="--service --run --name [SERVICE_NAME]" /> 
    53             <ServiceControl Id="StartSWCNSCP" Name="[SERVICE_NAME]" Start="install" Wait="no" /> 
    54             <ServiceControl Id="StopSWCNSCP" Name="[SERVICE_NAME]" Stop="both" Wait="yes" Remove="uninstall" /> 
     53            <ServiceControl Id="StartSWCNSCP" Name="[SERVICE_NAME]" Start="install" Stop="both" Wait="yes" Remove="uninstall" /> 
    5554            <RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuDir" On="uninstall" /> 
    5655          </Component> 
  • helpers/installers/ui/SelectConfigurationDlg.wxs

    rb7d17f8 re11d494  
    55      <ComboBox Property='CONFIGURATION_TYPE'> 
    66        <ListItem Value="old://${exe-path}/nsc.ini" Text="Old 0.3.x Configuration (Program Files)" /> 
    7         <ListItem Value="ini://${shared-path}/nsclient.ini" Text="INI file (Program files)" /> 
     7        <ListItem Value="ini://${exe-path}/nsclient.ini" Text="INI file (Program files)" /> 
    88        <ListItem Value="registry://HKEY_LOCAL_MACHINE/software/NSClient++" Text="Registry (HKLM)" /> 
    99      </ComboBox> 
  • helpers/settings_manager/settings_manager_impl.cpp

    rb7d17f8 re11d494  
    101101    return false; 
    102102  } 
     103 
     104  std::wstring NSCSettingsImpl::expand_context(std::wstring key) { 
     105#ifdef WIN32 
     106    if (key == _T("old")) 
     107      return DEFAULT_CONF_OLD_LOCATION; 
     108    if (key == _T("registry")) 
     109      return DEFAULT_CONF_REG_LOCATION; 
     110#endif 
     111    if (key == _T("ini")) 
     112      return DEFAULT_CONF_INI_LOCATION; 
     113    return key; 
     114  } 
     115 
     116  bool NSCSettingsImpl::context_exists(std::wstring key) { 
     117    net::wurl url = net::parse(key); 
     118#ifdef WIN32 
     119    if (url.protocol == _T("old")) 
     120      return settings::OLDSettings::context_exists(this, key); 
     121    if (url.protocol == _T("registry")) 
     122      return settings::REGSettings::context_exists(this, key); 
     123#endif 
     124    if (url.protocol == _T("ini")) 
     125      return settings::INISettings::context_exists(this, key); 
     126    if (url.protocol == _T("http")) 
     127      return true; 
     128    return false; 
     129  } 
     130 
     131  bool NSCSettingsImpl::has_boot_conf() { 
     132    return file_helpers::checks::exists(boot_.string()); 
     133  } 
     134 
    103135  ////////////////////////////////////////////////////////////////////////// 
    104136  /// Boot the settings subsystem from the given file (boot.ini). 
     
    107139  /// 
    108140  /// @author mickem 
    109   void NSCSettingsImpl::boot(std::wstring file) { 
    110     std::wstring key = file; 
    111     if (file.empty()) { 
    112       boot_ = provider_->expand_path(BOOT_CONF_LOCATION); 
    113       get_logger()->debug(__FILE__, __LINE__, _T("---> ") + boot_.string()); 
    114       if (file_helpers::checks::exists(boot_.string())) { 
    115         key = get_boot_string(_T("settings"), _T("location"), DEFAULT_CONF_LOCATION); 
    116         get_logger()->debug(__FILE__, __LINE__, _T("---> ") + key); 
    117       } else { 
    118         if (!check_file(DEFAULT_CONF_OLD_LOCATION, _T("old"), key)) 
    119           if (!check_file(DEFAULT_CONF_INI_LOCATION, _T("ini"), key)) 
    120             key = DEFAULT_CONF_LOCATION; 
     141  void NSCSettingsImpl::boot(std::wstring key) { 
     142    std::list<std::wstring> order; 
     143    if (!key.empty()) { 
     144      order.push_back(key); 
     145    }  
     146    boot_ = provider_->expand_path(BOOT_CONF_LOCATION); 
     147    if (file_helpers::checks::exists(boot_.string())) { 
     148      get_logger()->debug(__FILE__, __LINE__, _T("Boot.ini found in: ") + boot_.string()); 
     149      for (int i=0;i<20;i++) { 
     150        std::wstring v = get_boot_string(_T("settings"), strEx::itos(i), _T("")); 
     151        if (!v.empty())  
     152          order.push_back(expand_context(v)); 
    121153      } 
    122154    } 
    123     set_instance(key); 
     155    if (order.size() == 0) { 
     156      get_logger()->debug(__FILE__, __LINE__, _T("No entries found looking in (adding default): ") + boot_.string()); 
     157      order.push_back(DEFAULT_CONF_OLD_LOCATION); 
     158      order.push_back(DEFAULT_CONF_INI_LOCATION); 
     159    } 
     160    int i=0; 
     161    std::wstring boot_order; 
     162    BOOST_FOREACH(std::wstring k, order) { 
     163      strEx::append_list(boot_order, k, _T(", ")); 
     164    } 
     165    get_logger()->debug(__FILE__, __LINE__, _T("Boot order: ") + boot_order); 
     166    BOOST_FOREACH(std::wstring k, order) { 
     167      if (context_exists(k)) { 
     168        get_logger()->debug(__FILE__, __LINE__, _T("Activating: ") + k); 
     169        set_instance(k); 
     170        return; 
     171      } 
     172    } 
     173    if (!key.empty()) { 
     174      get_logger()->info(__FILE__, __LINE__, _T("No valid settings found but one was givben (using that): ") + key); 
     175      set_instance(key); 
     176      return; 
     177    }  
     178 
     179    get_logger()->err(__FILE__, __LINE__, _T("No valid settings found (tried): ") + boot_order); 
     180  } 
     181 
     182  void NSCSettingsImpl::set_primary(std::wstring key) { 
     183    std::list<std::wstring> order; 
     184    for (int i=0;i<20;i++) { 
     185      std::wstring v = get_boot_string(_T("settings"), strEx::itos(i), _T("")); 
     186      if (!v.empty()) { 
     187        order.push_back(expand_context(v)); 
     188        set_boot_string(_T("settings"), strEx::itos(i), _T("")); 
     189      } 
     190    } 
     191    order.remove(key); 
     192    order.push_front(key); 
     193    int i=1; 
     194    BOOST_FOREACH(std::wstring k, order) { 
     195      set_boot_string(_T("settings"), strEx::itos(i++), k); 
     196    } 
     197  } 
     198 
     199 
     200  bool NSCSettingsImpl::create_context(std::wstring key) { 
     201    try { 
     202      change_context(key); 
     203    } catch (settings::settings_exception e) { 
     204      provider_->log_fatal_error(_T("Failed to initialize settings: ") + e.getError()); 
     205      return false; 
     206    } catch (...) { 
     207      provider_->log_fatal_error(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 
     208      return false; 
     209    } 
     210    return true; 
    124211  } 
    125212 
     
    156243  } 
    157244 
     245  bool has_boot_conf() { 
     246    return settings_impl->has_boot_conf(); 
     247  } 
     248  bool context_exists(std::wstring key) { 
     249    return settings_impl->context_exists(key); 
     250  } 
     251  bool create_context(std::wstring key) { 
     252    return settings_impl->create_context(key); 
     253  } 
     254 
     255 
    158256} 
  • helpers/settings_manager/settings_manager_impl.h

    rb7d17f8 re11d494  
    4747    } 
    4848 
    49     void boot(std::wstring file = _T("boot.ini")); 
     49    std::wstring expand_context(std::wstring key); 
     50    void boot(std::wstring file = BOOT_CONF_LOCATION); 
    5051    std::wstring find_file(std::wstring file, std::wstring fallback = _T("")); 
    5152    std::wstring expand_path(std::wstring file); 
     
    5354    bool check_file(std::wstring file, std::wstring tag, std::wstring &key); 
    5455    void change_context(std::wstring file); 
     56    bool context_exists(std::wstring key); 
     57    bool create_context(std::wstring key); 
     58    bool has_boot_conf(); 
     59    void set_primary(std::wstring key); 
    5560  }; 
    5661 
     
    6570  bool init_settings(provider_interface *provider, std::wstring context = _T("")); 
    6671  void change_context(std::wstring context); 
     72  bool has_boot_conf(); 
     73  bool context_exists(std::wstring key); 
     74  bool create_context(std::wstring key); 
    6775} 
Note: See TracChangeset for help on using the changeset viewer.