Index: include/client/command_line_parser.cpp
===================================================================
--- include/client/command_line_parser.cpp	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ include/client/command_line_parser.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -53,24 +53,39 @@
 
 
-int client::command_line_parser::commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
+int client::command_line_parser::do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) {
 	if (!config.validate())
 		throw cli_exception("Invalid data: " + config.to_string());
 	if (command == _T("help")) {
-		result = build_help(config);
-		return NSCAPI::returnUNKNOWN;
+		return nscapi::functions::create_simple_exec_response_unknown(command, build_help(config), result);
 	} else if (command == _T("query")) {
 		std::wstring msg, perf;
-		int ret = query(config, command, arguments, msg, perf);
-		if (perf.empty())
-			result = msg;
-		else
-			result = msg + _T("|") + perf;
+		int ret = do_query(config, command, arguments, result);
+		nscapi::functions::make_exec_from_query(result);
 		return ret;
 	} else if (command == _T("exec")) {
-		return exec(config, command, arguments, result);
+		return do_exec(config, command, arguments, result);
 	} else if (command == _T("submit")) {
-		boost::tuple<int,std::wstring> ret = simple_submit(config, command, arguments);
-		result = ret.get<1>();
-		return ret.get<0>();
+		int ret = do_submit(config, command, arguments, result);
+		nscapi::functions::make_exec_from_submit(result);
+		return ret;
+	}
+	return NSCAPI::returnIgnored;
+}
+
+int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) {
+	if (!config.validate())
+		throw cli_exception("Invalid data: " + config.to_string());
+	if (command == _T("help")) {
+		return nscapi::functions::create_simple_query_response_unknown(command, build_help(config), _T(""), result);
+	} else if (command == _T("query")) {
+		return do_query(config, command, arguments, result);
+	} else if (command == _T("exec")) {
+		int ret = do_exec(config, command, arguments, result);
+		nscapi::functions::make_query_from_exec(result);
+		return ret;
+	} else if (command == _T("submit")) {
+		int ret = do_submit(config, command, arguments, result);
+		nscapi::functions::make_query_from_submit(result);
+		return ret;
 	}
 	return NSCAPI::returnIgnored;
@@ -97,5 +112,5 @@
 }
 
-int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
+int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) {
 	command_type::const_iterator cit = commands.find(command);
 	if (cit == commands.end())
@@ -112,7 +127,7 @@
 	}
 	// TODO: Add support for target here!
-	return client::command_line_parser::commandLineExec(config, ci.command, rendered_arguments, message);
-}
-int client::command_line_parser::query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf) {
+	return client::command_line_parser::do_execute_command_as_exec(config, ci.command, rendered_arguments, response);
+}
+int client::command_line_parser::do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) {
 	boost::program_options::variables_map vm;
 
@@ -141,10 +156,8 @@
 	nscapi::functions::append_simple_query_request_payload(message.add_payload(), config.data->command, config.data->arguments);
 	std::string result;
-	int ret = config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result);
-	nscapi::functions::parse_simple_query_response(result, msg, perf);
-	return ret;
-}
-
-int client::command_line_parser::exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
+	return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result);
+}
+
+int client::command_line_parser::do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) {
 	boost::program_options::variables_map vm;
 
@@ -173,10 +186,8 @@
 	std::string response;
 	nscapi::functions::append_simple_exec_request_payload(message.add_payload(), config.data->command, config.data->arguments);
-	int ret = config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response);
-	nscapi::functions::parse_simple_exec_result(response, result);
-	return ret;
-}
-
-boost::tuple<int,std::wstring> client::command_line_parser::simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments) {
+	return config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response);
+}
+
+int client::command_line_parser::do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) {
 	boost::program_options::variables_map vm;
 	po::options_description common("Common options");
@@ -203,11 +214,5 @@
 	nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, config.data->result, config.data->message);
 
-	std::string response;
-	if (config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), response) != NSCAPI::isSuccess)
-		return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Failed to submit command"));
-
-	std::wstring messages;
-	int ret = nscapi::functions::parse_simple_submit_response(response, messages);
-	return boost::make_tuple(ret, messages);
+	return config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), result);
 }
 void client::command_line_parser::modify_header(configuration &config, ::Plugin::Common_Header* header, nscapi::functions::destination_container &recipient) {
@@ -225,5 +230,5 @@
 }
 
-int client::command_line_parser::relay_submit(configuration &config, const std::string &request, std::string &response) {
+int client::command_line_parser::do_relay_submit(configuration &config, const std::string &request, std::string &response) {
 	Plugin::SubmitRequestMessage message;
 	message.ParseFromString(request);
Index: include/client/command_line_parser.hpp
===================================================================
--- include/client/command_line_parser.hpp	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ include/client/command_line_parser.hpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -120,5 +120,5 @@
 
 		std::wstring add_command(std::wstring name, std::wstring args);
-		int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
+		int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response);
 
 		static std::wstring make_key(std::wstring key) {
@@ -137,8 +137,7 @@
 		static std::wstring build_help(configuration &config);
 
-		static int commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
-		static int relay_submit(configuration &config, const std::string &request, std::string &response);
-
-		static boost::tuple<int,std::wstring> simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments);
+		static int do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result);
+		static int do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result);
+		static int do_relay_submit(configuration &config, const std::string &request, std::string &response);
 
 		static std::wstring parse_command(std::wstring command, std::wstring prefix) {
@@ -163,7 +162,7 @@
 		}
 
-		static int query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf);
-		//static std::list<std::string> submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments);
-		static int exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+		static int do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result);
+		static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result);
+		static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result);
 
 	private:
Index: include/nscapi/functions.hpp
===================================================================
--- include/nscapi/functions.hpp	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ include/nscapi/functions.hpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -41,4 +41,39 @@
 
 namespace nscapi {
+
+	namespace traits {
+
+		template<class T>
+		struct perf_data_consts {
+			static const T get_valid_perf_numbers();
+			static const T get_replace_perf_coma_src();
+			static const T get_replace_perf_coma_tgt();
+		};
+
+		template<>
+		struct perf_data_consts<std::wstring> {
+			static const std::wstring get_valid_perf_numbers() {
+				return _T("0123456789,.");
+			}
+			static const std::wstring get_replace_perf_coma_src() {
+				return _T(",");
+			}
+			static const std::wstring get_replace_perf_coma_tgt() {
+				return _T(".");
+			}
+		};
+		template<>
+		struct perf_data_consts<std::string> {
+			static const std::string get_valid_perf_numbers() {
+				return "0123456789,.";
+			}
+			static const std::string get_replace_perf_coma_src() {
+				return ",";
+			}
+			static const std::string get_replace_perf_coma_tgt() {
+				return ".";
+			}
+		};
+	}
 	class functions {
 	public:
@@ -71,4 +106,15 @@
 			return NSCAPI::hasFailed;
 		}
+		static Plugin::Common::ResultCode gbp_status_to_gbp_nagios(Plugin::Common::Status::StatusType ret) {
+			if (ret == Plugin::Common_Status_StatusType_OK)
+				return Plugin::Common_ResultCode_OK;
+			return Plugin::Common_ResultCode_UNKNOWN;
+		}
+		static Plugin::Common::Status::StatusType gbp_to_nagios_gbp_status(Plugin::Common::ResultCode ret) {
+			if (ret == Plugin::Common_ResultCode_UNKNOWN||ret == Plugin::Common_ResultCode_WARNING||ret == Plugin::Common_ResultCode_CRITCAL)
+				return Plugin::Common_Status_StatusType_CRITICAL;
+			return Plugin::Common_Status_StatusType_OK;
+		}
+		
 		static Plugin::LogEntry::Entry::Level log_to_gpb(NSCAPI::messageTypes ret) {
 			if (ret == NSCAPI::critical)
@@ -98,11 +144,15 @@
 		}
 
-		static double trim_to_double(std::wstring s) {
-			std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,."));
-			if (pend != std::wstring::npos)
+
+		template<class T>
+		static double trim_to_double(T s) {
+			typename T::size_type pend = s.find_first_not_of(nscapi::traits::perf_data_consts<T>::get_valid_perf_numbers());
+			if (pend != T::npos)
 				s = s.substr(0,pend);
-			strEx::replace(s, _T(","), _T("."));
+			strEx::replace(s, nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_src(), nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_tgt());
 			return strEx::stod(s);
 		}
+
+		
 
 		struct decoded_simple_command_data {
@@ -280,4 +330,5 @@
 			Plugin::SubmitRequestMessage request;
 			request.mutable_header()->CopyFrom(response.header());
+			request.mutable_header()->set_source_id(request.mutable_header()->recipient_id());
 			request.set_channel(to_string(channel));
 			for (int i=0;i<response.payload_size();++i) {
@@ -287,4 +338,61 @@
 			}
 			message = request.SerializeAsString();
+		}
+
+		static void make_query_from_exec(std::string &data) {
+			Plugin::ExecuteResponseMessage exec_response_message;
+			exec_response_message.ParseFromString(data);
+			Plugin::QueryResponseMessage query_response_message;
+			query_response_message.mutable_header()->CopyFrom(exec_response_message);
+			for (int i=0;i<exec_response_message.payload_size();++i) {
+				Plugin::ExecuteResponseMessage::Response p = exec_response_message.payload(i);
+				append_simple_query_response_payload(query_response_message.add_payload(), p.command(), p.result(), p.message());
+			}
+			data = query_response_message.SerializeAsString();
+		}
+		static void make_query_from_submit(std::string &data) {
+			Plugin::SubmitResponseMessage submit_response_message;
+			submit_response_message.ParseFromString(data);
+			Plugin::QueryResponseMessage query_response_message;
+			query_response_message.mutable_header()->CopyFrom(submit_response_message);
+			for (int i=0;i<submit_response_message.payload_size();++i) {
+				Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i);
+				append_simple_query_response_payload(query_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message(), "");
+			}
+			data = query_response_message.SerializeAsString();
+		}
+
+		static void make_exec_from_submit(std::string &data) {
+			Plugin::SubmitResponseMessage submit_response_message;
+			submit_response_message.ParseFromString(data);
+			Plugin::ExecuteResponseMessage exec_response_message;
+			exec_response_message.mutable_header()->CopyFrom(submit_response_message);
+			for (int i=0;i<submit_response_message.payload_size();++i) {
+				Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i);
+				append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message());
+			}
+			data = exec_response_message.SerializeAsString();
+		}
+		static void make_exec_from_query(std::string &data) {
+			Plugin::QueryResponseMessage query_response_message;
+			query_response_message.ParseFromString(data);
+			Plugin::ExecuteResponseMessage exec_response_message;
+			exec_response_message.mutable_header()->CopyFrom(query_response_message);
+			for (int i=0;i<query_response_message.payload_size();++i) {
+				Plugin::QueryResponseMessage::Response p = query_response_message.payload(i);
+				std::string s = build_performance_data(p);
+				if (!s.empty())
+					s = p.message() + "|" + s;
+				else
+					s = p.message();
+				append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), p.result(), s);
+			}
+			data = exec_response_message.SerializeAsString();
+		}
+
+
+		static void make_return_header(::Plugin::Common_Header *target, const ::Plugin::Common_Header &source) {
+			target->CopyFrom(source);
+			target->set_source_id(target->recipient_id());
 		}
 
