mirror of
https://github.com/etlegacy/etlegacy-tools.git
synced 2024-11-21 11:31:22 +00:00
etlist: cleaned up getserversResponse parsing
This commit is contained in:
parent
38369febf3
commit
471f474107
2 changed files with 9 additions and 25 deletions
|
@ -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,8 +68,7 @@ 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
|
||||
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++] << "."
|
||||
<< (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();
|
||||
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++] << ":"
|
||||
<< (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++] != '\\')
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <iomanip> // using 'setw'
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
|
Loading…
Reference in a new issue