Add HTTPMessage::toString and family

This commit is contained in:
Vinnie Falco
2013-09-11 18:24:40 -07:00
parent 68422ed5b4
commit 43d386fa6e
19 changed files with 147 additions and 35 deletions

View File

@@ -809,7 +809,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </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)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">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\test\StateBase.h" />
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h" /> <ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h" />
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceStrings.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\ValidatorsImp.h" />
<ClInclude Include="..\..\src\ripple_core\validator\Validators.h" /> <ClInclude Include="..\..\src\ripple_core\validator\Validators.h" />
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorsUtilities.h" /> <ClInclude Include="..\..\src\ripple_core\validator\ValidatorsUtilities.h" />

View File

@@ -843,9 +843,6 @@
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceFile.cpp"> <ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceFile.cpp">
<Filter>[1] Ripple\ripple_core\validator</Filter> <Filter>[1] Ripple\ripple_core\validator</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceTrustedURL.cpp">
<Filter>[1] Ripple\ripple_core\validator</Filter>
</ClCompile>
<ClCompile Include="..\..\build\proto\ripple.pb.cc"> <ClCompile Include="..\..\build\proto\ripple.pb.cc">
<Filter>[1] Ripple</Filter> <Filter>[1] Ripple</Filter>
</ClCompile> </ClCompile>
@@ -880,6 +877,9 @@
<ClCompile Include="..\..\src\ripple_core\functional\Config.cpp"> <ClCompile Include="..\..\src\ripple_core\functional\Config.cpp">
<Filter>[1] Ripple\ripple_core\functional</Filter> <Filter>[1] Ripple\ripple_core\functional</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple_core\validator\ValidatorSourceURL.cpp">
<Filter>[1] Ripple\ripple_core\validator</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\src\ripple_app\ripple_app.h"> <ClInclude Include="..\..\src\ripple_app\ripple_app.h">
@@ -1725,9 +1725,6 @@
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h"> <ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceFile.h">
<Filter>[1] Ripple\ripple_core\validator</Filter> <Filter>[1] Ripple\ripple_core\validator</Filter>
</ClInclude> </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\BeastConfig.h" />
<ClInclude Include="..\..\src\ripple_core\peerfinder\ripple_PeerFinder.h"> <ClInclude Include="..\..\src\ripple_core\peerfinder\ripple_PeerFinder.h">
<Filter>[1] Ripple\ripple_core\peerfinder</Filter> <Filter>[1] Ripple\ripple_core\peerfinder</Filter>
@@ -1735,6 +1732,9 @@
<ClInclude Include="..\..\src\ripple_core\functional\Config.h"> <ClInclude Include="..\..\src\ripple_core\functional\Config.h">
<Filter>[1] Ripple\ripple_core\functional</Filter> <Filter>[1] Ripple\ripple_core\functional</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple_core\validator\ValidatorSourceURL.h">
<Filter>[1] Ripple\ripple_core\validator</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto"> <CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">

View File

@@ -72,3 +72,15 @@ String HTTPHeaders::operator[] (String const& field) const
{ {
return get (field); 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;
}

View File

@@ -61,6 +61,9 @@ public:
String operator[] (String const& field) const; String operator[] (String const& field) const;
/** @} */ /** @} */
/** Outputs all the headers into one string. */
String toString () const;
private: private:
StringPairArray m_fields; StringPairArray m_fields;
}; };

View File

@@ -40,3 +40,11 @@ ContentBodyBuffer const& HTTPMessage::body () const
{ {
return m_body; return m_body;
} }
String HTTPMessage::toString () const
{
String s;
s << "HTTP " << version().toString() << newLine;
s << m_headers.toString ();
return s;
}

View File

@@ -51,6 +51,9 @@ public:
/** Returns the content-body. */ /** Returns the content-body. */
ContentBodyBuffer const& body () const; ContentBodyBuffer const& body () const;
/** Outputs all the HTTPMessage data excluding the body into a string. */
String toString () const;
private: private:
HTTPVersion m_version; HTTPVersion m_version;
HTTPHeaders m_headers; HTTPHeaders m_headers;

View File

@@ -31,3 +31,12 @@ unsigned short HTTPResponse::status () const
{ {
return m_status; return m_status;
} }
String HTTPResponse::toString () const
{
String s;
s << "Status: " << String::fromNumber (status ()) << newLine;
s << this->HTTPMessage::toString ();
return s;
}

View File

@@ -35,6 +35,9 @@ public:
unsigned short status () const; unsigned short status () const;
/** Convert the response into a string, excluding the body. */
String toString () const;
private: private:
unsigned short m_status; unsigned short m_status;
}; };

View File

@@ -223,17 +223,23 @@ public:
// Initialize the Validators object with Config information. // Initialize the Validators object with Config information.
void initValidatorsConfig () void initValidatorsConfig ()
{ {
#if RIPPLE_USE_NEW_VALIDATORS
{ {
std::vector <std::string> const& strings (getConfig().validators); std::vector <std::string> const& strings (getConfig().validators);
if (! strings.empty ()) if (! strings.empty ())
m_validators->addStrings (strings); m_validators->addStrings (strings);
} }
#if 0 /*
if (getConfig().getValidatorsFile() != File::nonexistent())
{ {
String const& localValidatorsPath (getConfig().localValidatorsPath); m_validators->addFile (getConfig().getValidatorsFile());
if (localValidatorsPath != String::empty) }
m_validators->addFile (localValidatorsPath); */
if (! getConfig().getValidatorsURL().empty())
{
m_validators->addURL (getConfig().getValidatorsURL());
} }
#endif #endif
} }

View File