@@ -409,4 +517,8 @@
 			return NSCAPI::returnUNKNOWN;
 		}
+		static NSCAPI::nagiosReturn create_simple_query_response_unknown(std::wstring command, std::wstring msg, std::string &buffer) {
+			create_simple_query_response(command, NSCAPI::returnUNKNOWN, msg, _T(""), buffer);
+			return NSCAPI::returnUNKNOWN;
+		}
 
 		static void create_simple_query_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg, std::wstring perf, std::string &buffer) {
@@ -436,8 +548,42 @@
 		}
 
-		static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg) {
+		template<class T>
+		static void append_response_payloads(T &target_message, std::string &payload) {
+			T source_message;
+			source_message.ParseFromString(payload);
+			for (int i=0;i<source_message.payload_size();++i)
+				target_message.add_payload()->CopyFrom(source_message.payload(i));
+		}
+
+		static void append_simple_query_response_payload(Plugin::QueryResponseMessage::Response *payload, std::string command, NSCAPI::nagiosReturn ret, std::string msg, std::string perf = "") {
 			payload->set_command(to_string(command));
 			payload->set_message(to_string(msg));
 			payload->set_result(nagios_status_to_gpb(ret));
+			if (!perf.empty())
+				parse_performance_data(payload, perf);
+		}
+/*
+		static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) {
+			payload->set_command(command);
+			payload->set_message(msg);
+			payload->set_result(ret);
+		}
+		*/
+		static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, int ret, std::string msg) {
+			payload->set_command(command);
+			payload->set_message(msg);
+			payload->set_result(nagios_status_to_gpb(ret));
+		}
+		/*
+		static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) {
+			payload->set_command(command);
+			payload->mutable_status()->set_status(gbp_to_nagios_gbp_status(ret));
+			payload->mutable_status()->set_message(msg);
+		}
+		*/
+		static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, int ret, std::string msg) {
+			payload->set_command(command);
+			payload->mutable_status()->set_status(status_to_gpb(ret));
+			payload->mutable_status()->set_message(msg);
 		}
 
@@ -546,5 +692,6 @@
 		}
 
-		static void create_simple_exec_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring result, std::string &response) {
+		template<class T>
+		static int create_simple_exec_response(T command, NSCAPI::nagiosReturn ret, T result, std::string &response) {
 			Plugin::ExecuteResponseMessage message;
 			create_simple_header(message.mutable_header());
@@ -556,4 +703,18 @@
 			payload->set_result(nagios_status_to_gpb(ret));
 			message.SerializeToString(&response);
+			return ret;
+		}
+		template<class T>
+		static int create_simple_exec_response_unknown(T command, T result, std::string &response) {
+			Plugin::ExecuteResponseMessage message;
+			create_simple_header(message.mutable_header());
+
+			Plugin::ExecuteResponseMessage::Response *payload = message.add_payload();
+			payload->set_command(to_string(command));
+			payload->set_message(to_string(result));
+
+			payload->set_result(nagios_status_to_gpb(NSCAPI::returnUNKNOWN));
+			message.SerializeToString(&response);
+			return NSCAPI::returnUNKNOWN;
 		}
 		static decoded_simple_command_data parse_simple_exec_request(const wchar_t* char_command, const std::string &request) {
@@ -587,14 +748,24 @@
 		//////////////////////////////////////////////////////////////////////////
 
-		static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) {
-			boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring> tok(perf, boost::escaped_list_separator<wchar_t>(L'\\', L' ', L'\''));
-			BOOST_FOREACH(std::wstring s, tok) {
+		template<class T, class U>
+		struct tokenizer_data {
+			boost::escaped_list_separator<U> separator;	// \\, ' ', \'
+			T perf_item_splitter;						// ; 
+			T perf_equal_sign;							// =
+			T perf_valid_number;						// 0123456789.,
+
+		};
+
+		template<class T, class U>
+		static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, T &perf, tokenizer_data<T, U> tokenizer_data) {
+			boost::tokenizer<boost::escaped_list_separator<U>, typename T::const_iterator, T> tok(perf, tokenizer_data.separator);
+			BOOST_FOREACH(const T s, tok) {
 				if (s.size() == 0)
 					break;
-				strEx::splitVector items = strEx::splitV(s, _T(";"));
+				std::vector<T> items = strEx::splitV(s, tokenizer_data.perf_item_splitter);
 				if (items.size() < 1) {
 					Plugin::Common::PerformanceData* perfData = payload->add_perf();
 					perfData->set_type(Plugin::Common_DataType_STRING);
-					std::pair<std::wstring,std::wstring> fitem = strEx::split(_T(""), _T("="));
+					std::pair<T,T> fitem = strEx::split(T(), tokenizer_data.perf_equal_sign);
 					perfData->set_alias("invalid");
 					Plugin::Common_PerformanceData_StringValue* stringPerfData = perfData->mutable_string_value();
@@ -605,13 +776,13 @@
 				Plugin::Common::PerformanceData* perfData = payload->add_perf();
 				perfData->set_type(Plugin::Common_DataType_FLOAT);
-				std::pair<std::wstring,std::wstring> fitem = strEx::split(items[0], _T("="));
+				std::pair<T,T> fitem = strEx::split(items[0], tokenizer_data.perf_equal_sign);
 				perfData->set_alias(to_string(fitem.first));
 				Plugin::Common_PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value();
 
-				std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,."));
-				if (pend == std::wstring::npos) {
-					floatPerfData->set_value(trim_to_double(fitem.second.c_str()));
+				typename T::size_type pend = fitem.second.find_first_not_of(tokenizer_data.perf_valid_number);
+				if (pend == T::npos) {
+					floatPerfData->set_value(trim_to_double(fitem.second));
 				} else {
-					floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend).c_str()));
+					floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend)));
 					floatPerfData->set_unit(to_string(fitem.second.substr(pend)));
 				}
@@ -625,6 +796,26 @@
 				}
 			}
-//			std::wcout << _T("Converting performance data") << perf << _T(" -- ") << utf8::cvt<std::wstring>(build_performance_data(*resp)) << std::endl;
-		}
+		}
+		static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) {
+			typedef std::wstring t_string;
+			typedef wchar_t t_char;
+			tokenizer_data<t_string, t_char> data;
+			data.separator = boost::escaped_list_separator<t_char>(L'\\', L' ', L'\'');
+			data.perf_equal_sign = _T("=");
+			data.perf_item_splitter = _T(";");
+			data.perf_valid_number = _T("0123456789,.");
+			parse_performance_data<t_string, t_char>(payload, perf, data);
+		}
+		static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::string &perf) {
+			typedef std::string t_string;
+			typedef char t_char;
+			tokenizer_data<t_string, t_char> data;
+			data.separator = boost::escaped_list_separator<t_char>('\\', ' ', '\'');
+			data.perf_equal_sign = "=";
+			data.perf_item_splitter = ";";
+			data.perf_valid_number = "0123456789,.";
+			parse_performance_data<t_string, t_char>(payload, perf, data);
+		}
+
 		static std::string build_performance_data(Plugin::QueryResponseMessage::Response const &payload) {
 			std::stringstream ss;
Index: include/strEx.h
===================================================================
--- include/strEx.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ include/strEx.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -548,5 +548,6 @@
 		return boost::lexical_cast<int>(s.c_str());
 	}
-	inline double stod(std::wstring s) {
+	template<class T>
+	inline double stod(T s) {
 		return boost::lexical_cast<double>(s.c_str());
 	}
@@ -749,8 +750,9 @@
 	}
 	typedef std::vector<std::wstring> splitVector;
