Changeset c760fc9 in nscp


Ignore:
Timestamp:
01/11/11 07:07:30 (2 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
1f24a1c
Parents:
58ee653
Message:
  • Fixed so old settings mappings are read/stored in a text file
  • Changed so all polugin use the "simple-plugin interface
  • Created a settings helper for the "core" (and started to use it)
Files:
3 added
29 edited
2 moved

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r87cf3c4 rc760fc9  
    5757# TODO 
    5858ENDIF(WIN32 AND MSVC) 
    59  
    60  
    61 #SET(BREAKPAD_EXCEPTION_HANDLER_LIBRARIES "${INC_GOOGLE_BREAKPAD}/src" CACHE PATH "Path to Google breakpad include folder") 
    6259 
    6360# ### ### ### ### 
     
    143140ENDIF(WIN32) 
    144141 
    145 FIND_PACKAGE(GoogleBreakpad COMPONENTS common exception_handler crash_report_sender) 
     142FIND_PACKAGE(GoogleBreakpad COMPONENTS common exception_handler crash_report_sender crash_generation_client) 
    146143if(BREAKPAD_FOUND) 
    147144  MESSAGE(STATUS "Found google breakpad") 
     
    241238  ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.cpp 
    242239  ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.cpp 
    243   ${NSCP_INCLUDEDIR}/nscapi/settings.cpp 
     240  ${NSCP_INCLUDEDIR}/settings/client/settings_client.cpp 
    244241) 
    245242 
     
    253250  ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.hpp  
    254251  ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.hpp 
    255   ${NSCP_INCLUDEDIR}/nscapi/settings.hpp 
     252  ${NSCP_INCLUDEDIR}/settings/client/settings_client.hpp 
     253  ${NSCP_INCLUDEDIR}/nscapi/settings_proxy.hpp 
    256254  ${NSCP_INCLUDEDIR}/nscapi/macros.hpp 
    257255) 
  • include/breakpad/exception_handler_win32.cpp

    r1ecd26f rc760fc9  
    172172static bool MinidumpCallback(const wchar_t *minidump_folder, const wchar_t *minidump_id, void *context, EXCEPTION_POINTERS *exinfo, MDRawAssertionInfo *assertion, bool succeeded) { 
    173173  ExceptionManager* this_ptr = reinterpret_cast<ExceptionManager*>(context); 
     174  report_info(_T("Detected crash...")); 
    174175 
    175176  wchar_t minidump_path[MAX_PATH]; 
  • include/config.h.in

    r57a86f3 rc760fc9  
    7373#define DATE_FORMAT _T("%#c") 
    7474 
     75#define CRASH_SUBMIT_URL _T("http://crash.nsclient.org/submit") 
     76#define CRASH_ARCHIVE_FOLDER _T("${shared-path}/crash-dumps") 
    7577 
    7678#ifdef WIN32 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r1ecd26f rc760fc9  
    3232#include <unicode_char.hpp> 
    3333#include <strEx.h> 
     34#include <nscapi/settings_proxy.hpp> 
    3435 
    3536#include "../libs/protobuf/plugin.proto.h" 
     
    176177        return nscapi::plugin_singleton->get_core(); 
    177178      } 
     179      inline boost::shared_ptr<nscapi::settings_proxy> get_settings_proxy() { 
     180        return boost::shared_ptr<nscapi::settings_proxy>(new nscapi::settings_proxy(nscapi::plugin_singleton->get_core())); 
     181      } 
    178182    }; 
    179183 
  • include/nscapi/plugin.hpp

    r497b779 rc760fc9  
    22 
    33#include <nscapi/macros.hpp> 
    4 #include <nscapi/settings.hpp> 
     4#include <nscapi/settings_proxy.hpp> 
    55#include <nscapi/nscapi_helper.hpp> 
    66#include <nscapi/nscapi_plugin_wrapper.hpp> 
  • include/settings/client/settings_client.cpp

    r497b779 rc760fc9  
    11#pragma once 
    22 
    3 #include <nscapi/settings.hpp> 
     3#include <settings/client/settings_client.hpp> 
    44 
    55namespace nscapi { 
  • include/settings/client/settings_client.hpp

    r1ecd26f rc760fc9  
    1212  namespace settings_helper { 
    1313 
     14    class settings_impl_interface { 
     15    public: 
     16      typedef std::list<std::wstring> string_list; 
     17 
     18      ////////////////////////////////////////////////////////////////////////// 
     19      /// Register a path with the settings module. 
     20      /// A registered key or path will be nicely documented in some of the settings files when converted. 
     21      /// 
     22      /// @param path The path to register 
     23      /// @param title The title to use 
     24      /// @param description the description to use 
     25      /// @param advanced advanced options will only be included if they are changed 
     26      /// 
     27      /// @author mickem 
     28      virtual void register_path(std::wstring path, std::wstring title, std::wstring description, bool advanced) = 0; 
     29 
     30      ////////////////////////////////////////////////////////////////////////// 
     31      /// Register a key with the settings module. 
     32      /// A registered key or path will be nicely documented in some of the settings files when converted. 
     33      /// 
     34      /// @param path The path to register 
     35      /// @param key The key to register 
     36      /// @param type The type of value 
     37      /// @param title The title to use 
     38      /// @param description the description to use 
     39      /// @param defValue the default value 
     40      /// @param advanced advanced options will only be included if they are changed 
     41      /// 
     42      /// @author mickem 
     43      virtual void register_key(std::wstring path, std::wstring key, int type, std::wstring title, std::wstring description, std::wstring defValue, bool advanced) = 0; 
     44 
     45      ////////////////////////////////////////////////////////////////////////// 
     46      /// Get a string value if it does not exist the default value will be returned 
     47      ///  
     48      /// @param path the path to look up 
     49      /// @param key the key to lookup 
     50      /// @param def the default value to use when no value is found 
     51      /// @return the string value 
     52      /// 
     53      /// @author mickem 
     54      virtual std::wstring get_string(std::wstring path, std::wstring key, std::wstring def) = 0; 
     55      ////////////////////////////////////////////////////////////////////////// 
     56      /// Set or update a string value 
     57      /// 
     58      /// @param path the path to look up 
     59      /// @param key the key to lookup 
     60      /// @param value the value to set 
     61      /// 
     62      /// @author mickem 
     63      virtual void set_string(std::wstring path, std::wstring key, std::wstring value) = 0; 
     64 
     65      ////////////////////////////////////////////////////////////////////////// 
     66      /// Get an integer value if it does not exist the default value will be returned 
     67      ///  
     68      /// @param path the path to look up 
     69      /// @param key the key to lookup 
     70      /// @param def the default value to use when no value is found 
     71      /// @return the string value 
     72      /// 
     73      /// @author mickem 
     74      virtual int get_int(std::wstring path, std::wstring key, int def) = 0; 
     75      ////////////////////////////////////////////////////////////////////////// 
     76      /// Set or update an integer value 
     77      /// 
     78      /// @param path the path to look up 
     79      /// @param key the key to lookup 
     80      /// @param value the value to set 
     81      /// 
     82      /// @author mickem 
     83      virtual void set_int(std::wstring path, std::wstring key, int value) = 0; 
     84 
     85      ////////////////////////////////////////////////////////////////////////// 
     86      /// Get a boolean value if it does not exist the default value will be returned 
     87      ///  
     88      /// @param path the path to look up 
     89      /// @param key the key to lookup 
     90      /// @param def the default value to use when no value is found 
     91      /// @return the string value 
     92      /// 
     93      /// @author mickem 
     94      virtual bool get_bool(std::wstring path, std::wstring key, bool def) = 0; 
     95      ////////////////////////////////////////////////////////////////////////// 
     96      /// Set or update a boolean value 
     97      /// 
     98      /// @param path the path to look up 
     99      /// @param key the key to lookup 
     100      /// @param value the value to set 
     101      /// 
     102      /// @author mickem 
     103      virtual void set_bool(std::wstring path, std::wstring key, bool value) = 0; 
     104 
     105      // Meta Functions 
     106      ////////////////////////////////////////////////////////////////////////// 
     107      /// Get all (sub) sections (given a path). 
     108      /// If the path is empty all root sections will be returned 
     109      /// 
     110      /// @param path The path to get sections from (if empty root sections will be returned) 
     111      /// @return a list of sections 
     112      /// 
     113      /// @author mickem 
     114      virtual string_list get_sections(std::wstring path) = 0; 
     115      ////////////////////////////////////////////////////////////////////////// 
     116      /// Get all keys for a path. 
     117      /// 
     118      /// @param path The path to get keys under 
     119      /// @return a list of keys 
     120      /// 
     121      /// @author mickem 
     122      virtual string_list get_keys(std::wstring path) = 0; 
     123 
     124 
     125      virtual std::wstring expand_path(std::wstring key) = 0; 
     126 
     127      ////////////////////////////////////////////////////////////////////////// 
     128      /// Log an ERROR message. 
     129      /// 
     130      /// @param file the file where the event happened 
     131      /// @param line the line where the event happened 
     132      /// @param message the message to log 
     133      /// 
     134      /// @author mickem 
     135      virtual void err(std::string file, int line, std::wstring message) = 0; 
     136      ////////////////////////////////////////////////////////////////////////// 
     137      /// Log an WARNING message. 
     138      /// 
     139      /// @param file the file where the event happened 
     140      /// @param line the line where the event happened 
     141      /// @param message the message to log 
     142      /// 
     143      /// @author mickem 
     144      virtual void warn(std::string file, int line, std::wstring message) = 0; 
     145      ////////////////////////////////////////////////////////////////////////// 
     146      /// Log an INFO message. 
     147      /// 
     148      /// @param file the file where the event happened 
     149      /// @param line the line where the event happened 
     150      /// @param message the message to log 
     151      /// 
     152      /// @author mickem 
     153      virtual void info(std::string file, int line, std::wstring message) = 0; 
     154      ////////////////////////////////////////////////////////////////////////// 
     155      /// Log an DEBUG message. 
     156      /// 
     157      /// @param file the file where the event happened 
     158      /// @param line the line where the event happened 
     159      /// @param message the message to log 
     160      /// 
     161      /// @author mickem 
     162      virtual void debug(std::string file, int line, std::wstring message) = 0; 
     163    }; 
     164 
     165    typedef boost::shared_ptr<settings_impl_interface> settings_impl_interface_ptr; 
    14166 
    15167    class key_interface { 
     
    17169      virtual NSCAPI::settings_type get_type() const = 0; 
    18170      virtual std::wstring get_default_as_string() const = 0; 
    19       virtual void notify(nscapi::core_wrapper* core_, std::wstring path, std::wstring key) const = 0; 
    20       virtual void notify(nscapi::core_wrapper* core_, std::wstring parent, std::wstring path, std::wstring key) const = 0; 
     171      virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const = 0; 
     172      virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const = 0; 
    21173    }; 
    22174    template<class T> 
     
    47199        return NSCAPI::key_string; 
    48200      } 
    49       virtual void notify(nscapi::core_wrapper* core_, std::wstring path, std::wstring key) const { 
    50         T value = boost::lexical_cast<T>(core_->getSettingsString(path, key, typed_key<T>::default_value_as_text_)); 
     201      virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 
     202        T value = boost::lexical_cast<T>(core_->get_string(path, key, typed_key<T>::default_value_as_text_)); 
    51203        update_target(&value); 
    52204      } 
    53       virtual void notify(nscapi::core_wrapper* core_, std::wstring parent, std::wstring path, std::wstring key) const { 
    54         std::wstring default_value = core_->getSettingsString(parent, key, typed_key<T>::default_value_as_text_); 
    55         T value = boost::lexical_cast<T>(core_->getSettingsString(path, key, default_value)); 
     205      virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 
     206        std::wstring default_value = core_->get_string(parent, key, typed_key<T>::default_value_as_text_); 
     207        T value = boost::lexical_cast<T>(core_->get_string(path, key, default_value)); 
    56208        update_target(&value); 
    57209      } 
     
    64216        return NSCAPI::key_string; 
    65217      } 
    66       virtual void notify(nscapi::core_wrapper* core_, std::wstring path, std::wstring key) const { 
    67         std::wstring val = core_->getSettingsString(path, key, typed_key<T>::default_value_as_text_); 
     218      virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 
     219        std::wstring val = core_->get_string(path, key, typed_key<T>::default_value_as_text_); 
    68220        T value = boost::lexical_cast<T>(core_->expand_path(val)); 
    69221        update_target(&value); 
    70222      } 
    71       virtual void notify(nscapi::core_wrapper* core_, std::wstring parent, std::wstring path, std::wstring key) const { 
    72         std::wstring def_val = core_->getSettingsString(parent, key, typed_key<T>::default_value_as_text_); 
    73         std::wstring val = core_->getSettingsString(path, key, def_val); 
     223      virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 
     224        std::wstring def_val = core_->get_string(parent, key, typed_key<T>::default_value_as_text_); 
     225        std::wstring val = core_->get_string(path, key, def_val); 
    74226        T value = boost::lexical_cast<T>(core_->expand_path(val)); 
    75227        update_target(&value); 
     
    88240        return NSCAPI::key_integer; 
    89241      } 
    90       virtual void notify(nscapi::core_wrapper* core_, std::wstring path, std::wstring key) const { 
    91         T value = static_cast<T>(core_->getSettingsInt(path, key, default_value_as_int_)); 
     242      virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 
     243        T value = static_cast<T>(core_->get_int(path, key, default_value_as_int_)); 
    92244        update_target(&value); 
    93245      } 
    94       virtual void notify(nscapi::core_wrapper* core_, std::wstring parent, std::wstring path, std::wstring key) const { 
    95         T default_value = static_cast<T>(core_->getSettingsInt(parent, key, default_value_as_int_)); 
    96         T value = static_cast<T>(core_->getSettingsInt(path, key, default_value)); 
     246      virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 
     247        T default_value = static_cast<T>(core_->get_int(parent, key, default_value_as_int_)); 
     248        T value = static_cast<T>(core_->get_int(path, key, default_value)); 
    97249        update_target(&value); 
    98250      } 
     
    107259        return NSCAPI::key_bool; 
    108260      } 
    109       virtual void notify(nscapi::core_wrapper* core_, std::wstring path, std::wstring key) const { 
    110         T value = static_cast<T>(core_->getSettingsBool(path, key, typed_int_value<T>::default_value_as_int_==1)); 
     261      virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 
     262        T value = static_cast<T>(core_->get_bool(path, key, typed_int_value<T>::default_value_as_int_==1)); 
    111263        update_target(&value); 
    112264      } 
    113       virtual void notify(nscapi::core_wrapper* core_, std::wstring parent, std::wstring path, std::wstring key) const { 
    114         T default_value = static_cast<T>(core_->getSettingsBool(parent, key, typed_int_value<T>::default_value_as_int_==1)); 
    115         T value = static_cast<T>(core_->getSettingsBool(path, key, default_value)); 
     265      virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 
     266        T default_value = static_cast<T>(core_->get_bool(parent, key, typed_int_value<T>::default_value_as_int_==1)); 
     267        T value = static_cast<T>(core_->get_bool(path, key, default_value)); 
    116268        update_target(&value); 
    117269      } 
     
    176328    class path_interface { 
    177329    public: 
    178       virtual void notify(nscapi::core_wrapper* core_, std::wstring path) const = 0; 
     330      virtual void notify(settings_impl_interface_ptr core_, std::wstring path) const = 0; 
    179331    }; 
    180332 
     
    184336      typed_path_map(T* store_to)  : store_to_(store_to) {} 
    185337 
    186       virtual void notify(nscapi::core_wrapper* core_, std::wstring path) const { 
     338      virtual void notify(settings_impl_interface_ptr core_, std::wstring path) const { 
    187339        if (store_to_) { 
    188           std::list<std::wstring> list = core_->getSettingsSection(path); 
     340          std::list<std::wstring> list = core_->get_keys(path); 
    189341          T result; 
    190342          BOOST_FOREACH(std::wstring key, list) { 
    191             result[key] = core_->getSettingsString(path, key, _T("")); 
     343            result[key] = core_->get_string(path, key, _T("")); 
    192344          } 
    193345          *store_to_ = result; 
     
    203355      typed_path_list(std::list<std::wstring>* store_to)  : store_to_(store_to) {} 
    204356 
    205       virtual void notify(nscapi::core_wrapper* core_, std::wstring path) const { 
     357      virtual void notify(settings_impl_interface_ptr core_, std::wstring path) const { 
    206358        if (store_to_) { 
    207           *store_to_ = core_->getSettingsSection(path); 
     359          *store_to_ = core_->get_keys(path); 
    208360        } 
    209361      } 
     
    217369      typed_path_fun_value(boost::function<void (std::wstring, std::wstring)> callback) : callback_(callback) {} 
    218370 
    219       virtual void notify(nscapi::core_wrapper* core_, std::wstring path) const { 
     371      virtual void notify(settings_impl_interface_ptr core_, std::wstring path) const { 
    220372        if (callback_) { 
    221           std::list<std::wstring> list = core_->getSettingsSection(path); 
     373          std::list<std::wstring> list = core_->get_keys(path); 
    222374          BOOST_FOREACH(std::wstring key, list) { 
    223             std::wstring val = core_->getSettingsString(path, key, _T("")); 
     375            std::wstring val = core_->get_string(path, key, _T("")); 
    224376            callback_(key, val); 
    225377          } 
     
    235387      typed_path_fun(boost::function<void (std::wstring)> callback) : callback_(callback) {} 
    236388 
    237       virtual void notify(nscapi::core_wrapper* core_, std::wstring path) const { 
     389      virtual void notify(settings_impl_interface_ptr core_, std::wstring path) const { 
    238390        if (callback_) { 
    239           std::list<std::wstring> list = core_->getSettingsSection(path); 
     391          std::list<std::wstring> list = core_->get_keys(path); 
    240392          BOOST_FOREACH(std::wstring key, list) { 
    241393            callback_(key); 
     
    504656      key_list keys_; 
    505657      path_list paths_; 
    506       nscapi::core_wrapper* core_; 
     658      settings_impl_interface_ptr core_; 
    507659      std::wstring alias_; 
    508660    public: 
    509       settings_registry(nscapi::core_wrapper* core) : core_(core) {} 
     661      settings_registry(settings_impl_interface_ptr core) : core_(core) {} 
    510662      void add(boost::shared_ptr<key_info> info) { 
    511663        keys_.push_back(info); 
     
    521673        return settings_keys_easy_init(path, this); 
    522674      } 
     675      settings_keys_easy_init add_key_to_settings(std::wstring path) { 
     676        return settings_keys_easy_init(_T("/settings/") + path, this); 
     677      } 
    523678      settings_paths_easy_init add_path() { 
    524679        return settings_paths_easy_init(this); 
     680      } 
     681      settings_paths_easy_init add_path_to_settings() { 
     682        return settings_paths_easy_init(_T("/settings"), this); 
    525683      } 
    526684 
     
    556714            if (v->has_parent()) { 
    557715              desc += _T(" Parent element can be found under: ") + v->parent; 
    558               core_->settings_register_key(v->parent, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
     716              core_->register_key(v->parent, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
    559717            } 
    560             core_->settings_register_key(v->path, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
     718            core_->register_key(v->path, v->key_name, v->key->get_type(), v->description.title, desc, v->key->get_default_as_string(), v->description.advanced); 
    561719          } 
    562720        } 
    563721        BOOST_FOREACH(path_list::value_type v, paths_) { 
    564           core_->settings_register_path(v->path_name, v->description.title, v->description.description, v->description.advanced); 
     722          core_->register_path(v->path_name, v->description.title, v->description.description, v->description.advanced); 
    565723        } 
    566724      } 
     
    576734            } 
    577735          } catch (...) { 
    578             core_->Message(NSCAPI::error, __FILE__, __LINE__, _T("Failed to register: ") + v->key_name); 
     736            core_->err(__FILE__, __LINE__, _T("Failed to register: ") + v->key_name); 
    579737          } 
    580738        } 
     
    584742              v->path->notify(core_, v->path_name); 
    585743          } catch (...) { 
    586             core_->Message(NSCAPI::error, __FILE__, __LINE__, _T("Failed to register: ") + v->path_name); 
     744            core_->err(__FILE__, __LINE__, _T("Failed to register: ") + v->path_name); 
    587745          } 
    588746        } 
     
    590748      } 
    591749    }; 
    592 //    class simple_alias_settings_registry : public settings_registry { 
    593 //    private: 
    594 //      std::wstring alias_; 
    595 //  
    596 //    public: 
    597 //      simple_alias_settings_registry(nscapi::core_wrapper* core) : settings_registry(core) {} 
    598 //  
    599 //      settings_keys_easy_init add_key_to_path_w_alias(std::wstring path) { 
    600 //        return settings_keys_easy_init(path + _T("/") + alias_, this); 
    601 //      } 
    602 //      settings_keys_easy_init add_key_to_settings(std::wstring path = _T("")) { 
    603 //        return settings_keys_easy_init(get_settings_path(path), this); 
    604 //      } 
    605 //      settings_paths_easy_init add_path_w_alias(std::wstring path) { 
    606 //        return settings_paths_easy_init(path + _T("/") + alias_, this); 
    607 //      } 
    608 //      settings_paths_easy_init add_path_to_settings(std::wstring path = _T("")) { 
    609 //        if (path.empty()) 
    610 //          return settings_paths_easy_init(_T("/settings/") + alias_, this); 
    611 //        return settings_paths_easy_init(_T("/settings/") + alias_ + _T("/") + path, this); 
    612 //      } 
    613 //      static std::wstring get_settings_path(std::wstring alias, std::wstring path) { 
    614 //        if (path.empty()) 
    615 //          return _T("/settings/") + alias; 
    616 //        return _T("/settings/") + alias + _T("/") + path; 
    617 //      } 
    618 //      std::wstring get_settings_path(std::wstring path) { 
    619 //        if (path.empty()) 
    620 //          return _T("/settings/") + alias_; 
    621 //        return _T("/settings/") + alias_ + _T("/") + path; 
    622 //      } 
    623 //      void set_alias(std::wstring cur, std::wstring def) { 
    624 //        if (cur.empty()) 
    625 //          alias_ = def; 
    626 //        else 
    627 //          alias_ = cur; 
    628 //      } 
    629 //      void set_alias(std::wstring prefix, std::wstring cur, std::wstring def) { 
    630 //        if (!prefix.empty()) 
    631 //          prefix += _T("/"); 
    632 //        if (cur.empty()) 
    633 //          alias_ = prefix + def; 
    634 //        else 
    635 //          alias_ = prefix + cur; 
    636 //      } 
    637 //  
    638 //    }; 
    639750  } 
    640751} 
  • include/settings/settings_handler_impl.hpp

    r1ecd26f rc760fc9  
    5959      set_logger(NULL); 
    6060    } 
     61 
     62    virtual std::wstring expand_path(std::wstring key) = 0; 
    6163 
    6264    ////////////////////////////////////////////////////////////////////////// 
  • include/settings/settings_interface_impl.hpp

    r1ecd26f rc760fc9  
    125125      return core_; 
    126126    } 
     127    logger_interface* get_logger() const { 
     128      if (core_ == NULL) 
     129        throw settings_exception(_T("FATAL ERROR: Settings subsystem not initialized")); 
     130      return core_->get_logger(); 
     131    } 
    127132 
    128133    void add_child(std::wstring context) { 
  • include/settings/settings_old.hpp

    r1ecd26f rc760fc9  
    66#include <simpleini/SimpleIni.h> 
    77#include <settings/macros.h> 
    8  
    9 #define MAIN_MODULES_SECTION_OLD _T("modules") 
    10 #define MAIN_SECTION_TITLE _T("Settings") 
    11 #define MAIN_STRING_LENGTH _T("string_length") 
     8#include <iostream> 
     9#include <fstream> 
     10 
     11 
     12//#define MAIN_MODULES_SECTION_OLD _T("modules") 
     13//#define MAIN_SECTION_TITLE _T("Settings") 
     14//#define MAIN_STRING_LENGTH _T("string_length") 
    1215 
    1316namespace settings { 
     
    1619  public: 
    1720    OLDSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) { 
    18       add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD); 
    19       add_mapping(setting_keys::settings_def::PAYLOAD_LEN_PATH, setting_keys::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH); 
    20  
    21 #define SETTINGS_MAP_KEY_A(name, section, key) \ 
    22   add_mapping(setting_keys::name ## _PATH, setting_keys::name, section, key); 
    23 #define SETTINGS_MAP_SECTION_A(name, section) \ 
    24   add_mapping(setting_keys::name ## _PATH, section); 
    25  
    26  
    27 #define EXTSCRIPT_SECTION_TITLE _T("External Script") 
    28 #define EXTSCRIPT_SETTINGS_ALLOW_ARGUMENTS _T("allow_arguments") 
    29 #define EXTSCRIPT_SETTINGS_ALLOW_NASTY_META _T("allow_nasty_meta_chars") 
    30 #define EXTSCRIPT_SETTINGS_TIMEOUT _T("command_timeout") 
    31 #define EXTSCRIPT_SETTINGS_SCRIPTDIR _T("script_dir") 
    32 #define EXTSCRIPT_SCRIPT_SECTION_TITLE _T("External Scripts") 
    33 #define EXTSCRIPT_ALIAS_SECTION_TITLE _T("External Alias") 
    34  
    35       SETTINGS_MAP_KEY_A(external_scripts::TIMEOUT,   EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_TIMEOUT); 
    36       SETTINGS_MAP_KEY_A(external_scripts::SCRIPT_PATH, EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_SCRIPTDIR); 
    37       SETTINGS_MAP_KEY_A(external_scripts::ALLOW_ARGS,  EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_ALLOW_ARGUMENTS); 
    38       SETTINGS_MAP_KEY_A(external_scripts::ALLOW_NASTY, EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_ALLOW_NASTY_META); 
    39  
    40       SETTINGS_MAP_SECTION_A(external_scripts::SCRIPT_SECTION,EXTSCRIPT_SCRIPT_SECTION_TITLE); 
    41       SETTINGS_MAP_SECTION_A(external_scripts::ALIAS_SECTION,EXTSCRIPT_ALIAS_SECTION_TITLE); 
    42  
    43 #define LOG_SECTION_TITLE _T("log") 
    44 #define LOG_FILENAME _T("file")  
    45 #define LOG_DATEMASK _T("date_mask") 
    46  
    47       SETTINGS_MAP_KEY_A(log::FILENAME, LOG_SECTION_TITLE, LOG_FILENAME); 
    48       SETTINGS_MAP_KEY_A(log::DATEMASK, LOG_SECTION_TITLE, LOG_DATEMASK); 
    49       SETTINGS_MAP_KEY_A(log::DEBUG_LOG,  LOG_SECTION_TITLE, _T("debug")); 
    50  
    51 #define EVENTLOG_SECTION_TITLE _T("Eventlog") 
    52 #define EVENTLOG_DEBUG _T("debug") 
    53 #define EVENTLOG_SYNTAX _T("syntax") 
    54       SETTINGS_MAP_KEY_A(event_log::DEBUG_KEY,  EVENTLOG_SECTION_TITLE, EVENTLOG_DEBUG); 
    55       SETTINGS_MAP_KEY_A(event_log::SYNTAX,   EVENTLOG_SECTION_TITLE, EVENTLOG_SYNTAX); 
    56  
    57  
    58 #define LUA_SCRIPT_SECTION_TITLE _T("LUA Scripts") 
    59       SETTINGS_MAP_SECTION_A(lua::SECTION,  LUA_SCRIPT_SECTION_TITLE); 
    60  
    61 #define NRPE_SECTION_TITLE _T("NRPE") 
    62 #define NRPE_SETTINGS_READ_TIMEOUT _T("socket_timeout") 
    63 #define NRPE_SETTINGS_PORT _T("port") 
    64 #define NRPE_SETTINGS_BINDADDR _T("bind_to_address") 
    65 #define NRPE_SETTINGS_LISTENQUE _T("socket_back_log") 
    66 #define NRPE_SETTINGS_USE_SSL _T("use_ssl") 
    67 #define NRPE_SETTINGS_STRLEN _T("string_length") 
    68 #define NRPE_SETTINGS_PERFDATA _T("performance_data") 
    69 #define NRPE_HANDLER_SECTION_TITLE _T("NRPE Handlers") 
    70 #define NRPE_SETTINGS_SCRIPTDIR _T("script_dir") 
    71 #define NRPE_SETTINGS_TIMEOUT _T("command_timeout") 
    72 #define NRPE_SETTINGS_ALLOW_ARGUMENTS _T("allow_arguments") 
    73 #define NRPE_SETTINGS_ALLOW_NASTY_META _T("allow_nasty_meta_chars") 
    74  
    75       SETTINGS_MAP_KEY_A(nrpe::PORT,      NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT); 
    76       SETTINGS_MAP_KEY_A(nrpe::BINDADDR,    NRPE_SECTION_TITLE, NRPE_SETTINGS_BINDADDR); 
    77       SETTINGS_MAP_KEY_A(nrpe::LISTENQUE,   NRPE_SECTION_TITLE, NRPE_SETTINGS_LISTENQUE); 
    78       SETTINGS_MAP_KEY_A(nrpe::READ_TIMEOUT,  NRPE_SECTION_TITLE, NRPE_SETTINGS_READ_TIMEOUT); 
    79       SETTINGS_MAP_KEY_A(nrpe::KEYUSE_SSL,  NRPE_SECTION_TITLE, NRPE_SETTINGS_USE_SSL); 
    80       SETTINGS_MAP_KEY_A(nrpe::PAYLOAD_LENGTH,NRPE_SECTION_TITLE, NRPE_SETTINGS_STRLEN); 
    81       SETTINGS_MAP_KEY_A(nrpe::ALLOW_PERFDATA,NRPE_SECTION_TITLE, NRPE_SETTINGS_PERFDATA); 
    82       SETTINGS_MAP_KEY_A(nrpe::CMD_TIMEOUT, NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT); 
    83       SETTINGS_MAP_KEY_A(nrpe::ALLOW_ARGS,  NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS); 
    84       SETTINGS_MAP_KEY_A(nrpe::ALLOW_NASTY, NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META); 
    85  
    86 #define NSCA_AGENT_SECTION_TITLE _T("NSCA Agent") 
    87 #define NSCA_CMD_SECTION_TITLE _T("NSCA Commands") 
    88  
    89 #define NSCA_INTERVAL _T("interval") 
    90 #define NSCA_HOSTNAME _T("hostname") 
    91 #define NSCA_SERVER _T("nsca_host") 
    92 #define NSCA_PORT _T("nsca_port") 
    93 #define NSCA_ENCRYPTION _T("encryption_method") 
    94 #define NSCA_PASSWORD _T("password") 
    95 #define NSCA_DEBUG_THREADS _T("debug_threads") 
    96 #define NSCA_CACHE_HOST _T("cache_hostname") 
    97  
    98       SETTINGS_MAP_KEY_A(nsca::INTERVAL,    NSCA_AGENT_SECTION_TITLE, NSCA_INTERVAL); 
    99       SETTINGS_MAP_KEY_A(nsca::HOSTNAME,    NSCA_AGENT_SECTION_TITLE, NSCA_HOSTNAME); 
    100       SETTINGS_MAP_KEY_A(nsca::SERVER_HOST, NSCA_AGENT_SECTION_TITLE, NSCA_SERVER); 
    101       SETTINGS_MAP_KEY_A(nsca::SERVER_PORT, NSCA_AGENT_SECTION_TITLE, NSCA_PORT); 
    102       SETTINGS_MAP_KEY_A(nsca::ENCRYPTION,  NSCA_AGENT_SECTION_TITLE, NSCA_ENCRYPTION); 
    103       SETTINGS_MAP_KEY_A(nsca::PASSWORD,    NSCA_AGENT_SECTION_TITLE, NSCA_PASSWORD); 
    104       SETTINGS_MAP_KEY_A(nsca::THREADS,   NSCA_AGENT_SECTION_TITLE, NSCA_DEBUG_THREADS); 
    105       SETTINGS_MAP_KEY_A(nsca::CACHE_HOST,  NSCA_AGENT_SECTION_TITLE, NSCA_CACHE_HOST); 
    106  
    107       SETTINGS_MAP_SECTION_A(nsca::CMD_SECTION, NSCA_CMD_SECTION_TITLE); 
    108  
    109 #define NSCLIENT_SECTION_TITLE _T("NSClient") 
    110 #define NSCLIENT_SETTINGS_PORT _T("port") 
    111 #define NSCLIENT_SETTINGS_VERSION _T("version") 
    112 #define NSCLIENT_SETTINGS_BINDADDR _T("bind_to_address") 
    113 #define NSCLIENT_SETTINGS_LISTENQUE _T("socket_back_log") 
    114 #define NSCLIENT_SETTINGS_READ_TIMEOUT _T("socket_timeout") 
    115  
    116       SETTINGS_MAP_KEY_A(nsclient::PORT,      NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT); 
    117       SETTINGS_MAP_KEY_A(nsclient::VERSION,   NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_VERSION); 
    118       SETTINGS_MAP_KEY_A(nsclient::BINDADDR,    NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR); 
    119       SETTINGS_MAP_KEY_A(nsclient::LISTENQUE,   NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_LISTENQUE); 
    120       SETTINGS_MAP_KEY_A(nsclient::READ_TIMEOUT,  NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_READ_TIMEOUT); 
    121  
    122     } 
     21      std::wstring fname = core->find_file(_T("${exe-path}/old-settings.map"), _T("old-settings.map")); 
     22      read_map_file(fname); 
     23    } 
     24    void read_map_file(std::wstring file) { 
     25      get_logger()->debug(__FILE__, __LINE__, _T("Reading MAP file: ") + file); 
     26 
     27      std::ifstream in(strEx::wstring_to_string(file).c_str()); 
     28      if(!in) { 
     29        get_logger()->err(__FILE__, __LINE__, _T("Failed to read MAP file: ") + file); 
     30        return; 
     31      } 
     32      in.exceptions(std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit); 
     33 
     34      try{ 
     35        std::string tmp; 
     36        while(true) { 
     37          std::getline(in,tmp); 
     38          parse_line(to_wstring(tmp)); 
     39        } 
     40      } 
     41      catch(std::ifstream::failure e){ 
     42        if(!in.eof()) 
     43          cerr << e.what() <<'\n'; 
     44      } 
     45    } 
     46    void parse_line(std::wstring line) { 
     47      int pos = line.find('#'); 
     48      if (pos != -1) 
     49        line = line.substr(0, pos); 
     50      pos = line.find_first_not_of(_T(" \t")); 
     51      if (pos == -1) 
     52        return; 
     53      line = line.substr(pos); 
     54      pos = line.find('='); 
     55      if (pos == -1) { 
     56        get_logger()->err(__FILE__, __LINE__, _T("Invalid syntax: ") + line); 
     57        return; 
     58      } 
     59      std::pair<std::wstring,std::wstring> old_key = split_key(line.substr(0, pos)); 
     60      std::pair<std::wstring,std::wstring> new_key = split_key(line.substr(pos+1)); 
     61      if (old_key.second == _T("*") || old_key.second.empty()) { 
     62        add_mapping(new_key.first, old_key.first); 
     63        get_logger()->debug(__FILE__, __LINE__, _T("Adding: ") + old_key.first + _T(" >> ") + new_key.first); 
     64      } else { 
     65        add_mapping(new_key.first, new_key.second, old_key.first, old_key.second); 
     66        get_logger()->debug(__FILE__, __LINE__, _T("Adding: ") + old_key.first + _T(":") + old_key.second + _T(" >> ") + new_key.first + _T(":") + new_key.second); 
     67      } 
     68 
     69    } 
     70    std::pair<std::wstring,std::wstring> split_key(std::wstring key) { 
     71      std::pair<std::wstring,std::wstring> ret; 
     72      int pos = key.find_last_of('/'); 
     73      if (pos == -1) 
     74        return std::pair<std::wstring,std::wstring>(key, _T("")); 
     75      return std::pair<std::wstring,std::wstring>(key.substr(0, pos), key.substr(pos+1)); 
     76    } 
     77 
    12378    typedef std::map<std::wstring,std::wstring> path_map; 
    12479    typedef std::map<settings_core::key_path_type,settings_core::key_path_type> key_map; 
  • modules/CheckDisk/CheckDisk.cpp

    rf7663c9 rc760fc9  
    5151    get_core()->registerCommand(_T("CheckFile2"), _T("Check various aspects of a file and/or folder.")); 
    5252 
    53     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     53    sh::settings_registry settings(get_settings_proxy()); 
    5454    settings.set_alias(_T("NRPE"), alias, _T("server")); 
    5555 
  • modules/CheckEventLog/CheckEventLog.cpp

    r1ecd26f rc760fc9  
    6969    get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
    7070 
    71     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     71    sh::settings_registry settings(get_settings_proxy()); 
    7272    settings.set_alias(_T("CheckEventlog"), alias); 
    7373 
  • modules/CheckExternalScripts/CheckExternalScripts.cpp

    rc015acc rc760fc9  
    7373  try { 
    7474 
    75     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     75    sh::settings_registry settings(get_settings_proxy()); 
    7676    settings.set_alias(alias, _T("external scripts")); 
    7777 
  • modules/CheckNSCP/CheckNSCP.cpp

    r1ecd26f rc760fc9  
    3232namespace sh = nscapi::settings_helper; 
    3333 
    34 CheckNSCP::CheckNSCP() { 
    35 } 
    36 CheckNSCP::~CheckNSCP() { 
    37 } 
    38  
    3934bool CheckNSCP::loadModule() { 
    4035  return false; 
    4136} 
    4237bool CheckNSCP::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    43   //std::wstring appRoot = file_helpers::folders::get_local_appdata_folder(SZAPPNAME); 
    4438  try { 
    4539 
    46     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     40    sh::settings_registry settings(get_settings_proxy()); 
    4741    settings.set_alias(_T("crash"), alias); 
    4842 
     
    5246 
    5347    settings.alias().add_key_to_settings() 
    54       (_T("archive"), sh::wstring_key(&crashFolder ), 
    55       _T("ARCHIVE FOLDER"), _T("The archive folder for crash dunpes.")) 
     48      (_T("archive folder"), sh::wstring_key(&crashFolder, CRASH_ARCHIVE_FOLDER), 
     49      CRASH_ARCHIVE_FOLDER_KEY, _T("The archive folder for crash dunpes.")) 
    5650      ; 
    5751 
     
    6054 
    6155    get_core()->registerCommand(_T("check_nscp"), _T("Check the internal healt of NSClient++.")); 
    62     //crashFolder = NSCModuleHelper::getSettingsString(CRASH_SECTION_TITLE, CRASH_ARCHIVE_FOLDER, file_helpers::folders::get_subfolder(appRoot, _T("crash dumps"))); 
    63  
    64  
    6556  } catch (nscapi::nscapi_exception &e) { 
    6657    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     
    6859    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    6960  } 
    70  
    7161  return true; 
    7262} 
  • modules/CheckNSCP/CheckNSCP.h

    r1ecd26f rc760fc9  
    3030  error_list errors_; 
    3131public: 
    32   CheckNSCP(); 
    33   virtual ~CheckNSCP(); 
    3432  // Module calls 
    3533  bool loadModule(); 
  • modules/CheckSystem/CheckSystem.cpp

    r87cf3c4 rc760fc9  
    7070    bool default_counters; 
    7171 
    72     sh::settings_registry settings(get_core()); 
     72    sh::settings_registry settings(get_settings_proxy()); 
    7373    settings.set_alias(_T("check"), alias, _T("system/windows")); 
    7474 
  • modules/FileLogger/FileLogger.cpp

    r1ecd26f rc760fc9  
    9393    std::wstring log_mask, file, root; 
    9494 
    95     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     95    sh::settings_registry settings(get_settings_proxy()); 
    9696    settings.set_alias(_T("log"), alias); 
    9797 
  • modules/LUAScript/LUAScript.cpp

    r87cf3c4 rc760fc9  
    4444  try { 
    4545 
    46     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     46    sh::settings_registry settings(get_settings_proxy()); 
    4747    settings.set_alias(alias, _T("lua")); 
    4848 
  • modules/NRPEClient/NRPEClient.cpp

    r1ecd26f rc760fc9  
    5151 
    5252    //"/settings/NRPE/client/handlers" 
    53     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     53    sh::settings_registry settings(get_settings_proxy()); 
    5454    settings.set_alias(_T("NRPE"), alias, _T("client")); 
    5555 
  • modules/NRPEClient/NRPEClient.h

    r1ecd26f rc760fc9  
    2525 
    2626 
    27 class NRPEClient : public nscapi::impl::SimpleCommand { 
     27class NRPEClient : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 
    2828private: 
    2929  typedef enum { 
  • modules/NRPEServer/NRPEServer.cpp

    rf7663c9 rc760fc9  
    5959  try { 
    6060 
    61     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     61    sh::settings_registry settings(get_settings_proxy()); 
    6262    settings.set_alias(_T("NRPE"), alias, _T("server")); 
    6363 
  • modules/NSCAAgent/NSCAAgent.cpp

    rf7663c9 rc760fc9  
    5959 
    6060  try { 
    61     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     61    sh::settings_registry settings(get_settings_proxy()); 
    6262    settings.set_alias(_T("NSCA"), alias, _T("agent")); 
    6363 
  • modules/NSCAAgent/NSCAAgent.h

    r5e12ba6 rc760fc9  
    2424NSC_WRAPPERS_CHANNELS(); 
    2525 
    26 class NSCAAgent : public nscapi::impl::SimpleNotificationHandler { 
     26class NSCAAgent : public nscapi::impl::SimpleNotificationHandler, public nscapi::impl::simple_plugin { 
    2727private: 
    2828 
  • modules/Scheduler/Scheduler.cpp

    rc015acc rc760fc9  
    4040    typedef std::map<std::wstring,std::wstring> schedule_map; 
    4141    schedule_map schedules; 
    42     sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     42    sh::settings_registry settings(get_settings_proxy()); 
    4343    settings.set_alias(_T("scheduler"), alias); 
    4444 
     
    9696  std::wstring report, duration; 
    9797 
    98   sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     98  sh::settings_registry settings(get_settings_proxy()); 
    9999 
    100100  settings.path(path).add_path() 
  • service/CMakeLists.txt

    r87cf3c4 rc760fc9  
    77LINK_DIRECTORIES(${BOOST_LIB_DIRS}) 
    88#INCLUDE_DIRECTORIES(${NSCP_INCLUDEDIR}) 
    9  
    10 ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 
    119 
    1210SET(VERSION_HPP ${CMAKE_CURRENT_SOURCE_DIR}/version.hpp) 
     
    3028 
    3129  ${NSCP_INCLUDEDIR}/nscapi/nscapi_helper.cpp 
     30  ${NSCP_INCLUDEDIR}/settings/client/settings_client.cpp 
    3231 
    3332  ${NSCP_INCLUDEDIR}/simpleini/ConvertUTF.c 
     
    7069    ${NSCP_INCLUDEDIR}/settings/settings_handler_impl.hpp 
    7170    ${NSCP_INCLUDEDIR}/settings/settings_interface_impl.hpp 
     71    ${NSCP_INCLUDEDIR}/settings/client/settings_client.hpp 
    7272    ${NSCP_INCLUDEDIR}/com_helpers.hpp 
    7373    ${NSCP_INCLUDEDIR}/dll/dll.hpp 
     
    8989ENDIF(WIN32) 
    9090IF(BREAKPAD_FOUND) 
    91   SET(EXTRA_LIBS ${BREAKPAD_COMMON_LIBRARY}) 
     91  SET(service_SRCS ${service_SRCS} ${NSCP_INCLUDEDIR}/breakpad/exception_handler_win32.cpp) 
     92  IF(WIN32) 
     93    SET(service_SRCS ${service_SRCS} ${NSCP_INCLUDEDIR}/breakpad/exception_handler_win32.hpp) 
     94  ENDIF(WIN32) 
     95  SET(EXTRA_LIBS ${BREAKPAD_COMMON_LIBRARY} ${BREAKPAD_EXCEPTION_HANDLER_LIBRARY} ${BREAKPAD_CRASH_GENERATION_CLIENT_LIBRARY}) 
     96  ADD_DEFINITIONS(-DUSE_BREAKPAD) 
    9297ENDIF(BREAKPAD_FOUND) 
    9398 
     
    95100add_executable (${TARGET} ${service_SRCS}) 
    96101add_dependencies(${TARGET} ${TARGET}_VERSION) 
     102 
     103MESSAGE(STATUS "Extra: ${EXTRA_LIBS}") 
    97104 
    98105target_link_libraries(${TARGET} 
  • service/NSClient++.cpp

    r1ecd26f rc760fc9  
    3939#include "service_manager.hpp" 
    4040#include <nscapi/nscapi_helper.hpp> 
     41#include <settings/client/settings_client.hpp> 
    4142#include "cli_parser.hpp" 
    4243 
    4344#include "../libs/protobuf/plugin.proto.h" 
     45 
     46#ifdef USE_BREAKPAD 
     47#include <breakpad/exception_handler_win32.hpp> 
     48// Used for breakpad crash handling 
     49static ExceptionManager *g_exception_manager = NULL; 
     50#endif 
    4451 
    4552NSClient mainClient(SZSERVICENAME); // Global core instance. 
     
    5461#define LOG_DEBUG_CORE_STD(msg) LOG_DEBUG_CORE(std::wstring(msg)) 
    5562 
    56  
    57 #define SETTINGS_GET_BOOL_CORE(key) \ 
    58   settings_manager::get_settings()->get_bool(setting_keys::key ## _PATH, setting_keys::key, setting_keys::key ## _DEFAULT) 
    59  
    60 #define SETTINGS_GET_STRING_CORE(key) \ 
    61   settings_manager::get_settings()->get_string(setting_keys::key ## _PATH, setting_keys::key, setting_keys::key ## _DEFAULT) 
    62 /* 
    63 #define SETTINGS_SET_STRING_CORE(key, value) \ 
    64   settings::get_settings()->set_string(setting_keys::key ## _PATH, setting_keys::key, value); 
    65 */ 
    6663/** 
    6764 * START OF Tray starter MERGE HELPER 
     
    9895  } 
    9996 
    100   static bool start(unsigned long  dwSessionId) { 
    101     boost::filesystem::wpath program = mainClient.getBasePath() / SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
    102     std::wstring cmdln = _T("\"") + program.string() + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
    103     return tray_starter::startTrayHelper(dwSessionId, program.string(), cmdln); 
     97  static bool start(std::wstring command, unsigned long  dwSessionId) { 
     98    std::wstring cmdln = _T("\"") + command + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
     99    return tray_starter::startTrayHelper(dwSessionId, command, cmdln); 
    104100  } 
    105101 
     
    204200 */ 
    205201 
    206 #define XNSC_DEFINE_SETTING_KEY(name, tag) \ 
    207   name ## _SECTION \ 
    208    
    209  /** 
    210  * RANDOM JUNK (MERGE HELP) 
    211  */ 
    212  
    213 void display(std::wstring title, std::wstring message) { 
    214 #ifdef WIN32 
    215   ::MessageBox(NULL, message.c_str(), title.c_str(), MB_OK|MB_ICONERROR); 
    216 #endif 
    217   std::wcout << title << std::endl << message << std::endl; 
    218 } 
    219  
    220  
    221202bool is_module(boost::filesystem::wpath file )  
    222203{ 
     
    440421  BOOST_FOREACH(std::wstring key, list) { 
    441422    std::wstring val = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, key); 
     423    if ((key.length() > 4) && (key.substr(key.length()-4) == _T(".dll")) ) 
     424      key = key.substr(0, key.length()-4); 
    442425    if (val.empty() || val == _T("enabled")) { 
    443426      ret.insert(plugin_alias_list_type::value_type(_T(""), key)); 
     
    561544// Service functions 
    562545 
     546namespace sh = nscapi::settings_helper; 
     547 
    563548/** 
    564549 * Initialize the program 
     
    574559    return false; 
    575560  } 
    576   LOG_INFO_CORE(_T("Got settings subsystem...")); 
     561  LOG_INFO_CORE(_T("Booted settings subsystem...")); 
     562 
     563  bool crash_submit = false; 
     564  bool crash_archive = false; 
     565  bool crash_restart = false; 
     566  std::wstring crash_url, crash_folder, crash_target, log_level; 
    577567  try { 
    578     if (debug_) 
    579       settings_manager::get_settings()->set_int(_T("log"), _T("debug"), 1); 
    580     settings_manager::get_settings()->set_int(_T("Settings"), _T("shared_Session"), 1); 
    581     enable_shared_session_ = false; //SETTINGS_GET_BOOL_CORE(settings_def::SHARED_SESSION); 
     568 
     569    sh::settings_registry settings(settings_manager::get_proxy()); 
     570 
     571    settings.add_path_to_settings() 
     572      (_T("log"),     _T("LOG SETTINGS"), _T("Section for configuring the log handling.")) 
     573      (_T("shared session"),  _T("SHRED SESSION"), _T("Section for configuring the shared session.")) 
     574      (_T("crash"),     _T("CRASH HANDLER"), _T("Section for configuring the crash handler.")) 
     575      ; 
     576 
     577    settings.add_key_to_settings(_T("log")) 
     578      (_T("level"), sh::wstring_key(&log_level, _T("INFO")), 
     579      _T("LOG LEVEL"), _T("Log level to use")) 
     580      ; 
     581 
     582    settings.add_key_to_settings(_T("shared session")) 
     583      (_T("enabled"), sh::bool_key(&enable_shared_session_ , false), 
     584      _T("LOG LEVEL"), _T("Log level to use")) 
     585      ; 
     586 
     587    settings.add_key_to_settings(_T("crash")) 
     588      (_T("submit"), sh::bool_key(&crash_submit, false), 
     589      _T("SUBMIT CRASHREPORTS"), _T("Submit crash reports to nsclient.org (or your configured submission server)")) 
     590 
     591      (_T("archive"), sh::bool_key(&crash_archive, true), 
     592      _T("ARCHIVE CRASHREPORTS"), _T("Archive crash reports in the archive folder")) 
     593 
     594      (_T("restart"), sh::bool_key(&crash_restart, true), 
     595      _T("RESTART"), _T("Submit crash reports to nsclient.org (or your configured submission server)")) 
     596 
     597      (_T("restart target"), sh::wstring_key(&crash_target, SZSERVICENAME), 
     598      _T("RESTART SERVICE NAME"), _T("The url to submit crash reports to")) 
     599 
     600      (_T("submit url"), sh::wstring_key(&crash_url, CRASH_SUBMIT_URL), 
     601      _T("SUBMISSION URL"), _T("The url to submit crash reports to")) 
     602 
     603      (_T("archive folder"), sh::wpath_key(&crash_folder, CRASH_ARCHIVE_FOLDER), 
     604      CRASH_ARCHIVE_FOLDER_KEY, _T("The folder to archive crash dumps in")) 
     605      ; 
     606 
     607    settings.register_all(); 
     608    settings.notify(); 
     609 
    582610  } catch (settings::settings_exception e) { 
    583611    LOG_ERROR_CORE_STD(_T("Could not find settings: ") + e.getMessage()); 
    584612  } 
     613 
     614#ifdef USE_BREAKPAD 
     615 
     616  if (!g_exception_manager) { 
     617    g_exception_manager = new ExceptionManager(false); 
     618 
     619    g_exception_manager->setup_app(to_wstring(SZSERVICENAME), to_wstring(STRPRODUCTVER), to_wstring(STRPRODUCTDATE)); 
     620 
     621    if (crash_restart) { 
     622      LOG_DEBUG_CORE(_T("On crash: restart: ") + crash_target); 
     623      g_exception_manager->setup_restart(crash_target); 
     624    } 
     625 
     626    bool crashHandling = false; 
     627    if (crash_submit) { 
     628      g_exception_manager->setup_submit(false, crash_url); 
     629      LOG_DEBUG_CORE(_T("Submitting crash dumps to central server: ") + crash_url); 
     630      crashHandling = true; 
     631    } 
     632    if (crash_archive) { 
     633      g_exception_manager->setup_archive(crash_folder); 
     634      LOG_DEBUG_CORE(_T("Archiving crash dumps in: ") + crash_folder); 
     635      crashHandling = true; 
     636    } 
     637    if (!crashHandling) { 
     638      LOG_ERROR_CORE(_T("No crash handling configured")); 
     639    } else { 
     640      g_exception_manager->StartMonitoring(); 
     641    } 
     642  } 
     643#else 
     644  LOG_ERROR_CORE(_T("Warning Not compiled with google breakpad support!")); 
     645#endif 
     646 
    585647 
    586648  if (enable_shared_session_) { 
     
    801863//    return; 
    802864//  } 
    803   LOG_DEBUG_CORE_STD(_T("Got session change: ") + strEx::itos(dwSessionId)); 
    804   if (!logon) { 
    805     LOG_DEBUG_CORE_STD(_T("Not a logon event: ") + strEx::itos(dwEventType)); 
    806     return; 
    807   } 
    808   tray_starter::start(dwSessionId); 
     865// LOG_DEBUG_CORE_STD(_T("Got session change: ") + strEx::itos(dwSessionId)); 
     866// if (!logon) { 
     867//    LOG_DEBUG_CORE_STD(_T("Not a logon event: ") + strEx::itos(dwEventType)); 
     868//    return; 
     869// } 
     870// tray_starter::start(dwSessionId); 
    809871} 
    810872 
     
    856918} 
    857919 
    858 /** 
    859  * Load a list of plug-ins 
    860  * @param plugins A list with plug-ins (DLL files) to load 
    861  */ 
    862 // void NSClientT::addPlugins(const std::list<std::wstring> plugins) { 
    863 //  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
    864 //  if (!readLock.owns_lock()) { 
    865 //    LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex (002).")); 
    866 //    return; 
    867 //  } 
    868 //  std::list<std::wstring>::const_iterator it; 
    869 //  for (it = plugins.begin(); it != plugins.end(); ++it) { 
    870 //    loadPlugin(*it); 
    871 //  } 
    872 // } 
     920 
    873921/** 
    874922 * Unload all plug-ins (in reversed order) 
     
    10151063void NSClientT::registerCommand(unsigned int id, std::wstring cmd, std::wstring desc) { 
    10161064  return commands_.register_command(id, cmd, desc); 
    1017 } 
    1018  
    1019 unsigned int NSClientT::getBufferLength() { 
    1020   static unsigned int len = 0; 
    1021   if (len == 0) { 
    1022     try { 
    1023       len = settings_manager::get_settings()->get_int(SETTINGS_KEY(settings_def::PAYLOAD_LEN)); 
    1024     } catch (settings::settings_exception &e) { 
    1025       LOG_DEBUG_CORE_STD(_T("Failed to get length: ") + e.getMessage()); 
    1026       return setting_keys::settings_def::PAYLOAD_LEN_DEFAULT; 
    1027     } catch (...) { 
    1028       LOG_ERROR_CORE(_T("Failed to get length: :(")); 
    1029       return setting_keys::settings_def::PAYLOAD_LEN_DEFAULT; 
    1030     } 
    1031   } 
    1032   return len; 
    10331065} 
    10341066 
  • service/NSClient++.h

    r1ecd26f rc760fc9  
    171171  std::list<std::wstring> getAllCommandNames(); 
    172172  void registerCommand(unsigned int id, std::wstring cmd, std::wstring desc); 
    173   unsigned int getBufferLength(); 
    174173  void startTrayIcons(); 
    175174  void startTrayIcon(DWORD dwSessionId); 
  • service/core_api.cpp

    r1ecd26f rc760fc9  
    2020#include <msvc_wrappers.h> 
    2121#include <arrayBuffer.h> 
    22 //#include <settings/settings_ini.hpp> 
    23 //#include <settings/settings_registry.hpp> 
    24 //#include <settings/settings_old.hpp> 
    2522#include <settings/settings_core.hpp> 
    2623#include "settings_manager_impl.h" 
  • service/settings_manager_impl.cpp

    r1ecd26f rc760fc9  
    22 
    33#include "settings_manager_impl.h" 
     4#include <settings/client/settings_proxy.hpp> 
     5#include <settings/client/settings_client.hpp> 
    46#include <config.h> 
    57#include "NSClient++.h" 
     
    1214namespace settings_manager { 
    1315  // Alias to make handling "compatible" with old syntax 
     16  nscapi::settings_helper::settings_impl_interface_ptr get_proxy() { 
     17    return nscapi::settings_helper::settings_impl_interface_ptr(new settings_client::settings_proxy(SettingsHandler::getInstance())); 
     18  } 
    1419  settings::instance_ptr get_settings() { 
    1520    return SettingsHandler::getInstance()->get(); 
     
    3136    return mainClient.expand_path(file); 
    3237  } 
     38  std::wstring NSCSettingsImpl::expand_path(std::wstring file) { 
     39    return mainClient.expand_path(file); 
     40  } 
     41 
    3342 
    3443  ////////////////////////////////////////////////////////////////////////// 
  • service/settings_manager_impl.h

    r291548e rc760fc9  
    44#include <settings/settings_core.hpp> 
    55#include <settings/settings_ini.hpp> 
     6#include <settings/client/settings_client.hpp> 
    67#ifdef WIN32 
    78#include <settings/settings_old.hpp> 
     
    4748  // Alias to make handling "compatible" with old syntax 
    4849  settings::instance_ptr get_settings(); 
    49    settings::instance_ptr get_settings_no_wait(); 
     50  settings::instance_ptr get_settings_no_wait(); 
    5051  settings::settings_core* get_core(); 
     52  nscapi::settings_helper::settings_impl_interface_ptr get_proxy(); 
    5153  void destroy_settings(); 
    5254  bool init_settings(std::wstring context = _T("")); 
  • service/simple_client.hpp

    r497b779 rc760fc9  
    5252          core_->startTrayIcon(0); 
    5353        } else if (s == _T("assert")) { 
     54          int *foo = 0; 
     55          *foo = 0; 
    5456          throw "test"; 
    5557        } else { 
Note: See TracChangeset for help on using the changeset viewer.