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.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp
index 8cf73b2..0ed3150 100644
--- a/proto_lib/packet.cpp
+++ b/proto_lib/packet.cpp
@@ -22,7 +22,8 @@
#include "packet.h"
#include "utilities.h"
-
+namespace proto
+{
packet::packet(std::vector<unsigned char>& new_data)
{
@@ -41,6 +42,11 @@ bool packet::assign(std::vector<unsigned char>& v)
return is_good();
}
+const std::vector<unsigned char> &packet::raw()
+{
+ return data;
+}
+
bool packet::is_good()
{
if(data.empty())
@@ -88,12 +94,12 @@ packet_type packet::get_type()
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?AUTH_REQUEST:AUTH_REPLY;
+ return cli?TYPE_AUTH_REQUEST:TYPE_AUTH_REPLY;
if(std::search(type.begin(), type.end(), type_services, type_services + sizeof(type_services)) != type.end())
- return cli?SERVICES_REQUEST:SERVICES_REPLY;
+ return cli?TYPE_SERVICES_REQUEST:TYPE_SERVICES_REPLY;
if(std::search(type.begin(), type.end(), type_command, type_command + sizeof(type_command)) != type.end())
- return cli?COMMAND_REQUEST:COMMAND_REPLY;
- return UNKNOWN;
+ return cli?TYPE_COMMAND_REQUEST:TYPE_COMMAND_REPLY;
+ return TYPE_UNKNOWN;
}
bool packet::is_status_packet()
@@ -101,13 +107,13 @@ 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);
- if(*i == success || *i == failure)
+ if(*i == STATUS_SUCCESS || *i == STATUS_FAILURE)
return true;
return false;
}
-packet *packet::cli_make_auth_packet()
+packet *packet::cli_make_init_packet()
{
std::vector<unsigned char> v;
pack_cli_header(v);
@@ -292,8 +298,31 @@ bool packet::check_status()
if(i != data.end())
{
i += sizeof(type);
- if(*i == success)
+ if(*i == STATUS_SUCCESS)
return true;
}
return false;
}
+
+svc_cmd packet::serv_extract_command(packet& p)
+{
+ svc_cmd c;
+ 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);
+ std::vector<unsigned char>::const_iterator i2 = std::find(i, p.raw().end(), delimiter);
+ if(i2 != p.raw().end())
+ {
+ for(; i < i2; ++i)
+ c.service.push_back((char)*i);
+ i++;
+ i2 = std::search(p.raw().begin(), p.raw().end(), proto_footer, proto_footer + sizeof(proto_footer));
+ for(; i < i2; ++i)
+ c.command.push_back((char)*i);
+ }
+ }
+ return c;
+}
+
+};