mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Relax JSON parsing
Allow comments and trailing commas
This commit is contained in:
parent
759d2ecc82
commit
519b4b548d
3 changed files with 10 additions and 7 deletions
|
@ -350,7 +350,7 @@ void p2pool::submit_block() const
|
|||
[height, diff, &submit_data](const char* data, size_t size)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
|
||||
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) {
|
||||
LOGERR(0, "submit_block: invalid JSON response from daemon");
|
||||
return;
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ void p2pool::get_info()
|
|||
void p2pool::parse_get_info_rpc(const char* data, size_t size)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(data, size);
|
||||
doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size);
|
||||
|
||||
if (!doc.IsObject() || !doc.HasMember("result")) {
|
||||
LOGWARN(1, "get_info RPC response is invalid (\"result\" not found), trying again in 1 second");
|
||||
|
@ -599,7 +599,7 @@ void p2pool::get_miner_data()
|
|||
void p2pool::parse_get_miner_data_rpc(const char* data, size_t size)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(data, size);
|
||||
doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size);
|
||||
|
||||
if (!doc.IsObject() || !doc.HasMember("result")) {
|
||||
LOGWARN(1, "get_miner_data RPC response is invalid, skipping it");
|
||||
|
@ -647,7 +647,7 @@ void p2pool::parse_get_miner_data_rpc(const char* data, size_t size)
|
|||
bool p2pool::parse_block_header(const char* data, size_t size, ChainMain& result)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
|
||||
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) {
|
||||
LOGERR(1, "parse_block_header: invalid JSON response from daemon");
|
||||
return false;
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ bool p2pool::parse_block_header(const char* data, size_t size, ChainMain& result
|
|||
uint32_t p2pool::parse_block_headers_range(const char* data, size_t size)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (doc.Parse(data, size).HasParseError() || !doc.IsObject()) {
|
||||
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) {
|
||||
LOGERR(1, "parse_block_headers_range: invalid JSON response from daemon");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1493,7 +1493,7 @@ bool SideChain::load_config(const std::string& filename)
|
|||
|
||||
rapidjson::Document doc;
|
||||
rapidjson::IStreamWrapper s(f);
|
||||
if (doc.ParseStream(s).HasParseError()) {
|
||||
if (doc.ParseStream<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(s).HasParseError()) {
|
||||
LOGERR(1, "failed to parse JSON data in " << filename);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -143,7 +143,10 @@ void ZMQReader::parse(char* data, size_t size)
|
|||
using namespace rapidjson;
|
||||
|
||||
Document doc;
|
||||
doc.Parse(value, end - value);
|
||||
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(value, end - value).HasParseError()) {
|
||||
LOGWARN(1, "ZeroMQ message failed to parse, skipping it");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(data, "json-minimal-txpool_add") == 0) {
|
||||
if (!doc.IsArray()) {
|
||||
|
|
Loading…
Reference in a new issue