vcpe/srcs/user/user_info.c

66 lines
1.6 KiB
C
Raw Normal View History

2022-05-10 06:43:27 +00:00
//
// Created by xajhuang on 2022/5/11.
//
#include "user_info.h"
#include "user_errno.h"
static PUSER_INFO_LIST g_pUserList = NULL;
static USER_INFO g_userInfo[] = {
{0, 1, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x02}, "xajhuang", "aaaHuang1"},
{1, 2, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x03}, "xajhuang1", "aaaHuang1"},
{3, 4, {0x00, 0x0C, 0x01, 0x02, 0x00, 0x04}, "xajhuang2", "aaaHuang1"},
2022-05-10 06:43:27 +00:00
};
void user_info_init() {
user_info_add(0, &g_userInfo[0]);
user_info_add(1, &g_userInfo[1]);
user_info_add(2, &g_userInfo[2]);
2022-05-10 06:43:27 +00:00
}
int user_info_add(unsigned int userid, PUSER_INFO pInfo) {
if (pInfo) {
PUSER_INFO_LIST pList = (PUSER_INFO_LIST)malloc(sizeof(USER_INFO_LIST));
if (!pList) {
return ERR_MALLOC_MEMORY;
}
pList->userid = userid;
pList->user_info.qinq_tag1 = pInfo->qinq_tag1;
pList->user_info.qinq_tag2 = pInfo->qinq_tag2;
pList->user_info.pppoe_user = strdup(pInfo->pppoe_user);
pList->user_info.pppoe_passwd = strdup(pInfo->pppoe_passwd);
memcpy(pList->user_info.mac_addr, pInfo->mac_addr, 6);
HASH_ADD_INT(g_pUserList, userid, pList);
}
return ERR_OK;
}
void user_info_remove(unsigned int userid) {
PUSER_INFO_LIST pInfo;
HASH_FIND_INT(g_pUserList, &userid, pInfo);
if (pInfo) {
HASH_DEL(g_pUserList, pInfo);
}
}
PUSER_INFO user_info_get_by_userid(unsigned int userid) {
PUSER_INFO_LIST pInfo;
HASH_FIND_INT(g_pUserList, &userid, pInfo);
if (pInfo) {
return &pInfo->user_info;
}
return NULL;
}
PUSER_INFO_LIST user_info_getall() {
return g_pUserList;
}