Changeset 7e54a5f in nscp
- Timestamp:
- 03/08/11 23:40:04 (2 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 569a179
- Parents:
- 197b263
- Files:
-
- 4 edited
-
files/old-settings.map (modified) (3 diffs)
-
include/settings/settings_old.hpp (modified) (10 diffs)
-
service/logger.hpp (modified) (1 diff)
-
service/settings_client.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
files/old-settings.map
rc760fc9 r7e54a5f 28 28 Settings/password=/settings/default/password 29 29 Settings/allowed_hosts=/settings/allowed hosts 30 Settings/shared_session=/settings/shared _session30 Settings/shared_session=/settings/shared session/enabled 31 31 32 32 # Log section … … 37 37 # log/root_folder 38 38 39 NSClient/allowed_hosts=/settings/NSClient Server/allowed hosts40 NSClient/port=/settings/NSClient Server/port41 NSClient/bind_to_address=/settings/NSClient Server/bind to address42 NSClient/socket_timeout=/settings/NSClient Server/socket timeout39 NSClient/allowed_hosts=/settings/NSClient/server/allowed hosts 40 NSClient/port=/settings/NSClient/server/port 41 NSClient/bind_to_address=/settings/NSClient/server/bind to address 42 NSClient/socket_timeout=/settings/NSClient/server/socket timeout 43 43 44 44 NRPE/allowed_hosts=/settings/NRPE/server/allowed hosts … … 69 69 #Script Wrappings/bat= 70 70 71 External Scripts/*=/settings/ External Scripts/command71 External Scripts/*=/settings/external scripts/scripts 72 72 73 73 External Alias/*=/settings/External Alias/command -
include/settings/settings_old.hpp
rc760fc9 r7e54a5f 78 78 typedef std::map<std::wstring,std::wstring> path_map; 79 79 typedef std::map<settings_core::key_path_type,settings_core::key_path_type> key_map; 80 typedef std::pair<std::wstring,std::wstring> section_key_type; 81 typedef std::pair<settings_core::key_path_type,settings_core::key_path_type> keys_key_type; 82 80 83 path_map sections_; 81 84 key_map keys_; … … 97 100 settings_core::key_path_type map_key(settings_core::key_path_type new_key) { 98 101 key_map::iterator it1 = keys_.find(new_key); 99 if (it1 != keys_.end()) 102 if (it1 != keys_.end()) { 103 get_core()->get_logger()->quick_debug(new_key.first + _T(".") + new_key.second + _T(" not found in alias list")); 100 104 return (*it1).second; 105 } 101 106 path_map::iterator it2 = sections_.find(new_key.first); 102 107 if (it2 != sections_.end()) … … 125 130 key = map_key(key); 126 131 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second); 127 return internal_get_value(key.first, key.second .c_str());132 return internal_get_value(key.first, key.second); 128 133 } 129 134 #define UNLIKELY_STRING _T("$$$EMPTY_KEY$$$") … … 131 136 std::wstring internal_get_value(std::wstring path, std::wstring key, int bufferSize = 1024) { 132 137 get_core()->get_logger()->quick_debug(path + _T("//") + key); 138 if (!has_key_int(path, key)) 139 throw KeyNotFoundException(key); 140 133 141 TCHAR* buffer = new TCHAR[bufferSize+2]; 134 142 if (buffer == NULL) 135 throw settings_exception(_T("Out of mem mory error!"));136 int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), UNLIKELY_STRING, buffer, bufferSize, get_file_name().c_str());143 throw settings_exception(_T("Out of memory error!")); 144 int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), _T(""), buffer, bufferSize, get_file_name().c_str()); 137 145 if (retVal == bufferSize-1) { 138 146 delete [] buffer; … … 141 149 std::wstring ret = buffer; 142 150 delete [] buffer; 143 if (ret != UNLIKELY_STRING) 144 return ret; 145 if (has_key_int(path, key)) { 146 return _T(""); 147 } 148 throw KeyNotFoundException(key); 149 //return ret; 151 return ret; 150 152 } 151 153 … … 183 185 /// @author mickem 184 186 virtual bool has_real_key(settings_core::key_path_type key) { 185 return has_key_int(key.first, key.second); 186 } 187 188 bool has_key_int(std::wstring path, std::wstring key, int bufferLength=1024) { 189 string_list ret; 187 settings_core::key_path_type old = map_key(key); 188 return has_key_int(old.first, old.second); 189 } 190 191 192 std::set<std::wstring> internal_read_keys_from_section(std::wstring section, int bufferLength = 1024) { 190 193 TCHAR* buffer = new TCHAR[bufferLength+1]; 191 194 if (buffer == NULL) 192 throw settings_exception(_T("has_key_int:: Failed to allocate memory for buffer!")); 193 std::wstring mapped = map_path(path); 194 unsigned int count = ::GetPrivateProfileSection(mapped.c_str(), buffer, bufferLength-2, get_file_name().c_str()); 195 throw settings_exception(_T("internal_read_keys_from_section:: Failed to allocate memory for buffer!")); 196 unsigned int count = ::GetPrivateProfileSection(section.c_str(), buffer, bufferLength-2, get_file_name().c_str()); 195 197 if (count == bufferLength-2) { 196 198 delete [] buffer; 197 return has_key_int(path, key, bufferLength*10); 198 } 199 199 return internal_read_keys_from_section(section, bufferLength*10); 200 } 201 202 std::set<std::wstring> ret; 200 203 unsigned int last = 0; 201 204 for (unsigned int i=0;i<count;i++) { … … 203 206 std::wstring s = &buffer[last]; 204 207 std::size_t p = s.find('='); 205 if ((p == std::wstring::npos && s == key) || (s.substr(0,p) == key)) { 206 delete [] buffer; 207 return true; 208 } 208 ret.insert((p == std::wstring::npos)?s:s.substr(0,p)); 209 209 last = i+1; 210 210 } 211 211 } 212 212 delete [] buffer; 213 return false; 213 return ret; 214 } 215 216 typedef std::map<std::wstring,std::set<std::wstring> > section_cache_type; 217 section_cache_type section_cache_; 218 bool has_key_int(std::wstring path, std::wstring key) { 219 section_cache_type::const_iterator it = section_cache_.find(path); 220 if (it == section_cache_.end()) { 221 std::set<std::wstring> list = internal_read_keys_from_section(path); 222 section_cache_[path] = list; 223 it = section_cache_.find(path); 224 } 225 return (*it).second.find(key) != (*it).second.end(); 214 226 } 215 227 … … 248 260 virtual void get_real_sections(std::wstring path, string_list &list) { 249 261 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path); 262 263 unsigned int path_length = path.length(); 250 264 //string_list lst = get_mapped_sections(path); 251 265 //list.insert(list.end(), lst.begin(), lst.end()); 252 /* 253 string_list src = int_read_sections(); 254 for (string_list::const_iterator cit = src.begin(); cit != src.end(); ++cit) { 255 std::wstring mapped = get_core()->reverse_map_path((*cit)); 266 BOOST_FOREACH(section_key_type key, sections_) { 267 if (path_length == 0 || path == _T("/")) { 268 std::wstring::size_type pos = key.first.find(L'/', 1); 269 list.push_back(pos == std::wstring::npos?key.first:key.first.substr(0,pos)); 270 } else if (key.first.length() > path_length && path == key.first.substr(0, path_length)) { 271 std::wstring::size_type pos = key.first.find(L'/', path_length+1); 272 list.push_back(pos == std::wstring::npos?key.first.substr(path_length+1):key.first.substr(path_length+1,pos-path_length-1)); 273 } 274 } 275 BOOST_FOREACH(keys_key_type key, keys_) { 256 276 if (path.empty() || path == _T("/")) { 257 std::wstring::size_type pos = mapped.find(L'/', 1);277 std::wstring::size_type pos = key.first.first.find(L'/', 1); 258 278 if (pos != std::wstring::npos) 259 mapped = mapped.substr(0,pos); 260 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: ")) + mapped); 261 list.push_back(mapped); 262 } else if (mapped.length() > path.length() && mapped == path.substr(0, path.length())) { 263 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: FUCKED")) + mapped); 264 } 265 } 266 */ 267 //list.insert(list.end(), src.begin(), src.end()); 268 /* 269 CSimpleIni::TNamesDepend lst; 270 ini.GetAllSections(lst); 271 if (path.empty()) { 272 for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 273 std::wstring mapped = get_core()->reverse_map_path((*cit).pItem); 274 if (mapped.length() > 1) { 275 std::wstring::size_type pos = mapped.find(L'/', 1); 276 if (pos != std::wstring::npos) 277 mapped = mapped.substr(0,pos); 278 } 279 list.push_back(mapped); 280 } 281 } else { 282 for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 283 std::wstring mapped = get_core()->reverse_map_path((*cit).pItem); 284 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Looking for: ")) + mapped + _T(": ") + mapped); 285 std::wstring::size_type mapped_len = mapped.length(); 286 std::wstring::size_type path_len = path.length(); 287 if (mapped_len > path_len+1 && mapped.substr(0,path_len) == path) { 288 std::wstring::size_type pos = mapped.find(L'/', path_len+1); 289 if (pos == std::wstring::npos) 290 mapped = mapped.substr(path_len+1); 291 else 292 mapped = mapped.substr(path_len+1, pos-path_len-1); 293 list.push_back(mapped); 294 } 295 } 296 } 297 */ 279 key.first.first = key.first.first.substr(0,pos); 280 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: ")) + key.first.first); 281 list.push_back(key.first.first); 282 } else if (key.first.first.length() > path_length && path == key.first.first.substr(0, path_length)) { 283 std::wstring::size_type pos = key.first.first.find(L'/', path_length+1); 284 list.push_back(pos == std::wstring::npos?key.first.first.substr(path_length+1):key.first.first.substr(path_length+1,pos-path_length-1)); 285 } 286 } 287 list.unique(); 298 288 } 299 289 … … 336 326 /// @author mickem 337 327 virtual void get_real_keys(std::wstring path, string_list &list) { 338 std::wstring mapped_path = map_path(path); 339 int_read_section(mapped_path, list); 340 /* 341 settings::settings_core::mapped_key_list_type mapped_keys = get_core()->find_maped_keys(path); 342 for (settings::settings_core::mapped_key_list_type::const_iterator cit = mapped_keys.begin(); cit != mapped_keys.end(); ++cit) { 343 if (has_key((*cit).dst.first, (*cit).dst.second)) 344 list.push_back((*cit).src.second); 345 } 346 */ 347 } 348 // virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 349 // return settings_core::key_string; 350 // } 328 if (path.empty() || path == _T("/")) { 329 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Loose leaves not supported: TODO"))); 330 return; 331 } 332 // @todo: this will NOT work for "nodes in paths" 333 BOOST_FOREACH(keys_key_type key, keys_) { 334 if (path == key.first.first) { 335 if (has_key_int(key.second.first, key.second.second)) 336 list.push_back(key.first.second); 337 } else { 338 //get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: TODO FOO fix sub sections")) + key.first.first); 339 } 340 } 341 342 BOOST_FOREACH(section_key_type key, sections_) { 343 if (key.first == path) { 344 section_cache_type::const_iterator it = section_cache_.find(key.second); 345 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("=============>>>>>>>>>>>")) + key.first + _T(" >>>> ") + key.second); 346 if (it == section_cache_.end()) { 347 std::set<std::wstring> list = internal_read_keys_from_section(path); 348 section_cache_[path] = list; 349 it = section_cache_.find(path); 350 } 351 list.insert(list.end(), (*it).second.begin(), (*it).second.end()); 352 } 353 } 354 355 } 351 356 private: 352 bool has_key(std::wstring section, std::wstring key) { 353 TCHAR* buffer = new TCHAR[1024]; 354 GetPrivateProfileString(section.c_str(), key.c_str(), UNLIKELY_STRING, buffer, 1023, get_file_name().c_str()); 355 std::wstring ret = buffer; 356 delete [] buffer; 357 return ret != UNLIKELY_STRING; 358 } 357 359 358 void int_read_section(std::wstring section, string_list &list, unsigned int bufferLength = BUFF_LEN) { 360 359 //get_core()->get_logger()->debug(__FILE__, __LINE__, _T("Reading (OLD) section: ") + section); … … 384 383 } 385 384 385 string_list int_read_section_from_inifile(std::wstring section, unsigned int bufferLength = BUFF_LEN) { 386 TCHAR* buffer = new TCHAR[bufferLength+1]; 387 if (buffer == NULL) 388 throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 389 unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 390 if (count == bufferLength-2) { 391 delete [] buffer; 392 return int_read_section_from_inifile(section, bufferLength*10); 393 } 394 unsigned int last = 0; 395 string_list list; 396 for (unsigned int i=0;i<count;i++) { 397 if (buffer[i] == '\0') { 398 std::wstring s = &buffer[last]; 399 std::size_t p = s.find('='); 400 if (p == std::wstring::npos) 401 list.push_back(s); 402 else 403 list.push_back(s.substr(0,p)); 404 last = i+1; 405 } 406 } 407 delete [] buffer; 408 return list; 409 } 410 411 386 412 inline std::wstring get_file_name() { 387 413 if (filename_.empty()) { -
service/logger.hpp
r1ecd26f r7e54a5f 205 205 } 206 206 } 207 cache_.clear(); 207 208 } 208 209 const char* buf = buffer.c_str(); -
service/settings_client.hpp
r1ecd26f r7e54a5f 39 39 try { 40 40 debug_msg(_T("Migrating from: ") + src); 41 core_->load_all_plugins(NSCAPI::dontStart); 41 42 settings_manager::get_core()->migrate_from(src); 42 43 return 1; … … 51 52 try { 52 53 debug_msg(_T("Migrating to: ") + target); 54 core_->load_all_plugins(NSCAPI::dontStart); 53 55 settings_manager::get_core()->migrate_to(target); 54 56 return 1;
Note: See TracChangeset
for help on using the changeset viewer.








