Add aaa-12 修改vlan get json封装
SOL 修改vlan get json封装 修改人:yinbin 检视人:yinbin Signed-off-by: yinbin <yinbin@cmhi.chinamobile.com>
This commit is contained in:
parent
0cc0d1aeab
commit
32b1fd5a46
|
@ -159,13 +159,13 @@ ret_code vlan_config_json_parse_test(char *path, interface_vlan_info *if_vlan_in
|
|||
ret_code vlan_config_json_parse_test1(operation_type op_type, interface_vlan_info *if_vlan_info, int *if_vlnum);
|
||||
ret_code vlan_config_chk_test(operation_type op_type);
|
||||
ret_code interface_vlan_check(interface_vlan_info *if_vlan_info);
|
||||
ret_code if_attr_chk(interface_vlan_info *if_vlan_info);
|
||||
ret_code if_attr_chk(interface_link_attr attr);
|
||||
ret_code op_type_chk(interface_vlan_info *if_vlan_info);
|
||||
ret_code op_type_add_chk(interface_vlan_info *if_vlan_info);
|
||||
ret_code op_type_del_chk(interface_vlan_info *if_vlan_info);
|
||||
ret_code vid_value_chk(int vid);
|
||||
ret_code vid_num_chk(char *if_name, operation_type op_type, int num);
|
||||
ret_code if_name_chk(interface_vlan_info *if_vlan_info);
|
||||
ret_code if_name_chk(char *if_name);
|
||||
ret_code vlan_config_set_chk(uint source, pointer input);
|
||||
ret_code vlan_operate_parse(pointer input, int *operate_type);
|
||||
ret_code vlan_config_get_chk(uint source, pointer input);
|
||||
|
|
|
@ -1503,6 +1503,13 @@ ret_code vlan_get_json_parse(int *interface, pointer input)
|
|||
ret = RET_INPUTERR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = if_name_chk(ifName->valuestring);
|
||||
if(ret != RET_OK){
|
||||
printf("[vlan-chk]vlan_get_json_parse: if-name-chk failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
//if_vlan_info[i].if_name= ifName->valuestring;//memcpy
|
||||
/* 如果找到了对应的ifnode,则对应下标置1 */
|
||||
ifnode = get_ifnode_from_global(ifName->valuestring);
|
||||
|
@ -1529,10 +1536,10 @@ ret_code vlan_config_format_json(int *interface, pointer output, int *output_len
|
|||
{
|
||||
cJSON *root = NULL, *arr = NULL, *js_list = NULL, *js_vid = NULL;
|
||||
char *out = NULL;
|
||||
int i, j, vid;
|
||||
int i, j, vid, ret = RET_OK;
|
||||
root = cJSON_CreateObject();
|
||||
if(!root){
|
||||
printf("[vlan]cJSON_CreateObject1 error.\n");
|
||||
printf("[vlan]vlan_config_format_json: cJSON create root failed.\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
cJSON_AddItemToObject(root, "if-vlan", arr = cJSON_CreateArray());
|
||||
|
@ -1543,20 +1550,30 @@ ret_code vlan_config_format_json(int *interface, pointer output, int *output_len
|
|||
}
|
||||
js_list = cJSON_CreateObject();
|
||||
if(!js_list){
|
||||
printf("[vlan]cJSON_CreateObject2 error.\n");
|
||||
printf("[vlan]vlan_config_format_json: cJSON create js_list failed.\n");
|
||||
cJSON_Delete(root);
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(js_list , "if-name", g_if_vlan_info[i].if_name);
|
||||
cJSON_AddNumberToObject(js_list , "if-attr", g_if_vlan_info[i].attr);
|
||||
if(g_if_vlan_info[i].attr == LINK_TYPE_TRUNK){
|
||||
cJSON_AddStringToObject(js_list , "if-attr", "trunk");
|
||||
}
|
||||
//else if(g_if_vlan_info[i].attr == LINK_TYPE_ACCESS){
|
||||
//cJSON_AddStringToObject(js_list , "if-attr", "access");
|
||||
//}
|
||||
else {
|
||||
printf("[vlan]vlan_config_format_json: if-atrtr error.\n");
|
||||
cJSON_Delete(root);
|
||||
return RET_ERR;
|
||||
|
||||
}
|
||||
cJSON_AddItemToObject(js_list, "vid", js_vid = cJSON_CreateArray());
|
||||
for(vid = VID_MIN; vid <= VID_MAX;vid++){
|
||||
if(vlan_bitmap_check(g_if_vlan_info[i].vlan_bitmap, vid)){
|
||||
cJSON_AddItemToArray(js_vid, cJSON_CreateNumber(vid));
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_AddItemToArray(arr, js_list);
|
||||
}
|
||||
out = cJSON_PrintUnformatted(root);
|
||||
|
@ -1568,8 +1585,10 @@ ret_code vlan_config_format_json(int *interface, pointer output, int *output_len
|
|||
*output_len = strlen(out) + 1;
|
||||
memcpy(output, out, *output_len);
|
||||
xfree(out);
|
||||
cJSON_Delete(root);
|
||||
return RET_OK;
|
||||
if(root){
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1861,9 +1880,9 @@ ret_code vid_num_chk(char *if_name, operation_type op_type, int num)
|
|||
* 输出:
|
||||
* 返回值:
|
||||
************************************************************/
|
||||
ret_code if_attr_chk(interface_vlan_info *if_vlan_info)
|
||||
ret_code if_attr_chk(interface_link_attr attr)
|
||||
{
|
||||
if(if_vlan_info->attr != LINK_TYPE_TRUNK){
|
||||
if(attr != LINK_TYPE_TRUNK){
|
||||
printf("[vlan]if_attr_chk: now we only support link-type trunk.\n");
|
||||
return RET_ATTR_INVALID;
|
||||
}
|
||||
|
@ -1939,6 +1958,10 @@ ret_code op_type_chk(interface_vlan_info *if_vlan_info)
|
|||
{
|
||||
int ifnode, vid, i;
|
||||
ret_code ret = RET_OK;
|
||||
if(!if_vlan_info){
|
||||
printf("[vlan]op_type_chk: input is null.\n");
|
||||
return RET_NULLP;
|
||||
}
|
||||
/* ADD操作校验 */
|
||||
if(if_vlan_info->op_type == OP_ADD){
|
||||
ret = op_type_add_chk(if_vlan_info);
|
||||
|
@ -1960,10 +1983,14 @@ ret_code op_type_chk(interface_vlan_info *if_vlan_info)
|
|||
* 输出:
|
||||
* 返回值:
|
||||
************************************************************/
|
||||
ret_code if_name_chk(interface_vlan_info *if_vlan_info)
|
||||
ret_code if_name_chk(char *if_name)
|
||||
{
|
||||
if(!(strcmp(if_vlan_info->if_name, ""))){
|
||||
printf("[vlan]if_name_chk: if-name is emptyp, return error.\n");
|
||||
if(!if_name){
|
||||
printf("[vlan]if_name_chk: if_name null.\n");
|
||||
return RET_NULLP;
|
||||
}
|
||||
if(!(strcmp(if_name, ""))){
|
||||
printf("[vlan]if_name_chk: if-name is empty string, return error.\n");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
return RET_OK;
|
||||
|
@ -1985,14 +2012,14 @@ ret_code interface_vlan_check(interface_vlan_info *if_vlan_info)
|
|||
printf("[vlan]interface_vlan_check: ifname=%s, op_type=%d, attr=%d\n",
|
||||
if_vlan_info->if_name, if_vlan_info->op_type, if_vlan_info->attr);
|
||||
/* if_name校验 */
|
||||
ret = if_name_chk(if_vlan_info);
|
||||
ret = if_name_chk(if_vlan_info->if_name);
|
||||
if(ret != RET_OK){
|
||||
printf("[vlan-chk]interface_vlan_check: if-name-chk failed.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* if_attr校验 */
|
||||
ret = if_attr_chk(if_vlan_info);
|
||||
ret = if_attr_chk(if_vlan_info->attr);
|
||||
if(ret != RET_OK){
|
||||
printf("[vlan-chk]interface_vlan_check: if-attr-chk failed.\n");
|
||||
goto out;
|
||||
|
|
Loading…
Reference in New Issue