mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add HTTPMessage::toString and family
This commit is contained in:
@@ -809,7 +809,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceTrustedURL.cpp">
|
||||
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceURL.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
@@ -1532,7 +1532,7 @@
|
||||
<ClInclude Include="..\..\src\ripple_core\test\StateBase.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceStrings.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceTrustedURL.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceURL.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorsImp.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\Validators.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorsUtilities.h" />
|
||||
|
||||
@@ -843,9 +843,6 @@
|
||||
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceFile.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceTrustedURL.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\build\proto\ripple.pb.cc">
|
||||
<Filter>[1] Ripple</Filter>
|
||||
</ClCompile>
|
||||
@@ -880,6 +877,9 @@
|
||||
<ClCompile Include="..\..\src\ripple_core\functional\Config.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceURL.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\ripple_app\ripple_app.h">
|
||||
@@ -1725,9 +1725,6 @@
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceTrustedURL.h">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\BeastConfig.h" />
|
||||
<ClInclude Include="..\..\src\ripple_core\peerfinder\ripple_PeerFinder.h">
|
||||
<Filter>[1] Ripple\ripple_core\peerfinder</Filter>
|
||||
@@ -1735,6 +1732,9 @@
|
||||
<ClInclude Include="..\..\src\ripple_core\functional\Config.h">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceURL.h">
|
||||
<Filter>[1] Ripple\ripple_core\validator</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">
|
||||
|
||||
@@ -72,3 +72,15 @@ String HTTPHeaders::operator[] (String const& field) const
|
||||
{
|
||||
return get (field);
|
||||
}
|
||||
|
||||
String HTTPHeaders::toString () const
|
||||
{
|
||||
String s;
|
||||
for (int i = 0; i < m_fields.size (); ++i)
|
||||
{
|
||||
HTTPField const field (at(i));
|
||||
s << field.name() << ": " << field.value() << newLine;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
String operator[] (String const& field) const;
|
||||
/** @} */
|
||||
|
||||
/** Outputs all the headers into one string. */
|
||||
String toString () const;
|
||||
|
||||
private:
|
||||
StringPairArray m_fields;
|
||||
};
|
||||
|
||||
@@ -40,3 +40,11 @@ ContentBodyBuffer const& HTTPMessage::body () const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
String HTTPMessage::toString () const
|
||||
{
|
||||
String s;
|
||||
s << "HTTP " << version().toString() << newLine;
|
||||
s << m_headers.toString ();
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ public:
|
||||
/** Returns the content-body. */
|
||||
ContentBodyBuffer const& body () const;
|
||||
|
||||
/** Outputs all the HTTPMessage data excluding the body into a string. */
|
||||
String toString () const;
|
||||
|
||||
private:
|
||||
HTTPVersion m_version;
|
||||
HTTPHeaders m_headers;
|
||||
|
||||
@@ -31,3 +31,12 @@ unsigned short HTTPResponse::status () const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
String HTTPResponse::toString () const
|
||||
{
|
||||
String s;
|
||||
s << "Status: " << String::fromNumber (status ()) << newLine;
|
||||
s << this->HTTPMessage::toString ();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ public:
|
||||
|
||||
unsigned short status () const;
|
||||
|
||||
/** Convert the response into a string, excluding the body. */
|
||||
String toString () const;
|
||||
|
||||
private:
|
||||
unsigned short m_status;
|
||||
};
|
||||
|
||||
@@ -223,17 +223,23 @@ public:
|
||||
// Initialize the Validators object with Config information.
|
||||
void initValidatorsConfig ()
|
||||
{
|
||||
#if RIPPLE_USE_NEW_VALIDATORS
|
||||
{
|
||||
std::vector <std::string> const& strings (getConfig().validators);
|
||||
if (! strings.empty ())
|
||||
m_validators->addStrings (strings);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
if (getConfig().getValidatorsFile() != File::nonexistent())
|
||||
{
|
||||
String const& localValidatorsPath (getConfig().localValidatorsPath);
|
||||
if (localValidatorsPath != String::empty)
|
||||
m_validators->addFile (localValidatorsPath);
|
||||
m_validators->addFile (getConfig().getValidatorsFile());
|
||||
}
|
||||
*/
|
||||
|
||||
if (! getConfig().getValidatorsURL().empty())
|
||||
{
|
||||
m_validators->addURL (getConfig().getValidatorsURL());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ Config::Config ()
|
||||
|
||||
ACCOUNT_PROBE_MAX = 10;
|
||||
|
||||
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE;
|
||||
VALIDATORS_SITE = "";
|
||||
|
||||
SSL_VERIFY = true;
|
||||
|
||||
@@ -722,6 +722,17 @@ File Config::getDatabaseDir () const
|
||||
return File (String (DATA_DIR.native ().c_str ()));
|
||||
}
|
||||
|
||||
File Config::getValidatorsFile () const
|
||||
{
|
||||
return getConfigDir().getChildFile (String (VALIDATORS_FILE.native().c_str()));
|
||||
}
|
||||
|
||||
UniformResourceLocator Config::getValidatorsURL () const
|
||||
{
|
||||
String s = "https://" + VALIDATORS_SITE + VALIDATORS_URI;
|
||||
return ParsedURL (s).url ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void Config::setRpcIpAndOptionalPort (std::string const& newAddress)
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
// VFALCO NOTE Set this to 1 to enable code which is unnecessary
|
||||
#define ENABLE_INSECURE 0
|
||||
|
||||
#define DEFAULT_VALIDATORS_SITE ""
|
||||
|
||||
const int DOMAIN_BYTES_MAX = 256;
|
||||
const int PUBLIC_BYTES_MAX = 33; // Maximum bytes for an account public key.
|
||||
|
||||
@@ -197,6 +195,12 @@ public:
|
||||
|
||||
// Settings related to validators
|
||||
|
||||
/** Return the path to the separate, optional validators file. */
|
||||
File getValidatorsFile () const;
|
||||
|
||||
/** Returns the optional URL to a trusted network source of validators. */
|
||||
UniformResourceLocator getValidatorsURL () const;
|
||||
|
||||
boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg.
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -67,11 +67,11 @@ namespace ripple
|
||||
#include "validator/ValidatorsUtilities.cpp"
|
||||
# include "validator/ValidatorSourceFile.h"
|
||||
# include "validator/ValidatorSourceStrings.h"
|
||||
# include "validator/ValidatorSourceTrustedURL.h"
|
||||
# include "validator/ValidatorSourceURL.h"
|
||||
# include "validator/ValidatorsImp.h"
|
||||
#include "validator/ValidatorSourceFile.cpp"
|
||||
#include "validator/ValidatorSourceStrings.cpp"
|
||||
#include "validator/ValidatorSourceTrustedURL.cpp"
|
||||
#include "validator/ValidatorSourceURL.cpp"
|
||||
#include "validator/Validators.cpp"
|
||||
|
||||
#include "peerfinder/ripple_PeerFinder.h" // private (for now)
|
||||
|
||||
@@ -8,6 +8,7 @@ class ValidatorSourceStringsImp : public ValidatorSourceStrings
|
||||
{
|
||||
public:
|
||||
ValidatorSourceStringsImp (StringArray const& strings)
|
||||
: m_strings (strings)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -19,10 +20,20 @@ public:
|
||||
{
|
||||
Result result;
|
||||
|
||||
result.list.ensureStorageAllocated (m_strings.size ());
|
||||
|
||||
for (int i = 0; i < m_strings.size (); ++i)
|
||||
{
|
||||
ValidatorsUtilities::parseResultLine (result, m_strings [i]);
|
||||
}
|
||||
|
||||
result.success = result.list.size () > 0;
|
||||
result.expirationTime = Time::getCurrentTime () + RelativeTime::hours (24);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
StringArray m_strings;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class ValidatorSourceTrustedURLImp : public ValidatorSourceTrustedURL
|
||||
class ValidatorSourceURLImp : public ValidatorSourceURL
|
||||
{
|
||||
public:
|
||||
explicit ValidatorSourceTrustedURLImp (UniformResourceLocator const& url)
|
||||
explicit ValidatorSourceURLImp (UniformResourceLocator const& url)
|
||||
: m_url (url)
|
||||
{
|
||||
}
|
||||
|
||||
~ValidatorSourceTrustedURLImp ()
|
||||
~ValidatorSourceURLImp ()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ private:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ValidatorSourceTrustedURL* ValidatorSourceTrustedURL::New (
|
||||
ValidatorSourceURL* ValidatorSourceURL::New (
|
||||
UniformResourceLocator const& url)
|
||||
{
|
||||
ScopedPointer <ValidatorSourceTrustedURL> object (
|
||||
new ValidatorSourceTrustedURLImp (url));
|
||||
ScopedPointer <ValidatorSourceURL> object (
|
||||
new ValidatorSourceURLImp (url));
|
||||
|
||||
return object.release ();
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
/** Provides validators from a trusted URI (e.g. HTTPS)
|
||||
*/
|
||||
class ValidatorSourceTrustedURL : public Validators::Source
|
||||
class ValidatorSourceURL : public Validators::Source
|
||||
{
|
||||
public:
|
||||
static ValidatorSourceTrustedURL* New (UniformResourceLocator const& url);
|
||||
static ValidatorSourceURL* New (UniformResourceLocator const& url);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
|
||||
bool success;
|
||||
String message;
|
||||
Time expirationTime;
|
||||
Array <Info> list;
|
||||
};
|
||||
virtual Result fetch (CancelCallback& callback) = 0;
|
||||
@@ -99,7 +100,7 @@ public:
|
||||
/** Add a live source of validators from a trusted URL.
|
||||
The URL will be contacted periodically to update the list.
|
||||
*/
|
||||
virtual void addTrustedURL (UniformResourceLocator const& url) = 0;
|
||||
virtual void addURL (UniformResourceLocator const& url) = 0;
|
||||
|
||||
/** Add a live source of validators.
|
||||
The caller loses ownership of the object.
|
||||
|
||||
@@ -406,9 +406,9 @@ public:
|
||||
addStaticSource (ValidatorSourceFile::New (path));
|
||||
}
|
||||
|
||||
void addTrustedURL (UniformResourceLocator const& url)
|
||||
void addURL (UniformResourceLocator const& url)
|
||||
{
|
||||
addSource (ValidatorSourceTrustedURL::New (url));
|
||||
addSource (ValidatorSourceURL::New (url));
|
||||
}
|
||||
|
||||
void addSource (Source* source)
|
||||
|
||||
@@ -4,3 +4,27 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
bool ValidatorsUtilities::parseInfoLine (Validators::Source::Info& info, String line)
|
||||
{
|
||||
bool success (false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ValidatorsUtilities::parseResultLine (
|
||||
Validators::Source::Result& result,
|
||||
String line)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
if (! success)
|
||||
{
|
||||
Validators::Source::Info info;
|
||||
|
||||
success = parseInfoLine (info, line);
|
||||
if (success)
|
||||
result.list.add (info);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,12 +14,7 @@ class ValidatorsUtilities
|
||||
public:
|
||||
typedef std::vector <std::string> Strings;
|
||||
|
||||
/** Turn a linear buffer of newline delimited text into strings.
|
||||
This can be called incrementally, i.e. successive calls with
|
||||
multiple buffer segments.
|
||||
*/
|
||||
static void parseLines (Strings& lines, char const* buf, std::size_t bytes);
|
||||
|
||||
#if 0
|
||||
/** Parse a ConstBufferSequence of newline delimited text into strings.
|
||||
This works incrementally.
|
||||
*/
|
||||
@@ -30,6 +25,28 @@ public:
|
||||
iter != buffers.end (); ++iter)
|
||||
parserLines (lines, *iter);
|
||||
}
|
||||
|
||||
/** Turn a linear buffer of newline delimited text into strings.
|
||||
This can be called incrementally, i.e. successive calls with
|
||||
multiple buffer segments.
|
||||
*/
|
||||
static void parseLines (Strings& lines, char const* buf, std::size_t bytes);
|
||||
#endif
|
||||
|
||||
/** Parse a string into the Source::Result.
|
||||
Invalid or comment lines will be skipped.
|
||||
Lines containing validator info will be added to the Result object.
|
||||
Metadata lines will update the corresponding Result fields.
|
||||
*/
|
||||
static void parseResultLine (
|
||||
Validators::Source::Result& result,
|
||||
String line);
|
||||
|
||||
private:
|
||||
/** Parse a string into a Source::Info.
|
||||
@return `true` on success.
|
||||
*/
|
||||
static bool parseInfoLine (Validators::Source::Info& info, String line);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user