Changeset 438998b in nscp
- Timestamp:
- 08/22/11 10:30:36 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- bd18eb2
- Parents:
- fe75eff
- Files:
-
- 32 added
- 2 deleted
- 12 edited
-
include/Socket.cpp (deleted)
-
include/Socket.h (deleted)
-
include/nrpe/server/tcp_connection.hpp (modified) (1 diff)
-
include/nscapi/functions.hpp (modified) (1 diff)
-
include/nscp/client/socket.hpp (added)
-
include/nscp/packet.cpp (added)
-
include/nscp/packet.hpp (added)
-
include/nscp/server/connection.cpp (added)
-
include/nscp/server/connection.hpp (added)
-
include/nscp/server/handler.hpp (added)
-
include/nscp/server/parser.hpp (added)
-
include/nscp/server/server.cpp (added)
-
include/nscp/server/server.hpp (added)
-
include/nscp/server/ssl_connection.cpp (added)
-
include/nscp/server/ssl_connection.hpp (added)
-
include/nscp/server/tcp_connection.cpp (added)
-
include/nscp/server/tcp_connection.hpp (added)
-
include/socket/socket_helpers.cpp (modified) (1 diff)
-
include/socket/socket_helpers.hpp (modified) (5 diffs)
-
include/strEx.h (modified) (2 diffs)
-
libs/protobuf/CMakeLists.txt (modified) (3 diffs)
-
libs/protobuf/envelope.proto (added)
-
libs/protobuf/ipc.proto (added)
-
libs/protobuf/settings.proto (modified) (1 diff)
-
modules/NRPEClient/CMakeLists.txt (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (2 diffs)
-
modules/NRPEServer/CMakeLists.txt (modified) (1 diff)
-
modules/NRPEServer/handler_impl.cpp (modified) (1 diff)
-
modules/NSCPClient/CMakeLists.txt (added)
-
modules/NSCPClient/NSCPClient.cpp (added)
-
modules/NSCPClient/NSCPClient.def (added)
-
modules/NSCPClient/NSCPClient.h (added)
-
modules/NSCPClient/module.cmake (added)
-
modules/NSCPClient/stdafx.cpp (added)
-
modules/NSCPClient/stdafx.h (added)
-
modules/NSCPServer/CMakeLists.txt (added)
-
modules/NSCPServer/NSCPServer.cpp (added)
-
modules/NSCPServer/NSCPServer.def (added)
-
modules/NSCPServer/NSCPServer.h (added)
-
modules/NSCPServer/handler_impl.cpp (added)
-
modules/NSCPServer/handler_impl.hpp (added)
-
modules/NSCPServer/module.cmake (added)
-
modules/NSCPServer/settings.hpp (added)
-
modules/NSCPServer/stdafx.cpp (added)
-
modules/NSCPServer/stdafx.h (added)
-
service/cli_parser.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/nrpe/server/tcp_connection.hpp
r294b37b r438998b 41 41 boost::asio::ip::tcp::socket socket_; 42 42 }; 43 44 /*45 namespace socket_handlers {46 47 class socket {48 public:49 typedef boost::asio::basic_socket<tcp,boost::asio::stream_socket_service<tcp> > basic_socket_type;50 virtual basic_socket_type& get() = 0;51 };52 53 class normal_socket : public socket {54 public:55 socket::basic_socket_type& get() {56 return socket_;57 }58 normal_socket(boost::asio::io_service& io_service)59 : socket_(io_service)60 {}61 private:62 basic_socket_type socket_;63 };64 class ssl_socket : public socket {65 public:66 socket::basic_socket_type& get() {67 return socket_.lowest_layer();68 }69 70 ssl_socket(boost::asio::io_service& io_service, boost::asio::ssl::context &context)71 : socket_(io_service, context)72 {}73 private:74 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_type;75 socket_type socket_;76 };77 78 }79 /// Represents a single connection from a client.80 class connection_base : public boost::enable_shared_from_this<connection_base>, private boost::noncopyable {81 public:82 /// Construct a connection with the given io_service.83 explicit connection_base(boost::asio::io_service& io_service, nrpe::server::socket_handlers::socket* socket, nrpe::server::handler& handler);84 virtual ~connection_base() {85 handler_.log_debug(__FILEW__, __LINE__, _T("Destroying socket..."));86 }87 88 /// Get the socket associated with the connection.89 nrpe::server::socket_handlers::socket::basic_socket_type& socket();90 91 /// Start the first asynchronous operation for the connection.92 void start();93 void start_ssl();94 95 private:96 /// Handle completion of a read operation.97 void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred);98 99 /// Handle completion of a write operation.100 void handle_write(const boost::system::error_code& e);101 102 void handle_handshake(const boost::system::error_code& error);103 104 /// Strand to ensure the connection's handlers are not called concurrently.105 boost::asio::io_service::strand strand_;106 107 /// Socket for the connection.108 //socket_handler socket_;109 boost::shared_ptr<nrpe::server::socket_handlers::socket> socket_;110 111 /// The handler used to process the incoming request.112 //request_handler& request_handler_;113 114 typedef boost::array<char, 8192> buffer_type;115 /// Buffer for incoming data.116 buffer_type buffer_;117 118 /// The incoming request.119 //request request_;120 121 /// The parser for the incoming request.122 nrpe::server::handler &handler_;123 nrpe::server::parser parser_;124 //request_parser request_parser_;125 126 /// The reply to be sent back to the client.127 //reply reply_;128 129 };130 */131 132 /*133 class ssl_connection : public boost::enable_shared_from_this<ssl_connection>, private boost::noncopyable {134 private:135 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;136 connection_ptr connection_;137 public:138 139 explicit ssl_connection(boost::asio::io_service& io_service, boost::asio::ssl::context &context, nrpe::server::handler& handler);140 virtual ~ssl_connection() {141 handler_.log_debug(__FILEW__, __LINE__, _T("Destroying SSL socket..."));142 }143 144 ssl_socket::lowest_layer_type& socket();145 void start();146 147 private:148 ssl_socket socket_;149 nrpe::server::handler &handler_;150 151 };152 153 typedef boost::shared_ptr<ssl_connection> ssl_connection_ptr;154 */155 156 43 } // namespace server 157 44 } // namespace nrpe -
include/nscapi/functions.hpp
rfe75eff r438998b 153 153 } 154 154 155 static void create_simple_query_request(std::wstring command, std::vector<std::wstring> arguments, std::string &buffer) { 156 PluginCommand::RequestMessage message; 157 ::PluginCommand::Header* header = message.mutable_header(); 158 159 header->set_type(PluginCommand::Header_Type_REQUEST); 160 header->set_version(PluginCommand::Header_Version_VERSION_1); 161 162 PluginCommand::Request *payload = message.add_payload(); 163 payload->set_command(to_string(command)); 164 165 BOOST_FOREACH(std::wstring s, arguments) 166 payload->add_arguments(to_string(s)); 167 168 payload->set_version(PluginCommand::Request_Version_VERSION_1); 169 message.SerializeToString(&buffer); 170 } 171 172 static void create_simple_query_result(NSCAPI::nagiosReturn ret, std::wstring msg, std::wstring perf, std::string &buffer) { 173 PluginCommand::ResponseMessage message; 174 ::PluginCommand::Header* header = message.mutable_header(); 175 176 header->set_type(PluginCommand::Header_Type_RESPONSE); 177 header->set_version(PluginCommand::Header_Version_VERSION_1); 178 179 PluginCommand::Response *payload = message.add_payload(); 180 payload->set_message(to_string(msg)); 181 if (!perf.empty()) 182 parse_performance_data(payload, perf); 183 184 payload->set_version(PluginCommand::Response_Version_VERSION_1); 185 message.SerializeToString(&buffer); 186 } 187 188 155 189 static decoded_simple_command_data process_simple_command_request(const wchar_t* char_command, const std::string &request) { 156 190 decoded_simple_command_data data; -
include/socket/socket_helpers.cpp
rb9498ef r438998b 78 78 79 79 void socket_helpers::io::set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) { 80 a->reset(b); 80 if (!b) { 81 a->reset(b); 82 } else { 83 std::cout << "timer aborted incorrectly: " << b.message() << std::endl; 84 } 81 85 } -
include/socket/socket_helpers.hpp
rb9498ef r438998b 117 117 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b); 118 118 119 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 120 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 119 struct timed_writer : boost::noncopyable { 120 boost::asio::io_service &io_service; 121 boost::posix_time::time_duration duration; 122 boost::asio::deadline_timer timer; 123 124 boost::optional<boost::system::error_code> timer_result; 125 boost::optional<boost::system::error_code> read_result; 126 127 timed_writer(boost::asio::io_service &io_service, boost::posix_time::time_duration duration) 128 : io_service(io_service) 129 , timer(io_service) 130 { 131 timer.expires_from_now(duration); 132 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 133 } 134 ~timed_writer() { 135 timer.cancel(); 136 } 137 138 template <typename AsyncWriteStream, typename MutableBufferSequence> 139 void write(AsyncWriteStream& socket, MutableBufferSequence &buffer) { 140 async_write(socket, buffer, boost::bind(set_result, &read_result, _1)); 141 } 142 143 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 144 bool write_and_wait(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffer) { 145 write(sock, buffer); 146 return wait(rawSocket); 147 } 148 149 template <typename RawSocket> 150 bool wait(RawSocket& socket) { 151 io_service.reset(); 152 while (io_service.run_one()) { 153 if (read_result) { 154 return true; 155 } 156 else if (timer_result) { 157 socket.close(); 158 return false; 159 } 160 } 161 } 162 }; 163 164 165 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 166 void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 121 167 boost::optional<boost::system::error_code> timer_result; 122 168 boost::asio::deadline_timer timer(sock.get_io_service()); … … 125 171 126 172 boost::optional<boost::system::error_code> read_result; 127 async_ read(sock, buffers, boost::bind(set_result, &read_result, _1));173 async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 128 174 129 175 sock.get_io_service().reset(); … … 137 183 if (*read_result) 138 184 throw boost::system::system_error(*read_result); 139 } 140 141 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 142 void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 185 } 186 187 188 struct timed_reader : boost::noncopyable { 189 boost::asio::io_service &io_service; 190 boost::posix_time::time_duration duration; 191 boost::asio::deadline_timer timer; 192 193 boost::optional<boost::system::error_code> timer_result; 194 boost::optional<boost::system::error_code> write_result; 195 196 timed_reader(boost::asio::io_service &io_service, boost::posix_time::time_duration duration) 197 : io_service(io_service) 198 , timer(io_service) 199 { 200 timer.expires_from_now(duration); 201 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 202 } 203 ~timed_reader() { 204 timer.cancel(); 205 } 206 207 template <typename AsyncWriteStream, typename MutableBufferSequence> 208 void read(AsyncWriteStream& socket, MutableBufferSequence &buffers) { 209 async_read(socket, buffers, boost::bind(set_result, &write_result, _1)); 210 } 211 212 template <typename AsyncWriteStream, typename MutableBufferSequence> 213 bool read_and_wait(AsyncWriteStream& sock, MutableBufferSequence& buffers) { 214 read(sock, buffers); 215 return wait(); 216 } 217 bool wait() { 218 io_service.reset(); 219 while (io_service.run_one()) { 220 if (write_result) { 221 std::cout << "---read---" << std::endl; 222 //timer.cancel(); 223 return true; 224 } 225 else if (timer_result) { 226 std::cout << "---timer (read)---" << std::endl; 227 //socket.close(); 228 return false; 229 } 230 } 231 } 232 }; 233 234 235 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 236 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 143 237 boost::optional<boost::system::error_code> timer_result; 144 238 boost::asio::deadline_timer timer(sock.get_io_service()); … … 147 241 148 242 boost::optional<boost::system::error_code> read_result; 149 async_ write(sock, buffers, boost::bind(set_result, &read_result, _1));243 async_read(sock, buffers, boost::bind(set_result, &read_result, _1)); 150 244 151 245 sock.get_io_service().reset(); … … 160 254 throw boost::system::system_error(*read_result); 161 255 } 162 163 256 } 164 257 } -
include/strEx.h
rb9498ef r438998b 136 136 } 137 137 138 inline std::string strip_hex(std::vector<char> str) { 139 std::string ret; ret.reserve(str.size()); 140 BOOST_FOREACH(char c, str) 141 { 142 if (c==0||c==7||c==10||c==11||c==12||c==13||c==127) 143 ret.push_back('?'); 144 else 145 ret.push_back(c); 146 } 147 return ret; 148 } 149 138 150 inline void append_list(std::wstring &lst, std::wstring &append, std::wstring sep = _T(", ")) { 139 151 if (append.empty()) … … 179 191 std::string chars; 180 192 for (unsigned int i=0;i<len;i++) { 193 if (i%32==0) { 194 if (i > 0) { 195 ss << chars; 196 ss << "\n"; 197 } 198 chars = ""; 199 ss << std::hex << std::setw(8) << std::setfill('0') << i; 200 ss << ": "; 201 } 202 ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(static_cast<unsigned char>(buf[i])); 203 ss << ", "; 204 if (buf[i] < 30 || buf[i] == 127) 205 chars += '?'; 206 else 207 chars += buf[i]; 208 } 209 return ss.str(); 210 } 211 inline std::string format_buffer(const std::vector<char> &buf) { 212 std::stringstream ss; 213 std::string chars; 214 for (unsigned int i=0;i<buf.size();i++) { 181 215 if (i%32==0) { 182 216 if (i > 0) { -
libs/protobuf/CMakeLists.txt
r39c73cd r438998b 5 5 WRAP_PROTO(PROTO_EXEC_SRC exec.proto) 6 6 WRAP_PROTO(PROTO_SETTINGS_SRC settings.proto) 7 WRAP_PROTO(PROTO_ENVELOPE_SRC envelope.proto) 7 8 8 9 SET(TARGET protobuf) … … 13 14 exec.proto 14 15 settings.proto 16 envelope.proto 15 17 16 18 ${PROTO_PLUGIN_SRC} … … 18 20 ${PROTO_EXEC_SRC} 19 21 ${PROTO_SETTINGS_SRC} 22 ${PROTO_ENVELOPE_SRC} 20 23 ) 21 24 -
libs/protobuf/settings.proto
r39c73cd r438998b 1 package PluginCommand;1 package SettingsCommand; 2 2 3 3 message Header { -
modules/NRPEClient/CMakeLists.txt
rb9498ef r438998b 39 39 ) 40 40 INCLUDE(${BUILD_CMAKE_FOLDER}/module.cmake) 41 SOURCE_GROUP("Server" REGULAR_EXPRESSION .*include/nrpe/.*) -
modules/NRPEClient/NRPEClient.cpp
rfe75eff r438998b 110 110 111 111 settings.alias().add_path_to_settings() 112 // (_T("EXTERNAL SCRIPT SECTION"), _T("Section for external scripts configuration options (CheckExternalScripts)."))113 112 114 113 (_T("handlers"), sh::fun_values_path(boost::bind(&NRPEClient::add_command, this, _1, _2)), … … 238 237 239 238 int NRPEClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) { 240 if (command != _T("query ") && command != _T("help"))239 if (command != _T("query_nrpe") && command != _T("help")) 241 240 return NSCAPI::returnIgnored; 242 241 try { -
modules/NRPEServer/CMakeLists.txt
rb9498ef r438998b 53 53 ) 54 54 INCLUDE(${BUILD_CMAKE_FOLDER}/module.cmake) 55 SOURCE_GROUP("Server" REGULAR_EXPRESSION .*include/nrpe/.*) -
modules/NRPEServer/handler_impl.cpp
r2c95d22 r438998b 56 56 } 57 57 if (data.length() >= p.get_payload_length()-1) { 58 NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :("));58 //NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :(")); 59 59 data = data.substr(0,p.get_payload_length()-2); 60 60 } -
service/cli_parser.hpp
r2c95d22 r438998b 308 308 core_->initCore(false); 309 309 } 310 int ret = 0; 310 311 std::vector<std::wstring> resp; 311 mainClient.simple_exec(module, command, arguments, resp); 312 if (mainClient.simple_exec(module, command, arguments, resp) == NSCAPI::returnIgnored) { 313 ret = 1; 314 std::wcout << _T("No handler for that command: ") << command << std::endl; 315 } 312 316 mainClient.exitCore(false); 313 317 … … 315 319 std::wcout << r << std::endl; 316 320 } 317 return 0;321 return ret; 318 322 } catch(std::exception & e) { 319 323 mainClient.log_error(__FILE__, __LINE__, std::string("Unable to parse command line (settings): ") + e.what());
Note: See TracChangeset
for help on using the changeset viewer.








