Changeset d6194a0 in nscp


Ignore:
Timestamp:
07/27/12 07:06:17 (10 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.1, 0.4.2
Children:
724a835
Parents:
c327ce5
Message:
  • Fixed some memoryelaks in LUAModule
  • Extracted the test functions into a library
  • Added lib folder as search path for lua scripts
  • Tweaks and improvments all around
  • Improved the build scripts a lot making files work on linux (still need to manually build the targets though)
  • Added support for LUAScripts to linux enviornments (still a few warnings to sort out)
  • Improved lua unit test scripts
  • Added support for using member functions as handlers in Lua scripts
Files:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r53be5c8 rd6194a0  
    5757  ${LUA_DIR}/src 
    5858  /usr/include/lua 
    59 ) 
     59  /usr/include/lua5.1 
     60) 
     61FIND_PROGRAM(PROTOC_GEN_LUA_FOUND 
     62  NAMES protoc-gen-lua 
     63  PATHS  
     64    /usr/local/bin/ 
     65    /usr/bin/ 
     66) 
     67 
    6068IF (LUA_INCLUE_DIR) 
    6169  message(STATUS "Found lua in ${LUA_INCLUE_DIR}") 
    62   SET(HAVE_LUA TRUE PARENT_SCOPE) 
    6370  SET(HAVE_LUA TRUE) 
    6471  SET(LUA_SOURCE_DIR ${LUA_INCLUE_DIR}) 
  • build/cmake/GoogleProtoBuf.cmake

    rc327ce5 rd6194a0  
    3838  LIST(APPEND ARGS --python_out ${PROJECT_BINARY_DIR}/scripts/python/lib) 
    3939  IF(PROTOC_GEN_LUA_FOUND) 
    40   SET(PROTOC_GEN_LUA_EXTRA --plugin=protoc-gen-lua=${PROTOC_GEN_LUA_CMD}) 
     40  IF(PROTOC_GEN_LUA_CMD) 
     41    SET(PROTOC_GEN_LUA_EXTRA --plugin=protoc-gen-lua=${PROTOC_GEN_LUA_CMD}) 
     42  ENDIF(PROTOC_GEN_LUA_CMD) 
    4143  LIST(APPEND ARGS --lua_out ${PROJECT_BINARY_DIR}/libs/lua_pb ${PROTOC_GEN_LUA_EXTRA}) 
    4244  ENDIF(PROTOC_GEN_LUA_FOUND) 
  • build/cmake/functions.cmake

    rc327ce5 rd6194a0  
    2020 
    2121 
    22 MACRO(copy_single_file target, src destDir) 
     22MACRO(copy_single_file _TARGET_LIST src destDir) 
    2323  GET_FILENAME_COMPONENT(TARGET ${src} NAME) 
    2424  SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/${src}) 
     
    2828    SET(target_file ${CMAKE_BINARY_DIR}/${destDir}/${TARGET}) 
    2929  ENDIF(${destDir} STREQUAL ".") 
    30   #message(STATUS " - Copying ${source_file} to ${target_file}...") 
     30  message(STATUS " - Copying ${source_file} to ${target_file}...") 
    3131  ADD_CUSTOM_COMMAND( 
    3232    OUTPUT ${target_file} 
     
    3636    DEPENDS ${source_file} 
    3737    ) 
    38   LIST(APPEND ALL_FILES ${target_file}) 
     38  SET(${_TARGET_LIST} ${${_TARGET_LIST}} ${target_file}) 
    3939ENDMACRO(copy_single_file) 
    4040 
  • changelog

    rc327ce5 rd6194a0  
    44 * Fix dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-07-26 MickeM 
     8 * Fixed some memoryelaks in LUAModule 
     9 * Extracted the test functions into a library 
     10 * Added lib folder as search path for lua scripts 
     11 * Tweaks and improvments all around 
     12 * Improved the build scripts a lot making files work on linux (still need to manually build the targets though) 
     13 
     142012-07-23 MickeM 
     15 * Added support for LUAScripts to linux enviornments (still a few warnings to sort out) 
     16 * Improved lua unit test scripts 
     17 * Added support for using member functions as handlers in Lua scripts 
    618 
    7192012-07-17 MickeM 
  • files/CMakeLists.txt

    rc327ce5 rd6194a0  
    22 
    33SET(ALL_FILES) 
    4 copy_single_file(copy_files license.txt .) 
    5 copy_single_file(copy_files nrpe_dh_512.pem security) 
    6 copy_single_file(copy_files old-settings.map .) 
    7 copy_single_file(copy_files counters.defs .) 
    8 copy_single_file(copy_files nsclient.dist .) 
    9 copy_single_file(copy_files ../changelog .) 
     4copy_single_file(ALL_FILES license.txt .) 
     5copy_single_file(ALL_FILES nrpe_dh_512.pem security) 
     6copy_single_file(ALL_FILES old-settings.map .) 
     7copy_single_file(ALL_FILES counters.defs .) 
     8copy_single_file(ALL_FILES nsclient.dist .) 
     9copy_single_file(ALL_FILES ../changelog .) 
    1010 
    1111ADD_CUSTOM_TARGET(copy_files DEPENDS ${ALL_FILES}) 
  • helpers/installer-dlls/main_dll/main_dll.cpp

    r440c0cb rd6194a0  
    4646 
    4747 
    48   void do_log(const std::string &data) { 
     48  void do_log(const std::string data) { 
    4949    std::wstring str = utf8::cvt<std::wstring>(data); 
    5050    if (str.empty()) 
  • include/nrpe/packet.hpp

    ra48fd4c rd6194a0  
    172172      unsigned int packet_length = nrpe::length::get_packet_length(payload_length_); 
    173173      tmpBuffer = new char[packet_length+1]; 
     174      memset(tmpBuffer, 0, packet_length+1); 
    174175      //TODO readd this ZeroMemory(tmpBuffer, getBufferLength()+1); 
    175176      nrpe::data::packet *p = reinterpret_cast<nrpe::data::packet*>(tmpBuffer); 
  • include/nsca/client/nsca_client_protocol.hpp

    rc327ce5 rd6194a0  
    3737        sent_request, 
    3838        has_request, 
    39         done, 
     39        done 
    4040      }; 
    4141      state current_state_; 
  • include/nsclient/base_logger_impl.hpp

    r6533c1a rd6194a0  
    6666      } 
    6767 
    68       virtual void do_log(const std::string &data) = 0; 
     68      virtual void do_log(const std::string data) = 0; 
    6969      virtual void configure() = 0; 
    7070      virtual bool shutdown() { 
  • include/settings/client/settings_client.hpp

    ra48fd4c rd6194a0  
    513513      settings_keys_easy_init(std::wstring path, settings_registry* owner_) : owner(owner_), path_(path) {} 
    514514      settings_keys_easy_init(std::wstring path, std::wstring parent, settings_registry* owner_) : owner(owner_), path_(path), parent_(parent) {} 
     515      virtual ~settings_keys_easy_init() {} 
    515516 
    516517      settings_keys_easy_init& operator()(std::wstring path, std::wstring key_name, boost::shared_ptr<key_interface> value, std::wstring title, std::wstring description, bool advanced = false) { 
     
    643644    public: 
    644645      settings_registry(settings_impl_interface_ptr core) : core_(core) {} 
     646      virtual ~settings_registry() {} 
    645647      void add(boost::shared_ptr<key_info> info) { 
    646648        keys_.push_back(info); 
  • include/socket/client.hpp

    ra48fd4c rd6194a0  
    350350        , dh_key_(dh_key) 
    351351      {} 
     352      virtual ~client_handler() {} 
    352353 
    353354      bool use_ssl() { return ssl_; } 
  • libs/cryptopp/CMakeLists.txt

    rc327ce5 rd6194a0  
    22 
    33IF (HAVE_CRYPTOPP) 
    4   message(STATUS "Found CACHED Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 
     4  MESSAGE(STATUS "Found CACHED Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 
    55ELSE (HAVE_CRYPTOPP) 
    66  FIND_PATH(CRYPTOPP_SOURCE_DIR cryptlib.h ${CRYPTOPP_DIR}) 
    77   
    88  IF (CRYPTOPP_SOURCE_DIR) 
    9     message(STATUS "Found Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 
     9    MESSAGE(STATUS "Found Crypto++ in ${CRYPTOPP_SOURCE_DIR}") 
    1010    SET(HAVE_CRYPTOPP TRUE PARENT_SCOPE) 
    1111    SET(HAVE_CRYPTOPP TRUE) 
    1212  ELSE (CRYPTOPP_SOURCE_DIR) 
    13     message(STATUS "Crypto++ was not found in ${CRYPTOPP_SOURCE_DIR} (CRYPTOPP_SOURCE_DIR)") 
     13    MESSAGE(STATUS "Crypto++ was not found in ${CRYPTOPP_SOURCE_DIR} (CRYPTOPP_SOURCE_DIR)") 
    1414  ENDIF (CRYPTOPP_SOURCE_DIR) 
    1515 
    1616ENDIF (HAVE_CRYPTOPP) 
    1717 
     18SET(CRYPTOS des rijndael cast tea 3way blowfish twofish rc2 arc4 serpent gost ) 
    1819 
    1920IF (HAVE_CRYPTOPP) 
    20   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/des.cpp) 
    21   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rijndael.cpp) 
    22   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cast.cpp) 
    23   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/tea.cpp) 
    24   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/3way.cpp) 
    25   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/blowfish.cpp) 
    26   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/twofish.cpp) 
    27   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rc2.cpp) 
    28   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/arc4.cpp) 
    29   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/serpent.cpp) 
    30   LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/gost.cpp) 
    31    
     21 
     22  FOREACH(CRYPTO ${CRYPTOS}) 
     23    LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/${CRYPTO}.cpp) 
     24    IF (WIN32) 
     25      LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/${CRYPTO}.h) 
     26    ENDIF (WIN32) 
     27  ENDFOREACH(CRYPTO ${CRYPTOS}) 
     28 
     29 
    3230  LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/filters.cpp) 
    3331  LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/osrng.cpp) 
     
    3533  LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cryptlib.cpp) 
    3634  LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/misc.cpp) 
    37    
    3835  LIST(APPEND cryptopp_SOURCES cryptopp.cpp) 
     36 
    3937  IF (WIN32) 
    40     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/des.h) 
    41     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/aes.h) 
    42     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cast.h) 
    43     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/tea.h) 
    44     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/3way.h) 
    45     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/blowfish.h) 
    46     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/twofish.h) 
    47     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/rc2.h) 
    48     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/arc4.h) 
    49     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/serpent.h) 
    50     LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/gost.h) 
    51      
    5238    LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/filters.h) 
    5339    LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/osrng.h) 
     
    5541    LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/cryptlib.h) 
    5642    LIST(APPEND cryptopp_SOURCES ${CRYPTOPP_SOURCE_DIR}/misc.h) 
    57      
    5843    LIST(APPEND cryptopp_SOURCES ${NSCP_INCLUDEDIR}/cryptopp/cryptopp.hpp) 
     44 
    5945  ENDIF (WIN32) 
    60   message(STATUS "Using Crypto++ from ${CRYPTOPP_SOURCE_DIR}") 
    6146  IF (MSVC) 
    62   # ADD_DEFINITIONS (-DCRYPTOPP_GENERATE_X64_MASM) 
    63   # ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 
    64   # ADD_DEFINITIONS (-DNDEBUG) 
     47    # ADD_DEFINITIONS (-DCRYPTOPP_GENERATE_X64_MASM) 
     48    # ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 
     49    # ADD_DEFINITIONS (-DNDEBUG) 
    6550    CMAKE_POLICY(SET CMP0008 NEW) 
    6651    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 
     52       
     53    IF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 
     54      string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 
     55    ENDIF(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 
    6756  ENDIF (MSVC) 
    6857 
     
    8574  #SET_TARGET_PROPERTIES(cryptopp PROPERTIES FOLDER "libraries") 
    8675  #IF(NOT WIN32) 
     76  MESSAGE(STATUS "===> ${CMAKE_CXX_FLAGS}") 
    8777  ADD_LIBRARY(cryptopp_static STATIC  ${cryptopp_SOURCES}) 
    8878  SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES FOLDER "libraries") 
     
    9888 
    9989  IF(APPLE) 
    100      #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
    101      SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
     90    #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
     91    SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
    10292  ELSEIF(UNIX AND NOT APPLE) 
    103     #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    104     SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
     93    #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
     94    SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    10595  ELSEIF(WIN32) 
    106     IF(NOT MSVC) 
    107     #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
    108     SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
    109     ENDIF(NOT MSVC) 
     96    IF(NOT MSVC) 
     97      #SET_TARGET_PROPERTIES(cryptopp PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
     98      SET_TARGET_PROPERTIES(cryptopp_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
     99    ENDIF(NOT MSVC) 
    110100  ENDIF(APPLE) 
    111101ENDIF (HAVE_CRYPTOPP) 
  • libs/lua/CMakeLists.txt

    r53be5c8 rd6194a0  
    22 
    33IF (HAVE_LUA) 
    4   SET(LUA_SOURCE_DIR ${LUA_INCLUE_DIR}) 
    5   #FILE (GLOB lua_SOURCES "${LUA_SOURCE_DIR}/*.c") 
     4 
     5 
     6  FIND_LIBRARY(LUA_LIB 
     7    NAMES liblua5.1 lua5.1 lua 
     8  ) 
     9  IF(LUA_LIB) 
     10    MESSAGE(STATUS "Found existing LUA lib: ${LUA_LIB}") 
     11  ELSE(LUA_LIB) 
     12    FIND_PATH(LUA_SOURCE_DIR lapi.c 
     13      ${LUA_INCLUE_DIR} 
     14      ${LUA_INCLUE_DIR}/src 
     15      ${LUA_DIR} 
     16      ${LUA_DIR}/src 
     17    ) 
    618   
    7   SET(lua_SOURCES 
    8     ${LUA_SOURCE_DIR}/lapi.c 
    9     ${LUA_SOURCE_DIR}/lauxlib.c 
    10     ${LUA_SOURCE_DIR}/lbaselib.c 
    11     ${LUA_SOURCE_DIR}/lcode.c 
    12     ${LUA_SOURCE_DIR}/ldblib.c 
    13     ${LUA_SOURCE_DIR}/ldebug.c 
    14     ${LUA_SOURCE_DIR}/ldo.c 
    15     ${LUA_SOURCE_DIR}/ldump.c 
    16     ${LUA_SOURCE_DIR}/lfunc.c 
    17     ${LUA_SOURCE_DIR}/lgc.c 
    18     ${LUA_SOURCE_DIR}/linit.c 
    19     ${LUA_SOURCE_DIR}/liolib.c 
    20     ${LUA_SOURCE_DIR}/llex.c 
    21     ${LUA_SOURCE_DIR}/lmathlib.c 
    22     ${LUA_SOURCE_DIR}/lmem.c 
    23     ${LUA_SOURCE_DIR}/loadlib.c 
    24     ${LUA_SOURCE_DIR}/lobject.c 
    25     ${LUA_SOURCE_DIR}/lopcodes.c 
    26     ${LUA_SOURCE_DIR}/loslib.c 
    27     ${LUA_SOURCE_DIR}/lparser.c 
    28     ${LUA_SOURCE_DIR}/lstate.c 
    29     ${LUA_SOURCE_DIR}/lstring.c 
    30     ${LUA_SOURCE_DIR}/lstrlib.c 
    31     ${LUA_SOURCE_DIR}/ltable.c 
    32     ${LUA_SOURCE_DIR}/ltablib.c 
    33     ${LUA_SOURCE_DIR}/ltm.c 
    34     ${LUA_SOURCE_DIR}/lundump.c 
    35     ${LUA_SOURCE_DIR}/lvm.c 
    36     ${LUA_SOURCE_DIR}/lzio.c 
    37   ) 
    38    
    39   FILE (GLOB lua_HEADERS "${LUA_SOURCE_DIR}/*.h") 
    40   IF (MSVC) 
    41     CMAKE_POLICY(SET CMP0008 NEW) 
    42     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 
    43   ENDIF (MSVC) 
     19    MESSAGE(STATUS "* * * * * NOT Found LUA sources (will build library): ${LUA_SOURCE_DIR}") 
     20     
     21    SET(lua_SOURCES 
     22      ${LUA_SOURCE_DIR}/lapi.c 
     23      ${LUA_SOURCE_DIR}/lauxlib.c 
     24      ${LUA_SOURCE_DIR}/lbaselib.c 
     25      ${LUA_SOURCE_DIR}/lcode.c 
     26      ${LUA_SOURCE_DIR}/ldblib.c 
     27      ${LUA_SOURCE_DIR}/ldebug.c 
     28      ${LUA_SOURCE_DIR}/ldo.c 
     29      ${LUA_SOURCE_DIR}/ldump.c 
     30      ${LUA_SOURCE_DIR}/lfunc.c 
     31      ${LUA_SOURCE_DIR}/lgc.c 
     32      ${LUA_SOURCE_DIR}/linit.c 
     33      ${LUA_SOURCE_DIR}/liolib.c 
     34      ${LUA_SOURCE_DIR}/llex.c 
     35      ${LUA_SOURCE_DIR}/lmathlib.c 
     36      ${LUA_SOURCE_DIR}/lmem.c 
     37      ${LUA_SOURCE_DIR}/loadlib.c 
     38      ${LUA_SOURCE_DIR}/lobject.c 
     39      ${LUA_SOURCE_DIR}/lopcodes.c 
     40      ${LUA_SOURCE_DIR}/loslib.c 
     41      ${LUA_SOURCE_DIR}/lparser.c 
     42      ${LUA_SOURCE_DIR}/lstate.c 
     43      ${LUA_SOURCE_DIR}/lstring.c 
     44      ${LUA_SOURCE_DIR}/lstrlib.c 
     45      ${LUA_SOURCE_DIR}/ltable.c 
     46      ${LUA_SOURCE_DIR}/ltablib.c 
     47      ${LUA_SOURCE_DIR}/ltm.c 
     48      ${LUA_SOURCE_DIR}/lundump.c 
     49      ${LUA_SOURCE_DIR}/lvm.c 
     50      ${LUA_SOURCE_DIR}/lzio.c 
     51    ) 
     52     
     53    FILE (GLOB lua_HEADERS "${LUA_SOURCE_DIR}/*.h") 
     54    IF (MSVC) 
     55      CMAKE_POLICY(SET CMP0008 NEW) 
     56      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi") 
     57    ENDIF (MSVC) 
    4458 
    45   IF (WIN32) 
    46     ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 
    47     SET(lua_DEFINES -DCRYPTOPP_DISABLE_ASM) 
    48   ENDIF (WIN32) 
     59    IF (WIN32) 
     60      ADD_DEFINITIONS (-DCRYPTOPP_DISABLE_ASM) 
     61      SET(lua_DEFINES -DCRYPTOPP_DISABLE_ASM) 
     62    ENDIF (WIN32) 
    4963 
    50   ADD_LIBRARY(lua SHARED ${lua_SOURCES}) 
    51   SET_TARGET_PROPERTIES(lua PROPERTIES FOLDER "libraries") 
    52   ADD_LIBRARY(lua_static STATIC  ${lua_SOURCES}) 
    53   SET_TARGET_PROPERTIES(lua_static PROPERTIES FOLDER "libraries") 
     64    ADD_LIBRARY(lua SHARED ${lua_SOURCES}) 
     65    SET_TARGET_PROPERTIES(lua PROPERTIES FOLDER "libraries") 
     66    ADD_LIBRARY(lua_static STATIC  ${lua_SOURCES}) 
     67    SET_TARGET_PROPERTIES(lua_static PROPERTIES FOLDER "libraries") 
    5468 
    55   IF(APPLE) 
    56      SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
    57      SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
    58   ELSEIF(UNIX AND NOT APPLE) 
    59     SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    60     SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    61   ELSEIF(WIN32) 
    62     IF(NOT MSVC) 
    63     SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
    64     SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
    65     ENDIF(NOT MSVC) 
    66   ENDIF(APPLE) 
     69    IF(APPLE) 
     70       SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
     71       SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-w -DOSX  -DNDEBUG -finline-functions -O3 -DCRYPTOPP_DISABLE_ASM") 
     72    ELSEIF(UNIX AND NOT APPLE) 
     73      SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
     74      SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
     75    ELSEIF(WIN32) 
     76      IF(NOT MSVC) 
     77      SET_TARGET_PROPERTIES(lua PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
     78      SET_TARGET_PROPERTIES(lua_static PROPERTIES COMPILE_FLAGS "-mthreads -w -finline-functions -O3 -DNDEBUG -D__MINGW__ -DWIN32 -D_WIN32_WINNT=0x0501 -D_WIN32") 
     79      ENDIF(NOT MSVC) 
     80    ENDIF(APPLE) 
     81    SET(LUA_LIB lua_static) 
     82    SET(LUA_LIB lua_static PARENT_SCOPE) 
     83  ENDIF(LUA_LIB) 
    6784ENDIF (HAVE_LUA) 
  • libs/lua_pb/CMakeLists.txt

    rc327ce5 rd6194a0  
    3131    ${PROTOBUF_LIBRARY} 
    3232    protobuf 
    33     lua_static 
     33    ${LUA_LIB} 
    3434  ) 
    3535  target_link_libraries(lua_pb_static 
    3636    ${PROTOBUF_LIBRARY} 
    3737    protobuf 
    38     lua_static 
     38    ${LUA_LIB} 
    3939  ) 
    4040   
     
    4444  ELSEIF(UNIX AND NOT APPLE) 
    4545    SET_TARGET_PROPERTIES(lua_pb PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    46     SET_TARGET_PROPERTIES(lua_pb_static PROPERTIES COMPILE_FLAGS " -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
     46    SET_TARGET_PROPERTIES(lua_pb_static PROPERTIES COMPILE_FLAGS "-fPIC -w -pipe -DNDEBUG -DLINUX -finline-functions -O3") 
    4747  ELSEIF(WIN32) 
    4848    IF(NOT MSVC) 
  • modules/LUAScript/CMakeLists.txt

    r53be5c8 rd6194a0  
    4444  ${Boost_PROGRAM_OPTIONS_LIBRARY} 
    4545  ${NSCP_DEF_PLUGIN_LIB} 
    46   lua_static 
     46  ${LUA_LIB} 
    4747  ${LUA_PB} 
    4848) 
  • modules/LUAScript/LUAScript.cpp

    r53be5c8 rd6194a0  
    2626#include <strEx.h> 
    2727#include <time.h> 
    28 #include <filter_framework.hpp> 
     28//#include <filter_framework.hpp> 
    2929#include <error.hpp> 
    3030#include <file_helpers.hpp> 
     
    3333 
    3434 
    35 LUAScript::LUAScript() : registry(new lua_wrappers::lua_registry()) { 
     35LUAScript::LUAScript() { 
    3636} 
    3737LUAScript::~LUAScript() { 
     
    4545} 
    4646bool LUAScript::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
     47  registry.reset(new lua_wrappers::lua_registry()); 
    4748  //std::wstring appRoot = file_helpers::folders::get_local_appdata_folder(SZAPPNAME); 
    4849  try { 
     
    7273    BOOST_FOREACH(script_container &script, scripts_) { 
    7374      try { 
    74         instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, script.alias, script.script.string())); 
     75        instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, script.alias, root_.string(), script.script.string())); 
    7576      } catch (const lua_wrappers::LUAException &e) { 
    7677        NSC_LOG_ERROR_STD(_T("Could not load script ") + script.to_wstring() + _T(": ") + e.getMessage()); 
     
    135136 
    136137bool LUAScript::unloadModule() { 
     138  BOOST_FOREACH(script_instance &i, instances_) { 
     139    try { 
     140      i->unload(); 
     141    } catch (const lua_wrappers::LUAException &e) { 
     142      NSC_LOG_ERROR_STD(_T("Exception when unloading script: ") + i->get_wscript() + _T(": ") + e.getMessage()); 
     143    } catch (...) { 
     144      NSC_LOG_ERROR_STD(_T("Unhandeled Exception when unloading script: ") + i->get_wscript()); 
     145    } 
     146  } 
     147  if (registry) 
     148    registry->clear(); 
    137149  instances_.clear(); 
    138150  scripts_.clear(); 
     151  registry.reset(); 
    139152  return true; 
    140153} 
     
    210223 
    211224    try { 
    212       instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, _T("cmdline"), (*ofile).string())); 
     225      instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, _T("cmdline"), root_.string(), (*ofile).string())); 
    213226    } catch (const lua_wrappers::LUAException &e) { 
    214227      NSC_LOG_ERROR_STD(_T("Could not load script ") + _T(": ") + e.getMessage()); 
     
    253266 
    254267 
    255 NSC_WRAP_DLL(); 
    256 NSC_WRAPPERS_MAIN_DEF(LUAScript); 
    257 NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    258 NSC_WRAPPERS_HANDLE_CMD_DEF(); 
    259 NSC_WRAPPERS_CLI_DEF(); 
    260 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(); 
     268NSC_WRAP_DLL() 
     269NSC_WRAPPERS_MAIN_DEF(LUAScript) 
     270NSC_WRAPPERS_IGNORE_MSG_DEF() 
     271NSC_WRAPPERS_HANDLE_CMD_DEF() 
     272NSC_WRAPPERS_CLI_DEF() 
     273NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() 
  • modules/LUAScript/LUAScript.h

    r53be5c8 rd6194a0  
    1919*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
    2020***************************************************************************/ 
    21 NSC_WRAPPERS_MAIN(); 
    22 NSC_WRAPPERS_CLI(); 
    23 NSC_WRAPPERS_CHANNELS(); 
     21NSC_WRAPPERS_MAIN() 
     22NSC_WRAPPERS_CLI() 
     23NSC_WRAPPERS_CHANNELS() 
     24 
     25#include <boost/optional.hpp> 
    2426 
    2527//#include <config.h> 
    2628#include <strEx.h> 
    2729#include <utils.h> 
    28 #include <checkHelpers.hpp> 
    29 #include "script_wrapper.hpp" 
    30  
    31 #include <boost/optional.hpp> 
    32  
    3330#include <scripts/functions.hpp> 
    3431 
     32#include "script_wrapper.hpp" 
    3533 
    3634class LUAScript : public nscapi::impl::simple_command_line_exec, public nscapi::impl::simple_submission_handler, public nscapi::impl::simple_plugin { 
  • modules/LUAScript/lua_wrappers.cpp

    r53be5c8 rd6194a0  
    4949} 
    5050 
     51int lua_wrappers::lua_wrapper::gc(int what, int data) 
     52{ 
     53  return lua_gc(L, what, data); 
     54} 
     55 
    5156NSCAPI::nagiosReturn lua_wrappers::lua_registry::on_query(const wchar_t* command, const std::string &request, std::string &response) { 
    5257  function_map::iterator it = functions.find(command); 
     
    5661  lua_wrapper lua(prep_function(c)); 
    5762  if (c.simple) { 
     63    int args = 2; 
     64    if (c.obj_ref != 0) 
     65      args = 3; 
    5866    nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(command, request); 
    5967    lua.push_string(command); 
    6068    lua.push_array(data.args); 
    6169    std::wstring msg, perf; 
    62     if (lua.pcall(2, LUA_MULTRET, 0) != 0) { 
     70    if (lua.pcall(args, LUA_MULTRET, 0) != 0) { 
    6371      NSC_LOG_ERROR_STD(_T("Failed to handle command: ") + command + _T(": ") + lua.pop_string()); 
    6472      return NSCAPI::returnUNKNOWN; 
     
    7280    if (arg_count > 0) 
    7381      ret = lua.pop_code(); 
     82    lua.gc(LUA_GCCOLLECT, 0); 
    7483    nscapi::functions::create_simple_query_response(command, ret, msg, perf, response); 
    7584    return ret; 
    7685  } else { 
     86    int args = 2; 
     87    if (c.obj_ref != 0) 
     88      args = 3; 
    7789    lua.push_string(command); 
    7890    lua.push_raw_string(request); 
    79     if (lua.pcall(2, LUA_MULTRET, 0) != 0) { 
     91    if (lua.pcall(args, LUA_MULTRET, 0) != 0) { 
    8092      NSC_LOG_ERROR_STD(_T("Failed to handle command: ") + command + _T(": ") + lua.pop_string()); 
    8193      return NSCAPI::returnUNKNOWN; 
     
    8496    if (arg_count > 1) 
    8597      response = utf8::cvt<std::string>(lua.pop_string()); 
     98    lua.gc(LUA_GCCOLLECT, 0); 
    8699    if (arg_count > 0) 
    87100      return lua.pop_code(); 
     
    106119  if (arg_count > 1) 
    107120    result = lua.pop_string(); 
     121  lua.gc(LUA_GCCOLLECT, 0); 
    108122  if (arg_count > 0) 
    109123    return lua.pop_code(); 
     
    127141    return NSCAPI::returnUNKNOWN; 
    128142  } 
     143  lua.gc(LUA_GCCOLLECT, 0); 
    129144  if (lua.size() > 0) 
    130145    return lua.pop_code(); 
  • modules/LUAScript/lua_wrappers.hpp

    r53be5c8 rd6194a0  
    1111#include <list> 
    1212 
     13 
     14#include <boost/weak_ptr.hpp> 
    1315#include <NSCAPI.h> 
    1416#include <nscapi/nscapi_core_wrapper.hpp> 
     
    3133    } 
    3234    inline lua_State* get_state() const { 
    33       int i = lua_gettop(L); 
     35      lua_gettop(L); 
    3436      return L; 
    3537    } 
     
    4648    lua_wrapper(lua_State *L) : L(L) {} 
    4749 
     50 
     51    int append_path(const std::string &path) { 
     52      lua_getglobal(L, "package"); 
     53      lua_getfield(L, -1, "path"); 
     54      std::string cur_path = lua_tostring(L, -1); 
     55      cur_path.append(";"); 
     56      cur_path.append(path); 
     57      lua_pop(L, 1); 
     58      lua_pushstring(L, cur_path.c_str()); 
     59      lua_setfield(L, -2, "path"); 
     60      lua_pop(L, 1); 
     61      return 0; 
     62    } 
    4863    ////////////////////////////////////////////////////////////////////////// 
    4964    /// get_xxx 
     
    5974      return _T("<NOT_A_STRING>"); 
    6075    } 
     76    std::string get_sstring(int pos = -1) { 
     77      if (pos == -1) 
     78        pos = lua_gettop(L); 
     79      if (pos == 0) 
     80        return "<EMPTY>"; 
     81      if (is_string(pos)) 
     82        return lua_tostring(L, pos); 
     83      if (is_number(pos)) 
     84        return strEx::s::xtos(lua_tonumber(L, pos)); 
     85      return "<NOT_A_STRING>"; 
     86    } 
    6187    bool get_string(std::wstring &str, int pos = -1) { 
    6288      if (pos == -1) 
     
    6894      else if (is_number(pos)) 
    6995        str = strEx::itos(lua_tonumber(L, pos)); 
     96      else 
     97        return false; 
     98      return true; 
     99    } 
     100    bool get_string(std::string &str, int pos = -1) { 
     101      if (pos == -1) 
     102        pos = lua_gettop(L); 
     103      if (pos == 0) 
     104        return false; 
     105      if (is_string(pos)) 
     106        str = lua_tostring(L, pos); 
     107      else if (is_number(pos)) 
     108        str = strEx::s::xtos(lua_tonumber(L, pos)); 
    70109      else 
    71110        return false; 
     
    109148    ////////////////////////////////////////////////////////////////////////// 
    110149    /// pop_xxx 
    111     boolean pop_boolean() { 
     150    bool pop_boolean() { 
    112151      int pos = lua_gettop(L); 
    113152      if (pos == 0) 
     
    126165      return ret; 
    127166    } 
     167    std::string pop_sstring() { 
     168      std::string ret; 
     169      int top = lua_gettop(L); 
     170      if (top == 0) 
     171        return "<EMPTY>"; 
     172      ret = get_sstring(top); 
     173      pop(); 
     174      return ret; 
     175    } 
    128176    bool pop_string(std::wstring &str) { 
    129177      int top = lua_gettop(L); 
     
    135183      return true; 
    136184    } 
    137     bool pop_function(int &funref) { 
     185    bool pop_function_ref(int &funref) { 
    138186      int top = lua_gettop(L); 
    139187      if (top == 0) 
     
    141189      if (!is_function(top)) 
    142190        return false; 
     191      funref = luaL_ref(L, LUA_REGISTRYINDEX); 
     192      if (funref == 0) 
     193        return false; 
     194      return true; 
     195    } 
     196    bool pop_instance_ref(int &funref) { 
     197      int top = lua_gettop(L); 
     198      if (top == 0) 
     199        return false; 
     200//      if (!is_function(top)) 
     201//        return false; 
    143202      funref = luaL_ref(L, LUA_REGISTRYINDEX); 
    144203      if (funref == 0) 
     
    263322      lua_pushlstring(L, s.c_str(), s.size()); 
    264323    } 
    265     void push_array(std::list<std::wstring> &arr) { 
     324    void push_array(const std::list<std::wstring> &arr) { 
    266325      lua_createtable(L, 0, arr.size()); 
    267326      int i=0; 
     
    331390      return luaL_checkstring(L, pos); 
    332391    } 
     392    /* 
    333393    std::wstring inline wstring(int pos) { 
    334394      return utf8::cvt<std::wstring>(string(pos)); 
    335395    } 
     396    */ 
    336397 
    337398    std::list<std::wstring> inline checkarray(int pos) { 
     
    340401    } 
    341402 
    342     boolean inline checkbool(int pos) { 
     403    bool inline checkbool(int pos) { 
    343404      return lua_toboolean(L, pos); 
    344405    } 
     
    349410      return luaL_checkint(L, pos); 
    350411    } 
     412    int gc(int what, int data); 
    351413  }; 
    352414 
     
    390452      , alias(alias) 
    391453      , script(script) 
    392     {} 
     454    { 
     455      std::wcout << _T("+++"); 
     456    } 
     457 
     458    virtual ~lua_script_instance() { 
     459      std::wcout << _T("---"); 
     460    } 
    393461 
    394462    int get_plugin_id() const { 
     
    412480  }; 
    413481 
    414   class lua_registry { 
     482  class lua_registry : boost::noncopyable { 
    415483    struct function_container { 
    416484      boost::shared_ptr<lua_script_instance> instance; 
    417485      int func_ref; 
     486      int obj_ref; 
    418487      bool simple; 
    419488    }; 
     
    427496      lua_State *L = c.instance->get_lua_state(); 
    428497      lua_rawgeti(L, LUA_REGISTRYINDEX, c.func_ref); 
     498      if (c.obj_ref != 0) 
     499        lua_rawgeti(L, LUA_REGISTRYINDEX, c.obj_ref); 
    429500      return L; 
    430501    } 
    431502  public: 
     503    lua_registry() {} 
     504    ~lua_registry() {} 
     505 
    432506 
    433507    NSCAPI::nagiosReturn on_query(const wchar_t* command, const std::string &request, std::string &response); 
     
    435509    NSCAPI::nagiosReturn on_submission(const std::wstring channel, const std::wstring source, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 
    436510 
    437     void register_query(const std::wstring &command, boost::shared_ptr<lua_script_instance> instance, int func_ref, bool simple = true) { 
     511    void register_query(const std::wstring &command, boost::shared_ptr<lua_script_instance> instance, int obj_ref, int func_ref, bool simple = true) { 
    438512      function_container c; 
    439513      c.func_ref = func_ref; 
     514      c.obj_ref = obj_ref; 
    440515      c.instance = instance; 
    441516      c.simple = simple; 
     
    476551  class lua_instance_manager { 
    477552  public: 
    478     typedef boost::shared_ptr<lua_script_instance> script_instance_type; 
     553    typedef boost::weak_ptr<lua_script_instance> script_instance_type; 
    479554    typedef std::vector<script_instance_type> script_map_type; 
    480555  private: 
    481556    static script_map_type scripts; 
    482557  public: 
     558    static void remove_script(script_instance_type script) { 
     559//      BOOST_FOREACH(script_instance_type &s, scripts) { 
     560//        if (s == script) { 
     561//          s.reset(); 
     562//        } 
     563//      } 
     564    } 
    483565    static void set_script(lua_State *L, script_instance_type script) { 
    484566      int index = 0; 
  • modules/LUAScript/script_wrapper.hpp

    rc327ce5 rd6194a0  
    2020  typedef lua_wrappers::lua_script_instance script_instance; 
    2121  typedef lua_wrappers::lua_instance_manager instance_manager; 
     22  typedef boost::shared_ptr<lua_wrappers::lua_script_instance> script_instance_type; 
    2223 
    2324 
     
    3031      instance = instance_manager::get_script(L); 
    3132    } 
    32     instance_manager::script_instance_type get_instance() { 
    33       if (!instance) 
     33    script_instance_type get_instance() { 
     34      script_instance_type inst = instance.lock(); 
     35      if (!inst) 
    3436        throw lua_wrappers::LUAException("Invalid instance"); 
    35       return instance; 
     37      return inst; 
    3638    } 
    3739  }; 
     
    9496      lua_wrappers::lua_wrapper lua(L); 
    9597      try { 
    96         int nargs = lua.size(); 
    97         std::wstring target = lua.wstring(1); 
    98         std::wstring command = lua.wstring(2); 
    99         std::list<std::wstring> arguments = lua.checkarray(3); 
     98        // simple_exec(target, command, arguments) 
     99        if (lua.size() > 1) 
     100          return lua.error("Incorrect syntax: simple_exec(target, command, arguments)"); 
     101        std::list<std::wstring> arguments = lua.pop_array(); 
     102        std::wstring command = lua.pop_string(); 
     103        std::wstring target = lua.pop_string(); 
    100104        std::list<std::wstring> result; 
    101105        NSCAPI::nagiosReturn ret = nscapi::core_helper::exec_simple_command(target, command, arguments, result); 
     
    115119      lua_wrappers::lua_wrapper lua(L); 
    116120      try { 
    117         int nargs = lua.size(); 
    118         std::wstring channel = lua.wstring(1); 
    119         std::wstring command = lua.wstring(2); 
    120         NSCAPI::nagiosReturn code = lua.get_code(3); 
    121         std::wstring message = lua.wstring(4); 
    122         std::wstring perf = lua.wstring(5); 
     121        // simple_submit(target, command, arguments) 
     122        if (lua.size() != 5) 
     123          return lua.error("Incorrect syntax: simple_submit(channel, command, code, message, perf)"); 
     124        std::wstring perf = lua.pop_string(); 
     125        std::wstring message = lua.pop_string(); 
     126        NSCAPI::nagiosReturn code = lua.pop_code(); 
     127        std::wstring command = lua.pop_string(); 
     128        std::wstring channel = lua.pop_string(); 
    123129        std::wstring result; 
    124130        NSCAPI::nagiosReturn ret = nscapi::core_helper::submit_simple_message(channel, command, code, message, perf, result); 
     
    143149        module = lua.pop_string(); 
    144150      get_instance()->get_core()->reload(module); 
     151      return 0; 
     152    } 
     153    int log(lua_State *L) { 
     154      lua_wrappers::lua_wrapper lua(L); 
     155      // log([level], message) 
     156      if (lua.size() > 2 || lua.size() < 1) 
     157        return lua.error("Incorrect syntax: log([<level>], <message>);"); 
     158      std::wstring level = _T("info"); 
     159      std::wstring message; 
     160      message = lua.pop_string(); 
     161      if (lua.size() > 0) 
     162        level = lua.pop_string(); 
     163      get_instance()->get_core()->log(nscapi::logging::parse(level), __FILE__, __LINE__, message); 
    145164      return 0; 
    146165    } 
     
    156175    { "submit", &core_wrapper::submit }, 
    157176    { "reload", &core_wrapper::reload }, 
     177    { "log", &core_wrapper::log }, 
    158178    { 0 } 
    159179  }; 
     
    169189    static const Luna<registry_wrapper>::RegType methods[]; 
    170190 
    171     boost::optional<int> read_registration(lua_wrapper &lua, std::wstring &command, int &funref, std::wstring &description) { 
     191    boost::optional<int> read_registration(lua_wrapper &lua, std::wstring &command, int &objref, int &funref, std::wstring &description) { 
     192      // ...(name, function, description) 
     193      // ...(name, instance, function, description) 
    172194      std::wstring funname; 
    173       if (lua.size() != 2 && lua.size() != 3) 
    174         return lua.error("Invalid number of arguments: " + strEx::s::xtos(lua.size()) + " expected 2 or 3"); 
    175       if (lua.size() > 2 && !lua.pop_string(description)) 
     195      int count = lua.size(); 
     196      if (count < 2 && count > 4) 
     197        return lua.error("Invalid number of arguments: " + strEx::s::xtos(lua.size()) + " expected 2-4 arguments"); 
     198      if (count > 2 && !lua.pop_string(description)) { 
    176199        return lua.error("Invalid description"); 
     200      } 
    177201      if (lua.pop_string(funname)) { 
    178202        lua.getglobal(funname); 
    179203      } 
    180       if (!lua.pop_function(funref)) 
     204      if (!lua.pop_function_ref(funref)) 
    181205        return lua.error("Invalid function"); 
     206      if (count > 3) { 
     207        if (!lua.pop_instance_ref(objref)) 
     208          return lua.error("Invalid object"); 
     209      } 
    182210      if (!lua.pop_string(command)) 
    183211        return lua.error("Invalid command"); 
     
    187215      // void = (cmd, function, desc) 
    188216      std::wstring command, description; 
    189       int funref = 0; 
    190       lua_wrapper lua(L); 
    191       boost::optional<int> error = read_registration(lua, command, funref, description); 
     217      int funref = 0, objref = 0; 
     218      lua_wrapper lua(L); 
     219      boost::optional<int> error = read_registration(lua, command, objref, funref, description); 
    192220      if (error) 
    193221        return *error; 
     
    196224        description = _T("Lua script: ") + command; 
    197225      get_instance()->get_core()->registerCommand(get_instance()->get_plugin_id(), command, description); 
    198       get_instance()->get_registry()->register_query(command, get_instance(), funref, false); 
     226      get_instance()->get_registry()->register_query(command, get_instance(), objref, funref, false); 
    199227      return 0; 
    200228    } 
     
    202230      // void = (cmd, function, desc) 
    203231      std::wstring command, description; 
    204       int funref = 0; 
    205       lua_wrapper lua(L); 
    206       boost::optional<int> error = read_registration(lua, command, funref, description); 
     232      int funref = 0, objref = 0; 
     233      lua_wrapper lua(L); 
     234      boost::optional<int> error = read_registration(lua, command, objref, funref, description); 
    207235      if (error) 
    208236        return *error; 
     
    211239        description = _T("Lua script: ") + command; 
    212240      get_instance()->get_core()->registerCommand(get_instance()->get_plugin_id(), command, description); 
    213       get_instance()->get_registry()->register_query(command, get_instance(), funref, true); 
     241      get_instance()->get_registry()->register_query(command, get_instance(), objref, funref, true); 
    214242      return 0; 
    215243    } 
     
    298326    int get_string(lua_State *L) { 
    299327      lua_wrapper lua(L); 
    300       std::wstring s = lua.wstring(1); 
    301       std::wstring k = lua.wstring(2); 
    302       std::wstring v = lua.op_wstring(3); 
     328      if (lua.size() != 3 && lua.size() != 2) 
     329        return lua.error("Invalid syntax: get_string(section, key, [value])"); 
     330      std::wstring v; 
     331      if (lua.size() > 2) 
     332        v = lua.pop_string(); 
     333      std::wstring k = lua.pop_string(); 
     334      std::wstring s = lua.pop_string(); 
    303335      lua.push_string(get_instance()->get_core()->getSettingsString(s, k, v)); 
    304336      return 1; 
     
    306338    int set_string(lua_State *L) { 
    307339      lua_wrapper lua(L); 
    308       std::wstring s = lua.wstring(1); 
    309       std::wstring k = lua.wstring(2); 
    310       std::wstring v = lua.wstring(3); 
     340      if (lua.size() != 3) 
     341        return lua.error("Invalid syntax: set_string(section, key, value)"); 
     342      std::wstring v = lua.pop_string(); 
     343      std::wstring k = lua.pop_string(); 
     344      std::wstring s = lua.pop_string(); 
    311345      get_instance()->get_core()->SetSettingsString(s, k, v); 
    312346      return 0; 
     
    314348    int get_bool(lua_State *L) { 
    315349      lua_wrapper lua(L); 
    316       std::wstring s = lua.wstring(1); 
    317       std::wstring k = lua.wstring(2); 
    318       bool v = lua.checkbool(3); 
     350      if (lua.size() != 3 && lua.size() != 2) 
     351        return lua.error("Invalid syntax: get_bool(section, key, [value])"); 
     352      bool v = false; 
     353      if (lua.size() > 2) 
     354        v = lua.pop_boolean(); 
     355      std::wstring k = lua.pop_string(); 
     356      std::wstring s = lua.pop_string(); 
    319357      lua.push_boolean(get_instance()->get_core()->getSettingsInt(s, k, v?1:0)==1); 
    320358      return 1; 
     
    322360    int set_bool(lua_State *L) { 
    323361      lua_wrapper lua(L); 
    324       std::wstring s = lua.wstring(1); 
    325       std::wstring k = lua.wstring(2); 
    326       bool v = lua.checkbool(3); 
     362      if (lua.size() != 3) 
     363        return lua.error("Invalid syntax: set_bool(section, key, value)"); 
     364      bool v = lua.pop_boolean(); 
     365      std::wstring k = lua.pop_string(); 
     366      std::wstring s = lua.pop_string(); 
    327367      get_instance()->get_core()->SetSettingsInt(s, k, v?1:0); 
    328368      return 0; 
     
    330370    int get_int(lua_State *L) { 
    331371      lua_wrapper lua(L); 
    332       std::wstring s = lua.wstring(1); 
    333       std::wstring k = lua.wstring(2); 
    334       int v = lua.checkint(3); 
     372      if (lua.size() != 3 && lua.size() != 2) 
     373        return lua.error("Invalid syntax: get_int(section, key, [value])"); 
     374      int v = 0; 
     375      if (lua.size() > 2) 
     376        v = lua.pop_int(); 
     377      std::wstring k = lua.pop_string(); 
     378      std::wstring s = lua.pop_string(); 
    335379      lua.push_int(get_instance()->get_core()->getSettingsInt(s, k, v)); 
    336380      return 1; 
     
    338382    int set_int(lua_State *L) { 
    339383      lua_wrapper lua(L); 
    340       std::wstring s = lua.wstring(1); 
    341       std::wstring k = lua.wstring(2); 
    342       int v = lua.checkint(3); 
     384      if (lua.size() != 3) 
     385        return lua.error("Invalid syntax: set_int(section, key, value)"); 
     386      int v = lua.pop_int(); 
     387      std::wstring k = lua.pop_string(); 
     388      std::wstring s = lua.pop_string(); 
    343389      get_instance()->get_core()->SetSettingsInt(s, k, v); 
    344390      return 0; 
     
    350396    int register_path(lua_State *L) { 
    351397      lua_wrapper lua(L); 
    352       std::wstring path = lua.wstring(1); 
    353       std::wstring title = lua.wstring(1); 
    354       std::wstring description = lua.wstring(1); 
     398      if (lua.size() != 3) 
     399        return lua.error("Invalid syntax: register_path(path, title, description)"); 
     400      std::wstring description = lua.pop_string(); 
     401      std::wstring title = lua.pop_string(); 
     402      std::wstring path = lua.pop_string(); 
    355403      get_instance()->get_core()->settings_register_path(path, title, description, false); 
    356404      return 0; 
    357405    } 
    358     NSCAPI::settings_type script_wrapper::settings_wrapper::get_type(std::string stype) { 
     406    NSCAPI::settings_type get_type(std::string stype) { 
    359407      if (stype == "string" || stype == "str" || stype == "s") 
    360408        return NSCAPI::key_string; 
     
    369417    int register_key(lua_State *L) { 
    370418      lua_wrapper lua(L); 
    371       std::wstring path = lua.wstring(1); 
    372       std::wstring key = lua.wstring(1); 
    373       std::string stype = lua.string(1); 
    374       NSCAPI::settings_type type = get_type(stype); 
    375       std::wstring title = lua.wstring(1); 
    376       std::wstring description = lua.wstring(1); 
    377       std::wstring defaultValue = lua.wstring(1); 
     419 
     420      if (lua.size() != 5) 
     421        return lua.error("Invalid syntax: register_key(path, key, type, title, description, default)"); 
     422      std::wstring defaultValue = lua.pop_string(); 
     423      std::wstring description = lua.pop_string(); 
     424      std::wstring title = lua.pop_string(); 
     425      NSCAPI::settings_type type = get_type(lua.pop_sstring()); 
     426      std::wstring key = lua.pop_string(); 
     427      std::wstring path = lua.pop_string(); 
    378428      get_instance()->get_core()->settings_register_key(path, key, type, title, description, defaultValue, false); 
    379429      return 0; 
     
    463513 
    464514  class lua_script : public script_instance, public boost::enable_shared_from_this<lua_script>  { 
    465     lua_script(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::string alias, const std::string script)  
    466       : script_instance(core, plugin_id, registry, alias, script) {} 
     515    std::string base_path_; 
     516    lua_script(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::string alias, const std::string base_path, const std::string script)  
     517      : script_instance(core, plugin_id, registry, alias, script), base_path_(base_path) { 
     518        std::wcout << _T("AAA"); 
     519    } 
    467520  public: 
    468  
    469     static boost::shared_ptr<lua_script> create_instance(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::wstring alias, const std::wstring script) { 
    470       boost::shared_ptr<lua_script> instance(new lua_script(core, plugin_id, registry, utf8::cvt<std::string>(alias), utf8::cvt<std::string>(script))); 
     521    virtual ~lua_script() { 
     522      std::wcout << _T("XXX"); 
     523    } 
     524 
     525    static boost::shared_ptr<lua_script> create_instance(nscapi::core_wrapper* core, const int plugin_id, boost::shared_ptr<lua_wrappers::lua_registry> registry, const std::wstring alias, const std::wstring base_path, const std::wstring script) { 
     526      boost::shared_ptr<lua_script> instance(new lua_script(core, plugin_id, registry, utf8::cvt<std::string>(alias), utf8::cvt<std::string>(base_path), utf8::cvt<std::string>(script))); 
    471527      if (instance) { 
    472         instance->init(); 
    473528        instance->load(); 
    474529      } 
    475530      return instance; 
    476531    } 
    477     void init() { 
     532 
     533    void load() { 
     534      std::wcout << _T("lll"); 
    478535      lua_wrappers::lua_instance_manager::set_script(get_lua_state(), shared_from_this()); 
    479     } 
    480  
    481     void load() { 
    482536      lua_wrappers::lua_wrapper lua(get_lua_state()); 
    483537      lua.openlibs(); 
    484538      nsclient_wrapper::luaopen(get_lua_state()); 
     539      lua.append_path(base_path_ + "\\scripts\\lua\\lib\\?.lua;" + base_path_ + "scripts\\lua\\?;"); 
    485540      if (lua.loadfile(get_script()) != 0) 
    486541        throw lua_wrappers::LUAException(_T("Failed to load script: ") + get_wscript() + _T(": ") + lua.pop_string()); 
    487542      if (lua.pcall(0, 0, 0) != 0) 
    488543        throw lua_wrappers::LUAException(_T("Failed to execute script: ") + get_wscript() + _T(": ") + lua.pop_string()); 
     544      std::wcout << _T("LLL"); 
    489545    } 
    490546    std::wstring get_wscript() const { 
    491547      return utf8::cvt<std::wstring>(get_script()); 
    492548    } 
    493     void unload() {} 
     549    void unload() { 
     550      std::wcout << _T("uuu"); 
     551      lua_wrappers::lua_wrapper lua(get_lua_state()); 
     552      lua.gc(LUA_GCCOLLECT, 0); 
     553      lua_wrappers::lua_instance_manager::remove_script(shared_from_this()); 
     554      std::wcout << _T("UUU"); 
     555      std::wcout << shared_from_this().use_count(); 
     556    } 
    494557    void reload() { 
    495558      unload(); 
  • modules/NRPEClient/NRPEClient.cpp

    ra48fd4c rd6194a0  
    298298 
    299299  } 
     300  virtual ~client_handler() {} 
    300301  void log_debug(std::string file, int line, std::string msg) const { 
    301302    if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 
     
    323324    socket_helpers::client::client<nrpe::client::protocol> client(boost::shared_ptr<client_handler>(new client_handler(con))); 
    324325    client.connect(); 
    325     packet = client.process_request(packet); 
     326    nrpe::packet response = client.process_request(packet); 
    326327    client.shutdown(); 
    327     return boost::make_tuple(static_cast<int>(packet.getResult()), packet.getPayload()); 
     328    return boost::make_tuple(static_cast<int>(response.getResult()), response.getPayload()); 
    328329  } catch (nrpe::nrpe_packet_exception &e) { 
    329330    return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("NRPE Packet errro: ") + e.wwhat()); 
  • scripts/CMakeLists.txt

    rc327ce5 rd6194a0  
    1010#FILE (GLOB scripts_PYT "python/*.py" "python/lib/*.py") 
    1111#ENDIF(WIN32) 
    12 FILE (GLOB scripts_LUA "lua/*.lua") 
     12FILE (GLOB_RECURSE scripts_LUA "lua/*.lua") 
    1313 
    1414SET(script_ALL ${scripts_BAT} ${scripts_VBS} ${scripts_PS1}) 
     
    2020  get_filename_component(filename ${file} NAME) 
    2121  #MESSAGE(STATUS " + ${filename} (${file})") 
    22   copy_single_file(copy_scripts ${filename} scripts) 
     22  copy_single_file(ALL_FILES ${filename} scripts) 
    2323ENDFOREACH(file ${script_ALL}) 
    2424 
     
    2727  get_filename_component(filename ${file} NAME) 
    2828  #MESSAGE(STATUS " + lib - ${filename}") 
    29   copy_single_file(copy_scripts lib/${filename} scripts/lib) 
     29  copy_single_file(ALL_FILES lib/${filename} scripts/lib) 
    3030ENDFOREACH(file ${scripts_LIB}) 
    3131 
     
    3636  STRING(REPLACE "/" "_" alias "${relpath}") 
    3737  STRING(REPLACE "." "_" alias "${alias}") 
    38   MESSAGE(STATUS " + python - ${filename} - ${relpath} - ${alias}") 
    39   copy_single_file(copy_scripts ${relpath}/${filename} scripts/${relpath}) 
     38  #MESSAGE(STATUS " + python - ${filename} - ${relpath} - ${alias}") 
     39  copy_single_file(ALL_FILES ${relpath}/${filename} scripts/${relpath}) 
    4040ENDFOREACH(file ${scripts_PYT}) 
    4141 
    4242FOREACH(file ${scripts_LUA}) 
    4343  get_filename_component(filename ${file} NAME) 
    44   #MESSAGE(STATUS " + lua - ${filename}") 
    45   copy_single_file(copy_scripts lua/${filename} scripts/lua) 
     44  get_filename_component(filepath ${file} PATH) 
     45  file(RELATIVE_PATH relpath ${CMAKE_CURRENT_SOURCE_DIR} "${filepath}") 
     46  STRING(REPLACE "/" "_" alias "${relpath}") 
     47  STRING(REPLACE "." "_" alias "${alias}") 
     48  #MESSAGE(STATUS " + lua - ${filename} - ${relpath} - ${alias}") 
     49  copy_single_file(ALL_FILES ${relpath}/${filename} scripts/${relpath}) 
    4650ENDFOREACH(file ${scripts_LUA}) 
    4751 
  • scripts/lua/test_nrpe.lua

    r53be5c8 rd6194a0  
    1 valid_chars = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 
    2   "0","1","2","3","4","5","6","7","8","9","-"} 
    3  
    4 math.randomseed(os.time()) 
    5  
    6 function random(len) -- args: smallest and largest possible password lengths, inclusive 
    7   pass = {} 
    8   for z = 1,len do 
    9     case = math.random(1,2) 
    10     a = math.random(1,#valid_chars) 
    11     if case == 1 then 
    12       x=string.upper(valid_chars[a]) 
    13     elseif case == 2 then 
    14       x=string.lower(valid_chars[a]) 
    15     end 
    16   table.insert(pass, x) 
    17   end 
    18   return(table.concat(pass)) 
    19 end 
    20 string.random = random 
    21  
    22 function status_to_int(status) 
    23   if status == 'ok' then 
    24     return 0 
    25   elseif status == 'warn' then 
    26     return 1 
    27   elseif status == 'crit' then 
    28     return 2 
    29   elseif status == 'unknown' then 
    30     return 3 
    31   else 
    32     print("Unknown status: "..status) 
    33     return 3 
    34   end 
    35 end 
    36  
    37 TestResult = { status = true; children = {} } 
    38 function TestResult:new(o) 
    39   o = o or {} 
    40   o["children"] = o["children"] or {} 
    41   if o["status"] == nil then o["status"] = true end 
    42   setmetatable(o, self) 
    43   self.__index = self 
    44   return o 
    45  
    46 end 
    47 function TestResult:add(result) 
    48   if not result.status then self.status = false end 
    49   table.insert(self.children,result) 
    50 end 
    51 function TestResult:add_message(result, message) 
    52   table.insert(self.children,TestResult:new{status=status, message=message}) 
    53 end 
    54 function TestResult:assert_equals(a, b, message) 
    55   if a==b then 
    56     table.insert(self.children,TestResult:new{status=true, message=message}) 
    57   else 
    58     table.insert(self.children,TestResult:new{status=false, message=message..': '..tostring(a)..' != '..tostring(b)}) 
    59   end 
    60 end 
    61  
    62  
    63 function TestResult:print(indent) 
    64   indent = indent or 0 
    65   pad = string.rep(' ', indent) 
    66   if self.status then 
    67     print(pad .. "[OK ] - " .. self.message) 
    68   else 
    69     print(pad .. "[ERR] - " .. self.message) 
    70   end 
    71   if # self.children > 0 then 
    72     for i,v in ipairs(self.children) do v:print(indent+2) end 
    73   end 
    74 end 
    75  
    76 function TestResult:print_failed(indent) 
    77   indent = indent or 0 
    78   pad = string.rep(' ', indent) 
    79   if not self.status then 
    80     print(pad .. "[ERR] - " .. self.message) 
    81   end 
    82   if # self.children > 0 then 
    83     for i,v in ipairs(self.children) do v:print(indent+2) end 
    84   end 
    85 end 
    86  
    87 function TestResult:count() 
    88   local ok = 0 
    89   local err = 0 
    90   if self.status then 
    91     ok = ok + 1 
    92   else 
    93     err = err + 1 
    94   end 
    95   if # self.children > 0 then 
    96     for i,v in ipairs(self.children) do 
    97       local lok, lerr = v:count()  
    98       ok = ok + lok 
    99       err = err + lerr 
    100     end 
    101   end 
    102   return ok, err 
    103 end 
    104    
    105  
    106  
    107 function TestResult:get_nagios() 
    108   local ok, err = self:count() 
    109   if not self.status then 
    110     return 'crit', tostring(err)..' test cases failed', '' 
    111   else 
    112     return 'ok', tostring(ok)..' test cases succeded', '' 
    113   end 
    114 end 
    115  
     1test = require("test_helper") 
    1162 
    1173TestMessage = { 
     
    15036function TestNRPE:setup() 
    15137  local reg = Registry(plugin_id) 
    152   reg:simple_query('check_py_nrpe_test_s', self.simple_handler, 'TODO') 
    153   reg:query('check_py_nrpe_test', self.handler, 'TODO') 
     38  reg:simple_query('check_py_nrpe_test_s', self, self.simple_handler, 'TODO') 
     39  reg:query('check_py_nrpe_test', self, self.handler, 'TODO') 
     40end 
     41function TestNRPE:teardown() 
    15442end 
    15543 
     
    20896end 
    20997 
    210 function TestNRPE.simple_handler(command, args) 
    211   msg = instance:get_response(args[0]) 
     98function TestNRPE:simple_handler(command, args) 
     99  msg = self:get_response(args[0]) 
    212100  msg.got_simple_response = true 
    213   instance:set_response(msg) 
    214   rmsg = instance:get_request(args[0]) 
     101  self:set_response(msg) 
     102  rmsg = self:get_request(args[0]) 
    215103  return rmsg.status, rmsg.message, rmsg.perfdata 
    216104end 
    217105 
    218 function TestNRPE.handler(req) 
    219   msg = instance:get_response(args[0]) 
     106function TestNRPE:handler(req) 
     107  msg = self:get_response(args[0]) 
    220108  msg.got_response = true 
    221   instance:set_response(msg) 
    222   rmsg = instance:get_request(args[0]) 
     109  self:set_response(msg) 
     110  rmsg = self:get_request(args[0]) 
    223111end 
    224112 
    225113function TestNRPE:submit_payload(tag, ssl, length, source, status, message, perf, target) 
    226114  local core = Core() 
    227   local result = TestResult:new{message='Testing NRPE: '..tag..' for '..target} 
     115  local result = test.TestResult:new{message='Testing NRPE: '..tag..' for '..target} 
    228116   
    229117  local msg = protobuf.Plugin.QueryRequestMessage.new() 
     
    270158      result:add_message(response_message:size_payload() == 1, 'Verify that we only get one payload response for '..tag) 
    271159      pl = response_message:get_payload(1) 
    272       result:assert_equals(pl:get_result(), status_to_int(status), 'Verify that status is sent through '..tag) 
     160      result:assert_equals(pl:get_result(), test.status_to_int(status), 'Verify that status is sent through '..tag) 
    273161      result:assert_equals(pl:get_message(), rmsg.message, 'Verify that message is sent through '..tag) 
    274162      --#result.assert_equals(rmsg.perfdata, perf, 'Verify that performance data is sent through') 
     
    290178function TestNRPE:test_one(ssl, length, status) 
    291179  tag = string.format("%s/%d/%s", tostring(ssl), length, status) 
    292   result = TestResult:new{message=string.format('Testing: %s with various targets', tag)} 
     180  local result = test.TestResult:new{message=string.format('Testing: %s with various targets', tag)} 
    293181  for k,t in pairs({'valid', 'test_rp', 'invalid'}) do 
    294182    result:add(self:submit_payload(tag, ssl, length, tag .. 'src' .. tag, status, tag .. 'msg' .. tag, '', t)) 
     
    321209  core:reload('test_nrpe_client') 
    322210 
    323   result = TestResult:new{message="Testing "..tostring(ssl)..", "..tostring(length)} 
     211  local result = test.TestResult:new{message="Testing "..tostring(ssl)..", "..tostring(length)} 
    324212  result:add(self:test_one(ssl, length, 'unknown')) 
    325213  result:add(self:test_one(ssl, length, 'ok')) 
     
    331219 
    332220function TestNRPE:run() 
    333   local result = TestResult:new{message="NRPE Test Suite"} 
     221  local result = test.TestResult:new{message="NRPE Test Suite"} 
    334222  result:add(self:do_one_test(true, 1024)) 
    335223  result:add(self:do_one_test(false, 1024)) 
     
    341229 
    342230 
    343 function lua_unittest_handler(command, args) 
    344   result = instance:setup() 
    345   result = instance:run() 
    346   print "--" 
    347   result:print() 
    348   print "--" 
    349   result:print_failed() 
    350   print "--" 
    351   return result:get_nagios() 
    352 end 
    353 function install_test_manager() 
    354   instance:install({}) 
    355   local reg = Registry(plugin_id) 
    356   reg:simple_query('lua_unittest', lua_unittest_handler, 'TODO') 
    357 end 
    358  
    359 instance = TestNRPE 
    360 install_test_manager() 
     231instances = { TestNRPE } 
     232test.install_test_manager(instances) 
  • service/NSClient++.cpp

    r53be5c8 rd6194a0  
    263263} 
    264264 
     265NSClientT::~NSClientT() { 
     266  try { 
     267    nsclient::logging::logger::destroy(); 
     268  } catch(...) { 
     269    std::wcerr << _T("UNknown exception raised: When destroying logger") << std::endl; 
     270  } 
     271} 
     272 
    265273 
    266274NSClientT::plugin_alias_list_type NSClientT::find_all_plugins(bool active) { 
     
    752760    } 
    753761    commands_.remove_all(); 
     762    channels_.remove_all(); 
     763    routers_.remove_all(); 
    754764    plugins_.clear(); 
    755765  } 
  • service/NSClient++.h

    r53be5c8 rd6194a0  
    103103  // c-tor, d-tor 
    104104  NSClientT(); 
    105   virtual ~NSClientT() {} 
     105  virtual ~NSClientT(); 
    106106 
    107107  // Service helper functions 
  • service/cli_parser.hpp

    r53be5c8 rd6194a0  
    310310      if (vm.count("run")) { 
    311311        try { 
    312           mainClient.start_and_wait(name); 
     312          core_->start_and_wait(name); 
    313313        } catch (...) { 
    314314          get_logger()->error(__FILE__, __LINE__, _T("Unknown exception in service")); 
     
    544544      } 
    545545      if (args.mode == client_arguments::query) { 
    546         ret = mainClient.simple_query(args.module, args.command, args.arguments, resp); 
     546        ret = core_->simple_query(args.module, args.command, args.arguments, resp); 
    547547      } else if (args.mode == client_arguments::exec || args.mode == client_arguments::combined) { 
    548548        ret = mainClient.simple_exec(args.command, args.arguments, resp); 
     
    551551          std::wcout << _T("Command not found (by module): ") << args.command << std::endl; 
    552552          resp.push_back(_T("Command not found: ") + args.command); 
    553           mainClient.simple_exec(_T("help"), args.arguments, resp); 
     553          core_->simple_exec(_T("help"), args.arguments, resp); 
    554554        } else if (args.mode == client_arguments::combined) { 
    555555          if (ret == NSCAPI::returnOK) { 
    556             mainClient.reload(_T("service")); 
    557             ret = mainClient.simple_query(args.module, args.combined_query, args.arguments, resp); 
     556            core_->reload(_T("service")); 
     557            ret = core_->simple_query(args.module, args.combined_query, args.arguments, resp); 
    558558          } else { 
    559559            std::wcerr << _T("Failed to execute command, will not attempt query") << std::endl; 
     
    565565        std::wcerr << _T("Need to specify one of --exec, --query or --submit") << std::endl; 
    566566      } 
    567       mainClient.stop_unload_plugins_pre(); 
    568       mainClient.stop_exit_pre(); 
    569       mainClient.stop_exit_post(); 
     567      core_->stop_unload_plugins_pre(); 
     568      core_->stop_exit_pre(); 
     569      core_->stop_exit_post(); 
    570570 
    571571      BOOST_FOREACH(std::wstring r, resp) { 
  • service/logger_impl.cpp

    ra48fd4c rd6194a0  
    115115 
    116116 
    117   void do_log(const std::string &data) { 
     117  void do_log(const std::string data) { 
    118118    if (file_.empty()) 
    119119      return; 
     
    217217  simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") {} 
    218218 
    219   void do_log(const std::string &data) { 
     219  void do_log(const std::string data) { 
    220220    if (get_console_log()) { 
    221221      std::wcout << render_console_message(data); 
     
    274274  } 
    275275 
    276   void do_log(const std::string &data) { 
     276  void do_log(const std::string data) { 
    277277    if (get_console_log()) { 
    278278      std::wcout << render_console_message(data); 
     
    325325        return false; 
    326326      } 
     327      background_logger_->shutdown(); 
    327328      return nsclient::logging::logging_interface_impl::shutdown(); 
    328329    } catch (const std::exception &e) { 
Note: See TracChangeset for help on using the changeset viewer.