diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-11 02:12:12 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-11 02:12:12 +0200 |
commit | 5a81b0e272a6e456e8c29ce2e755ac4e1c8b5546 (patch) | |
tree | fe3f315cf3ebf102ca5d6b8529fc172ab55c9352 /proto_lib/protocol.cpp | |
parent | 94a11e7736df09143fd7cf1a75282dc9b408fbd9 (diff) |
started separated proto lib implementation
started modules support implementation
Diffstat (limited to 'proto_lib/protocol.cpp')
-rw-r--r-- | proto_lib/protocol.cpp | 64 |
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; +} + |