- Timestamp:
- 07/25/11 23:16:48 (22 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 04ef932
- Parents:
- 7ec3dd1
- Location:
- helpers
- Files:
-
- 3 added
- 5 edited
-
installer-dlls/main_dll/main_dll.cpp (modified) (4 diffs)
-
installers/installer/Product.wxs (modified) (1 diff)
-
installers/ui/SelectConfigurationDlg.wxs (modified) (1 diff)
-
settings_manager/settings_manager_impl.cpp (modified) (3 diffs)
-
settings_manager/settings_manager_impl.h (modified) (3 diffs)
-
where_filter/CMakeLists.txt (added)
-
where_filter/StdAfx.cpp (added)
-
where_filter/StdAfx.h (added)
Legend:
- Unmodified
- Added
- Removed
-
helpers/installer-dlls/main_dll/main_dll.cpp
r3bdaf18 re11d494 114 114 class installer_logger : public settings::logger_interface { 115 115 public: 116 msi_helper &h;116 msi_helper *h; 117 117 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) {} 120 121 121 122 virtual void err(std::string file, int line, std::wstring message) { 122 123 error = message; 123 h.logMessage(_T("ERROR: ") + message); 124 h->logMessage(_T("ERROR: ") + message); 125 debug_log.push_back(_T("ERROR: ") + message); 124 126 } 125 127 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); 127 130 } 128 131 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 } 132 141 }; 133 142 134 143 struct installer_settings_provider : public settings_manager::provider_interface { 135 144 136 msi_helper &h;145 msi_helper *h; 137 146 std::wstring basepath; 138 147 installer_logger logger; 139 148 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) {} 141 150 142 151 virtual std::wstring expand_path(std::wstring file) { … … 157 166 std::wstring get_error() { 158 167 return logger.error; 168 } 169 std::list<std::wstring> get_debug() { 170 return logger.get_debug(); 159 171 } 160 172 }; … … 199 211 } 200 212 201 installer_settings_provider provider( h, target);213 installer_settings_provider provider(&h, target); 202 214 if (!settings_manager::init_settings(&provider, _T(""))) { 215 h.logMessage(_T("Settings context had fatal errors")); 203 216 h.setProperty(_T("CONF_OLD_ERROR"), provider.get_error()); 204 217 h.setProperty(_T("CONF_CAN_CHANGE"), _T("0")); 205 218 h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); 206 219 h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); 207 return ERROR_SUCCESS;208 220 } 209 221 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 216 254 h.setProperty(_T("CONFIGURATION_TYPE"), settings_manager::get_settings()->get_context()); 217 255 h.setProperty(_T("CONF_CAN_CHANGE"), _T("1")); 218 h.setProperty(_T("CONF_OLD_FOUND"), _T("1"));219 256 h.setProperty(_T("CONF_HAS_ERRORS"), _T("0")); 220 257 … … 341 378 int add_defaults = data.get_next_int(); 342 379 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)) { 345 382 h.errorMessage(_T("Failed to boot settings: ") + provider.get_error()); 346 383 return ERROR_INSTALL_FAILURE; 347 384 } 385 h.logMessage(_T("Switching to: ") + context); 348 386 settings_manager::change_context(context); 349 387 -
helpers/installers/installer/Product.wxs
r7ec3dd1 re11d494 51 51 Description="Monitoring agent for nagios (and others) used to respond to status queries" 52 52 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" /> 55 54 <RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuDir" On="uninstall" /> 56 55 </Component> -
helpers/installers/ui/SelectConfigurationDlg.wxs
rb7d17f8 re11d494 5 5 <ComboBox Property='CONFIGURATION_TYPE'> 6 6 <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)" /> 8 8 <ListItem Value="registry://HKEY_LOCAL_MACHINE/software/NSClient++" Text="Registry (HKLM)" /> 9 9 </ComboBox> -
helpers/settings_manager/settings_manager_impl.cpp
rb7d17f8 re11d494 101 101 return false; 102 102 } 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 103 135 ////////////////////////////////////////////////////////////////////////// 104 136 /// Boot the settings subsystem from the given file (boot.ini). … … 107 139 /// 108 140 /// @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)); 121 153 } 122 154 } 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; 124 211 } 125 212 … … 156 243 } 157 244 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 158 256 } -
helpers/settings_manager/settings_manager_impl.h
rb7d17f8 re11d494 47 47 } 48 48 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); 50 51 std::wstring find_file(std::wstring file, std::wstring fallback = _T("")); 51 52 std::wstring expand_path(std::wstring file); … … 53 54 bool check_file(std::wstring file, std::wstring tag, std::wstring &key); 54 55 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); 55 60 }; 56 61 … … 65 70 bool init_settings(provider_interface *provider, std::wstring context = _T("")); 66 71 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); 67 75 }
Note: See TracChangeset
for help on using the changeset viewer.








