Changeset a90ef7c in nscp


Ignore:
Timestamp:
08/09/12 07:26:16 (9 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.2
Children:
a74645c
Parents:
77c0100
Message:
  • Initial merge of 0.4.1 into 0.4.2
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r77c0100 ra90ef7c  
    44 * Fix dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-08-08 MickeM 
     8 * Initial merge of 0.4.1 into 0.4.2 
    69 
    7102012-08-07 MickeM 
  • helpers/settings_manager/settings_handler_impl.cpp

    rf14ab71 ra90ef7c  
    2929      if (!desc.advanced) { 
    3030        if (!get()->has_key(path, key)) { 
    31           get_logger()->debug(__FILE__, __LINE__, _T("Adding: ") + path + _T(".") + key); 
     31          get_logger()->debug(_T("settings"), __FILE__, __LINE__, _T("Adding: ") + path + _T(".") + key); 
    3232          if (desc.type == key_string) 
    3333            get()->set_string(path, key, desc.defValue); 
     
    3838              get()->set_int(path, key, strEx::stoi(desc.defValue)); 
    3939            } catch (const std::exception &e) { 
    40               get_logger()->error(__FILE__, __LINE__, _T("invalid default value for: ") + path + _T(".") + key); 
     40              get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("invalid default value for: ") + path + _T(".") + key); 
    4141            } 
    4242          } else 
    43             get_logger()->error(__FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
     43            get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    4444        } else { 
    4545          std::wstring val = get()->get_string(path, key); 
    46           get_logger()->debug(__FILE__, __LINE__, _T("Setting old (already exists): ") + path + _T(".") + key + _T(" = ") + val); 
     46          get_logger()->debug(_T("settings"), __FILE__, __LINE__, _T("Setting old (already exists): ") + path + _T(".") + key + _T(" = ") + val); 
    4747          if (desc.type == key_string) 
    4848            get()->set_string(path, key, val); 
     
    5252            get()->set_int(path, key, strEx::stoi(val)); 
    5353          else 
    54             get_logger()->error(__FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
     54            get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    5555        } 
    5656      } else { 
    57         get_logger()->debug(__FILE__, __LINE__, _T("Skipping (advanced): ") + path + _T(".") + key); 
     57        get_logger()->debug(_T("settings"), __FILE__, __LINE__, _T("Skipping (advanced): ") + path + _T(".") + key); 
    5858      } 
    5959    } 
    6060  } 
    61   get_logger()->info(__FILE__, __LINE__, _T("DONE Updating settings with default values!")); 
     61  get_logger()->info(_T("settings"), __FILE__, __LINE__, _T("DONE Updating settings with default values!")); 
    6262} 
    6363 
  • helpers/settings_manager/settings_handler_impl.hpp

    r77c0100 ra90ef7c  
    1 <<<<<<< HEAD:include/settings/settings_handler_impl.hpp 
    21/************************************************************************** 
    32*   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         * 
     
    8685    } 
    8786 
    88  
    89     instance_ptr get() { 
    90       boost::unique_lock<boost::timed_mutex> mutex(instance_mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    91       if (!mutex.owns_lock()) 
    92         throw settings_exception(_T("Failed to get mutex, cant get settings instance")); 
    93       if (!instance_) 
    94         throw settings_exception(_T("Failed initialize settings instance")); 
    95       return instance_ptr(instance_); 
    96     } 
    97     instance_ptr get_no_wait() { 
    98       boost::unique_lock<boost::timed_mutex> mutex(instance_mutex_, boost::try_to_lock); 
    99       if (!mutex.owns_lock()) 
    100         throw settings_exception(_T("Failed to get mutex, cant get settings instance")); 
    101       if (!instance_) 
    102         throw settings_exception(_T("Failed initialize settings instance")); 
    103       return instance_; 
    104 //      return instance_ptr(instance_, mutexHandler_, 0); 
    105 //      int i = boost::try_lock(&mutexHandler_); 
    106 //      if (i != -1) 
    107 //        throw settings_exception(_T("Failed to get mutex, cant get settings instance")); 
    108 //      if (!instance_) 
    109 //        throw settings_exception(_T("Failed initialize settings instance")); 
    110 //      return instance_; 
    111     } 
    112     ////////////////////////////////////////////////////////////////////////// 
    113     /// Overwrite the (current) settings store with default values. 
    114     /// 
    115     /// @author mickem 
    116     void update_defaults() { 
    117       BOOST_FOREACH(std::wstring path, get_reg_sections()) { 
    118         get()->add_path(path); 
    119         BOOST_FOREACH(std::wstring key, get_reg_keys(path)) { 
    120           settings_core::key_description desc = get_registred_key(path, key); 
    121           if (!desc.advanced) { 
    122             if (!get()->has_key(path, key)) { 
    123               if (desc.type == key_string) 
    124                 get()->set_string(path, key, desc.defValue); 
    125               else if (desc.type == key_bool) 
    126                 get()->set_bool(path, key, settings::settings_interface::string_to_bool(desc.defValue)); 
    127               else if (desc.type == key_integer) { 
    128                 try { 
    129                   get()->set_int(path, key, strEx::stoi(desc.defValue)); 
    130                 } catch (const std::exception &e) { 
    131                   get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("invalid default value for: ") + path + _T(".") + key); 
    132                 } 
    133               } else 
    134                 get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    135             } else { 
    136               std::wstring val = get()->get_string(path, key); 
    137               if (desc.type == key_string) 
    138                 get()->set_string(path, key, val); 
    139               else if (desc.type == key_bool) 
    140                 get()->set_bool(path, key, settings::settings_interface::string_to_bool(val)); 
    141               else if (desc.type == key_integer) 
    142                 get()->set_int(path, key, strEx::stoi(val)); 
    143               else 
    144                 get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    145             } 
    146           } else { 
    147             get_logger()->debug(_T("settings"), __FILE__, __LINE__, _T("Skipping (advanced): ") + path + _T(".") + key); 
    148           } 
    149         } 
    150       } 
    151       get_logger()->info(_T("settings"),__FILE__, __LINE__, _T("DONE Updating settings with default values!")); 
    152     } 
     87    settings::error_list validate(); 
     88 
     89 
     90 
     91    instance_ptr get(); 
     92    instance_ptr get_no_wait(); 
     93    void update_defaults(); 
    15394    void migrate(instance_ptr from, instance_ptr to) { 
    15495      if (!from || !to) 
     
    300241 
    301242  private: 
    302     void destroy_all_instances() { 
    303       boost::unique_lock<boost::timed_mutex> mutex(instance_mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    304       if (!mutex.owns_lock()) 
    305         throw settings_exception(_T("destroy_all_instances Failed to get mutext, cant get access settings")); 
    306       instance_.reset(); 
    307     } 
     243    void destroy_all_instances(); 
    308244 
    309245    virtual std::wstring to_string() { 
     
    319255 
    320256 
    321 ======= 
    322 /************************************************************************** 
    323 *   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         * 
    324 *                                                                         * 
    325 *   This code is part of NSClient++ - http://trac.nakednuns.org/nscp      * 
    326 *                                                                         * 
    327 *   This program is free software; you can redistribute it and/or modify  * 
    328 *   it under the terms of the GNU General Public License as published by  * 
    329 *   the Free Software Foundation; either version 2 of the License, or     * 
    330 *   (at your option) any later version.                                   * 
    331 *                                                                         * 
    332 *   This program is distributed in the hope that it will be useful,       * 
    333 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
    334 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
    335 *   GNU General Public License for more details.                          * 
    336 *                                                                         * 
    337 *   You should have received a copy of the GNU General Public License     * 
    338 *   along with this program; if not, write to the                         * 
    339 *   Free Software Foundation, Inc.,                                       * 
    340 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
    341 ***************************************************************************/ 
    342 #pragma once 
    343  
    344 #include <types.hpp> 
    345 #include <Singleton.h> 
    346 #include <string> 
    347 #include <map> 
    348 #include <set> 
    349 #include <boost/thread/thread.hpp> 
    350 #include <boost/thread/locks.hpp> 
    351 #include <boost/filesystem/path.hpp> 
    352 #include <boost/regex.hpp> 
    353 #include <strEx.h> 
    354 #include <settings/settings_core.hpp> 
    355 #include <nsclient/logger.hpp> 
    356  
    357 namespace settings { 
    358   class settings_handler_impl : public settings_core { 
    359   private: 
    360     typedef std::map<std::wstring, std::wstring> path_map; 
    361     typedef std::map<std::wstring,settings_core::path_description> reg_paths_type; 
    362     typedef std::map<key_path_type,key_path_type> mapped_paths_type; 
    363     typedef settings_interface::string_list string_list; 
    364      
    365     instance_raw_ptr instance_; 
    366     boost::timed_mutex instance_mutex_; 
    367     boost::filesystem::wpath base_path_; 
    368     reg_paths_type registred_paths_; 
    369  
    370   public: 
    371     settings_handler_impl() {} 
    372     ~settings_handler_impl() { 
    373       destroy_all_instances(); 
    374     } 
    375  
    376     ////////////////////////////////////////////////////////////////////////// 
    377     /// Set the basepath for the settings subsystem. 
    378     /// In other words set where the settings files reside 
    379     /// 
    380     /// @param path the path to the settings files 
    381     /// 
    382     /// @author mickem 
    383     void set_base(boost::filesystem::wpath path) { 
    384       base_path_ = path; 
    385     } 
    386  
    387     ////////////////////////////////////////////////////////////////////////// 
    388     /// Get the logging interface (will receive log messages) 
    389     /// 
    390     /// @return the logger to use 
    391     /// 
    392     /// @author mickem 
    393     nsclient::logging::logger_interface* get_logger() { 
    394       return nsclient::logging::logger::get_logger(); 
    395     } 
    396  
    397     ////////////////////////////////////////////////////////////////////////// 
    398     /// Get the basepath for the settings subsystem. 
    399     /// In other words get where the settings files reside 
    400     /// 
    401     /// @return the path to the settings files 
    402     /// 
    403     /// @author mickem 
    404     boost::filesystem::wpath get_base() { 
    405       return base_path_; 
    406     } 
    407  
    408     settings::error_list validate(); 
    409  
    410  
    411  
    412     instance_ptr get(); 
    413     instance_ptr get_no_wait(); 
    414     void update_defaults(); 
    415     void migrate(instance_ptr from, instance_ptr to) { 
    416       if (!from || !to) 
    417         throw new settings_exception(_T("Source or target is null")); 
    418       from->save_to(to); 
    419       set_primary(to->get_context()); 
    420     } 
    421     void migrate_to(instance_ptr to) { 
    422       migrate(get(), to); 
    423     } 
    424     void migrate_from(instance_ptr from) { 
    425       migrate(from, get()); 
    426     } 
    427     void migrate_to(std::wstring to) { 
    428       instance_ptr i = create_instance(to); 
    429       migrate_to(i); 
    430     } 
    431     void migrate_from(std::wstring from) { 
    432       instance_ptr i = create_instance(from); 
    433       migrate_from(i); 
    434     } 
    435     void migrate(std::wstring from, std::wstring to) { 
    436       instance_ptr ifrom = create_instance(from); 
    437       instance_ptr ito = create_instance(to); 
    438       migrate(ifrom, ito); 
    439     } 
    440  
    441     ////////////////////////////////////////////////////////////////////////// 
    442     /// Register a path with the settings module. 
    443     /// A registered key or path will be nicely documented in some of the settings files when converted. 
    444     /// 
    445     /// @param path The path to register 
    446     /// @param type The type of value 
    447     /// @param title The title to use 
    448     /// @param description the description to use 
    449     /// @param defValue the default value 
    450     /// @param advanced advanced options will only be included if they are changed 
    451     /// 
    452     /// @author mickem 
    453     void register_path(std::wstring path, std::wstring title, std::wstring description, bool advanced = false) { 
    454       reg_paths_type::iterator it = registred_paths_.find(path); 
    455       if (it == registred_paths_.end()) { 
    456         registred_paths_[path] = path_description(title, description, advanced); 
    457       } else { 
    458         (*it).second.update(title, description, advanced); 
    459       } 
    460     } 
    461  
    462     ////////////////////////////////////////////////////////////////////////// 
    463     /// Register a key with the settings module. 
    464     /// A registered key or path will be nicely documented in some of the settings files when converted. 
    465     /// 
    466     /// @param path The path to register 
    467     /// @param key The key to register 
    468     /// @param title The title to use 
    469     /// @param description the description to use 
    470     /// @param defValue the default value 
    471     /// @param advanced advanced options will only be included if they are changed 
    472     /// 
    473     /// @author mickem 
    474     void register_key(std::wstring path, std::wstring key, settings_core::key_type type, std::wstring title, std::wstring description, std::wstring defValue, bool advanced = false) { 
    475       reg_paths_type::iterator it = registred_paths_.find(path); 
    476       if (it == registred_paths_.end()) { 
    477         registred_paths_[path] = path_description(); 
    478         registred_paths_[path].keys[key] = key_description(title, description, type, defValue, advanced); 
    479       } else { 
    480         (*it).second.keys[key] = key_description(title, description, type, defValue, advanced); 
    481       } 
    482     } 
    483     ////////////////////////////////////////////////////////////////////////// 
    484     /// Get info about a registered key. 
    485     /// Used when writing settings files. 
    486     /// 
    487     /// @param path The path of the key 
    488     /// @param key The key of the key 
    489     /// @return the key description 
    490     /// 
    491     /// @author mickem 
    492     settings_core::key_description get_registred_key(std::wstring path, std::wstring key) { 
    493       reg_paths_type::const_iterator cit = registred_paths_.find(path); 
    494       if (cit != registred_paths_.end()) { 
    495         path_description::keys_type::const_iterator cit2 = (*cit).second.keys.find(key); 
    496         if (cit2 != (*cit).second.keys.end()) { 
    497           settings_core::key_description ret = (*cit2).second; 
    498           return ret; 
    499         } 
    500       } 
    501       throw KeyNotFoundException(path, key); 
    502     } 
    503     settings_core::path_description get_registred_path(std::wstring path) { 
    504       reg_paths_type::const_iterator cit = registred_paths_.find(path); 
    505       if (cit != registred_paths_.end()) { 
    506         return (*cit).second; 
    507       } 
    508       throw KeyNotFoundException(path); 
    509     } 
    510  
    511  
    512  
    513     ////////////////////////////////////////////////////////////////////////// 
    514     /// Get all registered sections 
    515     /// 
    516     /// @return a list of section paths 
    517     /// 
    518     /// @author mickem 
    519     string_list get_reg_sections() { 
    520       string_list ret; 
    521       for (reg_paths_type::const_iterator cit = registred_paths_.begin(); cit != registred_paths_.end(); ++cit) { 
    522         ret.push_back((*cit).first); 
    523       } 
    524       return ret; 
    525     } 
    526     ////////////////////////////////////////////////////////////////////////// 
    527     /// Get all keys for a registered section. 
    528     /// 
    529     /// @param path the path to find keys under 
    530     /// @return a list of key names 
    531     /// 
    532     /// @author mickem 
    533     virtual string_list get_reg_keys(std::wstring path) { 
    534       string_list ret; 
    535       reg_paths_type::const_iterator cit = registred_paths_.find(path); 
    536       if (cit != registred_paths_.end()) { 
    537         for (path_description::keys_type::const_iterator cit2 = (*cit).second.keys.begin();cit2 != (*cit).second.keys.end(); ++cit2) { 
    538           ret.push_back((*cit2).first); 
    539         } 
    540         return ret; 
    541       } 
    542       throw KeyNotFoundException(path, _T("")); 
    543     } 
    544  
    545  
    546     void set_instance(std::wstring key) { 
    547       boost::unique_lock<boost::timed_mutex> mutex(instance_mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    548       if (!mutex.owns_lock()) 
    549         throw settings_exception(_T("set_instance Failed to get mutext, cant get access settings")); 
    550       instance_ = create_instance(key); 
    551       if (!instance_) 
    552         throw settings_exception(_T("set_instance Failed to create instance for: ") + key); 
    553       instance_->set_core(this); 
    554     } 
    555  
    556  
    557   private: 
    558     void destroy_all_instances(); 
    559  
    560     virtual std::wstring to_string() { 
    561       if (instance_) 
    562         return instance_->to_string(); 
    563       return _T("<NULL>"); 
    564     } 
    565  
    566   }; 
    567   typedef settings_interface::string_list string_list; 
    568  
    569 } 
    570  
    571  
    572 >>>>>>> 0.4.1:helpers/settings_manager/settings_handler_impl.hpp 
  • include/nscapi/nscapi_plugin_impl.cpp

    r77c0100 ra90ef7c  
    1717} 
    1818 
     19 
     20void nscapi::impl::simple_plugin::register_command(std::wstring command, std::wstring description, std::list<std::wstring> aliases) { 
     21  BOOST_FOREACH(const std::wstring alias, aliases) { 
     22    register_command(alias, description); 
     23  } 
     24  register_command(command, description); 
     25} 
    1926void nscapi::impl::simple_plugin::register_command(std::wstring command, std::wstring description) { 
    2027  get_core()->registerCommand(get_id(), command, description); 
  • include/nscapi/nscapi_plugin_impl.hpp

    r77c0100 ra90ef7c  
    2424      } 
    2525      void register_command(std::wstring command, std::wstring description); 
     26      void register_command(std::wstring command, std::wstring description, std::list<std::wstring> aliases); 
    2627      void settings_register_key(std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced); 
    2728      void settings_register_path(std::wstring path, std::wstring title, std::wstring description, bool advanced); 
  • include/settings/impl/settings_http.hpp

    r77c0100 ra90ef7c  
    1 <<<<<<< HEAD:include/settings/settings_http.hpp 
    21#pragma once 
    32 
     
    1312 
    1413#include <settings/settings_core.hpp> 
    15 #include <settings/settings_core_impl.hpp> 
     14#include <settings/settings_interface_impl.hpp> 
    1615#include <error.hpp> 
    1716 
     
    148147    virtual void save() { 
    149148    } 
     149 
     150    settings::error_list validate() { 
     151      settings::error_list ret; 
     152      return ret; 
     153    } 
     154 
    150155  private: 
    151156 
     
    166171  }; 
    167172} 
    168 ======= 
    169 #pragma once 
    170  
    171 #include <string> 
    172 #include <map> 
    173  
    174 #include <boost/filesystem/path.hpp> 
    175 #include <boost/filesystem/operations.hpp> 
    176  
    177 #include <http/client.hpp> 
    178 #include <net/net.hpp> 
    179 #include <file_helpers.hpp> 
    180  
    181 #include <settings/settings_core.hpp> 
    182 #include <settings/settings_interface_impl.hpp> 
    183 #include <error.hpp> 
    184  
    185 namespace settings { 
    186   class settings_http : public settings::SettingsInterfaceImpl { 
    187   private: 
    188     std::wstring url_; 
    189  
    190     inline nsclient::logging::logger_interface* get_logger() const { 
    191       return nsclient::logging::logger::get_logger(); 
    192     } 
    193  
    194   public: 
    195     settings_http(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) { 
    196       net::url url = net::parse(utf8::cvt<std::string>(context), 80); 
    197       std::wstring path = core->expand_path(DEFAULT_CACHE_PATH); 
    198       if (!file_helpers::checks::is_directory(path)) { 
    199         if (file_helpers::checks::exists(path))  
    200           throw new settings_exception(_T("Cache path not found: ") + path); 
    201         //boost::wpath wp = path; 
    202         boost::filesystem::create_directories(path); 
    203         if (!file_helpers::checks::is_directory(path)) 
    204           throw new settings_exception(_T("Cache path not found: ") + path); 
    205       } 
    206       boost::filesystem::wpath wp(path); 
    207       wp /= _T("cached.ini"); 
    208       std::ofstream os(utf8::cvt<std::string>(wp.string()).c_str()); 
    209       std::string error; 
    210       if (!http::client::download(url.protocol, url.host, url.path, os, error)) { 
    211         os.close(); 
    212         get_logger()->error(__FILE__, __LINE__, _T("Failed to download settings: ") + utf8::to_unicode(error)); 
    213       } 
    214       os.close(); 
    215       if (!file_helpers::checks::exists(wp.string())) { 
    216         throw new settings_exception(_T("Failed to find cached settings: ") + wp.string()); 
    217       } 
    218       add_child(_T("ini://") + wp.string()); 
    219     } 
    220     ////////////////////////////////////////////////////////////////////////// 
    221     /// Create a new settings interface of "this kind" 
    222     /// 
    223     /// @param context the context to use 
    224     /// @return the newly created settings interface 
    225     /// 
    226     /// @author mickem 
    227     virtual SettingsInterfaceImpl* create_new_context(std::wstring context) { 
    228       return new settings_http(get_core(), context); 
    229     } 
    230     ////////////////////////////////////////////////////////////////////////// 
    231     /// Get a string value if it does not exist exception will be thrown 
    232     /// 
    233     /// @param path the path to look up 
    234     /// @param key the key to lookup 
    235     /// @return the string value 
    236     /// 
    237     /// @author mickem 
    238     virtual std::wstring get_real_string(settings_core::key_path_type key) { 
    239       throw KeyNotFoundException(key); 
    240     } 
    241     ////////////////////////////////////////////////////////////////////////// 
    242     /// Get an integer value if it does not exist exception will be thrown 
    243     /// 
    244     /// @param path the path to look up 
    245     /// @param key the key to lookup 
    246     /// @return the int value 
    247     /// 
    248     /// @author mickem 
    249     virtual int get_real_int(settings_core::key_path_type key) { 
    250       throw KeyNotFoundException(key); 
    251     } 
    252     ////////////////////////////////////////////////////////////////////////// 
    253     /// Get a boolean value if it does not exist exception will be thrown 
    254     /// 
    255     /// @param path the path to look up 
    256     /// @param key the key to lookup 
    257     /// @return the boolean value 
    258     /// 
    259     /// @author mickem 
    260     virtual bool get_real_bool(settings_core::key_path_type key) { 
    261       throw KeyNotFoundException(key); 
    262     } 
    263     ////////////////////////////////////////////////////////////////////////// 
    264     /// Check if a key exists 
    265     /// 
    266     /// @param path the path to look up 
    267     /// @param key the key to lookup 
    268     /// @return true/false if the key exists. 
    269     /// 
    270     /// @author mickem 
    271     virtual bool has_real_key(settings_core::key_path_type key) { 
    272       return false; 
    273     } 
    274     ////////////////////////////////////////////////////////////////////////// 
    275     /// Write a value to the resulting context. 
    276     /// 
    277     /// @param key The key to write to 
    278     /// @param value The value to write 
    279     /// 
    280     /// @author mickem 
    281     virtual void set_real_value(settings_core::key_path_type key, conainer value) { 
    282       get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Cant save over HTTP: ") + key.first + _T(".") + key.second)); 
    283     } 
    284  
    285     virtual void set_real_path(std::wstring path) { 
    286       get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Cant save over HTTP: ") + path)); 
    287     } 
    288  
    289     ////////////////////////////////////////////////////////////////////////// 
    290     /// Get all (sub) sections (given a path). 
    291     /// If the path is empty all root sections will be returned 
    292     /// 
    293     /// @param path The path to get sections from (if empty root sections will be returned) 
    294     /// @param list The list to append nodes to 
    295     /// @return a list of sections 
    296     /// 
    297     /// @author mickem 
    298     virtual void get_real_sections(std::wstring path, string_list &list) { 
    299     } 
    300     ////////////////////////////////////////////////////////////////////////// 
    301     /// Get all keys given a path/section. 
    302     /// If the path is empty all root sections will be returned 
    303     /// 
    304     /// @param path The path to get sections from (if empty root sections will be returned) 
    305     /// @param list The list to append nodes to 
    306     /// @return a list of sections 
    307     /// 
    308     /// @author mickem 
    309     virtual void get_real_keys(std::wstring path, string_list &list) { 
    310     } 
    311     ////////////////////////////////////////////////////////////////////////// 
    312     /// Save the settings store 
    313     /// 
    314     /// @author mickem 
    315     virtual void save() { 
    316     } 
    317  
    318     settings::error_list validate() { 
    319       settings::error_list ret; 
    320       return ret; 
    321     } 
    322  
    323   private: 
    324  
    325     std::wstring get_file_name() { 
    326       if (url_.empty()) { 
    327         url_ = get_file_from_context(); 
    328         get_logger()->debug(__FILE__, __LINE__, _T("Reading INI settings from: ") + url_); 
    329       } 
    330       return url_; 
    331     } 
    332     bool file_exists() { 
    333       return boost::filesystem::is_regular(get_file_name()); 
    334     } 
    335     virtual std::wstring get_info() { 
    336       return _T("HTTP settings: (") + context_ + _T(", ") + get_file_name() + _T(")"); 
    337     } 
    338  
    339   }; 
    340 } 
    341 >>>>>>> 0.4.1:include/settings/impl/settings_http.hpp 
  • include/settings/impl/settings_old.hpp

    r77c0100 ra90ef7c  
    1 <<<<<<< HEAD:include/settings/settings_old.hpp 
    21#pragma once 
    32 
     
    98#include <simpleini/SimpleIni.h> 
    109#include <nsclient/logger.hpp> 
    11 //#include <settings/macros.h> 
    1210 
    1311#include <strEx.h> 
    1412 
    15  
    16 //#define MAIN_MODULES_SECTION_OLD _T("modules") 
    17 //#define MAIN_SECTION_TITLE _T("Settings") 
    18 //#define MAIN_STRING_LENGTH _T("string_length") 
    1913 
    2014namespace settings { 
     
    208202      return new OLDSettings(get_core(), context); 
    209203    } 
     204    settings::error_list validate() { 
     205      settings::error_list ret; 
     206      return ret; 
     207    } 
     208 
    210209    ////////////////////////////////////////////////////////////////////////// 
    211210    /// Get a string value if it does not exist exception will be thrown 
     
    499498 
    500499  }; 
    501 ======= 
    502 #pragma once 
    503  
    504 #include <iostream> 
    505 #include <fstream> 
    506 #include <string> 
    507 #include <map> 
    508 #include <settings/settings_core.hpp> 
    509 #include <simpleini/SimpleIni.h> 
    510 #include <nsclient/logger.hpp> 
    511  
    512 #include <strEx.h> 
    513  
    514  
    515 namespace settings { 
    516   class OLDSettings : public settings::SettingsInterfaceImpl { 
    517     std::wstring filename_; 
    518     typedef std::pair<std::wstring,std::wstring> section_key_type; 
    519  
    520     inline nsclient::logging::logger_interface* get_logger() const { 
    521       return nsclient::logging::logger::get_logger(); 
    522     } 
    523  
    524     class settings_map : boost::noncopyable { 
    525     public: 
    526  
    527       typedef std::multimap<std::wstring,std::wstring> path_map; 
    528       typedef std::multimap<settings_core::key_path_type,settings_core::key_path_type> key_map; 
    529       typedef std::pair<std::wstring,std::wstring> section_key_type; 
    530       typedef std::pair<settings_core::key_path_type,settings_core::key_path_type> keys_key_type; 
    531  
    532       path_map sections_; 
    533       key_map keys_; 
    534  
    535       settings_map() {} 
    536  
    537       inline nsclient::logging::logger_interface* get_logger() const { 
    538         return nsclient::logging::logger::get_logger(); 
    539       } 
    540  
    541       void read_map_file(std::wstring file) { 
    542         get_logger()->debug(__FILE__, __LINE__, _T("Reading MAP file: ") + file); 
    543  
    544         std::ifstream in(strEx::wstring_to_string(file).c_str()); 
    545         if(!in) { 
    546           get_logger()->error(__FILE__, __LINE__, _T("Failed to read MAP file: ") + file); 
    547           return; 
    548         } 
    549         in.exceptions(std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit); 
    550  
    551         try{ 
    552           std::string tmp; 
    553           while(true) { 
    554             std::getline(in,tmp); 
    555             parse_line(utf8::cvt<std::wstring>(tmp)); 
    556           } 
    557         } 
    558         catch(std::ifstream::failure e){ 
    559           if(!in.eof()) 
    560             std::cerr << e.what() <<'\n'; 
    561         } 
    562       } 
    563       void read_map_data(std::wstring data) { 
    564         strEx::splitList list = strEx::splitEx(data, _T("\n")); 
    565         BOOST_FOREACH(std::wstring l, list) { 
    566           parse_line(l); 
    567         } 
    568       } 
    569       void parse_line(std::wstring line) { 
    570         strEx::replace(line, _T("\n"), _T("")); 
    571         strEx::replace(line, _T("\r"), _T("")); 
    572         std::wstring::size_type pos = line.find('#'); 
    573         if (pos != -1) 
    574           line = line.substr(0, pos); 
    575         pos = line.find_first_not_of(_T(" \t\n\r")); 
    576         if (pos == -1) 
    577           return; 
    578         line = line.substr(pos); 
    579         pos = line.find('='); 
    580         if (pos == -1) { 
    581           get_logger()->error(__FILE__, __LINE__, _T("Invalid syntax: ") + line); 
    582           return; 
    583         } 
    584         std::pair<std::wstring,std::wstring> old_key = split_key(line.substr(0, pos)); 
    585         std::pair<std::wstring,std::wstring> new_key = split_key(line.substr(pos+1)); 
    586         if (old_key.second == _T("*") || old_key.second.empty()) { 
    587           add(line.substr(pos+1), old_key.first); 
    588         } else { 
    589           add(new_key.first, new_key.second, old_key.first, old_key.second); 
    590         } 
    591  
    592       } 
    593       std::pair<std::wstring,std::wstring> split_key(std::wstring key) { 
    594         std::pair<std::wstring,std::wstring> ret; 
    595         std::wstring::size_type pos = key.find_last_of('/'); 
    596         if (pos == -1) 
    597           return std::pair<std::wstring,std::wstring>(key, _T("")); 
    598         return std::pair<std::wstring,std::wstring>(key.substr(0, pos), key.substr(pos+1)); 
    599       } 
    600  
    601       void add(std::wstring path_new, std::wstring path_old) { 
    602         sections_.insert(path_map::value_type(path_new, path_old)); 
    603       } 
    604       void add(std::wstring path_new, std::wstring key_new, std::wstring path_old, std::wstring key_old) { 
    605         settings_core::key_path_type new_key(path_new, key_new); 
    606         settings_core::key_path_type old_key(path_old, key_old); 
    607         keys_.insert(key_map::value_type(new_key, old_key)); 
    608       } 
    609       std::wstring path(std::wstring path_new) { 
    610         path_map::iterator it = sections_.find(path_new); 
    611         if (it == sections_.end()) 
    612           return path_new; 
    613         return (*it).second; 
    614       } 
    615       settings_core::key_path_type key(settings_core::key_path_type new_key) { 
    616         key_map::iterator it1 = keys_.find(new_key); 
    617         if (it1 != keys_.end()) { 
    618           //get_logger()->debug(__FILE__, __LINE__, new_key.first + _T(".") + new_key.second + _T(" found in alias list")); 
    619           return (*it1).second; 
    620         } 
    621         path_map::iterator it2 = sections_.find(new_key.first); 
    622         if (it2 != sections_.end()) { 
    623           return settings_core::key_path_type((*it2).second, new_key.second); 
    624         } 
    625         return new_key; 
    626       } 
    627       std::wstring status() { 
    628         return _T("Sections: ") + strEx::itos(sections_.size()) + _T(", ") 
    629           + _T("Keys: ") + strEx::itos(keys_.size()) 
    630           ; 
    631       } 
    632  
    633       void get_sections(std::wstring path, string_list &list) { 
    634         std::wstring::size_type path_length = path.length(); 
    635         BOOST_FOREACH(section_key_type key, sections_) { 
    636           if (path_length == 0 || path == _T("/")) { 
    637             std::wstring::size_type pos = key.first.find(L'/', 1); 
    638             list.push_back(pos == std::wstring::npos?key.first:key.first.substr(0,pos)); 
    639           } else if (key.first.length() > path_length && path == key.first.substr(0, path_length)) { 
    640             std::wstring::size_type pos = key.first.find(L'/', path_length+1); 
    641             list.push_back(pos == std::wstring::npos?key.first.substr(path_length+1):key.first.substr(path_length+1,pos-path_length-1)); 
    642           } 
    643         } 
    644         BOOST_FOREACH(keys_key_type key, keys_) { 
    645           if (path.empty() || path == _T("/")) { 
    646             std::wstring::size_type pos = key.first.first.find(L'/', 1); 
    647             if (pos != std::wstring::npos) 
    648               key.first.first = key.first.first.substr(0,pos); 
    649             list.push_back(key.first.first); 
    650           } else if (key.first.first.length() > path_length && path == key.first.first.substr(0, path_length)) { 
    651             std::wstring::size_type pos = key.first.first.find(L'/', path_length+1); 
    652             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)); 
    653           } 
    654         } 
    655         list.unique(); 
    656       } 
    657  
    658  
    659     }; 
    660  
    661       settings_map map; 
    662       typedef std::map<std::wstring,std::set<std::wstring> > section_cache_type; 
    663       section_cache_type section_cache_; 
    664  
    665  
    666     public: 
    667  
    668  
    669     OLDSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) { 
    670       get_logger()->debug(__FILE__, __LINE__, _T("Loading OLD: ") + context + _T(" for ") + context); 
    671       std::wstring mapfile = core->get_boot_string(_T("settings"), _T("old_settings_map_file"), _T("old-settings.map")); 
    672       std::wstring file = core->find_file(_T("${exe-path}/") + mapfile, mapfile); 
    673       bool readmap = false; 
    674       if (file_helpers::checks::exists(file)) { 
    675         readmap = true; 
    676         map.read_map_file(file); 
    677       } 
    678       std::wstring mapdata = core->get_boot_string(_T("settings"), _T("old_settings_map_data"), _T("")); 
    679       if (!mapdata.empty()) { 
    680         readmap = true; 
    681         map.read_map_data(mapdata); 
    682       } 
    683       if (!readmap) { 
    684         get_logger()->error(__FILE__, __LINE__,_T("Failed to read map file: ") + mapfile); 
    685       } 
    686  
    687       string_list list = get_keys(_T("/includes")); 
    688       BOOST_FOREACH(std::wstring key, list) { 
    689         if (key.length() > 5 && key.substr(key.length()-4,4) == _T(".ini") && key.find_first_of(_T(":/\\")) == std::wstring::npos) 
    690           add_child(_T("old://${exe-path}/") + key); 
    691         else 
    692           add_child(key); 
    693       } 
    694     } 
    695     ////////////////////////////////////////////////////////////////////////// 
    696     /// Create a new settings interface of "this kind" 
    697     /// 
    698     /// @param context the context to use 
    699     /// @return the newly created settings interface 
    700     /// 
    701     /// @author mickem 
    702     virtual SettingsInterfaceImpl* create_new_context(std::wstring context) { 
    703       return new OLDSettings(get_core(), context); 
    704     } 
    705     settings::error_list validate() { 
    706       settings::error_list ret; 
    707       return ret; 
    708     } 
    709  
    710     ////////////////////////////////////////////////////////////////////////// 
    711     /// Get a string value if it does not exist exception will be thrown 
    712     /// 
    713     /// @param path the path to look up 
    714     /// @param key the key to lookup 
    715     /// @return the string value 
    716     /// 
    717     /// @author mickem 
    718     virtual std::wstring get_real_string(settings_core::key_path_type in_key) { 
    719       settings_core::key_path_type key = map.key(in_key); 
    720       if (has_key_int(key.first, key.second)) 
    721         return internal_get_value(key.first, key.second); 
    722       if (has_key_int(in_key.first, in_key.second)) 
    723         return internal_get_value(in_key.first, in_key.second); 
    724       throw KeyNotFoundException(key); 
    725     } 
    726 #define UNLIKELY_STRING _T("$$$EMPTY_KEY$$$") 
    727  
    728     std::wstring internal_get_value(std::wstring path, std::wstring key, int bufferSize = 1024) { 
    729       if (!has_key_int(path, key)) 
    730         throw KeyNotFoundException(key); 
    731  
    732       TCHAR* buffer = new TCHAR[bufferSize+2]; 
    733       if (buffer == NULL) 
    734         throw settings_exception(_T("Out of memory error!")); 
    735       int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), _T(""), buffer, bufferSize, get_file_name().c_str()); 
    736       if (retVal == bufferSize-1) { 
    737         delete [] buffer; 
    738         return internal_get_value(path, key, bufferSize*10); 
    739       } 
    740       std::wstring ret = buffer; 
    741       delete [] buffer; 
    742       return ret; 
    743     } 
    744  
    745     ////////////////////////////////////////////////////////////////////////// 
    746     /// Get an integer value if it does not exist exception will be thrown 
    747     /// 
    748     /// @param path the path to look up 
    749     /// @param key the key to lookup 
    750     /// @return the int value 
    751     /// 
    752     /// @author mickem 
    753     virtual int get_real_int(settings_core::key_path_type key) { 
    754       std::wstring str = get_real_string(key); 
    755       return strEx::stoi(str); 
    756     } 
    757     ////////////////////////////////////////////////////////////////////////// 
    758     /// Get a boolean value if it does not exist exception will be thrown 
    759     /// 
    760     /// @param path the path to look up 
    761     /// @param key the key to lookup 
    762     /// @return the boolean value 
    763     /// 
    764     /// @author mickem 
    765     virtual bool get_real_bool(settings_core::key_path_type key) { 
    766       std::wstring str = get_real_string(key); 
    767       return SettingsInterfaceImpl::string_to_bool(str); 
    768     } 
    769     ////////////////////////////////////////////////////////////////////////// 
    770     /// Check if a key exists 
    771     /// 
    772     /// @param path the path to look up 
    773     /// @param key the key to lookup 
    774     /// @return true/false if the key exists. 
    775     /// 
    776     /// @author mickem 
    777     virtual bool has_real_key(settings_core::key_path_type key) { 
    778       settings_core::key_path_type old = map.key(key); 
    779       return has_key_int(old.first, old.second); 
    780     } 
    781  
    782  
    783     std::set<std::wstring> internal_read_keys_from_section(std::wstring section, int bufferLength = 1024) { 
    784       TCHAR* buffer = new TCHAR[bufferLength+1]; 
    785       if (buffer == NULL) 
    786         throw settings_exception(_T("internal_read_keys_from_section:: Failed to allocate memory for buffer!")); 
    787       unsigned int count = ::GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 
    788       if (count == bufferLength-2) { 
    789         delete [] buffer; 
    790         return internal_read_keys_from_section(section, bufferLength*10); 
    791       } 
    792       std::set<std::wstring> ret; 
    793       unsigned int last = 0; 
    794       for (unsigned int i=0;i<count;i++) { 
    795         if (buffer[i] == '\0') { 
    796           std::wstring s = &buffer[last]; 
    797           std::size_t p = s.find('='); 
    798           ret.insert((p == std::wstring::npos)?s:s.substr(0,p)); 
    799           last = i+1; 
    800         } 
    801       } 
    802       delete [] buffer; 
    803       return ret; 
    804     } 
    805  
    806     bool has_key_int(std::wstring path, std::wstring key) { 
    807       section_cache_type::const_iterator it = section_cache_.find(path); 
    808       if (it == section_cache_.end()) { 
    809         std::set<std::wstring> list = internal_read_keys_from_section(path); 
    810         section_cache_[path] = list; 
    811         it = section_cache_.find(path); 
    812       } 
    813       return (*it).second.find(key) != (*it).second.end(); 
    814     } 
    815  
    816     ////////////////////////////////////////////////////////////////////////// 
    817     /// Write a value to the resulting context. 
    818     /// 
    819     /// @param key The key to write to 
    820     /// @param value The value to write 
    821     /// 
    822     /// @author mickem 
    823     virtual void set_real_value(settings_core::key_path_type key, conainer value) { 
    824       try { 
    825         key = map.key(key); 
    826         WritePrivateProfileString(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), get_file_name().c_str()); 
    827       } catch (settings_exception e) { 
    828         get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 
    829       } catch (...) { 
    830         get_logger()->error(__FILE__, __LINE__, std::wstring(_T("Unknown filure when writing key: ") + key.first + _T(".") + key.second)); 
    831       } 
    832     } 
    833  
    834     virtual void set_real_path(std::wstring path) { 
    835       // NOT Supported (and not needed) so silently ignored! 
    836     } 
    837  
    838     ////////////////////////////////////////////////////////////////////////// 
    839     /// Get all (sub) sections (given a path). 
    840     /// If the path is empty all root sections will be returned 
    841     /// 
    842     /// @param path The path to get sections from (if empty root sections will be returned) 
    843     /// @param list The list to append nodes to 
    844     /// @return a list of sections 
    845     /// 
    846     /// @author mickem 
    847     virtual void get_real_sections(std::wstring path, string_list &list) { 
    848       unsigned int path_length = path.length(); 
    849       map.get_sections(path, list); 
    850       list.unique(); 
    851     } 
    852  
    853     /** 
    854     * Retrieves a list of section 
    855     * @access public 
    856     * @returns INIFile::sectionList 
    857     * @qualifier 
    858     * @param unsigned int bufferLength 
    859     */ 
    860     string_list int_read_sections(unsigned int bufferLength = BUFF_LEN) { 
    861       string_list ret; 
    862       TCHAR* buffer = new TCHAR[bufferLength+1]; 
    863       if (buffer == NULL) 
    864         throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 
    865       unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, get_file_name().c_str()); 
    866       if (count == bufferLength-2) { 
    867         delete [] buffer; 
    868         return int_read_sections(bufferLength*10); 
    869       } 
    870       unsigned int last = 0; 
    871       for (unsigned int i=0;i<count;i++) { 
    872         if (buffer[i] == '\0') { 
    873           std::wstring s = &buffer[last]; 
    874           ret.push_back(s); 
    875           last = i+1; 
    876         } 
    877       } 
    878       delete [] buffer; 
    879       return ret; 
    880     } 
    881     ////////////////////////////////////////////////////////////////////////// 
    882     /// Get all keys given a path/section. 
    883     /// If the path is empty all root sections will be returned 
    884     /// 
    885     /// @param path The path to get sections from (if empty root sections will be returned) 
    886     /// @param list The list to append nodes to 
    887     /// @return a list of sections 
    888     /// 
    889     /// @author mickem 
    890     virtual void get_real_keys(std::wstring path, string_list &list) { 
    891       std::wstring keyy = path + _T(" - ") + get_file_name(); 
    892       if (path.empty() || path == _T("/")) { 
    893         get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Loose leaves not supported: TODO"))); 
    894         return; 
    895       } 
    896       // @todo: this will NOT work for "nodes in paths" 
    897       std::set<std::wstring> ignore_list; 
    898       BOOST_FOREACH(settings_map::keys_key_type key, map.keys_) { 
    899         if (key.first.first == path) { 
    900           if (has_key_int(key.second.first, key.second.second)) { 
    901             list.push_back(key.first.second); 
    902             ignore_list.insert(key.second.first + _T("/") + key.second.second); 
    903           } 
    904         } 
    905       } 
    906  
    907       BOOST_FOREACH(settings_map::section_key_type key, map.sections_) { 
    908         if (key.first == path) { 
    909           section_cache_type::const_iterator it = section_cache_.find(key.second); 
    910           if (it == section_cache_.end()) { 
    911             std::set<std::wstring> list2 = internal_read_keys_from_section(key.second); 
    912             section_cache_[path] = list2; 
    913             it = section_cache_.find(path); 
    914           } 
    915           BOOST_FOREACH(std::wstring k, (*it).second) { 
    916             std::set<std::wstring>::const_iterator cit = ignore_list.find(key.second + _T("/") + k); 
    917             if (cit == ignore_list.end()) 
    918               list.push_back(k); 
    919           } 
    920           //list.insert(list.end(), (*it).second.begin(), (*it).second.end()); 
    921         } 
    922       } 
    923     } 
    924   private: 
    925  
    926     void int_read_section(std::wstring section, string_list &list, unsigned int bufferLength = BUFF_LEN) { 
    927       TCHAR* buffer = new TCHAR[bufferLength+1]; 
    928       if (buffer == NULL) 
    929         throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 
    930       unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 
    931       if (count == bufferLength-2) { 
    932         delete [] buffer; 
    933         int_read_section(section, list, bufferLength*10); 
    934         return; 
    935       } 
    936       unsigned int last = 0; 
    937       for (unsigned int i=0;i<count;i++) { 
    938         if (buffer[i] == '\0') { 
    939           std::wstring s = &buffer[last]; 
    940           std::size_t p = s.find('='); 
    941           if (p == std::wstring::npos) 
    942             list.push_back(s); 
    943           else 
    944             list.push_back(s.substr(0,p)); 
    945           last = i+1; 
    946         } 
    947       } 
    948       delete [] buffer; 
    949     } 
    950  
    951     string_list int_read_section_from_inifile(std::wstring section, unsigned int bufferLength = BUFF_LEN) { 
    952       TCHAR* buffer = new TCHAR[bufferLength+1]; 
    953       if (buffer == NULL) 
    954         throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 
    955       unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 
    956       if (count == bufferLength-2) { 
    957         delete [] buffer; 
    958         return int_read_section_from_inifile(section, bufferLength*10); 
    959       } 
    960       unsigned int last = 0; 
    961       string_list list; 
    962       for (unsigned int i=0;i<count;i++) { 
    963         if (buffer[i] == '\0') { 
    964           std::wstring s = &buffer[last]; 
    965           std::size_t p = s.find('='); 
    966           if (p == std::wstring::npos) 
    967             list.push_back(s); 
    968           else 
    969             list.push_back(s.substr(0,p)); 
    970           last = i+1; 
    971         } 
    972       } 
    973       delete [] buffer; 
    974       return list; 
    975     } 
    976  
    977  
    978     inline std::wstring get_file_name() { 
    979       if (filename_.empty()) { 
    980         filename_ = get_file_from_context(); 
    981         //filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 
    982         get_logger()->debug(__FILE__, __LINE__, _T("Reading old settings from: ") + filename_); 
    983       } 
    984       return filename_; 
    985     } 
    986     bool file_exists() { 
    987       return boost::filesystem::is_regular_file(get_file_name()); 
    988     } 
    989     virtual std::wstring get_info() { 
    990       return _T("INI settings: (") + context_ + _T(", ") + get_file_name() + _T(")"); 
    991     } 
    992 public: 
    993     static bool context_exists(settings::settings_core *core, std::wstring key) { 
    994       net::wurl url = net::parse(key); 
    995       std::wstring file = url.host + url.path; 
    996       std::wstring tmp = core->expand_path(file); 
    997       return file_helpers::checks::exists(tmp); 
    998     } 
    999  
    1000   }; 
    1001 >>>>>>> 0.4.1:include/settings/impl/settings_old.hpp 
    1002500} 
  • include/settings/settings_interface_impl.hpp

    rf898ded ra90ef7c  
    142142        } 
    143143      } catch (const std::exception &e) { 
    144         get_logger()->error(__FILE__, __LINE__, _T("Failed to load child: ") + utf8::to_unicode(e.what())); 
     144        get_logger()->error(_T("settings"), __FILE__, __LINE__, _T("Failed to load child: ") + utf8::to_unicode(e.what())); 
    145145      } 
    146146    } 
  • libs/protobuf/plugin.proto

    r77c0100 ra90ef7c  
    270270    optional string description = 2; 
    271271     
    272     optional string minVersion = 5; 
    273     optional string maxVersion = 6; 
     272    optional string min_version = 5; 
     273    optional string max_version = 6; 
    274274     
    275275    optional bool advanced = 8; 
  • modules/SamplePluginSimple/SamplePluginSimple.cpp

    rf14ab71 ra90ef7c  
    7676// For instance NSC_WRAPPERS_ROUTING_DEF will add routing support and call routing handlers in your class. 
    7777NSC_WRAP_DLL() 
    78 NSC_WRAPPERS_MAIN_DEF(SamplePluginSimple) 
     78NSC_WRAPPERS_MAIN_DEF(SamplePluginSimple, _T("sample")) 
    7979NSC_WRAPPERS_IGNORE_MSG_DEF() 
    8080NSC_WRAPPERS_HANDLE_CMD_DEF() 
  • service/CMakeLists.txt

    r393a00f ra90ef7c  
    55PROJECT(service) 
    66INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS}) 
    7 INCLUDE_DIRECTORIES(${JSON_SPIRIT_INCLUDE_DIR}) 
     7IF(JSON_SPIRIT_FOUND) 
     8  INCLUDE_DIRECTORIES(${JSON_SPIRIT_INCLUDE_DIR}) 
     9  ADD_DEFINITIONS(-DJSON_SPIRIT) 
     10  SET(JSON_LIB json_spirit_static) 
     11ELSE(JSON_SPIRIT_FOUND) 
     12  SET(JSON_LIB) 
     13ENDIF(JSON_SPIRIT_FOUND) 
     14 
     15 
    816LINK_DIRECTORIES(${BOOST_LIB_DIRS}) 
    917 
     
    9199  ${NSCP_DEF_PLUGIN_LIB} 
    92100  ${EXTRA_LIBS} 
    93   json_spirit_static 
     101  ${JSON_LIB} 
    94102  settings_manager 
    95103) 
  • service/cli_parser.hpp

    r77c0100 ra90ef7c  
    122122    if (nsclient::logging::logger::get_logger()->should_log(NSCAPI::log_level::debug)) { 
    123123      BOOST_FOREACH(const std::wstring & a, unknown_options) { 
    124         get_logger()->info(__FILE__, __LINE__, _T("Extra options: ") + a); 
     124        get_logger()->info(_T("client"), __FILE__, __LINE__, _T("Extra options: ") + a); 
    125125      } 
    126126    } 
     
    597597          std::wcout << _T("Command not found (by module): ") << args.command << std::endl; 
    598598          resp.push_back(_T("Command not found: ") + args.command); 
    599           mainClient.simple_exec(args.module, _T("help"), args.arguments, resp); 
     599          core_->simple_exec(_T("help"), args.arguments, resp); 
    600600        } else if (args.mode == client_arguments::combined) { 
    601601          if (ret == NSCAPI::returnOK) { 
  • service/settings_client.hpp

    r77c0100 ra90ef7c  
    22#include <settings/settings_core.hpp> 
    33#include <nsclient/logger.hpp> 
     4#ifdef JSON_SPIRIT 
    45#include <json_spirit.h> 
     6#endif 
    57 
    68class NSClientT; 
     
    204206            } 
    205207          } 
     208#ifdef JSON_SPIRIT 
    206209        } else if (target == _T("json") || target == _T("json-compact")) { 
    207210          json_spirit::wObject json_root; 
     
    244247          else 
    245248            write(json_root, std::wcout, json_spirit::pretty_print); 
     249#endif 
    246250        } else { 
    247251          //settings_manager::get_core()->update_defaults(); 
  • version.txt

    r0382c02 ra90ef7c  
    11version=0.4.2 
    2 build=0 
    3 date=2012-06-20 
     2build=1 
     3date=2012-08-08 
Note: See TracChangeset for help on using the changeset viewer.