Mod aaa-12 修改使用数据库接口时的int类型,添加删除用户/用户组接口到webserver
RCA: SOL: 修改人:zhouzian 检视人:zhouzian
This commit is contained in:
parent
32b1fd5a46
commit
e855be04c7
|
@ -357,7 +357,10 @@ static ret_code user_config_get_list_proc(uint source,
|
|||
cJSON * ret_root = cJSON_CreateObject();
|
||||
if (NULL == ret_root)
|
||||
{
|
||||
UCHAR_FREE(data_list);
|
||||
if(ret_get)
|
||||
{
|
||||
UCHAR_FREE(data_list);
|
||||
}
|
||||
ret = RET_ERR;
|
||||
return ret;
|
||||
}
|
||||
|
@ -373,7 +376,7 @@ static ret_code user_config_get_list_proc(uint source,
|
|||
memcpy(output, ret_char, strlen(ret_char)+1);
|
||||
*output_len = strlen(ret_char)+1;
|
||||
|
||||
UCHAR_FREE(data_list);
|
||||
//UCHAR_FREE(data_list);
|
||||
UCHAR_FREE(ret_char);
|
||||
cJSON_Delete(ret_root);
|
||||
return ret;
|
||||
|
@ -590,33 +593,30 @@ static ret_code user_config_add_proc(uint source, uint config_type,
|
|||
/*
|
||||
* 删除用户-处理
|
||||
* iuput格式:
|
||||
* {
|
||||
* "type": 1,
|
||||
* "data": ["用户01", "用户02", "用户03"]
|
||||
* }
|
||||
{
|
||||
"type":1,
|
||||
"data":{
|
||||
"user_id":4 //用户id
|
||||
}
|
||||
}
|
||||
*
|
||||
* output格式:
|
||||
* [{
|
||||
* "用户01": 0
|
||||
* },
|
||||
* {
|
||||
* "用户02": 1
|
||||
* },
|
||||
* {
|
||||
* "用户03": 2
|
||||
* }
|
||||
*]
|
||||
* 0:成功,1/2:失败,1:用户不存在,2:该用户绑定有策略,需先解除策略
|
||||
{
|
||||
"retcode": 0,
|
||||
"message": "删除成功",
|
||||
"data": "" //空
|
||||
}
|
||||
* 0:成功,1/2/3:失败,1:用户不存在,2:该用户绑定有策略,需先解除策略,3:数据库操作失败
|
||||
*/
|
||||
static ret_code user_config_del_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int array_size;
|
||||
cJSON *root, *data, *username_json, *ret_json, *ret_body_json, *user_id_del_success_json;
|
||||
USER_DEL *username;
|
||||
char *ret_char = NULL;
|
||||
int temp_output_len;
|
||||
cJSON *root, *data, *uuid_json, *res;
|
||||
char * ret_char;
|
||||
char *message[] = {"删除成功","删除用户不存在","先去策略模块解绑策略","数据库操作失败"};
|
||||
|
||||
/* 解析json串 */
|
||||
root = cJSON_Parse(input); //需要释放
|
||||
|
@ -629,11 +629,8 @@ static ret_code user_config_del_proc(uint source, uint config_type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
array_size = cJSON_GetArraySize(data);
|
||||
//unsigned short user_id_del_success[array_size]; //存储删除成功的用户id
|
||||
|
||||
username = (USER_DEL *)malloc(sizeof(USER_DEL)); //需要释放
|
||||
if(NULL == username)
|
||||
uuid_json = cJSON_GetObjectItem(data, "user_id");
|
||||
if(!uuid_json)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
//ASSERT_RET(ret);
|
||||
|
@ -641,61 +638,34 @@ static ret_code user_config_del_proc(uint source, uint config_type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret_json = cJSON_CreateArray(); //需要释放
|
||||
if(!ret_json)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
cJSON_Delete(root);
|
||||
UCHAR_FREE(username);
|
||||
//ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//memset(user_id_del_success, 0, sizeof(user_id_del_success));
|
||||
user_id_del_success_json = cJSON_CreateArray();
|
||||
|
||||
for(int i = 0; i < array_size; i++)
|
||||
{
|
||||
int ret_del_user;
|
||||
char *ret_username = NULL;
|
||||
username_json = cJSON_GetArrayItem(data, i);
|
||||
//if(!username_json)
|
||||
ret_username = username_json->valuestring;
|
||||
username->type = DELUSER_BY_USERNAME;
|
||||
strcpy(username->id_name.uname, ret_username);
|
||||
ret_del_user = usermanager_del_user(username); //执行操作-删除用户
|
||||
ret_body_json = cJSON_CreateObject();
|
||||
// if(!ret_result_json)
|
||||
/* 返回结果封json */
|
||||
cJSON_AddNumberToObject(ret_body_json, ret_username, ret_del_user); //ret_body_json {"用户01": 0}
|
||||
cJSON_AddItemToArray(ret_json, ret_body_json);
|
||||
|
||||
//保存删除成功的用户id
|
||||
if(DELUSER_SUCCESS == ret_del_user)
|
||||
{
|
||||
cJSON_AddItemToArray(user_id_del_success_json, cJSON_CreateNumber(username->id_name.id));
|
||||
// user_id_del_success[i] = username->id_name.id;
|
||||
}
|
||||
}
|
||||
int ret_del = usermanager_del_user(uuid_json->valueint);
|
||||
cJSON_Delete(root);
|
||||
|
||||
/* 处理返回结果 */
|
||||
ret_char = cJSON_PrintUnformatted(ret_json);
|
||||
memcpy(output, ret_char, strlen(ret_char)+1);
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_SYSERR;
|
||||
return ret;
|
||||
}
|
||||
cJSON_AddNumberToObject(res, "retcode", ret_del);
|
||||
cJSON_AddStringToObject(res, "message", message[ret_del]);
|
||||
cJSON_AddStringToObject(res, "data", "");
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
temp_output_len = strlen(ret_char)+1;
|
||||
|
||||
/* 强制下线删除成功的用户 */
|
||||
// for(int j = 0; j < GROUP_INDEX_MAX; j++)
|
||||
// {
|
||||
// cJSON_AddItemToArray(user_id_del_success_json, cJSON_CreateNumber(user_id_del_success[j]));
|
||||
// }
|
||||
//printf("需要下线的用户id:%s \n", cJSON_PrintUnformatted(user_id_del_success_json));
|
||||
offline_force_by_userid(cJSON_PrintUnformatted(user_id_del_success_json));
|
||||
if (CM_BUFF_SIZE < temp_output_len)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
}else
|
||||
{
|
||||
memcpy(output, ret_char, temp_output_len);
|
||||
*output_len = temp_output_len;
|
||||
}
|
||||
|
||||
/* 释放内存 */
|
||||
cJSON_Delete(root);
|
||||
cJSON_Delete(ret_json);
|
||||
cJSON_Delete(user_id_del_success_json);
|
||||
cJSON_Delete(res);
|
||||
UCHAR_FREE(ret_char);
|
||||
UCHAR_FREE(username);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ ret_code usergroup_config_chk(uint source, uint *config_type,
|
|||
}
|
||||
|
||||
/*
|
||||
* 根据用户组名查询用户组uuid-处理
|
||||
* 查询用户组列表
|
||||
* iuput格式:
|
||||
{
|
||||
"type": 4, //4:表示获得用户组列表
|
||||
|
@ -98,7 +98,10 @@ static ret_code usergroup_config_get_list_proc(uint source,
|
|||
cJSON * ret_root = cJSON_CreateObject();
|
||||
if (NULL == ret_root)
|
||||
{
|
||||
UCHAR_FREE(data_list);
|
||||
if(ret_get)
|
||||
{
|
||||
UCHAR_FREE(data_list);
|
||||
}
|
||||
ret = RET_SYSERR;
|
||||
return ret;
|
||||
}
|
||||
|
@ -113,7 +116,7 @@ static ret_code usergroup_config_get_list_proc(uint source,
|
|||
memcpy(output, ret_char, strlen(ret_char)+1);
|
||||
*output_len = strlen(ret_char)+1;
|
||||
|
||||
UCHAR_FREE(data_list);
|
||||
//UCHAR_FREE(data_list); //释放了不该释放的内存
|
||||
UCHAR_FREE(ret_char);
|
||||
cJSON_Delete(ret_root);
|
||||
return ret;
|
||||
|
@ -384,35 +387,29 @@ static ret_code usergroup_config_add_proc(uint source, uint config_type,
|
|||
/*
|
||||
* 删除用户组-处理
|
||||
* iuput格式:
|
||||
* {
|
||||
* "type": 1,
|
||||
* "data": ["用户组01", "用户组02", "用户组03"]
|
||||
* }
|
||||
{
|
||||
"type":1,
|
||||
"data":{
|
||||
"group_id":4 //用户组id
|
||||
}
|
||||
}
|
||||
*
|
||||
* output格式:
|
||||
* [{
|
||||
* "用户组01": 0
|
||||
* },
|
||||
* {
|
||||
* "用户组02": 1
|
||||
* },
|
||||
* {
|
||||
* "用户组03": 2
|
||||
* }
|
||||
*]
|
||||
* 0:成功,1/2:失败,1:用户组不存在,2:该用户组绑定有策略,需先解除策略
|
||||
{
|
||||
"retcode": 0,
|
||||
"message": "删除成功",
|
||||
"data": "" //空
|
||||
}
|
||||
* 0:成功,1/2/3:失败,1:用户组不存在,2:该用户组绑定有策略,需先解除策略,3:操作数据库失败
|
||||
*/
|
||||
static ret_code usergroup_config_del_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int array_size;
|
||||
GROUP_DEL *groupname;
|
||||
cJSON *root, *data, *ret_json, *ret_body_json, *group_id_del_success_json;
|
||||
char *ret_char = NULL;
|
||||
//unsigned short *group_id_del_success; //存储删除成功的用户组id
|
||||
unsigned short group_id_del_success[GROUP_INDEX_MAX];
|
||||
cJSON *root, *data, *uuid_json, *res;
|
||||
char *ret_char;
|
||||
char *message[] = {"删除成功","删除用户不存在","先去策略模块解绑策略","数据库操作失败"};
|
||||
|
||||
/* 解析json串 */
|
||||
root = cJSON_Parse(input);
|
||||
|
@ -420,70 +417,46 @@ static ret_code usergroup_config_del_proc(uint source, uint config_type,
|
|||
if(!data)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
//ASSERT_RET(ret);
|
||||
cJSON_Delete(root);
|
||||
return ret;
|
||||
}
|
||||
|
||||
array_size = cJSON_GetArraySize(data);
|
||||
|
||||
groupname = (GROUP_DEL *)malloc(sizeof(GROUP_DEL));
|
||||
if(NULL == groupname)
|
||||
uuid_json = cJSON_GetObjectItem(data, "group_id");
|
||||
if(!uuid_json)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
//ASSERT_RET(ret);
|
||||
ret = RET_INPUTERR;
|
||||
cJSON_Delete(root);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_json = cJSON_CreateArray();
|
||||
if(!ret_json)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
//ASSERT_RET(ret);
|
||||
cJSON_Delete(root);
|
||||
UCHAR_FREE(groupname);
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(group_id_del_success, 0, sizeof(group_id_del_success));
|
||||
for(int i = 0; i < array_size; i++)
|
||||
{
|
||||
int ret_del_group;
|
||||
char *ret_groupname = NULL;
|
||||
ret_groupname = cJSON_GetArrayItem(data, i)->valuestring;
|
||||
groupname->type = DELGROUP_BY_GROUPNAME;
|
||||
strcpy(groupname->id_name.gname, ret_groupname);
|
||||
ret_del_group = del_group_by_name(groupname); //执行操作-删除用户组
|
||||
ret_body_json = cJSON_CreateObject();
|
||||
// if(!ret_result_json)
|
||||
cJSON_AddNumberToObject(ret_body_json, ret_groupname, ret_del_group);
|
||||
cJSON_AddItemToArray(ret_json, ret_body_json);
|
||||
if(DELGROUP_SUCCESS == ret_del_group)
|
||||
{
|
||||
group_id_del_success[groupname->id_name.id] = groupname->id_name.id;
|
||||
}
|
||||
}
|
||||
|
||||
/* 强制下线删除成功的用户组 */
|
||||
group_id_del_success_json = cJSON_CreateArray();
|
||||
for(int j = 0; j < GROUP_INDEX_MAX; j++)
|
||||
{
|
||||
cJSON_AddItemToArray(group_id_del_success_json, cJSON_CreateNumber(group_id_del_success[j]));
|
||||
}
|
||||
//printf("需要下线的用户组id:%s \n", cJSON_PrintUnformatted(group_id_del_success_json));
|
||||
offline_force_by_groupid(cJSON_PrintUnformatted(group_id_del_success_json));
|
||||
int ret_del = usermanager_del_group(uuid_json->valueint);
|
||||
cJSON_Delete(root);
|
||||
|
||||
/* 处理返回结果 */
|
||||
ret_char = cJSON_PrintUnformatted(ret_json);
|
||||
memcpy(output, ret_char, strlen(ret_char)+1);
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_SYSERR;
|
||||
return ret;
|
||||
}
|
||||
cJSON_AddNumberToObject(res, "retcode", ret_del);
|
||||
cJSON_AddStringToObject(res, "message", message[ret_del]);
|
||||
cJSON_AddStringToObject(res, "data", "");
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
int temp_output_len = strlen(ret_char)+1;
|
||||
|
||||
if (CM_BUFF_SIZE < temp_output_len)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
}else
|
||||
{
|
||||
memcpy(output, ret_char, temp_output_len);
|
||||
*output_len = temp_output_len;
|
||||
}
|
||||
|
||||
/* 释放内存 */
|
||||
cJSON_Delete(root);
|
||||
cJSON_Delete(ret_json);
|
||||
cJSON_Delete(group_id_del_success_json);
|
||||
cJSON_Delete(res);
|
||||
UCHAR_FREE(ret_char);
|
||||
UCHAR_FREE(groupname);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
void * um_hdbc = NULL;//用户管理数据库连接句柄
|
||||
extern ARRAY g_user_index_head;
|
||||
extern ARRAY g_group_index_head;
|
||||
extern USERACCOUNT g_user_table[];
|
||||
extern USERGROUP g_group_table[];
|
||||
extern USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
|
||||
ret_code userecover_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
|
@ -155,7 +155,7 @@ ret_code userecover_config_get_all(uint source,
|
|||
s2j_struct_get_basic_element(temp_user, user, string, valid_end_time);
|
||||
|
||||
g_user_table[temp_user->ID].ID = temp_user->ID;
|
||||
g_user_table[temp_user->ID].GID = temp_user->ID;
|
||||
g_user_table[temp_user->ID].GID = temp_user->GID;
|
||||
g_user_table[temp_user->ID].multi_valid = MULTI_VALID(temp_user->multi, temp_user->valid);
|
||||
strcpy(g_user_table[temp_user->ID].uname, temp_user->uname);
|
||||
strcpy(g_user_table[temp_user->ID].udescription, temp_user->udescription);
|
||||
|
|
|
@ -72,7 +72,7 @@ typedef union
|
|||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
int type; //1:按用户名删除、2:按用户uuid删除
|
||||
USER_ID_NAME id_name;
|
||||
}USER_DEL;
|
||||
|
||||
|
@ -83,9 +83,6 @@ int init_user();
|
|||
/*添加元素-新增用户*/
|
||||
void usermanager_add_user(char* UNAME, char* UGNAME, char* udesp, char* pwd, int multi, int valid, char* valid_begin_time, char* valid_end_time, USERADD* UADDRES);
|
||||
|
||||
/* 按用户ID查询用户 */
|
||||
void get_user_by_id(unsigned short ID, USERLIST* ULIST);
|
||||
|
||||
/* 按照用户uuid查询用户详情 */
|
||||
bool get_user_detail_by_user_uuid(int user_uuid, char ** user_detail);
|
||||
|
||||
|
@ -104,11 +101,8 @@ bool mod_user_line(char* UNAME, const int INTYPE, char* IN);
|
|||
/* 修改用户-移动分组 */
|
||||
bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short old_group_uuid, unsigned short * user_uuid, int user_uuid_num);
|
||||
|
||||
/* 删除用户
|
||||
* id_name:条件,包括用户名、用户ID
|
||||
* type:类型,1-用户名、2-用户ID
|
||||
*/
|
||||
int usermanager_del_user(USER_DEL* id_name);
|
||||
/* 删除用户 */
|
||||
int usermanager_del_user(int uuid);
|
||||
|
||||
/* 强制下线用户 */
|
||||
void offline_force_by_userid(char *userid);
|
||||
|
|
|
@ -58,15 +58,9 @@ int add_group(char* UGNAME, char* UGDES);
|
|||
/* 修改用户组描述 */
|
||||
unsigned short mod_group_desp(int group_uuid, char* UGDES);
|
||||
|
||||
/* 获得用户组个数 */
|
||||
unsigned short get_group_count();
|
||||
|
||||
/* 查询用户组列表 */
|
||||
bool show_group_list(char ** group_list);
|
||||
|
||||
/* 根据用户组名查询用户组 */
|
||||
bool find_group_by_name(char* UGNAME, USERGROUP* UGRES);
|
||||
|
||||
/*根据用户组uuid查询用户组id*/
|
||||
unsigned short get_groupid_by_uuid(int uugid, void * hdbc);
|
||||
|
||||
|
@ -77,7 +71,7 @@ bool get_group_uuid_by_name(char* gname, unsigned short * group_uuid);
|
|||
unsigned short get_groupid_by_name(char* UGNAME, void* hdbc);
|
||||
|
||||
/* 根据用户组名删除用户组 */
|
||||
unsigned short del_group_by_name(GROUP_DEL* UGNAME);
|
||||
int usermanager_del_group(int group_uuid);
|
||||
|
||||
/* 强制下线用户-按用户组ID */
|
||||
void offline_force_by_groupid(char *groupid);
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
//#include "sg/user/user_manager/user_auth.h"
|
||||
|
||||
extern ARRAY g_user_index_head;
|
||||
extern USERGROUP g_group_table[];
|
||||
extern exce_mod_user g_user_modfunc_table[];
|
||||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
extern exce_mod_user g_user_modfunc_table[USER_ATTRIBUTE_NUM];
|
||||
extern void * um_hdbc;
|
||||
//extern USER_AUTH_LIST g_user_auth_ret_table[];
|
||||
USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
|
@ -136,17 +136,21 @@ void usermanager_add_user(char* uname, char* gname, char* udesp, char* pwd, int
|
|||
return;
|
||||
}
|
||||
|
||||
long long ID_templong = ID;
|
||||
long long GID_templong = GID_temp;
|
||||
long long multi_templong = multi;
|
||||
long long valid_templong = valid;
|
||||
/* 连接数据库,存user_account表 */
|
||||
char *adduser_sql = "INSERT INTO `user_account` SET id = ?, group_id = ?, user_name = ?, password = ?, udescription = ?, \
|
||||
char *adduser_sql = "INSERT INTO user_account SET id = ?, group_id = ?, user_name = ?, password = ?, udescription = ?, \
|
||||
multi_player = ?, valid_always = ?, valid_begin_time = ?, valid_end_time = ?";
|
||||
int ret_adduser = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_INSERT, USER_TABLE, adduser_sql, 9,
|
||||
DB_DATA_INT_TYPE, sizeof(ID), ID,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_temp), GID_temp,
|
||||
DB_DATA_INT_TYPE, sizeof(ID_templong), ID_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_templong), GID_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(uname)+1, uname,
|
||||
DB_DATA_STRING_TYPE, strlen(pwd)+1, pwd,
|
||||
DB_DATA_STRING_TYPE, strlen(udesp)+1, udesp,
|
||||
DB_DATA_INT_TYPE, sizeof(multi), multi,
|
||||
DB_DATA_INT_TYPE, sizeof(valid), valid,
|
||||
DB_DATA_INT_TYPE, sizeof(multi_templong), multi_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(valid_templong), valid_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(valid_begin_time)+1, valid_begin_time,
|
||||
DB_DATA_STRING_TYPE, strlen(valid_end_time)+1,valid_end_time);
|
||||
if(DB_RET_OK != ret_adduser)
|
||||
|
@ -194,11 +198,12 @@ bool get_user_detail_by_user_uuid(int user_uuid, char ** user_detail)
|
|||
return false;
|
||||
}
|
||||
|
||||
long long uid_templong = user_uuid;
|
||||
char * select_sql = "SELECT U.uuid ID, G.uuid GID, U.user_name uname, G.gname gname, U.udescription udescription,\
|
||||
U.multi_player multi, U.valid_always valid, U.valid_begin_time, U.valid_end_time \
|
||||
FROM user_account U, user_group G WHERE U.group_id = G.id AND U.uuid = ? ";
|
||||
char * udetail = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_TABLE, select_sql, 1, 0, &num, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(user_uuid), user_uuid);
|
||||
DB_DATA_INT_TYPE, 4, uid_templong);
|
||||
|
||||
if (0 == num || NULL == udetail)
|
||||
{
|
||||
|
@ -226,48 +231,6 @@ bool get_user_detail_by_user_uuid(int user_uuid, char ** user_detail)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* 按用户ID查询用户 */
|
||||
void get_user_by_id(unsigned short ID, USERLIST* ulist)
|
||||
{
|
||||
unsigned short temp_multi, temp_valid;
|
||||
char temp_begin_time[UTIME] = { 0 };
|
||||
char temp_end_time[UTIME] = { 0 };
|
||||
|
||||
if (NULL == ulist || INVALID_INDEX >= ID || (USER_INDEX_MAX - 1) <= ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(ulist, 0, sizeof(ulist));
|
||||
|
||||
/* 内存查询用户 */
|
||||
temp_multi = MULTI_GET(g_user_table[ID].multi_valid);
|
||||
temp_valid = VALID_GET(g_user_table[ID].multi_valid);
|
||||
|
||||
ulist->ID = ID;
|
||||
ulist->GID = g_user_table[ID].GID;
|
||||
ulist->multi = temp_multi;
|
||||
ulist->valid = temp_valid;
|
||||
strcpy(ulist->uname, g_user_table[ID].uname);
|
||||
strcpy(ulist->gname, g_group_table[ulist->GID].gname);
|
||||
strcpy(ulist->udescription, g_user_table[ID].udescription);
|
||||
strcpy(ulist->passwd, g_user_table[ID].passwd);
|
||||
|
||||
if (1 == temp_valid)
|
||||
{
|
||||
TIME_T2STRING(g_user_table[ID].valid_begin_time, temp_begin_time);
|
||||
TIME_T2STRING(g_user_table[ID].valid_end_time, temp_end_time);
|
||||
}
|
||||
|
||||
strcpy(ulist->valid_begin_time, temp_begin_time);
|
||||
strcpy(ulist->valid_end_time, temp_end_time);
|
||||
|
||||
/* 查数据库,这里查数据库没上面快 */
|
||||
/* SELECT id, group_id, multi_player, valid_always, user_name, udescription,valid_begin_time,valid_end_time FROM `user`WHERE id = */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* 修改用户-web */
|
||||
bool mod_user_web(USERLIST* ulist)
|
||||
{
|
||||
|
@ -391,31 +354,35 @@ bool mod_user_web(USERLIST* ulist)
|
|||
|
||||
char * moduser_web_sql;
|
||||
int ret_moduser_web;
|
||||
long long GID_templong = ulist->GID;
|
||||
long long multi_templong = ulist->multi;
|
||||
long long valid_templong = ulist->valid;
|
||||
long long ID_templong = ulist->ID;
|
||||
if (0 == ulist->resetpwd)
|
||||
{
|
||||
moduser_web_sql = "UPDATE `user_account` SET group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?),\
|
||||
moduser_web_sql = "UPDATE user_account SET group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?),\
|
||||
udescription = ?, password = ?, multi_player = ?, valid_always = ?, valid_begin_time = ?, valid_end_time = ? WHERE uuid = ?";
|
||||
ret_moduser_web = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_UPDATE, USER_TABLE, moduser_web_sql, 8,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->GID), ulist->GID,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_templong), GID_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_udes)+1, temp_udes,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_pwd)+1, temp_pwd,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->multi), ulist->multi,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->valid), ulist->valid,
|
||||
DB_DATA_INT_TYPE, sizeof(multi_templong), multi_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(valid_templong), valid_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_begin_time)+1, temp_begin_time,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_end_time)+1, temp_end_time,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->ID), ulist->ID);
|
||||
DB_DATA_INT_TYPE, sizeof(ID_templong), ID_templong);
|
||||
}else
|
||||
{
|
||||
moduser_web_sql = "UPDATE `user_account` SET group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?),\
|
||||
moduser_web_sql = "UPDATE user_account SET group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?),\
|
||||
udescription = ?, multi_player = ?, valid_always = ?, valid_begin_time = ?, valid_end_time = ? WHERE uuid = ?";
|
||||
ret_moduser_web = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_UPDATE, USER_TABLE, moduser_web_sql, 7,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->GID), ulist->GID,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_templong), GID_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_udes)+1, temp_udes,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->multi), ulist->multi,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->valid), ulist->valid,
|
||||
DB_DATA_INT_TYPE, sizeof(multi_templong), multi_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(valid_templong), valid_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_begin_time)+1, temp_begin_time,
|
||||
DB_DATA_STRING_TYPE, strlen(temp_end_time)+1, temp_end_time,
|
||||
DB_DATA_INT_TYPE, sizeof(ulist->ID), ulist->ID);
|
||||
DB_DATA_INT_TYPE, sizeof(ID_templong),ID_templong);
|
||||
}
|
||||
|
||||
if(DB_RET_OK != ret_moduser_web)
|
||||
|
@ -484,57 +451,33 @@ bool mod_user_web(USERLIST* ulist)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*解析用户组id的json字符串 --> 用户组id*/
|
||||
bool uuid_json2int(char * gid, char * name, unsigned short * id)
|
||||
/*根据用户uuid查询用户id*/
|
||||
static unsigned short get_userid_by_uuid(int uuid, void * hdbc)
|
||||
{
|
||||
//unsigned short GID_temp = INVALID_INDEX;
|
||||
if (NULL == gid || NULL == name || NULL == id)
|
||||
unsigned short UID_temp = INVALID_INDEX;
|
||||
int num;
|
||||
char *uid = NULL;
|
||||
|
||||
if(NULL == hdbc)
|
||||
{
|
||||
return false;
|
||||
return UID_temp;
|
||||
}
|
||||
|
||||
cJSON *root = cJSON_Parse(gid);
|
||||
if(!root)
|
||||
long long id_templong = uuid;
|
||||
|
||||
char *select_sql = "SELECT id FROM user_account WHERE uuid = ?";
|
||||
uid = select_datebase_by_number(USER_MANAGER_DBID, hdbc, USER_TABLE, select_sql, 1, 0, &num, 1,
|
||||
DB_DATA_INT_TYPE, 4, id_templong);
|
||||
|
||||
if(0 == num)
|
||||
{
|
||||
return false;
|
||||
return UID_temp;
|
||||
}
|
||||
|
||||
cJSON *id_list = cJSON_GetObjectItem(root, "data");
|
||||
if(!id_list)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
int id_list_size = cJSON_GetArraySize(id_list);
|
||||
if(1 != id_list_size)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *id_obj = cJSON_GetArrayItem(id_list, 0);
|
||||
if(!id_obj)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *gid_json = cJSON_GetObjectItem(id_obj, name);
|
||||
if(!gid_json)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
*id = gid_json->valueint;
|
||||
|
||||
cJSON_Delete(root);
|
||||
return true;
|
||||
ARRAYJSON2INT(uid, "id", &UID_temp);
|
||||
return UID_temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 根据用户名查询用户UUID */
|
||||
bool get_user_uuid_by_name(char* uname, unsigned short * user_uuid)
|
||||
{
|
||||
|
@ -564,8 +507,6 @@ bool get_user_uuid_by_name(char* uname, unsigned short * user_uuid)
|
|||
return true;
|
||||
}
|
||||
|
||||
//bool ret_json2int = uuid_json2int(uid, "uuid", &uuid_temp);
|
||||
|
||||
ARRAYJSON2INT(uid, "uuid", &uuid_temp);
|
||||
|
||||
if (INVALID_INDEX == uuid_temp)
|
||||
|
@ -677,11 +618,11 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
{
|
||||
if (0 == old_group_uuid)
|
||||
{
|
||||
moveug_sql = "UPDATE `user_account` SET group_id = ?";
|
||||
moveug_sql = "UPDATE user_account SET group_id = ?";
|
||||
root_all = true;
|
||||
}else
|
||||
{
|
||||
moveug_sql = "UPDATE `user_account` \
|
||||
moveug_sql = "UPDATE user_account \
|
||||
SET group_id = ? \
|
||||
WHERE group_id = ( \
|
||||
SELECT \
|
||||
|
@ -691,10 +632,11 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
WHERE \
|
||||
user_group.uuid = ? \
|
||||
)";
|
||||
selectuid_sql = "SELECT id FROM `user_account` WHERE group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?)";
|
||||
selectuid_sql = "SELECT id FROM user_account WHERE group_id = (SELECT user_group.id FROM user_group WHERE user_group.uuid = ?)";
|
||||
|
||||
long long gid_templong = old_group_uuid;
|
||||
ret_userids = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_TABLE, selectuid_sql, 1, 0, &sql_num, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(old_group_uuid), old_group_uuid);
|
||||
DB_DATA_INT_TYPE, 4, gid_templong);
|
||||
//解析ret_userids --> temp_userids
|
||||
if(0 == sql_num || NULL == ret_userids)
|
||||
{
|
||||
|
@ -726,9 +668,12 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
}
|
||||
}
|
||||
|
||||
long long temp_groupid_long = temp_groupid;
|
||||
long long old_group_uuid_templong = old_group_uuid;
|
||||
|
||||
ret_sql = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_UPDATE, USER_TABLE, moveug_sql, 2,
|
||||
DB_DATA_INT_TYPE, sizeof(temp_groupid), temp_groupid,
|
||||
DB_DATA_INT_TYPE, sizeof(old_group_uuid), old_group_uuid);
|
||||
DB_DATA_INT_TYPE, sizeof(temp_groupid_long), temp_groupid_long,
|
||||
DB_DATA_INT_TYPE, sizeof(old_group_uuid_templong), old_group_uuid_templong);
|
||||
if (DB_RET_OK != ret_sql)
|
||||
{
|
||||
return false;
|
||||
|
@ -744,12 +689,13 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
}
|
||||
|
||||
moveug_sql = "UPDATE user_account SET user_account.group_id = ? WHERE user_account.uuid = ?";
|
||||
selectuid_sql = "SELECT id FROM `user_account` WHERE uuid = ?";
|
||||
selectuid_sql = "SELECT id FROM user_account WHERE uuid = ?";
|
||||
for (int i = 0; i < user_uuid_num; i++)
|
||||
{
|
||||
unsigned short temp_uesr_uuid = 0;
|
||||
long long user_uuid_templong = user_uuid[i];
|
||||
ret_userids = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_TABLE, selectuid_sql, 1, 0, &sql_num, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(user_uuid[i]), user_uuid[i]);
|
||||
DB_DATA_INT_TYPE, sizeof(user_uuid_templong), user_uuid_templong);
|
||||
if(0 == sql_num || NULL ==ret_userids)
|
||||
{
|
||||
return false;
|
||||
|
@ -758,9 +704,12 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
temp_userids[temp_userid] = temp_userid;
|
||||
|
||||
temp_uesr_uuid = user_uuid[i];
|
||||
|
||||
long long temp_groupid_long = temp_groupid;
|
||||
long long temp_uesr_uuid_long = temp_uesr_uuid;
|
||||
ret_sql = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_UPDATE, USER_TABLE, moveug_sql, 2,
|
||||
DB_DATA_INT_TYPE, sizeof(temp_groupid), temp_groupid,
|
||||
DB_DATA_INT_TYPE, sizeof(temp_uesr_uuid), temp_uesr_uuid);
|
||||
DB_DATA_INT_TYPE, sizeof(temp_groupid_long), temp_groupid_long,
|
||||
DB_DATA_INT_TYPE, sizeof(temp_uesr_uuid_long), temp_uesr_uuid_long);
|
||||
if(DB_RET_OK != ret_sql)
|
||||
{
|
||||
return false;
|
||||
|
@ -789,18 +738,15 @@ bool move_user_group(int flag_all, unsigned short new_group_uuid, unsigned short
|
|||
/* 强制下线用户 */
|
||||
void offline_force_by_userid(char *userid)
|
||||
{
|
||||
printf("根据用户user_id强制下线:%s \n",userid);
|
||||
bool ret = redisPubInit();
|
||||
if (!ret)
|
||||
{
|
||||
//printf("Init failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = redisPubConnect();
|
||||
if (!ret)
|
||||
{
|
||||
//printf("connect failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -836,17 +782,11 @@ void offline_force_one_user(unsigned short user_id)
|
|||
}
|
||||
|
||||
/* 删除用户 */
|
||||
int usermanager_del_user(USER_DEL* in)
|
||||
int usermanager_del_user(int uuid)
|
||||
{
|
||||
unsigned short user_id_temp;
|
||||
|
||||
if(NULL == in)
|
||||
{
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
}
|
||||
|
||||
/* 连接数据库 */
|
||||
//deluser_hdbc = connect_database(12);
|
||||
re_connect();
|
||||
if(NULL == um_hdbc)
|
||||
{
|
||||
|
@ -856,42 +796,34 @@ int usermanager_del_user(USER_DEL* in)
|
|||
|
||||
/* 调用策略提供的接口,查询是否绑定策略,如果绑定了策略,返回删除失败-2:DELUSER_FAIL_STRTEGY*/
|
||||
|
||||
switch (in->type)
|
||||
user_id_temp = get_userid_by_uuid(uuid, um_hdbc);
|
||||
if (INVALID_INDEX == user_id_temp)
|
||||
{
|
||||
case DELUSER_BY_USERNAME: //根据用户名删除数据
|
||||
if(NULL == in->id_name.uname)
|
||||
{
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
}
|
||||
user_id_temp = get_userid_by_name(in->id_name.uname, um_hdbc);
|
||||
if (INVALID_INDEX == user_id_temp)
|
||||
{
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
}
|
||||
in->id_name.id = user_id_temp;
|
||||
break;
|
||||
case DELUSER_BY_USERID: //根据用户id删除数据
|
||||
user_id_temp = in->id_name.id;
|
||||
if(user_id_temp < 1 || user_id_temp >= (USER_INDEX_MAX-1))
|
||||
{
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
break;
|
||||
return DELUSER_FAIL_NOTEXIST;
|
||||
}
|
||||
|
||||
|
||||
/* 删数据库user_account */
|
||||
long long user_id_templong = user_id_temp;
|
||||
char* deluser_sql = "DELETE FROM user_account WHERE id = ?";
|
||||
int ret_del = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_DEL, USER_TABLE, deluser_sql, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(user_id_temp), user_id_temp);
|
||||
DB_DATA_INT_TYPE, sizeof(user_id_templong), user_id_templong);
|
||||
if(DB_RET_OK != ret_del)
|
||||
{
|
||||
return DELUSER_FAIL_DATABASE;
|
||||
}
|
||||
|
||||
/* 删内存,根据用户ID删除用户列表中对应的用户 - 释放index、ID置0 */
|
||||
free_index(&g_user_index_head, user_id_temp);
|
||||
g_user_table[user_id_temp].ID = INVALID_INDEX;
|
||||
|
||||
/* 强制用户下线 */
|
||||
char uid_temp[16];
|
||||
//itoa(user_id_temp, uid_temp, 10);
|
||||
sprintf(uid_temp, "%d", user_id_temp);
|
||||
//offline_force_by_userid(uid_temp);
|
||||
|
||||
return DELUSER_SUCCESS;
|
||||
/* 强制用户下线在外面 */
|
||||
}
|
||||
|
||||
/* 查询用户列表 */
|
||||
|
@ -933,6 +865,10 @@ bool useraccount_showlist(int uugroup_id, char * user_name, int page_start, int
|
|||
return false;
|
||||
}
|
||||
|
||||
long long uugroup_id_templong = uugroup_id;
|
||||
long long page_s_templong = page_s;
|
||||
long long page_counts_templong = page_counts;
|
||||
|
||||
if (INVALID_INDEX == uugroup_id) //所有用户组-过滤用户名
|
||||
{
|
||||
select_sql = "SELECT U.uuid ID, G.uuid GID, U.user_name uname, G.gname gname, U.udescription udescription,\
|
||||
|
@ -940,18 +876,18 @@ bool useraccount_showlist(int uugroup_id, char * user_name, int page_start, int
|
|||
FROM user_account U, user_group G WHERE U.group_id = G.id AND U.user_name LIKE ? LIMIT ?, ?";
|
||||
ulist = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_GROUP_TABLE, select_sql, 1, 0, &num, 3,
|
||||
DB_DATA_STRING_TYPE, arrlen+1, temp_uname,
|
||||
DB_DATA_INT_TYPE, sizeof(page_s), page_s,
|
||||
DB_DATA_INT_TYPE, sizeof(page_counts), page_counts);
|
||||
DB_DATA_INT_TYPE, sizeof(page_s_templong), page_s_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(page_counts_templong), page_counts_templong);
|
||||
}else
|
||||
{
|
||||
select_sql = "SELECT U.uuid ID, G.uuid GID, U.user_name uname, G.gname gname, U.udescription udescription,\
|
||||
U.multi_player multi, U.valid_always valid, U.valid_begin_time, U.valid_end_time \
|
||||
FROM user_account U, user_group G WHERE G.uuid = ? AND U.group_id = G.id AND U.user_name LIKE ? LIMIT ?, ?";
|
||||
ulist = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_GROUP_TABLE, select_sql, 1, 0, &num, 4,
|
||||
DB_DATA_INT_TYPE, sizeof(uugroup_id), uugroup_id,
|
||||
DB_DATA_INT_TYPE, sizeof(uugroup_id_templong), uugroup_id_templong,
|
||||
DB_DATA_STRING_TYPE, arrlen+1, temp_uname,
|
||||
DB_DATA_INT_TYPE, sizeof(page_s), page_s,
|
||||
DB_DATA_INT_TYPE, sizeof(page_counts), page_counts);
|
||||
DB_DATA_INT_TYPE, sizeof(page_s_templong), page_s_templong,
|
||||
DB_DATA_INT_TYPE, sizeof(page_counts_templong), page_counts_templong);
|
||||
}
|
||||
if (0 == num || NULL == ulist) //查询结果为空
|
||||
{
|
||||
|
@ -993,7 +929,8 @@ void um_getuser_db(char ** user_db)
|
|||
return;
|
||||
}
|
||||
|
||||
char * select_sql = "SELECT id ID, group_id GID, multi_player multi, valid_always valid, user_name uname, udescription, valid_begin_time,valid_end_time FROM `user_account`";
|
||||
char * select_sql = "SELECT id ID, group_id GID, multi_player multi, valid_always valid, user_name uname, udescription, \
|
||||
valid_begin_time,valid_end_time FROM user_account";
|
||||
char * ret_user = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_TABLE, select_sql, 1, 0, &num, 0);
|
||||
|
||||
if(0 == num || NULL == ret_user)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
extern ARRAY g_group_index_head;
|
||||
extern ARRAY g_user_index_head;
|
||||
extern USERACCOUNT g_user_table[];
|
||||
extern USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
extern void * um_hdbc;
|
||||
USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
|
||||
|
@ -78,10 +78,13 @@ int add_group(char* name, char* description)
|
|||
return ADDGROUP_FAIL_FULL;
|
||||
}
|
||||
|
||||
long long id_templong = ID;
|
||||
printf("add group new group_id:%d .\n",ID);
|
||||
|
||||
/* 连接数据库,向user_group表中添加:用户组ID、用户组名和用户组描述 */
|
||||
char *addgroup_sql = "INSERT INTO user_group SET id = ?, gname = ?, gdescription = ?";
|
||||
int ret_addgroup = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_INSERT, USER_GROUP_TABLE, addgroup_sql, 3,
|
||||
DB_DATA_INT_TYPE, sizeof(ID), ID,
|
||||
DB_DATA_INT_TYPE, 4, id_templong,
|
||||
DB_DATA_STRING_TYPE, strlen(name)+1, name,
|
||||
DB_DATA_STRING_TYPE, strlen(description)+1,description);
|
||||
/* ret_addgroup记录日志 */
|
||||
|
@ -125,11 +128,13 @@ unsigned short mod_group_desp(int group_uuid, char* gdesp)
|
|||
return MODGROUP_FAIL_INPUT;
|
||||
}
|
||||
|
||||
long long gid_templong = group_uuid;
|
||||
|
||||
/* 修改数据库 */
|
||||
char *modgroup_sql = "UPDATE user_group SET gdescription = ? WHERE uuid = ? ";
|
||||
int ret_modgroup = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_UPDATE, USER_GROUP_TABLE, modgroup_sql, 2,
|
||||
DB_DATA_STRING_TYPE, strlen(gdesp), gdesp,
|
||||
DB_DATA_INT_TYPE, sizeof(group_uuid), group_uuid);
|
||||
DB_DATA_INT_TYPE, 4, gid_templong);
|
||||
if(DB_RET_OK != ret_modgroup)
|
||||
{
|
||||
return MODGROUP_FAIL_DATABASE;
|
||||
|
@ -141,51 +146,6 @@ unsigned short mod_group_desp(int group_uuid, char* gdesp)
|
|||
return MODGROUP_SUCCESS;
|
||||
}
|
||||
|
||||
/* 查询用户组-按用户名 */
|
||||
bool find_group_by_name(char* gname, USERGROUP* groupout)
|
||||
{
|
||||
if (NULL == gname || NULL == groupout)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 内存中查询数据 */
|
||||
groupout->ID = INVALID_INDEX;
|
||||
for (int i = 0; i < GROUP_INDEX_MAX; i++)
|
||||
{
|
||||
if ((0 == strcmp(gname, g_group_table[i].gname)) && (INVALID_INDEX != g_group_table[i].ID))
|
||||
{
|
||||
groupout->ID = g_group_table[i].ID;
|
||||
strcpy(groupout->gname, g_group_table[i].gname);
|
||||
strcpy(groupout->gdescription, g_group_table[i].gdescription);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* 连接数据库,根据用户名查询表user_group */
|
||||
/* SELECT UG.id, UG.gname, UG.gdescription FROM user_group UG WHERE UG.gname = "" */
|
||||
}
|
||||
|
||||
|
||||
/* 获得用户组个数 */
|
||||
unsigned short get_group_count()
|
||||
{
|
||||
/* 内存查询数据 */
|
||||
int num = 0;
|
||||
for (int i = 0; i < GROUP_INDEX_MAX; i++)
|
||||
{
|
||||
if (INVALID_INDEX != g_group_table[i].ID)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
/* 连接数据库,查询表user_group中用户组数量 */
|
||||
/* SELECT COUNT(1) FROM user_group; */
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
/* 查询用户组列表 */
|
||||
bool show_group_list(char ** group_list)
|
||||
{
|
||||
|
@ -310,9 +270,11 @@ unsigned short get_groupid_by_uuid(int uugid, void * hdbc)
|
|||
return GID_temp;
|
||||
}
|
||||
|
||||
long long gid_templong = uugid;
|
||||
|
||||
char *select_sql = "SELECT id FROM user_group WHERE uuid = ?";
|
||||
gid = select_datebase_by_number(USER_MANAGER_DBID, hdbc, USER_GROUP_TABLE, select_sql, 1, 0, &num, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(uugid), uugid);
|
||||
DB_DATA_INT_TYPE, 4, gid_templong);
|
||||
|
||||
if(0 == num)
|
||||
{
|
||||
|
@ -396,18 +358,15 @@ unsigned short get_groupid_by_name(char* gname, void* hdbc)
|
|||
/* 强制下线用户-按用户组id */
|
||||
void offline_force_by_groupid(char *groupid)
|
||||
{
|
||||
printf("根据用户组group_id强制下线用户:%s \n",groupid);
|
||||
bool ret = redisPubInit();
|
||||
if (!ret)
|
||||
{
|
||||
//printf("Init failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = redisPubConnect();
|
||||
if (!ret)
|
||||
{
|
||||
//printf("connect failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -420,13 +379,9 @@ void offline_force_by_groupid(char *groupid)
|
|||
}
|
||||
|
||||
/*删除元素*/
|
||||
unsigned short del_group_by_name(GROUP_DEL* gname)
|
||||
int usermanager_del_group(int group_uuid)
|
||||
{
|
||||
unsigned short GID_temp = 0;
|
||||
if (NULL == gname)
|
||||
{
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
}
|
||||
|
||||
/* 连接数据库 */
|
||||
re_connect();
|
||||
|
@ -438,33 +393,23 @@ unsigned short del_group_by_name(GROUP_DEL* gname)
|
|||
|
||||
/* 调用策略提供的接口,查询是否绑定策略,如果绑定了策略,返回删除失败-2:DELGROUP_FAIL_STRTEGY */
|
||||
|
||||
switch(gname->type)
|
||||
GID_temp = get_groupid_by_uuid(group_uuid, um_hdbc);
|
||||
if(INVALID_INDEX == GID_temp)
|
||||
{
|
||||
case DELGROUP_BY_GROUPNAME: //根据用户组名删除数据
|
||||
if(NULL == gname->id_name.gname)
|
||||
{
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
}
|
||||
GID_temp = get_groupid_by_name(gname->id_name.gname, um_hdbc);
|
||||
if (INVALID_INDEX == GID_temp)
|
||||
{
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
}
|
||||
gname->id_name.id = GID_temp;
|
||||
break;
|
||||
case DELGROUP_BY_GROUPID: //根据用户组id删除数据
|
||||
GID_temp = gname->id_name.id;
|
||||
if(GID_temp < 1 || GID_temp >= (GROUP_INDEX_MAX - 1))
|
||||
{
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
break;
|
||||
return DELGROUP_FAIL_NOTEXIST;
|
||||
}
|
||||
long long gid_templong = GID_temp;
|
||||
|
||||
/* 连接数据库,根据用户组ID删除 用户组表 中对应数据*/
|
||||
char* delgroup_sql = "DELETE FROM user_group WHERE id = ?";
|
||||
int ret_del = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_DEL, USER_GROUP_TABLE, delgroup_sql, 1,
|
||||
DB_DATA_INT_TYPE, 4, gid_templong);
|
||||
if(DB_RET_OK != ret_del)
|
||||
{
|
||||
return DELGROUP_FAIL_DATABASE;
|
||||
}
|
||||
|
||||
/* 根据用户组ID查询用户ID,按照用户ID删除用户 - 释放index、ID置0 */
|
||||
/* 删除内存数据 - user */
|
||||
for(int i = 1; i < USER_INDEX_MAX-1; i++)
|
||||
{
|
||||
if(g_user_table[i].GID == GID_temp)
|
||||
|
@ -474,19 +419,15 @@ unsigned short del_group_by_name(GROUP_DEL* gname)
|
|||
}
|
||||
}
|
||||
|
||||
/* 根据用户组ID删除用户组列表中对应的用户组 - 释放index、ID置0 */
|
||||
/* 删除内存数据 - group */
|
||||
free_index(&g_group_index_head, GID_temp);
|
||||
g_group_table[GID_temp].ID = INVALID_INDEX;
|
||||
|
||||
/* 连接数据库,根据用户组ID删除 用户表 中对应数据*/
|
||||
char* deluser_sql = "DELETE FROM user WHERE group_id = ?";
|
||||
int ret_del = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_DEL, USER_TABLE, deluser_sql, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_temp), GID_temp);
|
||||
/* 连接数据库,根据用户组ID删除 用户组表 中对应数据*/
|
||||
char *delgroup_sql = "DELETE FROM user_group WHERE id = ? ";
|
||||
ret_del = update_database(USER_MANAGER_DBID, um_hdbc, DB_OP_DEL, USER_GROUP_TABLE, delgroup_sql, 1,
|
||||
DB_DATA_INT_TYPE, sizeof(GID_temp), GID_temp);
|
||||
/* 数据库连接释放结果记录日志 */
|
||||
/* 强制用户下线 */
|
||||
char gid_temp[16];
|
||||
//itoa(GID_temp, gid_temp, 10);
|
||||
sprintf(gid_temp, "%d", GID_temp);
|
||||
//offline_force_by_groupid(gid_temp);
|
||||
|
||||
return DELGROUP_SUCCESS;
|
||||
}
|
||||
|
@ -512,7 +453,7 @@ void um_getgroup_db(char ** group_db)
|
|||
return;
|
||||
}
|
||||
|
||||
char * select_sql = "SELECT user_group.id ID, user_group.gname, user_group.gdescription FROM `user_group`";
|
||||
char * select_sql = "SELECT user_group.id ID, user_group.gname, user_group.gdescription FROM user_group";
|
||||
char * ret_group = select_datebase_by_number(USER_MANAGER_DBID, um_hdbc, USER_GROUP_TABLE, select_sql, 1, 0, &num, 0);
|
||||
|
||||
if(0 == num || NULL == ret_group)
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#define AUTH_INIT_SUCCESS 0
|
||||
#define AUTH_USER_INDEX_MAX (100 + 2)
|
||||
|
||||
#define UNAMESIZE (127 + 1)
|
||||
#define UDESIZE (127 + 1)
|
||||
#define UPWDSIZE (63 + 1)
|
||||
#define UNAMESIZE (64)
|
||||
#define UDESIZE (64)
|
||||
#define UPWDSIZE (64)
|
||||
|
||||
typedef struct user_auth
|
||||
{
|
||||
|
@ -63,9 +63,9 @@ do { \
|
|||
USER_AUTH_LIST g_user_auth_ret_table[AUTH_USER_INDEX_MAX] = { 0 };
|
||||
|
||||
/*
|
||||
* config_lock_time 锁定后-时间,单位(分钟)
|
||||
* config_fail_num 锁定前-次数
|
||||
* config_fail_time 锁定前-时间,单位(分钟)
|
||||
* g_config_lock_time 锁定后-时间,单位(分钟)
|
||||
* g_config_fail_num 锁定前-次数
|
||||
* g_config_fail_time 锁定前-时间,单位(分钟)
|
||||
*/
|
||||
static int g_config_lock_time, g_config_fail_num, g_config_fail_time;
|
||||
|
||||
|
@ -78,6 +78,7 @@ static int init_fail_time_queue(unsigned short user_id, int max_size)
|
|||
//记录日志,申请内存失败
|
||||
return AUTH_INIT_FAIL;
|
||||
}
|
||||
memset(AUTH_RECORD.fail_time, 0, sizeof(time_t) * max_size);
|
||||
AUTH_RECORD.max_size = max_size;
|
||||
|
||||
return AUTH_INIT_SUCCESS;
|
||||
|
@ -230,6 +231,77 @@ static void auth_fail_operate(unsigned short user_id, time_t login_time, int con
|
|||
// user_info = NULL;
|
||||
// }
|
||||
|
||||
bool get_config_data(void * auth_hdbc, int * config_data)
|
||||
{
|
||||
int num;
|
||||
if(NULL == auth_hdbc || NULL == config_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char * select_sql = "SELECT locktime config_lock_time, failcount config_fail_num, timehorizon config_fail_time FROM `authparas` LIMIT 0,1";
|
||||
char * ret_sql = select_datebase_by_number(20, auth_hdbc, "authparas", select_sql, 1, 0, &num, 0);
|
||||
|
||||
if(0 == num || NULL == ret_sql)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON * root = cJSON_Parse(ret_sql);
|
||||
if(!root)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON * data = cJSON_GetObjectItem(root, "data");
|
||||
if(!data)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
int data_num = cJSON_GetArraySize(data);
|
||||
if (1 != data_num)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON * user_json = cJSON_GetArrayItem(data, 0);
|
||||
if(!user_json)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 解析各个数据项 */
|
||||
cJSON * config_lock_time = cJSON_GetObjectItem(user_json, "config_lock_time");
|
||||
if(!config_lock_time)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
config_data[0] = config_lock_time->valueint;
|
||||
|
||||
cJSON * config_fail_num = cJSON_GetObjectItem(user_json, "config_fail_num");
|
||||
if(!config_fail_num)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
config_data[1] = config_fail_num->valueint;
|
||||
|
||||
cJSON * config_fail_time = cJSON_GetObjectItem(user_json, "config_fail_time");
|
||||
if(!config_fail_time)
|
||||
{
|
||||
cJSON_Delete(root);
|
||||
return false;
|
||||
}
|
||||
config_data[2] = config_fail_time->valueint;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_user_from_database(char* username, void* hdbc, USERACCOUNT* user_info, int* num_sql)
|
||||
{
|
||||
char * ret_sql = NULL;
|
||||
|
@ -255,6 +327,7 @@ bool get_user_from_database(char* username, void* hdbc, USERACCOUNT* user_info,
|
|||
"multi_player": 0,
|
||||
"valid_always": 0,
|
||||
"user_name": "用户07",
|
||||
"password":"123456",
|
||||
"udescription": "",
|
||||
"valid_begin_time": "",
|
||||
"valid_end_time": ""
|
||||
|
@ -387,11 +460,11 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
int config_fail_time = 0; //规定时间,失败的时间范围,锁定前
|
||||
time_t login_time; //登陆时间
|
||||
time_t remain_lock_time; //锁定剩余时间
|
||||
USERACCOUNT *user_info; //临时数据,存储登陆用户名对应的用户信息
|
||||
USERACCOUNT user_info; //临时数据,存储登陆用户名对应的用户信息
|
||||
void * auth_hdbc;
|
||||
int sql_num;
|
||||
|
||||
memset(auth_result, 0, sizeof(USER_AUTH_RET));
|
||||
//memset(auth_result, 0, sizeof(USER_AUTH_RET));
|
||||
login_time = time(NULL);
|
||||
|
||||
//1、校验用户名和密码
|
||||
|
@ -410,27 +483,30 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
}
|
||||
|
||||
//2、数据库查询配置数据
|
||||
/*if (false)
|
||||
int config_data[3] = {0,0,0};
|
||||
|
||||
bool ret_getconfig = get_config_data(auth_hdbc, config_data);
|
||||
if (!ret_getconfig)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_LACKINFO;
|
||||
return auth_result;
|
||||
}*/
|
||||
return ;
|
||||
}
|
||||
|
||||
config_lock_time = 2;
|
||||
config_fail_num = 5;
|
||||
config_fail_time = 40;
|
||||
config_lock_time = config_data[0];
|
||||
config_fail_num = config_data[1];
|
||||
config_fail_time = config_data[2];
|
||||
/* 校验上述的三个参数都要大于0 */
|
||||
|
||||
//3、根据用户名查询用户信息-用户id和用户组id
|
||||
user_info = (USERACCOUNT*)malloc(sizeof(USERACCOUNT));
|
||||
memset(user_info, 0, sizeof(USERACCOUNT));
|
||||
if (NULL == user_info)
|
||||
{
|
||||
/* 记录日志 */
|
||||
//printf("user_auth()->user_auth->user_info:error. \n");
|
||||
auth_result->ret = AUTH_ERR;
|
||||
return;
|
||||
}
|
||||
// user_info = (USERACCOUNT*)malloc(sizeof(USERACCOUNT));
|
||||
// memset(user_info, 0, sizeof(USERACCOUNT));
|
||||
// if (NULL == user_info)
|
||||
// {
|
||||
// /* 记录日志 */
|
||||
// //printf("user_auth()->user_auth->user_info:error. \n");
|
||||
// auth_result->ret = AUTH_ERR;
|
||||
// return;
|
||||
// }
|
||||
//读取json文件获取数据
|
||||
// get_from_json(username, user_info);
|
||||
// if (NULL == user_info)
|
||||
|
@ -441,21 +517,21 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
// }
|
||||
|
||||
/* 数据库查询 */
|
||||
bool ret_getuser = get_user_from_database(username, auth_hdbc, user_info, &sql_num);
|
||||
bool ret_getuser = get_user_from_database(username, auth_hdbc, &user_info, &sql_num);
|
||||
if(!ret_getuser)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_DATABASE;
|
||||
return;
|
||||
}
|
||||
|
||||
if(0 == sql_num || NULL == user_info)
|
||||
if(0 == sql_num)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_PASSWD;
|
||||
return;
|
||||
}
|
||||
|
||||
user_id = user_info->ID;
|
||||
group_id = user_info->GID;
|
||||
user_id = user_info.ID;
|
||||
group_id = user_info.GID;
|
||||
|
||||
//4、初始化用户认证结果记录表对应id内的循环队列
|
||||
if (DATA_EMPTY == AUTH_RECORD.max_size)
|
||||
|
@ -468,7 +544,6 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
if (AUTH_INIT_FAIL == init_queue_ret)
|
||||
{
|
||||
auth_result->ret = AUTH_ERR;
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +561,6 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
if (AUTH_INIT_FAIL == init_queue_ret)
|
||||
{
|
||||
auth_result->ret = AUTH_ERR;
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
empty_fail_time_queue(user_id);
|
||||
|
@ -499,14 +573,12 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
if (remain_lock_time < 0)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_INPUT;
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
if ((int)(60.0 * config_lock_time) > 60 *remain_lock_time)
|
||||
if ((int)(60.0 * config_lock_time) > remain_lock_time)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_LOCK;
|
||||
auth_result->remain_lock_time = remain_lock_time;
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
//锁定时间已过,解锁,清空该队列
|
||||
|
@ -514,15 +586,14 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
}
|
||||
|
||||
//6、判断是否在有效期内
|
||||
user_valid = AUTH_VALID_GET(user_info->multi_valid);
|
||||
user_valid = AUTH_VALID_GET(user_info.multi_valid);
|
||||
if (1 == user_valid)
|
||||
{
|
||||
if (login_time < user_info->valid_begin_time || login_time > user_info->valid_end_time)
|
||||
if (login_time < user_info.valid_begin_time || login_time > user_info.valid_end_time)
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_VALID;
|
||||
/* 认证失败处理 */
|
||||
auth_fail_operate(user_id, login_time, config_fail_time);
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -534,18 +605,16 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
|
||||
/* 认证失败处理 */
|
||||
auth_fail_operate(user_id, login_time, config_fail_time);
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
|
||||
//8、匹配密码
|
||||
if (0 != strcmp(password, user_info->passwd))
|
||||
if (0 != strcmp(password, user_info.passwd))
|
||||
{
|
||||
auth_result->ret = AUTH_FAIL_PASSWD;
|
||||
|
||||
/* 认证失败处理 */
|
||||
auth_fail_operate(user_id, login_time, config_fail_time);
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -559,7 +628,6 @@ void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
|||
auth_result->group_id = group_id;
|
||||
|
||||
disconnect_database(20, auth_hdbc);
|
||||
xfree(user_info);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,116 +15,91 @@
|
|||
#include "database.h"
|
||||
#include "redisMq.h"
|
||||
|
||||
extern USERGROUP g_group_table[];
|
||||
extern USERACCOUNT g_user_table[];
|
||||
|
||||
// int main1(void)
|
||||
// {
|
||||
// printf("初始化用户组:%d\n", init_group());
|
||||
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa04", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa07", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa08", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa09", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa10", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa11", "描述04"));
|
||||
// printf("增加一个用户组:%d\n", add_group("aaa12", "描述04"));
|
||||
// char *testgroupin = "{\"type\": 0,\"data\": {\"gname\": \"aaa21\",\"gdescription\": \"xxx\"}}";
|
||||
// char *testgroupin01 = "{\"type\": 0,\"data\": {\"gname\": \"aaa22\",\"gdescription\": \"xxx\"}}";
|
||||
// char * outputgroup;
|
||||
// char * outputgroup01;
|
||||
// outputgroup = malloc(130);
|
||||
// outputgroup01 = malloc(130);
|
||||
// if (NULL == outputgroup || NULL == outputgroup01)
|
||||
// {
|
||||
// printf("ulist fail");
|
||||
// }
|
||||
// int *olenth = 1;
|
||||
// ret_code ret_add_group = usergroup_config_proc(1,1,testgroupin,1,outputgroup,olenth);
|
||||
// printf("测试对外接口-增加一个用户组:%d\n", ret_add_group);
|
||||
// printf("%s \n", outputgroup);
|
||||
|
||||
// ret_code ret_add_group01 = usergroup_config_proc(1,1,testgroupin01,1,outputgroup01,olenth);
|
||||
// printf("测试对外接口-增加一个用户组:%d\n", ret_add_group01);
|
||||
// printf("%s \n", outputgroup01);
|
||||
|
||||
|
||||
|
||||
|
||||
// printf("初始化用户:%d\n", init_user());
|
||||
|
||||
// USERADD* addUserResullt;
|
||||
// addUserResullt = (USERADD*)malloc(sizeof(USERADD));
|
||||
// if (NULL == addUserResullt)
|
||||
// {
|
||||
// printf("shibaile");
|
||||
// }
|
||||
|
||||
// usermanager_add_user("用户01", "aaa08", addUserResullt);
|
||||
// printf("%d,用户id:%d\n", addUserResullt->result, addUserResullt->userID);
|
||||
// usermanager_add_user("用户02", "aaa04", addUserResullt);
|
||||
// printf("%d,用户id:%d\n", addUserResullt->result, addUserResullt->userID);
|
||||
// usermanager_add_user("用户03", "aaa04", addUserResullt);
|
||||
// printf("%d,用户id:%d\n", addUserResullt->result, addUserResullt->userID);
|
||||
// usermanager_add_user("用户04", "aaa04", addUserResullt);
|
||||
// printf("%d,用户id:%d\n", addUserResullt->result, addUserResullt->userID);
|
||||
// usermanager_add_user("用户05", "aaa04", addUserResullt);
|
||||
// printf("%d,用户id:%d\n", addUserResullt->result, addUserResullt->userID);
|
||||
|
||||
// char * output1;
|
||||
// output1 = malloc(50);
|
||||
// if (NULL == output1)
|
||||
// {
|
||||
// printf("ulist fail");
|
||||
// }
|
||||
|
||||
// char *testin = "{\"type\": 0,\"data\": {\"uname\": \"小明\",\"gname\": \"aaa08\"}}";
|
||||
// int *a = 1;
|
||||
// ret_code c = user_config_proc(1, 1, testin, 1, output1, a);
|
||||
|
||||
// printf("*******************************************************************************\n");
|
||||
// printf("这里是个测试第一次结果,新增用户:%d\n", c);
|
||||
// printf("%s\n", output1);
|
||||
// printf("*******************************************************************************\n");
|
||||
|
||||
|
||||
// char *testmodweb = "{\"type\":2, \"data\":{\"ID\": 2,\"GID\" : 4,\"uname\" : \"用户05\",\"gname\" : \"xxx\",\"passwd\" : \"zhelishimima123\" , \
|
||||
// \"udescription\" : \"修改用\",\"multi\" : 1,\"valid\" : 1,\"valid_begin_time\" : \"2013-07-04 15:04:23\",\"valid_end_time\" : \"2019-07-04 15:04:23\"}}";
|
||||
|
||||
// char * output2;
|
||||
// output2 = malloc(50);
|
||||
// if (NULL == output2)
|
||||
// {
|
||||
// printf("ulist fail");
|
||||
// }
|
||||
// ret_code cc = user_config_proc(1, 1, testmodweb, 1, output2, a);
|
||||
// printf("*******************************************************************************\n");
|
||||
// printf("这里是个测试第二次结果,修改用户web:%d\n", cc);
|
||||
// printf("%s\n", output2);
|
||||
// printf("*******************************************************************************\n");
|
||||
// UCHAR_FREE(output2);
|
||||
|
||||
// char *testmodline = "{\"type\":5, \"data\":{\"uname\": \"用户05\",\"attr_type\" : 6,\"attr_data\" : \"2018-03-03 15:04:23\"}}";
|
||||
// char * output3;
|
||||
// output3 = malloc(50);
|
||||
// if (NULL == output3)
|
||||
// {
|
||||
// printf("ulist fail");
|
||||
// }
|
||||
// ret_code ccc = user_config_proc(1, 1, testmodline, 1, output3, a);
|
||||
// printf("*******************************************************************************\n");
|
||||
// printf("这里是个测试第三次结果,修改用户-line:%d\n", ccc);
|
||||
// printf("%s\n", output3);
|
||||
// printf("*******************************************************************************\n");
|
||||
// UCHAR_FREE(output3);
|
||||
|
||||
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
extern USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
|
||||
void test(int a, int b, int c, int d)
|
||||
{
|
||||
long long e;
|
||||
a = sizeof(long long);
|
||||
b = sizeof(long);
|
||||
d = 3;
|
||||
return;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char * testrec;
|
||||
int testnum;
|
||||
userecover_config_get_all(CONFIG_FROM_RECOVER1,testrec, &testnum);
|
||||
printf("usermanager recover... \n");
|
||||
|
||||
char * testin; //input
|
||||
char testout[2000]; //output
|
||||
ret_code ret_pro; //执行结果
|
||||
int outlen = 1; //out数据长度
|
||||
|
||||
printf("\n************************************修改 group 描述*******************************************\n");
|
||||
testin = "{\"type\": 2,\"data\": {\"gid\": 1013,\"gdescription\": \"修改用户组的描述\"}}";
|
||||
ret_pro = usergroup_config_proc(1, 1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
test(1,2,3,4);
|
||||
printf("\n************************************查询 user list*******************************************\n");
|
||||
testin = "{\"type\": 4,\"data\":{\"group_id\": 0, \"user_name\": \"3\",\"page_start\": 1,\"page_counts\": 20}}";
|
||||
ret_pro = user_config_get(1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
printf("************************************新增 group*******************************************\n");
|
||||
testin = "{\"type\": 0,\"data\": {\"gname\": \"group011\",\"gdescription\": \"描述group011\"}}";
|
||||
ret_pro = usergroup_config_proc(1, 1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
printf("\n************************************删除 group*******************************************\n");
|
||||
testin = "{\"type\": 1,\"data\": {\"group_id\": 1021}}";
|
||||
ret_pro = usergroup_config_proc(1, 1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
printf("\n************************************新增 user*******************************************\n");
|
||||
testin = "{\"type\": 0,\"data\": {\"uname\": \"user011\",\"gname\": \"测试组01\"}}";
|
||||
ret_pro = user_config_proc(1, 1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
printf("\n************************************删除 user*******************************************\n");
|
||||
testin = "{\"type\": 1,\"data\":{\"user_id\": 11}}";
|
||||
ret_pro = user_config_proc(1, 1, testin, strlen(testin)+1, testout, &outlen);
|
||||
printf("执行结果:%d, 返回数据:%s .\n", ret_pro, testout);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main4(void)
|
||||
{
|
||||
USER_AUTH_RET user_ret;
|
||||
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
user_auth_login("user04", "A31as%4G", &user_ret);
|
||||
|
||||
|
||||
printf("%d,%d,%d\n", user_ret.ret, user_ret.user_id, user_ret.group_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main3(void)
|
||||
{
|
||||
char * testrec;
|
||||
int testnum;
|
||||
|
@ -440,7 +415,7 @@ outsize = strlen(output12);
|
|||
printf("增加一个用户组:%d\n", add_group("aaa12", "描述04"));
|
||||
|
||||
//USERGROUP U[22] = { 0 };
|
||||
int gsize = get_group_count();
|
||||
//int gsize = get_group_count();
|
||||
|
||||
// USERGROUP* U;
|
||||
// U = (USERGROUP*)malloc(sizeof(USERGROUP) * gsize);
|
||||
|
@ -496,7 +471,7 @@ outsize = strlen(output12);
|
|||
printf("增加一个用户组:%d\n", add_group("aaa26", "描述04"));
|
||||
|
||||
|
||||
gsize = get_group_count();
|
||||
//gsize = get_group_count();
|
||||
|
||||
// USERGROUP* U1;
|
||||
// U1 = (USERGROUP*)malloc(sizeof(USERGROUP) * gsize);
|
||||
|
@ -521,7 +496,7 @@ outsize = strlen(output12);
|
|||
{
|
||||
printf("shibaile");
|
||||
}
|
||||
find_group_by_name(name2, U2);
|
||||
//find_group_by_name(name2, U2);
|
||||
if (NULL != U2)
|
||||
{
|
||||
printf("%s, %d, %s, %s \n", name2, U2->ID, U2->gname, U2->gdescription);
|
||||
|
@ -610,11 +585,6 @@ outsize = strlen(output12);
|
|||
printf("ulist fail");
|
||||
}
|
||||
|
||||
unsigned short id1 = 2;
|
||||
get_user_by_id(id1, ulist);
|
||||
printf("查找id为:%d, 用户名:%s, 用户组ID:%d,用户组名:%s,描述:%s", id1, ulist->uname, ulist->GID, ulist->gname, ulist->udescription);
|
||||
printf(" ,多用户登陆:%d, 永久性:%d, 开始时间:%s, 结束时间:%s", ulist->multi, ulist->valid, ulist->valid_begin_time, ulist->valid_end_time);
|
||||
printf("密码:%s\n", ulist->passwd);
|
||||
|
||||
// USERLIST* ulist2;
|
||||
// ulist2 = (USERLIST*)malloc(sizeof(USERLIST));
|
||||
|
@ -658,13 +628,6 @@ outsize = strlen(output12);
|
|||
{
|
||||
printf("ulist fail");
|
||||
}
|
||||
// get_user_by_id(id1, ulist22);
|
||||
// printf("查找id为:%d, 用户名:%s, 用户组ID:%d,用户组名:%s,描述:%s", id1, ulist22->uname, ulist22->GID, ulist22->gname, ulist22->udescription);
|
||||
// printf(" ,多用户登陆:%d, 永久性:%d, 开始时间:%s, 结束时间:%s", ulist22->multi, ulist22->valid, ulist22->valid_begin_time, ulist22->valid_end_time);
|
||||
// printf("密码:%s\n", ulist22->passwd);
|
||||
|
||||
//printf("内存表中的时间:%lld,%lld, mul_avil:%d", g_user_table[2].valid_begin_time, g_user_table[2].valid_end_time, g_user_table[2].multi_valid);
|
||||
|
||||
|
||||
mod_user_line("用户06", 0, "testtest描述");
|
||||
mod_user_line("用户06", 1, "aaa12");
|
||||
|
@ -689,14 +652,6 @@ outsize = strlen(output12);
|
|||
printf("*******************************************************************************\n");
|
||||
|
||||
|
||||
// unsigned short id2 = 3;
|
||||
// get_user_by_id(id2, ulist22);
|
||||
// printf("查找id为:%d, 用户名:%s, 用户组ID:%d,用户组名:%s,描述:%s", id2, ulist22->uname, ulist22->GID, ulist22->gname, ulist22->udescription);
|
||||
// printf(" ,多用户登陆:%d, 永久性:%d, 开始时间:%s, 结束时间:%s", ulist22->multi, ulist22->valid, ulist22->valid_begin_time, ulist22->valid_end_time);
|
||||
// printf("密码:%s\n", ulist22->passwd);
|
||||
|
||||
// printf("*********************************************************************************\n");
|
||||
|
||||
char * output4;
|
||||
output4 = malloc(100);
|
||||
if (NULL == output4)
|
||||
|
|
|
@ -23,13 +23,14 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
|||
WEBM_HANDLE_LOGIN,
|
||||
WEBM_HANDLE_HOMEPAGE,
|
||||
|
||||
/* 以下是页面取数展示的case,后续提升性能可能通过数据库查询,所以先放到一起 */
|
||||
/* <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> */
|
||||
WEBM_HANDLE_CONFIG_LIST_GROUP,
|
||||
|
||||
/* 以下是配置操作相关的case */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>case */
|
||||
WEBM_HANDLE_CONFIG_ADD_GROUP,
|
||||
WEBM_HANDLE_CONFIG_UUID_GROUP,
|
||||
WEBM_HANDLE_CONFIG_MOD_GROUP,
|
||||
WEBM_HANDLE_CONFIG_DEL_GROUP,
|
||||
|
||||
WEBM_HANDLE_CONFIG_ADD_USER,
|
||||
WEBM_HANDLE_CONFIG_MODWEB_USER,
|
||||
|
@ -37,6 +38,8 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
|||
WEBM_HANDLE_CONFIG_LIST_USER,
|
||||
WEBM_HANDLE_CONFIG_UUID_USER,
|
||||
WEBM_HANDLE_CONFIG_DETAIL_USER,
|
||||
WEBM_HANDLE_CONFIG_DEL_USER,
|
||||
|
||||
WEBM_HANDLE_CONFIG_IPV4,
|
||||
WEBM_HANDLE_CONFIG_VLAN_SET,
|
||||
WEBM_HANDLE_CONFIG_VLAN_GET,
|
||||
|
@ -128,6 +131,15 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg
|
|||
USER_MANAGER_CONFIG_GROUP, \
|
||||
webm_config_send_proc \
|
||||
},\
|
||||
\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_DEL_GROUP, \
|
||||
"/FSG-CF/um-group-delete", \
|
||||
CM_CONFIG_SET, \
|
||||
USER_MANAGER_CONFIG_GROUP, \
|
||||
webm_config_send_proc \
|
||||
},\
|
||||
\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_ADD_USER, \
|
||||
"/FSG-CF/um-user-add", \
|
||||
|
@ -170,6 +182,13 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg
|
|||
USER_MANAGER_CONFIG_USER, \
|
||||
webm_config_send_proc \
|
||||
},\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_DEL_USER, \
|
||||
"/FSG-CF/um-user-delete", \
|
||||
CM_CONFIG_SET, \
|
||||
USER_MANAGER_CONFIG_USER, \
|
||||
webm_config_send_proc \
|
||||
},\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_IPV4, \
|
||||
"/ISG-CF/ipv4", \
|
||||
|
|
Loading…
Reference in New Issue