Ignore:
Timestamp:
05/13/12 22:08:01 (13 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.1, 0.4.2
Children:
695f240
Parents:
b5a03fe
Message:
  • Refactored (same as with server) client internals to be more uniform (Again, next up are NSClient Server and NRDP)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/NSCAClient/NSCAClient.cpp

    r308ae18 raf05fa1  
    2929#include <nsca/nsca_socket.hpp> 
    3030 
     31#include <nsca/client/nsca_client_protocol.hpp> 
     32#include <socket/client.hpp> 
     33 
    3134#include <settings/client/settings_client.hpp> 
    3235#include <nscapi/nscapi_protobuf_functions.hpp> 
     
    378381// Protocol implementations 
    379382// 
    380  
     383struct client_handler : public socket_helpers::client::client_handler { 
     384  unsigned int encryption_; 
     385  std::string password_; 
     386  client_handler(NSCAAgent::connection_data &con)  
     387    : socket_helpers::client::client_handler(con.host, con.port, con.timeout, false, "") 
     388    , encryption_(con.get_encryption()) 
     389    , password_(con.password) 
     390  { 
     391 
     392  } 
     393  void log_debug(std::string file, int line, std::string msg) const { 
     394    if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { 
     395      GET_CORE()->log(NSCAPI::log_level::debug, file, line, utf8::to_unicode(msg)); 
     396    } 
     397  } 
     398  void log_error(std::string file, int line, std::string msg) const { 
     399    if (GET_CORE()->should_log(NSCAPI::log_level::error)) { 
     400      GET_CORE()->log(NSCAPI::log_level::error, file, line, utf8::to_unicode(msg)); 
     401    } 
     402  } 
     403  unsigned int get_encryption() { 
     404    return encryption_; 
     405  } 
     406  std::string get_password() { 
     407    return password_; 
     408  } 
     409}; 
    381410boost::tuple<int,std::wstring> NSCAAgent::send(connection_data data, const std::list<nsca::packet> packets) { 
    382411  try { 
    383412    NSC_DEBUG_MSG_STD(_T("Connection details: ") + data.to_wstring()); 
     413 
     414    socket_helpers::client::client<nsca::client::protocol<client_handler> > client(boost::shared_ptr<client_handler>(new client_handler(data))); 
     415    client.connect(); 
     416 
     417    BOOST_FOREACH(const nsca::packet &packet, packets) { 
     418      NSC_DEBUG_MSG_STD(_T("Sending (data): ") + utf8::cvt<std::wstring>(packet.to_string())); 
     419      bool ret = client.process_request(packet); 
     420    } 
     421    client.shutdown(); 
     422/* 
    384423    boost::asio::io_service io_service; 
    385424    nsca::socket socket(io_service); 
     
    395434    } 
    396435    socket.shutdown(); 
     436    */ 
    397437    return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("")); 
    398438  } catch (const nsca::nsca_encrypt::encryption_exception &e) { 
Note: See TracChangeset for help on using the changeset viewer.