mirror of
https://gitee.com/openharmony/security_asset
synced 2024-12-03 13:40:51 +00:00
implement napi query
Change-Id: I44b5206f38c96dc5077dda367869849e17876616 Match-id-7aecd2e3195bc47181ca911496cabd0f89a740db
This commit is contained in:
parent
dd8998295d
commit
27a5086861
@ -49,11 +49,8 @@ find -name "*.gn" | xargs ../../../prebuilts/build-tools/linux-x86/bin/gn format
|
||||
|
||||
## 工具汇总
|
||||
```bash
|
||||
# 格式化BUILD.gn文件
|
||||
../../../prebuilts/build-tools/linux-x86/bin/gn format *.gn
|
||||
../../../prebuilts/build-tools/linux-x86/bin/gn format **/*.gn
|
||||
../../../prebuilts/build-tools/linux-x86/bin/gn format **/**/*.gn
|
||||
../../../prebuilts/build-tools/linux-x86/bin/gn format **/**/**/*.gn
|
||||
# 格式化BUILD.gn文件, 在asset目录下执行
|
||||
find -name "*.gn" -or -name "*.gni" | xargs ../../../prebuilts/build-tools/linux-x86/bin/gn format
|
||||
```
|
||||
|
||||
### WIKI汇总
|
||||
|
@ -168,8 +168,32 @@ impl_enum_trait! {
|
||||
/// The error code indicates that the ipc communication is abnormal.
|
||||
IpcError = 24000008,
|
||||
|
||||
/// Generic error
|
||||
SqliteERROR = 24000009,
|
||||
/// The error code indicates that the Database operation is failed.
|
||||
SqliteError = 24000009,
|
||||
|
||||
/// The error code indicates that the operation of calling Bundle Manager service is failed.
|
||||
BmsError = 24000010,
|
||||
|
||||
/// The error code indicates that the cryptography operation is failed.
|
||||
CryptoError = 24000011,
|
||||
|
||||
/// The error code indicates that the operation of calling OS Account service is failed.
|
||||
AccountError = 24000012,
|
||||
|
||||
/// The error code indicates that the operation of calling Common Event service is failed.
|
||||
CommonEventError = 24000013,
|
||||
|
||||
/// The error code indicates that the operation of calling Access Token service is failed.
|
||||
AccessTokenError = 24000014,
|
||||
|
||||
/// The error code indicates that the operation of file is failed.
|
||||
FileOperationError = 24000015,
|
||||
|
||||
/// The error code indicates that the operation of file is failed.
|
||||
SystemTimeError = 24000016,
|
||||
|
||||
/// The error code indicates that the amount of map element or other limited quotas exceed the limit.
|
||||
ExceedLimit = 24000017,
|
||||
}
|
||||
}
|
||||
|
||||
|
2
frameworks/js/@ohos.security.asset.d.ts
vendored
2
frameworks/js/@ohos.security.asset.d.ts
vendored
@ -625,7 +625,7 @@ declare namespace asset {
|
||||
* @syscap SystemCapability.Security.Asset
|
||||
* @since 11
|
||||
*/
|
||||
DB_ERROR = 24000009,
|
||||
SQLITE_ERROR = 24000009,
|
||||
/**
|
||||
* The error code indicates that the operation of calling Bundle Manager service is failed.
|
||||
*
|
||||
|
@ -192,10 +192,12 @@ napi_value NapiGetVersion(napi_env env, napi_callback_info info)
|
||||
{
|
||||
Asset_Version version = OH_Asset_GetVersion();
|
||||
|
||||
napi_value versionObj;
|
||||
napi_value versionObj = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &versionObj));
|
||||
|
||||
napi_value major, minor, patch;
|
||||
napi_value major = nullptr;
|
||||
napi_value minor = nullptr;
|
||||
napi_value patch = nullptr;
|
||||
NAPI_CALL(env, napi_create_uint32(env, version.major, &major));
|
||||
NAPI_CALL(env, napi_create_uint32(env, version.minor, &minor));
|
||||
NAPI_CALL(env, napi_create_uint32(env, version.patch, &patch));
|
||||
|
@ -93,8 +93,9 @@ void FreeAssetAttrs(AsyncContext *context)
|
||||
AssetFree(context->updateAttrs);
|
||||
context->updateAttrs = nullptr;
|
||||
}
|
||||
|
||||
OH_Asset_FreeBlob(&context->challenge);
|
||||
// todo: delete reasultSet
|
||||
OH_Asset_FreeResultSet(&context->resultSet);
|
||||
}
|
||||
|
||||
AsyncContext *CreateAsyncContext()
|
||||
@ -229,7 +230,7 @@ napi_status ParseMapParam(napi_env env, napi_value arg, Asset_Attr **attrs, uint
|
||||
*attrs = static_cast<Asset_Attr *>(AssetMalloc(attrVec.size() * sizeof(Asset_Attr)));
|
||||
if (*attrs == nullptr) {
|
||||
FreeAttrVec(attrVec);
|
||||
NAPI_THROW_RETURN_ERR(env, true, ASSET_OUT_OF_MEMRORY, "Unable to allocate memory for Asset_Attr array.");
|
||||
NAPI_THROW_RETURN_ERR(env, true, ASSET_OUT_OF_MEMRORY, "Unable to allocate memory for Attribute array.");
|
||||
}
|
||||
(void)memcpy_s(*attrs, attrVec.size() * sizeof(Asset_Attr), &attrVec[0], attrVec.size() * sizeof(Asset_Attr));
|
||||
*attrCnt = attrVec.size();
|
||||
@ -250,40 +251,88 @@ napi_status ParseCallbackParam(napi_env env, napi_value arg, napi_ref *callback)
|
||||
|
||||
napi_value GetUndefinedValue(napi_env env)
|
||||
{
|
||||
napi_value value;
|
||||
napi_value value = nullptr;
|
||||
NAPI_CALL(env, napi_get_undefined(env, &value));
|
||||
return value;
|
||||
}
|
||||
|
||||
napi_value GetBusinessReturn(napi_env env, AsyncContext *context)
|
||||
napi_value GetUint8Array(napi_env env, const Asset_Blob *blob)
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
if (context->challenge.data != nullptr && context->challenge.size != 0) {
|
||||
// Create a temp array to store the challenge
|
||||
uint8_t *tmp = static_cast<uint8_t *>(AssetMalloc(context->challenge.size));
|
||||
NAPI_THROW(env, tmp == nullptr, ASSET_OUT_OF_MEMRORY, "Unable to allocate memory for challenge.");
|
||||
(void)memcpy_s(tmp, context->challenge.size, context->challenge.data, context->challenge.size);
|
||||
if (blob->data == nullptr || blob->size == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
// Create a temp array to store the blob value.
|
||||
uint8_t *tmp = static_cast<uint8_t *>(AssetMalloc(blob->size));
|
||||
NAPI_THROW(env, tmp == nullptr, ASSET_OUT_OF_MEMRORY, "Unable to allocate memory for out challenge.");
|
||||
(void)memcpy_s(tmp, blob->size, blob->data, blob->size);
|
||||
|
||||
// Create napi array to store the challenge
|
||||
napi_value challenge = nullptr;
|
||||
napi_status status = napi_create_external_arraybuffer(
|
||||
env, context->challenge.data, context->challenge.size,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
AssetFree(data);
|
||||
},
|
||||
nullptr, &challenge);
|
||||
if (status != napi_ok) {
|
||||
AssetFree(tmp);
|
||||
GET_AND_THROW_LAST_ERROR(env);
|
||||
// Create napi array to store the uint8_t array.
|
||||
napi_value array = nullptr;
|
||||
napi_status status = napi_create_external_arraybuffer(env, blob->data, blob->size,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
AssetFree(data);
|
||||
},
|
||||
nullptr, &array);
|
||||
if (status != napi_ok) {
|
||||
AssetFree(tmp);
|
||||
GET_AND_THROW_LAST_ERROR(env);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, blob->size, array, 0, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value GetMapObject(napi_env env, Asset_Result *result)
|
||||
{
|
||||
napi_value map = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &map));
|
||||
for (uint32_t i = 0; i < result->count; i++) {
|
||||
napi_value key = nullptr;
|
||||
napi_value value = nullptr;
|
||||
NAPI_CALL(env, napi_create_uint32(env, result->attrs[i].tag, &key));
|
||||
switch (result->attrs[i].tag & ASSET_TAG_TYPE_MASK) {
|
||||
case ASSET_TYPE_BOOL:
|
||||
NAPI_CALL(env, napi_get_boolean(env, result->attrs[i].value.boolean, &value));
|
||||
break;
|
||||
case ASSET_TYPE_UINT32:
|
||||
NAPI_CALL(env, napi_create_uint32(env, result->attrs[i].value.u32, &value));
|
||||
break;
|
||||
case ASSET_TYPE_BYTES:
|
||||
value = GetUint8Array(env, &result->attrs[i].value.blob);
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
NAPI_CALL(env, napi_set_property(env, map, key, value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
napi_value GetMapArray(napi_env env, Asset_ResultSet *resultSet)
|
||||
{
|
||||
napi_value array = nullptr;
|
||||
NAPI_CALL(env, napi_create_array(env, &array));
|
||||
for (uint32_t i = 0; i < resultSet->count; i++) {
|
||||
if (resultSet->results[i].attrs == nullptr || resultSet->results[i].count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, context->challenge.size, challenge, 0, &result));
|
||||
return result;
|
||||
napi_value map = GetMapObject(env, &resultSet->results[i]);
|
||||
NAPI_CALL(env, napi_set_element(env, array, i, map));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
napi_value GetBusinessValue(napi_env env, AsyncContext *context)
|
||||
{
|
||||
// Processing the return value of the PreQueryAsset function.
|
||||
if (context->challenge.data != nullptr && context->challenge.size != 0) {
|
||||
return GetUint8Array(env, &context->challenge);
|
||||
}
|
||||
|
||||
// Processing the return value of the QueryAsset function.
|
||||
if (context->resultSet.results != nullptr && context->resultSet.count != 0) {
|
||||
// todo: return the result set to JS
|
||||
return result;
|
||||
return GetMapArray(env, &context->resultSet);
|
||||
}
|
||||
|
||||
return GetUndefinedValue(env);
|
||||
@ -308,7 +357,7 @@ void ResolvePromise(napi_env env, AsyncContext *context)
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
if (context->result == ASSET_SUCCESS) {
|
||||
result = GetBusinessReturn(env, context);
|
||||
result = GetBusinessValue(env, context);
|
||||
NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, result));
|
||||
} else {
|
||||
result = GetBusinessError(env, context->result);
|
||||
@ -322,7 +371,7 @@ void ResolveCallback(napi_env env, AsyncContext *context)
|
||||
size_t index = 0;
|
||||
if (context->result == ASSET_SUCCESS) {
|
||||
cbArgs[index++] = GetUndefinedValue(env);
|
||||
cbArgs[index++] = GetBusinessReturn(env, context);
|
||||
cbArgs[index++] = GetBusinessValue(env, context);
|
||||
} else {
|
||||
cbArgs[index++] = GetBusinessError(env, context->result);
|
||||
}
|
||||
|
@ -55,21 +55,21 @@ impl Manager {
|
||||
self.remote.add(input)
|
||||
}
|
||||
|
||||
/// Query one or more Assets that match a search query.
|
||||
pub fn query(&self, input: &AssetMap) -> Result<Vec<AssetMap>> {
|
||||
logi!("[YZT][RUST SDK]enter asset query");
|
||||
self.remote.query(input)
|
||||
}
|
||||
|
||||
/// Update one Assets that match a search query.
|
||||
pub fn update(&self, query: &AssetMap, attributes_to_update: &AssetMap) -> Result<()> {
|
||||
logi!("[YZT][RUST SDK]enter asset query");
|
||||
self.remote.update(query, attributes_to_update)
|
||||
}
|
||||
|
||||
/// Remove an Asset.
|
||||
pub fn remove(&self, input: &AssetMap) -> Result<()> {
|
||||
logi!("[JIN][RUST SDK]enter asset remove");
|
||||
self.remote.remove(input)
|
||||
}
|
||||
|
||||
/// Update an Asset that matches a search query.
|
||||
pub fn update(&self, query: &AssetMap, attributes_to_update: &AssetMap) -> Result<()> {
|
||||
logi!("[YZT][RUST SDK]enter asset update");
|
||||
self.remote.update(query, attributes_to_update)
|
||||
}
|
||||
|
||||
/// Query one or more Assets that match a search query.
|
||||
pub fn query(&self, input: &AssetMap) -> Result<Vec<AssetMap>> {
|
||||
logi!("[YZT][RUST SDK]enter asset query");
|
||||
self.remote.query(input)
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ int32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob
|
||||
* returns an error code otherwise.
|
||||
* @since 11
|
||||
*/
|
||||
int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *result);
|
||||
int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet);
|
||||
|
||||
/**
|
||||
* @brief Post-processing (e.g. release cached resource) for querying multiple Assets that require user authentication.
|
||||
@ -156,4 +156,4 @@ void OH_Asset_FreeResultSet(Asset_ResultSet *resultSet);
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* ASSET_API_H */
|
||||
#endif // ASSET_API_H
|
||||
|
@ -221,7 +221,7 @@ typedef enum {
|
||||
/**
|
||||
* The error code indicates that the Database operation is failed.
|
||||
*/
|
||||
ASSET_DB_ERROR = 24000009,
|
||||
ASSET_SQLITE_ERROR = 24000009,
|
||||
/**
|
||||
* The error code indicates that the operation of calling Bundle Manager service is failed.
|
||||
*/
|
||||
@ -232,7 +232,6 @@ typedef enum {
|
||||
ASSET_CRYPTO_ERROR = 24000011,
|
||||
/**
|
||||
* The error code indicates that the operation of calling OS Account service is failed.
|
||||
*
|
||||
*/
|
||||
ASSET_ACCOUNT_ERROR = 24000012,
|
||||
/**
|
||||
|
@ -1,5 +1,32 @@
|
||||
[
|
||||
{
|
||||
"name": "OH_Asset_Add"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_Remove"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_Update"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_PreQuery"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_Query"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_PostQuery"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_GetVersion"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_ParseAttr"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_FreeBlob"
|
||||
},
|
||||
{
|
||||
"name": "OH_Asset_FreeResultSet"
|
||||
}
|
||||
]
|
@ -20,38 +20,43 @@
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
extern int32_t AddAssetC2Rust(const Asset_Attr *attributes, uint32_t attrCnt);
|
||||
extern int32_t RemoveAssetC2Rust(const Asset_Attr *query, uint32_t queryCnt);
|
||||
extern int32_t add_asset(const Asset_Attr *attributes, uint32_t attr_cnt);
|
||||
extern int32_t remove_asset(const Asset_Attr *query, uint32_t query_cnt);
|
||||
extern int32_t update_asset(const Asset_Attr *query, uint32_t query_cnt,
|
||||
const Asset_Attr *attributes_to_update, uint32_t update_cnt);
|
||||
extern int32_t pre_query_asset(const Asset_Attr *query, uint32_t query_cnt, Asset_Blob *challenge);
|
||||
extern int32_t query_asset(const Asset_Attr *query, uint32_t query_cnt, Asset_ResultSet *result_set);
|
||||
extern int32_t post_query_asset(const Asset_Attr *handle, uint32_t handle_cnt);
|
||||
|
||||
int32_t OH_Asset_Add(const Asset_Attr *attributes, uint32_t attrCnt)
|
||||
{
|
||||
return AddAssetC2Rust(attributes, attrCnt);
|
||||
return add_asset(attributes, attrCnt);
|
||||
}
|
||||
|
||||
int32_t OH_Asset_Remove(const Asset_Attr *query, uint32_t queryCnt)
|
||||
{
|
||||
return RemoveAssetC2Rust(query, queryCnt);
|
||||
return remove_asset(query, queryCnt);
|
||||
}
|
||||
|
||||
int32_t OH_Asset_Update(const Asset_Attr *query, uint32_t queryCnt,
|
||||
const Asset_Attr *attributesToUpdate, uint32_t updateCnt)
|
||||
{
|
||||
return ASSET_SUCCESS;
|
||||
return update_asset(query, queryCnt, attributesToUpdate, updateCnt);
|
||||
}
|
||||
|
||||
int32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob *challenge)
|
||||
{
|
||||
return ASSET_SUCCESS;
|
||||
return pre_query_asset(query, queryCnt, challenge);
|
||||
}
|
||||
|
||||
int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *result)
|
||||
int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet)
|
||||
{
|
||||
return ASSET_SUCCESS;
|
||||
return query_asset(query, queryCnt, resultSet);
|
||||
}
|
||||
|
||||
int32_t OH_Asset_PostQuery(const Asset_Attr *handle, uint32_t handleCnt)
|
||||
{
|
||||
return ASSET_SUCCESS;
|
||||
return post_query_asset(handle, handleCnt);
|
||||
}
|
||||
|
||||
Asset_Version OH_Asset_GetVersion(void)
|
||||
|
@ -23,15 +23,12 @@ use asset_common::{
|
||||
};
|
||||
use asset_sdk::Manager;
|
||||
|
||||
/// add asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn AddAssetC2Rust(attributes: *const AssetAttr, attr_cnt: u32) -> i32 {
|
||||
loge!("[YZT] enter AddAssetC2Rust!");
|
||||
const RESULT_CODE_SUCCESS: i32 = 0;
|
||||
|
||||
unsafe fn into_map(attributes: *const Asset_Attr, attr_cnt: u32) -> Option<AssetMap> {
|
||||
if attributes.is_null() || attr_cnt == 0 {
|
||||
loge!("[YZT] null pointer");
|
||||
return ErrCode::InvalidArgument as i32;
|
||||
loge!("[FATAL] attributes is null or attr_cnt is 0");
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut map = AssetMap::with_capacity(attr_cnt as usize);
|
||||
@ -39,7 +36,7 @@ pub unsafe extern "C" fn AddAssetC2Rust(attributes: *const AssetAttr, attr_cnt:
|
||||
let attr = attributes.offset(i as isize);
|
||||
let attr_tag = match Tag::try_from((*attr).tag) {
|
||||
Ok(tag) => tag,
|
||||
Err(err_code) => return err_code as i32,
|
||||
Err(_) => return None,
|
||||
};
|
||||
match attr_tag.data_type() {
|
||||
DataType::Bool => {
|
||||
@ -55,16 +52,28 @@ pub unsafe extern "C" fn AddAssetC2Rust(attributes: *const AssetAttr, attr_cnt:
|
||||
},
|
||||
}
|
||||
}
|
||||
loge!("[YZT] end AddAssetC2Rust!");
|
||||
match Manager::build() {
|
||||
Ok(manager) => {
|
||||
if let Err(e) = manager.add(&map) {
|
||||
e as i32
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
Err(e) => e as i32
|
||||
Some(map)
|
||||
}
|
||||
|
||||
/// add asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn add_asset(attributes: *const Asset_Attr, attr_cnt: u32) -> i32 {
|
||||
let map = match into_map(attributes, attr_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
if let Err(e) = manager.add(&map) {
|
||||
e as i32
|
||||
} else {
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,66 +81,152 @@ pub unsafe extern "C" fn AddAssetC2Rust(attributes: *const AssetAttr, attr_cnt:
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn RemoveAssetC2Rust(query: *const AssetAttr, query_cnt: u32) -> i32 {
|
||||
loge!("[JIN] enter RemoveAssetC2Rust!");
|
||||
if query.is_null() || query_cnt == 0 {
|
||||
loge!("[JIN] null pointer");
|
||||
return ErrCode::InvalidArgument as i32;
|
||||
}
|
||||
pub unsafe extern "C" fn remove_asset(query: *const Asset_Attr, query_cnt: u32) -> i32 {
|
||||
let map = match into_map(query, query_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let mut map = AssetMap::with_capacity(query_cnt as usize);
|
||||
for i in 0..query_cnt {
|
||||
let attr = query.offset(i as isize);
|
||||
let attr_tag = match Tag::try_from((*attr).tag) {
|
||||
Ok(tag) => tag,
|
||||
Err(err_code) => return err_code as i32,
|
||||
};
|
||||
match attr_tag.data_type() {
|
||||
DataType::Bool => {
|
||||
map.insert(attr_tag, Value::Bool((*attr).value.boolean));
|
||||
}
|
||||
DataType::Uint32 => {
|
||||
map.insert(attr_tag, Value::Number((*attr).value.uint32));
|
||||
},
|
||||
DataType::Bytes => {
|
||||
let blob_slice = slice::from_raw_parts((*attr).value.blob.data, (*attr).value.blob.size as usize);
|
||||
let blob_vec = blob_slice.to_vec();
|
||||
map.insert(attr_tag, Value::Bytes(blob_vec));
|
||||
},
|
||||
let manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
if let Err(e) = manager.remove(&map) {
|
||||
e as i32
|
||||
} else {
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
/// update asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn update_asset(query: *const Asset_Attr, query_cnt: u32,
|
||||
attributes_to_update: *const Asset_Attr, update_cnt: u32) -> i32 {
|
||||
let query_map = match into_map(query, query_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let update_map = match into_map(attributes_to_update, update_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
if let Err(e) = manager.update(&query_map, &update_map) {
|
||||
e as i32
|
||||
} else {
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
/// preQuery asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn pre_query_asset(query: *const Asset_Attr, query_cnt: u32, _challenge: *mut Asset_Blob) -> i32 {
|
||||
let _map = match into_map(query, query_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let _manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
loge!("[YZT] enter pre query");
|
||||
// if let Err(e) = manager.pre_query(&map) {
|
||||
// e as i32
|
||||
// }
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
|
||||
/// query asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn query_asset(query: *const Asset_Attr, query_cnt: u32,
|
||||
_result_set: *mut Asset_ResultSet) -> i32 {
|
||||
let map = match into_map(query, query_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
loge!("[YZT] enter query");
|
||||
match manager.query(&map) {
|
||||
Err(e) => e as i32,
|
||||
Ok(_res) => {
|
||||
loge!("[YZT] end query");
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
}
|
||||
loge!("[JIN] end RemoveAssetC2Rust!");
|
||||
match Manager::build() {
|
||||
Ok(manager) => {
|
||||
if let Err(e) = manager.remove(&map) {
|
||||
e as i32
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
Err(e) => e as i32
|
||||
}
|
||||
}
|
||||
|
||||
/// asset param from c
|
||||
/// postQuery asset c2rust
|
||||
/// # Safety
|
||||
/// dereference pointer
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn post_query_asset(handle: *const Asset_Attr, handle_cnt: u32) -> i32 {
|
||||
let _map = match into_map(handle, handle_cnt) {
|
||||
Some(map) => map,
|
||||
None => return ErrCode::InvalidArgument as i32,
|
||||
};
|
||||
|
||||
let _manager = match Manager::build() {
|
||||
Ok(manager) => manager,
|
||||
Err(e) => return e as i32,
|
||||
};
|
||||
|
||||
loge!("[YZT] enter post query");
|
||||
// if let Err(e) = manager.post_query(&map) {
|
||||
// e as i32
|
||||
// }
|
||||
RESULT_CODE_SUCCESS
|
||||
}
|
||||
|
||||
/// Attribute of Asset
|
||||
#[repr(C)]
|
||||
pub struct AssetAttr {
|
||||
pub struct Asset_Attr {
|
||||
tag: u32,
|
||||
value: AssetValue,
|
||||
value: Asset_Value,
|
||||
}
|
||||
|
||||
/// Blob of Asset
|
||||
#[repr(C)]
|
||||
struct AssetBlob {
|
||||
pub struct Asset_Blob {
|
||||
size: u32,
|
||||
data: *mut u8,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
union AssetValue {
|
||||
int32: i32,
|
||||
uint32: u32,
|
||||
int64: i64,
|
||||
uint64: u64,
|
||||
union Asset_Value {
|
||||
boolean: bool,
|
||||
blob: std::mem::ManuallyDrop<AssetBlob>,
|
||||
}
|
||||
uint32: u32,
|
||||
blob: std::mem::ManuallyDrop<Asset_Blob>,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Asset_Result {
|
||||
attrs: *mut Asset_Attr,
|
||||
count: u32,
|
||||
}
|
||||
|
||||
/// Result Set of Asset
|
||||
#[repr(C)]
|
||||
pub struct Asset_ResultSet {
|
||||
results: *mut Asset_Result,
|
||||
count: u32,
|
||||
}
|
||||
|
@ -37,21 +37,21 @@ fn precise_query(alias: &str, calling_info: &CallingInfo, db_data: &Vec<Pair>) -
|
||||
Some(Value::Number(res)) => res,
|
||||
_ => {
|
||||
loge!("get auth type failed!");
|
||||
return Err(ErrCode::SqliteERROR);
|
||||
return Err(ErrCode::SqliteError);
|
||||
},
|
||||
};
|
||||
let access_type = match map.get(&Tag::Accessibility) {
|
||||
Some(Value::Number(res)) => res,
|
||||
_ => {
|
||||
loge!("get access type failed!");
|
||||
return Err(ErrCode::SqliteERROR);
|
||||
return Err(ErrCode::SqliteError);
|
||||
},
|
||||
};
|
||||
let secret = match map.get(&Tag::Secret) {
|
||||
Some(Value::Bytes(res)) => res,
|
||||
_ => {
|
||||
loge!("get secret failed!");
|
||||
return Err(ErrCode::SqliteERROR);
|
||||
return Err(ErrCode::SqliteError);
|
||||
},
|
||||
};
|
||||
map.insert_attr(Tag::Secret, decrypt(calling_info, auth_type, access_type, secret)?)?;
|
||||
@ -84,7 +84,7 @@ pub(crate) fn query(input: &AssetMap, calling_info: &CallingInfo) -> Result<Vec<
|
||||
}
|
||||
_ => {
|
||||
loge!("get alias and not not found failed!");
|
||||
Err(ErrCode::SqliteERROR)
|
||||
Err(ErrCode::SqliteError)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub(crate) fn remove(input: &AssetMap, calling_info: &CallingInfo) -> Result<()>
|
||||
},
|
||||
_ => {
|
||||
loge!("get alias and not not found failed!");
|
||||
Err(ErrCode::SqliteERROR)
|
||||
Err(ErrCode::SqliteError)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ fn tag_value_match(tag: &Tag, value: &Value) -> bool {
|
||||
if let Value::Bool(_) = value {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
DataType::Bytes => {
|
||||
if let Value::Bytes(_) = value {
|
||||
return true;
|
||||
|
@ -243,7 +243,7 @@ fn back_db_when_succ<T, F: Fn(&Table) -> Result<T, SqliteErrCode>>(
|
||||
let r_ret = copy_db_file(table.db, true);
|
||||
if r_ret.is_err() {
|
||||
println!("recovery master db {} fail", table.db.path);
|
||||
Err(ErrCode::SqliteERROR)
|
||||
Err(ErrCode::SqliteError)
|
||||
} else {
|
||||
println!("recovery master db {} succ", table.db.path);
|
||||
|
||||
@ -563,13 +563,13 @@ fn open_default_table<'a>(db: &'a mut Database) -> Result<Option<Table<'a>>, Err
|
||||
let r_ret = copy_db_file(db, true);
|
||||
if r_ret.is_err() {
|
||||
asset_common::loge!("recovery master db {} fail", db.path);
|
||||
Err(ErrCode::SqliteERROR)
|
||||
Err(ErrCode::SqliteError)
|
||||
} else {
|
||||
asset_common::logi!("recovery master db {} succ", db.path);
|
||||
let o_ret = db.re_open();
|
||||
if let Err(e) = o_ret {
|
||||
asset_common::loge!("reopen master db {} fail {}", db.path, e);
|
||||
return Err(ErrCode::SqliteERROR);
|
||||
return Err(ErrCode::SqliteError);
|
||||
}
|
||||
process_err_msg(
|
||||
db.open_table(G_ASSET_TABLE_NAME).map_err(from_sqlite_code_to_asset_code),
|
||||
|
@ -23,7 +23,7 @@ pub fn from_sqlite_code_to_asset_code(value: SqliteErrCode) -> ErrCode {
|
||||
if value != SQLITE_OK && value != SQLITE_DONE {
|
||||
asset_common::loge!("error ret {}", value);
|
||||
}
|
||||
ErrCode::SqliteERROR
|
||||
ErrCode::SqliteError
|
||||
}
|
||||
|
||||
/// Successful result
|
||||
|
Loading…
Reference in New Issue
Block a user