-	inline splitVector splitV(const std::wstring str, const std::wstring key) {
-		splitVector ret;
-		std::wstring::size_type pos = 0, lpos = 0;
-		while ((pos = str.find(key, pos)) !=  std::wstring::npos) {
+	template<class T>
+	inline std::vector<T> splitV(const T str, const T key) {
+		std::vector<T> ret;
+		typename T::size_type pos = 0, lpos = 0;
+		while ((pos = str.find(key, pos)) !=  T::npos) {
 			ret.push_back(str.substr(lpos, pos-lpos));
 			lpos = ++pos;
@@ -789,9 +791,10 @@
 		return trim_left( trim_right( str , t) , t );
 	} 
-	inline std::pair<std::wstring,std::wstring> split(std::wstring str, std::wstring key) {
-		std::wstring::size_type pos = str.find(key);
-		if (pos == std::wstring::npos)
-			return std::pair<std::wstring,std::wstring>(str, _T(""));
-		return std::pair<std::wstring,std::wstring>(str.substr(0, pos), str.substr(pos+key.length()));
+	template<class T>
+	inline std::pair<T,T> split(T str, T key) {
+		typename T::size_type pos = str.find(key);
+		if (pos == T::npos)
+			return std::pair<T,T>(str, T());
+		return std::pair<T,T>(str.substr(0, pos), str.substr(pos+key.length()));
 	}
 	typedef std::pair<std::wstring,std::wstring> token;
@@ -1056,4 +1059,7 @@
 			return utf8::cvt<std::string>(arg);
 		}
+		template <typename T> std::string to_string(const wchar_t* arg) {
+			return utf8::cvt<std::string>(std::wstring(arg));
+		}
 		template <typename T> std::wstring to_wstring(const T& arg) {
 			try {
Index: include/utils.h
===================================================================
--- include/utils.h	(revision 7443b5841b19024682a3b9ea88e8175cbf2adf66)
+++ include/utils.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -31,5 +31,5 @@
 #define MAP_OPTIONS_BEGIN(args) \
 	for (std::list<std::wstring>::const_iterator cit__=args.begin();cit__!=args.end();++cit__) { \
-	std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,_T("=")); if (false) {}
+	std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,std::wstring(_T("="))); if (false) {}
 
 #define MAP_OPTIONS_SHOWALL(obj) \
@@ -108,5 +108,5 @@
 #define MAP_OPTIONS_SECONDARY_BEGIN(splt, arg) \
 	else if (p__.first.find(splt) != std::wstring::npos) { \
-	std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,splt); if (false) {}
+	std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,std::wstring(splt)); if (false) {}
 
 #define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \
Index: modules/CheckHelpers/CheckHelpers.cpp
===================================================================
--- modules/CheckHelpers/CheckHelpers.cpp	(revision a44cb15ff718e3bedc825dac2f253af777c9357b)
+++ modules/CheckHelpers/CheckHelpers.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -145,5 +145,5 @@
 	for (cit=arguments.begin();cit!=arguments.end();++cit) {
 		std::wstring arg = *cit;
-		std::pair<std::wstring,std::wstring> p = strEx::split(arg,_T("="));
+		std::pair<std::wstring,std::wstring> p = strEx::split(arg,std::wstring(_T("=")));
 		if (p.first == _T("command")) {
 			if (!currentCommand.first.empty())
Index: modules/DistributedClient/DistributedClient.cpp
===================================================================
--- modules/DistributedClient/DistributedClient.cpp	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/DistributedClient/DistributedClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -22,5 +22,5 @@
 #include "DistributedClient.h"
 #include <time.h>
-#include <strEx.h>
+#include <boost/filesystem.hpp>
 
 #include <strEx.h>
@@ -36,20 +36,20 @@
 
 /**
- * Default c-tor
- * @return 
- */
+* Default c-tor
+* @return 
+*/
 DistributedClient::DistributedClient() {}
 
 /**
- * Default d-tor
- * @return 
- */
+* Default d-tor
+* @return 
+*/
 DistributedClient::~DistributedClient() {}
 
 /**
- * Load (initiate) module.
- * Start the background collector thread and let it run until unloadModule() is called.
- * @return true
- */
+* Load (initiate) module.
+* Start the background collector thread and let it run until unloadModule() is called.
+* @return true
+*/
 bool DistributedClient::loadModule() {
 	return false;
@@ -70,5 +70,4 @@
 		sh::settings_registry settings(get_settings_proxy());
 		settings.set_alias(_T("distributed"), alias, _T("client"));
-
 		target_path = settings.alias().get_settings_path(_T("targets"));
 
@@ -81,4 +80,5 @@
 			(_T("targets"), sh::fun_values_path(boost::bind(&DistributedClient::add_target, this, _1, _2)), 
 			_T("REMOTE TARGET DEFINITIONS"), _T(""))
+
 			;
 
@@ -89,5 +89,5 @@
 			;
 
-		settings.alias(_T("/targets/default")).add_key_to_settings()
+		settings.alias().add_key_to_settings(_T("targets/default"))
 
 			(_T("timeout"), sh::uint_key(&timeout, 30),
@@ -140,4 +140,11 @@
 	return true;
 }
+std::string get_command(std::string alias, std::string command = "") {
+	if (!alias.empty())
+		return alias; 
+	if (!command.empty())
+		return command; 
+	return "_NRPE_CHECK";
+}
 
 //////////////////////////////////////////////////////////////////////////
@@ -147,5 +154,18 @@
 void DistributedClient::add_target(std::wstring key, std::wstring arg) {
 	try {
-		targets.add(get_settings_proxy(), target_path , key, arg);
+		nscapi::target_handler::target t = targets.add(get_settings_proxy(), target_path , key, arg);
+		if (t.has_option(_T("certificate"))) {
+			boost::filesystem::wpath p = t.options[_T("certificate")];
+			if (!boost::filesystem::is_regular(p)) {
+				p = get_core()->getBasePath() / p;
+				t.options[_T("certificate")] = utf8::cvt<std::wstring>(p.string());
+				targets.add(t);
+			}
+			if (boost::filesystem::is_regular(p)) {
+				NSC_DEBUG_MSG_STD(_T("Using certificate: ") + p.string());
+			} else {
+				NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string());
+			}
+		}
 	} catch (...) {
 		NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key);
@@ -157,5 +177,5 @@
 		std::wstring key = commands.add_command(name, args);
 		if (!key.empty())
-			register_command(key.c_str(), _T("Custom command for: ") + name);
+			register_command(key.c_str(), _T("DNSCP relay for: ") + name);
 	} catch (boost::program_options::validation_error &e) {
 		NSC_LOG_ERROR_STD(_T("Could not add command ") + name + _T(": ") + utf8::to_unicode(e.what()));
@@ -166,57 +186,36 @@
 
 /**
- * Unload (terminate) module.
- * Attempt to stop the background processing thread.
- * @return true if successfully, false if not (if not things might be bad)
- */
+* Unload (terminate) module.
+* Attempt to stop the background processing thread.
+* @return true if successfully, false if not (if not things might be bad)
+*/
 bool DistributedClient::unloadModule() {
 	return true;
 }
 
-NSCAPI::nagiosReturn DistributedClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("dist"));
-
+NSCAPI::nagiosReturn DistributedClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
 	client::configuration config;
 	setup(config);
-	if (cmd == _T("query"))
-		return client::command_line_parser::query(config, cmd, arguments, message, perf);
-	if (cmd == _T("submit")) {
-		boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-		message = result.get<1>();
-		return result.get<0>();
-	}
-	if (cmd == _T("exec")) {
-		return client::command_line_parser::exec(config, cmd, arguments, message);
-	}
-	return commands.exec_simple(config, target, command, arguments, message, perf);
-}
-
-int DistributedClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nrpe"));
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+int DistributedClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-NSCAPI::nagiosReturn DistributedClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		setup(config);
-
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
-		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn DistributedClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
+	client::configuration config;
+	setup(config);
+	return client::command_line_parser::do_relay_submit(config, request, result);
 }
 
@@ -227,4 +226,11 @@
 void DistributedClient::add_local_options(po::options_description &desc, client::configuration::data_type data) {
 	desc.add_options()
+		("certificate,c", po::value<std::string>()->notifier(boost::bind(&nscapi::functions::destination_container::set_string_data, &data->recipient, "certificate", _1)), 
+		"Length of payload (has to be same as on the server)")
+		/*
+		("no-ssl,n", po::value<bool>(&command_data.no_ssl)->zero_tokens()->default_value(false), "Do not initial an ssl handshake with the server, talk in plain text.")
+
+		("cert,c", po::value<std::wstring>(&command_data.cert)->default_value(cert_), "Certificate to use.")
+		*/
 		;
 }
@@ -235,6 +241,6 @@
 
 	net::wurl url;
-	url.protocol = _T("nrpe");
-	url.port = 5666;
+	url.protocol = _T("dnscp");
+	url.port = 5669;
 	nscapi::target_handler::optarget opt = targets.find_target(_T("default"));
 	if (opt) {
@@ -245,5 +251,5 @@
 				url.port = strEx::stoi(t.options[_T("port")]);
 			} catch (...) {}
-}
+		}
 		std::string keys[] = {"certificate", "timeout", "payload length", "ssl"};
 		BOOST_FOREACH(std::string s, keys) {
@@ -270,111 +276,100 @@
 //
 
-
+std::string gather_and_log_errors(std::string  &payload) {
+	NSCPIPC::ErrorMessage message;
+	message.ParseFromString(payload);
+	std::string ret;
+	for (int i=0;i<message.error_size();i++) {
+		ret += message.error(i).message();
+		NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
+	}
+	return ret;
+}
 int DistributedClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &packet, chunks) {
-			if (nscp::checks::is_query_response(packet)) {
-				reply = packet.payload;
-			} else if (nscp::checks::is_error(packet)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(packet.payload);
-				for (int i=0;i<message.error_size();i++) {
-					NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
-				}
-				ret = NSCAPI::returnUNKNOWN;
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(packet.signature.payload_type));
-				ret = NSCAPI::returnUNKNOWN;
-			}
-		}
-		return ret;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		return NSCAPI::returnUNKNOWN;
-	}
+	int ret = NSCAPI::returnUNKNOWN;
+	Plugin::QueryRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::QueryResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_envelope_request(1));
+	chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_query_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
 }
 
 int DistributedClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	std::list<std::string> result;