@@ -87,7 +87,7 @@ Config::Config ()
ACCOUNT_PROBE_MAX = 10; ACCOUNT_PROBE_MAX = 10;
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE; VALIDATORS_SITE = "";
SSL_VERIFY = true; SSL_VERIFY = true;
@@ -722,6 +722,17 @@ File Config::getDatabaseDir () const
return File (String (DATA_DIR.native ().c_str ())); 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) void Config::setRpcIpAndOptionalPort (std::string const& newAddress)

View File

@@ -19,8 +19,6 @@
// VFALCO NOTE Set this to 1 to enable code which is unnecessary // VFALCO NOTE Set this to 1 to enable code which is unnecessary
#define ENABLE_INSECURE 0 #define ENABLE_INSECURE 0
#define DEFAULT_VALIDATORS_SITE ""
const int DOMAIN_BYTES_MAX = 256; const int DOMAIN_BYTES_MAX = 256;
const int PUBLIC_BYTES_MAX = 33; // Maximum bytes for an account public key. const int PUBLIC_BYTES_MAX = 33; // Maximum bytes for an account public key.
@@ -197,6 +195,12 @@ public:
// Settings related to validators // 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. boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------

View File

@@ -67,11 +67,11 @@ namespace ripple
#include "validator/ValidatorsUtilities.cpp" #include "validator/ValidatorsUtilities.cpp"
# include "validator/ValidatorSourceFile.h" # include "validator/ValidatorSourceFile.h"
# include "validator/ValidatorSourceStrings.h" # include "validator/ValidatorSourceStrings.h"
# include "validator/ValidatorSourceTrustedURL.h" # include "validator/ValidatorSourceURL.h"
# include "validator/ValidatorsImp.h" # include "validator/ValidatorsImp.h"
#include "validator/ValidatorSourceFile.cpp" #include "validator/ValidatorSourceFile.cpp"
#include "validator/ValidatorSourceStrings.cpp" #include "validator/ValidatorSourceStrings.cpp"
#include "validator/ValidatorSourceTrustedURL.cpp" #include "validator/ValidatorSourceURL.cpp"
#include "validator/Validators.cpp" #include "validator/Validators.cpp"
#include "peerfinder/ripple_PeerFinder.h" // private (for now) #include "peerfinder/ripple_PeerFinder.h" // private (for now)

View File

@@ -8,6 +8,7 @@ class ValidatorSourceStringsImp : public ValidatorSourceStrings
{ {
public: public:
ValidatorSourceStringsImp (StringArray const& strings) ValidatorSourceStringsImp (StringArray const& strings)
: m_strings (strings)
{ {
} }
@@ -18,11 +19,21 @@ public:
Result fetch (CancelCallback&) Result fetch (CancelCallback&)
{ {
Result result; 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; return result;
} }
private: private:
StringArray m_strings;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@@ -4,15 +4,15 @@
*/ */
//============================================================================== //==============================================================================
class ValidatorSourceTrustedURLImp : public ValidatorSourceTrustedURL class ValidatorSourceURLImp : public ValidatorSourceURL
{ {
public: public:
explicit ValidatorSourceTrustedURLImp (UniformResourceLocator const& url) explicit ValidatorSourceURLImp (UniformResourceLocator const& url)
: m_url (url) : m_url (url)
{ {
} }
~ValidatorSourceTrustedURLImp () ~ValidatorSourceURLImp ()
{ {
} }
@@ -37,11 +37,11 @@ private:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ValidatorSourceTrustedURL* ValidatorSourceTrustedURL::New ( ValidatorSourceURL* ValidatorSourceURL::New (
UniformResourceLocator const& url) UniformResourceLocator const& url)
{ {
ScopedPointer <ValidatorSourceTrustedURL> object ( ScopedPointer <ValidatorSourceURL> object (
new ValidatorSourceTrustedURLImp (url)); new ValidatorSourceURLImp (url));
return object.release (); return object.release ();
} }

View File

@@ -9,10 +9,10 @@
/** Provides validators from a trusted URI (e.g. HTTPS) /** Provides validators from a trusted URI (e.g. HTTPS)
*/ */
class ValidatorSourceTrustedURL : public Validators::Source class ValidatorSourceURL : public Validators::Source
{ {
public: public:
static ValidatorSourceTrustedURL* New (UniformResourceLocator const& url); static ValidatorSourceURL* New (UniformResourceLocator const& url);
}; };
#endif #endif

View File

@@ -57,6 +57,7 @@ public:
bool success; bool success;
String message; String message;
Time expirationTime;
Array <Info> list; Array <Info> list;
}; };
virtual Result fetch (CancelCallback& callback) = 0; virtual Result fetch (CancelCallback& callback) = 0;
@@ -99,7 +100,7 @@ public:
/** Add a live source of validators from a trusted URL. /** Add a live source of validators from a trusted URL.
The URL will be contacted periodically to update the list. 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. /** Add a live source of validators.
The caller loses ownership of the object. The caller loses ownership of the object.

View File

@@ -406,9 +406,9 @@ public:
addStaticSource (ValidatorSourceFile::New (path)); 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) void addSource (Source* source)

View File

@@ -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);
}
}

View File

@@ -14,12 +14,7 @@ class ValidatorsUtilities
public: public:
typedef std::vector <std::string> Strings; typedef std::vector <std::string> Strings;
/** Turn a linear buffer of newline delimited text into strings. #if 0
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);
/** Parse a ConstBufferSequence of newline delimited text into strings. /** Parse a ConstBufferSequence of newline delimited text into strings.
This works incrementally. This works incrementally.
*/ */
@@ -30,6 +25,28 @@ public:
iter != buffers.end (); ++iter) iter != buffers.end (); ++iter)
parserLines (lines, *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 #endif