react-native-mmkv 3.3.0 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +18 -9
- package/android/build.gradle +6 -2
- package/cpp/{MMKVManagedBuffer.h → ManagedMMBuffer.h} +6 -6
- package/cpp/MmkvHostObject.cpp +13 -8
- package/cpp/MmkvHostObject.h +1 -2
- package/cpp/MmkvTypes.h +50 -0
- package/cpp/NativeMmkvModule.cpp +3 -3
- package/cpp/NativeMmkvModule.h +1 -8
- package/package.json +22 -23
- package/react-native-mmkv.podspec +3 -9
- package/react-native.config.js +9 -0
- package/MMKV/Core/CMakeLists.txt +0 -172
- package/MMKV/Core/CodedInputData.cpp +0 -252
- package/MMKV/Core/CodedInputData.h +0 -87
- package/MMKV/Core/CodedInputDataCrypt.cpp +0 -280
- package/MMKV/Core/CodedInputDataCrypt.h +0 -87
- package/MMKV/Core/CodedInputDataCrypt_OSX.cpp +0 -62
- package/MMKV/Core/CodedInputData_OSX.cpp +0 -92
- package/MMKV/Core/CodedOutputData.cpp +0 -186
- package/MMKV/Core/CodedOutputData.h +0 -88
- package/MMKV/Core/Core.xcodeproj/project.pbxproj +0 -707
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +0 -67
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +0 -67
- package/MMKV/Core/InterProcessLock.cpp +0 -186
- package/MMKV/Core/InterProcessLock.h +0 -119
- package/MMKV/Core/InterProcessLock_Android.cpp +0 -103
- package/MMKV/Core/InterProcessLock_Win32.cpp +0 -108
- package/MMKV/Core/KeyValueHolder.cpp +0 -236
- package/MMKV/Core/KeyValueHolder.h +0 -122
- package/MMKV/Core/MMBuffer.cpp +0 -210
- package/MMKV/Core/MMBuffer.h +0 -111
- package/MMKV/Core/MMKV.cpp +0 -1702
- package/MMKV/Core/MMKV.h +0 -595
- package/MMKV/Core/MMKVLog.cpp +0 -127
- package/MMKV/Core/MMKVLog.h +0 -86
- package/MMKV/Core/MMKVLog_Android.cpp +0 -134
- package/MMKV/Core/MMKVMetaInfo.hpp +0 -99
- package/MMKV/Core/MMKVPredef.h +0 -293
- package/MMKV/Core/MMKV_Android.cpp +0 -261
- package/MMKV/Core/MMKV_IO.cpp +0 -1905
- package/MMKV/Core/MMKV_IO.h +0 -57
- package/MMKV/Core/MMKV_OSX.cpp +0 -423
- package/MMKV/Core/MMKV_OSX.h +0 -57
- package/MMKV/Core/MemoryFile.cpp +0 -603
- package/MMKV/Core/MemoryFile.h +0 -194
- package/MMKV/Core/MemoryFile_Android.cpp +0 -236
- package/MMKV/Core/MemoryFile_Linux.cpp +0 -125
- package/MMKV/Core/MemoryFile_OSX.cpp +0 -142
- package/MMKV/Core/MemoryFile_Win32.cpp +0 -554
- package/MMKV/Core/MiniPBCoder.cpp +0 -672
- package/MMKV/Core/MiniPBCoder.h +0 -151
- package/MMKV/Core/MiniPBCoder_OSX.cpp +0 -237
- package/MMKV/Core/PBEncodeItem.hpp +0 -104
- package/MMKV/Core/PBUtility.cpp +0 -61
- package/MMKV/Core/PBUtility.h +0 -148
- package/MMKV/Core/ScopedLock.hpp +0 -69
- package/MMKV/Core/ThreadLock.cpp +0 -75
- package/MMKV/Core/ThreadLock.h +0 -81
- package/MMKV/Core/ThreadLock_Win32.cpp +0 -89
- package/MMKV/Core/aes/AESCrypt.cpp +0 -273
- package/MMKV/Core/aes/AESCrypt.h +0 -112
- package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +0 -1243
- package/MMKV/Core/aes/openssl/openssl_aes.h +0 -130
- package/MMKV/Core/aes/openssl/openssl_aes_core.cpp +0 -1044
- package/MMKV/Core/aes/openssl/openssl_aes_locl.h +0 -38
- package/MMKV/Core/aes/openssl/openssl_aesv8-armx.S +0 -308
- package/MMKV/Core/aes/openssl/openssl_arm_arch.h +0 -84
- package/MMKV/Core/aes/openssl/openssl_cfb128.cpp +0 -97
- package/MMKV/Core/aes/openssl/openssl_md32_common.h +0 -254
- package/MMKV/Core/aes/openssl/openssl_md5.h +0 -49
- package/MMKV/Core/aes/openssl/openssl_md5_dgst.cpp +0 -166
- package/MMKV/Core/aes/openssl/openssl_md5_locl.h +0 -75
- package/MMKV/Core/aes/openssl/openssl_md5_one.cpp +0 -30
- package/MMKV/Core/aes/openssl/openssl_opensslconf.h +0 -271
- package/MMKV/Core/core.vcxproj +0 -288
- package/MMKV/Core/core.vcxproj.filters +0 -150
- package/MMKV/Core/crc32/Checksum.h +0 -75
- package/MMKV/Core/crc32/crc32_armv8.cpp +0 -134
- package/MMKV/Core/crc32/zlib/CMakeLists.txt +0 -60
- package/MMKV/Core/crc32/zlib/crc32.cpp +0 -55
- package/MMKV/Core/crc32/zlib/crc32.h +0 -48
- package/MMKV/Core/crc32/zlib/zconf.h +0 -380
- package/MMKV/Core/crc32/zlib/zutil.h +0 -25
- package/MMKV/LICENSE.TXT +0 -193
- package/MMKV/README.md +0 -354
package/MMKV/Core/MMKV_IO.h
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making
|
|
3
|
-
* MMKV available.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (C) 2020 THL A29 Limited, a Tencent company.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the BSD 3-Clause License (the "License"); you may not use
|
|
9
|
-
* this file except in compliance with the License. You may obtain a copy of
|
|
10
|
-
* the License at
|
|
11
|
-
*
|
|
12
|
-
* https://opensource.org/licenses/BSD-3-Clause
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
#ifndef MMKV_IO_h
|
|
22
|
-
#define MMKV_IO_h
|
|
23
|
-
#ifdef __cplusplus
|
|
24
|
-
|
|
25
|
-
#include "MMKV.h"
|
|
26
|
-
|
|
27
|
-
MMKV_NAMESPACE_BEGIN
|
|
28
|
-
|
|
29
|
-
std::string mmapedKVKey(const std::string &mmapID, const MMKVPath_t *rootPath = nullptr);
|
|
30
|
-
MMKVPath_t mappedKVPathWithID(const std::string &mmapID, MMKVMode mode, const MMKVPath_t *rootPath);
|
|
31
|
-
MMKVPath_t crcPathWithID(const std::string &mmapID, MMKVMode mode, const MMKVPath_t *rootPath);
|
|
32
|
-
|
|
33
|
-
MMKVRecoverStrategic onMMKVCRCCheckFail(const std::string &mmapID);
|
|
34
|
-
MMKVRecoverStrategic onMMKVFileLengthError(const std::string &mmapID);
|
|
35
|
-
|
|
36
|
-
template <typename T>
|
|
37
|
-
void clearDictionary(T *dic) {
|
|
38
|
-
if (!dic) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
#ifdef MMKV_APPLE
|
|
42
|
-
for (auto &pair : *dic) {
|
|
43
|
-
[pair.first release];
|
|
44
|
-
}
|
|
45
|
-
#endif
|
|
46
|
-
dic->clear();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
enum : bool {
|
|
50
|
-
KeepSequence = false,
|
|
51
|
-
IncreaseSequence = true,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
MMKV_NAMESPACE_END
|
|
55
|
-
|
|
56
|
-
#endif
|
|
57
|
-
#endif /* MMKV_IO_h */
|
package/MMKV/Core/MMKV_OSX.cpp
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making
|
|
3
|
-
* MMKV available.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the BSD 3-Clause License (the "License"); you may not use
|
|
9
|
-
* this file except in compliance with the License. You may obtain a copy of
|
|
10
|
-
* the License at
|
|
11
|
-
*
|
|
12
|
-
* https://opensource.org/licenses/BSD-3-Clause
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
#include "MMKVPredef.h"
|
|
22
|
-
|
|
23
|
-
#ifdef MMKV_APPLE
|
|
24
|
-
|
|
25
|
-
# include "CodedInputData.h"
|
|
26
|
-
# include "CodedOutputData.h"
|
|
27
|
-
# include "InterProcessLock.h"
|
|
28
|
-
# include "MMKV.h"
|
|
29
|
-
# include "MemoryFile.h"
|
|
30
|
-
# include "MiniPBCoder.h"
|
|
31
|
-
# include "PBUtility.h"
|
|
32
|
-
# include "ScopedLock.hpp"
|
|
33
|
-
# include "ThreadLock.h"
|
|
34
|
-
# include "aes/AESCrypt.h"
|
|
35
|
-
# include <sys/utsname.h>
|
|
36
|
-
# include <sys/sysctl.h>
|
|
37
|
-
# include "MMKV_OSX.h"
|
|
38
|
-
# include "MMKVLog.h"
|
|
39
|
-
|
|
40
|
-
# ifdef MMKV_IOS
|
|
41
|
-
# include <sys/mman.h>
|
|
42
|
-
# endif
|
|
43
|
-
|
|
44
|
-
# ifdef __aarch64__
|
|
45
|
-
# include "crc32/Checksum.h"
|
|
46
|
-
# endif
|
|
47
|
-
|
|
48
|
-
# if __has_feature(objc_arc)
|
|
49
|
-
# error This file must be compiled with MRC. Use -fno-objc-arc flag.
|
|
50
|
-
# endif
|
|
51
|
-
|
|
52
|
-
using namespace std;
|
|
53
|
-
using namespace mmkv;
|
|
54
|
-
|
|
55
|
-
extern ThreadLock *g_instanceLock;
|
|
56
|
-
extern MMKVPath_t g_rootDir;
|
|
57
|
-
|
|
58
|
-
MMKV_NAMESPACE_BEGIN
|
|
59
|
-
|
|
60
|
-
# ifdef MMKV_IOS
|
|
61
|
-
MLockPtr::MLockPtr(void *ptr, size_t size) : m_lockDownSize(0), m_lockedPtr(nullptr) {
|
|
62
|
-
if (!ptr || size == 0) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// calc ptr to mlock()
|
|
66
|
-
auto writePtr = (size_t) ptr;
|
|
67
|
-
auto lockPtr = (writePtr / DEFAULT_MMAP_SIZE) * DEFAULT_MMAP_SIZE;
|
|
68
|
-
auto lockDownSize = writePtr - lockPtr + size;
|
|
69
|
-
if (mlock((void *) lockPtr, lockDownSize) == 0) {
|
|
70
|
-
m_lockedPtr = (uint8_t *) lockPtr;
|
|
71
|
-
m_lockDownSize = lockDownSize;
|
|
72
|
-
} else {
|
|
73
|
-
MMKVError("fail to mlock [%p], %s", m_lockedPtr, strerror(errno));
|
|
74
|
-
// just fail on this condition, otherwise app will crash anyway
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
MLockPtr::MLockPtr(MLockPtr &&other) : m_lockDownSize(other.m_lockDownSize), m_lockedPtr(other.m_lockedPtr) {
|
|
79
|
-
other.m_lockedPtr = nullptr;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
MLockPtr::~MLockPtr() {
|
|
83
|
-
if (m_lockedPtr) {
|
|
84
|
-
munlock(m_lockedPtr, m_lockDownSize);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
bool MLockPtr::isMLockPtrEnabled = true;
|
|
89
|
-
|
|
90
|
-
# endif
|
|
91
|
-
|
|
92
|
-
# ifdef MMKV_IOS
|
|
93
|
-
|
|
94
|
-
static bool g_isInBackground = false;
|
|
95
|
-
|
|
96
|
-
void MMKV::setIsInBackground(bool isInBackground) {
|
|
97
|
-
if (!g_instanceLock) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
SCOPED_LOCK(g_instanceLock);
|
|
101
|
-
|
|
102
|
-
g_isInBackground = isInBackground;
|
|
103
|
-
MMKVInfo("g_isInBackground:%d", g_isInBackground);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
bool MMKV::isInBackground() {
|
|
107
|
-
if (!g_instanceLock) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
SCOPED_LOCK(g_instanceLock);
|
|
111
|
-
|
|
112
|
-
return g_isInBackground;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
pair<bool, MLockPtr> guardForBackgroundWriting(void *ptr, size_t size) {
|
|
116
|
-
if (g_isInBackground && MLockPtr::isMLockPtrEnabled) {
|
|
117
|
-
MLockPtr mlockPtr(ptr, size);
|
|
118
|
-
return make_pair(mlockPtr.isLocked(), std::move(mlockPtr));
|
|
119
|
-
} else {
|
|
120
|
-
return make_pair(true, MLockPtr(nullptr, 0));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
# endif // MMKV_IOS
|
|
125
|
-
|
|
126
|
-
bool MMKV::set(NSObject<NSCoding> *__unsafe_unretained obj, MMKVKey_t key) {
|
|
127
|
-
return set(obj, key, m_expiredInSeconds);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
bool MMKV::set(NSObject<NSCoding> *__unsafe_unretained obj, MMKVKey_t key, uint32_t expireDuration) {
|
|
131
|
-
if (isKeyEmpty(key)) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
if (!obj) {
|
|
135
|
-
removeValueForKey(key);
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
NSData *tmpData = nil;
|
|
140
|
-
if ([obj isKindOfClass:NSString.class]) {
|
|
141
|
-
auto str = (NSString *) obj;
|
|
142
|
-
tmpData = [str dataUsingEncoding:NSUTF8StringEncoding];
|
|
143
|
-
} else if ([obj isKindOfClass:NSData.class]) {
|
|
144
|
-
tmpData = (NSData *) obj;
|
|
145
|
-
}
|
|
146
|
-
if (tmpData) {
|
|
147
|
-
// delay write the size needed for encoding tmpData
|
|
148
|
-
// avoid memory copying
|
|
149
|
-
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
150
|
-
return setDataForKey(MMBuffer(tmpData, MMBufferNoCopy), key, true);
|
|
151
|
-
} else {
|
|
152
|
-
MMBuffer data(tmpData, MMBufferNoCopy);
|
|
153
|
-
if (data.length() > 0) {
|
|
154
|
-
auto tmp = MMBuffer(pbMMBufferSize(data) + Fixed32Size);
|
|
155
|
-
CodedOutputData output(tmp.getPtr(), tmp.length());
|
|
156
|
-
output.writeData(data);
|
|
157
|
-
auto time = (expireDuration != 0) ? getCurrentTimeInSecond() + expireDuration : 0;
|
|
158
|
-
output.writeRawLittleEndian32(UInt32ToInt32(time));
|
|
159
|
-
data = std::move(tmp);
|
|
160
|
-
}
|
|
161
|
-
return setDataForKey(std::move(data), key);
|
|
162
|
-
}
|
|
163
|
-
} else if ([obj isKindOfClass:NSDate.class]) {
|
|
164
|
-
NSDate *oDate = (NSDate *) obj;
|
|
165
|
-
double time = oDate.timeIntervalSince1970;
|
|
166
|
-
return set(time, key, expireDuration);
|
|
167
|
-
} else {
|
|
168
|
-
/*if ([object conformsToProtocol:@protocol(NSCoding)])*/ {
|
|
169
|
-
@try {
|
|
170
|
-
NSError *error = nil;
|
|
171
|
-
auto archived = [NSKeyedArchiver archivedDataWithRootObject:obj requiringSecureCoding:NO error:&error];
|
|
172
|
-
if (error) {
|
|
173
|
-
MMKVError("fail to archive: %@", error);
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
if (archived.length > 0) {
|
|
177
|
-
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
178
|
-
return setDataForKey(MMBuffer(archived, MMBufferNoCopy), key);
|
|
179
|
-
} else {
|
|
180
|
-
MMBuffer data(archived, MMBufferNoCopy);
|
|
181
|
-
if (data.length() > 0) {
|
|
182
|
-
auto tmp = MMBuffer(data.length() + Fixed32Size);
|
|
183
|
-
CodedOutputData output(tmp.getPtr(), tmp.length());
|
|
184
|
-
output.writeRawData(data); // NSKeyedArchiver has its own size management
|
|
185
|
-
auto time = (expireDuration != 0) ? getCurrentTimeInSecond() + expireDuration : 0;
|
|
186
|
-
output.writeRawLittleEndian32(UInt32ToInt32(time));
|
|
187
|
-
data = std::move(tmp);
|
|
188
|
-
}
|
|
189
|
-
return setDataForKey(std::move(data), key);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
} @catch (NSException *exception) {
|
|
193
|
-
MMKVError("exception: %@", exception.reason);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
static id unSecureUnArchiveObjectWithData(NSData *data) {
|
|
201
|
-
@try {
|
|
202
|
-
NSError *error = nil;
|
|
203
|
-
auto unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:&error];
|
|
204
|
-
if (error) {
|
|
205
|
-
MMKVError("fail to init unarchiver %@", error);
|
|
206
|
-
return nil;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
unarchiver.requiresSecureCoding = NO;
|
|
210
|
-
id result = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
|
|
211
|
-
[unarchiver release];
|
|
212
|
-
return result;
|
|
213
|
-
} @catch (NSException *exception) {
|
|
214
|
-
MMKVError("exception: %@", exception.reason);
|
|
215
|
-
}
|
|
216
|
-
return nil;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
NSObject *MMKV::getObject(MMKVKey_t key, Class cls) {
|
|
220
|
-
if (isKeyEmpty(key) || !cls) {
|
|
221
|
-
return nil;
|
|
222
|
-
}
|
|
223
|
-
SCOPED_LOCK(m_lock);
|
|
224
|
-
SCOPED_LOCK(m_sharedProcessLock);
|
|
225
|
-
auto data = getDataForKey(key);
|
|
226
|
-
if (data.length() > 0) {
|
|
227
|
-
if (MiniPBCoder::isCompatibleClass(cls)) {
|
|
228
|
-
try {
|
|
229
|
-
auto result = MiniPBCoder::decodeObject(data, cls);
|
|
230
|
-
return result;
|
|
231
|
-
} catch (std::exception &exception) {
|
|
232
|
-
MMKVError("%s", exception.what());
|
|
233
|
-
} catch (...) {
|
|
234
|
-
MMKVError("decode fail");
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
if ([cls conformsToProtocol:@protocol(NSCoding)]) {
|
|
238
|
-
auto tmp = [NSData dataWithBytesNoCopy:data.getPtr() length:data.length() freeWhenDone:NO];
|
|
239
|
-
return unSecureUnArchiveObjectWithData(tmp);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return nil;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
# ifndef MMKV_DISABLE_CRYPT
|
|
247
|
-
|
|
248
|
-
pair<bool, KeyValueHolder>
|
|
249
|
-
MMKV::appendDataWithKey(const MMBuffer &data, MMKVKey_t key, const KeyValueHolderCrypt &kvHolder, bool isDataHolder) {
|
|
250
|
-
if (kvHolder.type != KeyValueHolderType_Offset) {
|
|
251
|
-
return appendDataWithKey(data, key, isDataHolder);
|
|
252
|
-
}
|
|
253
|
-
SCOPED_LOCK(m_exclusiveProcessLock);
|
|
254
|
-
|
|
255
|
-
uint32_t keyLength = kvHolder.keySize;
|
|
256
|
-
// size needed to encode the key
|
|
257
|
-
size_t rawKeySize = keyLength + pbRawVarint32Size(keyLength);
|
|
258
|
-
|
|
259
|
-
auto basePtr = (uint8_t *) m_file->getMemory() + Fixed32Size;
|
|
260
|
-
MMBuffer keyData(rawKeySize);
|
|
261
|
-
AESCrypt decrypter = m_crypter->cloneWithStatus(kvHolder.cryptStatus);
|
|
262
|
-
decrypter.decrypt(basePtr + kvHolder.offset, keyData.getPtr(), rawKeySize);
|
|
263
|
-
|
|
264
|
-
return doAppendDataWithKey(data, keyData, isDataHolder, keyLength);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
pair<bool, KeyValueHolder>
|
|
268
|
-
MMKV::overrideDataWithKey(const MMBuffer &data, MMKVKey_t key, const KeyValueHolderCrypt &kvHolder, bool isDataHolder) {
|
|
269
|
-
if (kvHolder.type != KeyValueHolderType_Offset) {
|
|
270
|
-
return overrideDataWithKey(data, key, isDataHolder);
|
|
271
|
-
}
|
|
272
|
-
SCOPED_LOCK(m_exclusiveProcessLock);
|
|
273
|
-
|
|
274
|
-
uint32_t keyLength = kvHolder.keySize;
|
|
275
|
-
// size needed to encode the key
|
|
276
|
-
size_t rawKeySize = keyLength + pbRawVarint32Size(keyLength);
|
|
277
|
-
|
|
278
|
-
auto basePtr = (uint8_t *) m_file->getMemory() + Fixed32Size;
|
|
279
|
-
MMBuffer keyData(rawKeySize);
|
|
280
|
-
AESCrypt decrypter = m_crypter->cloneWithStatus(kvHolder.cryptStatus);
|
|
281
|
-
decrypter.decrypt(basePtr + kvHolder.offset, keyData.getPtr(), rawKeySize);
|
|
282
|
-
|
|
283
|
-
return doOverrideDataWithKey(data, keyData, isDataHolder, keyLength);
|
|
284
|
-
}
|
|
285
|
-
# endif
|
|
286
|
-
|
|
287
|
-
NSArray *MMKV::allKeys(bool filterExpire) {
|
|
288
|
-
SCOPED_LOCK(m_lock);
|
|
289
|
-
checkLoadData();
|
|
290
|
-
|
|
291
|
-
if (mmkv_unlikely(filterExpire && m_enableKeyExpire)) {
|
|
292
|
-
SCOPED_LOCK(m_exclusiveProcessLock);
|
|
293
|
-
fullWriteback(nullptr, true);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
NSMutableArray *keys = [NSMutableArray array];
|
|
297
|
-
if (m_crypter) {
|
|
298
|
-
for (const auto &pair : *m_dicCrypt) {
|
|
299
|
-
[keys addObject:pair.first];
|
|
300
|
-
}
|
|
301
|
-
} else {
|
|
302
|
-
for (const auto &pair : *m_dic) {
|
|
303
|
-
[keys addObject:pair.first];
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return keys;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
bool MMKV::removeValuesForKeys(NSArray *arrKeys) {
|
|
310
|
-
if (isReadOnly()) {
|
|
311
|
-
MMKVWarning("[%s] file readonly", m_mmapID.c_str());
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
if (arrKeys.count == 0) {
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
if (arrKeys.count == 1) {
|
|
318
|
-
return removeValueForKey(arrKeys[0]);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
SCOPED_LOCK(m_lock);
|
|
322
|
-
SCOPED_LOCK(m_exclusiveProcessLock);
|
|
323
|
-
checkLoadData();
|
|
324
|
-
|
|
325
|
-
size_t deleteCount = 0;
|
|
326
|
-
if (m_crypter) {
|
|
327
|
-
for (NSString *key in arrKeys) {
|
|
328
|
-
auto itr = m_dicCrypt->find(key);
|
|
329
|
-
if (itr != m_dicCrypt->end()) {
|
|
330
|
-
auto oldKey = itr->first;
|
|
331
|
-
m_dicCrypt->erase(itr);
|
|
332
|
-
[oldKey release];
|
|
333
|
-
deleteCount++;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
} else {
|
|
337
|
-
for (NSString *key in arrKeys) {
|
|
338
|
-
auto itr = m_dic->find(key);
|
|
339
|
-
if (itr != m_dic->end()) {
|
|
340
|
-
auto oldKey = itr->first;
|
|
341
|
-
m_dic->erase(itr);
|
|
342
|
-
[oldKey release];
|
|
343
|
-
deleteCount++;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (deleteCount > 0) {
|
|
348
|
-
m_hasFullWriteback = false;
|
|
349
|
-
|
|
350
|
-
return fullWriteback();
|
|
351
|
-
}
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
void MMKV::enumerateKeys(EnumerateBlock block) {
|
|
356
|
-
if (block == nil) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
SCOPED_LOCK(m_lock);
|
|
360
|
-
checkLoadData();
|
|
361
|
-
|
|
362
|
-
MMKVInfo("enumerate [%s] begin", m_mmapID.c_str());
|
|
363
|
-
if (m_crypter) {
|
|
364
|
-
for (const auto &pair : *m_dicCrypt) {
|
|
365
|
-
BOOL stop = NO;
|
|
366
|
-
block(pair.first, &stop);
|
|
367
|
-
if (stop) {
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
} else {
|
|
372
|
-
for (const auto &pair : *m_dic) {
|
|
373
|
-
BOOL stop = NO;
|
|
374
|
-
block(pair.first, &stop);
|
|
375
|
-
if (stop) {
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
MMKVInfo("enumerate [%s] finish", m_mmapID.c_str());
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
void GetAppleMachineInfo(int &device, int &version) {
|
|
384
|
-
device = UnKnown;
|
|
385
|
-
version = 0;
|
|
386
|
-
|
|
387
|
-
# if 0
|
|
388
|
-
struct utsname systemInfo = {};
|
|
389
|
-
uname(&systemInfo);
|
|
390
|
-
std::string machine(systemInfo.machine);
|
|
391
|
-
# else
|
|
392
|
-
size_t size;
|
|
393
|
-
sysctlbyname("hw.machine", nullptr, &size, nullptr, 0);
|
|
394
|
-
char *answer = (char *) malloc(size);
|
|
395
|
-
sysctlbyname("hw.machine", answer, &size, nullptr, 0);
|
|
396
|
-
std::string machine(answer);
|
|
397
|
-
free(answer);
|
|
398
|
-
# endif
|
|
399
|
-
|
|
400
|
-
if (machine.find("PowerMac") != std::string::npos || machine.find("Power Macintosh") != std::string::npos) {
|
|
401
|
-
device = PowerMac;
|
|
402
|
-
} else if (machine.find("Mac") != std::string::npos || machine.find("Macintosh") != std::string::npos) {
|
|
403
|
-
device = Mac;
|
|
404
|
-
} else if (machine.find("iPhone") != std::string::npos) {
|
|
405
|
-
device = iPhone;
|
|
406
|
-
} else if (machine.find("iPod") != std::string::npos) {
|
|
407
|
-
device = iPod;
|
|
408
|
-
} else if (machine.find("iPad") != std::string::npos) {
|
|
409
|
-
device = iPad;
|
|
410
|
-
} else if (machine.find("AppleTV") != std::string::npos) {
|
|
411
|
-
device = AppleTV;
|
|
412
|
-
} else if (machine.find("AppleWatch") != std::string::npos) {
|
|
413
|
-
device = AppleWatch;
|
|
414
|
-
}
|
|
415
|
-
auto pos = machine.find_first_of("0123456789");
|
|
416
|
-
if (pos != std::string::npos) {
|
|
417
|
-
version = std::atoi(machine.substr(pos).c_str());
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
MMKV_NAMESPACE_END
|
|
422
|
-
|
|
423
|
-
#endif // MMKV_APPLE
|
package/MMKV/Core/MMKV_OSX.h
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making
|
|
3
|
-
* MMKV available.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the BSD 3-Clause License (the "License"); you may not use
|
|
9
|
-
* this file except in compliance with the License. You may obtain a copy of
|
|
10
|
-
* the License at
|
|
11
|
-
*
|
|
12
|
-
* https://opensource.org/licenses/BSD-3-Clause
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
#pragma once
|
|
22
|
-
#include "MMKVPredef.h"
|
|
23
|
-
|
|
24
|
-
MMKV_NAMESPACE_BEGIN
|
|
25
|
-
|
|
26
|
-
#if defined(MMKV_IOS) && defined(__cplusplus)
|
|
27
|
-
|
|
28
|
-
class MLockPtr {
|
|
29
|
-
size_t m_lockDownSize;
|
|
30
|
-
uint8_t *m_lockedPtr;
|
|
31
|
-
|
|
32
|
-
public:
|
|
33
|
-
MLockPtr(void *ptr, size_t size);
|
|
34
|
-
MLockPtr(MLockPtr &&other);
|
|
35
|
-
|
|
36
|
-
~MLockPtr();
|
|
37
|
-
|
|
38
|
-
bool isLocked() const {
|
|
39
|
-
return (m_lockedPtr != nullptr);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static bool isMLockPtrEnabled;
|
|
43
|
-
|
|
44
|
-
// just forbid it for possibly misuse
|
|
45
|
-
explicit MLockPtr(const MLockPtr &other) = delete;
|
|
46
|
-
MLockPtr &operator=(const MLockPtr &other) = delete;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
std::pair<bool, MLockPtr> guardForBackgroundWriting(void *ptr, size_t size);
|
|
50
|
-
|
|
51
|
-
#endif
|
|
52
|
-
|
|
53
|
-
enum { UnKnown = 0, PowerMac = 1, Mac, iPhone, iPod, iPad, AppleTV, AppleWatch };
|
|
54
|
-
|
|
55
|
-
void GetAppleMachineInfo(int &device, int &version);
|
|
56
|
-
|
|
57
|
-
MMKV_NAMESPACE_END
|