From b69d6a602a8c2a771de023b59f45c693e52faee9 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 12 Feb 2013 14:45:56 +0200 Subject: basic protocol implemented (untested) --- proto_lib/packet.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'proto_lib/packet.cpp') 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 *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::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::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 &slist) return new packet(v); } +packet *packet::serv_make_command_reply_packet(std::string &str, status s) +{ + std::vector 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); -- cgit v1.2.3