summaryrefslogtreecommitdiff
path: root/proto_lib/packet.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-02-12 14:45:56 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-02-12 14:45:56 +0200
commitb69d6a602a8c2a771de023b59f45c693e52faee9 (patch)
treed0bd8e3b3a75c348a71dc471d3cedc0cf7e64909 /proto_lib/packet.cpp
parent1e4aaa2f93cc0a5c394a03d53c6707fe98c0c1c2 (diff)
basic protocol implemented (untested)
Diffstat (limited to 'proto_lib/packet.cpp')
-rw-r--r--proto_lib/packet.cpp29
1 files changed, 27 insertions, 2 deletions
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);