diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-13 18:05:13 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-13 18:05:13 +0200 |
commit | 49729a7593320662545b7c795f028d0f87827b0f (patch) | |
tree | 7bba69ac6cca15c29d1187c7267bf917fae14fa3 /proto_lib | |
parent | e255c37eca94d4d9c23f689b473b106575b9e2fa (diff) |
proto lib fixes
Diffstat (limited to 'proto_lib')
-rw-r--r-- | proto_lib/api_protocol.h | 6 | ||||
-rw-r--r-- | proto_lib/packet.cpp | 45 | ||||
-rw-r--r-- | proto_lib/utilities.cpp | 8 |
3 files changed, 23 insertions, 36 deletions
diff --git a/proto_lib/api_protocol.h b/proto_lib/api_protocol.h index bebd401..afa8224 100644 --- a/proto_lib/api_protocol.h +++ b/proto_lib/api_protocol.h @@ -25,14 +25,14 @@ struct service_s { std::string command, description; #ifdef DEBUG - bool operator==(const cmd&); + bool operator==(const cmd&) const; #endif }; std::string service; std::list<cmd> cmds; #ifdef DEBUG - bool operator==(service_s&); - bool operator!=(service_s&); + bool operator==(const service_s&) const; + bool operator!=(const service_s&) const; #endif }; diff --git a/proto_lib/packet.cpp b/proto_lib/packet.cpp index 92d8508..0487f4f 100644 --- a/proto_lib/packet.cpp +++ b/proto_lib/packet.cpp @@ -170,41 +170,27 @@ std::list<service_s> *packet::cli_extract_services(packet& p) for(; i < i2; ++i) service.push_back((char)*i); i2++; + i = i2; i2 = std::find(i2, i3, delimiter); - bool bdesc = false; std::string cmd, desc; while(i2 < i3) { cmd.clear(); desc.clear(); - if(!bdesc) - { - i++; //wtf ? - for(; i < i2; ++i) - cmd.push_back((char)*i); - bdesc = true; - } - else - { - i++; //wtf ? - for(; i < i2; ++i) - desc.push_back((char)*i); - bdesc = false; - service_s::cmd c; - c.command = cmd; - c.description = desc; - cmds.push_back(c); - } + for(; i < i2; ++i) + cmd.push_back((char)*i); i2++; + i = i2; + i2 = std::find(i2, i3, delimiter); + for(; i < i2; ++i) + desc.push_back((char)*i); + service_s::cmd c; + c.command = cmd; + c.description = desc; + cmds.push_back(c); + i2++; + i = i2; i2 = std::find(i2, i3, delimiter); } - i++; //wtf ? - desc.clear(); - for(; i < i2; ++i) - desc.push_back((char)*i); - service_s::cmd c; - c.command = cmd; - c.description = desc; - cmds.push_back(c); } else //found service without commands { @@ -219,6 +205,7 @@ std::list<service_s> *packet::cli_extract_services(packet& p) s.cmds = cmds; s.service = service; list->push_back(s); + i++; } } return list; @@ -250,10 +237,10 @@ bool packet::serv_validate_client_proto(packet &p) return false; i += sizeof(type_auth); i++; //wtf ? -#ifdef DEBUG +/*#ifdef DEBUG printf("version found %d\n", *i); printf("actual version %d\n", proto_version); -#endif +#endif*/ if(*i < proto_version) return false; return true; diff --git a/proto_lib/utilities.cpp b/proto_lib/utilities.cpp index b54e45a..ee5e9b4 100644 --- a/proto_lib/utilities.cpp +++ b/proto_lib/utilities.cpp @@ -82,7 +82,7 @@ const unsigned char *to_internal_type(packet_type t) } #ifdef DEBUG -bool service_s::cmd::operator==(const cmd& c) +bool service_s::cmd::operator==(const cmd& c) const { if(c.command != command) return false; @@ -91,18 +91,18 @@ bool service_s::cmd::operator==(const cmd& c) return true; } -bool service_s::operator==(service_s& s) +bool service_s::operator==(const service_s& s) const { if(s.service != service) return false; - for(std::list<service_s::cmd>::iterator i = s.cmds.begin(), end = s.cmds.end(); i != end; ++i) + for(std::list<service_s::cmd>::const_iterator i = s.cmds.begin(), end = s.cmds.end(); i != end; ++i) { if(std::find(cmds.begin(), cmds.end(), *i) == cmds.end()) return false; } return true; } -bool service_s::operator!=(service_s& s) +bool service_s::operator!=(const service_s& s) const { return !(*this == s); } |