From ee27856922dcc4a0299c2e70db3802d73969079a Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 15:33:53 +0800 Subject: [PATCH] =?UTF-8?q?MOD=20aaa-12=20=E9=85=8D=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9=E5=AD=90=20SOL=20=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9?= =?UTF-8?q?=E5=AD=90=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2j.h | 12 ++++++ Common/s2j/s2jdef.h | 40 ++++++++++++++++++- .../configm/config-server/include/configm.h | 2 +- .../configm/config-server/include/parsefile.h | 2 + 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Common/s2j/s2j.h b/Common/s2j/s2j.h index ff67266a6..8d2642e30 100644 --- a/Common/s2j/s2j.h +++ b/Common/s2j/s2j.h @@ -72,10 +72,22 @@ extern "C" { #define s2j_struct_get_basic_element(to_struct, from_json, type, element) \ S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element) +#define s2j_struct_get_string_element(to_struct, from_json, type, element, n) \ + S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, type, element, n) + /* Get array type element for structure object */ #define s2j_struct_get_array_element(to_struct, from_json, type, element) \ S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element) +/* Get array type element for structure object */ +#define s2j_struct_get_array_element_n(to_struct, from_json, type, element, NUM) \ + S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element) + +/* Get array type element for structure object */ +#define s2j_struct_get_array_string_n(to_struct, from_json, type, element, NUM, BUFFLEN) \ + S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, element, NUM, BUFFLEN) + + /* Get child structure type element for structure object */ #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \ S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element) diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index 9002b088e..cd27ac78e 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -52,8 +52,9 @@ typedef struct { #define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \ json_temp = cJSON_GetObjectItem(from_json, #_element); \ - if (json_temp && json_temp->valuestring && n > 1)\ - strncpy((to_struct)->_element, json_temp->valuestring, n-1); + if (json_temp && json_temp->valuestring && n > 1){\ + strncpy((to_struct)->_element, json_temp->valuestring, n - 1);\ + to_struct->_element[n - 1] = '\0';} #define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \ json_temp = cJSON_GetObjectItem(from_json, #_element); \ @@ -65,6 +66,9 @@ typedef struct { #define S2J_STRUCT_ARRAY_GET_string_ELEMENT(to_struct, from_json, _element, index) \ strcpy((to_struct)->_element[index], from_json->valuestring); +#define S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, from_json, _element, index, maxlen) \ + strncpy((to_struct)->_element + maxlen * index, from_json->valuestring, maxlen - 1); + #define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \ (to_struct)->_element[index] = from_json->valuedouble; @@ -145,6 +149,38 @@ typedef struct { } \ } +#define S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM) \ + { \ + cJSON *array, *array_element; \ + size_t index = 0, size = 0; \ + array = cJSON_GetObjectItem(from_json, #_element); \ + if (array) { \ + size = cJSON_GetArraySize(array); \ + while (index < size && index < NUM) { \ + array_element = cJSON_GetArrayItem(array, index); \ + if (array_element) S2J_STRUCT_ARRAY_GET_ELEMENT(to_struct, array_element, type, _element, index++); \ + } \ + } \ + } + +#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM, LEN) \ + { \ + cJSON *array, *array_element; \ + size_t index = 0, size = 0; \ + array = cJSON_GetObjectItem(from_json, #_element); \ + if (array) { \ + size = cJSON_GetArraySize(array); \ + NUM = size;\ + (to_struct)->_element = (char *)malloc(size * LEN);\ + memset((to_struct)->_element, 0, size * LEN);\ + while (index < size) { \ + array_element = cJSON_GetArrayItem(array, index); \ + if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, type, _element, index++, LEN); \ + } \ + } \ + } + + #define S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, _element) \ type *child_struct = &((to_struct)->_element); \ cJSON *child_json = cJSON_GetObjectItem(from_json, #_element); diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 8d1f02768..e30e9d5d0 100644 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -169,7 +169,7 @@ typedef struct _config_init config_init_t; /* 配置注册 */ struct _config_service { - uint32 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ + uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ boolean multi_inst; /* 是否是多实例 */ diff --git a/Platform/user/configm/config-server/include/parsefile.h b/Platform/user/configm/config-server/include/parsefile.h index 5bc6f51ce..92b5bdbe5 100644 --- a/Platform/user/configm/config-server/include/parsefile.h +++ b/Platform/user/configm/config-server/include/parsefile.h @@ -1,6 +1,8 @@ #ifndef PARSEFILE_H_ #define PARSEFILE_H_ +#include "rpc_common.h" + #define IFCONFIG_PATH "/etc/network/interfaces" #define IF_BUFF_LEN 128