1 // Copyright 2016 The Weave Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBWEAVE_SRC_ACCESS_BLACK_LIST_H_
6 #define LIBWEAVE_SRC_ACCESS_BLACK_LIST_H_
7 
8 #include <vector>
9 
10 #include <base/time/time.h>
11 
12 namespace weave {
13 
14 class AccessBlackListManager {
15  public:
16   struct Entry {
17     // user_id is empty, app_id is empty: block everything.
18     // user_id is not empty, app_id is empty: block if user_id matches.
19     // user_id is empty, app_id is not empty: block if app_id matches.
20     // user_id is not empty, app_id is not empty: block if both match.
21     std::vector<uint8_t> user_id;
22     std::vector<uint8_t> app_id;
23 
24     // Time after which to discard the rule.
25     base::Time expiration;
26   };
27   virtual ~AccessBlackListManager() = default;
28 
29   virtual void Block(const std::vector<uint8_t>& user_id,
30                      const std::vector<uint8_t>& app_id,
31                      const base::Time& expiration,
32                      const DoneCallback& callback) = 0;
33   virtual void Unblock(const std::vector<uint8_t>& user_id,
34                        const std::vector<uint8_t>& app_id,
35                        const DoneCallback& callback) = 0;
36   virtual bool IsBlocked(const std::vector<uint8_t>& user_id,
37                          const std::vector<uint8_t>& app_id) const = 0;
38   virtual std::vector<Entry> GetEntries() const = 0;
39   virtual size_t GetSize() const = 0;
40   virtual size_t GetCapacity() const = 0;
41 };
42 
43 inline bool operator==(const AccessBlackListManager::Entry& l,
44                        const AccessBlackListManager::Entry& r) {
45   return l.user_id == r.user_id && l.app_id == r.app_id &&
46          l.expiration == r.expiration;
47 }
48 
49 inline bool operator!=(const AccessBlackListManager::Entry& l,
50                        const AccessBlackListManager::Entry& r) {
51   return !(l == r);
52 }
53 
54 }  // namespace weave
55 
56 #endif  // LIBWEAVE_SRC_ACCESS_BLACK_LIST_H_
57