690 lines
25 KiB
C
690 lines
25 KiB
C
#include <stdio.h>
|
||
#include <time.h>
|
||
#include <stdlib.h>
|
||
#include <unistd.h>
|
||
#include <cjson/cJSON.h>
|
||
#include "common_user.h"
|
||
#include "array_index.h"
|
||
#include "user_group.h"
|
||
#include "user.h"
|
||
#include "user_account_config.h"
|
||
#include "user_group_config.h"
|
||
#include "user_auth.h"
|
||
#include "database.h"
|
||
#include "redisMq.h"
|
||
|
||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||
extern USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||
|
||
// 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;
|
||
// }
|
||
|
||
|
||
void offline_force(char *userid)
|
||
{
|
||
bool ret = redisPubInit();
|
||
if (!ret)
|
||
{
|
||
printf("Init failed.\n");
|
||
return;
|
||
}
|
||
|
||
ret = redisPubConnect();
|
||
if (!ret)
|
||
{
|
||
printf("connect failed.");
|
||
return;
|
||
}
|
||
|
||
// while (true)
|
||
// {
|
||
// redisPublish(OFFLINE_USER_BY_UID, userid);
|
||
// sleep(1);
|
||
// }
|
||
redisPublish(OFFLINE_USER_BY_UID, userid);
|
||
//sleep(1);
|
||
redisPubDisconnect();
|
||
redisPubUninit();
|
||
return;
|
||
}
|
||
|
||
int main1(void)
|
||
{
|
||
|
||
offline_force("111");
|
||
offline_force("222");
|
||
offline_force("333");
|
||
return 0;
|
||
}
|
||
|
||
void test_func_recv(struct RecvMsg_t *mmsg)
|
||
{
|
||
if (mmsg->msg)
|
||
{
|
||
printf("%s,%d,%llu,%s,%d\n", __FUNCTION__, __LINE__, pthread_self(), mmsg->msg, mmsg->len);
|
||
freeMsg(mmsg);
|
||
}
|
||
}
|
||
|
||
|
||
void sub_example()
|
||
{
|
||
bool ret = redisSubInit(8);
|
||
if (!ret)
|
||
{
|
||
printf("Init failed.\n");
|
||
return;
|
||
}
|
||
redisRegisterChannelFunc("offuser_by_userid_channel",test_func_recv);
|
||
|
||
|
||
ret = redisSubConnect();
|
||
if (!ret)
|
||
{
|
||
printf("Connect failed.\n");
|
||
return;
|
||
}
|
||
redisSubscriber("offuser_by_userid_channel");
|
||
|
||
while (true)
|
||
{
|
||
sleep(1);
|
||
}
|
||
|
||
redisSubDisconnect();
|
||
redisSubUninit();
|
||
|
||
return;
|
||
|
||
}
|
||
|
||
int main(void)
|
||
{
|
||
|
||
// int ID = 1;
|
||
// int GID_temp = 2;
|
||
// char *uname = "xiaoming";
|
||
// char *udesp = "";
|
||
// int multi = 0;
|
||
// int valid = 0;
|
||
// char *valid_begin_time = "";
|
||
// char *valid_end_time = "";
|
||
// void *adduser_hdbc = connect_database(USER_ACCOUNT_DATABASE_ID);
|
||
// if(NULL == adduser_hdbc)
|
||
// {
|
||
// printf("aaaaaaaaa");
|
||
// }
|
||
// 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_ACCOUNT_DATABASE_ID, adduser_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_STRING_TYPE, strlen(uname)+1, uname,
|
||
// DB_DATA_STRING_TYPE, 9, "12345678",
|
||
// DB_DATA_STRING_TYPE, strlen(udesp)+1, udesp,
|
||
// DB_DATA_INT_TYPE, sizeof(multi), multi,
|
||
// DB_DATA_INT_TYPE, sizeof(valid), valid,
|
||
// DB_DATA_STRING_TYPE, strlen(valid_begin_time)+1, valid_begin_time,
|
||
// DB_DATA_STRING_TYPE, strlen(valid_end_time)+1,valid_end_time);
|
||
// printf("ret_adduser = %d .\n",ret_adduser);
|
||
// return 0;
|
||
|
||
printf("初始化用户组:%d\n", init_group());
|
||
|
||
printf("增加一个用户组:%d\n", add_group("", ""));
|
||
printf("增加一个用户组:%d\n", add_group("aaa01", "描述02"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa03", "描述03"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa,", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("", "描述04"));
|
||
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"));
|
||
|
||
//USERGROUP U[22] = { 0 };
|
||
int gsize = get_group_count();
|
||
|
||
USERGROUP* U;
|
||
U = (USERGROUP*)malloc(sizeof(USERGROUP) * gsize);
|
||
if (NULL == U)
|
||
{
|
||
printf("shibaile");
|
||
}
|
||
|
||
show_group_list(U);
|
||
for (int i = 0; i < gsize; i++)
|
||
{
|
||
printf("第 %d 用户组 ID : %d, NAME: %s, 描述:%s \n", i, U[i].ID, U[i].gname, U[i].gdescription);
|
||
}
|
||
|
||
// char* name1 = { "aaa18" };
|
||
// printf("删除一个组:%s, %d\n", name1, del_group_by_name(name1));
|
||
// printf("删除一个组:%s, %d\n", "aaa03", del_group_by_name("aaa03"));
|
||
// printf("删除一个组:%s, %d\n", "aaaa03", del_group_by_name("aaaa03"));
|
||
|
||
printf("增加一个用户组:%d\n", add_group("aaa30", "就爱看九分阿道夫就卡了阿道夫阿道夫就"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa31", "描述31"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa32", "描述31"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa13", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa14", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa15", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa16", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa17", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa18", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa18", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa20", "描述04"));
|
||
//printf("增加一个用户组:%d\n", add_group("aaa21", "描述04"));
|
||
|
||
char *testgroupin = "{\"type\": 0,\"data\": {\"gname\": \"aaa21\",\"gdescription\": \"xxx\"}}";
|
||
char * outputgroup;
|
||
outputgroup = malloc(130);
|
||
if (NULL == outputgroup)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
int olenth_01 = 1;
|
||
int *olenth = &olenth_01;
|
||
ret_code ret_add_group = usergroup_config_proc(1,1,testgroupin,1,outputgroup,olenth);
|
||
printf("测试对外接口-增加一个用户组:%d\n", ret_add_group);
|
||
printf("%s \n", outputgroup);
|
||
UCHAR_FREE(outputgroup);
|
||
|
||
printf("增加一个用户组:%d\n", add_group("aaa22", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa23", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa20", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa20", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa24", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa25", "描述04"));
|
||
printf("增加一个用户组:%d\n", add_group("aaa26", "描述04"));
|
||
|
||
|
||
gsize = get_group_count();
|
||
|
||
USERGROUP* U1;
|
||
U1 = (USERGROUP*)malloc(sizeof(USERGROUP) * gsize);
|
||
if (NULL == U1)
|
||
{
|
||
printf("shibaile");
|
||
}
|
||
|
||
show_group_list(U1);
|
||
for (int i = 0; i < gsize; i++)
|
||
{
|
||
printf("第 %d 用户组 ID : %d, NAME: %s, 描述:%s \n", i, U1[i].ID, U1[i].gname, U1[i].gdescription);
|
||
}
|
||
|
||
|
||
|
||
|
||
char* name2 = { "aaa10" };
|
||
USERGROUP* U2;
|
||
U2 = (USERGROUP*)malloc(sizeof(USERGROUP));
|
||
if (NULL == U2)
|
||
{
|
||
printf("shibaile");
|
||
}
|
||
find_group_by_name(name2, U2);
|
||
if (NULL != U2)
|
||
{
|
||
printf("%s, %d, %s, %s \n", name2, U2->ID, U2->gname, U2->gdescription);
|
||
}
|
||
|
||
printf("*************************************\n");
|
||
|
||
|
||
printf("初始化用户:%d\n", init_user());
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
printf("初始化后的第 %d 个用户,ID:%d, PWD:%s \n", i, g_user_table[i].ID, g_user_table[i].passwd);
|
||
}
|
||
|
||
USERADD* addUserResullt;
|
||
addUserResullt = (USERADD*)malloc(sizeof(USERADD));
|
||
printf("sizeof(USERADD): %d\n",sizeof(USERADD));
|
||
memset(addUserResullt, 0, sizeof(USERADD));
|
||
|
||
if (NULL == addUserResullt)
|
||
{
|
||
printf("shibaile");
|
||
}
|
||
|
||
usermanager_add_user("用户01", "aaa04", "hello", 0, 0, NULL, NULL,addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
//addUserResullt = AddUser("用户02", "aaa04", NULL);
|
||
//printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user(NULL, "aaa04", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("", "aaa04", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户04,", "aaa04", NULL,0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户05", "aCaa04", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户01", "aaa04", NULL, 0, 0, NULL, NULL,addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户04", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户05", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户06", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户07", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户08", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
usermanager_add_user("用户09", "aaa07", NULL, 0, 0, NULL, NULL, addUserResullt);
|
||
printf("%d,%d\n", addUserResullt->result, addUserResullt->userID);
|
||
|
||
|
||
|
||
char * output1;
|
||
output1 = malloc(40);
|
||
if (NULL == output1)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
|
||
char *testin = "{\"type\": 0,\"data\": {\"uname\": \"小明\",\"gname\": \"aaa14\"}}";
|
||
int a_01 = 1;
|
||
int *a = &a_01;
|
||
ret_code c = user_config_proc(1, 1, testin, 1, output1, a);
|
||
|
||
printf("*******************************************************************************\n");
|
||
printf("这里是个测试第一次结果,新增用户:%d\n", c);
|
||
printf("%s\n", output1);
|
||
printf("*******************************************************************************\n");
|
||
UCHAR_FREE(output1);
|
||
|
||
for (int i = 0; i < USER_INDEX_MAX; i++)
|
||
{
|
||
if (g_user_table[i].ID != 0)
|
||
{
|
||
printf("tianjia后的第 %d 个用户, ID:%d, GID:%d, 用户名:%s, PWD:%s \n", i, g_user_table[i].ID, g_user_table[i].GID, g_user_table[i].uname, g_user_table[i].passwd);
|
||
}
|
||
}
|
||
|
||
printf("*****************************************************\n");
|
||
|
||
USERLIST* ulist;
|
||
ulist = (USERLIST*)malloc(sizeof(USERLIST));
|
||
if (NULL == ulist)
|
||
{
|
||
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));
|
||
// if (NULL == ulist2)
|
||
// {
|
||
// printf("ulist fail");
|
||
// }
|
||
|
||
// ulist2->ID = 2;
|
||
// ulist2->GID = 4;
|
||
// strcpy(ulist2->udescription, "修改用");
|
||
// strcpy(ulist2->passwd, "zhelishimima123");
|
||
// ulist2->multi = 1;
|
||
// ulist2->valid = 1;
|
||
// strcpy(ulist2->valid_begin_time, "2013-07-04 15:04:23");
|
||
// strcpy(ulist2->valid_end_time, "2019-07-04 15:04:23");
|
||
|
||
|
||
// printf("%d\n", mod_user_web(ulist2));
|
||
|
||
char *testmodweb = "{\"type\":2, \"data\":{\"ID\": 3,\"GID\" : 5,\"uname\" : \"用户05\",\"gname\" : \"aaa07\", \"resetpwd\" : 1,\
|
||
\"udescription\" : \"修改用\",\"multi\" : 1,\"valid\" : 1,\"valid_begin_time\" : \"2013-07-04 15:04:23\",\"valid_end_time\" : \"2019-10-04 15:04:23\"}}";
|
||
|
||
char * output2;
|
||
output2 = malloc(50);
|
||
if (NULL == output2)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
//printf("123 .\n");
|
||
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);
|
||
|
||
USERLIST* ulist22;
|
||
ulist22 = (USERLIST*)malloc(sizeof(USERLIST));
|
||
if (NULL == ulist22)
|
||
{
|
||
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");
|
||
mod_user_line("用户06", 2, "zhelishidenglumima");
|
||
mod_user_line("用户05", 3, "1");
|
||
mod_user_line("用户06", 4, "1");
|
||
mod_user_line("用户06", 5, "2013-03-03 15:04:23");
|
||
mod_user_line("用户05", 6, "2018-03-03 15:04:23");
|
||
mod_user_line("用户05", 7, "2020-03-03 15:04:23");
|
||
char *testmodline = "{\"type\":5, \"data\":{\"uname\": \"用户06\",\"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);
|
||
|
||
// 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)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
|
||
char *testin4 = "{\"type\": 1,\"data\":[\"用户01\", \"用户02\", \"用户04\"]}";
|
||
int a4_01 = 1;
|
||
int *a4 = &a4_01;;
|
||
ret_code c4 = user_config_proc(1, 1, testin4, 1, output4, a4);
|
||
|
||
printf("*******************************************************************************\n");
|
||
printf("这里是个测试第四次结果,删除用户:%d\n", c4);
|
||
printf("%s\n", output4);
|
||
printf("*******************************************************************************\n");
|
||
UCHAR_FREE(output4);
|
||
|
||
|
||
char * output5;
|
||
output5 = malloc(100);
|
||
if (NULL == output5)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
|
||
char *testin5 = "{\"type\": 1,\"data\":[\"aaa\", \"aaa07\", \"aaa08\"]}";
|
||
int a5_01 = 1;
|
||
int *a5 = &a5_01;
|
||
ret_code c5 = usergroup_config_proc(1, 1, testin5, 1, output5, a5);
|
||
|
||
printf("*******************************************************************************\n");
|
||
printf("这里是个测试第五次结果,删除用户组:%d\n", c5);
|
||
printf("%s\n", output5);
|
||
printf("*******************************************************************************\n");
|
||
UCHAR_FREE(output5);
|
||
|
||
USER_AUTH_RET *aret;
|
||
aret = (USER_AUTH_RET*)malloc(sizeof(USER_AUTH_RET));
|
||
if (NULL == aret)
|
||
{
|
||
printf("111111111111");
|
||
}
|
||
time_t t1 = time(NULL);
|
||
|
||
user_auth_login("用户07", "12345678", aret);
|
||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||
|
||
sleep(1);
|
||
t1 = time(NULL);
|
||
USER_AUTH_RET aret01;
|
||
user_auth_login("用户05", "zhelishidenglumima", &aret01);
|
||
printf("%d,%d,%d\n", aret01.ret, aret01.user_id, aret01.group_id);
|
||
|
||
// sleep(1);
|
||
// t1 = time(NULL);
|
||
// user_auth_login("用户05", "zhelishidenglumima", aret);
|
||
// printf("%d,%d,%d\n",aret->ret,aret->user_id,aret->group_id);
|
||
|
||
// sleep(1);
|
||
// t1 = time(NULL);
|
||
// user_auth_login("用户05", "zhelishidenglumima", aret);
|
||
// printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||
|
||
// sleep(1);
|
||
// t1 = time(NULL);
|
||
// user_auth_login("用户05", "zhelishidenglumima", aret);
|
||
// printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||
|
||
// sleep(1);
|
||
// t1 = time(NULL);
|
||
// user_auth_login("用户05", "zhelishidenglumima", aret);
|
||
// printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||
|
||
// mod_user_line("用户05", 6, "2020-03-03 15:04:23");
|
||
// sleep(1);
|
||
// t1 = time(NULL);
|
||
// user_auth_login("用户05", "zhelishidenglumima", aret);
|
||
// printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||
|
||
|
||
char * output6;
|
||
output6 = malloc(100);
|
||
if (NULL == output6)
|
||
{
|
||
printf("ulist fail");
|
||
}
|
||
char *testin6 = "{\"type\": 1,\"data\":[\"用户01\", \"用户02\", \"用户04\", \"用户05\"]}";
|
||
int a6_01 = 1;
|
||
int *a6 = &a6_01;;
|
||
ret_code c6 = user_config_proc(1, 1, testin6, 1, output6, a6);
|
||
|
||
printf("*******************************************************************************\n");
|
||
printf("这里是个测试第六次结果,删除用户05:%d\n", c4);
|
||
printf("%s\n", output6);
|
||
printf("*******************************************************************************\n");
|
||
UCHAR_FREE(output6);
|
||
|
||
int user_ids[3] = {1,2,4};
|
||
reset_online_by_userid(user_ids, 3);
|
||
|
||
void * test_hdbc;
|
||
|
||
/* 连接数据库 */
|
||
test_hdbc = connect_database(12);
|
||
if(NULL == test_hdbc)
|
||
{
|
||
printf("fall connnect database. \n");
|
||
return -1;
|
||
}
|
||
|
||
int num_sql;
|
||
int ret;
|
||
char * ret_sql = NULL;
|
||
char * select_sql = "SELECT U.uid, U.id FROM `user_group` U WHERE id > ?";
|
||
ret_sql = select_datebase_by_number(1, test_hdbc, "user_group", select_sql, 1, 20, &num_sql, 1,
|
||
DB_DATA_INT_TYPE, 8, 2);
|
||
|
||
printf("num_sql = %d \n", num_sql);
|
||
printf("test_hdbc = %s \n", test_hdbc);
|
||
//printf("ret_sql = %s \n",ret_sql);
|
||
|
||
/* 创建table, 其中列类型包括长整形、浮点型、字符串 */
|
||
//ret = create_database_table(1, test_hdbc, "ctest", "create table ctest ( id bigint, fl double, dt character(10), status character(7))");
|
||
|
||
/* 根据指定信息查询数据库的获取的结果的条目数 */
|
||
ret = get_select_datebase_number(1, test_hdbc, "ctest", "select * from ctest where id = '911231233333333337'", &num_sql, 0);
|
||
printf("num_sql = %d \n", num_sql);
|
||
printf("ret = %d \n", ret);
|
||
|
||
int num;
|
||
char * retptr = NULL;
|
||
retptr = select_datebase_by_number(1, test_hdbc, "user_group", " SELECT UG.id FROM user_group UG WHERE UG.gname = '用户组01'", 1, 0, &num, 0);
|
||
printf("user_group = %s\n", retptr);
|
||
|
||
retptr = select_datebase_by_number(1, test_hdbc, "user_account", " SELECT * FROM user_account WHERE id = 4", 1, 0, &num, 0);
|
||
printf("user_group = %s\n", retptr);
|
||
|
||
char *usergrouname = "test17";
|
||
num = update_database(1, test_hdbc, DB_OP_INSERT, "user_group", "INSERT INTO user_group SET id = ?, gname = ? ", 2,
|
||
DB_DATA_INT_TYPE, 4, 26,
|
||
DB_DATA_STRING_TYPE, strlen(usergrouname), usergrouname);
|
||
printf("insert user_group ret = %d \n", num);
|
||
|
||
num = update_database(1, test_hdbc, DB_OP_DEL, "user_group", "DELETE FROM user_group WHERE gname = ? ", 1,
|
||
DB_DATA_STRING_TYPE, 10, "用户组03");
|
||
printf("delete user_group ret = %d \n", num);
|
||
|
||
num = update_database(1, test_hdbc, DB_OP_UPDATE, "user_group", "UPDATE user_group SET gdescription = ? WHERE gname = ? ", 2,
|
||
DB_DATA_STRING_TYPE, 10, "z111111111111111111",
|
||
DB_DATA_STRING_TYPE, 10, "test04");
|
||
printf("update user_group ret = %d \n", num);
|
||
|
||
// num = update_database(1, test_hdbc, 1, "user_account",
|
||
// "INSERT INTO user_account SET id = ?, group_id = ?, user_name = ?", 3,
|
||
// DB_DATA_INT_TYPE, 4, 9,
|
||
// DB_DATA_INT_TYPE, 4, 3,
|
||
// DB_DATA_STRING_TYPE, 10, "test01");
|
||
// printf("insert user01 ret = %d \n", num);
|
||
|
||
// num = update_database(1, test_hdbc, 1, "user_account",
|
||
// "INSERT INTO user_account SET id = 8, group_id = 12, user_name = 'test02' ", 0);
|
||
// printf("insert user02 ret = %d \n", num);
|
||
|
||
// num = update_database(1, test_hdbc, 1, "user_group",
|
||
// "INSERT INTO user_group SET id = ?, gname = ?", 2,
|
||
// DB_DATA_INT_TYPE, 4, 10,
|
||
// DB_DATA_STRING_TYPE, 10, "test04");
|
||
// printf("insert user_group ret = %d \n", num);
|
||
|
||
// ret = update_database(1, test_hdbc, 1, "ctest", "insert into ctest values(?, ?, ?, '30' )", 3,
|
||
// DB_DATA_INT_TYPE, 4, 91123123333333333,
|
||
// DB_DATA_FLOAT_TYPE, 8, 11111111.555555555,
|
||
// DB_DATA_STRING_TYPE, 4, "TEMP");
|
||
// printf("insert ret = %d \n", ret);
|
||
|
||
|
||
|
||
ret = disconnect_database(1, test_hdbc);
|
||
|
||
return 0;
|
||
}
|
||
|