mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 08:48:03 +00:00
Abstract parseUrl.
This commit is contained in:
@@ -22,7 +22,7 @@ HTTPRequestAction HTTPRequest::requestDone(bool forceClose)
|
|||||||
if (forceClose || bShouldClose)
|
if (forceClose || bShouldClose)
|
||||||
return haCLOSE_CONN;
|
return haCLOSE_CONN;
|
||||||
reset();
|
reset();
|
||||||
return haREAD_LINE;
|
return haREAD_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HTTPRequest::getReplyHeaders(bool forceClose)
|
std::string HTTPRequest::getReplyHeaders(bool forceClose)
|
||||||
@@ -91,7 +91,6 @@ HTTPRequestAction HTTPRequest::consume(boost::asio::streambuf& buf)
|
|||||||
|
|
||||||
if (headerName == "authorization")
|
if (headerName == "authorization")
|
||||||
sAuthorization = headerValue;
|
sAuthorization = headerValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return haREAD_LINE;
|
return haREAD_LINE;
|
||||||
@@ -100,3 +99,5 @@ HTTPRequestAction HTTPRequest::consume(boost::asio::streambuf& buf)
|
|||||||
assert(false);
|
assert(false);
|
||||||
return haERROR;
|
return haERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim:ts=4
|
||||||
|
|||||||
@@ -362,22 +362,4 @@ void HttpsClient::httpsGet(
|
|||||||
client->httpsGet(deqSites, timeout, complete);
|
client->httpsGet(deqSites, timeout, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HttpsClient::httpsParseUrl(const std::string& strUrl, std::string& strDomain, std::string& strPath)
|
|
||||||
{
|
|
||||||
static boost::regex reUrl("(?i)\\`\\s*https://([^/]+)(/.*)\\s*\\'"); // https://DOMAINPATH
|
|
||||||
|
|
||||||
boost::smatch smMatch;
|
|
||||||
|
|
||||||
bool bMatch = boost::regex_match(strUrl, smMatch, reUrl); // Match status code.
|
|
||||||
|
|
||||||
if (bMatch)
|
|
||||||
{
|
|
||||||
strDomain = smMatch[1];
|
|
||||||
strPath = smMatch[2];
|
|
||||||
}
|
|
||||||
// std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'" << std::endl;
|
|
||||||
|
|
||||||
return bMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ public:
|
|||||||
std::size_t responseMax,
|
std::size_t responseMax,
|
||||||
boost::posix_time::time_duration timeout,
|
boost::posix_time::time_duration timeout,
|
||||||
boost::function<void(const boost::system::error_code& ecResult, std::string& strData)> complete);
|
boost::function<void(const boost::system::error_code& ecResult, std::string& strData)> complete);
|
||||||
|
|
||||||
static bool httpsParseUrl(const std::string& strUrl, std::string& strDomain, std::string& strPath);
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -91,10 +91,8 @@ class RPCHandler
|
|||||||
Json::Value doSubscribe(Json::Value params);
|
Json::Value doSubscribe(Json::Value params);
|
||||||
Json::Value doUnsubscribe(Json::Value params);
|
Json::Value doUnsubscribe(Json::Value params);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
enum { GUEST, USER, ADMIN };
|
enum { GUEST, USER, ADMIN };
|
||||||
|
|
||||||
RPCHandler(NetworkOPs* netOps);
|
RPCHandler(NetworkOPs* netOps);
|
||||||
|
|||||||
@@ -14,8 +14,6 @@
|
|||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include <boost/asio/read_until.hpp>
|
#include <boost/asio/read_until.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "../json/reader.h"
|
#include "../json/reader.h"
|
||||||
#include "../json/writer.h"
|
#include "../json/writer.h"
|
||||||
|
|
||||||
@@ -28,12 +26,9 @@ SETUP_LOG();
|
|||||||
RPCServer::RPCServer(boost::asio::io_service& io_service , NetworkOPs* nopNetwork)
|
RPCServer::RPCServer(boost::asio::io_service& io_service , NetworkOPs* nopNetwork)
|
||||||
: mNetOps(nopNetwork), mSocket(io_service)
|
: mNetOps(nopNetwork), mSocket(io_service)
|
||||||
{
|
{
|
||||||
|
|
||||||
mRole = RPCHandler::GUEST;
|
mRole = RPCHandler::GUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RPCServer::connected()
|
void RPCServer::connected()
|
||||||
{
|
{
|
||||||
//std::cerr << "RPC request" << std::endl;
|
//std::cerr << "RPC request" << std::endl;
|
||||||
@@ -152,7 +147,6 @@ std::string RPCServer::handleRequest(const std::string& requestStr)
|
|||||||
return HTTPReply(200, strReply);
|
return HTTPReply(200, strReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// now, expire, n
|
// now, expire, n
|
||||||
bool RPCServer::parseAcceptRate(const std::string& sAcceptRate)
|
bool RPCServer::parseAcceptRate(const std::string& sAcceptRate)
|
||||||
|
|||||||
@@ -798,12 +798,14 @@ void UniqueNodeList::responseIps(const std::string& strSite, const RippleAddress
|
|||||||
void UniqueNodeList::getIpsUrl(const RippleAddress& naNodePublic, section secSite)
|
void UniqueNodeList::getIpsUrl(const RippleAddress& naNodePublic, section secSite)
|
||||||
{
|
{
|
||||||
std::string strIpsUrl;
|
std::string strIpsUrl;
|
||||||
|
std::string strScheme;
|
||||||
std::string strDomain;
|
std::string strDomain;
|
||||||
std::string strPath;
|
std::string strPath;
|
||||||
|
|
||||||
if (sectionSingleB(secSite, SECTION_IPS_URL, strIpsUrl)
|
if (sectionSingleB(secSite, SECTION_IPS_URL, strIpsUrl)
|
||||||
&& !strIpsUrl.empty()
|
&& !strIpsUrl.empty()
|
||||||
&& HttpsClient::httpsParseUrl(strIpsUrl, strDomain, strPath))
|
&& parseUrl(strIpsUrl, strScheme, strDomain, strPath)
|
||||||
|
&& strScheme == "https")
|
||||||
{
|
{
|
||||||
HttpsClient::httpsGet(
|
HttpsClient::httpsGet(
|
||||||
theApp->getIOService(),
|
theApp->getIOService(),
|
||||||
@@ -837,12 +839,14 @@ void UniqueNodeList::responseValidators(const std::string& strValidatorsUrl, con
|
|||||||
void UniqueNodeList::getValidatorsUrl(const RippleAddress& naNodePublic, section secSite)
|
void UniqueNodeList::getValidatorsUrl(const RippleAddress& naNodePublic, section secSite)
|
||||||
{
|
{
|
||||||
std::string strValidatorsUrl;
|
std::string strValidatorsUrl;
|
||||||
|
std::string strScheme;
|
||||||
std::string strDomain;
|
std::string strDomain;
|
||||||
std::string strPath;
|
std::string strPath;
|
||||||
|
|
||||||
if (sectionSingleB(secSite, SECTION_VALIDATORS_URL, strValidatorsUrl)
|
if (sectionSingleB(secSite, SECTION_VALIDATORS_URL, strValidatorsUrl)
|
||||||
&& !strValidatorsUrl.empty()
|
&& !strValidatorsUrl.empty()
|
||||||
&& HttpsClient::httpsParseUrl(strValidatorsUrl, strDomain, strPath))
|
&& parseUrl(strValidatorsUrl, strScheme, strDomain, strPath)
|
||||||
|
&& strScheme == "https")
|
||||||
{
|
{
|
||||||
HttpsClient::httpsGet(
|
HttpsClient::httpsGet(
|
||||||
theApp->getIOService(),
|
theApp->getIOService(),
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public:
|
|||||||
|
|
||||||
bool getPublic() { return mPublic; };
|
bool getPublic() { return mPublic; };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void send(connection_ptr cpClient, message_ptr mpMessage)
|
void send(connection_ptr cpClient, message_ptr mpMessage)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
@@ -191,6 +193,27 @@ bool parseIpPort(const std::string& strSource, std::string& strIP, int& iPort)
|
|||||||
return bValid;
|
return bValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseUrl(const std::string& strUrl, std::string& strScheme, std::string& strDomain, std::string& strPath)
|
||||||
|
{
|
||||||
|
// scheme://username:password@hostname:port/rest
|
||||||
|
static boost::regex reUrl("(?i)\\`\\s*([[:alpha:]][-+.[:alpha:][:digit:]]*)://([^/]+)(/.*)?\\s*?\\'");
|
||||||
|
boost::smatch smMatch;
|
||||||
|
|
||||||
|
bool bMatch = boost::regex_match(strUrl, smMatch, reUrl); // Match status code.
|
||||||
|
|
||||||
|
if (bMatch)
|
||||||
|
{
|
||||||
|
strScheme = smMatch[1];
|
||||||
|
strDomain = smMatch[2];
|
||||||
|
strPath = smMatch[3];
|
||||||
|
|
||||||
|
boost::algorithm::to_lower(strScheme);
|
||||||
|
}
|
||||||
|
// std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'" << std::endl;
|
||||||
|
|
||||||
|
return bMatch;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Quality parsing
|
// Quality parsing
|
||||||
// - integers as is.
|
// - integers as is.
|
||||||
@@ -267,4 +290,45 @@ uint32_t be32toh(uint32_t value){ return(value); }
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( Utils)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( ParseUrl )
|
||||||
|
{
|
||||||
|
std::string strScheme;
|
||||||
|
std::string strDomain;
|
||||||
|
std::string strPath;
|
||||||
|
|
||||||
|
if (!parseUrl("lower://domain", strScheme, strDomain, strPath))
|
||||||
|
BOOST_FAIL("parseUrl: lower://domain failed");
|
||||||
|
|
||||||
|
if (strScheme != "lower")
|
||||||
|
BOOST_FAIL("parseUrl: lower://domain : scheme failed");
|
||||||
|
|
||||||
|
if (strDomain != "domain")
|
||||||
|
BOOST_FAIL("parseUrl: lower://domain : domain failed");
|
||||||
|
|
||||||
|
if (strPath != "")
|
||||||
|
BOOST_FAIL("parseUrl: lower://domain : path failed");
|
||||||
|
|
||||||
|
if (!parseUrl("UPPER://domain/", strScheme, strDomain, strPath))
|
||||||
|
BOOST_FAIL("parseUrl: UPPER://domain/ failed");
|
||||||
|
|
||||||
|
if (strScheme != "upper")
|
||||||
|
BOOST_FAIL("parseUrl: UPPER://domain : scheme failed");
|
||||||
|
|
||||||
|
if (strPath != "/")
|
||||||
|
BOOST_FAIL("parseUrl: UPPER://domain : scheme failed");
|
||||||
|
|
||||||
|
if (!parseUrl("Mixed://domain/path", strScheme, strDomain, strPath))
|
||||||
|
BOOST_FAIL("parseUrl: Mixed://domain/path failed");
|
||||||
|
|
||||||
|
if (strScheme != "mixed")
|
||||||
|
BOOST_FAIL("parseUrl: Mixed://domain/path tolower failed");
|
||||||
|
|
||||||
|
if (strPath != "/path")
|
||||||
|
BOOST_FAIL("parseUrl: Mixed://domain/path path failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -265,6 +265,8 @@ template<typename T, typename U> T range_check_cast(const U& value, const T& min
|
|||||||
return static_cast<T>(value);
|
return static_cast<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseUrl(const std::string& strUrl, std::string& strScheme, std::string& strDomain, std::string& strPath);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
Reference in New Issue
Block a user