Ignore:
Timestamp:
12/06/09 22:23:10 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
79e734f
Parents:
dcd90b2
Message:

First version of a working NRPE Listener (does not (yet) handle commands but sockets are there and such)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/NRPEClient/NRPEClient.cpp

    rdcd90b2 r9b3f53c  
    6969} 
    7070 
    71 void NRPEClient::add_options(po::options_description &desc, nrpe_connection_data command_data) { 
     71void NRPEClient::add_options(po::options_description &desc, nrpe_connection_data &command_data) { 
    7272  desc.add_options() 
    7373    ("help,h", "Show this help message.") 
     
    102102    tokenizer_t tok(args, sep); 
    103103    for(tokenizer_t::iterator beg=tok.begin(); beg!=tok.end();++beg){ 
    104       std::wcout << *beg << std::endl; 
    105104      list.push_back(*beg); 
    106105    } 
     
    192191NRPEClient::nrpe_result_data NRPEClient::execute_nrpe_command(nrpe_connection_data con, std::wstring arguments) { 
    193192  try { 
    194     NRPEPacket packet; 
     193    nrpe::packet packet; 
    195194    if (!con.no_ssl) { 
    196195#ifdef USE_SSL 
    197       packet = send_ssl(con.host, con.port, con.timeout, NRPEPacket::make_request(con.get_cli(arguments), con.buffer_length)); 
     196      packet = send_ssl(con.host, con.port, con.timeout, nrpe::packet::make_request(con.get_cli(arguments), con.buffer_length)); 
    198197#else 
    199198      return nrpe_result_data(NSCAPI::returnUNKNOWN, _T("SSL support not available (compiled without USE_SSL)!")); 
    200199#endif 
    201200    } else 
    202       packet = send_nossl(con.host, con.port, con.timeout, NRPEPacket::make_request(con.get_cli(arguments), con.buffer_length)); 
     201      packet = send_nossl(con.host, con.port, con.timeout, nrpe::packet::make_request(con.get_cli(arguments), con.buffer_length)); 
    203202    return nrpe_result_data(packet.getResult(), packet.getPayload()); 
    204   } catch (NRPEPacket::NRPEPacketException &e) { 
     203  } catch (nrpe::nrpe_packet_exception &e) { 
    205204    return nrpe_result_data(NSCAPI::returnUNKNOWN, _T("NRPE Packet errro: ") + e.getMessage()); 
    206205  } catch (std::runtime_error &e) { 
     
    323322  } 
    324323 
    325   void send(NRPEPacket &packet, boost::posix_time::seconds timeout) { 
    326     std::vector<char> buf(packet.getBufferLength()); 
    327     write_with_timeout(socket_, socket_, boost::asio::buffer(packet.getBuffer(), packet.getBufferLength()), timeout); 
    328   } 
    329   NRPEPacket recv(const NRPEPacket &packet, boost::posix_time::seconds timeout) { 
    330     std::vector<char> buf(packet.getBufferLength()); 
     324  void send(nrpe::packet &packet, boost::posix_time::seconds timeout) { 
     325    std::vector<char> buf(packet.get_packet_length()); 
     326    write_with_timeout(socket_, socket_, boost::asio::buffer(packet.create_buffer(), packet.get_packet_length()), timeout); 
     327  } 
     328  nrpe::packet recv(const nrpe::packet &packet, boost::posix_time::seconds timeout) { 
     329    std::vector<char> buf(packet.get_packet_length()); 
     330    std::cout <<  "About to read: " << buf.size() << std::endl; 
    331331    read_with_timeout(socket_, socket_, boost::asio::buffer(buf), timeout); 
    332     return NRPEPacket(&buf[0], buf.size(), packet.getInternalBufferLength()); 
     332    std::cout <<  "Read data: " << buf.size() << std::endl; 
     333    return nrpe::packet(&buf[0], buf.size(), packet.get_payload_length()); 
    333334  } 
    334335}; 
     
    370371  } 
    371372 
    372   void send(NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     373  void send(nrpe::packet &packet, boost::posix_time::seconds timeout) { 
    373374    NSC_LOG_CRITICAL(_T("Writing...")); 
    374     std::vector<char> buf(packet.getBufferLength()); 
    375     write_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(packet.getBuffer(), packet.getBufferLength()), timeout); 
     375    std::vector<char> buf(packet.get_packet_length()); 
     376    write_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(packet.create_buffer(), packet.get_packet_length()), timeout); 
    376377    NSC_LOG_CRITICAL(_T("Written...")); 
    377378  } 
    378   NRPEPacket recv(const NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     379  nrpe::packet recv(const nrpe::packet &packet, boost::posix_time::seconds timeout) { 
    379380    NSC_LOG_CRITICAL(_T("Reading...")); 
    380     std::vector<char> buf(packet.getBufferLength()); 
     381    std::vector<char> buf(packet.get_packet_length()); 
    381382    read_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(buf), timeout); 
    382     return NRPEPacket(&buf[0], buf.size(), packet.getInternalBufferLength()); 
     383    return nrpe::packet(&buf[0], buf.size(), packet.get_payload_length()); 
    383384    NSC_LOG_CRITICAL(_T("Read...")); 
    384385  } 
    385386}; 
    386 NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 
     387nrpe::packet NRPEClient::send_ssl(std::wstring host, int port, int timeout, nrpe::packet packet) 
    387388{ 
    388389  boost::asio::io_service io_service; 
     
    397398#endif 
    398399 
    399 NRPEPacket NRPEClient::send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet) 
     400nrpe::packet NRPEClient::send_nossl(std::wstring host, int port, int timeout, nrpe::packet packet) 
    400401{ 
    401402  boost::asio::io_service io_service; 
Note: See TracChangeset for help on using the changeset viewer.