Changeset a34b229 in nscp


Ignore:
Timestamp:
09/09/08 10:11:36 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
7221dc8
Parents:
dc59b0e
Message:

2008-09-09 MickeM

  • Fixed issue with & and some commands via check_nt.
  • Fixed a crash on exit (which I added in Rc1).
  • Added 10 "bytes" the CPU buffer: (#174) + Added new option to [EventLog?] section buffer_size to change the size of the buffer used when scanning the evenlotg (defaults to 64k).
  • Fixed error handling in CHeckEventLog so errors are repoorted properly (#184)
Files:
2 added
1 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    rdc59b0e ra34b229  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,4,4 
    6 #define PRODUCTVER     0,3,4,4 
    7 #define STRFILEVER     _T("0.3.4.4") 
    8 #define STRPRODUCTVER  _T("0.3.4.4") 
    9 #define STRPRODUCTDATE  _T("2008-09-08") 
     5#define FILEVER        0,3,4,23 
     6#define PRODUCTVER     0,3,4,23 
     7#define STRFILEVER     _T("0.3.4.23") 
     8#define STRPRODUCTVER  _T("0.3.4.23") 
     9#define STRPRODUCTDATE  _T("2008-09-09") 
    1010#endif // AUTOBUILD_H 
  • NSC.dist

    rdc59b0e ra34b229  
    300300check_other=-H 192.168.0.1 -p 5666 -c remote_command -a arguments 
    301301 
     302;# LUA SCRIPT SECTION 
     303;  A list of all Lua scripts to load. 
     304;[LUA Scripts] 
     305;scripts\test.lua 
  • NSCPlugin.cpp

    rc0522cd ra34b229  
    4545  ,fHideTray(NULL) 
    4646  ,bLoaded_(false) 
     47  ,lastIsMsgPlugin_(false) 
    4748{ 
    4849} 
     
    6364  ,fHideTray(NULL) 
    6465  ,bLoaded_(false) 
     66  ,lastIsMsgPlugin_(false) 
    6567{ 
    6668  if (other.bLoaded_) { 
     
    179181    throw NSPluginException(file_, _T("Module not loaded")); 
    180182  try { 
    181     if (fHasMessageHandler()) 
     183    if (fHasMessageHandler()) { 
     184      lastIsMsgPlugin_ = true; 
    182185      return true; 
     186    } 
    183187    return false; 
    184188  } catch (...) { 
  • NSCPlugin.h

    rc0522cd ra34b229  
    160160    return ret; 
    161161  } 
     162  bool getLastIsMsgPlugin() { 
     163    return lastIsMsgPlugin_; 
     164  } 
    162165 
    163166private: 
     167  bool lastIsMsgPlugin_; 
    164168  bool isLoaded() const { 
    165169    return bLoaded_; 
  • NSClient++-2005.sln

    rdc59b0e ra34b229  
    139139  EndProjectSection 
    140140  ProjectSection(ProjectDependencies) = postProject 
     141    {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B} 
     142    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
     143    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} 
     144    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
     145    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} = {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} 
     146    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} 
     147    {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24} 
     148    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} 
     149    {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8} 
     150    {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {F3401E75-60FB-4A0E-A18C-6505587D5B1A} 
     151    {26B84883-BE52-40E6-9BEE-55AD056D5751} = {26B84883-BE52-40E6-9BEE-55AD056D5751} 
     152    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} 
     153    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} 
     154    {6F55C9BF-57F6-4A15-A058-C83A52F539EE} = {6F55C9BF-57F6-4A15-A058-C83A52F539EE} 
     155    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} = {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} 
     156    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} 
     157    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} 
     158  EndProjectSection 
     159EndProject 
     160Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UploadInstaller", "helpers\UploadInstaller\UploadInstaller.vcproj", "{6206F046-3D36-4258-BB03-3291A7070117}" 
     161  ProjectSection(WebsiteProperties) = preProject 
     162    Debug.AspNetCompiler.Debug = "True" 
     163    Release.AspNetCompiler.Debug = "False" 
     164  EndProjectSection 
     165  ProjectSection(ProjectDependencies) = postProject 
    141166    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
    142167    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
    143   EndProjectSection 
    144 EndProject 
    145 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UploadInstaller", "helpers\UploadInstaller\UploadInstaller.vcproj", "{6206F046-3D36-4258-BB03-3291A7070117}" 
     168    {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {A3CF4E23-1D1B-4D93-A16A-48C52D118560} 
     169  EndProjectSection 
     170EndProject 
     171Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UploadBinaries", "helpers\UploadBinaries\UploadBinaries.vcproj", "{D96F7075-F6CD-4921-B5D8-8488E2D24BDB}" 
    146172  ProjectSection(WebsiteProperties) = preProject 
    147173    Debug.AspNetCompiler.Debug = "True" 
     
    150176  ProjectSection(ProjectDependencies) = postProject 
    151177    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
    152     {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {A3CF4E23-1D1B-4D93-A16A-48C52D118560} 
    153   EndProjectSection 
    154 EndProject 
    155 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UploadBinaries", "helpers\UploadBinaries\UploadBinaries.vcproj", "{D96F7075-F6CD-4921-B5D8-8488E2D24BDB}" 
    156   ProjectSection(WebsiteProperties) = preProject 
    157     Debug.AspNetCompiler.Debug = "True" 
    158     Release.AspNetCompiler.Debug = "False" 
    159   EndProjectSection 
    160   ProjectSection(ProjectDependencies) = postProject 
    161178    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
    162     {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
    163179  EndProjectSection 
    164180EndProject 
     
    11731189    {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {9757464B-C125-4307-A84A-F4181AE6A081} 
    11741190    {0E2B21D9-F432-4127-8E92-7716B1072510} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
     1191    {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    11751192    {6206F046-3D36-4258-BB03-3291A7070117} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    11761193    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    1177     {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    11781194    {630857C0-6AD8-4CEE-B5F7-CA1DF620CA9A} = {C8DCE3D7-A802-4C5D-ABB1-B478F545B6E5} 
    11791195    {B6D08289-B8AE-4391-9D07-93B22618BE58} = {C8DCE3D7-A802-4C5D-ABB1-B478F545B6E5} 
  • NSClient++-2005.vcproj

    rc0522cd ra34b229  
    24292429      </File> 
    24302430      <File 
     2431        RelativePath=".\resource.h" 
     2432        > 
     2433      </File> 
     2434      <File 
    24312435        RelativePath=".\include\ServiceCmd.h" 
    24322436        > 
     
    24692473      Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 
    24702474      > 
     2475      <File 
     2476        RelativePath=".\NSClient++.rc" 
     2477        > 
     2478      </File> 
     2479      <File 
     2480        RelativePath=".\res\standby.ico" 
     2481        > 
     2482      </File> 
    24712483    </Filter> 
    24722484    <Filter 
  • NSClient++.cpp

    rbc97cd8 ra34b229  
    189189      } catch (const serviceControll::SCException& e) { 
    190190        LOG_MESSAGE_STD(_T("Couldn't set service description: ") + e.error_); 
     191        return -1; 
    191192      } 
    192193      LOG_MESSAGE(_T("Service installed!")); 
     194      return 0; 
    193195    } else if ( _wcsicmp( _T("uninstall"), argv[1]+1 ) == 0 ) { 
    194196      g_bConsoleLog = true; 
     
    197199      } catch (const serviceControll::SCException& e) { 
    198200        LOG_MESSAGE_STD(_T("Service deinstallation failed; ") + e.error_); 
    199         return -1; 
    200201      } 
    201202      LOG_MESSAGE(_T("Service uninstalled!")); 
     203      return 0; 
    202204    } else if ( _wcsicmp( _T("encrypt"), argv[1]+1 ) == 0 ) { 
    203205      g_bConsoleLog = true; 
     
    521523 
    522524bool NSClientT::exitCore(bool boot) { 
     525  plugins_loaded_ = false; 
    523526  LOG_MESSAGE(_T("Attempting to stop NSCLient++ - " SZVERSION)); 
    524527  if (boot) { 
     
    527530      mainClient.unloadPlugins(false); 
    528531    } catch(NSPluginException e) { 
    529       std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 
     532      LOG_ERROR_STD(_T("Exception raised when unloading non msg plguins: ") + e.error_ + _T(" in module: ") + e.file_); 
    530533    } catch(...) { 
    531       std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     534      LOG_ERROR_STD(_T("Unknown exception raised when unloading non msg plugins")); 
    532535    } 
    533536  } 
     
    557560    } 
    558561  } catch(nsclient_session::session_exception &e) { 
    559     std::wcout << _T("Exception closing shared client session: ") << e.what() << std::endl;; 
     562    LOG_ERROR_STD(_T("Exception closing shared client session: ") + e.what()); 
    560563  } catch(...) { 
    561     std::wcout << _T("Exception closing shared client session: Unknown exception!") << std::endl;; 
     564    LOG_ERROR_STD(_T("Exception closing shared client session: Unknown exception!")); 
    562565  } 
    563566  try { 
     
    568571    } 
    569572  } catch(...) { 
    570     std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     573    LOG_ERROR_STD(_T("UNknown exception raised: When closing shared session")); 
    571574  } 
    572575  if (boot) { 
     
    575578      mainClient.unloadPlugins(true); 
    576579    } catch(NSPluginException e) { 
    577       std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 
     580      LOG_ERROR_STD(_T("Exception raised when unloading msg plugins: ") + e.error_ + _T(" in module: ") + e.file_); 
    578581    } catch(...) { 
    579       std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     582      LOG_ERROR_STD(_T("UNknown exception raised: When stopping message plguins")); 
    580583    } 
    581584  } 
     
    713716      return; 
    714717    } 
    715     for (pluginList::size_type i=plugins_.size();i>0;i--) { 
    716       NSCPlugin *p = plugins_[i-1]; 
     718    for (pluginList::reverse_iterator it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 
     719      NSCPlugin *p = *it; 
     720      if (p == NULL) 
     721        continue; 
    717722      if (!unloadLoggers && p->hasMessageHandler()) { 
    718723        LOG_DEBUG_STD(_T("Skipping log plugin: ") + p->getModule() + _T("...")); 
     
    729734      return; 
    730735    } 
    731     for (pluginList::size_type i=plugins_.size();i>0;i--) { 
    732       NSCPlugin *p = plugins_[i-1]; 
    733       if (unloadLoggers || !p->hasMessageHandler()) { 
    734         LOG_DEBUG_STD(_T("Deleating plugin instance: ") + p->getModule() + _T("...")); 
    735         plugins_[i-1] = NULL; 
    736         delete p; 
    737         plugins_.erase(plugins_.begin() + i-1); 
    738         --i; 
    739       } 
    740     } 
    741     //plugins_.clear(); 
     736    for (pluginList::iterator it = plugins_.begin(); it != plugins_.end(); ++it) { 
     737      NSCPlugin *p = (*it); 
     738      if (p == NULL) 
     739        continue; 
     740      try { 
     741        if (unloadLoggers || !p->getLastIsMsgPlugin()) { 
     742          *it = NULL; 
     743          delete p; 
     744          it = plugins_.erase(it); 
     745        } 
     746      } catch(NSPluginException e) { 
     747        LOG_ERROR_STD(_T("Exception raised when unloading plugin: ") + e.error_ + _T(" in module: ") + e.file_); 
     748      } catch(...) { 
     749        LOG_ERROR_STD(_T("Unknown exception raised when unloading plugin")); 
     750      } 
     751    } 
    742752  } 
    743753} 
     
    948958} 
    949959 
     960void log_broken_message(std::wstring msg) { 
     961  OutputDebugString(msg.c_str()); 
     962  std::wcout << msg << std::endl; 
     963} 
    950964/** 
    951965 * Report a message to all logging enabled modules. 
     
    964978      shared_server_->sendLogMessageToClients(msgType, file, line, message); 
    965979    } catch (nsclient_session::session_exception e) { 
    966       std::wcout << _T("Failed to send message to clients: ") << e.what() << std::endl; 
     980      log_broken_message(_T("Failed to send message to clients: ") + e.what()); 
    967981    } 
    968982  } 
     
    974988    ReadLock readLock(&m_mutexRW, true, 5000); 
    975989    if (!readLock.IsLocked()) { 
    976       OutputDebugString(_T("Message was lost as the core was locked...")); 
    977       std::wcout << _T("Message was lost as the core was locked...") << std::endl; 
     990      log_broken_message(_T("Message was lost as the (mutexRW) core was locked: ") + message); 
    978991      return; 
    979992    } 
    980993    MutexLock lock(messageMutex); 
    981994    if (!lock.hasMutex()) { 
    982       OutputDebugString(_T("Message was lost as the core was locked...")); 
    983       OutputDebugString(message.c_str()); 
    984       std::wcout << _T("Message was lost as the core was locked...") << std::endl; 
    985       std::wcout << message << std::endl; 
     995      log_broken_message(_T("Message was lost as the core was locked: ") + message); 
    986996      return; 
    987997    } 
     
    10121022    } else { 
    10131023      if (log_cache_.size() > 0) { 
    1014         std::wcout << _T("*** SENDING CACHE***") << std::endl; 
    10151024        for (log_cache_type::const_iterator cit=log_cache_.begin();cit!=log_cache_.end();++cit) { 
    10161025          for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     
    10181027              messageHandlers_[i]->handleMessage((*cit).msgType, (_T("CACHE") + (*cit).file).c_str(), (*cit).line, (*cit).message.c_str()); 
    10191028            } catch(const NSPluginException& e) { 
    1020               // Here we are pretty much fucked! (as logging this might cause a loop :) 
    1021               std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 
    1022               std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 
     1029              log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
     1030              return; 
     1031            } catch(...) { 
     1032              log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
     1033              return; 
    10231034            } 
    10241035          } 
     
    10301041          messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
    10311042        } catch(const NSPluginException& e) { 
    1032           // Here we are pretty much fucked! (as logging this might cause a loop :) 
    1033           std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 
    1034           std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 
     1043          log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
     1044          return; 
     1045        } catch(...) { 
     1046          log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
     1047          return; 
    10351048        } 
    10361049      } 
  • NSClient++.rc

    ra0528c4 ra34b229  
    3030// remains consistent on all systems. 
    3131IDI_STANDBY             ICON                    "res/standby.ico" 
    32  
    33 ///////////////////////////////////////////////////////////////////////////// 
    34 // 
    35 // Menu 
    36 // 
    37  
    38  
    3932#endif    // English (U.S.) resources 
    40 ///////////////////////////////////////////////////////////////////////////// 
    41  
    42  
    43 #ifdef APSTUDIO_INVOKED 
    44 ///////////////////////////////////////////////////////////////////////////// 
    45 // 
    46 // TEXTINCLUDE 
    47 // 
    48  
    49 1 TEXTINCLUDE  
    50 BEGIN 
    51     "resource.h\0" 
    52 END 
    53  
    54 2 TEXTINCLUDE  
    55 BEGIN 
    56     "#include ""afxres.h""\r\n" 
    57     "\0" 
    58 END 
    59  
    60 #endif    // APSTUDIO_INVOKED 
    61  
    62  
    63 ///////////////////////////////////////////////////////////////////////////// 
    64 // 
    65 // String Table 
    66 // 
    67  
    68 STRINGTABLE  
    69 BEGIN 
    70     IDS_HELLO               "Hello from MFC!" 
    71 END 
    72  
    73 #endif    // French (France) resources 
    7433///////////////////////////////////////////////////////////////////////////// 
    7534 
     
    8443#endif //_WIN32 
    8544 
     45#ifdef APSTUDIO_INVOKED 
    8646///////////////////////////////////////////////////////////////////////////// 
    8747// 
    88 // DESIGNINFO 
     48// TEXTINCLUDE 
    8949// 
    9050 
     511 TEXTINCLUDE  
     52BEGIN 
     53    "resource.\0" 
     54END 
    9155 
    92 ///////////////////////////////////////////////////////////////////////////// 
    93 // 
    94 // Dialog 
    95 // 
    9656 
     573 TEXTINCLUDE  
     58BEGIN 
     59    "\r\0" 
     60END 
     61 
     62#endif    // APSTUDIO_INVOKED 
    9763 
    9864#endif    // Swedish resources 
     
    10167 
    10268 
     69#ifndef APSTUDIO_INVOKED 
     70///////////////////////////////////////////////////////////////////////////// 
     71// 
     72// Generated from the TEXTINCLUDE 3 resource. 
     73// 
     74 
     75 
     76///////////////////////////////////////////////////////////////////////////// 
     77#endif    // not APSTUDIO_INVOKED 
     78 
  • changelog

    rdc59b0e ra34b229  
    44 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
    55 * Improved socket performance (would be nice if we could be used as a "hub") 
     6 
     72008-09-09 MickeM 
     8 * Fixed issue with & and some commands via check_nt. 
     9 * Fixed a crash on exit (which I added in Rc1). 
     10 * Added 10 "bytes" the CPU buffer: (#174) 
     11 + Added new option to [EventLog] section buffer_size to change the size of the buffer used when scanning the evenlotg (defaults to 64k). 
     12 * Fixed error handling in CHeckEventLog so errors are repoorted properly (#184) 
     13 
     142008-09-08 MickeM 
     15 * Fixed issue in windows 2008 with system tray (shared_session). 
     16 * Fixed installer issue (should run (i hope) service installer on install now on 64 bit os) 
     17 * Fixed issue with unloading plugins and log (causing "timeouts" when exiting some times) 
    618 
    7192008-09-07 MickeM 
  • helpers/systray_helper/TrayWidget.cpp

    rbc97cd8 ra34b229  
    3333 
    3434logging::file_logger g_log_instance(_T("nsclient++"),_T("systray.log")); 
     35HINSTANCE ghInstance = NULL; 
     36TrayWidget *gTrayInstance = NULL; 
    3537 
    3638#define LOG_ERROR_FILE(x) g_log_instance.log(_T("error"), __FILEW__, __LINE__, std::wstring(x).c_str()); 
     
    4143 
    4244#define LOG_ERROR_TO_TRAY(x) gTrayInstance->log(_T("error"), __FILEW__, __LINE__, std::wstring(x).c_str()); 
     45#define LOG_MESSAGE_TO_TRAY(x) gTrayInstance->log(_T("message"), __FILEW__, __LINE__, std::wstring(x).c_str()); 
    4346 
    4447#if WINVER < 0x0600 
     
    5255    HMODULE hMod = GetModuleHandle(TEXT("user32")); 
    5356    if (hMod == NULL) 
    54       return false; 
     57      return FALSE; 
    5558    fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(hMod,"ChangeWindowMessageFilter"); 
    5659  } 
    5760  if (fnChangeWindowMessageFilter == NULL) { 
    58     return true; 
    59   } 
     61    LOG_ERROR_FILE(_T("Could not find ChangeWindowMessageFilter: ") + error::lookup::last_error()); 
     62    return TRUE; 
     63  } 
     64  LOG_ERROR_FILE(_T("registred windows thingy...")); 
    6065  return fnChangeWindowMessageFilter(message,what); 
    6166} 
     
    7277  return _T(""); 
    7378} 
    74 HINSTANCE ghInstance = NULL; 
    75 TrayWidget *gTrayInstance = NULL; 
    7679TrayWidget::TrayWidget(std::wstring cmdLine) { 
    7780  strEx::splitList list = strEx::splitEx(cmdLine, _T(" ")); 
     
    124127 
    125128 
     129 
    126130void TrayWidget::createDialog(HINSTANCE hInstance) { 
     131  LOG_MESSAGE_TRAY(_T("Creating dialog...")); 
    127132  ghInstance = hInstance; 
    128   hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 
    129   if ((hDlgWnd == NULL)||!IsWindow(hDlgWnd)) { 
    130     LOG_ERROR_TRAY(_T("Failed to create windows: ") + error::lookup::last_error()); 
    131   } 
     133  //hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 
     134  //if ((hDlgWnd == NULL)||!IsWindow(hDlgWnd)) { 
     135//    LOG_ERROR_TRAY(_T("Failed to create windows: ") + error::lookup::last_error()); 
     136//  } 
     137 
     138  WNDCLASSEX wndclass; 
     139  wndclass.lpszMenuName=NULL; 
     140  wndclass.cbSize=sizeof(wndclass); 
     141  wndclass.lpfnWndProc=TrayIcon::DialogProc; 
     142  wndclass.cbClsExtra=0; 
     143  wndclass.cbWndExtra=0; 
     144  wndclass.hInstance=hInstance; 
     145  wndclass.hIcon=NULL; 
     146  wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); 
     147  wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); 
     148  wndclass.hIconSm=NULL; 
     149  wndclass.lpszClassName=_T("NSClient_pp_TrayClass"); 
     150  wndclass.style=0; 
     151  // register task bar restore event after crash 
     152  //WM_TASKBARCREATED=RegisterWindowMessage(TEXT("TaskbarCreated")); 
     153  //MyChangeWindowMessageFilter(WM_TASKBARCREATED, MSGFLT_ADD);  
    132154 
    133155  UINT UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 
     
    139161  } 
    140162 
     163  if (!RegisterClassEx(&wndclass)) { 
     164    LOG_ERROR_TRAY(_T("Failed to register window class: ") + error::lookup::last_error()); 
     165  } 
     166 
     167  MSG msg; 
     168  hDlgWnd=CreateWindow(_T("NSClient_pp_TrayClass"),NULL,0,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL); 
     169  if(hDlgWnd==NULL) 
     170  { 
     171    LOG_ERROR_TRAY(_T("Failed to create window: ") + error::lookup::last_error()); 
     172    return; 
     173  } 
     174  while(GetMessage(&msg,NULL,0,0)) 
     175  { 
     176    if (msg.message == WM_MY_CLOSE) { 
     177      ::DestroyWindow(hDlgWnd); 
     178    } else if (msg.message == UDM_TASKBARCREATED) { 
     179      LOG_MESSAGE_TRAY(_T("Recreating systray icon...")); 
     180      TrayIcon::addIcon(msg.hwnd); 
     181    } else { 
     182      TranslateMessage(&msg); 
     183      DispatchMessage(&msg); 
     184    } 
     185  } 
     186  return; 
     187   
     188  /* 
    141189  MSG Msg; 
    142190  BOOL bRet; 
     
    158206    }  
    159207  } 
     208  */ 
    160209} 
    161210 
     
    529578namespace TrayIcon 
    530579{ 
     580  UINT UDM_TASKBARCREATED = -1; 
    531581  HMENU hPopupMenu_ = NULL; 
    532582} 
    533 INT_PTR CALLBACK TrayIcon::DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) 
     583//LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 
     584LRESULT CALLBACK TrayIcon::DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) 
    534585{ 
     586  if (uMsg == UDM_TASKBARCREATED) { 
     587    addIcon(hwndDlg); 
     588    LOG_MESSAGE_TO_TRAY(_T("UDM_TASKBARCREATED")); 
     589  } 
     590 
    535591  switch (uMsg)  
    536592  { 
     
    542598    return 0; 
    543599 
     600  case WM_CREATE: 
    544601  case WM_INITDIALOG: 
     602    LOG_MESSAGE_TO_TRAY(_T("WM_INITDIALOG")); 
     603 
     604 
     605    UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 
     606    if (UDM_TASKBARCREATED == 0) { 
     607      LOG_MESSAGE_TO_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 
     608    } 
     609    if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
     610      LOG_MESSAGE_TO_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 
     611    } 
     612 
    545613    addIcon(hwndDlg); 
    546614    break; 
     
    601669    break; 
    602670  } 
    603   return FALSE; 
     671  return DefWindowProc(hwndDlg,uMsg,wParam,lParam); 
     672  //return FALSE; 
    604673} 
    605674void TrayIcon::addIcon(HWND hWnd) { 
  • helpers/systray_helper/TrayWidget.h

    rbc97cd8 ra34b229  
    7575namespace TrayIcon 
    7676{ 
    77   INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
     77  LRESULT CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
    7878  INT_PTR CALLBACK InjectDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
    7979  INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
  • include/NSCHelper.cpp

    rbc97cd8 ra34b229  
    257257  return retC; 
    258258} 
     259 
     260/** 
     261* Inject a request command in the core (this will then be sent to the plug-in stack for processing) 
     262* @param command Command to inject (password should not be included. 
     263* @param argLen The length of the argument buffer 
     264* @param **argument The argument buffer 
     265* @param message The return message buffer 
     266* @param perf The return performance data buffer 
     267* @return The return of the command 
     268*/ 
     269NSCAPI::nagiosReturn NSCModuleHelper::InjectCommand(const TCHAR* command, std::list<std::wstring> argument, std::wstring & message, std::wstring & perf)  
     270{ 
     271  if (!fNSAPIInject) 
     272    throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 
     273  unsigned int buf_len = getBufferLength(); 
     274 
     275 
     276  unsigned int argLen; 
     277  TCHAR ** aBuffer = arrayBuffer::list2arrayBuffer(argument, argLen); 
     278  TCHAR *msgBuffer = new TCHAR[buf_len+1]; 
     279  TCHAR *perfBuffer = new TCHAR[buf_len+1]; 
     280  msgBuffer[0] = 0; 
     281  perfBuffer[0] = 0; 
     282  NSCAPI::nagiosReturn retC = InjectCommandRAW(command, argLen, aBuffer, msgBuffer, buf_len, perfBuffer, buf_len); 
     283  switch (retC) { 
     284    case NSCAPI::returnIgnored: 
     285      NSC_LOG_MESSAGE_STD(_T("No handler for command '") + command + _T("'.")); 
     286      break; 
     287    case NSCAPI::returnInvalidBufferLen: 
     288      NSC_LOG_ERROR(_T("Inject buffer to small, increase the value of: string_length.")); 
     289      break; 
     290    case NSCAPI::returnOK: 
     291    case NSCAPI::returnCRIT: 
     292    case NSCAPI::returnWARN: 
     293    case NSCAPI::returnUNKNOWN: 
     294      message = msgBuffer; 
     295      perf = perfBuffer; 
     296      break; 
     297    default: 
     298      delete [] msgBuffer; 
     299      delete [] perfBuffer; 
     300      throw NSCMHExcpetion(_T("Unknown return code when injecting: ") + std::wstring(command)); 
     301  } 
     302  delete [] msgBuffer; 
     303  delete [] perfBuffer; 
     304  return retC; 
     305} 
     306 
    259307/** 
    260308 * A wrapper around the InjetCommand that is simpler to use. 
  • include/NSCHelper.h

    rc0522cd ra34b229  
    135135  NSCAPI::nagiosReturn InjectCommandRAW(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen); 
    136136  NSCAPI::nagiosReturn InjectCommand(const TCHAR* command, const unsigned int argLen, TCHAR **argument, std::wstring & message, std::wstring & perf); 
     137  NSCAPI::nagiosReturn InjectCommand(const TCHAR* command, std::list<std::wstring> argument, std::wstring & message, std::wstring & perf); 
    137138  NSCAPI::nagiosReturn InjectSplitAndCommand(const TCHAR* command, TCHAR* buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf); 
    138139  NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
  • include/NTService.h

    rbc97cd8 ra34b229  
    139139        OutputDebugString(_T("Not >w2k so sessiong messages disabled...")); 
    140140    } 
    141     ssStatus.dwControlsAccepted = dwControlsAccepted; 
    142141    if (sshStatusHandle == 0) 
    143142      throw service_exception(_T("Failed to register service: ") + error::lookup::last_error()); 
     
    146145    ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 
    147146    ssStatus.dwServiceSpecificExitCode = 0; 
     147    ssStatus.dwControlsAccepted = dwControlsAccepted; 
    148148 
    149149    // report the status to the service control manager. 
     
    153153    } 
    154154    try { 
    155       OutputDebugString(_T("Attempting to start service...")); 
     155      OutputDebugString(std::wstring(_T("Attempting to start service with: ") + strEx::ihextos(dwControlsAccepted)).c_str()); 
    156156      ServiceStart(dwArgc, lpszArgv); 
    157157    } catch (...) { 
  • include/config.h

    rdc59b0e ra34b229  
    161161#define EVENTLOG_SYNTAX _T("syntax") 
    162162#define EVENTLOG_SYNTAX_DEFAULT _T("") 
     163#define EVENTLOG_BUFFER _T("buffer_size") 
     164#define EVENTLOG_BUFFER_DEFAULT 1024*64 
    163165 
    164166#define NSCA_AGENT_SECTION_TITLE _T("NSCA Agent") 
  • include/nsclient_session.hpp

    rdc59b0e ra34b229  
    650650      remote_channel::local_message_type msg; 
    651651      msg.command = message_inject; 
    652       error(__FILEW__, __LINE__, _T("splitter") + strEx::ctos(splitter)); 
    653       error(__FILEW__, __LINE__, _T("splitter") + splitter); 
    654652       
    655653      msg.arguments.push_back(command); 
     
    658656      msg.arguments.push_back(escape?_T("1"):_T("0")); 
    659657 
    660       error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 
    661       error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 
    662       error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 
     658      //error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 
     659      //error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 
     660      //error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 
    663661 
    664662      unsigned int msg_id = send_server(msg); 
     
    779777        if (msg.arguments.size() == 4) { 
    780778          try { 
    781             error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 
    782             error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 
    783             error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 
     779            //error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 
     780            //error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 
     781            //error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 
    784782            ret = handler_->session_inject(msg.arguments[0], msg.arguments[1], strEx::stoc(msg.arguments[2]), msg.arguments[3]==_T("1"), message, perf); 
    785783          } catch (...) { 
  • include/sysinfo.h

    rbc97cd8 ra34b229  
    5959  } 
    6060  inline bool isAboveXP(const OSVERSIONINFO &osVersion) { 
    61     if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion>=4)&&(osVersion.dwMinorVersion>=1)) 
     61    if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion==4)&&(osVersion.dwMinorVersion>=1)) 
     62      return true; 
     63    if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion>4)) 
    6264      return true; 
    6365    return false; 
  • modules/CheckEventLog/CheckEventLog.cpp

    rdc59b0e ra34b229  
    4949    debug_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_DEBUG, EVENTLOG_DEBUG_DEFAULT)==1; 
    5050    syntax_ = NSCModuleHelper::getSettingsString(EVENTLOG_SECTION_TITLE, EVENTLOG_SYNTAX, EVENTLOG_SYNTAX_DEFAULT); 
     51    buffer_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT); 
    5152  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
    5253    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     
    387388      else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filteritem_type(filtermode, filter)); } 
    388389 
    389  
    390 #define BUFFER_SIZE 1024*64 
     390struct event_log_buffer { 
     391  BYTE *bBuffer; 
     392  DWORD bufferSize_; 
     393  event_log_buffer(DWORD bufferSize) : bufferSize_(bufferSize) { 
     394    bBuffer = new BYTE[bufferSize+10]; 
     395  } 
     396  ~event_log_buffer() { 
     397    delete [] bBuffer; 
     398  } 
     399  EVENTLOGRECORD* getBufferUnsafe() { 
     400    return reinterpret_cast<EVENTLOGRECORD*>(bBuffer); 
     401  } 
     402  DWORD getBufferSize() { 
     403    return bufferSize_; 
     404  } 
     405}; 
     406 
    391407NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
    392408  if (command != _T("CheckEventLog")) 
     
    414430  const int filter_normal = 3; 
    415431  const int filter_compat = 3; 
     432  event_log_buffer buffer(buffer_); 
    416433 
    417434  try { 
     
    486503    //DWORD dwThisRecord; 
    487504    DWORD dwRead, dwNeeded; 
    488     EVENTLOGRECORD *pevlr; 
    489     BYTE bBuffer[BUFFER_SIZE];  
    490  
    491     pevlr = reinterpret_cast<EVENTLOGRECORD*>(&bBuffer); 
     505 
    492506 
    493507    __time64_t ltime; 
     
    497511 
    498512    while (ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, 
    499       0, pevlr, BUFFER_SIZE, &dwRead, &dwNeeded)) 
     513      0, buffer.getBufferUnsafe(), buffer.getBufferSize(), &dwRead, &dwNeeded)) 
    500514    { 
    501       while (dwRead > 0)  
    502       {  
     515      EVENTLOGRECORD *pevlr = buffer.getBufferUnsafe();  
     516      while (dwRead > 0) {  
    503517        //bool bMatch = bFilterAll; 
    504518        bool bMatch = !bFilterIn; 
     
    590604        } 
    591605        dwRead -= pevlr->Length;  
    592         pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length);  
     606        pevlr = reinterpret_cast<EVENTLOGRECORD*>((LPBYTE)pevlr + pevlr->Length);  
    593607      }  
    594       pevlr = (EVENTLOGRECORD *) &bBuffer;  
    595     }  
     608    } 
     609    DWORD err = GetLastError(); 
     610    if (err == ERROR_INSUFFICIENT_BUFFER) { 
     611      NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small (set the value of ") + EVENTLOG_BUFFER + _T("): ") + error::lookup::last_error(err)); 
     612      message = std::wstring(_T("EvenlogBuffer is too small (set the value of ")) + EVENTLOG_BUFFER + _T("): ") + error::lookup::last_error(err); 
     613      return NSCAPI::returnUNKNOWN; 
     614    } else if (err != ERROR_HANDLE_EOF) { 
     615      NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err)); 
     616      message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); 
     617      return NSCAPI::returnUNKNOWN; 
     618    } 
    596619    CloseEventLog(hLog); 
    597620    for (uniq_eventlog_map::const_iterator cit = uniq_records.begin(); cit != uniq_records.end(); ++cit) { 
  • modules/CheckEventLog/CheckEventLog.h

    r8c7d67f ra34b229  
    3131  bool debug_; 
    3232  std::wstring syntax_; 
     33  DWORD buffer_; 
    3334 
    3435public: 
  • modules/CheckSystem/PDHCollector.cpp

    rdd02c15 ra34b229  
    2929  std::wstring s = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU_BUFFER_TIME, C_SYSTEM_CPU_BUFFER_TIME_DEFAULT); 
    3030  unsigned int i = strEx::stoui_as_time(s, checkIntervall_*100); 
    31   cpu.resize(i/(checkIntervall_*100)); 
     31  cpu.resize(i/(checkIntervall_*100)+10); 
    3232} 
    3333 
  • modules/NSClientListener/NSClientListener.cpp

    rdc59b0e ra34b229  
    138138  return false; 
    139139} 
    140  
     140void split_to_list(std::list<std::wstring> &list, std::wstring str) { 
     141  strEx::splitList add = strEx::splitEx(str, _T("&")); 
     142  list.insert(list.begin(), add.begin(), add.end()); 
     143} 
    141144std::string NSClientListener::parseRequest(std::string str_buffer)  { 
    142145  std::wstring buffer = strEx::string_to_wstring(str_buffer); 
     
    168171  NSC_DEBUG_MSG_STD(_T("Data: ") + cmd.second); 
    169172 
     173  std::list<std::wstring> args; 
    170174 
    171175  // prefix various commands 
     
    173177    case REQ_CPULOAD: 
    174178      cmd.first = _T("checkCPU"); 
    175       cmd.second += _T("&nsclient"); 
     179      split_to_list(args, cmd.second); 
     180      args.push_back(_T("nsclient")); 
    176181      break; 
    177182    case REQ_UPTIME: 
    178183      cmd.first = _T("checkUpTime"); 
    179       cmd.second = _T("nsclient"); 
     184      args.push_back(_T("nsclient")); 
    180185      break; 
    181186    case REQ_USEDDISKSPACE: 
    182187      cmd.first = _T("CheckDriveSize"); 
    183       cmd.second += _T("&nsclient"); 
     188      split_to_list(args, cmd.second); 
     189      args.push_back(_T("nsclient")); 
    184190      break; 
    185191    case REQ_CLIENTVERSION: 
     
    192198    case REQ_SERVICESTATE: 
    193199      cmd.first = _T("checkServiceState"); 
    194       cmd.second += _T("&nsclient"); 
     200      split_to_list(args, cmd.second); 
     201      args.push_back(_T("nsclient")); 
    195202      break; 
    196203    case REQ_PROCSTATE: 
    197204      cmd.first = _T("checkProcState"); 
    198       cmd.second += _T("&nsclient"); 
     205      split_to_list(args, cmd.second); 
     206      args.push_back(_T("nsclient")); 
    199207      break; 
    200208    case REQ_MEMUSE: 
    201209      cmd.first = _T("checkMem"); 
    202       cmd.second = _T("nsclient"); 
     210      args.push_back(_T("nsclient")); 
    203211      break; 
    204212    case REQ_COUNTER: 
    205213      cmd.first = _T("checkCounter"); 
    206       cmd.second = _T("Counter=") + cmd.second + _T("&nsclient"); 
     214      args.push_back(_T("Counter=") + cmd.second); 
     215      args.push_back(_T("nsclient")); 
    207216      break; 
    208217    case REQ_FILEAGE: 
    209218      cmd.first = _T("getFileAge"); 
    210       cmd.second = _T("path=") + cmd.second; 
    211       break; 
     219      args.push_back(_T("path=") + cmd.second); 
     220      break; 
     221    default: 
     222      split_to_list(args, cmd.second); 
    212223  } 
    213224 
    214225  std::wstring message, perf; 
    215   NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second.c_str(), '&', message, perf); 
     226  NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectCommand(cmd.first.c_str(), args, message, perf); 
    216227  if (!NSCHelper::isNagiosReturnCode(ret)) { 
    217228    if (message.empty()) 
Note: See TracChangeset for help on using the changeset viewer.