-	std::wstring channel;
-	try {
-
-		Plugin::SubmitRequestMessage message;
-		message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-		channel = utf8::cvt<std::wstring>(message.channel());
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &chunk, chunks) {
-			if (nscp::checks::is_query_response(chunk)) {
-				result.push_back(chunk.payload);
-			} else if (nscp::checks::is_error(chunk)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(chunk.payload);
-				for (int i=0;i<message.error_size();i++) {
-					result.push_back("Error: " + message.error(i).message());
-				}
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
-				result.push_back("Invalid payload");
-			}
-		}
-		if (result.empty()) {
-			std::wstring msg;
-			BOOST_FOREACH(std::string &e, result) {
-				msg += utf8::cvt<std::wstring>(e);
-			}
-			nscapi::functions::create_simple_submit_response(channel, _T(""), result.empty()?NSCAPI::isSuccess:NSCAPI::hasFailed, msg, reply);
-		}
-
-		return result.empty()?NSCAPI::isSuccess:NSCAPI::hasFailed;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		nscapi::functions::create_simple_submit_response(channel, _T(""), NSCAPI::hasFailed, utf8::cvt<std::wstring>(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
+	int ret = NSCAPI::returnUNKNOWN;
+	Plugin::SubmitRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_submit_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
 }
 
 int DistributedClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
 	int ret = NSCAPI::returnOK;
-	try {
-		Plugin::ExecuteRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &chunk, chunks) {
-			if (nscp::checks::is_exec_response(chunk)) {
-				reply = chunk.payload;
-			} else if (nscp::checks::is_error(chunk)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(chunk.payload);
-				for (int i=0;i<message.error_size();i++) {
-					NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
-					ret = NSCAPI::returnUNKNOWN;
-				}
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
-				ret = NSCAPI::returnUNKNOWN;
-			}
-		}
-		return ret;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		return NSCAPI::returnUNKNOWN;
-	}
+	Plugin::ExecuteRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::ExecuteResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_envelope_request(1));
+	chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_exec_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
 }
 
@@ -389,7 +384,7 @@
 	std::wstring host = generic_data->host;
 	if (host.empty() && !generic_data->target.empty()) {
-		nscapi::target_handler::optarget t = targets.find_target(generic_data->target);
-		if (t)
-			host = (*t).host;
+	nscapi::target_handler::optarget t = targets.find_target(generic_data->target);
+	if (t)
+	host = (*t).host;
 	}
 	*/
Index: modules/DistributedClient/DistributedClient.h
===================================================================
--- modules/DistributedClient/DistributedClient.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/DistributedClient/DistributedClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -39,5 +39,5 @@
 
 
-class DistributedClient : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
+class DistributedClient : public nscapi::impl::simple_plugin {
 private:
 
@@ -49,5 +49,4 @@
 
 	struct connection_data {
-		std::string cert;
 		std::string address;
 		int timeout;
@@ -56,10 +55,6 @@
 
 		connection_data(nscapi::functions::destination_container recipient) {
-			cert = recipient.get_string_data("certificate");
 			timeout = recipient.get_int_data("timeout", 30);
-			buffer_length = recipient.get_int_data("payload length", 1024);
-			use_ssl = recipient.get_bool_data("ssl");
-			if (recipient.has_data("no ssl"))
-				use_ssl = !recipient.get_bool_data("no ssl");
+
 			address = recipient.address;
 		}
@@ -69,7 +64,4 @@
 			ss << _T("address: ") << utf8::cvt<std::wstring>(address);
 			ss << _T(", timeout: ") << timeout;
-			ss << _T(", buffer_length: ") << buffer_length;
-			ss << _T(", use_ssl: ") << use_ssl;
-			ss << _T(", certificate: ") << utf8::cvt<std::wstring>(cert);
 			return ss.str();
 		}
@@ -137,6 +129,6 @@
 	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
 
 private:
Index: modules/DistributedServer/handler_impl.cpp
===================================================================
--- modules/DistributedServer/handler_impl.cpp	(revision 98113da8ef0615be4afe630cb3fd0523873a746a)
+++ modules/DistributedServer/handler_impl.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -145,5 +145,5 @@
 	std::string outBuffer;
 	if (command.empty() || command == _T("_NSCP_CHECK")) {
-		nscapi::functions::create_simple_exec_response(_T("_NSCP_CHECK"), NSCAPI::returnOK, _T("I (") + nscapi::plugin_singleton->get_core()->getApplicationVersionString() + _T(") seem to be doing fine..."), outBuffer);
+		nscapi::functions::create_simple_exec_response<std::string>("_NSCP_CHECK", NSCAPI::returnOK, "I (" + utf8::cvt<std::string>(nscapi::plugin_singleton->get_core()->getApplicationVersionString()) + ") seem to be doing fine...", outBuffer);
 	} else if (!allowArgs_ && payload.arguments_size() > 0) {
 		nscapi::functions::create_simple_exec_response(command, NSCAPI::returnUNKNOWN, _T("Arguments not allowed for command: ") + command, outBuffer);
Index: modules/NRPEClient/NRPEClient.cpp
===================================================================
--- modules/NRPEClient/NRPEClient.cpp	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/NRPEClient/NRPEClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -54,5 +54,4 @@
 
 bool NRPEClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {
-	std::map<std::wstring,std::wstring> commands;
 
 	std::wstring certificate;
@@ -187,49 +186,28 @@
 }
 
-NSCAPI::nagiosReturn NRPEClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nrpe"));
-
+NSCAPI::nagiosReturn NRPEClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
 	client::configuration config;
 	setup(config);
-	if (cmd == _T("query"))
-		return client::command_line_parser::query(config, cmd, arguments, message, perf);
-	if (cmd == _T("submit")) {
-		boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-		message = result.get<1>();
-		return result.get<0>();
-	}
-	if (cmd == _T("exec")) {
-		return client::command_line_parser::exec(config, cmd, arguments, message);
-	}
-	return commands.exec_simple(config, target, command, arguments, message, perf);
-}
-
-int NRPEClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nrpe"));
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+NSCAPI::nagiosReturn NRPEClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-NSCAPI::nagiosReturn NRPEClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		setup(config);
-
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
-		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn NRPEClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
+	client::configuration config;
+	setup(config);
+	return client::command_line_parser::do_relay_submit(config, request, result);
 }
 
@@ -292,82 +270,65 @@
 
 int NRPEClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		Plugin::QueryResponseMessage response_message;
-		nscapi::functions::create_simple_header(response_message.mutable_header());	// TODO copy request header (inverted)
-
-		for (int i=0;i<request_message.payload_size();i++) {
-			std::string command = get_command(request_message.payload(i).alias(), request_message.payload(i).command());
-			std::string data = command;
-			for (int a=0;a<request_message.payload(i).arguments_size();a++) {
-				data += "!" + request_message.payload(i).arguments(a);
-			}
-			boost::tuple<int,std::wstring> ret = instance->send(con, data);
-			std::pair<std::wstring,std::wstring> rdata = strEx::split(ret.get<1>(), _T("|"));
-			nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), utf8::cvt<std::wstring>(command), ret.get<0>(), rdata.first, rdata.second);
-		}
-		response_message.SerializeToString(&reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_query_response(_T("command"), NSCAPI::returnUNKNOWN, _T("Exception: ") + utf8::to_unicode(e.what()), _T(""), reply);
-		return NSCAPI::returnUNKNOWN;
-	}
+	Plugin::QueryRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::QueryResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	for (int i=0;i<request_message.payload_size();i++) {
+		std::string command = get_command(request_message.payload(i).alias(), request_message.payload(i).command());
+		std::string data = command;
+		for (int a=0;a<request_message.payload(i).arguments_size();a++) {
+			data += "!" + request_message.payload(i).arguments(a);
+		}
+		boost::tuple<int,std::wstring> ret = instance->send(con, data);
+		std::pair<std::wstring,std::wstring> rdata = strEx::split(ret.get<1>(), std::wstring(_T("|")));
+		nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), utf8::cvt<std::wstring>(command), ret.get<0>(), rdata.first, rdata.second);
+	}
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 int NRPEClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	std::wstring channel;
-	try {
-		Plugin::SubmitRequestMessage message;
-		message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-		channel = utf8::cvt<std::wstring>(message.channel());
-		
-		for (int i=0;i<message.payload_size();++i) {
-			std::string command = get_command(message.payload(i).alias(), message.payload(i).command());
-			std::string data = command;
-			for (int a=0;a<message.payload(i).arguments_size();a++) {
-				data += "!" + message.payload(i).arguments(i);
-			}
-			boost::tuple<int,std::wstring> ret = instance->send(con, data);
-			// TODO: Change this to append!
-			nscapi::functions::create_simple_submit_response(channel, utf8::cvt<std::wstring>(command), ret.get<0>(), _T("Message submitted successfully: ") + ret.get<1>(), reply);
-			return NSCAPI::isSuccess;
-		}
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), NSCAPI::returnUNKNOWN, _T("Empty message was submitted"), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), NSCAPI::returnUNKNOWN, utf8::to_unicode(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}	
+	Plugin::SubmitRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+	std::wstring channel = utf8::cvt<std::wstring>(request_message.channel());
+	
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	for (int i=0;i<request_message.payload_size();++i) {
+		std::string command = get_command(request_message.payload(i).alias(), request_message.payload(i).command());
+		std::string data = command;
+		for (int a=0;a<request_message.payload(i).arguments_size();a++) {
+			data += "!" + request_message.payload(i).arguments(i);
+		}
+		boost::tuple<int,std::wstring> ret = instance->send(con, data);
+		nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), command, ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
+	}
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 int NRPEClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-		Plugin::ExecuteRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		for (int i=0;i<request_message.payload_size();i++) {
-			std::string command = get_command(request_message.payload(i).command());
-			std::string data = command;
-			for (int a=0;a<request_message.payload(i).arguments_size();a++) {
-				data += "!" + request_message.payload(i).arguments(a);
-			}
-			boost::tuple<int,std::wstring> ret = instance->send(con, data);
-			nscapi::functions::create_simple_exec_response(utf8::cvt<std::wstring>(command), ret.get<0>(), ret.get<1>(), reply);
-		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_exec_response(_T("command"), NSCAPI::returnUNKNOWN, _T("Exception: ") + utf8::to_unicode(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
+	Plugin::ExecuteRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::ExecuteResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	for (int i=0;i<request_message.payload_size();i++) {
+		std::string command = get_command(request_message.payload(i).command());
+		std::string data = command;
+		for (int a=0;a<request_message.payload(i).arguments_size();a++)
+			data += "!" + request_message.payload(i).arguments(a);
+		boost::tuple<int,std::wstring> ret = instance->send(con, data);
+		nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), command, ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
+	}
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
Index: modules/NRPEClient/NRPEClient.h
===================================================================
--- modules/NRPEClient/NRPEClient.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/NRPEClient/NRPEClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -34,5 +34,5 @@
 namespace po = boost::program_options;
 
-class NRPEClient : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
+class NRPEClient : public nscapi::impl::simple_plugin {
 private:
 
@@ -145,6 +145,6 @@
 	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
 
 private:
Index: modules/NSCAClient/NSCAClient.cpp
===================================================================
--- modules/NSCAClient/NSCAClient.cpp	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/NSCAClient/NSCAClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -222,52 +222,28 @@
 }
 
-NSCAPI::nagiosReturn NSCAAgent::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nsca"));
-
+NSCAPI::nagiosReturn NSCAAgent::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
 	client::configuration config;
 	setup(config);
-	if (cmd == _T("query"))
-		return client::command_line_parser::query(config, cmd, arguments, message, perf);
-	if (cmd == _T("submit")) {
-		boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-		message = result.get<1>();
-		return result.get<0>();
-	}
-	if (cmd == _T("exec")) {
-		return client::command_line_parser::exec(config, cmd, arguments, message);
-	}
-	return commands.exec_simple(config, target, command, arguments, message, perf);
-}
-
-int NSCAAgent::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nsca"));
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+NSCAPI::nagiosReturn NSCAAgent::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-NSCAPI::nagiosReturn NSCAAgent::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		setup(config);
-
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
-		}
-		return NSCAPI::isSuccess;
-	} catch (nsca::nsca_encrypt::encryption_exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to encrypt data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn NSCAAgent::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
+	client::configuration config;
+	setup(config);
+	return client::command_line_parser::do_relay_submit(config, request, result);
 }
 
