summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-02-13 18:05:13 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-02-13 18:05:13 +0200
commit49729a7593320662545b7c795f028d0f87827b0f (patch)
tree7bba69ac6cca15c29d1187c7267bf917fae14fa3
parente255c37eca94d4d9c23f689b473b106575b9e2fa (diff)
proto lib fixes
-rw-r--r--proto_lib/api_protocol.h6
-rw-r--r--proto_lib/packet.cpp45
-rw-r--r--proto_lib/utilities.cpp8
-rw-r--r--proto_test/main.cpp23
-rw-r--r--proto_test/proto_test.project3
-rw-r--r--restarter.workspace2
6 files changed, 45 insertions, 42 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);
}
diff --git a/proto_test/main.cpp b/proto_test/main.cpp
index 28d04e9..ba0b8e8 100644
--- a/proto_test/main.cpp
+++ b/proto_test/main.cpp
@@ -76,6 +76,7 @@ bool test_services_extraction()
c.description = "command 3 desc";
s1.cmds.push_back(c);
list1.push_back(s1);
+ s1.cmds.clear();
s1.service = "sd,fhjsiufhifhirhwiefbbbbvwyefgweyfuyvbwf service 2 aaaaaaaaaaaaaaaaaa111111111111111111111111asdasdasd";
c.command = "2command 1";
c.description = "2some desc";
@@ -87,6 +88,7 @@ bool test_services_extraction()
c.description = "2command 3 desc";
s1.cmds.push_back(c);
list1.push_back(s1);
+ s1.cmds.clear();
s1.service = "sd,fhjsiufhiadadsdfgdffghghjbnfdghdgffhirhwiefbbbbvwyefgweyfuyvbwf service 2 aaaaaaaaaaaaaaaaaa111111111111111111111111asdasdasd";
c.command = "32commanasdasdd 1";
c.description = "32some desc";
@@ -101,13 +103,24 @@ bool test_services_extraction()
delete p;
p = packet::serv_make_services_packet(list1);
std::list<service_s> *list2 = packet::cli_extract_services(*p);
- for(std::list<service_s>::iterator i = list2->begin(), end = list2->end(); i != end; ++i)
+/* std::cout<<"\n\nlist1 content\n\n\n";
+ for(std::list<service_s>::iterator i = list1.begin(), end = list1.end(); i != end; ++i)
{
- //if(std::find(list1.begin(), list1.end(), *i) == list1.end()) //fuck
- for(std::list<service_s>::iterator ii = list1.begin(), end = list1.end(); ii != end; ++ii)
- if(*ii != *i)
- return false;
+ std::cout<<"service name: "<<i->service<<"\n\t";
+ for(std::list<service_s::cmd>::iterator ii = i->cmds.begin(), eend = i->cmds.end(); ii != eend; ++ii)
+ std::cout<<ii->command<<"|"<<ii->description<<"; ";
+ std::cout<<"\n\n";
}
+ std::cout<<"\n\nlist2 content\n\n\n";
+ for(std::list<service_s>::iterator i = list2->begin(), end = list2->end(); i != end; ++i)
+ {
+ std::cout<<"service name: "<<i->service<<"\n\t";
+ for(std::list<service_s::cmd>::iterator ii = i->cmds.begin(), eend = i->cmds.end(); ii != eend; ++ii)
+ std::cout<<ii->command<<"|"<<ii->description<<"; ";
+ std::cout<<"\n\n";
+ } */
+ if(list1 != *list2)
+ return false;
return true;
}
diff --git a/proto_test/proto_test.project b/proto_test/proto_test.project
index ffb4e33..63124f1 100644
--- a/proto_test/proto_test.project
+++ b/proto_test/proto_test.project
@@ -70,7 +70,8 @@
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
- <![CDATA[]]>
+ <![CDATA[
+ ]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
<PostConnectCommands/>
diff --git a/restarter.workspace b/restarter.workspace
index bb329b0..371c615 100644
--- a/restarter.workspace
+++ b/restarter.workspace
@@ -7,6 +7,8 @@
<![CDATA[
+
+
]]>
</Environment>
<Project Name="proto_test" Path="proto_test/proto_test.project" Active="Yes"/>