summaryrefslogtreecommitdiff
path: root/proto_lib/packet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'proto_lib/packet.cpp')
-rw-r--r--proto_lib/packet.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp
index 0487f4f..8dc1b12 100644
--- a/proto_lib/packet.cpp
+++ b/proto_lib/packet.cpp
@@ -93,21 +93,20 @@ packet_type packet::get_type()
type.push_back(*i);
i++;
type.push_back(*i);
- bool cli = is_client_packet();
if(std::search(type.begin(), type.end(), type_auth, type_auth + sizeof(type_auth)) != type.end())
- return cli?TYPE_AUTH_REQUEST:TYPE_AUTH_REPLY;
+ return TYPE_AUTH;
if(std::search(type.begin(), type.end(), type_services, type_services + sizeof(type_services)) != type.end())
- return cli?TYPE_SERVICES_REQUEST:TYPE_SERVICES_REPLY;
+ return TYPE_SERVICES;
if(std::search(type.begin(), type.end(), type_command, type_command + sizeof(type_command)) != type.end())
- return cli?TYPE_COMMAND_REQUEST:TYPE_COMMAND_REPLY;
+ return TYPE_COMMAND;
return TYPE_UNKNOWN;
}
bool packet::is_status_packet()
{
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);
+ std::vector<unsigned char>::iterator i = std::search(data.begin(), data.end(), type, type + 2);
+ i += 2;
if(*i == STATUS_SUCCESS || *i == STATUS_FAILURE)
return true;
return false;
@@ -283,6 +282,12 @@ packet *packet::serv_make_command_reply_packet(std::string &str, status s)
return new packet(v);
}
+packet *packet::serv_make_command_reply_packet(const char* data, status s)
+{
+ std::string str = data;
+ return serv_make_command_reply_packet(str, s);
+}
+
packet *packet::serv_make_command_reply_packet(std::vector<unsigned char>& data, status s)
{
std::vector<unsigned char> v;
@@ -294,28 +299,33 @@ packet *packet::serv_make_command_reply_packet(std::vector<unsigned char>& data,
return new packet(v);
}
-packet *packet::make_status_packet(packet_type t, status s)
+packet *packet::cli_make_status_packet(packet_type type, status s)
+{
+ std::vector<unsigned char> v;
+ pack_cli_header(v);
+ make_status_packet(type, s, v);
+ return new packet(v);
+}
+
+packet *packet::serv_make_status_packet(packet_type type, 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);
- v.push_back(s);
- pack_buffer(proto_footer, sizeof(proto_footer), v);
+ make_status_packet(type, s, v);
return new packet(v);
}
-bool packet::check_status()
+
+status packet::get_status()
{
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));
+ std::vector<unsigned char>::const_iterator i = std::search(data.begin(), data.end(), type, type + 2);
if(i != data.end())
{
- i += sizeof(type);
- if(*i == STATUS_SUCCESS)
- return true;
+ i += 2;
+ return (status)*i;
}
- return false;
+ return STATUS_FAILURE;
}
svc_cmd packet::serv_extract_command(packet& p)