etlist: cleaned up getserversResponse parsing

This commit is contained in:
Radegast 2012-10-14 00:47:05 +01:00
parent 38369febf3
commit 471f474107
2 changed files with 9 additions and 25 deletions

View file

@ -34,8 +34,7 @@ ETParser::ETParser(std::vector<std::string> packets)
std::map <std::string, std::string>::iterator it; std::map <std::string, std::string>::iterator it;
for (it = response_variables_.begin(); it != response_variables_.end(); ++it) for (it = response_variables_.begin(); it != response_variables_.end(); ++it)
{ {
std::cout << std::setw(22) << it->first << ": " << it->second << std::cout << it->first << ": " << it->second << std::endl;
std::endl;
} }
} }
@ -69,8 +68,7 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
/* /*
* The following code was adapted from the Wetsi project * The following code was adapted from the Wetsi project
*/ */
static int servernr = 1; int i = rsp_to_parse.find('\\') + 1; // skip to the first item
int i = rsp_to_parse.find('\\') + 1; // skip to the first item
if (i >= rsp_to_parse.npos) if (i >= rsp_to_parse.npos)
{ {
@ -78,12 +76,6 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
return; return;
} }
struct
{
std::string address;
unsigned short port;
} server;
while (i < rsp_to_parse.npos) while (i < rsp_to_parse.npos)
{ {
// 'EOT' found, abort successfully // 'EOT' found, abort successfully
@ -100,21 +92,14 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
} }
// parse out ip // parse out ip
std::stringstream ss; std::stringstream server_addr;
ss << (int)(unsigned char)rsp_to_parse[i++] << "." server_addr << (int)(unsigned char)rsp_to_parse[i++] << "."
<< (int)(unsigned char)rsp_to_parse[i++] << "." << (int)(unsigned char)rsp_to_parse[i++] << "."
<< (int)(unsigned char)rsp_to_parse[i++] << "." << (int)(unsigned char)rsp_to_parse[i++] << "."
<< (int)(unsigned char)rsp_to_parse[i++]; << (int)(unsigned char)rsp_to_parse[i++] << ":"
server.address = ss.str(); << (unsigned short)((rsp_to_parse[i++] << 8) + rsp_to_parse[i++]);
// parse out port add_variable("server", server_addr.str());
server.port = rsp_to_parse[i++] << 8;
server.port += rsp_to_parse[i++];
std::cout << "|" << servernr << "| "
<< server.address << ":" << server.port << std::endl;
servernr++;
// should never happen // should never happen
if (rsp_to_parse[i++] != '\\') if (rsp_to_parse[i++] != '\\')

View file

@ -24,7 +24,6 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <map> #include <map>
#include <iomanip> // using 'setw'
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>