1 /*
2 * Copyright (c) 2023 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 #define LOG_TAG "ExtensionUtil"
17 #include "extension_util.h"
18 #include "log_print.h"
19
20 namespace OHOS::CloudData {
Convert(DBVBuckets && buckets)21 std::pair<OhCloudExtVector *, size_t> ExtensionUtil::Convert(DBVBuckets &&buckets)
22 {
23 OhCloudExtVector *datas = OhCloudExtVectorNew(OhCloudExtRustType::VALUETYPE_HASHMAP_VALUE);
24 if (datas == nullptr) {
25 return { nullptr, 0 };
26 }
27 size_t datasLen = 0;
28 for (auto &bucket : buckets) {
29 auto value = Convert(bucket);
30 if (value.first == nullptr) {
31 return { nullptr, 0 };
32 }
33 auto status = OhCloudExtVectorPush(datas, value.first, value.second);
34 if (status != ERRNO_SUCCESS) {
35 return { nullptr, 0 };
36 }
37 datasLen += 1;
38 }
39 return { datas, datasLen };
40 }
41
Convert(const DBVBucket & bucket)42 std::pair<OhCloudExtHashMap *, size_t> ExtensionUtil::Convert(const DBVBucket &bucket)
43 {
44 OhCloudExtHashMap *values = OhCloudExtHashMapNew(OhCloudExtRustType::VALUETYPE_VALUE);
45 if (values == nullptr) {
46 return { nullptr, 0 };
47 }
48 size_t valuesLen = 0;
49 for (auto &[col, dbValue] : bucket) {
50 void *value = nullptr;
51 size_t valueLen = 0;
52 if (dbValue.index() == TYPE_INDEX<DBAsset>) {
53 DBAsset dbAsset = std::get<DBAsset>(dbValue);
54 auto data = Convert(dbAsset);
55 OhCloudExtValue *asset = OhCloudExtValueNew(
56 OhCloudExtValueType::VALUEINNERTYPE_ASSET, data.first, data.second);
57 value = asset;
58 valueLen = data.second;
59 } else if (dbValue.index() == TYPE_INDEX<DBAssets>) {
60 DBAssets dbAssets = std::get<DBAssets>(dbValue);
61 auto data = Convert(dbAssets);
62 OhCloudExtValue *assets = OhCloudExtValueNew(
63 OhCloudExtValueType::VALUEINNERTYPE_ASSETS, data.first, data.second);
64 value = assets;
65 valueLen = data.second;
66 } else {
67 auto data = Convert(dbValue);
68 value = data.first;
69 valueLen = data.second;
70 }
71 if (value == nullptr) {
72 return { nullptr, 0 };
73 }
74 auto status = OhCloudExtHashMapInsert(values,
75 const_cast<void *>(reinterpret_cast<const void *>(col.c_str())), col.size(), value, valueLen);
76 if (status != ERRNO_SUCCESS) {
77 return { nullptr, 0 };
78 }
79 valuesLen += valueLen;
80 }
81 return { values, valuesLen };
82 }
83
Convert(const DBValue & dbValue)84 std::pair<OhCloudExtValue *, size_t> ExtensionUtil::Convert(const DBValue &dbValue)
85 {
86 OhCloudExtValue *value = nullptr;
87 size_t valueLen = 0;
88 if (dbValue.index() == TYPE_INDEX<int64_t>) {
89 int64_t val = std::get<int64_t>(dbValue);
90 value = OhCloudExtValueNew(OhCloudExtValueType::VALUEINNERTYPE_INT, &val, sizeof(int64_t));
91 valueLen = sizeof(int64_t);
92 } else if (dbValue.index() == TYPE_INDEX<std::string>) {
93 std::string val = std::get<std::string>(dbValue);
94 value = OhCloudExtValueNew(OhCloudExtValueType::VALUEINNERTYPE_STRING,
95 const_cast<void *>(reinterpret_cast<const void *>(val.c_str())), val.size());
96 valueLen = val.size();
97 } else if (dbValue.index() == TYPE_INDEX<bool>) {
98 bool val = std::get<bool>(dbValue);
99 value = OhCloudExtValueNew(OhCloudExtValueType::VALUEINNERTYPE_BOOL, &val, sizeof(bool));
100 valueLen = sizeof(bool);
101 } else if (dbValue.index() == TYPE_INDEX<DBBytes>) {
102 DBBytes val = std::get<DBBytes>(dbValue);
103 if (!val.empty()) {
104 value = OhCloudExtValueNew(OhCloudExtValueType::VALUEINNERTYPE_BYTES, &val[0], val.size());
105 valueLen = val.size() * sizeof(uint8_t);
106 }
107 } else {
108 value = OhCloudExtValueNew(OhCloudExtValueType::VALUEINNERTYPE_EMPTY, nullptr, 0);
109 valueLen = 0;
110 }
111 return { value, valueLen };
112 }
113
Convert(const DBMeta & dbMeta)114 std::pair<OhCloudExtDatabase *, size_t> ExtensionUtil::Convert(const DBMeta &dbMeta)
115 {
116 OhCloudExtHashMap *databases = OhCloudExtHashMapNew(OhCloudExtRustType::VALUETYPE_TABLE);
117 if (databases == nullptr) {
118 return { nullptr, 0 };
119 }
120 size_t dbLen = 0;
121 for (auto &table : dbMeta.tables) {
122 auto [fields, tbLen] = Convert(table);
123 if (fields == nullptr) {
124 return { nullptr, 0 };
125 }
126 OhCloudExtTable *tb = OhCloudExtTableNew(reinterpret_cast<const unsigned char *>(table.name.c_str()),
127 table.name.size(), reinterpret_cast<const unsigned char *>(table.alias.c_str()),
128 table.alias.size(), fields);
129 if (tb == nullptr) {
130 return { nullptr, 0 };
131 }
132 tbLen = tbLen + table.name.size() + table.alias.size();
133 auto status = OhCloudExtHashMapInsert(databases,
134 const_cast<void *>(reinterpret_cast<const void *>(table.name.c_str())), table.name.size(), tb, tbLen);
135 if (status != ERRNO_SUCCESS) {
136 return { nullptr, 0 };
137 }
138 }
139 dbLen = dbLen + dbMeta.name.size() + dbMeta.alias.size();
140 OhCloudExtDatabase *db = OhCloudExtDatabaseNew(reinterpret_cast<const unsigned char *>(dbMeta.name.c_str()),
141 dbMeta.name.size(), reinterpret_cast<const unsigned char *>(dbMeta.alias.c_str()),
142 dbMeta.alias.size(), databases);
143 if (db == nullptr) {
144 return { nullptr, 0 };
145 }
146 return { db, dbLen };
147 }
148
Convert(const DBTable & dbTable)149 std::pair<OhCloudExtVector *, size_t> ExtensionUtil::Convert(const DBTable &dbTable)
150 {
151 size_t tbLen = 0;
152 OhCloudExtVector *fields = OhCloudExtVectorNew(OhCloudExtRustType::VALUETYPE_FIELD);
153 if (fields == nullptr) {
154 return { nullptr, 0 };
155 }
156 for (auto &field : dbTable.fields) {
157 size_t fdLen = field.colName.size() + field.alias.size() + sizeof(int) + sizeof(bool) * 2;
158 OhCloudExtFieldBuilder builder {
159 .colName = reinterpret_cast<const unsigned char *>(field.colName.c_str()),
160 .colNameLen = field.colName.size(),
161 .alias = reinterpret_cast<const unsigned char *>(field.alias.c_str()),
162 .aliasLen = field.alias.size(),
163 .typ = static_cast<unsigned int>(field.type),
164 .primary = field.primary,
165 .nullable = field.nullable
166 };
167 OhCloudExtField *fd = OhCloudExtFieldNew(&builder);
168 if (fd == nullptr) {
169 return { nullptr, 0 };
170 }
171 OhCloudExtVectorPush(fields, fd, fdLen);
172 tbLen += fdLen;
173 }
174 return { fields, tbLen };
175 }
176
ConvertBuckets(OhCloudExtVector * values)177 DBVBuckets ExtensionUtil::ConvertBuckets(OhCloudExtVector *values)
178 {
179 DBVBuckets buckets;
180 size_t len = 0;
181 auto status = OhCloudExtVectorGetLength(values, reinterpret_cast<unsigned int *>(&len));
182 if (status != ERRNO_SUCCESS || len == 0) {
183 return buckets;
184 }
185 buckets.reserve(len);
186 for (size_t i = 0; i < len; i++) {
187 void *value = nullptr;
188 size_t valueLen = 0;
189 status = OhCloudExtVectorGet(values, i, &value, reinterpret_cast<unsigned int *>(&valueLen));
190 if (status != ERRNO_SUCCESS || value == nullptr) {
191 return buckets;
192 }
193 auto pValues = std::shared_ptr<OhCloudExtHashMap>(reinterpret_cast<OhCloudExtHashMap *>(value),
194 [](auto *val) {
195 OhCloudExtHashMapFree(val);
196 });
197 buckets.emplace_back(ConvertBucket(pValues.get()));
198 }
199 return buckets;
200 }
201
ConvertBucket(OhCloudExtHashMap * value)202 DBVBucket ExtensionUtil::ConvertBucket(OhCloudExtHashMap *value)
203 {
204 DBVBucket bucket;
205 OhCloudExtVector *valKeys = nullptr;
206 OhCloudExtVector *valValues = nullptr;
207 auto status = OhCloudExtHashMapIterGetKeyValuePair(value, &valKeys, &valValues);
208 if (status != ERRNO_SUCCESS || valKeys == nullptr || valValues == nullptr) {
209 return bucket;
210 }
211 auto pValKeys = std::shared_ptr<OhCloudExtVector>(valKeys, [](auto *valkey) { OhCloudExtVectorFree(valkey); });
212 auto pValValues = std::shared_ptr<OhCloudExtVector>(valValues, [](auto *valValue) {
213 OhCloudExtVectorFree(valValue);
214 });
215 size_t valKeysLen = 0;
216 size_t valValuesLen = 0;
217 OhCloudExtVectorGetLength(pValKeys.get(), reinterpret_cast<unsigned int *>(&valKeysLen));
218 OhCloudExtVectorGetLength(pValValues.get(), reinterpret_cast<unsigned int *>(&valValuesLen));
219 if (valKeysLen == 0 || valKeysLen != valValuesLen) {
220 return bucket;
221 }
222 for (size_t j = 0; j < valKeysLen; j++) {
223 void *keyItem = nullptr;
224 size_t keyItemLen = 0;
225 status = OhCloudExtVectorGet(pValKeys.get(), j, &keyItem, reinterpret_cast<unsigned int *>(&keyItemLen));
226 if (status != ERRNO_SUCCESS || keyItem == nullptr) {
227 return bucket;
228 }
229 void *valueItem = nullptr;
230 size_t valueItemLen = 0;
231 status = OhCloudExtVectorGet(pValValues.get(), j, &valueItem, reinterpret_cast<unsigned int *>(&valueItemLen));
232 if (status != ERRNO_SUCCESS || valueItem == nullptr) {
233 return bucket;
234 }
235 OhCloudExtValue *valueOut = reinterpret_cast<OhCloudExtValue *>(valueItem);
236 std::string keyOut(reinterpret_cast<char *>(keyItem), keyItemLen);
237 bucket[keyOut] = ConvertValue(valueOut);
238 OhCloudExtValueFree(valueOut);
239 }
240 return bucket;
241 }
242
ConvertValue(OhCloudExtValue * value)243 DBValue ExtensionUtil::ConvertValue(OhCloudExtValue *value)
244 {
245 DBValue result;
246 OhCloudExtValueType type = OhCloudExtValueType::VALUEINNERTYPE_EMPTY;
247 void *content = nullptr;
248 size_t ctLen = 0;
249 auto status = OhCloudExtValueGetContent(value, &type, &content, reinterpret_cast<unsigned int *>(&ctLen));
250 if (status != ERRNO_SUCCESS || content == nullptr) {
251 return result;
252 }
253 DoConvertValue(content, ctLen, type, result);
254 return result;
255 }
256
ConvertValues(OhCloudExtValueBucket * bucket,const std::string & key)257 DBValue ExtensionUtil::ConvertValues(OhCloudExtValueBucket *bucket, const std::string &key)
258 {
259 DBValue result;
260 auto keyStr = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(key.c_str()));
261 OhCloudExtKeyName keyName = OhCloudExtKeyNameNew(keyStr, key.size());
262 OhCloudExtValueType type = OhCloudExtValueType::VALUEINNERTYPE_EMPTY;
263 void *content = nullptr;
264 unsigned int ctLen = 0;
265 auto status = OhCloudExtValueBucketGetValue(bucket, keyName, &type, &content, &ctLen);
266 if (status != ERRNO_SUCCESS || content == nullptr) {
267 return result;
268 }
269 DoConvertValue(content, ctLen, type, result);
270 return result;
271 }
272
DoConvertValue(void * content,unsigned int ctLen,OhCloudExtValueType type,DBValue & dbvalue)273 void ExtensionUtil::DoConvertValue(void *content, unsigned int ctLen, OhCloudExtValueType type, DBValue &dbvalue)
274 {
275 switch (type) {
276 case OhCloudExtValueType::VALUEINNERTYPE_EMPTY:
277 break;
278 case OhCloudExtValueType::VALUEINNERTYPE_INT:
279 dbvalue = *reinterpret_cast<int64_t *>(content);
280 break;
281 case OhCloudExtValueType::VALUEINNERTYPE_BOOL:
282 dbvalue = *reinterpret_cast<bool *>(content);
283 break;
284 case OhCloudExtValueType::VALUEINNERTYPE_STRING:
285 dbvalue = std::string(reinterpret_cast<char *>(content), ctLen);
286 break;
287 case OhCloudExtValueType::VALUEINNERTYPE_BYTES: {
288 std::vector<uint8_t> bytes;
289 uint8_t *begin = reinterpret_cast<uint8_t *>(content);
290 for (size_t i = 0; i < ctLen; i++) {
291 uint8_t bt = *begin;
292 bytes.emplace_back(bt);
293 begin = begin + 1;
294 }
295 dbvalue = bytes;
296 break;
297 }
298 case OhCloudExtValueType::VALUEINNERTYPE_ASSET: {
299 OhCloudExtCloudAsset *asset = reinterpret_cast<OhCloudExtCloudAsset *>(content);
300 dbvalue = ConvertAsset(asset);
301 OhCloudExtCloudAssetFree(asset);
302 break;
303 }
304 case OhCloudExtValueType::VALUEINNERTYPE_ASSETS: {
305 OhCloudExtVector *assets = reinterpret_cast<OhCloudExtVector *>(content);
306 dbvalue = ConvertAssets(assets);
307 OhCloudExtVectorFree(assets);
308 break;
309 }
310 default:
311 break;
312 }
313 }
314
ConvertAssets(OhCloudExtVector * values)315 DBAssets ExtensionUtil::ConvertAssets(OhCloudExtVector *values)
316 {
317 DBAssets result;
318 size_t assetsLen = 0;
319 auto status = OhCloudExtVectorGetLength(values, reinterpret_cast<unsigned int *>(&assetsLen));
320 if (status != ERRNO_SUCCESS || assetsLen == 0) {
321 return result;
322 }
323 result.reserve(assetsLen);
324 for (size_t i = 0; i < assetsLen; i++) {
325 void *value = nullptr;
326 size_t valueLen = 0;
327 status = OhCloudExtVectorGet(values, i, &value, reinterpret_cast<unsigned int *>(&valueLen));
328 if (status != ERRNO_SUCCESS || value == nullptr) {
329 return result;
330 }
331 OhCloudExtCloudAsset *asset = reinterpret_cast<OhCloudExtCloudAsset *>(value);
332 result.push_back(ConvertAsset(asset));
333 OhCloudExtCloudAssetFree(asset);
334 }
335 return result;
336 }
337
ConvertAsset(OhCloudExtCloudAsset * asset)338 DBAsset ExtensionUtil::ConvertAsset(OhCloudExtCloudAsset *asset)
339 {
340 DBAsset result;
341 unsigned char *id = nullptr;
342 size_t idLen = 0;
343 auto status = OhCloudExtCloudAssetGetId(asset, &id, reinterpret_cast<unsigned int *>(&idLen));
344 if (status != ERRNO_SUCCESS || id == nullptr) {
345 return result;
346 }
347 result.id = std::string(reinterpret_cast<char *>(id), idLen);
348 unsigned char *name = nullptr;
349 size_t nameLen = 0;
350 status = OhCloudExtCloudAssetGetName(asset, &name, reinterpret_cast<unsigned int *>(&nameLen));
351 if (status != ERRNO_SUCCESS || name == nullptr) {
352 return result;
353 }
354 result.name = std::string(reinterpret_cast<char *>(name), nameLen);
355 unsigned char *uri = nullptr;
356 size_t uriLen = 0;
357 status = OhCloudExtCloudAssetGetUri(asset, &uri, reinterpret_cast<unsigned int *>(&uriLen));
358 if (status != ERRNO_SUCCESS || uri == nullptr) {
359 return result;
360 }
361 result.uri = std::string(reinterpret_cast<char *>(uri), uriLen);
362 unsigned char *crtTime = nullptr;
363 size_t crtTimeLen = 0;
364 status = OhCloudExtCloudAssetGetCreateTime(asset, &crtTime, reinterpret_cast<unsigned int *>(&crtTimeLen));
365 if (status != ERRNO_SUCCESS || crtTime == nullptr) {
366 return result;
367 }
368 result.createTime = std::string(reinterpret_cast<char *>(crtTime), crtTimeLen);
369 ConvertAssetLeft(asset, result);
370 return result;
371 }
372
ConvertAssetLeft(OhCloudExtCloudAsset * asset,DBAsset & dbAsset)373 void ExtensionUtil::ConvertAssetLeft(OhCloudExtCloudAsset *asset, DBAsset &dbAsset)
374 {
375 unsigned char *mdTime = nullptr;
376 size_t mdTimeLen = 0;
377 auto status = OhCloudExtCloudAssetGetModifiedTime(asset, &mdTime, reinterpret_cast<unsigned int *>(&mdTimeLen));
378 if (status != ERRNO_SUCCESS || mdTime == nullptr) {
379 return;
380 }
381 dbAsset.modifyTime = std::string(reinterpret_cast<char *>(mdTime), mdTimeLen);
382 unsigned char *size = nullptr;
383 size_t sizeLen = 0;
384 status = OhCloudExtCloudAssetGetSize(asset, &size, reinterpret_cast<unsigned int *>(&sizeLen));
385 if (status != ERRNO_SUCCESS || size == nullptr) {
386 return;
387 }
388 dbAsset.size = std::string(reinterpret_cast<char *>(size), sizeLen);
389 unsigned char *hash = nullptr;
390 size_t hashLen = 0;
391 status = OhCloudExtCloudAssetGetHash(asset, &hash, reinterpret_cast<unsigned int *>(&hashLen));
392 if (status != ERRNO_SUCCESS || hash == nullptr) {
393 return;
394 }
395 dbAsset.hash = std::string(reinterpret_cast<char *>(hash), hashLen);
396 unsigned char *path = nullptr;
397 size_t pathLen = 0;
398 status = OhCloudExtCloudAssetGetLocalPath(asset, &path, reinterpret_cast<unsigned int *>(&pathLen));
399 if (status != ERRNO_SUCCESS || path == nullptr) {
400 return;
401 }
402 dbAsset.path = std::string(reinterpret_cast<char *>(path), pathLen);
403 }
404
ConvertAppInfo(OhCloudExtAppInfo * appInfo)405 DBInfo ExtensionUtil::ConvertAppInfo(OhCloudExtAppInfo *appInfo)
406 {
407 DBInfo info;
408 unsigned char *appId = nullptr;
409 size_t appIdLen = 0;
410 auto status = OhCloudExtAppInfoGetAppId(appInfo, &appId, reinterpret_cast<unsigned int *>(&appIdLen));
411 if (status != ERRNO_SUCCESS || appId == nullptr) {
412 return info;
413 }
414 info.appId = std::string(reinterpret_cast<char *>(appId), appIdLen);
415 unsigned char *bundle = nullptr;
416 size_t bundleLen = 0;
417 status = OhCloudExtAppInfoGetBundleName(appInfo, &bundle, reinterpret_cast<unsigned int *>(&bundleLen));
418 if (status != ERRNO_SUCCESS || bundle == nullptr) {
419 return info;
420 }
421 info.bundleName = std::string(reinterpret_cast<char *>(bundle), bundleLen);
422 OhCloudExtAppInfoGetCloudSwitch(appInfo, &info.cloudSwitch);
423 OhCloudExtAppInfoGetInstanceId(appInfo, &info.instanceId);
424 return info;
425 }
426
Convert(const DBAsset & dbAsset)427 std::pair<OhCloudExtCloudAsset *, size_t> ExtensionUtil::Convert(const DBAsset &dbAsset)
428 {
429 OhCloudExtCloudAssetBuilder builder {
430 .version = dbAsset.version,
431 .status = ConvertAssetStatus(static_cast<DBAssetStatus>(dbAsset.status)),
432 .expiresTime = dbAsset.expiresTime,
433 .id = reinterpret_cast<const unsigned char *>(dbAsset.id.c_str()),
434 .idLen = dbAsset.id.size(),
435 .name = reinterpret_cast<const unsigned char *>(dbAsset.name.c_str()),
436 .nameLen = dbAsset.name.size(),
437 .uri = reinterpret_cast<const unsigned char *>(dbAsset.uri.c_str()),
438 .uriLen = dbAsset.uri.size(),
439 .localPath = reinterpret_cast<const unsigned char *>(dbAsset.path.c_str()),
440 .localPathLen = dbAsset.path.size(),
441 .createTime = reinterpret_cast<const unsigned char *>(dbAsset.createTime.c_str()),
442 .createTimeLen = dbAsset.createTime.size(),
443 .modifyTime = reinterpret_cast<const unsigned char *>(dbAsset.modifyTime.c_str()),
444 .modifyTimeLen = dbAsset.modifyTime.size(),
445 .size = reinterpret_cast<const unsigned char *>(dbAsset.size.c_str()),
446 .sizeLen = dbAsset.size.size(),
447 .hash = reinterpret_cast<const unsigned char *>(dbAsset.hash.c_str()),
448 .hashLen = dbAsset.hash.size()
449 };
450 OhCloudExtCloudAsset *asset = OhCloudExtCloudAssetNew(&builder);
451 size_t assetLen = sizeof(uint64_t) * 2 + sizeof(OhCloudExtAssetStatus) + dbAsset.id.size()
452 + dbAsset.name.size() + dbAsset.uri.size() + dbAsset.createTime.size() + dbAsset.modifyTime.size()
453 + dbAsset.size.size() + dbAsset.hash.size() + dbAsset.path.size();
454 if (asset == nullptr) {
455 return { nullptr, 0 };
456 }
457 return { asset, assetLen };
458 }
459
Convert(const DBAssets & dbAssets)460 std::pair<OhCloudExtVector *, size_t> ExtensionUtil::Convert(const DBAssets &dbAssets)
461 {
462 OhCloudExtVector *assets = OhCloudExtVectorNew(OhCloudExtRustType::VALUETYPE_CLOUD_ASSET);
463 if (assets == nullptr) {
464 return { nullptr, 0 };
465 }
466 size_t assetsLen = 0;
467 for (const auto &dbAsset : dbAssets) {
468 auto data = Convert(dbAsset);
469 if (data.first == nullptr) {
470 return { nullptr, 0 };
471 }
472 auto status = OhCloudExtVectorPush(assets, data.first, data.second);
473 if (status != ERRNO_SUCCESS) {
474 return { nullptr, 0 };
475 }
476 assetsLen += 1;
477 }
478 return { assets, assetsLen };
479 }
480
ConvertAssetStatus(DBAssetStatus status)481 OhCloudExtAssetStatus ExtensionUtil::ConvertAssetStatus(DBAssetStatus status)
482 {
483 switch (status) {
484 case DBAssetStatus::STATUS_UNKNOWN:
485 return OhCloudExtAssetStatus::ASSETSTATUS_UNKNOWN;
486 case DBAssetStatus::STATUS_NORMAL:
487 return OhCloudExtAssetStatus::ASSETSTATUS_NORMAL;
488 case DBAssetStatus::STATUS_INSERT:
489 return OhCloudExtAssetStatus::ASSETSTATUS_INSERT;
490 case DBAssetStatus::STATUS_UPDATE:
491 return OhCloudExtAssetStatus::ASSETSTATUS_UPDATE;
492 case DBAssetStatus::STATUS_DELETE:
493 return OhCloudExtAssetStatus::ASSETSTATUS_DELETE;
494 case DBAssetStatus::STATUS_ABNORMAL:
495 return OhCloudExtAssetStatus::ASSETSTATUS_ABNORMAL;
496 case DBAssetStatus::STATUS_DOWNLOADING:
497 return OhCloudExtAssetStatus::ASSETSTATUS_DOWNLOADING;
498 case DBAssetStatus::STATUS_BUTT:
499 return OhCloudExtAssetStatus::ASSETSTATUS_BUTT;
500 default:
501 ZLOGI("err: 0x%{public}x", status);
502 break;
503 }
504 return OhCloudExtAssetStatus::ASSETSTATUS_UNKNOWN;
505 }
506
ConvertStatus(int status)507 DBErr ExtensionUtil::ConvertStatus(int status)
508 {
509 switch (status) {
510 case ERRNO_SUCCESS:
511 return DBErr::E_OK;
512 case ERRNO_NETWORK_ERROR:
513 return DBErr::E_NETWORK_ERROR;
514 case ERRNO_LOCKED_BY_OTHERS:
515 return DBErr::E_LOCKED_BY_OTHERS;
516 case ERRNO_RECORD_LIMIT_EXCEEDED:
517 return DBErr::E_RECODE_LIMIT_EXCEEDED;
518 case ERRNO_NO_SPACE_FOR_ASSET:
519 return DBErr::E_NO_SPACE_FOR_ASSET;
520 case ERRNO_UNSUPPORTED:
521 return DBErr::E_NOT_SUPPORT;
522 default:
523 ZLOGI("err: 0x%{public}x", status);
524 break;
525 }
526 return DBErr::E_ERROR;
527 }
528 } // namespace OHOS::CloudData