Mod aaa-12 修改用户认证-未认证权限(输出结果修改为json数组)

RCA:
SOL:
修改人:chenling
检视人:
This commit is contained in:
ChenLing 2019-08-28 15:46:33 +08:00
parent da07b7b223
commit d6ebaae1f8
2 changed files with 86 additions and 29 deletions

View File

@ -16,7 +16,7 @@
/*定义结构体数组 存在免认证规则 */
freeauth_configure_t freeauth_array[RULE_MAX_NUM] = {0};
#define UNAMESIZE (127 + 1)
#define UNAMESIZE (60 + 1)
#define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符
#ifdef FREEAUTH_ACK_COOKIES
@ -536,6 +536,8 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
int i;
int cnt;
cJSON *res;
cJSON *pJsonArry;
cJSON *pJsonsub;
authfree_result_t authfree_result;
freeauth_configure_t *freeauth_configure = NULL;
uint conf_type = FREEAUTH_CONFIG_GET;
@ -564,6 +566,9 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
freeauth_configure[j].dip, freeauth_configure[j].dport, freeauth_configure[j].dport, j);
}
pJsonArry= cJSON_CreateArray(); /*创建数组*/
/*查找要修改的免认证规则名字,不存在则退出程序 */
for(i = 0; i < RULE_MAX_NUM; i++) {
/*两个字符串相等 strcmp值为0*/
@ -603,34 +608,42 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
printf("cfgchannel main exit!\r\n");
#endif
/*创建json对象 */
res = cJSON_CreateObject();
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对象*/
if(!res) {
return RET_ERR;
/*在json对象上添加键值对*/
char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
if (result_message == NULL)
{
return RET_NOMEM;
}
/*将json对象转换成json字符串 返回处理结果*/
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
cJSON_AddStringToObject(res, "message", authfree_result.message);
ret_char = cJSON_PrintUnformatted(res);
strcpy(result_message, freeauth_configure[j].name);
strcat(result_message, authfree_result.message);
printf("%s\n", result_message);
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
cJSON_AddStringToObject(pJsonsub, "message", result_message);
ret_char = cJSON_Print(pJsonArry);
ret_int = strlen(ret_char);
if(output_len) {
if(output_len)
{
*output_len = ret_int;
}
/*超出2k的内存报错 */
if(ret_int >= 1024 * 2) {
if(ret_int >= 1024 * 2)
{
free(ret_char);
cJSON_Delete(res);
cJSON_Delete(pJsonArry);
return RET_NOMEM;
}
memcpy(output, ret_char, ret_int + 1);
free(ret_char);
cJSON_Delete(res);
}
}
}
@ -651,6 +664,8 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
int i;
int cnt;
cJSON *res;
cJSON *pJsonArry;
cJSON *pJsonsub;
authfree_result_t authfree_result;
freeauth_configure_t *freeauth_configure = NULL;
uint conf_type = FREEAUTH_CONFIG_GET;
@ -679,6 +694,7 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
printf("[%s %d]\n", freeauth_configure[j].name, j);
}
pJsonArry= cJSON_CreateArray(); /*创建数组*/
/*查找要修改的免认证规则名字,不存在则退出程序 */
for(i = 0; i < RULE_MAX_NUM; i++) {
@ -719,18 +735,24 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
printf("cfgchannel main exit!\r\n");
#endif
/*创建json对象 */
res = cJSON_CreateObject();
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject());
if(!res)
/*在json对象上添加键值对*/
char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
if (result_message == NULL)
{
return RET_ERR;
return RET_NOMEM;
}
/*将json对象转换成json字符串 返回处理结果*/
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
cJSON_AddStringToObject(res, "message", authfree_result.message);
ret_char = cJSON_PrintUnformatted(res);
strcpy(result_message, freeauth_configure[j].name);
strcat(result_message, authfree_result.message);
printf("%s\n", result_message);
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
cJSON_AddStringToObject(pJsonsub, "message", result_message);
ret_char = cJSON_Print(pJsonArry);
ret_int = strlen(ret_char);
if(output_len)
@ -749,7 +771,6 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
memcpy(output, ret_char, ret_int + 1);
free(ret_char);
cJSON_Delete(res);
}
}
}

View File

@ -23,10 +23,10 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
WEBM_HANDLE_LOGIN,
WEBM_HANDLE_HOMEPAGE,
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>չʾ<EFBFBD><EFBFBD>case<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷŵ<EFBFBD>һ<EFBFBD><EFBFBD> */
/* 以下是页面取数展示的case后续提升性能可能通过数据库查询所以先放到一起 */
WEBM_HANDLE_CONFIG_LIST_GROUP,
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>case */
/* 以下是配置操作相关的case */
WEBM_HANDLE_CONFIG_ADD_GROUP,
WEBM_HANDLE_CONFIG_UUID_GROUP,
WEBM_HANDLE_CONFIG_MOD_GROUP,
@ -40,7 +40,12 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
WEBM_HANDLE_CONFIG_IPV4,
WEBM_HANDLE_CONFIG_VLAN_SET,
WEBM_HANDLE_CONFIG_VLAN_GET,
WEBM_HANDLE_MAX
WEBM_HANDLE_MAX,
WEBM_HANDLE_CONFIG_MOD_AUTHPARA,
WEBM_HANDLE_CONFIG_ADD_AUTHRULE,
WEBM_HANDLE_CONFIG_MOD_AUTHRULE,
WEBM_HANDLE_CONFIG_DEL_AUTHRULE
} webm_handle_index;
typedef struct _webm_config_st
@ -185,6 +190,37 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg
CM_CONFIG_GET, \
VLAN_CONFIG, \
webm_config_send_proc \
}, \
{\
WEBM_HANDLE_CONFIG_MOD_AUTHPARA, \
"/FSG-CF/userauth-parameters-mod", \
CM_CONFIG_SET, \
FREEPARAMETERS_CONFIG , \
webm_config_send_proc \
}, \
\
{\
WEBM_HANDLE_CONFIG_ADD_AUTHRULE, \
"/FSG-GF/userauth-rule-add", \
CM_CONFIG_SET, \
AUTHFREE_CONFIG, \
webm_config_send_proc \
}, \
\
{\
WEBM_HANDLE_CONFIG_MOD_AUTHRULE, \
"/FSG-GF/userauth-rule-mod", \
CM_CONFIG_SET, \
AUTHFREE_CONFIG, \
webm_config_send_proc \
}, \
\
{\
WEBM_HANDLE_CONFIG_DEL_AUTHRULE, \
"/FSG-GF/userauth-rule-del", \
CM_CONFIG_SET, \
AUTHFREE_CONFIG, \
webm_config_send_proc \
} \
\
}