Changeset c760fc9 in nscp for include


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)
Location:
include
Files:
2 added
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • 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; 
Note: See TracChangeset for help on using the changeset viewer.