OCT 1. 更新代码格式

This commit is contained in:
huangxin 2022-12-02 11:51:28 +08:00
parent 2c149cdb91
commit f82cb95c05
1 changed files with 32 additions and 12 deletions

View File

@ -28,6 +28,7 @@ typedef struct {
#define CFG_BOOL_VALUE(p) (p->value.longValue == FALSE ? FALSE : TRUE) #define CFG_BOOL_VALUE(p) (p->value.longValue == FALSE ? FALSE : TRUE)
#define CFG_FLOAT_VALUE(p) (p->value.floatValue) #define CFG_FLOAT_VALUE(p) (p->value.floatValue)
#define CFG_STRING_VALUE(p) (p->value.strValue) #define CFG_STRING_VALUE(p) (p->value.strValue)
#define ENC_HEAD ("AES@")
typedef union { typedef union {
long long longValue; long long longValue;
@ -57,6 +58,7 @@ PCONFIG_ITEM g_pConfigItem = NULL;
#define DEF_CFG_ITEM(id, key, type, defVal, desc) \ #define DEF_CFG_ITEM(id, key, type, defVal, desc) \
{ .cfgId = (id), .cfgPath = (key), .valType = (type), .defValue = (defVal), .readme = (desc), .pStrId = (#id) } { .cfgId = (id), .cfgPath = (key), .valType = (type), .defValue = (defVal), .readme = (desc), .pStrId = (#id) }
// clang-format off
static CFG_ITEM g_cfgItem[] = { static CFG_ITEM g_cfgItem[] = {
DEF_CFG_ITEM(CFG_DIRECTORY, "system.config_file_path", VAL_STR, ".", "Configuration files location path"), DEF_CFG_ITEM(CFG_DIRECTORY, "system.config_file_path", VAL_STR, ".", "Configuration files location path"),
DEF_CFG_ITEM(CFG_CURL_CA_PATH, "system.ssl_ca_file_path", VAL_STR, "~/.ssh/ca.crt", "Libcurl access HTTPS CA File"), DEF_CFG_ITEM(CFG_CURL_CA_PATH, "system.ssl_ca_file_path", VAL_STR, "~/.ssh/ca.crt", "Libcurl access HTTPS CA File"),
@ -124,8 +126,7 @@ static int cfg_is_upgrade(PCONFIG_ITEM pItem) {
return FALSE; return FALSE;
} }
// clang-format on
#define ENC_HEAD ("AES@")
static const char *load_string_value(const char *pKeyName) { static const char *load_string_value(const char *pKeyName) {
const char *pCfgVal; const char *pCfgVal;
@ -148,7 +149,8 @@ static const char *load_string_value(const char *pKeyName) {
return NULL; return NULL;
} }
if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey) != ERR_SUCCESS) { if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey)
!= ERR_SUCCESS) {
free((void *)pKey); free((void *)pKey);
free(pBuf); free(pBuf);
return NULL; return NULL;
@ -226,8 +228,9 @@ static int cmp_dhcp_obj(const void *a, const void *b) {
POBJ_DHCP_RNG pV1 = (POBJ_DHCP_RNG)a; POBJ_DHCP_RNG pV1 = (POBJ_DHCP_RNG)a;
POBJ_DHCP_RNG pV2 = (POBJ_DHCP_RNG)b; POBJ_DHCP_RNG pV2 = (POBJ_DHCP_RNG)b;
if (strcmp(pV1->rangAddr, pV2->rangAddr) == 0 && strcmp(pV1->subnet, pV2->subnet) == 0 && strcmp(pV1->dnsSvr, pV2->dnsSvr) == 0 if (strcmp(pV1->rangAddr, pV2->rangAddr) == 0 && strcmp(pV1->subnet, pV2->subnet) == 0
&& strcmp(pV1->gateway, pV2->gateway) == 0 && pV1->lease == pV2->lease) { && strcmp(pV1->dnsSvr, pV2->dnsSvr) == 0 && strcmp(pV1->gateway, pV2->gateway) == 0
&& pV1->lease == pV2->lease) {
return 0; return 0;
} }
@ -324,8 +327,12 @@ static int setConfigItemValue(PCONFIG_ITEM pItem, const char *pValue) {
return ERR_SUCCESS; return ERR_SUCCESS;
} }
static int add_new_cfg_item(CONFIG_ITEM_ID id, const char *pKey, CONFIG_VALUE_TYPE valType, const char *pDefVal, const char *pStrId, static int add_new_cfg_item(CONFIG_ITEM_ID id,
const char *pDesc) { const char *pKey,
CONFIG_VALUE_TYPE valType,
const char *pDefVal,
const char *pStrId,
const char *pDesc) {
PCONFIG_ITEM pItem; PCONFIG_ITEM pItem;
int ret; int ret;
@ -379,7 +386,10 @@ static void refreshCfgFileCb() {
int cfgUpgrade = FALSE; int cfgUpgrade = FALSE;
if (!config_read_file(&g_cfgContent, g_cfgFilePath)) { if (!config_read_file(&g_cfgContent, g_cfgFilePath)) {
dzlog_error("%s:%d - %s\n", config_error_file(&g_cfgContent), config_error_line(&g_cfgContent), config_error_text(&g_cfgContent)); dzlog_error("%s:%d - %s\n",
config_error_file(&g_cfgContent),
config_error_line(&g_cfgContent),
config_error_text(&g_cfgContent));
return; return;
} }
@ -492,14 +502,24 @@ const char *config_item_dump_fmt(const char *titleMessage) {
sprintf(tmp2, "%s%s", cfg_is_upgrade(pItem) ? "*" : " ", pItem->pStrId); sprintf(tmp2, "%s%s", cfg_is_upgrade(pItem) ? "*" : " ", pItem->pStrId);
switch (pItem->valType) { switch (pItem->valType) {
case VAL_BOOL: case VAL_BOOL:
s = sdscatprintf( s = sdscatprintf(s,
s, "|%4d | %-25s | %-45s | %-64s |\n", pItem->cfgId, tmp2, pItem->pcfgKey, CFG_BOOL_VALUE(pItem) ? "True" : "False"); "|%4d | %-25s | %-45s | %-64s |\n",
pItem->cfgId,
tmp2,
pItem->pcfgKey,
CFG_BOOL_VALUE(pItem) ? "True" : "False");
break; break;
case VAL_INT: case VAL_INT:
s = sdscatprintf(s, "|%4d | %-25s | %-45s | %-64lld |\n", pItem->cfgId, tmp2, pItem->pcfgKey, CFG_INT_VALUE(pItem)); s = sdscatprintf(
s, "|%4d | %-25s | %-45s | %-64lld |\n", pItem->cfgId, tmp2, pItem->pcfgKey, CFG_INT_VALUE(pItem));
break; break;
case VAL_FLOAT: case VAL_FLOAT:
s = sdscatprintf(s, "|%4d | %-25s | %-45s | %-64Lf |\n", pItem->cfgId, tmp2, pItem->pcfgKey, CFG_FLOAT_VALUE(pItem)); s = sdscatprintf(s,
"|%4d | %-25s | %-45s | %-64Lf |\n",
pItem->cfgId,
tmp2,
pItem->pcfgKey,
CFG_FLOAT_VALUE(pItem));
break; break;
case VAL_STR: case VAL_STR:
tmp = sdsempty(); tmp = sdsempty();