From: Abhishek Vijay Date: Fri, 27 Mar 2020 06:38:07 +0000 (+0530) Subject: [Non-ACR] Bug fixe & removing deprecated json API X-Git-Tag: submit/tizen/20200401.060048^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_6.0_hotfix;p=platform%2Fcore%2Fapi%2Fcontext.git [Non-ACR] Bug fixe & removing deprecated json API Change-Id: Id37dbcd88864060de02b84ded2190b45088ba8fe Signed-off-by: Abhishek Vijay (cherry picked from commit 85f0a47131ea1bdb5e7c8ce73659ce59b332bdde) --- diff --git a/src/history/context_history.cpp b/src/history/context_history.cpp index 2208e23..0ce43cc 100644 --- a/src/history/context_history.cpp +++ b/src/history/context_history.cpp @@ -210,9 +210,8 @@ EXPORT_API int context_history_get_list(context_history_h handle, context_histor std::string filterStr; if (filter) { - Json::FastWriter fw; - fw.omitEndingLineFeed(); - filterStr = fw.write(filter->jfilter); + Json::StreamWriterBuilder builder; + filterStr = Json::writeString(builder, filter->jfilter); } int err = _ctx_history_query(data_type_str.c_str(), filterStr.c_str(), &((*list)->cursor)); @@ -294,7 +293,7 @@ EXPORT_API int context_history_record_get_int(context_history_record_h record, c int64_t value; IF_FAIL_RETURN_TAG(record->tuple->getAt(index, &value), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid data"); - *val = value; + (value < 0) ? (*val = 0) : (*val = value); return CONTEXT_HISTORY_ERROR_NONE; } diff --git a/src/trigger/ContextItem.cpp b/src/trigger/ContextItem.cpp index 7943d4a..5f17717 100644 --- a/src/trigger/ContextItem.cpp +++ b/src/trigger/ContextItem.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -70,9 +71,11 @@ bool ContextItem::isValid(ctx_sched_job_context_h jobContext) Json::Value jCtx; try { - Json::Reader reader; - if (!reader.parse(serialized, jCtx)) { - _E("Parsing failed"); + std::string error; + Json::CharReaderBuilder builder; + std::unique_ptr reader(builder.newCharReader()); + if (!reader->parse(serialized, (serialized+strlen(serialized)), &jCtx, &error)) { + _E("Parsing failed - error[%s]", error.c_str()); return false; } } catch (const Json::Exception& e) { diff --git a/src/trigger/CustomTemplate.cpp b/src/trigger/CustomTemplate.cpp index 93031eb..72ab4f6 100644 --- a/src/trigger/CustomTemplate.cpp +++ b/src/trigger/CustomTemplate.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include "CustomTemplate.h" @@ -42,12 +43,15 @@ const std::string& CustomTemplate::getName() const int CustomTemplate::match(const std::string& fact) { // true if the given fact is valid w.r.t. the template - Json::Reader reader; Json::Value factJson; + std::string error; + Json::CharReaderBuilder builder; + std::unique_ptr reader(builder.newCharReader()); + // Error: Invalid Json - if (!reader.parse(fact, factJson)) { - _E("Fact: invalid json"); + if (!reader->parse(fact.c_str(), (fact.c_str()+fact.size()), &factJson, &error)) { + _E("Fact: invalid json, error [%s]", error.c_str()); return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; } @@ -198,12 +202,16 @@ int CustomTemplate::add(const std::string& name, const std::string& attrTmpl) static std::regex nameRegex(R"~(^[\w-\._\/]+$)~", std::regex::optimize); IF_FAIL_RETURN_TAG(std::regex_match(name, nameRegex), CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Invalid name"); - Json::Reader reader; Json::Value tmplJson; + std::string error; + Json::CharReaderBuilder builder; + std::unique_ptr reader(builder.newCharReader()); + // Error: Invalid Json - if (!reader.parse(attrTmpl, tmplJson)) { - _E("Template: invalid json"); + if (!reader->parse(attrTmpl.c_str(), \ + (attrTmpl.c_str()+attrTmpl.size()), &tmplJson, &error)) { + _E("Template: invalid json, error [%s]", error.c_str()); return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; }