From c7013adfd4159bb71e6ef8bd3d84f3cf6077d2f6 Mon Sep 17 00:00:00 2001 From: Markus Grimm Date: Fri, 29 Dec 2017 23:45:10 +0100 Subject: [PATCH 1/3] Close sockets when server responds with HTTP/1.0 --- clients/roscpp/src/libros/xmlrpc_manager.cpp | 2 +- utilities/xmlrpcpp/src/XmlRpcClient.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clients/roscpp/src/libros/xmlrpc_manager.cpp b/clients/roscpp/src/libros/xmlrpc_manager.cpp index 15175ff5e7..930036d414 100644 --- a/clients/roscpp/src/libros/xmlrpc_manager.cpp +++ b/clients/roscpp/src/libros/xmlrpc_manager.cpp @@ -370,7 +370,7 @@ void XMLRPCManager::releaseXMLRPCClient(XmlRpcClient *c) { if (c == i->client_) { - if (shutting_down_) + if (shutting_down_ || !c->getKeepOpen()) { // if we are shutting down we won't be re-using the client i->client_->close(); diff --git a/utilities/xmlrpcpp/src/XmlRpcClient.cpp b/utilities/xmlrpcpp/src/XmlRpcClient.cpp index b53305968b..ce56eb3250 100644 --- a/utilities/xmlrpcpp/src/XmlRpcClient.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcClient.cpp @@ -107,6 +107,7 @@ XmlRpcClient::execute(const char* method, XmlRpcValue const& params, XmlRpcValue return false; XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s completed.", method); + _header = ""; _response = ""; return true; } @@ -403,7 +404,6 @@ XmlRpcClient::readHeader() // Otherwise copy non-header data to response buffer and set state to read response. _response = bp; - _header = ""; // should parse out any interesting bits from the header (connection, etc)... _connectionState = READ_RESPONSE; return true; // Continue monitoring this source } @@ -447,6 +447,7 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) int offset = 0; if ( ! XmlRpcUtil::findTag(METHODRESPONSE_TAG,_response,&offset)) { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s", _response.c_str()); + _header = ""; return false; } @@ -458,15 +459,31 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) if ( ! result.fromXml(_response, &offset)) { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response value. Response:\n%s", _response.c_str()); _response = ""; + _header = ""; return false; } } else { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s", _response.c_str()); _response = ""; + _header = ""; return false; } _response = ""; + + if (_header.size() < 8 || _header.find("HTTP/") != 0) + XmlRpcUtil::error("Error XmlRpcClient::parseResponse: Header does not start with protocol"); + else + { + const unsigned protocolVersion = atoi(&_header[5]) * 10 + atoi(&_header[7]); + if (protocolVersion == 10) + { + setKeepOpen(false); + close(); + } + } + + _header = ""; return result.valid(); } From 140820e2dd22fd9f1111d27ba42d63a5cc35462e Mon Sep 17 00:00:00 2001 From: Markus Grimm Date: Mon, 10 Aug 2020 20:58:01 +0200 Subject: [PATCH 2/3] Simplify HTTP/1.0 check --- utilities/xmlrpcpp/src/XmlRpcClient.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/utilities/xmlrpcpp/src/XmlRpcClient.cpp b/utilities/xmlrpcpp/src/XmlRpcClient.cpp index ce56eb3250..6169e62da3 100644 --- a/utilities/xmlrpcpp/src/XmlRpcClient.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcClient.cpp @@ -471,16 +471,10 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) _response = ""; - if (_header.size() < 8 || _header.find("HTTP/") != 0) - XmlRpcUtil::error("Error XmlRpcClient::parseResponse: Header does not start with protocol"); - else - { - const unsigned protocolVersion = atoi(&_header[5]) * 10 + atoi(&_header[7]); - if (protocolVersion == 10) - { - setKeepOpen(false); - close(); - } + // Close connection if protocol is HTTP/1.0 + if (_header.size() > 8 && _header[5] == '1' && _header[7] == '0') { + setKeepOpen(false); + close(); } _header = ""; From 285b7664f8e4ad2981b1bcdd115cb9f94a53d49b Mon Sep 17 00:00:00 2001 From: Markus Grimm Date: Mon, 10 Aug 2020 21:48:16 +0200 Subject: [PATCH 3/3] Check if prefix matches --- utilities/xmlrpcpp/src/XmlRpcClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/xmlrpcpp/src/XmlRpcClient.cpp b/utilities/xmlrpcpp/src/XmlRpcClient.cpp index 6169e62da3..83f91b1156 100644 --- a/utilities/xmlrpcpp/src/XmlRpcClient.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcClient.cpp @@ -472,7 +472,7 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) _response = ""; // Close connection if protocol is HTTP/1.0 - if (_header.size() > 8 && _header[5] == '1' && _header[7] == '0') { + if (_header.rfind("HTTP/1.0", 0) == 0) { setKeepOpen(false); close(); }