@@ -337,89 +313,81 @@
 
 int NSCAAgent::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		std::list<nsca::packet> list;
-		for (int i=0;i < request_message.payload_size(); ++i) {
-			nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
-			nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(request_message.payload(i));
-			packet.code = 0;
-			packet.result = utf8::cvt<std::string>(data.command);
-			list.push_back(packet);
-		}
-
-		boost::tuple<int,std::wstring> ret = instance->send(con, list);
-		nscapi::functions::create_simple_query_response(_T("UNKNOWN"), ret.get<0>(), ret.get<1>(), _T(""), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_query_response(_T("command"), NSCAPI::returnUNKNOWN, _T("Exception: ") + utf8::to_unicode(e.what()), _T(""), reply);
-		return NSCAPI::returnUNKNOWN;
-	}
+	Plugin::QueryRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::QueryResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nsca::packet> list;
+	for (int i=0;i < request_message.payload_size(); ++i) {
+		nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
+		nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(request_message.payload(i));
+		packet.code = 0;
+		packet.result = utf8::cvt<std::string>(data.command);
+		list.push_back(packet);
+	}
+
+	boost::tuple<int,std::wstring> ret = instance->send(con, list);
+
+	nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), "TODO", ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()), "");
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 int NSCAAgent::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	std::wstring channel;
-	try {
-		Plugin::SubmitRequestMessage message;
-		message.ParseFromString(request);
-
-		connection_data con = parse_header(*header);
-		channel = utf8::cvt<std::wstring>(message.channel());
-
-		std::list<nsca::packet> list;
-
-		for (int i=0;i < message.payload_size(); ++i) {
-			nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
-			std::wstring alias, msg;
-			packet.code = nscapi::functions::parse_simple_submit_request_payload(message.payload(i), alias, msg);
-			if (alias != _T("host_check"))
-				packet.service = utf8::cvt<std::string>(alias);
-			packet.result = utf8::cvt<std::string>(msg);
-			list.push_back(packet);
-		}
-
-		boost::tuple<int,std::wstring> ret = instance->send(con, list);
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), ret.get<0>(), ret.get<1>(), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), NSCAPI::returnUNKNOWN, utf8::to_unicode(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
+	Plugin::SubmitRequestMessage message;
+	message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+	std::wstring channel = utf8::cvt<std::wstring>(message.channel());
+
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nsca::packet> list;
+
+	for (int i=0;i < message.payload_size(); ++i) {
+		nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
+		std::wstring alias, msg;
+		packet.code = nscapi::functions::parse_simple_submit_request_payload(message.payload(i), alias, msg);
+		if (alias != _T("host_check"))
+			packet.service = utf8::cvt<std::string>(alias);
+		packet.result = utf8::cvt<std::string>(msg);
+		list.push_back(packet);
+	}
+
+	boost::tuple<int,std::wstring> ret = instance->send(con, list);
+	nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "TODO", ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 int NSCAAgent::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-		Plugin::ExecuteRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		std::list<nsca::packet> list;
-		for (int i=0;i < request_message.payload_size(); ++i) {
-			nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
-			nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request_payload(request_message.payload(i));
-			packet.code = 0;
-			if (data.command != _T("host_check"))
-				packet.service = utf8::cvt<std::string>(data.command);
-			//packet.result = data.;
-			list.push_back(packet);
-		}
-		boost::tuple<int,std::wstring> ret = instance->send(con, list);
-		nscapi::functions::create_simple_exec_response(_T("UNKNOWN"), ret.get<0>(), ret.get<1>(), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_exec_response(_T("command"), NSCAPI::returnUNKNOWN, _T("Exception: ") + utf8::to_unicode(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
+	Plugin::ExecuteRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::ExecuteResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nsca::packet> list;
+	for (int i=0;i < request_message.payload_size(); ++i) {
+		nsca::packet packet(con.sender_hostname, con.buffer_length, con.time_delta);
+		nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request_payload(request_message.payload(i));
+		packet.code = 0;
+		if (data.command != _T("host_check"))
+			packet.service = utf8::cvt<std::string>(data.command);
+		//packet.result = data.;
+		list.push_back(packet);
+	}
+	boost::tuple<int,std::wstring> ret = instance->send(con, list);
+	nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "TODO", ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 //////////////////////////////////////////////////////////////////////////
 // Protocol implementations
+//
 
 boost::tuple<int,std::wstring> NSCAAgent::send(connection_data data, const std::list<nsca::packet> packets) {
@@ -438,5 +406,5 @@
 			socket.send_nsca(packet, boost::posix_time::seconds(data.timeout));
 		}
-		return NSCAPI::isSuccess;
+		return boost::make_tuple(NSCAPI::returnUNKNOWN, _T(""));
 	} catch (nsca::nsca_encrypt::encryption_exception &e) {
 		NSC_LOG_ERROR_STD(_T("NSCA Error: ") + utf8::to_unicode(e.what()));
Index: modules/NSCAClient/NSCAClient.h
===================================================================
--- modules/NSCAClient/NSCAClient.h	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/NSCAClient/NSCAClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -34,5 +34,5 @@
 namespace po = boost::program_options;
 
-class NSCAAgent : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
+class NSCAAgent : public nscapi::impl::simple_plugin {
 private:
 
@@ -148,6 +148,6 @@
 	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
 
 private:
Index: modules/NSCPClient/NSCPClient.cpp
===================================================================
--- modules/NSCPClient/NSCPClient.cpp	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/NSCPClient/NSCPClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -72,4 +72,5 @@
 
 		settings.alias().add_path_to_settings()
+			(_T("NSCP CLIENT SECTION"), _T("Section for NSCP active/passive check module."))
 
 			(_T("handlers"), sh::fun_values_path(boost::bind(&NSCPClient::add_command, this, _1, _2)), 
@@ -192,49 +193,28 @@
 }
 
-NSCAPI::nagiosReturn NSCPClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nscp"));
-
+NSCAPI::nagiosReturn NSCPClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
 	client::configuration config;
 	setup(config);
-	if (cmd == _T("query"))
-		return client::command_line_parser::query(config, cmd, arguments, message, perf);
-	if (cmd == _T("submit")) {
-		boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-		message = result.get<1>();
-		return result.get<0>();
-	}
-	if (cmd == _T("exec")) {
-		return client::command_line_parser::exec(config, cmd, arguments, message);
-	}
-	return commands.exec_simple(config, target, command, arguments, message, perf);
-}
-
-int NSCPClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nscp"));
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+NSCAPI::nagiosReturn NSCPClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-NSCAPI::nagiosReturn NSCPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		setup(config);
-
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
-		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn NSCPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
+	client::configuration config;
+	setup(config);
+	return client::command_line_parser::do_relay_submit(config, request, result);
 }
 
@@ -295,116 +275,100 @@
 //
 
+std::string gather_and_log_errors(std::string  &payload) {
+	NSCPIPC::ErrorMessage message;
+	message.ParseFromString(payload);
+	std::string ret;
+	for (int i=0;i<message.error_size();i++) {
+		ret += message.error(i).message();
+		NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
+	}
+	return ret;
+}
 int NSCPClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
-	try {
-
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		// TODO: Humm, this cant be right?!?!
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_envelope_request(1));
-		chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &chunk, chunks) {
-			if (nscp::checks::is_query_response(chunk)) {
-				reply = chunk.payload;
-			} else if (nscp::checks::is_error(chunk)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(chunk.payload);
-				for (int i=0;i<message.error_size();i++) {
-					NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
-				}
-				ret = NSCAPI::returnUNKNOWN;
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
-				ret = NSCAPI::returnUNKNOWN;
-			}
-		}
-		return ret;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		return NSCAPI::returnUNKNOWN;
-	}
-}
+	int ret = NSCAPI::returnUNKNOWN;
+	Plugin::QueryRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::QueryResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_envelope_request(1));
+	chunks.push_back(nscp::factory::create_payload(nscp::data::command_request, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_query_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_query_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
+}
+
 int NSCPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	std::list<std::string> result;
-	try {
-
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		// TODO: Humm, this cant be right?!?!
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &chunk, chunks) {
-			if (nscp::checks::is_query_response(chunk)) {
-				result.push_back(chunk.payload);
-			} else if (nscp::checks::is_error(chunk)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(chunk.payload);
-				for (int i=0;i<message.error_size();i++) {
-					result.push_back("Error: " + message.error(i).message());
-				}
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
-				result.push_back("Invalid payload");
-			}
-		}
-
-		if (result.empty()) {
-			std::wstring msg;
-			BOOST_FOREACH(std::string &e, result) {
-				msg += utf8::cvt<std::wstring>(e);
-			}
-			nscapi::functions::create_simple_submit_response(_T(""), _T(""), result.empty()?NSCAPI::isSuccess:NSCAPI::hasFailed, msg, reply);
-		}
-		return result.empty()?NSCAPI::isSuccess:NSCAPI::hasFailed;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		nscapi::functions::create_simple_submit_response(_T(""), _T(""), NSCAPI::hasFailed, utf8::cvt<std::wstring>(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
-}
+	int ret = NSCAPI::returnUNKNOWN;
+	Plugin::SubmitRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_payload(nscp::data::command_response, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_submit_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
+}
+
 int NSCPClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
 	int ret = NSCAPI::returnOK;
-	try {
-
-
-		Plugin::QueryRequestMessage request_message;
-		request_message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-
-		// TODO: Humm, this cant be right?!?!
-
-		std::list<nscp::packet> chunks;
-		chunks.push_back(nscp::factory::create_envelope_request(1));
-		chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request, 0));
-		chunks = instance->send(con, chunks);
-		BOOST_FOREACH(nscp::packet &chunk, chunks) {
-			if (nscp::checks::is_exec_response(chunk)) {
-				reply = chunk.payload;
-			} else if (nscp::checks::is_error(chunk)) {
-				NSCPIPC::ErrorMessage message;
-				message.ParseFromString(chunk.payload);
-				for (int i=0;i<message.error_size();i++) {
-					NSC_LOG_ERROR_STD(_T("Error: ") + utf8::cvt<std::wstring>(message.error(i).message()));
-					ret = NSCAPI::returnUNKNOWN;
-				}
-			} else {
-				NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
-				ret = NSCAPI::returnUNKNOWN;
-			}
-		}
-		return ret;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		return NSCAPI::returnUNKNOWN;
-	}
+	Plugin::ExecuteRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::ExecuteResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	std::list<nscp::packet> chunks;
+	chunks.push_back(nscp::factory::create_envelope_request(1));
+	chunks.push_back(nscp::factory::create_payload(nscp::data::exec_request, request, 0));
+	chunks = instance->send(con, chunks);
+	BOOST_FOREACH(nscp::packet &chunk, chunks) {
+		if (nscp::checks::is_exec_response(chunk)) {
+			nscapi::functions::append_response_payloads(response_message, chunk.payload);
+		} else if (nscp::checks::is_error(chunk)) {
+			std::string error = gather_and_log_errors(chunk.payload);
+			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, error);
+			ret = NSCAPI::returnUNKNOWN;
+		} else {
+			NSC_LOG_ERROR_STD(_T("Unsupported message type: ") + strEx::itos(chunk.signature.payload_type));
+			nscapi::functions::append_simple_exec_response_payload(response_message.add_payload(), "", NSCAPI::returnUNKNOWN, "Unsupported response type");
+			ret = NSCAPI::returnUNKNOWN;
+		}
+	}
+	response_message.SerializeToString(&reply);
+	return ret;
 }
 
