From: Michal Michalski Date: Tue, 12 Nov 2019 12:57:27 +0000 (+0100) Subject: [messaging] Fixed AttributeFilter for TO attribute. X-Git-Tag: submit/tizen/20191211.130748~21^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd48c9bf15ea6aff04a0390f41680cbff1b3b3eb;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [messaging] Fixed AttributeFilter for TO attribute. AttributeFilter in case of TO attribute accepts an array of recipients instead of a single string, as was previously incorrectly assumed in the implementation. [Verification] tct-messaging-email-tizen-tests 100% tct-messaging-sms-tizen-tests 100% tct-messaging-mms-tizen-tests 100% Signed-off-by: Michal Michalski Change-Id: If20589614ecd920a01a8afa1b987699fdf919ad2 --- diff --git a/src/messaging/MsgCommon/AbstractFilter.cpp b/src/messaging/MsgCommon/AbstractFilter.cpp index 123128e5..3acdf316 100644 --- a/src/messaging/MsgCommon/AbstractFilter.cpp +++ b/src/messaging/MsgCommon/AbstractFilter.cpp @@ -195,16 +195,16 @@ bool FilterUtils::isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& in ScopeLogger(); if (!initial_value || !end_value) { - LoggerD("initial_value is %snull. end_value is %snull", - initial_value ? "NOT " : "", end_value ? "NOT " : ""); + LoggerD("initial_value is %snull. end_value is %snull", initial_value ? "NOT " : "", + end_value ? "NOT " : ""); return false; } - time_t from_time = initial_value->isNullOrUndefined() ? - std::numeric_limits::min() : initial_value->toTimeT(); + 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(); + 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 2d0bd378..feea7865 100644 --- a/src/messaging/MsgCommon/AbstractFilter.h +++ b/src/messaging/MsgCommon/AbstractFilter.h @@ -17,10 +17,10 @@ #ifndef __TIZEN_TIZEN_ABSTRACT_FILTER_H__ #define __TIZEN_TIZEN_ABSTRACT_FILTER_H__ +#include #include #include #include -#include //#include #include "Any.h" diff --git a/src/messaging/message_conversation.cc b/src/messaging/message_conversation.cc index e8116ddc..71ce7405 100644 --- a/src/messaging/message_conversation.cc +++ b/src/messaging/message_conversation.cc @@ -27,6 +27,39 @@ using common::ErrorCode; using common::PlatformResult; +namespace { + +using extension::messaging::AnyPtr; +using common::AttributeMatchFlag; +using namespace extension::messaging::FilterUtils; + +bool ContainsAllRequiredRecipients(AnyPtr match_value, std::vector recipients, + const AttributeMatchFlag match_flag) { + ScopeLogger(); + if (!match_value->getValue().is()) { + LoggerE("AttributeFilter value for TO attribute must be an array of strings."); + return false; + } + + const auto array = match_value->getValue().get(); + for (const auto value : array) { + if (!value.is()) { + LoggerE("AttributeFilter value for TO attribute must be an array of strings."); + return false; + } + + if (!isAnyStringMatching(value.get(), recipients, match_flag)) { + LoggerD("AttributeFilter TO match failed on %s", value.get().c_str()); + return false; + } + } + + return true; +} + +} // namespace + + namespace extension { namespace messaging { @@ -442,7 +475,6 @@ void MessageConversation::setLastMessageId(int last_message_id) { * bcc | Yes | No * lastMessageId | Yes | No */ - bool MessageConversation::isMatchingAttribute(const std::string& attribute_name, const common::AttributeMatchFlag match_flag, AnyPtr match_value) const { @@ -474,7 +506,14 @@ bool MessageConversation::isMatchingAttribute(const std::string& attribute_name, } else if (MESSAGE_CONVERSATION_ATTRIBUTE_FROM == attribute_name) { return FilterUtils::isMatching(*match_value, getFrom(), match_flag); } else if (MESSAGE_CONVERSATION_ATTRIBUTE_TO == attribute_name) { - return FilterUtils::isAnyStringMatching(match_value->toString(), getTo(), match_flag); + if (match_value->getValue().is()) { + return ContainsAllRequiredRecipients(match_value, getTo(), match_flag); + } else if (match_value->getValue().is()) { + return FilterUtils::isAnyStringMatching(match_value->toString(), getTo(), match_flag); + } else { + LoggerE("Unsupported type of AttributeFilter value for TO attribute."); + return false; + } } else if (MESSAGE_CONVERSATION_ATTRIBUTE_CC == attribute_name) { return FilterUtils::isAnyStringMatching(match_value->toString(), getCC(), match_flag); } else if (MESSAGE_CONVERSATION_ATTRIBUTE_BCC == attribute_name) { diff --git a/src/messaging/messaging_instance.cc b/src/messaging/messaging_instance.cc index 98e9b71f..0b15aa7c 100644 --- a/src/messaging/messaging_instance.cc +++ b/src/messaging/messaging_instance.cc @@ -91,8 +91,7 @@ MessagingInstance::MessagingInstance() : manager_(*this), queue_(*this) { using std::placeholders::_1; using std::placeholders::_2; -#define REGISTER_METHOD(M) \ - RegisterSyncHandler(#M, std::bind(&MessagingInstance::M, this, _1, _2)) +#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MessagingInstance::M, this, _1, _2)) REGISTER_METHOD(GetMessageServices); REGISTER_METHOD(MessageServiceSendMessage); REGISTER_METHOD(MessageServiceLoadMessageBody); @@ -105,7 +104,6 @@ MessagingInstance::MessagingInstance() : manager_(*this), queue_(*this) { REGISTER_METHOD(MessageStorageRemoveConversations); REGISTER_METHOD(MessageStorageFindFolders); - REGISTER_METHOD(MessageServiceSync); REGISTER_METHOD(MessageServiceStopSync); REGISTER_METHOD(MessageServiceSyncFolder); @@ -399,7 +397,8 @@ void MessagingInstance::MessageServiceStopSync(const picojson::value& args, pico } } -void MessagingInstance::MessageStorageAddDraftMessage(const picojson::value& args, picojson::object& out) { +void MessagingInstance::MessageStorageAddDraftMessage(const picojson::value& args, + picojson::object& out) { ScopeLogger(); CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);