summaryrefslogtreecommitdiff
path: root/proto_lib/protocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'proto_lib/protocol.cpp')
-rw-r--r--proto_lib/protocol.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/proto_lib/protocol.cpp b/proto_lib/protocol.cpp
new file mode 100644
index 0000000..e709415
--- /dev/null
+++ b/proto_lib/protocol.cpp
@@ -0,0 +1,64 @@
+// Copyright © 2013 sss
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <string>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include "api_protocol.h"
+#include "packet.h"
+
+
+
+bool 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())
+ return false;
+ if(std::search(data.begin(), data.end(), proto_footer, proto_footer + sizeof(proto_footer)) == data.end())
+ 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())
+ return false;
+ i += sizeof(cli_packet);
+ if(*i < proto_version)
+ return false;
+ return true;
+}
+
+packet cli_make_auth_packet()
+{
+ 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]);
+ size = sizeof(type_auth);
+ for(int i = 0; i < size; i++)
+ v.push_back(type_auth[i]);
+ v.push_back(proto_version);
+ size = sizeof(proto_footer);
+ for(int i = 0; i < size; i++)
+ v.push_back(proto_footer[i]);
+ packet *p = new packet;
+ p->assign(v);
+ return *p;
+}
+