Index: modules/NSCPClient/NSCPClient.h
===================================================================
--- modules/NSCPClient/NSCPClient.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/NSCPClient/NSCPClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -35,5 +35,5 @@
 
 
-class NSCPClient : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
+class NSCPClient : public nscapi::impl::simple_plugin {
 private:
 
@@ -142,6 +142,6 @@
 	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
 
 private:
Index: modules/SMTPClient/SMTPClient.cpp
===================================================================
--- modules/SMTPClient/SMTPClient.cpp	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/SMTPClient/SMTPClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -19,6 +19,6 @@
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
-
 #include "stdafx.h"
+#include "SMTPClient.h"
 
 #include <utils.h>
@@ -28,5 +28,4 @@
 #include <strEx.h>
 
-#include "SMTPClient.h"
 
 #include <settings/client/settings_client.hpp>
@@ -35,6 +34,4 @@
 
 namespace sh = nscapi::settings_helper;
-namespace str = nscp::helpers;
-namespace po = boost::program_options;
 
 /**
@@ -43,4 +40,5 @@
  */
 SMTPClient::SMTPClient() {}
+
 /**
  * Default d-tor
@@ -48,4 +46,5 @@
  */
 SMTPClient::~SMTPClient() {}
+
 /**
  * Load (initiate) module.
@@ -56,7 +55,9 @@
 	return false;
 }
+
 bool SMTPClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {
 
-
+	std::wstring template_string, sender, recipient;
+	unsigned int timeout;
 	try {
 		sh::settings_registry settings(get_settings_proxy());
@@ -66,14 +67,12 @@
 		settings.alias().add_path_to_settings()
 			(_T("SMTP CLIENT SECTION"), _T("Section for SMTP passive check module."))
+			(_T("handlers"), sh::fun_values_path(boost::bind(&SMTPClient::add_command, this, _1, _2)), 
+			_T("CLIENT HANDLER SECTION"), _T(""))
 
 			(_T("targets"), sh::fun_values_path(boost::bind(&SMTPClient::add_target, this, _1, _2)), 
 			_T("REMOTE TARGET DEFINITIONS"), _T(""))
-
 			;
 
 		settings.alias().add_key_to_settings()
-			(_T("hostname"), sh::string_key(&hostname_),
-			_T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used."))
-
 			(_T("channel"), sh::wstring_key(&channel_, _T("SMTP")),
 			_T("CHANNEL"), _T("The channel to listen to."))
@@ -81,4 +80,20 @@
 			;
 
+		settings.alias().add_key_to_settings(_T("targets/default"))
+
+			(_T("timeout"), sh::uint_key(&timeout, 30),
+			_T("TIMEOUT"), _T("Timeout when reading/writing packets to/from sockets."))
+
+			(_T("sender"), sh::wpath_key(&sender, _T("nscp@localhost")),
+			_T("SENDER"), _T("Sender of email message"))
+
+			(_T("recipient"), sh::wpath_key(&recipient, _T("nscp@localhost")),
+			_T("RECIPIENT"), _T("Recipient of email message"))
+
+			(_T("template"), sh::wpath_key(&template_string, _T("Hello, this is %source% reporting %message%!")),
+			_T("TEMPLATE"), _T("Template for message data"))
+
+			;
+
 		settings.register_all();
 		settings.notify();
@@ -86,16 +101,67 @@
 		get_core()->registerSubmissionListener(get_id(), channel_);
 
+		if (!targets.has_target(_T("default"))) {
+			add_target(_T("default"), _T("default"));
+			targets.rebuild();
+		}
+		nscapi::target_handler::optarget t = targets.find_target(_T("default"));
+		if (t) {
+			if (!t->has_option("template"))
+				t->options[_T("template")] = template_string;
+			if (!t->has_option("timeout"))
+				t->options[_T("timeout")] = strEx::itos(timeout);
+			if (!t->has_option("recipient"))
+				t->options[_T("recipient")] = recipient;
+			if (!t->has_option("sender"))
+				t->options[_T("sender")] = sender;
+			targets.add(*t);
+		} else {
+			NSC_LOG_ERROR(_T("Default target not found!"));
+		}
+
 	} catch (nscapi::nscapi_exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what()));
+		NSC_LOG_ERROR_STD(_T("NSClient API exception: ") + utf8::to_unicode(e.what()));
 		return false;
 	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::cvt<std::wstring>(e.what()));
+		NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::to_unicode(e.what()));
 		return false;
 	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to register command."));
+		NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>"));
 		return false;
 	}
 	return true;
 }
+std::string get_command(std::string alias, std::string command = "") {
+	if (!alias.empty())
+		return alias; 
+	if (!command.empty())
+		return command; 
+	return "TODO";
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Settings helpers
+//
+
+void SMTPClient::add_target(std::wstring key, std::wstring arg) {
+	try {
+		targets.add(get_settings_proxy(), target_path , key, arg);
+	} catch (...) {
+		NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key);
+	}
+}
+
+void SMTPClient::add_command(std::wstring name, std::wstring args) {
+	try {
+		std::wstring key = commands.add_command(name, args);
+		if (!key.empty())
+			register_command(key.c_str(), _T("NRPE relay for: ") + name);
+	} catch (boost::program_options::validation_error &e) {
+		NSC_LOG_ERROR_STD(_T("Could not add command ") + name + _T(": ") + utf8::to_unicode(e.what()));
+	} catch (...) {
+		NSC_LOG_ERROR_STD(_T("Could not add command ") + name);
+	}
+}
+
 /**
  * Unload (terminate) module.
@@ -107,81 +173,84 @@
 }
 
-void SMTPClient::add_target(std::wstring key, std::wstring arg) {
-	try {
-		targets.add(get_settings_proxy(), target_path , key, arg);
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key);
-	}
-}
-void SMTPClient::add_local_options(po::options_description &desc, connection_data &command_data) {
-	/*
-	desc.add_options()
-		("payload-length,l", po::value<unsigned int>(&command_data.payload_length)->zero_tokens()->default_value(512), "The payload length to use in the NSCA packet.")
-		("encryption,e", po::value<std::string>(&command_data.encryption)->default_value("ASE"), "Encryption algorithm to use.")
-		;
-		*/
-}
-
-void SMTPClient::setup(client::configuration &config) {
-	clp_handler_impl *handler = new clp_handler_impl(this);
-	add_local_options(config.local, handler->local_data);
-	config.handler = client::configuration::handler_type(handler);
-}
-
-NSCAPI::nagiosReturn SMTPClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nsca"));
+
+
+NSCAPI::nagiosReturn SMTPClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
+	client::configuration config;
+	setup(config);
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+NSCAPI::nagiosReturn SMTPClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-	message = result.get<1>();
-	return result.get<0>();
-}
-
-
-int SMTPClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("smtp"));
-	if (!client::command_line_parser::is_command(cmd))
-		return NSCAPI::returnIgnored;
-
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn SMTPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-
-NSCAPI::nagiosReturn SMTPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		net::wurl url;
-		url.protocol = _T("smtp");
-		nscapi::target_handler::optarget target = targets.find_target(_T("default"));
-		if (target) {
-			url.host = target->host;
-			url.port = strEx::stoi(target->options[_T("port")]);
-			config.data->recipient.data["template"] = utf8::cvt<std::string>(target->options[_T("template")]);
-			config.data->recipient.data["recipient"] = utf8::cvt<std::string>(target->options[_T("recipient")]);
-			config.data->recipient.data["sender"] = utf8::cvt<std::string>(target->options[_T("sender")]);
+	return client::command_line_parser::do_relay_submit(config, request, result);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Parser setup/Helpers
+//
+
+void SMTPClient::add_local_options(po::options_description &desc, client::configuration::data_type data) {
+
+ 	desc.add_options()
+		("sender", po::value<std::string>()->notifier(boost::bind(&nscapi::functions::destination_container::set_string_data, &data->recipient, "sender", _1)), 
+			"Length of payload (has to be same as on the server)")
+
+		("recipient", po::value<std::string>()->notifier(boost::bind(&nscapi::functions::destination_container::set_string_data, &data->recipient, "recipient", _1)), 
+			"Length of payload (has to be same as on the server)")
+
+		("template", po::value<std::string>()->notifier(boost::bind(&nscapi::functions::destination_container::set_string_data, &data->recipient, "template", _1)), 
+		"Do not initial an ssl handshake with the server, talk in plaintext.")
+ 		;
+}
+
+void SMTPClient::setup(client::configuration &config) {
+	boost::shared_ptr<clp_handler_impl> handler = boost::shared_ptr<clp_handler_impl>(new clp_handler_impl(this));
+	add_local_options(config.local, config.data);
+
+	net::wurl url;
+	url.protocol = _T("smtp");
+	url.port = 25;
+	nscapi::target_handler::optarget opt = targets.find_target(_T("default"));
+	if (opt) {
+		nscapi::target_handler::target t = *opt;
+		url.host = t.host;
+		if (t.has_option("port")) {
+			try {
+				url.port = strEx::stoi(t.options[_T("port")]);
+			} catch (...) {}
 		}
-		config.data->recipient.id = "default";
-		config.data->recipient.address = utf8::cvt<std::string>(url.to_string());
-		config.data->host_self.id = "self";
-		config.data->host_self.host = hostname_;
-
-		setup(config);
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
+		std::string keys[] = {"sender", "timeout", "recipient", "template"};
+		BOOST_FOREACH(std::string s, keys) {
+			config.data->recipient.data[s] = utf8::cvt<std::string>(t.options[utf8::cvt<std::wstring>(s)]);
 		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::cvt<std::wstring>(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	}
+	config.data->recipient.id = "default";
+	config.data->recipient.address = utf8::cvt<std::string>(url.to_string());
+	config.data->host_self.id = "self";
+	//config.data->host_self.host = hostname_;
+
+	config.target_lookup = handler;
+	config.handler = handler;
+}
+
+SMTPClient::connection_data SMTPClient::parse_header(const ::Plugin::Common_Header &header) {
+	nscapi::functions::destination_container recipient;
+	nscapi::functions::parse_destination(header, header.recipient_id(), recipient, true);
+	return connection_data(recipient);
 }
 
@@ -192,4 +261,32 @@
 	return NSCAPI::hasFailed;
 }
+
+int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
+	Plugin::SubmitRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+	std::wstring channel = utf8::cvt<std::wstring>(request_message.channel());
+
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	for (int i=0;i < request_message.payload_size(); ++i) {
+		const ::Plugin::QueryResponseMessage::Response& payload = request_message.payload(i);
+		boost::asio::io_service io_service;
+		boost::shared_ptr<smtp::client::smtp_client> client(new smtp::client::smtp_client(io_service));
+		std::list<std::string> recipients;
+		std::string message = con.template_string;
+		strEx::replace(message, "%message%", payload.message());
+		recipients.push_back(con.recipient_str);
+		client->send_mail(con.sender, recipients, "Hello world\n");
+		io_service.run();
+		nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "TODO", NSCAPI::returnOK, "Message send successfully");
+	}
+
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
+
+}
+
 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
 	NSC_LOG_ERROR_STD(_T("SMTP does not support exec patterns"));
