[Non-ACR] Bug fixe & removing deprecated json API 84/229184/1 accepted/tizen_6.0_unified_hotfix tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.122700 accepted/tizen/6.0/unified/hotfix/20201103.005004 accepted/tizen/6.0/unified/hotfix/20201103.052429 accepted/tizen/unified/20200402.155623 submit/tizen/20200401.060048 submit/tizen_6.0/20201029.205102 submit/tizen_6.0_hotfix/20201102.192502 submit/tizen_6.0_hotfix/20201103.114802 tizen_6.0.m2_release
authorAbhishek Vijay <abhishek.v@samsung.com>
Fri, 27 Mar 2020 06:38:07 +0000 (12:08 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Mon, 30 Mar 2020 07:13:01 +0000 (07:13 +0000)
Change-Id: Id37dbcd88864060de02b84ded2190b45088ba8fe
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
(cherry picked from commit 85f0a47131ea1bdb5e7c8ce73659ce59b332bdde)

src/history/context_history.cpp
src/trigger/ContextItem.cpp
src/trigger/CustomTemplate.cpp

index 2208e23..0ce43cc 100644 (file)
@@ -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;
 }
index 7943d4a..5f17717 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <memory>
 #include <map>
 #include <vector>
 #include <algorithm>
@@ -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<Json::CharReader> 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) {
index 93031eb..72ab4f6 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <memory>
 #include <regex>
 #include <context_trigger.h>
 #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<Json::CharReader> 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<Json::CharReader> 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;
        }