Mod aaa-12 删除之前写的用户认证监测表增删改查功能
RCA: SOL: 修改人:chenling 检视人:
This commit is contained in:
parent
28b11c3ba1
commit
aef1b985ea
|
@ -1,62 +0,0 @@
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "u-hashtable.h"
|
|
||||||
|
|
||||||
/*initialize */
|
|
||||||
USER_STRUCT *users = NULL;
|
|
||||||
|
|
||||||
/*add user information */
|
|
||||||
void uadd_user(uint32_t user_ip, USER user_info)
|
|
||||||
{
|
|
||||||
USER_STRUCT *s ;
|
|
||||||
HASH_FIND_INT(users, &user_ip, s); /*ip already in the hash? */
|
|
||||||
if(s == NULL)
|
|
||||||
{
|
|
||||||
s = (struct user_struct *)malloc(sizeof *s);
|
|
||||||
s->ip = user_ip;
|
|
||||||
HASH_ADD_INT(users, ip, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->info = user_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*find user information */
|
|
||||||
USER_STRUCT *ufind_user(uint32_t user_ip)
|
|
||||||
{
|
|
||||||
USER_STRUCT *s;
|
|
||||||
HASH_FIND_INT(users, &user_ip, s);
|
|
||||||
printf("user_nams: %s user_id:%d usergroud_id:%d\n", s->info.name, s->info.user_id, s->info.usergroud_id);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*delete user information */
|
|
||||||
void udelete_user(USER_STRUCT *user)
|
|
||||||
{
|
|
||||||
HASH_DEL(users, user); /* user: pointer to delete */
|
|
||||||
free(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*delect all uesr'informations */
|
|
||||||
void udelete_all()
|
|
||||||
{
|
|
||||||
USER_STRUCT *current_user, *tmp;
|
|
||||||
HASH_ITER(hh, users, current_user, tmp)
|
|
||||||
{
|
|
||||||
HASH_DEL(users,current_user); /* delete; users advances to next */
|
|
||||||
free(current_user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*printf user information */
|
|
||||||
void uprint_users()
|
|
||||||
{
|
|
||||||
USER_STRUCT *s;
|
|
||||||
char str[32];
|
|
||||||
for(s=users; s != NULL; s=(USER_STRUCT *)(s->hh.next))
|
|
||||||
{
|
|
||||||
inet_ntop(AF_INET, (void *)&s->ip, str, 32);
|
|
||||||
printf(" user_ip: %s user_nams: %s user_id:%d usergroud_id:%d\n", str, s->info.name, s->info.user_id, s->info.usergroud_id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
#ifndef U_HASHTABLE_H
|
|
||||||
#define U_HASHTABLE_H
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "uthash.h"
|
|
||||||
|
|
||||||
typedef struct user_info
|
|
||||||
{
|
|
||||||
char name[32]; /*用户名 */
|
|
||||||
int user_id; /*用户ID */
|
|
||||||
int usergroud_id; /*用户组ID */
|
|
||||||
uint64_t message_num; /*下行报文数 */
|
|
||||||
uint64_t byte_num; /*下行字节数*/
|
|
||||||
time_t online_time; /*在线时间 */
|
|
||||||
}USER;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct user_struct
|
|
||||||
{
|
|
||||||
uint32_t ip; /*用户IP key*/
|
|
||||||
USER info; /*用户信息 */
|
|
||||||
UT_hash_handle hh;
|
|
||||||
}USER_STRUCT;
|
|
||||||
|
|
||||||
/*add user information */
|
|
||||||
void uadd_user(uint32_t user_ip, USER user_info);
|
|
||||||
|
|
||||||
/*find user information */
|
|
||||||
USER_STRUCT *ufind_user(uint32_t user_ip);
|
|
||||||
|
|
||||||
/*delete user information */
|
|
||||||
void udelete_user(USER_STRUCT *user);
|
|
||||||
|
|
||||||
/*delect all uesr'informations */
|
|
||||||
void udelete_all();
|
|
||||||
|
|
||||||
/*printf user information */
|
|
||||||
void uprint_users();
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue