diff --git a/lib/jsoncpp/json/json-forwards.h b/lib/jsoncpp/json/json-forwards.h index 342438995..b9d46e688 100644 --- a/lib/jsoncpp/json/json-forwards.h +++ b/lib/jsoncpp/json/json-forwards.h @@ -11,13 +11,13 @@ The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all +Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is -released under the terms of the MIT License (see below). +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and +The JsonCpp Authors, and is released under the terms of the MIT License (see below). In jurisdictions which recognize Public Domain property, the user of this software may choose to accept it either as 1) Public Domain, 2) under the @@ -32,7 +32,7 @@ described in clear, concise terms at: The full text of the MIT License follows: ======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur +Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -83,7 +83,7 @@ license you like. // Beginning of content of file: include/json/config.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -94,6 +94,12 @@ license you like. #include //typedef String #include //typedef int64_t, uint64_t +/* own assert() which does not abort... */ +#define assert(x) do { \ + if (x) \ + fprintf(stderr, "JSONCPP:%s:%d assert(%s) failed\n", __func__, __LINE__, #x); \ +} while (0) + /// If defined, indicates that json library is embedded in CppTL library. //# define JSON_IN_CPPTL 1 @@ -205,6 +211,9 @@ license you like. #endif #ifdef __clang__ +# if __has_extension(attribute_deprecated_with_message) +# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) +# endif #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) @@ -281,7 +290,7 @@ typedef UInt64 LargestUInt; // Beginning of content of file: include/json/forwards.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE diff --git a/lib/jsoncpp/json/json.h b/lib/jsoncpp/json/json.h index 02a31f4a0..0ad699dbc 100644 --- a/lib/jsoncpp/json/json.h +++ b/lib/jsoncpp/json/json.h @@ -10,13 +10,13 @@ The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all +Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is -released under the terms of the MIT License (see below). +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and +The JsonCpp Authors, and is released under the terms of the MIT License (see below). In jurisdictions which recognize Public Domain property, the user of this software may choose to accept it either as 1) Public Domain, 2) under the @@ -31,7 +31,7 @@ described in clear, concise terms at: The full text of the MIT License follows: ======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur +Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -87,10 +87,10 @@ license you like. #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "1.8.0" +# define JSONCPP_VERSION_STRING "1.8.3" # define JSONCPP_VERSION_MAJOR 1 # define JSONCPP_VERSION_MINOR 8 -# define JSONCPP_VERSION_PATCH 0 +# define JSONCPP_VERSION_PATCH 3 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) @@ -116,7 +116,7 @@ license you like. // Beginning of content of file: include/json/config.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -127,6 +127,12 @@ license you like. #include //typedef String #include //typedef int64_t, uint64_t +/* own assert() which does not abort... */ +#define assert(x) do { \ + if (x) \ + fprintf(stderr, "JSONCPP:%s:%d assert(%s) failed\n", __func__, __LINE__, #x); \ +} while (0) + /// If defined, indicates that json library is embedded in CppTL library. //# define JSON_IN_CPPTL 1 @@ -238,6 +244,9 @@ license you like. #endif #ifdef __clang__ +# if __has_extension(attribute_deprecated_with_message) +# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) +# endif #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) @@ -314,7 +323,7 @@ typedef UInt64 LargestUInt; // Beginning of content of file: include/json/forwards.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -365,7 +374,7 @@ class ValueConstIterator; // Beginning of content of file: include/json/features.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -440,7 +449,7 @@ public: // Beginning of content of file: include/json/value.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -465,7 +474,7 @@ public: #endif //Conditional NORETURN attribute on the throw functions would: -// a) suppress false positives from static code analysis +// a) suppress false positives from static code analysis // b) possibly improve optimization opportunities. #if !defined(JSONCPP_NORETURN) # if defined(_MSC_VER) @@ -506,7 +515,7 @@ protected: /** Exceptions which the user cannot easily avoid. * * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input - * + * * \remark derived from Json::Exception */ class JSON_API RuntimeError : public Exception { @@ -517,7 +526,7 @@ public: /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. * * These are precondition-violations (user bugs) and internal errors (our bugs). - * + * * \remark derived from Json::Exception */ class JSON_API LogicError : public Exception { @@ -632,6 +641,9 @@ public: typedef Json::LargestUInt LargestUInt; typedef Json::ArrayIndex ArrayIndex; + // Required for boost integration, e. g. BOOST_TEST + typedef std::string value_type; + static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value(). static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null static Value const& nullSingleton(); ///< Prefer this to null or nullRef. @@ -675,7 +687,12 @@ private: CZString(CZString&& other); #endif ~CZString(); - CZString& operator=(CZString other); + CZString& operator=(const CZString& other); + +#if JSON_HAS_RVALUE_REFERENCES + CZString& operator=(CZString&& other); +#endif + bool operator<(CZString const& other) const; bool operator==(CZString const& other) const; ArrayIndex index() const; @@ -765,11 +782,17 @@ Json::Value obj_value(Json::objectValue); // {} /// Deep copy, then swap(other). /// \note Over-write existing comments. To preserve comments, use #swapPayload(). Value& operator=(Value other); + /// Swap everything. void swap(Value& other); /// Swap values but leave comments and source offsets in place. void swapPayload(Value& other); + /// copy everything. + void copy(const Value& other); + /// copy values but leave comments and source offsets in place. + void copyPayload(const Value& other); + ValueType type() const; /// Compare payload only, not comments etc. @@ -880,6 +903,10 @@ Json::Value obj_value(Json::objectValue); // {} /// Equivalent to jsonvalue[jsonvalue.size()] = value; Value& append(const Value& value); +#if JSON_HAS_RVALUE_REFERENCES + Value& append(Value&& value); +#endif + /// Access an object value by name, create a null member if it does not exist. /// \note Because of our implementation, keys are limited to 2^30 -1 chars. /// Exceeding that will cause an exception. @@ -945,10 +972,12 @@ Json::Value obj_value(Json::objectValue); // {} /// \pre type() is objectValue or nullValue /// \post type() is unchanged /// \deprecated + JSONCPP_DEPRECATED("") Value removeMember(const char* key); /// Same as removeMember(const char*) /// \param key may contain embedded nulls. /// \deprecated + JSONCPP_DEPRECATED("") Value removeMember(const JSONCPP_STRING& key); /// Same as removeMember(const char* begin, const char* end, Value* removed), /// but 'key' is null-terminated. @@ -1324,7 +1353,7 @@ inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); } // Beginning of content of file: include/json/reader.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -1358,7 +1387,7 @@ namespace Json { * * \deprecated Use CharReader and CharReaderBuilder. */ -class JSON_API Reader { +class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader { public: typedef char Char; typedef const Char* Location; @@ -1556,6 +1585,9 @@ private: void addComment(Location begin, Location end, CommentPlacement placement); void skipCommentTokens(Token& token); + static bool containsNewLine(Location begin, Location end); + static JSONCPP_STRING normalizeEOL(Location begin, Location end); + typedef std::stack Nodes; Nodes nodes_; Errors errors_; @@ -1746,7 +1778,7 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&); // Beginning of content of file: include/json/writer.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -1763,7 +1795,7 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&); // Disable warning C4251: : needs to have dll-interface to // be used by... -#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) @@ -1888,7 +1920,7 @@ public: /** \brief Abstract class for writers. * \deprecated Use StreamWriter. (And really, this is an implementation detail.) */ -class JSON_API Writer { +class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer { public: virtual ~Writer(); @@ -1904,8 +1936,11 @@ public: * \sa Reader, Value * \deprecated Use StreamWriterBuilder. */ -class JSON_API FastWriter : public Writer { - +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) // Deriving from deprecated class +#endif +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer { public: FastWriter(); ~FastWriter() JSONCPP_OVERRIDE {} @@ -1932,6 +1967,9 @@ private: bool dropNullPlaceholders_; bool omitEndingLineFeed_; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /** \brief Writes a Value in JSON format in a *human friendly way. @@ -1957,7 +1995,11 @@ private: * \sa Reader, Value, Value::setComment() * \deprecated Use StreamWriterBuilder. */ -class JSON_API StyledWriter : public Writer { +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) // Deriving from deprecated class +#endif +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer { public: StyledWriter(); ~StyledWriter() JSONCPP_OVERRIDE {} @@ -1992,6 +2034,9 @@ private: unsigned int indentSize_; bool addChildValues_; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /** \brief Writes a Value in JSON format in a human friendly way, @@ -2015,12 +2060,18 @@ private: * If the Value have comments then they are outputed according to their #CommentPlacement. * - * \param indentation Each level will be indented by this amount extra. * \sa Reader, Value, Value::setComment() * \deprecated Use StreamWriterBuilder. */ -class JSON_API StyledStreamWriter { +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) // Deriving from deprecated class +#endif +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter { public: +/** + * \param indentation Each level will be indented by this amount extra. + */ StyledStreamWriter(JSONCPP_STRING indentation = "\t"); ~StyledStreamWriter() {} @@ -2057,6 +2108,9 @@ private: bool addChildValues_ : 1; bool indented_ : 1; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif #if defined(JSON_HAS_INT64) JSONCPP_STRING JSON_API valueToString(Int value); @@ -2095,7 +2149,7 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root); // Beginning of content of file: include/json/assertions.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE diff --git a/lib/jsoncpp/jsoncpp.cpp b/lib/jsoncpp/jsoncpp.cpp index 7634ed4f3..ce72ec1d8 100644 --- a/lib/jsoncpp/jsoncpp.cpp +++ b/lib/jsoncpp/jsoncpp.cpp @@ -10,13 +10,13 @@ The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all +Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is -released under the terms of the MIT License (see below). +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and +The JsonCpp Authors, and is released under the terms of the MIT License (see below). In jurisdictions which recognize Public Domain property, the user of this software may choose to accept it either as 1) Public Domain, 2) under the @@ -31,7 +31,7 @@ described in clear, concise terms at: The full text of the MIT License follows: ======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur +Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -84,7 +84,7 @@ license you like. // Beginning of content of file: src/lib_json/json_tool.h // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -215,7 +215,7 @@ static inline void fixNumericLocaleInput(char* begin, char* end) { // Beginning of content of file: src/lib_json/json_reader.cpp // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2011 Baptiste Lepilleur +// Copyright 2007-2011 Baptiste Lepilleur and The JsonCpp Authors // Copyright (C) 2016 InfoTeCS JSC. All rights reserved. // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. @@ -229,7 +229,7 @@ static inline void fixNumericLocaleInput(char* begin, char* end) { #endif // if !defined(JSON_IS_AMALGAMATION) #include #include -#include +//#include #include #include #include @@ -298,7 +298,7 @@ Features Features::strictMode() { // Implementation of class Reader // //////////////////////////////// -static bool containsNewLine(Reader::Location begin, Reader::Location end) { +bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) { for (; begin < end; ++begin) if (*begin == '\n' || *begin == '\r') return true; @@ -320,8 +320,7 @@ Reader::Reader(const Features& features) bool Reader::parse(const std::string& document, Value& root, bool collectComments) { - JSONCPP_STRING documentCopy(document.data(), document.data() + document.capacity()); - std::swap(documentCopy, document_); + document_.assign(document.begin(), document.end()); const char* begin = document_.c_str(); const char* end = begin + document_.length(); return parse(begin, end, root, collectComments); @@ -354,7 +353,7 @@ bool Reader::parse(const char* beginDoc, current_ = begin_; lastValueEnd_ = 0; lastValue_ = 0; - commentsBefore_ = ""; + commentsBefore_.clear(); errors_.clear(); while (!nodes_.empty()) nodes_.pop(); @@ -393,7 +392,7 @@ bool Reader::readValue() { if (collectComments_ && !commentsBefore_.empty()) { currentValue().setComment(commentsBefore_, commentBefore); - commentsBefore_ = ""; + commentsBefore_.clear(); } switch (token.type_) { @@ -587,7 +586,7 @@ bool Reader::readComment() { return true; } -static JSONCPP_STRING normalizeEOL(Reader::Location begin, Reader::Location end) { +JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin, Reader::Location end) { JSONCPP_STRING normalized; normalized.reserve(static_cast(end - begin)); Reader::Location current = begin; @@ -691,7 +690,7 @@ bool Reader::readObject(Token& tokenStart) { break; if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object return true; - name = ""; + name.clear(); if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); @@ -1236,6 +1235,9 @@ private: void addComment(Location begin, Location end, CommentPlacement placement); void skipCommentTokens(Token& token); + static JSONCPP_STRING normalizeEOL(Location begin, Location end); + static bool containsNewLine(Location begin, Location end); + typedef std::stack Nodes; Nodes nodes_; Errors errors_; @@ -1253,6 +1255,13 @@ private: // complete copy of Read impl, for OurReader +bool OurReader::containsNewLine(OurReader::Location begin, OurReader::Location end) { + for (; begin < end; ++begin) + if (*begin == '\n' || *begin == '\r') + return true; + return false; +} + OurReader::OurReader(OurFeatures const& features) : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), lastValue_(), commentsBefore_(), @@ -1273,7 +1282,7 @@ bool OurReader::parse(const char* beginDoc, current_ = begin_; lastValueEnd_ = 0; lastValue_ = 0; - commentsBefore_ = ""; + commentsBefore_.clear(); errors_.clear(); while (!nodes_.empty()) nodes_.pop(); @@ -1315,7 +1324,7 @@ bool OurReader::readValue() { if (collectComments_ && !commentsBefore_.empty()) { currentValue().setComment(commentsBefore_, commentBefore); - commentsBefore_ = ""; + commentsBefore_.clear(); } switch (token.type_) { @@ -1562,6 +1571,25 @@ bool OurReader::readComment() { return true; } +JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin, OurReader::Location end) { + JSONCPP_STRING normalized; + normalized.reserve(static_cast(end - begin)); + OurReader::Location current = begin; + while (current != end) { + char c = *current++; + if (c == '\r') { + if (current != end && *current == '\n') + // convert dos EOL + ++current; + // convert Mac EOL + normalized += '\n'; + } else { + normalized += c; + } + } + return normalized; +} + void OurReader::addComment(Location begin, Location end, CommentPlacement placement) { assert(collectComments_); @@ -1664,7 +1692,7 @@ bool OurReader::readObject(Token& tokenStart) { break; if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object return true; - name = ""; + name.clear(); if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); @@ -2241,10 +2269,6 @@ JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) { JSONCPP_STRING errs; bool ok = parseFromStream(b, sin, &root, &errs); if (!ok) { - fprintf(stderr, - "Error from reader: %s", - errs.c_str()); - throwRuntimeError(errs); } return sin; @@ -2265,7 +2289,7 @@ JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) { // Beginning of content of file: src/lib_json/json_valueiterator.inl // ////////////////////////////////////////////////////////////////////// -// Copyright 2007-2010 Baptiste Lepilleur +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -2446,7 +2470,7 @@ ValueIterator& ValueIterator::operator=(const SelfType& other) { // Beginning of content of file: src/lib_json/json_value.cpp // ////////////////////////////////////////////////////////////////////// -// Copyright 2011 Baptiste Lepilleur +// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -2460,7 +2484,7 @@ ValueIterator& ValueIterator::operator=(const SelfType& other) { #include #include #include -#include +//#include #ifdef JSON_USE_CPPTL #include #endif @@ -2740,11 +2764,21 @@ void Value::CZString::swap(CZString& other) { std::swap(index_, other.index_); } -Value::CZString& Value::CZString::operator=(CZString other) { - swap(other); +Value::CZString& Value::CZString::operator=(const CZString& other) { + cstr_ = other.cstr_; + index_ = other.index_; return *this; } +#if JSON_HAS_RVALUE_REFERENCES +Value::CZString& Value::CZString::operator=(CZString&& other) { + cstr_ = other.cstr_; + index_ = other.index_; + other.cstr_ = nullptr; + return *this; +} +#endif + bool Value::CZString::operator<(const CZString& other) const { if (!cstr_) return index_ < other.index_; //return strcmp(cstr_, other.cstr_) < 0; @@ -2846,7 +2880,7 @@ Value::Value(double value) { Value::Value(const char* value) { initBasic(stringValue, true); - JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor"); + JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor"); value_.string_ = duplicateAndPrefixStringValue(value, static_cast(strlen(value))); } @@ -2971,6 +3005,12 @@ void Value::swapPayload(Value& other) { other.allocated_ = temp2 & 0x1; } +void Value::copyPayload(const Value& other) { + type_ = other.type_; + value_ = other.value_; + allocated_ = other.allocated_; +} + void Value::swap(Value& other) { swapPayload(other); std::swap(comments_, other.comments_); @@ -2978,6 +3018,13 @@ void Value::swap(Value& other) { std::swap(limit_, other.limit_); } +void Value::copy(const Value& other) { + copyPayload(other); + comments_ = other.comments_; + start_ = other.start_; + limit_ = other.limit_; +} + ValueType Value::type() const { return type_; } int Value::compare(const Value& other) const { @@ -3328,7 +3375,7 @@ bool Value::isConvertibleTo(ValueType other) const { case nullValue: return (isNumeric() && asDouble() == 0.0) || (type_ == booleanValue && value_.bool_ == false) || - (type_ == stringValue && asString() == "") || + (type_ == stringValue && asString().empty()) || (type_ == arrayValue && value_.map_->size() == 0) || (type_ == objectValue && value_.map_->size() == 0) || type_ == nullValue; @@ -3572,6 +3619,10 @@ Value const& Value::operator[](CppTL::ConstString const& key) const Value& Value::append(const Value& value) { return (*this)[size()] = value; } +#if JSON_HAS_RVALUE_REFERENCES + Value& Value::append(Value&& value) { return (*this)[size()] = std::move(value); } +#endif + Value Value::get(char const* key, char const* cend, Value const& defaultValue) const { Value const* found = find(key, cend); @@ -3608,6 +3659,9 @@ bool Value::removeMember(JSONCPP_STRING const& key, Value* removed) { return removeMember(key.data(), key.data() + key.length(), removed); } + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" Value Value::removeMember(const char* key) { JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue, @@ -3623,6 +3677,7 @@ Value Value::removeMember(const JSONCPP_STRING& key) { return removeMember(key.c_str()); } +#pragma GCC diagnostic pop bool Value::removeIndex(ArrayIndex index, Value* removed) { if (type_ != arrayValue) { @@ -3808,11 +3863,23 @@ bool Value::isUInt64() const { } bool Value::isIntegral() const { + switch (type_) { + case intValue: + case uintValue: + return true; + case realValue: #if defined(JSON_HAS_INT64) - return isInt64() || isUInt64(); + // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a + // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we + // require the value to be strictly less than the limit. + return value_.real_ >= double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_); #else - return isInt() || isUInt(); -#endif + return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_); +#endif // JSON_HAS_INT64 + default: + break; + } + return false; } bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; } @@ -3862,8 +3929,13 @@ ptrdiff_t Value::getOffsetStart() const { return start_; } ptrdiff_t Value::getOffsetLimit() const { return limit_; } JSONCPP_STRING Value::toStyledString() const { - StyledWriter writer; - return writer.write(*this); + StreamWriterBuilder builder; + + JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : ""; + out += Json::writeString(builder, *this); + out += "\n"; + + return out; } Value::const_iterator Value::begin() const { @@ -3942,6 +4014,7 @@ Path::Path(const JSONCPP_STRING& path, const PathArgument& a4, const PathArgument& a5) { InArgs in; + in.reserve(5); in.push_back(&a1); in.push_back(&a2); in.push_back(&a3); @@ -4077,7 +4150,7 @@ Value& Path::make(Value& root) const { // Beginning of content of file: src/lib_json/json_writer.cpp // ////////////////////////////////////////////////////////////////////// -// Copyright 2011 Baptiste Lepilleur +// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -4091,7 +4164,7 @@ Value& Path::make(Value& root) const { #include #include #include -#include +//#include #include #include @@ -4221,17 +4294,18 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p char buffer[36]; int len = -1; - char formatString[6]; - sprintf(formatString, "%%.%dg", precision); + char formatString[15]; + snprintf(formatString, sizeof(formatString), "%%.%dg", precision); // Print into the buffer. We need not request the alternative representation // that always has a decimal point because JSON doesn't distingish the // concepts of reals and integers. if (isfinite(value)) { len = snprintf(buffer, sizeof(buffer), formatString, value); - + fixNumericLocale(buffer, buffer + len); + // try to ensure we preserve the fact that this was given to us as a double on input - if (!strstr(buffer, ".") && !strstr(buffer, "e")) { + if (!strchr(buffer, '.') && !strchr(buffer, 'e')) { strcat(buffer, ".0"); } @@ -4244,10 +4318,8 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p } else { len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999"); } - // For those, we do not need to call fixNumLoc, but it is fast. } assert(len >= 0); - fixNumericLocale(buffer, buffer + len); return buffer; } } @@ -4414,7 +4486,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; } JSONCPP_STRING FastWriter::write(const Value& root) { - document_ = ""; + document_.clear(); writeValue(root); if (!omitEndingLineFeed_) document_ += "\n"; @@ -4482,9 +4554,9 @@ StyledWriter::StyledWriter() : rightMargin_(74), indentSize_(3), addChildValues_() {} JSONCPP_STRING StyledWriter::write(const Value& root) { - document_ = ""; + document_.clear(); addChildValues_ = false; - indentString_ = ""; + indentString_.clear(); writeCommentBeforeValue(root); writeValue(root); writeCommentAfterValueOnSameLine(root); @@ -4662,7 +4734,7 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) { while (iter != comment.end()) { document_ += *iter; if (*iter == '\n' && - (iter != comment.end() && *(iter + 1) == '/')) + ((iter+1) != comment.end() && *(iter + 1) == '/')) writeIndent(); ++iter; } @@ -4698,7 +4770,7 @@ StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation) void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) { document_ = &out; addChildValues_ = false; - indentString_ = ""; + indentString_.clear(); indented_ = true; writeCommentBeforeValue(root); if (!indented_) writeIndent(); @@ -4878,7 +4950,7 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { while (iter != comment.end()) { *document_ << *iter; if (*iter == '\n' && - (iter != comment.end() && *(iter + 1) == '/')) + ((iter+1) != comment.end() && *(iter + 1) == '/')) // writeIndent(); // would include newline *document_ << indentString_; ++iter; @@ -4980,7 +5052,7 @@ int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) sout_ = sout; addChildValues_ = false; indented_ = true; - indentString_ = ""; + indentString_.clear(); writeCommentBeforeValue(root); if (!indented_) writeIndent(); indented_ = true; @@ -5166,7 +5238,7 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) { while (iter != comment.end()) { *sout_ << *iter; if (*iter == '\n' && - (iter != comment.end() && *(iter + 1) == '/')) + ((iter+1) != comment.end() && *(iter + 1) == '/')) // writeIndent(); // would write extra newline *sout_ << indentString_; ++iter; @@ -5234,10 +5306,10 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const } JSONCPP_STRING nullSymbol = "null"; if (dnp) { - nullSymbol = ""; + nullSymbol.clear(); } if (pre > 17) pre = 17; - JSONCPP_STRING endingLineFeedSymbol = ""; + JSONCPP_STRING endingLineFeedSymbol; return new BuiltStyledStreamWriter( indentation, cs, colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre); diff --git a/src/gui/components/cc_frm_clock.h b/src/gui/components/cc_frm_clock.h index 4595edd58..590353478 100644 --- a/src/gui/components/cc_frm_clock.h +++ b/src/gui/components/cc_frm_clock.h @@ -58,7 +58,7 @@ class CComponentsFrmClock : public CComponentsForm, public CCTextScreen int cl_interval; ///raw time chars - char cl_timestr[20]; + char cl_timestr[32]; ///handle paint clock within thread and is not similar to cc_allow_paint bool paintClock; diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index a989e910e..4811214f0 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include @@ -835,12 +836,12 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi return false; } + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(result_string, root, false); - if (!parsedSuccess) { + bool ok = parseJsonFromString(result_string, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); if (box != NULL) { box->hide(); delete box; diff --git a/src/gui/osd_setup.cpp b/src/gui/osd_setup.cpp index f244145ee..25c8ed147 100644 --- a/src/gui/osd_setup.cpp +++ b/src/gui/osd_setup.cpp @@ -1325,7 +1325,7 @@ void COsdSetup::showOsdInfobarSetup(CMenuWidget *menu_infobar) } //channellist -void COsdSetup::showOsdChanlistSetup(CMenuWidget *menu_chanlist) +void COsdSetup::showOsdChanlistSetup(CMenuWidget *menu_chanlist, bool hint_paint) { CMenuOptionChooser * mc; @@ -1334,27 +1334,32 @@ void COsdSetup::showOsdChanlistSetup(CMenuWidget *menu_chanlist) // channellist additional mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_ADDITIONAL, &g_settings.channellist_additional, CHANNELLIST_ADDITIONAL_OPTIONS, CHANNELLIST_ADDITIONAL_OPTION_COUNT, true); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_ADDITIONAL); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_ADDITIONAL); menu_chanlist->addItem(mc); // epg align mc = new CMenuOptionChooser(LOCALE_MISCSETTINGS_CHANNELLIST_EPGTEXT_ALIGN, &g_settings.channellist_epgtext_align_right, CHANNELLIST_EPGTEXT_ALIGN_RIGHT_OPTIONS, CHANNELLIST_EPGTEXT_ALIGN_RIGHT_OPTIONS_COUNT, true); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_EPG_ALIGN); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_EPG_ALIGN); menu_chanlist->addItem(mc); // extended channel list mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_EXTENDED, &g_settings.theme.progressbar_design_channellist, PROGRESSBAR_COLOR_OPTIONS, PROGRESSBAR_COLOR_OPTION_COUNT, true, this); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_EXTENDED); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_EXTENDED); menu_chanlist->addItem(mc); // show infobox mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_SHOW_INFOBOX, &g_settings.channellist_show_infobox, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true, channellistNotifier); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_INFOBOX); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_INFOBOX); menu_chanlist->addItem(mc); // foot mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_FOOT, &g_settings.channellist_foot, CHANNELLIST_FOOT_OPTIONS, CHANNELLIST_FOOT_OPTIONS_COUNT, g_settings.channellist_show_infobox); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_FOOT); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_FOOT); menu_chanlist->addItem(mc); channellistNotifier->addItem(mc); @@ -1362,13 +1367,15 @@ void COsdSetup::showOsdChanlistSetup(CMenuWidget *menu_chanlist) #if 0 //show channel logo mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_SHOW_CHANNELLOGO, &g_settings.channellist_show_channellogo, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_CHANNELLOGO); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_CHANNELLOGO); menu_chanlist->addItem(mc); #endif //show numbers mc = new CMenuOptionChooser(LOCALE_CHANNELLIST_SHOW_CHANNELNUMBER, &g_settings.channellist_show_numbers, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true); - mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_CHANNELNUMBER); + if(hint_paint) + mc->setHint("", LOCALE_MENU_HINT_CHANNELLIST_SHOW_CHANNELNUMBER); menu_chanlist->addItem(mc); } @@ -1608,7 +1615,7 @@ int COsdSetup::showContextChanlistMenu(CChannelList *parent_channellist) menu_chanlist->enableFade(false); menu_chanlist->setSelected(cselected); - showOsdChanlistSetup(menu_chanlist); + showOsdChanlistSetup(menu_chanlist, false); menu_chanlist->addItem(new CMenuSeparator(CMenuSeparator::LINE)); CMenuWidget *fontSettingsSubMenu = new CMenuWidget(LOCALE_FONTMENU_HEAD, NEUTRINO_ICON_KEYBINDING); @@ -1626,7 +1633,7 @@ int COsdSetup::showContextChanlistMenu(CChannelList *parent_channellist) fontSettingsSubMenu->addItem(new CMenuForwarder(LOCALE_OPTIONS_DEFAULT, true, NULL, this, font_sizes_groups[i].actionkey)); CMenuForwarder * mf = new CMenuDForwarder(LOCALE_FONTMENU_HEAD, true, NULL, fontSettingsSubMenu, NULL, CRCInput::RC_red); - mf->setHint("", LOCALE_MENU_HINT_FONTS); +// mf->setHint("", LOCALE_MENU_HINT_FONTS);//FIXME menu restoreScreen menu_chanlist->addItem(mf); int res = menu_chanlist->exec(NULL, ""); diff --git a/src/gui/osd_setup.h b/src/gui/osd_setup.h index d61080345..d587eb76f 100644 --- a/src/gui/osd_setup.h +++ b/src/gui/osd_setup.h @@ -75,7 +75,7 @@ class COsdSetup : public CMenuTarget, public CChangeObserver void showOsdMenusSetup(CMenuWidget *menu_menus); void showOsdChannellogosSetup(CMenuWidget *menu_channellogos); //NI void showOsdInfobarSetup(CMenuWidget *menu_infobar); - void showOsdChanlistSetup(CMenuWidget *menu_chanlist); + void showOsdChanlistSetup(CMenuWidget *menu_chanlist, bool hint_paint = true); void showOsdEventlistSetup(CMenuWidget *menu_eventlist); void showOsdVolumeSetup(CMenuWidget *menu_volume); void showOsdInfoclockSetup(CMenuWidget *menu_infoclock); diff --git a/src/gui/timerlist.cpp b/src/gui/timerlist.cpp index f51cb68df..34c61c0f6 100644 --- a/src/gui/timerlist.cpp +++ b/src/gui/timerlist.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include #include @@ -738,16 +739,15 @@ bool CTimerList::RemoteBoxChanExists(t_channel_id channel_id) r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id); r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(r_url, root, false); - if (!parsedSuccess) { + bool ok = parseJsonFromString(r_url, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); } r_url = root.get("success","false").asString(); - if (r_url == "false") ShowMsg(LOCALE_REMOTEBOX_CHANNEL_NA, convertChannelId2String(channel_id), CMsgBox::mbrOk, CMsgBox::mbOk, NULL, 450, 30, false); @@ -796,13 +796,12 @@ void CTimerList::RemoteBoxTimerList(CTimerd::TimerList &rtimerlist) r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); //printf("[remotetimer] timers:%s\n",r_url.c_str()); + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(r_url, root, false); - if (!parsedSuccess) - { + bool ok = parseJsonFromString(r_url, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); it->online = false; } else it->online = true; @@ -1293,13 +1292,12 @@ void CTimerList::paintItem(int pos) r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer.channel_id); r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(r_url, root, false); - if (!parsedSuccess) - { + bool ok = parseJsonFromString(r_url, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); } Json::Value remotechannel = root["data"]["channel"][0]; diff --git a/src/gui/tmdb.cpp b/src/gui/tmdb.cpp index 8ebe101c1..5a8208e27 100644 --- a/src/gui/tmdb.cpp +++ b/src/gui/tmdb.cpp @@ -35,6 +35,7 @@ #include "system/settings.h" #include "system/helpers.h" +#include #include "system/set_threadname.h" #include "gui/widget/hintbox.h" @@ -197,12 +198,12 @@ bool cTmdb::GetMovieDetails(std::string lang) if (!getUrl(url, answer)) return false; + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(answer, root, false); - if (!parsedSuccess) { + bool ok = parseJsonFromString(answer, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); return false; } @@ -219,10 +220,11 @@ bool cTmdb::GetMovieDetails(std::string lang) answer.clear(); if (!getUrl(url, answer)) return false; - parsedSuccess = reader.parse(answer, root, false); - if (!parsedSuccess) { + + ok = parseJsonFromString(answer, &root, &errMsg); + if (!ok) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); return false; } diff --git a/src/system/helpers-json.h b/src/system/helpers-json.h new file mode 100644 index 000000000..0e4923649 --- /dev/null +++ b/src/system/helpers-json.h @@ -0,0 +1,31 @@ +#ifndef __system_helpers_json__ +#define __system_helpers_json__ + +/* + Neutrino-HD + + License: GPL + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include + +using namespace std; + +bool parseJsonFromFile(string& jFile, Json::Value *root, string *errMsg); +bool parseJsonFromString(string& jData, Json::Value *root, string *errMsg); + +#endif diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 940114b15..3eb4b6862 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include "debug.h" @@ -49,6 +50,7 @@ #include //#include #include +#include #include #include #define MD5_DIGEST_LENGTH 16 @@ -1588,3 +1590,51 @@ string readLink(string lnk) return ""; } + +string readFile(string file) +{ + string ret_s; + ifstream tmpData(file.c_str(), ifstream::binary); + if (tmpData.is_open()) { + tmpData.seekg(0, tmpData.end); + int length = tmpData.tellg(); + tmpData.seekg(0, tmpData.beg); + char* buffer = new char[length+1]; + tmpData.read(buffer, length); + tmpData.close(); + buffer[length] = '\0'; + ret_s = (string)buffer; + delete [] buffer; + } + else { + cerr << "Error read " << file << endl; + return ""; + } + + return ret_s; +} + +bool parseJsonFromFile(string& jFile, Json::Value *root, string *errMsg) +{ + string jData = readFile(jFile); + bool ret = parseJsonFromString(jData, root, errMsg); + jData.clear(); + return ret; +} + +bool parseJsonFromString(string& jData, Json::Value *root, string *errMsg) +{ + Json::CharReaderBuilder builder; + Json::CharReader* reader(builder.newCharReader()); + JSONCPP_STRING errs = ""; + const char* jData_c = jData.c_str(); + + bool ret = reader->parse(jData_c, jData_c + strlen(jData_c), root, &errs); + if (!ret || (!errs.empty())) { + ret = false; + if (errMsg != NULL) + *errMsg = errs; + } + delete reader; + return ret; +} diff --git a/src/system/helpers.h b/src/system/helpers.h index 502ffc37f..c39eac448 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -155,4 +155,6 @@ std::string get_path(const char * path); std::string check_var(const char * file); inline bool file_exists(const std::string file) { return file_exists(file.c_str()); } +std::string readFile(std::string file); + #endif diff --git a/src/system/ytparser.cpp b/src/system/ytparser.cpp index 407d452a4..6bd43c576 100644 --- a/src/system/ytparser.cpp +++ b/src/system/ytparser.cpp @@ -38,6 +38,7 @@ #include #include "settings.h" #include "helpers.h" +#include "helpers-json.h" #include "set_threadname.h" #include #include @@ -288,25 +289,25 @@ std::string cYTFeedParser::getXmlData(xmlNodePtr node) bool cYTFeedParser::parseFeedJSON(std::string &answer) { + string errMsg = ""; Json::Value root; - Json::Reader reader; std::ostringstream ss; std::ifstream fh(curfeedfile.c_str(),std::ifstream::in); ss << fh.rdbuf(); std::string filedata = ss.str(); - bool parsedSuccess = reader.parse(filedata,root,false); + bool parsedSuccess = parseJsonFromString(filedata, &root, NULL); if(!parsedSuccess) { - parsedSuccess = reader.parse(answer,root,false); + parsedSuccess = parseJsonFromString(answer, &root, &errMsg); } if(!parsedSuccess) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); return false; } @@ -383,15 +384,16 @@ bool cYTFeedParser::parseFeedDetailsJSON(cYTVideoInfo* vinfo) if (!getUrl(url, answer)) return false; + string errMsg = ""; Json::Value root; - Json::Reader reader; - bool parsedSuccess = reader.parse(answer, root, false); + bool parsedSuccess = parseJsonFromString(answer, &root, &errMsg); if (!parsedSuccess) { printf("Failed to parse JSON\n"); - printf("%s\n", reader.getFormattedErrorMessages().c_str()); + printf("%s\n", errMsg.c_str()); return false; } + Json::Value elements = root["items"]; std::string duration = elements[0]["contentDetails"].get("duration", "").asString(); if (duration.find("PT") != std::string::npos) {