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;
for (it = response_variables_.begin(); it != response_variables_.end(); ++it)
{
std::cout << std::setw(22) << it->first << ": " << it->second <<
std::endl;
std::cout << it->first << ": " << it->second << std::endl;
}
}
@ -69,7 +68,6 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
/*
* 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
if (i >= rsp_to_parse.npos)
@ -78,12 +76,6 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
return;
}
struct
{
std::string address;
unsigned short port;
} server;
while (i < rsp_to_parse.npos)
{
// 'EOT' found, abort successfully
@ -100,21 +92,14 @@ void ETParser::ParseResponse(std::string rsp_to_parse)
}
// parse out ip
std::stringstream ss;
ss << (int)(unsigned char)rsp_to_parse[i++] << "."
std::stringstream server_addr;
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++];
server.address = ss.str();
<< (int)(unsigned char)rsp_to_parse[i++] << ":"
<< (unsigned short)((rsp_to_parse[i++] << 8) + rsp_to_parse[i++]);
// parse out port
server.port = rsp_to_parse[i++] << 8;
server.port += rsp_to_parse[i++];
std::cout << "|" << servernr << "| "
<< server.address << ":" << server.port << std::endl;
servernr++;
add_variable("server", server_addr.str());
// should never happen
if (rsp_to_parse[i++] != '\\')

View file

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