Changeset f0eb62d in nscp for service


Ignore:
Timestamp:
11/01/09 11:06:01 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
5229435
Parents:
5da0459
Message:

Refactored service into its own project

Location:
service
Files:
11 moved

Legend:

Unmodified
Added
Removed
  • service/NSClient++-2005.vcproj

    r5da0459 rf0eb62d  
    26932693      </File> 
    26942694      <File 
    2695         RelativePath=".\include\INISettings.h" 
    2696         > 
    2697       </File> 
    2698       <File 
    26992695        RelativePath=".\include\Mutex.h" 
    27002696        > 
     
    27292725      </File> 
    27302726      <File 
    2731         RelativePath=".\include\OLDSettings.hpp" 
    2732         > 
    2733       </File> 
    2734       <File 
    27352727        RelativePath=".\include\PDHCounter.h" 
    27362728        > 
    27372729      </File> 
    27382730      <File 
    2739         RelativePath=".\include\REGSettings.h" 
    2740         > 
    2741       </File> 
    2742       <File 
    27432731        RelativePath=".\include\remote_processes.hpp" 
    27442732        > 
     
    27532741      </File> 
    27542742      <File 
    2755         RelativePath=".\include\Settings.h" 
     2743        RelativePath=".\include\settings\Settings.h" 
     2744        > 
     2745      </File> 
     2746      <File 
     2747        RelativePath=".\include\settings\settings_ini.hpp" 
     2748        > 
     2749      </File> 
     2750      <File 
     2751        RelativePath=".\include\settings\settings_old.hpp" 
     2752        > 
     2753      </File> 
     2754      <File 
     2755        RelativePath=".\include\settings\settings_registry.hpp" 
    27562756        > 
    27572757      </File> 
     
    31103110            CommandLine="echo Copying $(InputFileName)...&#x0D;&#x0A;cmd /c &quot;copy &quot;$(InputDir)\$(InputFileName)&quot; &quot;$(TargetDir)&quot;&quot;&#x0D;&#x0A;" 
    31113111            Outputs="$(TargetDir)$(InputFileName)" 
    3112           /> 
    3113         </FileConfiguration> 
    3114       </File> 
    3115       <File 
    3116         RelativePath=".\Doxyfile" 
    3117         > 
    3118         <FileConfiguration 
    3119           Name="Release|Win32" 
    3120           ExcludedFromBuild="true" 
    3121           > 
    3122           <Tool 
    3123             Name="VCCustomBuildTool" 
    3124             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3125             Outputs=".\Doc" 
    3126           /> 
    3127         </FileConfiguration> 
    3128         <FileConfiguration 
    3129           Name="Release|x64" 
    3130           ExcludedFromBuild="true" 
    3131           > 
    3132           <Tool 
    3133             Name="VCCustomBuildTool" 
    3134             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3135             Outputs=".\Doc" 
    3136           /> 
    3137         </FileConfiguration> 
    3138         <FileConfiguration 
    3139           Name="Debug|Win32" 
    3140           > 
    3141           <Tool 
    3142             Name="VCCustomBuildTool" 
    3143             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3144             Outputs="html" 
    3145           /> 
    3146         </FileConfiguration> 
    3147         <FileConfiguration 
    3148           Name="Debug|x64" 
    3149           ExcludedFromBuild="true" 
    3150           > 
    3151           <Tool 
    3152             Name="VCCustomBuildTool" 
    3153             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3154           /> 
    3155         </FileConfiguration> 
    3156         <FileConfiguration 
    3157           Name="Distribution|Win32" 
    3158           ExcludedFromBuild="true" 
    3159           > 
    3160           <Tool 
    3161             Name="VCCustomBuildTool" 
    3162             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3163             Outputs=".\Doc" 
    3164           /> 
    3165         </FileConfiguration> 
    3166         <FileConfiguration 
    3167           Name="Distribution|x64" 
    3168           ExcludedFromBuild="true" 
    3169           > 
    3170           <Tool 
    3171             Name="VCCustomBuildTool" 
    3172             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3173             Outputs=".\Doc" 
    3174           /> 
    3175         </FileConfiguration> 
    3176         <FileConfiguration 
    3177           Name="Nightly|Win32" 
    3178           ExcludedFromBuild="true" 
    3179           > 
    3180           <Tool 
    3181             Name="VCCustomBuildTool" 
    3182             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3183             Outputs=".\Doc" 
    3184           /> 
    3185         </FileConfiguration> 
    3186         <FileConfiguration 
    3187           Name="Nightly|x64" 
    3188           ExcludedFromBuild="true" 
    3189           > 
    3190           <Tool 
    3191             Name="VCCustomBuildTool" 
    3192             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3193             Outputs=".\Doc" 
    3194           /> 
    3195         </FileConfiguration> 
    3196         <FileConfiguration 
    3197           Name="Debug-MemCheck|Win32" 
    3198           ExcludedFromBuild="true" 
    3199           > 
    3200           <Tool 
    3201             Name="VCCustomBuildTool" 
    3202             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3203           /> 
    3204         </FileConfiguration> 
    3205         <FileConfiguration 
    3206           Name="Debug-MemCheck|x64" 
    3207           ExcludedFromBuild="true" 
    3208           > 
    3209           <Tool 
    3210             Name="VCCustomBuildTool" 
    3211             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3212           /> 
    3213         </FileConfiguration> 
    3214         <FileConfiguration 
    3215           Name="OP5|Win32" 
    3216           ExcludedFromBuild="true" 
    3217           > 
    3218           <Tool 
    3219             Name="VCCustomBuildTool" 
    3220             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3221             Outputs=".\Doc" 
    3222           /> 
    3223         </FileConfiguration> 
    3224         <FileConfiguration 
    3225           Name="OP5|x64" 
    3226           ExcludedFromBuild="true" 
    3227           > 
    3228           <Tool 
    3229             Name="VCCustomBuildTool" 
    3230             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3231             Outputs=".\Doc" 
    3232           /> 
    3233         </FileConfiguration> 
    3234         <FileConfiguration 
    3235           Name="Release|Itanium" 
    3236           ExcludedFromBuild="true" 
    3237           > 
    3238           <Tool 
    3239             Name="VCCustomBuildTool" 
    3240             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3241             Outputs=".\Doc" 
    3242           /> 
    3243         </FileConfiguration> 
    3244         <FileConfiguration 
    3245           Name="Debug|Itanium" 
    3246           ExcludedFromBuild="true" 
    3247           > 
    3248           <Tool 
    3249             Name="VCCustomBuildTool" 
    3250             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3251           /> 
    3252         </FileConfiguration> 
    3253         <FileConfiguration 
    3254           Name="Distribution|Itanium" 
    3255           ExcludedFromBuild="true" 
    3256           > 
    3257           <Tool 
    3258             Name="VCCustomBuildTool" 
    3259             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3260             Outputs=".\Doc" 
    3261           /> 
    3262         </FileConfiguration> 
    3263         <FileConfiguration 
    3264           Name="Nightly|Itanium" 
    3265           ExcludedFromBuild="true" 
    3266           > 
    3267           <Tool 
    3268             Name="VCCustomBuildTool" 
    3269             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    3270             Outputs=".\Doc" 
    3271           /> 
    3272         </FileConfiguration> 
    3273         <FileConfiguration 
    3274           Name="Debug-MemCheck|Itanium" 
    3275           ExcludedFromBuild="true" 
    3276           > 
    3277           <Tool 
    3278             Name="VCCustomBuildTool" 
    3279             CommandLine="doxygen.exe $(InputPath)&#x0D;&#x0A;" 
    32803112          /> 
    32813113        </FileConfiguration> 
  • service/NSClient++.cpp

    r5da0459 rf0eb62d  
    1616#include <winsvc.h> 
    1717#include "NSClient++.h" 
    18 #include <Settings.h> 
     18#include <settings/Settings.h> 
    1919#include <charEx.h> 
    2020#include <Socket.h> 
     
    2828#include <crtdbg.h> 
    2929//#endif 
    30 #include <settings.h> 
    31 #include <INISettings.h> 
    32 #include <REGSettings.h> 
    33 #include <OLDSettings.hpp> 
     30#include <settings/settings_ini.hpp> 
     31#include <settings/settings_registry.hpp> 
     32#include <settings/settings_old.hpp> 
    3433#include <Userenv.h> 
    3534#include <remote_processes.hpp> 
     
    7271 
    7372  static bool start(DWORD dwSessionId) { 
    74     std::wstring program = mainClient.getBasePath() +  _T("\\") + Settings::getInstance()->getString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_SYSTRAY_EXE, NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT); 
     73    std::wstring program = mainClient.getBasePath() +  _T("\\") + SETTINGS_GET_STRING(nsclient::SYSTRAY_EXE); 
    7574    std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
    7675    return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 
     
    234233  } 
    235234}; 
    236  
    237235 
    238236#define SETTINGS_GET_BOOL(key) \ 
     
    303301      throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type)); 
    304302    } 
     303 
    305304  }; 
    306305 
    307306  typedef Singleton<NSCSettingsImpl> SettingsHandler; 
     307 
    308308  // Alias to make handling "compatible" with old syntax 
    309309  Settings::SettingsInterface* get_settings() { 
     
    316316    SettingsHandler::destroyInstance(); 
    317317  } 
     318 
    318319 
    319320  bool init_settings() { 
     
    322323      get_core()->set_base(mainClient.getBasePath()); 
    323324      get_core()->boot(_T("boot.ini")); 
    324 #define MAIN_MODULES_SECTION_OLD _T("modules") 
    325 #define MAIN_SECTION_TITLE _T("Settings") 
    326 #define MAIN_STRING_LENGTH _T("string_length") 
    327       get_core()->add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD); 
    328       get_core()->add_mapping(settings::settings_def::PAYLOAD_LEN_PATH, settings::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH); 
    329325      get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, Settings::SettingsCore::key_integer)); 
    330326      get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, Settings::SettingsCore::key_string)); 
     
    995991    } 
    996992    try { 
    997       loadPlugins(); 
     993      loadPlugins(boot?NSCAPI::normalStart:NSCAPI::dontStart); 
    998994    } catch (...) { 
    999995      LOG_ERROR_STD(_T("Unknown exception loading plugins")); 
     
    11431139  return mainClient.service_ctrl_ex(dwControl, dwEventType, lpEventData, lpContext); 
    11441140} 
    1145  
    11461141/** 
    11471142 * Forward this to the main service dispatcher helper class 
     
    11651160  tray_starter::start(dwSessionId); 
    11661161} 
    1167  
    11681162 
    11691163////////////////////////////////////////////////////////////////////////// 
     
    12921286} 
    12931287 
    1294 void NSClientT::loadPlugins() { 
     1288void NSClientT::loadPlugins(NSCAPI::moduleLoadMode mode) { 
    12951289  bool hasBroken = false; 
    12961290  { 
     
    13151309        LOG_ERROR_STD(_T("Could not load plugin: ") + (*it)->getModule()); 
    13161310      } 
     1311    } 
    13171312  } 
    13181313  for (pluginList::iterator it=plugins_.begin(); it != plugins_.end();) { 
    13191314    LOG_DEBUG_STD(_T("Loading plugin: ") + (*it)->getName() + _T("...")); 
    13201315    try { 
    1321       (*it)->load_plugin(); 
     1316      (*it)->load_plugin(mode); 
    13221317      ++it; 
    13231318    } catch(NSPluginException e) { 
     
    15131508void NSClientT::listPlugins() { 
    15141509  ReadLock readLock(&m_mutexRW, true, 10000); 
     1510  if (!readLock.IsLocked()) { 
     1511    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
     1512    return; 
     1513  } 
     1514  for (pluginList::iterator it=plugins_.begin(); it != plugins_.end(); ++it) { 
    15151515    try { 
    1516       std::wstring msg, perf; 
    1517       int returnCode = shared_client_->inject(command, arrayBuffer::arrayBuffer2string(argument, argLen, _T(" ")), L' ', true, msg, perf); 
    1518       NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, msg, returnCode); 
    1519       return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, perf, returnCode); 
    1520     } catch (nsclient_session::session_exception &e) { 
    1521       LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 
    1522       int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: ") + e.what(), NSCAPI::returnCRIT); 
    1523       return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 
    1524     } catch (...) { 
    1525       LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 
    1526       int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command:  + e.what()"), NSCAPI::returnCRIT); 
    1527       return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 
    1528     } 
    1529   } else { 
    1530     ReadLock readLock(&m_mutexRW, true, 5000); 
    1531     if (!readLock.IsLocked()) { 
    1532       LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    1533       return NSCAPI::returnUNKNOWN; 
    1534     } 
    1535     for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 
    1536       try { 
    1537         NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
    1538         switch (c) { 
    1539           case NSCAPI::returnInvalidBufferLen: 
    1540             LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 
    1541             return c; 
    1542           case NSCAPI::returnIgnored: 
    1543             break; 
    1544           case NSCAPI::returnOK: 
    1545           case NSCAPI::returnWARN: 
    1546           case NSCAPI::returnCRIT: 
    1547           case NSCAPI::returnUNKNOWN: 
    1548             LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 
    1549             LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 
    1550             return c; 
    1551           default: 
    1552             LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 
    1553             return c; 
    1554         } 
    1555       } catch(const NSPluginException& e) { 
    1556         LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
    1557         return NSCAPI::returnCRIT; 
    1558       } catch(...) { 
    1559         LOG_ERROR_STD(_T("Unknown exception raised in module")); 
    1560         return NSCAPI::returnCRIT; 
    1561       } 
    1562     } 
    1563     LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 
    1564     return NSCAPI::returnIgnored; 
    1565   } 
     1516      if ((*it)->isBroken()) { 
     1517        std::wcout << (*it)->getModule() << _T(": ") << _T("broken") << std::endl; 
     1518      } else { 
     1519        std::wcout << (*it)->getModule() << _T(": ") << (*it)->getName() << std::endl; 
     1520      } 
     1521    } catch (NSPluginException e) { 
     1522      LOG_ERROR_STD(_T("Could not load plugin: ") + e.file_ + _T(": ") + e.error_); 
     1523    } 
     1524  } 
     1525 
    15661526} 
    15671527 
     
    15791539  return (debug_ == log_debug); 
    15801540} 
    1581 void NSClientT::enableDebug(bool debug) { 
    1582   if (debug) { 
    1583     debug_ = log_debug; 
    1584     LOG_DEBUG(_T("Enabling debug mode...")); 
    1585   } 
    1586   else 
    1587     debug_ = log_nodebug; 
    1588 } 
    1589  
    15901541 
    15911542void log_broken_message(std::wstring msg) { 
     
    19491900  return NSCAPI::isSuccess; 
    19501901} 
    1951 NSCAPI::errorReturn NSAPISettingsAddKeyMapping(const TCHAR* source_path, const TCHAR* source_key, const TCHAR* destination_path, const TCHAR* destination_key) { 
    1952   try { 
    1953     settings_manager::get_core()->add_mapping(source_path, source_key, destination_path, destination_key); 
    1954   } catch (SettingsException e) { 
    1955     LOG_ERROR_STD(_T("Failed to add mapping: ") + e.getMessage()); 
    1956     return NSCAPI::hasFailed; 
    1957   } catch (...) { 
    1958     LOG_ERROR_STD(_T("Failed to add mapping")); 
    1959     return NSCAPI::hasFailed; 
    1960   } 
    1961   return NSCAPI::isSuccess; 
    1962 } 
    1963 NSCAPI::errorReturn NSAPISettingsAddPathMapping(const TCHAR* src, const TCHAR* dst) { 
    1964   try { 
    1965     settings_manager::get_core()->add_mapping(src, dst); 
    1966   } catch (SettingsException e) { 
    1967     LOG_ERROR_STD(_T("Failed to add mapping: ") + e.getMessage()); 
    1968     return NSCAPI::hasFailed; 
    1969   } catch (...) { 
    1970     LOG_ERROR_STD(_T("Failed to add mapping")); 
    1971     return NSCAPI::hasFailed; 
    1972   } 
    1973   return NSCAPI::isSuccess; 
    1974 } 
    1975  
    19761902NSCAPI::errorReturn NSAPISettingsRegKey(const TCHAR* path, const TCHAR* key, int type, const TCHAR* title, const TCHAR* description, const TCHAR* defVal, int advanced) { 
    19771903  try { 
     
    21002026  if (_wcsicmp(buffer, _T("NSAPIRegisterCommand")) == 0) 
    21012027    return &NSAPIRegisterCommand; 
    2102   if (_wcsicmp(buffer, _T("NSAPISettingsAddKeyMapping")) == 0) 
    2103     return &NSAPISettingsAddKeyMapping; 
    2104   if (_wcsicmp(buffer, _T("NSAPISettingsAddPathMapping")) == 0) 
    2105     return &NSAPISettingsAddPathMapping; 
    2106  
    21072028  if (_wcsicmp(buffer, _T("NSAPISettingsRegKey")) == 0) 
    21082029    return &NSAPISettingsRegKey; 
  • service/NSClient++.h

    r5da0459 rf0eb62d  
    115115public: 
    116116  // c-tor, d-tor 
    117   NSClientT(void) : debug_(log_unknown), boot_(true) {} 
    118117  NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {} 
    119118  virtual ~NSClientT(void) {} 
     
    123122    else 
    124123      debug_ = log_nodebug; 
    125   } 
    126   void setBoot(bool boot = true) { 
    127     boot_ = boot; 
    128124  } 
    129125 
     
    149145  void addPlugins(const std::list<std::wstring> plugins); 
    150146  plugin_type loadPlugin(const std::wstring plugin); 
    151   void loadPlugins(void); 
     147  void loadPlugins(NSCAPI::moduleLoadMode mode); 
    152148  void unloadPlugins(bool unloadLoggers); 
    153149  std::wstring describeCommand(std::wstring command); 
     
    218214NSCAPI::errorReturn NSAPIReleaseAllCommandNamessBuffer(TCHAR***, unsigned int *); 
    219215NSCAPI::errorReturn NSAPIRegisterCommand(const TCHAR*,const TCHAR*); 
    220 NSCAPI::errorReturn NSAPISettingsAddKeyMapping(const TCHAR*, const TCHAR*, const TCHAR*, const TCHAR*); 
    221 NSCAPI::errorReturn NSAPISettingsAddPathMapping(const TCHAR*, const TCHAR*); 
    222216NSCAPI::errorReturn NSAPISettingsRegKey(const TCHAR*, const TCHAR*, int, const TCHAR*, const TCHAR*, const TCHAR*, int); 
    223217NSCAPI::errorReturn NSAPISettingsRegPath(const TCHAR*, const TCHAR*, const TCHAR*, int); 
     
    225219NSCAPI::errorReturn NSAPIReleasePluginList(int,NSCAPI::plugin_info*[]); 
    226220NSCAPI::errorReturn NSAPISettingsSave(void); 
    227  
    228221 
    229222 
Note: See TracChangeset for help on using the changeset viewer.