diff options
| -rw-r--r-- | proto_lib/api_protocol.h | 1 | ||||
| -rw-r--r-- | proto_lib/packet.cpp | 29 | 
2 files changed, 28 insertions, 2 deletions
diff --git a/proto_lib/api_protocol.h b/proto_lib/api_protocol.h index af6d84b..88195e2 100644 --- a/proto_lib/api_protocol.h +++ b/proto_lib/api_protocol.h @@ -57,6 +57,7 @@ public:  	//server functions  	static bool serv_validate_client_proto(packet&); //false on fail  	static packet *serv_make_services_packet(std::list<service_s>&); +	static packet *serv_make_command_reply_packet(std::string&, status s);  	//generic  	static packet *make_status_packet(packet_type type, status s); diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp index c9c3d6e..8cf73b2 100644 --- a/proto_lib/packet.cpp +++ b/proto_lib/packet.cpp @@ -200,9 +200,19 @@ std::list<service_s> *packet::cli_extract_services(packet& p)  	return list;  } -std::string packet::cli_parse_command_reply(packet&) +std::string packet::cli_parse_command_reply(packet& p)  { -	return std::string(); +	std::string str; +	std::vector<unsigned char>::const_iterator i = std::search(p.raw().begin(), p.raw().end(), type_command, type_command + sizeof(type_command)); +	if(i != p.raw().end()) +	{ +		i += sizeof(type_command); +		i++; +		 +		for(std::vector<unsigned char>::const_iterator ii = std::search(p.raw().begin(), p.raw().end(), proto_footer, proto_footer + sizeof(proto_footer)); i < ii; ++i) +			str.push_back((char)*i); +	} +	return str;  }  bool packet::serv_validate_client_proto(packet &p) @@ -249,6 +259,21 @@ packet *packet::serv_make_services_packet(std::list<service_s> &slist)  	return new packet(v);  } +packet *packet::serv_make_command_reply_packet(std::string &str, status s) +{ +	std::vector<unsigned char> v; +	pack_serv_header(v); +	pack_buffer(type_command, sizeof(type_command), v); +	v.push_back(s); +	if(!str.empty()) +	{ +		for(size_t i = 0; i < str.length(); i++) +			v.push_back(str[i]); +	} +	pack_buffer(proto_footer, sizeof(proto_footer), v); +	return new packet(v); +} +  packet *packet::make_status_packet(packet_type t, status s)  {  	const unsigned char *type = to_internal_type(t);  | 