@@ -197,37 +294,13 @@
 }
 
-int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	try {
-
-		Plugin::SubmitRequestMessage message;
-		message.ParseFromString(request);
-
-		std::wstring alias, command, msg, perf;
-		nscapi::functions::destination_container recipient; // = data->host_default_recipient;
-		nscapi::functions::parse_destination(*header, header->recipient_id(), recipient, true);
-		nscapi::functions::destination_container source;
-		nscapi::functions::parse_destination(*header, header->source_id(), source);
-
-		for (int i=0;i < message.payload_size(); ++i) {
-			boost::asio::io_service io_service;
-			boost::shared_ptr<smtp::client::smtp_client> client(new smtp::client::smtp_client(io_service));
-			std::list<std::string> recipients;
-			recipients.push_back("michael@medin.name");
-			client->send_mail("test@test.medin.name", recipients, "Hello world\n");
-			io_service.run();
-		}
-
-		nscapi::functions::create_simple_submit_response(_T(""), _T(""), NSCAPI::isSuccess, _T(""), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::cvt<std::wstring>(e.what()));
-		nscapi::functions::create_simple_submit_response(_T(""), _T(""), NSCAPI::hasFailed, utf8::cvt<std::wstring>(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
-}
+//////////////////////////////////////////////////////////////////////////
+// Protocol implementations
+//
 
 NSC_WRAP_DLL();
 NSC_WRAPPERS_MAIN_DEF(SMTPClient);
 NSC_WRAPPERS_IGNORE_MSG_DEF();
-NSC_WRAPPERS_IGNORE_CMD_DEF();
+NSC_WRAPPERS_HANDLE_CMD_DEF();
+NSC_WRAPPERS_CLI_DEF();
 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF();
+
Index: modules/SMTPClient/SMTPClient.h
===================================================================
--- modules/SMTPClient/SMTPClient.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/SMTPClient/SMTPClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -23,30 +23,81 @@
 
 #include <client/command_line_parser.hpp>
-#include <boost/program_options.hpp>
-
 #include <nscapi/targets.hpp>
 
 NSC_WRAPPERS_MAIN();
+NSC_WRAPPERS_CLI();
 NSC_WRAPPERS_CHANNELS();
+
+namespace po = boost::program_options;
 
 class SMTPClient : public nscapi::impl::simple_plugin {
 private:
 
-	std::string hostname_;
 	std::wstring channel_;
-	nscapi::target_handler targets;
 	std::wstring target_path;
 
-	struct connection_data : public client::nscp_cli_data {};
-	struct clp_handler_impl : public client::clp_handler {
+	nscapi::target_handler targets;
+	client::command_manager commands;
+
+	struct connection_data {
+		std::string recipient_str;
+		std::string sender;
+		std::string template_string;
+		std::string host;
+		std::string port;
+		int timeout;
+
+		connection_data(nscapi::functions::destination_container recipient) {
+			recipient_str = recipient.get_string_data("recipient");
+			timeout = recipient.get_int_data("timeout", 30);
+			sender = recipient.get_string_data("sender");
+			template_string = recipient.get_string_data("template");
+
+			net::url url = recipient.get_url(25);
+			host = url.host;
+			port = url.get_port();
+		}
+
+		std::wstring to_wstring() const {
+			std::wstringstream ss;
+			ss << _T("host: ") << utf8::cvt<std::wstring>(host);
+			ss << _T(", port: ") << utf8::cvt<std::wstring>(port);
+			ss << _T(", timeout: ") << timeout;
+			ss << _T(", recipient: ") << utf8::cvt<std::wstring>(recipient_str);
+			ss << _T(", sender: ") << utf8::cvt<std::wstring>(sender);
+			ss << _T(", template: ") << utf8::cvt<std::wstring>(template_string);
+			return ss.str();
+		}
+	};
+
+	struct clp_handler_impl : public client::clp_handler, client::target_lookup_interface {
 
 		SMTPClient *instance;
 		clp_handler_impl(SMTPClient *instance) : instance(instance) {}
-		connection_data local_data;
 
 		int query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);
 		int submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);
 		int exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply);
+
+		virtual nscapi::functions::destination_container lookup_target(std::wstring &id) {
+			nscapi::functions::destination_container ret;
+			nscapi::target_handler::optarget t = instance->targets.find_target(id);
+			if (t) {
+				if (!t->alias.empty())
+					ret.id = utf8::cvt<std::string>(t->alias);
+				if (!t->host.empty())
+					ret.host = utf8::cvt<std::string>(t->host);
+				if (t->has_option("address"))
+					ret.address = utf8::cvt<std::string>(t->options[_T("address")]);
+				else 
+					ret.address = utf8::cvt<std::string>(t->host);
+				BOOST_FOREACH(const nscapi::target_handler::target::options_type::value_type &kvp, t->options) {
+					ret.data[utf8::cvt<std::string>(kvp.first)] = utf8::cvt<std::string>(kvp.second);
+				}
+			}
+			return ret;
+		}
 	};
+
 
 public:
@@ -70,5 +121,5 @@
 	*/
 	static nscapi::plugin_wrapper::module_version getModuleVersion() {
-		nscapi::plugin_wrapper::module_version version = {0, 3, 0 };
+		nscapi::plugin_wrapper::module_version version = {0, 4, 0 };
 		return version;
 	}
@@ -76,13 +127,21 @@
 		return _T("Passive check support via SMTP");
 	}
