Revision: 8ce6ee3cad09: print errors in more convenient way Revision: 502a2c7e81bf: renamed (Gb, Mb, Kb) -> (GB, MB, KB) as bytes Revision: f04cf1d965bc: sqstat: reworked parsing peer info to properly handle ipv6 addresses Revision: 9cafb9feb080: sqstat: added support for squid 3.2 HTTP/1.1 responses (thanks to cccarlos...@gmail.com) Revision: dc33d36f6c17: fixed to work with squid3.3.5 Index: src/sqstat.cpp --- src/sqstat.cpp.orig +++ src/sqstat.cpp @@ -195,7 +195,7 @@ string sqstat::SpeedsFormat(Options::SPEED_MODE mode, break; } case Options::SPEED_AVERAGE: - result << "average speed: " + av_speed_pair.first + " " + av_speed_pair.second; + result << "average speed: " + av_speed_pair.first + av_speed_pair.second; break; }; return result.str(); @@ -253,9 +253,9 @@ Uri_Stats sqstat::FindUriStatsById(vector sqstat::GetInfo(Options* pOpt while ((con >> temp_str) != 0) { if (connections.size()==0) { if (n==0) { - if (temp_str != "HTTP/1.0 200 OK" && temp_str != "HTTP/1.1 200 OK") { + if (temp_str != "HTTP/1.0 200 OK") { std::stringstream error; - error << "Access to squid statistic denied: " << temp_str; + error << "Access to squid statistic denied: " << temp_str << endl << endl; /*string ip; try { ip = get_ip(); @@ -322,10 +322,10 @@ vector sqstat::GetInfo(Options* pOpt catch (string) { ip = ""; }*/ - /*error << "You must enable access to squid statistic in squid.conf by adding strings like:" << endl << endl; + error << "You must enable access to squid statistic in squid.conf by adding strings like:" << endl << endl; error << "\tacl adminhost src /255.255.255.255" << endl; error << "\thttp_access allow manager adminhost" << endl; - error << "\thttp_access deny manager";*/ + error << "\thttp_access deny manager"; throw sqstatException(error.str(), ACCESS_DENIED); } else { n=1; @@ -355,25 +355,23 @@ vector sqstat::GetInfo(Options* pOpt newStats.etime = 0; newStats.delay_pool = -1; } else { FormatChanged(temp_str); } - } else if ((temp_str.substr(0,6) == "peer: ") or (temp_str.substr(0,8) == "remote: ")) { - result = Utils::SplitString(temp_str, " "); - if (result.size() == 2) { - std::pair peer = Utils::SplitIPPort(result[1]); - if (!peer.first.empty()) { - Conn_it = std::find_if( connections.begin(), connections.end(), std::bind2nd( std::ptr_fun(ConnByPeer) , peer.first) ); - // if it is new peer, create new SQUID_Connection - if (Conn_it == connections.end()) { - SQUID_Connection connection; - connection.peer = peer.first; + } else if (temp_str.substr(0,6) == "peer: ") { + result = Utils::SplitString(temp_str, ":"); + if (result.size() == 3) { + string peer = result[1].substr(1); + Conn_it = std::find_if( connections.begin(), connections.end(), std::bind2nd( std::ptr_fun(ConnByPeer) , peer) ); + // if it is new peer, create new SQUID_Connection + if (Conn_it == connections.end()) { + SQUID_Connection connection; + connection.peer = peer; #ifdef WITH_RESOLVER - connection.hostname = DoResolve(pOpts, peer.first); + connection.hostname = DoResolve(pOpts, peer); #endif - connections.push_back(connection); - Conn_it = connections.end() - 1; - } - Conn_it->stats.push_back(newStats); - Stat_it = Conn_it->stats.end() - 1; + connections.push_back(connection); + Conn_it = connections.end() - 1; } + Conn_it->stats.push_back(newStats); + Stat_it = Conn_it->stats.end() - 1; } else { FormatChanged(temp_str); } } else if (temp_str.substr(0,4) == "uri ") { result = Utils::SplitString(temp_str, " ");