[messaging] Fixed AttributeFilter for TO attribute. 92/217692/1
authorMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 12 Nov 2019 12:57:27 +0000 (13:57 +0100)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Wed, 13 Nov 2019 09:26:02 +0000 (10:26 +0100)
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 <m.michalski2@partner.samsung.com>
Change-Id: If20589614ecd920a01a8afa1b987699fdf919ad2

src/messaging/MsgCommon/AbstractFilter.cpp
src/messaging/MsgCommon/AbstractFilter.h
src/messaging/message_conversation.cc
src/messaging/messaging_instance.cc

index 123128e..3acdf31 100644 (file)
@@ -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<time_t>::min() : initial_value->toTimeT();
+  time_t from_time = initial_value->isNullOrUndefined() ? std::numeric_limits<time_t>::min()
+                                                        : initial_value->toTimeT();
 
-  time_t to_time = end_value->isNullOrUndefined() ?
-                    std::numeric_limits<time_t>::max() : end_value->toTimeT();
+  time_t to_time =
+      end_value->isNullOrUndefined() ? std::numeric_limits<time_t>::max() : end_value->toTimeT();
 
   bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time);
 
index 2d0bd37..feea786 100644 (file)
 #ifndef __TIZEN_TIZEN_ABSTRACT_FILTER_H__
 #define __TIZEN_TIZEN_ABSTRACT_FILTER_H__
 
+#include <time.h>
 #include <memory>
 #include <sstream>
 #include <vector>
-#include <time.h>
 //#include <JSArray.h>
 
 #include "Any.h"
index e8116dd..71ce740 100644 (file)
 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<std::string> recipients,
+                                   const AttributeMatchFlag match_flag) {
+  ScopeLogger();
+  if (!match_value->getValue().is<picojson::array>()) {
+    LoggerE("AttributeFilter value for TO attribute must be an array of strings.");
+    return false;
+  }
+
+  const auto array = match_value->getValue().get<picojson::array>();
+  for (const auto value : array) {
+    if (!value.is<std::string>()) {
+      LoggerE("AttributeFilter value for TO attribute must be an array of strings.");
+      return false;
+    }
+
+    if (!isAnyStringMatching(value.get<std::string>(), recipients, match_flag)) {
+      LoggerD("AttributeFilter TO match failed on %s", value.get<std::string>().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<picojson::array>()) {
+      return ContainsAllRequiredRecipients(match_value, getTo(), match_flag);
+    } else if (match_value->getValue().is<std::string>()) {
+      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) {
index 98e9b71..0b15aa7 100644 (file)
@@ -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);