diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-13 03:20:52 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-13 03:20:52 +0200 |
commit | e255c37eca94d4d9c23f689b473b106575b9e2fa (patch) | |
tree | 0d7916bcd872d3da2367acbec6d0594c837193fd /proto_lib/packet.cpp | |
parent | 85a13d70cc5249e2f583bb16f0914646aefe4fe6 (diff) |
some testing code
Diffstat (limited to 'proto_lib/packet.cpp')
-rw-r--r-- | proto_lib/packet.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp index 92272a8..92d8508 100644 --- a/proto_lib/packet.cpp +++ b/proto_lib/packet.cpp @@ -18,6 +18,7 @@ #include <vector> #include <algorithm> #include <string.h> +#include <stdio.h> #include "api_protocol.h" #include "packet.h" #include "utilities.h" @@ -135,6 +136,12 @@ packet *packet::cli_make_command_packet(std::string &service, std::string &comma return new packet(v); } +packet *packet::cli_make_command_packet(const char* service, const char* command) +{ + std::string s = service, c = command; + return cli_make_command_packet(s, c); +} + packet *packet::cli_make_request_services_packet() { std::vector<unsigned char> v; @@ -165,17 +172,20 @@ std::list<service_s> *packet::cli_extract_services(packet& p) i2++; i2 = std::find(i2, i3, delimiter); bool bdesc = false; + std::string cmd, desc; while(i2 < i3) { - std::string cmd, desc; + cmd.clear(); desc.clear(); if(!bdesc) { + i++; //wtf ? for(; i < i2; ++i) cmd.push_back((char)*i); bdesc = true; } else { + i++; //wtf ? for(; i < i2; ++i) desc.push_back((char)*i); bdesc = false; @@ -187,6 +197,14 @@ std::list<service_s> *packet::cli_extract_services(packet& p) i2++; i2 = std::find(i2, i3, delimiter); } + i++; //wtf ? + desc.clear(); + for(; i < i2; ++i) + desc.push_back((char)*i); + service_s::cmd c; + c.command = cmd; + c.description = desc; + cmds.push_back(c); } else //found service without commands { @@ -194,8 +212,8 @@ std::list<service_s> *packet::cli_extract_services(packet& p) service.push_back((char)*i); } i = i3; - i2 = std::find(i, p.raw().end(), delimiter); - i3 = std::find(i, p.raw().end(), block_end); + i2 = std::find(i+1, p.raw().end(), delimiter); + i3 = std::find(i+1, p.raw().end(), block_end); } service_s s; s.cmds = cmds; @@ -223,17 +241,19 @@ std::string packet::cli_parse_command_reply(packet& p) bool packet::serv_validate_client_proto(packet &p) { - const std::vector<unsigned char> &data = p.raw(); - if(data.empty()) - return false; - if(std::search(data.begin(), data.end(), proto_header, proto_header + sizeof(proto_header)) == data.end()) + if(!p.is_good()) return false; - if(std::search(data.begin(), data.end(), proto_footer, proto_footer + sizeof(proto_footer)) == data.end()) + if(!p.is_client_packet()) return false; - std::vector<unsigned char>::const_iterator i = std::search(data.begin(), data.end(), cli_packet, cli_packet + sizeof(cli_packet)); - if(i == data.end()) + std::vector<unsigned char>::const_iterator i = std::search(p.raw().begin(), p.raw().end(), type_auth, type_auth + sizeof(type_auth)); + if(i == p.raw().end()) return false; - i += sizeof(cli_packet); + i += sizeof(type_auth); + i++; //wtf ? +#ifdef DEBUG + printf("version found %d\n", *i); + printf("actual version %d\n", proto_version); +#endif if(*i < proto_version) return false; return true; |