From 3c757a20b0e291015a3262922dbd1276721e36a4 Mon Sep 17 00:00:00 2001 From: Pawel Wasowski Date: Wed, 27 Feb 2019 20:14:19 +0100 Subject: [PATCH] [messaging] Fix bugs occurring when filtering by strings or value ranges The following bugs have been fixed: - daylight saving time was not taken into account when filtering by timestamp attribute with AttributeRangeFilter - AttributeRangeFilter did not work with null/undefined range limits - isBetweenTimeRange did not work properly with lower limit close to the minimal value of time_t type variables - filter with an empty string matchValue never matched other strings [Verification] Subtestcases from TCT tests added in https://review.tizen.org/gerrit/#/c/test/tct/web/api/+/199159/ that used to fail due to the described bugs now pass. tct-messaging-sms-tizen-tests pass rate: 100% This commit has already been reviewed: https://review.tizen.org/gerrit/#/c/platform/core/api/webapi-plugins/+/200662/ Change-Id of the original change was: Ia6c2074408e8f4fadd10605d6986b5a2d2d4c93b Change-Id: I6d28a8d153a34cf54084dae5585cbd7d0e771e4a Signed-off-by: Pawel Wasowski --- packaging/webapi-plugins.pc.in | 4 ++-- src/messaging/MsgCommon/AbstractFilter.cpp | 26 ++++++++++++-------------- src/messaging/MsgCommon/AbstractFilter.h | 5 +++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packaging/webapi-plugins.pc.in b/packaging/webapi-plugins.pc.in index e9cade2..747a966 100644 --- a/packaging/webapi-plugins.pc.in +++ b/packaging/webapi-plugins.pc.in @@ -1,6 +1,6 @@ project_name=webapi-plugins -libdir=__LIB_DIR__ -includedir=__INCLUDE_DIR__ +libdir=/usr/lib/tizen-extensions-crosswalk +includedir=/usr/include/webapi-plugins/src Name: ${project_name} Description: ${project_name} diff --git a/src/messaging/MsgCommon/AbstractFilter.cpp b/src/messaging/MsgCommon/AbstractFilter.cpp index 1eb527a..123128e 100644 --- a/src/messaging/MsgCommon/AbstractFilter.cpp +++ b/src/messaging/MsgCommon/AbstractFilter.cpp @@ -60,6 +60,10 @@ bool isMatchingString(const std::string& match_value, const std::string& value, AttributeMatchFlag flag) { ScopeLogger(); + if (match_value.empty() && value.empty()) { + return true; + } + switch (flag) { case AttributeMatchFlag::kEndsWith: { if (match_value.empty()) { @@ -189,24 +193,18 @@ bool FilterUtils::isAnyStringMatching(const std::string& key, bool FilterUtils::isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value, tizen::AnyPtr& end_value) { ScopeLogger(); - time_t from_time = 0; - if (initial_value && !initial_value->isNullOrUndefined()) { - struct tm ftime = *initial_value->toDateTm(); - from_time = mktime(&ftime); - } else { - LoggerE("initialValue is not Time!"); + if (!initial_value || !end_value) { + LoggerD("initial_value is %snull. end_value is %snull", + initial_value ? "NOT " : "", end_value ? "NOT " : ""); return false; } - time_t to_time = 0; - if (end_value && !end_value->isNullOrUndefined()) { - struct tm ttime = *end_value->toDateTm(); - to_time = mktime(&ttime); - } else { - LoggerE("endValue is not Time!"); - return false; - } + time_t from_time = initial_value->isNullOrUndefined() ? + std::numeric_limits::min() : initial_value->toTimeT(); + + time_t to_time = end_value->isNullOrUndefined() ? + std::numeric_limits::max() : end_value->toTimeT(); bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time); diff --git a/src/messaging/MsgCommon/AbstractFilter.h b/src/messaging/MsgCommon/AbstractFilter.h index c4eea0e..2d0bd37 100644 --- a/src/messaging/MsgCommon/AbstractFilter.h +++ b/src/messaging/MsgCommon/AbstractFilter.h @@ -20,6 +20,7 @@ #include #include #include +#include //#include #include "Any.h" @@ -94,8 +95,8 @@ bool isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value, tizen::AnyPtr& end_value); bool isInRange(const unsigned long messageCount, const unsigned long initial_value, const unsigned long end_value); -inline bool isBetweenTimeRange(const time_t current, const time_t from, const time_t to) { - return ((current - from) >= 0) && ((to - current) >= 0); +inline bool isBetweenTimeRange(const time_t timestamp, const time_t from, const time_t to) { + return (difftime(timestamp, from) >= 0.0) && (difftime(to, timestamp) >= 0.0); } /* -- 2.7.4