// 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 #include #include #include #include "api_protocol.h" #include "packet.h" bool serv_validate_client_proto(packet &p) { const std::vector &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::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 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; }