From 1b3bc5f8a7e00e3c6d68e892648c1464ca9c8257 Mon Sep 17 00:00:00 2001 From: zhouzian Date: Wed, 3 Jul 2019 20:11:46 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20aaa-12=20=E6=A0=B9=E6=8D=AEreview?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=B9=B6=E5=B0=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A4=B4=E6=96=87=E4=BB=B6=E6=94=BE=E5=85=A5?= =?UTF-8?q?=E9=A1=B6=E5=B1=82Common=E6=96=87=E4=BB=B6=E5=A4=B9=E5=86=85=20?= =?UTF-8?q?RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhouzian=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhouzia?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sg}/user/user_manager/user.h | 15 +++- .../sg}/user/user_manager/user_group.h | 10 +++ .../config-server/include/user_group_config.h | 10 ++- .../user_manager_config/user_group_config.c | 83 ++++++++++++------- Product/common/common_user.h | 2 + Product/user/user_manager/array_index.c | 4 +- Product/user/user_manager/user.c | 37 ++++----- Product/user/user_manager/user_group.c | 13 --- 8 files changed, 101 insertions(+), 73 deletions(-) rename {Product => Common/sg}/user/user_manager/user.h (73%) rename {Product => Common/sg}/user/user_manager/user_group.h (79%) diff --git a/Product/user/user_manager/user.h b/Common/sg/user/user_manager/user.h similarity index 73% rename from Product/user/user_manager/user.h rename to Common/sg/user/user_manager/user.h index 690e9ed92..56c6b5d51 100644 --- a/Product/user/user_manager/user.h +++ b/Common/sg/user/user_manager/user.h @@ -8,14 +8,21 @@ #define UPWDSIZE (63 + 1) #define UTIME 20 +#define ADD_FAIL_NOGROUP 1 +#define ADD_FAIL_NAMELEN 2 +#define ADD_FAIL_NAMESPE 3 +#define ADD_FAIL_NAMEDUP 4 +#define ADD_FAIL_USERFULL 5 +#define ADD_SUCCESS 0 + typedef struct user -{ +{ unsigned short ID; //用户id + unsigned short multi_valid; //多人登陆、永久有效 + int GID; //用户组ID char uname[UNAMESIZE]; //用户名 char udescription[UDESIZE]; //用户描述 - int GID; //用户组ID char passwd[UPWDSIZE]; //密码 - unsigned short multi_valid; //多人登陆、永久有效 time_t valid_begin_time; //有效期开始时间 time_t valid_end_time; //有效期结束时间 }USERACCOUNT; @@ -30,6 +37,6 @@ typedef struct result_user_add int init_user(); /*添加元素-新增用户*/ -USERADD* add_user(char* UNAME, char* UGNAME, USERADD* UADDRES); +void usermanager_add_user(char* UNAME, char* UGNAME, USERADD* UADDRES); #endif \ No newline at end of file diff --git a/Product/user/user_manager/user_group.h b/Common/sg/user/user_manager/user_group.h similarity index 79% rename from Product/user/user_manager/user_group.h rename to Common/sg/user/user_manager/user_group.h index 0c7d96ded..7efe519fc 100644 --- a/Product/user/user_manager/user_group.h +++ b/Common/sg/user/user_manager/user_group.h @@ -4,6 +4,16 @@ #define GNAMESIZE (127 + 1) #define GDESIZE (127 + 1) +#define ADD_SUCCESS 0 +#define ADD_FAIL_FULL 1 +#define ADD_FAIL_LENGTH 2 +#define ADD_FAIL_SPECHARS 3 +#define ADD_FAIL_DUP 4 + +#define DEL_SUCCESS 0 +#define DEL_FAIL_NOTEXIST 1 +#define DEL_FAIL_STRTEGY 2 + typedef struct usergroup { unsigned short ID; diff --git a/Platform/user/configm/config-server/include/user_group_config.h b/Platform/user/configm/config-server/include/user_group_config.h index 04206af47..e95e93975 100644 --- a/Platform/user/configm/config-server/include/user_group_config.h +++ b/Platform/user/configm/config-server/include/user_group_config.h @@ -14,11 +14,13 @@ #include -#include "../../../../common/configm/configmapi.h" -#include "../../../../common/rpc/rpc_common.h" -#include "../../../../../Product/user/user_manager/user_group.h" - +#include "configmapi.h" +#include "rpc_common.h" +#include "sg/user/user_manager/user_group.h" +typedef ret_code (*usergroup_config)(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); /* user group config */ diff --git a/Platform/user/configm/config-server/user_manager_config/user_group_config.c b/Platform/user/configm/config-server/user_manager_config/user_group_config.c index 846e2d514..ab6d1e2ba 100644 --- a/Platform/user/configm/config-server/user_manager_config/user_group_config.c +++ b/Platform/user/configm/config-server/user_manager_config/user_group_config.c @@ -3,6 +3,11 @@ #include "rpc.h" #include "parsefile.h" +/* 用户组处理函数数组 */ +static usergroup_config gs_usergroup_fun_table[] = { + usergroup_config_add_proc +}; + /* check暂时不做操作,所有的检查在业务接口中完成 */ ret_code usergroup_config_chk(uint source, uint config_type, pointer input, int input_len, @@ -54,26 +59,31 @@ ret_code usergroup_config_chk(uint source, uint config_type, return ret; } -/* 新增用户组-处理 */ +/* +* 新增用户组-处理 +* input格式:{"type": 0,"data": {"gname": "xxx","gdescription": "xxx"}} +*/ ret_code usergroup_config_add_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len) { ret_code ret = RET_OK; unsigned short result; - cJSON *root, *name, *description, *res; + cJSON *root, *data, *name, *description, *res; char *des = NULL; char *ret_char = NULL; root = cJSON_Parse(input); - if(!root) + data = cJSON_GetObjectItem(root, "data"); + if(!data) { ret = RET_INPUTERR; ASSERT_RET(ret); + cJSON_Delete(root); return ret; } - name = cJSON_GetObjectItem(root, "gname"); + name = cJSON_GetObjectItem(data, "gname"); if(!name) { ret = RET_INPUTERR; @@ -82,7 +92,7 @@ ret_code usergroup_config_add_proc(uint source, uint config_type, return ret; } - description = cJSON_GetObjectItem(root, "gdescription"); + description = cJSON_GetObjectItem(data, "gdescription"); if(description) { des = description->valuestring; @@ -107,39 +117,54 @@ ret_code usergroup_config_add_proc(uint source, uint config_type, return ret; } +/*用户组配置处理 +*input格式:{"type": 0,"data": {xxx}} +*output格式:{"result": 0} + */ ret_code usergroup_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len) { ret_code ret = RET_OK; - int code; + int fun_type; + int usergroup_fun_table_len; + cJSON *root, *type, *data; - switch(config_type) + //获取函数数组的长度 + usergroup_fun_table_len = sizeof(gs_usergroup_fun_table)/sizeof(gs_usergroup_fun_table[0]); + + //解析input,获取type + root = cJSON_Parse(input); + if(!root) { - case CM_CONFIG_ADD: - ret = usergroup_config_add_proc(source, config_type, - input, input_len, - output, output_len); - break; - case CM_CONFIG_DEL: - ret = usergroup_config_del_proc(source, config_type, - input, input_len, - output, output_len); - break; - case CM_CONFIG_GET: - ret = usergroup_config_get_proc(source, config_type, - input, input_len, - output, output_len); - break; - case CM_CONFIG_GET_ALL: - ret = usergroup_config_getall_proc(source, config_type, - input, input_len, - output, output_len); - break; - default: - ret = RET_NOTSUPPORT; + ret = RET_INPUTERR; + ASSERT_RET(ret); + return ret; } + type = cJSON_GetObjectItem(root, "type"); + if(!type) + { + ret = RET_INPUTERR; + ASSERT_RET(ret); + cJSON_Delete(root); + return ret; + } + fun_type = type->valueint; + + //type在数组长度的范围内,执行数组内的函数,否则 ret = RET_NOTSUPPORT; + if(fun_type < 0 || fun_type >= usergroup_fun_table_len) + { + ret = RET_NOTSUPPORT; + ASSERT_RET(ret); + return ret; + } + + ret = gs_usergroup_fun_table[fun_type](source, config_type, + input, input_len, + output, *output_len); + + return ret; } diff --git a/Product/common/common_user.h b/Product/common/common_user.h index 24083de23..f7c590d2e 100644 --- a/Product/common/common_user.h +++ b/Product/common/common_user.h @@ -5,6 +5,8 @@ #define GETID(ID, NAME1, NAME2) ((((ID) != 0) && (strcmp((NAME1), (NAME2)) == 0)) ? (ID) : 0) //根据name查询ID #define CHECKOUTARG(element) ((NULL == (element) || "" == (element) || SPECHAR(element)) ? true : false) //校验参数 #define INVALID_INDEX (0) +#define INIT_FAIL -1 +#define INIT_SUCCESS 0 #define TIME_T2STRING(time_int, time_char) (strftime((time_char), 20, "%Y-%m-%d %H:%M:%S", (localtime(&time_int)))) #define STRING2TIME_T(time_char,time_int) \ diff --git a/Product/user/user_manager/array_index.c b/Product/user/user_manager/array_index.c index 38ef64b02..751d17b97 100644 --- a/Product/user/user_manager/array_index.c +++ b/Product/user/user_manager/array_index.c @@ -36,7 +36,7 @@ int init_array(ARRAY* head, int index_size) head->array = malloc(sizeof(head->array) * index_size); if (NULL == head->array) { - return 1; + return INIT_FAIL; } //head->cur = 1; @@ -57,7 +57,7 @@ int init_array(ARRAY* head, int index_size) /*初始化最后一个值*/ head->array[i] = HI_ELEMENT_SET(head->array[i], i - 1); head->array[i] = LOW_ELEMENT_SET(head->array[i], 0); - return 0; + return INIT_SUCCESS; } /* 顺序分配index */ diff --git a/Product/user/user_manager/user.c b/Product/user/user_manager/user.c index 8f8fef1b3..213471af5 100644 --- a/Product/user/user_manager/user.c +++ b/Product/user/user_manager/user.c @@ -21,8 +21,6 @@ USERACCOUNT g_user_table[USER_INDEX_MAX]; /*初始化参数*/ int init_user() { - const int INIT_FAIL = 1; - const int INIT_SUCCESS = 0; /* 初始化用户的index */ int init_result = init_array(&g_user_index_head, USER_INDEX_MAX); if (INIT_FAIL == init_result) @@ -35,19 +33,11 @@ int init_user() } /*添加元素-新增用户*/ -USERADD* add_user(char* uname, char* gname, USERADD* uaddres) +void usermanager_add_user(char* uname, char* gname, USERADD* uaddres) { - const int ADD_FAIL_NOGROUP = 1; - const int ADD_FAIL_NAMELEN = 2; - const int ADD_FAIL_NAMESPE = 3; - const int ADD_FAIL_NAMEDUP = 4; - const int ADD_FAIL_USERFULL = 5; - const int ADD_SUCCESS = 0; - const char DEFAULT_PWD[8] = "123456"; - if (NULL == uaddres) { - return NULL; + return; } uaddres->userID = INVALID_INDEX; @@ -55,22 +45,27 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres) if (NULL == uname || (UNAMESIZE) < strlen(uname) || 0 >= strlen(uname)) { uaddres->result = ADD_FAIL_NAMELEN; - return uaddres; + return; } /* 校验用户名中不含特殊字符 */ if (SPECHAR(uname)) { uaddres->result = ADD_FAIL_NAMESPE; - return uaddres; + return; } /* 根据用户组名查询用户组ID */ - unsigned short GID_temp = get_groupid_by_name(gname); - if (CHECKOUTARG(gname) || INVALID_INDEX == GID_temp) + if(NULL == gname) { uaddres->result = ADD_FAIL_NOGROUP; - return uaddres; + return; + } + unsigned short GID_temp = get_groupid_by_name(gname); + if(INVALID_INDEX == GID_temp) + { + uaddres->result = ADD_FAIL_NOGROUP; + return; } /* 校验重名 */ @@ -79,7 +74,7 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres) if (0 == strcmp(uname, g_user_table[i].uname)) { uaddres->result = ADD_FAIL_NAMEDUP; - return uaddres; + return; } } @@ -88,14 +83,14 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres) if (INVALID_INDEX == ID) { uaddres->result = ADD_FAIL_USERFULL; - return uaddres; + return; } /* 存内存 */ g_user_table[ID].ID = ID; g_user_table[ID].GID = GID_temp; strcpy(g_user_table[ID].uname, uname); - strcpy(g_user_table[ID].passwd, DEFAULT_PWD); + strcpy(g_user_table[ID].passwd, "123456"); /* 连接数据库,存user表 */ /* INSERT INTO `user` SET id = , group_id = , user_name = "", password = "", multi_player = , valid_always = */ @@ -103,5 +98,5 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres) uaddres->result = ADD_SUCCESS; uaddres->userID = ID; - return uaddres; + return; } \ No newline at end of file diff --git a/Product/user/user_manager/user_group.c b/Product/user/user_manager/user_group.c index 895333645..b2bb9ddea 100644 --- a/Product/user/user_manager/user_group.c +++ b/Product/user/user_manager/user_group.c @@ -11,9 +11,6 @@ USERGROUP g_group_table[GROUP_INDEX_MAX]; /* 初始化参数 */ int init_group() { - const int INIT_FAIL = 1; - const int INIT_SUCCESS = 0; - /* 初始化用户组的index */ int init_result = init_array(&g_group_index_head, GROUP_INDEX_MAX); if (INIT_FAIL == init_result) @@ -27,12 +24,6 @@ int init_group() /* 添加元素 */ unsigned short add_group(char* name, char* description) { - const int ADD_SUCCESS = 0; - const int ADD_FAIL_FULL = 1; - const int ADD_FAIL_LENGTH = 2; - const int ADD_FAIL_SPECHARS = 3; - const int ADD_FAIL_DUP = 4; - /* 校验用户组名和描述的长度 */ if (NULL == description) { @@ -176,10 +167,6 @@ unsigned short get_groupid_by_name(char* gname) /*删除元素*/ unsigned short del_group_by_name(char* gname) { - const int DEL_SUCCESS = 0; - const int DEL_FAIL_NOTEXIST = 1; - const int DEL_FAIL_STRTEGY = 2; - if (CHECKOUTARG(gname)) { return DEL_FAIL_NOTEXIST;