• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DISTRIBUTEDDB_TYPES_EXPORT_H
17 #define DISTRIBUTEDDB_TYPES_EXPORT_H
18 
19 #include <cstdint>
20 #include <vector>
21 #include <climits>
22 #include <string>
23 #include <functional>
24 
25 namespace DistributedDB {
26 #ifdef _WIN32
27     #ifdef DB_DLL_EXPORT
28         #define DB_API __declspec(dllexport)
29     #else
30         #define DB_API
31     #endif
32 #else
33     #define DB_API __attribute__ ((visibility ("default")))
34 #endif
35 
36 #define DB_SYMBOL DB_API
37 
38 using Key = std::vector<uint8_t>;
39 using Value = std::vector<uint8_t>;
40 
41 struct Entry {
42     Key key;
43     Value value;
44 };
45 
46 enum class CipherType {
47     DEFAULT,
48     AES_256_GCM, // AES-256-GCM
49 };
50 
51 class CipherPassword final {
52 public:
53     enum ErrorCode {
54         OK = 0,
55         OVERSIZE,
56         INVALID_INPUT,
57         SECUREC_ERROR,
58     };
59 
60     DB_API CipherPassword();
61     DB_API ~CipherPassword();
62 
63     DB_API bool operator==(const CipherPassword &input) const;
64     DB_API bool operator!=(const CipherPassword &input) const;
65 
66     DB_API size_t GetSize() const;
67     DB_API const uint8_t *GetData() const;
68     DB_API int SetValue(const uint8_t *inputData, size_t inputSize);
69     DB_API int Clear();
70 
71 private:
72     static const size_t MAX_PASSWORD_SIZE = 128;
73     uint8_t data_[MAX_PASSWORD_SIZE] = {UCHAR_MAX};
74     size_t size_ = 0;
75 };
76 
77 using PragmaData = void *;
78 
79 struct PragmaEntryDeviceIdentifier {
80     Key key;
81     bool origDevice = true;
82     std::string deviceIdentifier;
83 };
84 
85 using KvStoreNbPublishAction = std::function<void (const Entry &local, const Entry *sync, bool isLocalLastest)>;
86 
87 struct PragmaDeviceIdentifier {
88     std::string deviceID;
89     std::string deviceIdentifier;
90 };
91 
92 enum WipePolicy {
93     RETAIN_STALE_DATA = 1, // remote stale data will be retained in syncing when remote db rebuiled.
94     WIPE_STALE_DATA // remote stale data will be wiped when in syncing remote db rebuiled.
95 };
96 
97 // We don't parse, read or modify the array type, so there are not a corresponding array value
98 // The leaf object is empty, an internal object always composed by other type values.
99 struct FieldValue {
100     union {
101         bool boolValue;
102         int32_t integerValue;
103         int64_t longValue = 0;
104         double doubleValue;
105     };
106     std::string stringValue;
107 };
108 
109 enum PermissionCheckFlag {
110     CHECK_FLAG_SEND = 1, // send
111     CHECK_FLAG_RECEIVE = 2, // receive
112     CHECK_FLAG_AUTOSYNC = 4, // autosync flag
113     CHECK_FLAG_SPONSOR = 8, // sync sponsor
114 };
115 
116 using PermissionCheckCallback = std::function<bool (const std::string &userId, const std::string &appId,
117     const std::string &storeId, uint8_t flag)>;
118 
119 using PermissionCheckCallbackV2 = std::function<bool (const std::string &userId, const std::string &appId,
120     const std::string &storeId, const std::string &deviceId, uint8_t flag)>;
121 
122 using StoreStatusNotifier = std::function<void (std::string userId, std::string appId, std::string storeId,
123     const std::string deviceId, bool onlineStatus)>; // status, 1: online, 0: offline
124 
125 using SyncActivationCheckCallback = std::function<bool (const std::string &userId, const std::string &appId,
126     const std::string &storeId)>;
127 
128 enum AutoLaunchStatus {
129     WRITE_OPENED = 1,
130     WRITE_CLOSED = 2,
131     INVALID_PARAM = 3, // AutoLaunchRequestCallback, if param check failed
132 };
133 
134 using AutoLaunchNotifier = std::function<void (const std::string &userId,
135     const std::string &appId, const std::string &storeId, AutoLaunchStatus status)>;
136 
137 enum SecurityLabel : int {
138     INVALID_SEC_LABEL = -1,
139     NOT_SET = 0,
140     S0,
141     S1,
142     S2,
143     S3,
144     S4
145 };
146 
147 // security flag type
148 enum SecurityFlag : int {
149     INVALID_SEC_FLAG = -1,
150     ECE = 0,
151     SECE
152 };
153 
154 struct SecurityOption {
155     int securityLabel = 0; // the securityLabel is the class of data sensitive, see enum SecurityLabel
156     int securityFlag = 0;  // the securityFlag is the encryption method of the file only used for S3 like 0:ECE, 1:SECE
157     bool operator==(const SecurityOption &rhs) const
158     {
159         return securityLabel == rhs.securityLabel && securityFlag == rhs.securityFlag;
160     }
161 };
162 
163 enum class ResultSetCacheMode : int {
164     CACHE_FULL_ENTRY = 0,       // Ordinary mode efficient when sequential access, the default mode
165     CACHE_ENTRY_ID_ONLY = 1,    // Special mode efficient when random access
166 };
167 
168 struct RemotePushNotifyInfo {
169     std::string deviceId;
170 };
171 using RemotePushFinishedNotifier = std::function<void (const RemotePushNotifyInfo &info)>;
172 using RemotePushFinisheNotifier = RemotePushFinishedNotifier; // To correct spelling errors in the previous version
173 
174 enum class CompressAlgorithm : uint8_t {
175     NONE = 0,
176     ZLIB = 1
177 };
178 } // namespace DistributedDB
179 #endif // DISTRIBUTEDDB_TYPES_EXPORT_H
180