Mod aaa-12 根据review修改代码,并将接口头文件放入顶层Common文件夹内
RCA: SOL: 修改人:zhouzian 检视人:zhouzian
This commit is contained in:
parent
122fd2d982
commit
1b3bc5f8a7
|
@ -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
|
|
@ -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;
|
|
@ -14,11 +14,13 @@
|
|||
#include <cjson/cJSON.h>
|
||||
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue