提交 96a45aec 编写于 作者: C chengjinsong2

Merge branch '1010_API' of https://gitee.com/chneg-jinsong/startup_init_lite_1 into 1010_API

......@@ -40,7 +40,7 @@ INIT_LOCAL_API int GetSystemError(int err)
case PARAM_CODE_INVALID_PARAM:
case PARAM_CODE_INVALID_NAME:
case PARAM_CODE_READ_ONLY:
return SYSPARAM_INVALID_INPUT;
return EC_INVALID;
case PARAM_CODE_INVALID_VALUE:
return SYSPARAM_INVALID_VALUE;
case PARAM_CODE_NOT_FOUND:
......
......@@ -81,6 +81,15 @@ static napi_value BusinessErrorCreate(napi_env env, int status)
return businessError;
}
#define PARAM_NAPI_ASSERT(env, assertion, result, info) \
do { \
if (!(assertion)) { \
napi_value d_err = BusinessErrorCreate(env, result); \
napi_throw(env, d_err); \
return nullptr; \
} \
} while (0)
static int GetParamString(napi_env env, napi_value arg, char *buffer, size_t maxBuff, size_t *keySize)
{
(void)napi_get_value_string_utf8(env, arg, nullptr, maxBuff - 1, keySize);
......@@ -141,7 +150,8 @@ static napi_value Set(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
void *data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
NAPI_ASSERT(env, argc >= ARGC_NUMBER, "requires 2 parameter");
PARAM_NAPI_ASSERT(env, argc >= ARGC_NUMBER, SYSPARAM_INVALID_INPUT, "requires 2 parameter");
StorageAsyncContextPtr asyncContext = new StorageAsyncContext();
asyncContext->env = env;
for (size_t i = 0; i < argc; i++) {
......@@ -184,12 +194,13 @@ static napi_value SetSync(napi_env env, napi_callback_info info)
size_t argc = ARGC_NUMBER;
napi_value args[ARGC_NUMBER] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
NAPI_ASSERT(env, argc == ARGC_NUMBER, "Wrong number of arguments");
PARAM_NAPI_ASSERT(env, argc == ARGC_NUMBER, SYSPARAM_INVALID_INPUT, "Wrong number of arguments");
napi_valuetype valuetype0 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
napi_valuetype valuetype1 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
NAPI_ASSERT(env, valuetype0 == napi_string && valuetype1 == napi_string, "Wrong argument type. string expected.");
PARAM_NAPI_ASSERT(env, valuetype0 == napi_string && valuetype1 == napi_string,
SYSPARAM_INVALID_INPUT, "Wrong argument type. string expected.");
size_t keySize = 0;
std::vector<char> keyBuf(MAX_NAME_LENGTH, 0);
......@@ -224,14 +235,16 @@ static napi_value GetSync(napi_env env, napi_callback_info info)
size_t argc = ARGC_NUMBER;
napi_value args[ARGC_NUMBER] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
NAPI_ASSERT(env, argc == 1 || argc == ARGC_NUMBER, "Wrong number of arguments");
PARAM_NAPI_ASSERT(env, argc == 1 || argc == ARGC_NUMBER, SYSPARAM_INVALID_INPUT, "Wrong number of arguments");
napi_valuetype valuetype0 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
NAPI_ASSERT(env, valuetype0 == napi_string, "Wrong argument type. Numbers expected.");
PARAM_NAPI_ASSERT(env, valuetype0 == napi_string,
SYSPARAM_INVALID_INPUT, "Wrong argument type. Numbers expected.");
if (argc == ARGC_NUMBER) {
napi_valuetype valuetype1 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
NAPI_ASSERT(env, valuetype1 == napi_string, "Wrong argument type. string expected.");
PARAM_NAPI_ASSERT(env, valuetype1 == napi_string,
SYSPARAM_INVALID_INPUT, "Wrong argument type. string expected.");
}
size_t keySize = 0;
......@@ -320,7 +333,7 @@ static napi_value Get(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
void *data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
PARAM_NAPI_ASSERT(env, argc >= 1, SYSPARAM_INVALID_INPUT, "requires 1 parameter");
StorageAsyncContextPtr asyncContext = new StorageAsyncContext();
asyncContext->env = env;
for (size_t i = 0; i < argc; i++) {
......
......@@ -516,7 +516,7 @@ INIT_LOCAL_API int ReadParamName(ParamHandle handle, char *name, uint32_t length
PARAM_CHECK(name != NULL, return PARAM_CODE_INVALID_PARAM, "Invalid param");
ParamNode *entry = (ParamNode *)GetTrieNodeByHandle(handle);
if (entry == NULL) {
return -1;
return PARAM_CODE_NOT_FOUND;
}
PARAM_CHECK(length > entry->keyLength, return -1, "Invalid param size %u %u", entry->keyLength, length);
int ret = ParamMemcpy(name, length, entry->data, entry->keyLength);
......
......@@ -174,7 +174,7 @@ int SystemSetParameter(const char *name, const char *value)
g_clientFd = GetClientSocket(DEFAULT_PARAM_SET_TIMEOUT);
}
if (g_clientFd < 0) {
ret = PARAM_CODE_INVALID_PARAM;
ret = DAC_RESULT_FORBIDED;
break;
}
ret = StartRequest(g_clientFd, request, DEFAULT_PARAM_SET_TIMEOUT);
......@@ -182,7 +182,7 @@ int SystemSetParameter(const char *name, const char *value)
close(g_clientFd);
g_clientFd = INVALID_SOCKET;
retryCount++;
ret = 0;
ret = DAC_RESULT_FORBIDED;
} else {
break;
}
......
......@@ -365,7 +365,7 @@ int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId)
ParamNode *entry = (ParamNode *)GetTrieNodeByHandle(handle);
if (entry == NULL) {
return -1;
return PARAM_CODE_NOT_FOUND;
}
*commitId = ReadCommitId(entry);
return 0;
......
......@@ -135,7 +135,7 @@ HWTEST_F(SysparaUnitTest, parameterTest005, TestSize.Level0)
char value4[] = "rw.sys.version.version.version.version flash_offset = *(hi_u32 *)DT_SetGetU32(&g_Element[0], 0)a\
size = *(hi_u32 *)DT_SetGetU32(&g_Element[1], 0)a";
int ret = SetParameter(key4, value4);
EXPECT_EQ(ret, EC_INVALID);
EXPECT_EQ(ret, SYSPARAM_INVALID_VALUE);
}
HWTEST_F(SysparaUnitTest, parameterTest006, TestSize.Level0)
......@@ -171,7 +171,7 @@ HWTEST_F(SysparaUnitTest, parameterTest009, TestSize.Level0)
char value5[] = "rw.sys.version.version.version.version \
flash_offset = *(hi_u32 *)DT_SetGetU32(&g_Element[0], 0)";
int ret = SetParameter(key5, value5);
EXPECT_EQ(ret, EC_INVALID);
EXPECT_EQ(ret, SYSPARAM_INVALID_VALUE);
char valueGet[2] = {0};
char defValue3[] = "value of key > 32 ...";
ret = GetParameter(key5, defValue3, valueGet, 2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册