REM:
1. 避免冲突,重命名libs里面的ERR_OK
This commit is contained in:
huangxin 2022-06-01 11:35:42 +08:00
parent da396530d6
commit 33449cac5d
14 changed files with 72 additions and 64 deletions

View File

@ -116,10 +116,10 @@ static int on_cmd1(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
if ((ret = user_init(pCfgFile, pCfgDir, pKey, 0)) != ERR_OK) {
if ((ret = user_init(pCfgFile, pCfgDir, pKey, 0)) != ERR_SUCCESS) {
printf("System init error: %d\n", ret);
return ret;
}
@ -150,7 +150,7 @@ static int on_cmd2(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
memset(&msg, 0, sizeof(MQ_CMD_MSG));
@ -200,7 +200,7 @@ static int on_cmd3(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
if (type == 0) {
@ -216,7 +216,7 @@ static int on_cmd3(void *pTbl[], const char *pName, void *pInfo) {
printf("Base64 %s: {%s} --> [%s]\n", type == 0 ? "encode" : "decode", pValue, pRet);
free((void *)pRet);
return ERR_OK;
return ERR_SUCCESS;
}
static int on_cmd4(void *pTbl[], const char *pName, void *pInfo) {
@ -228,7 +228,7 @@ static int on_cmd4(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
if (strcmp(type, "sha256") == 0) {
@ -245,7 +245,7 @@ static int on_cmd4(void *pTbl[], const char *pName, void *pInfo) {
printf("%s %s hash value: [%s]\n", type, pFile, pHashValue);
free(pHashValue);
return ERR_OK;
return ERR_SUCCESS;
}
static int on_cmd5(void *pTbl[], const char *pName, void *pInfo) {
@ -262,7 +262,7 @@ static int on_cmd5(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
if (strcmp(alg, "3des_ecb") == 0) {
@ -297,7 +297,7 @@ static int on_cmd5(void *pTbl[], const char *pName, void *pInfo) {
}
if (encrypt > 0) {
if (symmetric_encrypto(algType, (unsigned char *)data, strlen(data), &buf, &outSize, key) != ERR_OK) {
if (symmetric_encrypto(algType, (unsigned char *)data, strlen(data), &buf, &outSize, key) != ERR_SUCCESS) {
printf("Unsupported aes algorithms: %s\n", alg);
return -ERR_EVP_ENCRYPTION;
} else {
@ -311,7 +311,7 @@ static int on_cmd5(void *pTbl[], const char *pName, void *pInfo) {
return -ERR_EVP_DECRYPTION;
}
if (symmetric_decrypto(algType, pBase64, outSize, &buf, &outSize, key) != ERR_OK) {
if (symmetric_decrypto(algType, pBase64, outSize, &buf, &outSize, key) != ERR_SUCCESS) {
printf("Unsupported aes algorithms: %s\n", alg);
free((void *)pBase64);
return -ERR_EVP_DECRYPTION;
@ -325,7 +325,7 @@ static int on_cmd5(void *pTbl[], const char *pName, void *pInfo) {
free(buf);
free((void *)strRet);
return ERR_OK;
return ERR_SUCCESS;
}
static int on_cmd6(void *pTbl[], const char *pName, void *pInfo) {
@ -338,11 +338,11 @@ static int on_cmd6(void *pTbl[], const char *pName, void *pInfo) {
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
if (symmetric_encrypto(DES3_CBC_PKCS7PADDING, (unsigned char *)pKey, strlen(pKey), &buf, &outSize, pKeygen)
!= ERR_OK) {
!= ERR_SUCCESS) {
free((void *)pKeygen);
return -ERR_EVP_ENCRYPTION;
} else {
@ -354,7 +354,7 @@ static int on_cmd6(void *pTbl[], const char *pName, void *pInfo) {
free(buf);
free((void *)pKeygen);
return ERR_OK;
return ERR_SUCCESS;
}
static int on_cmd_(void *pTbl[], const char *pName, void *pInfo) {
@ -385,7 +385,7 @@ static int on_cmd_(void *pTbl[], const char *pName, void *pInfo) {
#endif
}
return ERR_OK;
return ERR_SUCCESS;
}
int menu_run(int argc, char **argv) {
@ -516,7 +516,7 @@ int menu_run(int argc, char **argv) {
for (i = 0; i < g_nArgTbl; i++) {
PARG_TBL_INFO pArg = &argTblInfo[i];
if (*pArg->pErrCode == 0 && pArg->pCmd) {
if (pArg->pCmd(pArg->argTbl, pAppName, pArg) != ERR_OK) {
if (pArg->pCmd(pArg->argTbl, pAppName, pArg) != ERR_SUCCESS) {
pArg->pHelp(pArg->argTbl, pAppName, NULL);
}
@ -547,5 +547,5 @@ int menu_run(int argc, char **argv) {
arg_freetable(argTblInfo[i].argTbl, argTblInfo[i].nArgItem);
}
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -49,5 +49,5 @@ int mq_cmd_run(const char *pSvr, const char *pCmd) {
zmq_close(requester);
zmq_ctx_destroy(context);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -79,7 +79,7 @@ static const char *load_string_value(const char *pKeyName) {
return NULL;
}
if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey) != ERR_OK) {
if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey) != ERR_SUCCESS) {
free((void *)pKey);
free(pBuf);
return NULL;
@ -157,7 +157,7 @@ static int setConfigItemValue(PCONFIG_ITEM pItem, const char *pValue) {
return -ERR_UN_SUPPORT;
}
return ERR_OK;
return ERR_SUCCESS;
}
static int add_new_cfg_item(CONFIG_ITEM_ID id, const char *pKey, CONFIG_VALUE_TYPE valType, const char *pDefVal,
@ -188,14 +188,14 @@ static int add_new_cfg_item(CONFIG_ITEM_ID id, const char *pKey, CONFIG_VALUE_TY
ret = setConfigItemValue(pItem, pItem->defaultValue);
if (ret != ERR_OK) {
if (ret != ERR_SUCCESS) {
free(pItem);
return ret;
}
HASH_ADD_INT(g_pConfigItem, cfgId, pItem);
return ERR_OK;
return ERR_SUCCESS;
}
static PCFG_VALUE cfg_get_value(CONFIG_ITEM_ID id) {
@ -498,7 +498,7 @@ int init_config_system(const char *pCfgFile, const char *pKey) {
// clang-format on
refreshCfgFileCb();
return ERR_OK;
return ERR_SUCCESS;
}
const char *get_config_keygen() {
@ -527,7 +527,7 @@ const char *get_config_key(const char *pKeygen) {
return NULL;
}
if (symmetric_decrypto(DES3_CBC_PKCS7PADDING, pBase64, outSize, &buf, &outSize, pKey) != ERR_OK) {
if (symmetric_decrypto(DES3_CBC_PKCS7PADDING, pBase64, outSize, &buf, &outSize, pKey) != ERR_SUCCESS) {
free((void *)pKey);
free((void *)pBase64);
if (buf) {

View File

@ -82,7 +82,7 @@ int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValu
bin2hex(*pHashValue, hashValue, rdSize);
return ERR_OK;
return ERR_SUCCESS;
}
/**
@ -136,5 +136,5 @@ int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int
EVP_MD_CTX_destroy(pCtx);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -16,7 +16,7 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
int ret = hash_digest_mem(HASH_TYPE_SHA1, (const unsigned char *)pKey, strlen(pKey), &pHashValue, &outSize);
if (ret != ERR_OK) {
if (ret != ERR_SUCCESS) {
if (pHashValue) {
free(pHashValue);
@ -30,7 +30,7 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
ret = hash_digest_mem(HASH_TYPE_SHA1, data, SHA_DIGEST_LENGTH, &pHashValue, &outSize);
if (ret != ERR_OK) {
if (ret != ERR_SUCCESS) {
if (pHashValue) {
free(pHashValue);
@ -43,7 +43,7 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
free(pHashValue);
return ERR_OK;
return ERR_SUCCESS;
}
#define EVP_ENV_INIT(algorithmType, pCipher, keyBuf, pKey) \
@ -66,7 +66,7 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
strncpy((char *)keyBuf, pKey, EVP_CIPHER_key_length(pCipher)); \
break; \
case AES128_ECB_PKCS7PADDING_SHA1PRNG: \
if (sha1prng_for_aes_key(pKey, keyBuf) != ERR_OK) { \
if (sha1prng_for_aes_key(pKey, keyBuf) != ERR_SUCCESS) { \
EVP_CIPHER_CTX_cleanup(pCtx); \
return -ERR_AES128_KEYGEN; \
} \
@ -177,7 +177,7 @@ int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned i
EVP_CIPHER_CTX_cleanup(pCtx);
EVP_CIPHER_CTX_free(pCtx);
return ERR_OK;
return ERR_SUCCESS;
}
int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
@ -247,5 +247,5 @@ int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned i
EVP_CIPHER_CTX_cleanup(pCtx);
EVP_CIPHER_CTX_free(pCtx);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -30,7 +30,7 @@ static int get_cpu_info_cmd(const char *pCmd) {
char *pOver;
long val;
if (shell_with_output(pCmd, &pRet) != ERR_OK || pRet == NULL || strlen(pRet) == 0) {
if (shell_with_output(pCmd, &pRet) != ERR_SUCCESS || pRet == NULL || strlen(pRet) == 0) {
if (pRet) {
free(pRet);
}
@ -81,7 +81,7 @@ int get_cpu_desc(PCPU_DESC pDesc) {
uv_free_cpu_info(pCpu, nCpu);
return ERR_OK;
return ERR_SUCCESS;
}
static int get_cpu_time_info(unsigned long *pTotal, unsigned long *pIdle) {
@ -109,7 +109,7 @@ static int get_cpu_time_info(unsigned long *pTotal, unsigned long *pIdle) {
uv_free_cpu_info(pCpu, nCpu);
return ERR_OK;
return ERR_SUCCESS;
}
static void cpuUsedRefresh() {
@ -118,14 +118,14 @@ static void cpuUsedRefresh() {
memset(&beginTime, 0, sizeof(CPU_TIME));
memset(&endTime, 0, sizeof(CPU_TIME));
if (get_cpu_time_info(&beginTime.cpuTotal, &beginTime.cpuIdle) != ERR_OK) {
if (get_cpu_time_info(&beginTime.cpuTotal, &beginTime.cpuIdle) != ERR_SUCCESS) {
return;
}
// 延时 1s 后再获取1次CPU信息
uv_sleep(1000);
if (get_cpu_time_info(&endTime.cpuTotal, &endTime.cpuIdle) != ERR_OK) {
if (get_cpu_time_info(&endTime.cpuTotal, &endTime.cpuIdle) != ERR_SUCCESS) {
return;
} else {
uint64_t idle = endTime.cpuIdle - beginTime.cpuIdle;
@ -166,7 +166,7 @@ int cpu_watch_init() {
uv_thread_create(&uvThread, cpuCalcCb, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
int get_cpu_info(PCPU_INFO pInfo) {
@ -188,5 +188,5 @@ int get_cpu_info(PCPU_INFO pInfo) {
memcpy(pInfo, &g_cpuInfo, sizeof(CPU_INFO));
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -34,7 +34,7 @@ static PDISK_PART_INFO g_diskPartInfo = NULL;
static int disk_info_refresh() {
int i = 0;
int errCode = ERR_OK;
int errCode = ERR_SUCCESS;
FILE *fp;
char buf[MAX_PATH];
@ -119,7 +119,7 @@ int get_disk_info(PDISK_INFO pInfo) {
}
uv_rwlock_rdunlock(&g_uvLock);
return ERR_OK;
return ERR_SUCCESS;
}
_Noreturn void diskRefreshCb(void *UNUSED(pArg)) {
@ -143,11 +143,11 @@ int disk_watch_info() {
uv_rwlock_init(&g_uvLock);
if (disk_info_refresh() != ERR_OK) {
if (disk_info_refresh() != ERR_SUCCESS) {
return -ERR_SYS_DISK_GET_INFO;
}
uv_thread_create(&uvThread, diskRefreshCb, NULL);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -55,7 +55,7 @@ int init_hardware() {
disk_watch_info();
sensor_watch_init();
return ERR_OK;
return ERR_SUCCESS;
}
/***************************************************************

View File

@ -39,7 +39,7 @@ static PIPMI_SENSOR_INFO g_pSensorInfo = NULL;
static int sensor_info_refresh() {
int i = 0;
int errCode = ERR_OK;
int errCode = ERR_SUCCESS;
FILE *fp;
char buf[1024];
@ -146,7 +146,7 @@ int get_sensor_info(PSENSOR_INFO pInfo) {
}
uv_rwlock_rdunlock(&g_uvLock);
return ERR_OK;
return ERR_SUCCESS;
}
_Noreturn void sensorRefreshCb(void *UNUSED(pArg)) {
@ -184,11 +184,11 @@ int sensor_watch_init() {
return -ERR_SYS_IPMI_UNSUP;
}
if (sensor_info_refresh() != ERR_OK) {
if (sensor_info_refresh() != ERR_SUCCESS) {
return -ERR_SYS_SENSOR_GET_INFO;
}
uv_thread_create(&uvThread, sensorRefreshCb, NULL);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -43,7 +43,7 @@ unsigned int get_sys_total_memory() {
}
static int memory_info_refresh() {
int errCode = ERR_OK;
int errCode = ERR_SUCCESS;
FILE *fp;
char buf[MAX_PATH];
@ -115,13 +115,13 @@ int memory_watch_init() {
uv_rwlock_init(&g_uvLock);
if (memory_info_refresh() != ERR_OK) {
if (memory_info_refresh() != ERR_SUCCESS) {
return -ERR_SYS_DISK_GET_INFO;
}
uv_thread_create(&uvThread, memRefreshCb, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
#define MEM_VALUE_SET(dst, src) \
@ -175,5 +175,5 @@ int get_memory_info(PMEMORY_INFO pInfo) {
pInfo->timestamp = time(NULL);
return ERR_OK;
return ERR_SUCCESS;
}

View File

@ -8,13 +8,16 @@
extern "C" {
#endif
#define USED_USER_ERRNO
typedef enum {
ERR_OK = 0,
ERR_INPUT_PARAMS = 1,
ERR_UN_SUPPORT = 3,
ERR_CALL_SHELL = 4,
ERR_ITEM_EXISTS = 5,
ERR_SYS_INIT = 6,
ERR_SUCCESS = 0,
ERR_INPUT_PARAMS = 1,
ERR_UN_SUPPORT = 3,
ERR_CALL_SHELL = 4,
ERR_ITEM_EXISTS = 5,
ERR_ITEM_UNEXISTS = 6,
ERR_SYS_INIT = 7,
// 文件读取相关错误
ERR_OPEN_FILE = 100,
@ -66,6 +69,11 @@ typedef enum {
// JSON 序列化相关错误
ERR_JSON_CREAT_OBJ = 2400,
// PPPoE 相关
ERR_CREATE_NETIF = 2500,
ERR_CREATE_PPPOE_NETIF = 2501,
ERR_CREATE_PPP_SESSION = 2502,
} USER_ERRNO;
#ifdef __cplusplus

View File

@ -50,7 +50,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
utstring_new(pPath);
utstring_printf(pPath, "%s/%s", bufCfgDir, "zlog.conf");
if ((ret = dzlog_init(utstring_body(pPath), "libagent")) != ERR_OK) {
if ((ret = dzlog_init(utstring_body(pPath), "libagent")) != ERR_SUCCESS) {
printf("Zlog configure file [%s] init result: %d+++++\n", utstring_body(pPath), ret);
zlog_profile();
return -ERR_ZLOG_INIT;
@ -64,7 +64,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
// 处置化配置文件库,系统集成配置文件支持功能
dzlog_info("System used configure file [%s]\n", bufCfgFile);
if ((ret = init_config_system(bufCfgFile, pKey)) != ERR_OK) {
if ((ret = init_config_system(bufCfgFile, pKey)) != ERR_SUCCESS) {
dzlog_error("Load system configuration error: %d\n", ret);
return -ERR_CONFIG_INIT;
}
@ -87,11 +87,11 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
init_hardware();
}
if ((ret = mq_init()) != ERR_OK) {
if ((ret = mq_init()) != ERR_SUCCESS) {
dzlog_error("Message queue init error: %d\n", ret);
}
return ERR_OK;
return ERR_SUCCESS;
}
void user_uninit() {

View File

@ -127,7 +127,7 @@ int shell_with_output(const char *pCmd, char **pResult) {
}
pclose(pFile);
return ERR_OK;
return ERR_SUCCESS;
}
int file_exists(const char *pPath) {

View File

@ -102,7 +102,7 @@ int mq_init(void) {
uv_thread_create(&uvThread, mqServerCb, NULL);
return ERR_OK;
return ERR_SUCCESS;
}
void mq_uninit(void) {