From 1e4aaa2f93cc0a5c394a03d53c6707fe98c0c1c2 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 12 Feb 2013 14:23:46 +0200 Subject: working with proto lib --- proto_lib/packet.cpp | 67 +++++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) (limited to 'proto_lib/packet.cpp') 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 #include "api_protocol.h" #include "packet.h" +#include "utilities.h" -packet::packet() -{ -} packet::packet(std::vector& new_data) { @@ -98,50 +96,16 @@ packet_type packet::get_type() return UNKNOWN; } -void pack_cli_header(std::vector &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 &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 &v) -{ - for(size_t i = 0; i < len; i++) - v.push_back(buf[i]); -} - -void pack_buffer(std::vector &source, std::vector &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::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 &v) -{ - for(size_t i = 0; i < str.length(); i++) - v.push_back(str[i]); -} - -void pack_buffer(const char* str, std::vector &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 *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 &data = p.raw(); @@ -280,8 +249,9 @@ packet *packet::serv_make_services_packet(std::list &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 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::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::const_iterator i = std::search(data.begin(), data.end(), type, type + sizeof(type)); + if(i != data.end()) { i += sizeof(type); if(*i == success) -- cgit v1.2.3