-	bool hasNotificationHandler() { return true; }
 
+	bool hasCommandHandler() { return true; };
+	bool hasMessageHandler() { return true; };
+	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
 
+private:
+	static connection_data parse_header(const ::Plugin::Common_Header &header);
+
+private:
+	void add_local_options(po::options_description &desc, client::configuration::data_type data);
 	void setup(client::configuration &config);
-	void add_local_options(boost::program_options::options_description &desc, connection_data &command_data);
+	void add_command(std::wstring key, std::wstring args);
 	void add_target(std::wstring key, std::wstring args);
 
 };
+
Index: modules/Scheduler/Scheduler.cpp
===================================================================
--- modules/Scheduler/Scheduler.cpp	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/Scheduler/Scheduler.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -160,4 +160,5 @@
 		if (code == NSCAPI::returnIgnored) {
 			NSC_LOG_ERROR_STD(_T("Command was not found: ") + item.command.c_str());
+			//make_submit_from_query(response, item.channel, item.alias);
 			nscapi::functions::create_simple_submit_request(item.channel, item.command, NSCAPI::returnUNKNOWN, _T("Command was not found: ") + item.command, _T(""), response);
 			std::string result;
Index: modules/SyslogClient/SyslogClient.cpp
===================================================================
--- modules/SyslogClient/SyslogClient.cpp	(revision 9853bc39a73a5c0e5b135cd88d7a7b8ce7118c7b)
+++ modules/SyslogClient/SyslogClient.cpp	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -222,49 +222,28 @@
 }
 
-NSCAPI::nagiosReturn SyslogClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nsca"));
-
+NSCAPI::nagiosReturn SyslogClient::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("syslog"));
 	client::configuration config;
 	setup(config);
-	if (cmd == _T("query"))
-		return client::command_line_parser::query(config, cmd, arguments, message, perf);
-	if (cmd == _T("submit")) {
-		boost::tuple<int,std::wstring> result = client::command_line_parser::simple_submit(config, cmd, arguments);
-		message = result.get<1>();
-		return result.get<0>();
-	}
-	if (cmd == _T("exec")) {
-		return client::command_line_parser::exec(config, cmd, arguments, message);
-	}
-	return commands.exec_simple(config, target, command, arguments, message, perf);
-}
-
-int SyslogClient::commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {
-	std::wstring cmd = client::command_line_parser::parse_command(command, _T("nsca"));
+	if (!client::command_line_parser::is_command(cmd))
+		return client::command_line_parser::do_execute_command_as_query(config, cmd, data.args, result);
+	return commands.exec_simple(config, data.target, char_command, data.args, result);
+}
+
+NSCAPI::nagiosReturn SyslogClient::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) {
+	nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request);
+	std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("syslog"));
 	if (!client::command_line_parser::is_command(cmd))
 		return NSCAPI::returnIgnored;
-
 	client::configuration config;
 	setup(config);
-	return client::command_line_parser::commandLineExec(config, cmd, arguments, result);
-}
-
-NSCAPI::nagiosReturn SyslogClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) {
-	try {
-		client::configuration config;
-		setup(config);
-
-		if (!client::command_line_parser::relay_submit(config, request, response)) {
-			NSC_LOG_ERROR_STD(_T("Failed to submit message..."));
-			return NSCAPI::hasFailed;
-		}
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::to_unicode(e.what()));
-		return NSCAPI::hasFailed;
-	} catch (...) {
-		NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));
-		return NSCAPI::hasFailed;
-	}
+	return client::command_line_parser::do_execute_command_as_exec(config, cmd, data.args, result);
+}
+
+NSCAPI::nagiosReturn SyslogClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &result) {
+	client::configuration config;
+	setup(config);
+	return client::command_line_parser::do_relay_submit(config, request, result);
 }
 
@@ -343,50 +322,48 @@
 int SyslogClient::clp_handler_impl::query(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
 	NSC_LOG_ERROR_STD(_T("SYSLOG does not support query patterns"));
+	nscapi::functions::create_simple_query_response_unknown(_T("UNKNOWN"), _T("SYSLOG does not support query patterns"), reply);
 	return NSCAPI::hasFailed;
 }
 
 int SyslogClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
-	std::wstring channel;
-	try {
-		Plugin::SubmitRequestMessage message;
-		message.ParseFromString(request);
-		connection_data con = parse_header(*header);
-		channel = utf8::cvt<std::wstring>(message.channel());
-
-		//TODO: Map seveity!
-
-		std::list<std::string> messages;
-		for (int i=0;i < message.payload_size(); ++i) {
-			const ::Plugin::QueryResponseMessage::Response& payload = message.payload(i);
-			std::string date = "Nov 10 00:12:00"; // TODO is this actually used?
-			std::string tag = con.tag_syntax;
-			std::string message = con.message_syntax;
-			strEx::replace(message, "%message%", payload.message());
-			strEx::replace(tag, "%message%", payload.message());
-
-			std::string severity = con.severity;
-			if (payload.result() == ::Plugin::Common_ResultCode_OK)
-				severity = con.ok_severity;
-			if (payload.result() == ::Plugin::Common_ResultCode_WARNING)
-				severity = con.warn_severity;
-			if (payload.result() == ::Plugin::Common_ResultCode_CRITCAL)
-				severity = con.crit_severity;
-			if (payload.result() == ::Plugin::Common_ResultCode_UNKNOWN)
-				severity = con.unknown_severity;
-
-			messages.push_back(instance->parse_priority(severity, con.facility) + date + " " + tag + " " + message);
-		}
-		boost::tuple<int,std::wstring> ret = instance->send(con, messages);
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), ret.get<0>(), _T("Message submitted successfully: ") + ret.get<1>(), reply);
-		return NSCAPI::isSuccess;
-	} catch (std::exception &e) {
-		NSC_LOG_ERROR_STD(_T("Exception: ") + utf8::to_unicode(e.what()));
-		nscapi::functions::create_simple_submit_response(channel, _T("UNKNOWN"), NSCAPI::returnUNKNOWN, utf8::to_unicode(e.what()), reply);
-		return NSCAPI::hasFailed;
-	}
+	Plugin::SubmitRequestMessage request_message;
+	request_message.ParseFromString(request);
+	connection_data con = parse_header(*header);
+
+	Plugin::SubmitResponseMessage response_message;
+	nscapi::functions::make_return_header(response_message.mutable_header(), *header);
+
+	//TODO: Map seveity!
+
+	std::list<std::string> messages;
+	for (int i=0;i < request_message.payload_size(); ++i) {
+		const ::Plugin::QueryResponseMessage::Response& payload = request_message.payload(i);
+		std::string date = "Nov 10 00:12:00"; // TODO is this actually used?
+		std::string tag = con.tag_syntax;
+		std::string message = con.message_syntax;
+		strEx::replace(message, "%message%", payload.message());
+		strEx::replace(tag, "%message%", payload.message());
+
+		std::string severity = con.severity;
+		if (payload.result() == ::Plugin::Common_ResultCode_OK)
+			severity = con.ok_severity;
+		if (payload.result() == ::Plugin::Common_ResultCode_WARNING)
+			severity = con.warn_severity;
+		if (payload.result() == ::Plugin::Common_ResultCode_CRITCAL)
+			severity = con.crit_severity;
+		if (payload.result() == ::Plugin::Common_ResultCode_UNKNOWN)
+			severity = con.unknown_severity;
+
+		messages.push_back(instance->parse_priority(severity, con.facility) + date + " " + tag + " " + message);
+	}
+	boost::tuple<int,std::wstring> ret = instance->send(con, messages);
+	nscapi::functions::append_simple_submit_response_payload(response_message.add_payload(), "UNKNOWN", ret.get<0>(), utf8::cvt<std::string>(ret.get<1>()));
+	response_message.SerializeToString(&reply);
+	return NSCAPI::isSuccess;
 }
 
 int SyslogClient::clp_handler_impl::exec(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &reply) {
 	NSC_LOG_ERROR_STD(_T("SYSLOG does not support exec patterns"));
+	nscapi::functions::create_simple_exec_response_unknown("UNKNOWN", "SYSLOG does not support exec patterns", reply);
 	return NSCAPI::hasFailed;
 }
Index: modules/SyslogClient/SyslogClient.h
===================================================================
--- modules/SyslogClient/SyslogClient.h	(revision 96c146143360e73a3810f89441fef50048f509ca)
+++ modules/SyslogClient/SyslogClient.h	(revision f33c12f03a774b04fde52f07dab7399eddea3d3f)
@@ -32,5 +32,5 @@
 namespace po = boost::program_options;
 
-class SyslogClient : public nscapi::impl::simple_command_handler, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec {
+class SyslogClient : public nscapi::impl::simple_plugin {
 private:
 
@@ -144,6 +144,7 @@
 	bool hasNotificationHandler() { return true; };
 	NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, std::string request, std::string &response);
-	NSCAPI::nagiosReturn handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf);
-	int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);
+	NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response);
+	NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response);
+
 
 private:
