diff options
Diffstat (limited to 'proto_lib/packet.cpp')
-rw-r--r-- | proto_lib/packet.cpp | 67 |
1 files changed, 19 insertions, 48 deletions
diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp index c52c24d..c9c3d6e 100644 --- a/proto_lib/packet.cpp +++ b/proto_lib/packet.cpp @@ -20,11 +20,9 @@ #include <string.h> #include "api_protocol.h" #include "packet.h" +#include "utilities.h" -packet::packet() -{ -} packet::packet(std::vector<unsigned char>& new_data) { @@ -98,50 +96,16 @@ packet_type packet::get_type() return UNKNOWN; } -void pack_cli_header(std::vector<unsigned char> &v) -{ - int size = sizeof(proto_header); - for(int i = 0; i < size; i++) - v.push_back(proto_header[i]); - size = sizeof(cli_packet); - for(int i = 0; i < size; i++) - v.push_back(cli_packet[i]); -} - -void pack_serv_header(std::vector<unsigned char> &v) -{ - int size = sizeof(proto_header); - for(int i = 0; i < size; i++) - v.push_back(proto_header[i]); - size = sizeof(serv_packet); - for(int i = 0; i < size; i++) - v.push_back(serv_packet[i]); -} - - -void pack_buffer(const unsigned char *buf, size_t len, std::vector<unsigned char> &v) -{ - for(size_t i = 0; i < len; i++) - v.push_back(buf[i]); -} - -void pack_buffer(std::vector<unsigned char> &source, std::vector<unsigned char> &dest) +bool packet::is_status_packet() { - dest.insert(dest.end(), source.begin(), source.end()); + const unsigned char *type = to_internal_type(get_type()); + std::vector<unsigned char>::iterator i = std::search(data.begin(), data.end(), type, type + sizeof(type)); + i += sizeof(type); + if(*i == success || *i == failure) + return true; + return false; } -void pack_buffer(std::string &str, std::vector<unsigned char> &v) -{ - for(size_t i = 0; i < str.length(); i++) - v.push_back(str[i]); -} - -void pack_buffer(const char* str, std::vector<unsigned char> &v) -{ - size_t len = strlen(str); - for(size_t i = 0; i < len; i++) - v.push_back(str[i]); -} packet *packet::cli_make_auth_packet() { @@ -236,6 +200,11 @@ std::list<service_s> *packet::cli_extract_services(packet& p) return list; } +std::string packet::cli_parse_command_reply(packet&) +{ + return std::string(); +} + bool packet::serv_validate_client_proto(packet &p) { const std::vector<unsigned char> &data = p.raw(); @@ -280,8 +249,9 @@ packet *packet::serv_make_services_packet(std::list<service_s> &slist) return new packet(v); } -packet *packet::make_status_packet(const unsigned char* type, status s) +packet *packet::make_status_packet(packet_type t, status s) { + const unsigned char *type = to_internal_type(t); std::vector<unsigned char> v; pack_serv_header(v); pack_buffer(type, sizeof(type), v); @@ -290,10 +260,11 @@ packet *packet::make_status_packet(const unsigned char* type, status s) return new packet(v); } -bool packet::check_status_packet(const unsigned char *type, packet& p) +bool packet::check_status() { - std::vector<unsigned char>::const_iterator i = std::search(p.raw().begin(), p.raw().end(), type, type + sizeof(type)); - if(i != p.raw().end()) + const unsigned char *type = to_internal_type(get_type()); + std::vector<unsigned char>::const_iterator i = std::search(data.begin(), data.end(), type, type + sizeof(type)); + if(i != data.end()) { i += sizeof(type); if(*i == success) |