diff --git a/Product/build/user.web-auth.Makefile b/Product/build/user.web-auth.Makefile index e5ef623ad..4f422bb95 100644 --- a/Product/build/user.web-auth.Makefile +++ b/Product/build/user.web-auth.Makefile @@ -21,13 +21,13 @@ DEBUG = TRUE PLAT_LINUX ?= TRUE PLAT_ARM64 ?= FALSE -VPATH = ../user/user_auth +VPATH = ../user/user_auth ../user/user_manager/usermanager-auth # source code # set the source file, don't used .o because of ... -COMMON_SRCS = web_auth.c user_hashtable.c +COMMON_SRCS = web_auth.c user_hashtable.c user_auth.c # MRS Board Source Files PLAT_LINUX_SRCS = $(COMMON_SRCS) diff --git a/Product/common/user_hashtable.c b/Product/common/user_hashtable.c deleted file mode 100644 index a76226ca1..000000000 --- a/Product/common/user_hashtable.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "hlist.h" -#include "user_hashtable.h" - -struct hlist_head *hash; -struct hlist_node *p = NULL, *n = NULL ; -int i = 0; -USER_INFO *pNode ; - -/*计算hash值 */ -struct hlist_head *call_hash(struct hlist_head *hash, uint32_t ip) -{ - unsigned int val = ip % 100; - return &hash[val]; -} - -/*初始化函数 */ -int Init_hash() -{ - hash = (struct hlist_head*)malloc(sizeof(*hash)*100); - if(NULL == hash) - { - printf("alloc error\n"); - return -1; - } - - for(i = 0; i < 100; i++) - INIT_HLIST_HEAD(&hash[i]); -} - - -/*查找用户信息*/ -struct user_info *ufind_user(uint32_t user_ip) -{ - hlist_for_each_safe(p,n,call_hash(hash,user_ip)) - { - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - printf("user_id :%d\n",pNode->id); - return pNode; - } -} - -/*增加用户信息*/ -int uadd_user(uint32_t user_ip, int user_id) -{ - USER_INFO *pNode =NULL; - hlist_for_each_safe(p,n,call_hash(hash, user_ip)) /*查找ip是否存在hash表中 */ - { - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - printf("IP ALEADY EXISTED\n"); - } - - if (pNode == NULL) - { - pNode = (struct user_info *)malloc(sizeof(struct user_info)); - if (NULL == pNode) - { - return -1; - } - memset(pNode,0,sizeof(struct user_info)); - INIT_HLIST_NODE(&pNode->hnode); - pNode->ip = user_ip; - hlist_add_head(&pNode->hnode, call_hash(hash, user_ip)); - } - pNode->id = user_id; - -} - -/*删除用户信息 */ -void udelete_user(int user_ip) -{ - hlist_for_each_safe(p,n,call_hash(hash,user_ip)) - { - pNode = hlist_entry(p, struct user_info ,hnode); - hlist_del(&pNode->hnode); - free(pNode); - } -} - -/*删除所有的hash节点 */ -void udelete_all() -{ - for(i = 0; i < 100; i++) - { - hlist_for_each_safe(p,n,&hash[i]) - { - pNode = hlist_entry(p, struct user_info ,hnode); - hlist_del(&pNode->hnode); - free(pNode); - } - } -} - -/*打印所有信息信息 */ -void uprintf_users() -{ - for(i = 0; i < 100; i++) - { - hlist_for_each_safe(p,n,&hash[i]) - { - char str[32]; - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - inet_ntop(AF_INET, (void *)&pNode->ip, str, 32); - printf("user_ip :%s user_id:%d\n", str, pNode->id); - } - } -} - diff --git a/Product/user/user_auth/user_hashtable.c b/Product/user/user_auth/user_hashtable.c index c6b7f6660..97626ed30 100644 --- a/Product/user/user_auth/user_hashtable.c +++ b/Product/user/user_auth/user_hashtable.c @@ -6,6 +6,10 @@ #include #include "hlist.h" #include "user_hashtable.h" +#include "user_auth.h" + + +extern USER_AUTH_LIST g_user_auth_ret_table[] ; /*链表全局变量 */ struct hlist_head *hash; @@ -122,11 +126,19 @@ void udelete_user(int user_ip) struct hlist_node *p = NULL, *n = NULL ; int i = 0; + unsigned short check_id; hlist_for_each_safe(p,n,call_hash(hash,user_ip)) { pNode = hlist_entry(p, struct user_info ,hnode); - hlist_del(&pNode->hnode); + + /*查找用户ID,确认ID是否存在 */ + check_id = g_user_auth_ret_table[pNode->id].group_id; + if(check_id != NULL) + { + hlist_del(&pNode->hnode); + } + free(pNode); } } diff --git a/Product/user/user_auth/web_auth.c b/Product/user/user_auth/web_auth.c index b65a2b461..82b19946e 100644 --- a/Product/user/user_auth/web_auth.c +++ b/Product/user/user_auth/web_auth.c @@ -77,15 +77,19 @@ ret_code user_auth(pointer content, RESULT *uresult) if (resultinfo->ret == 0) { printf("认证成功\n"); + uint32_t client_ip=10001; /*解析报文拿到用户IP */ + printf("client_ip :%d\n", client_ip); + Init_hash(); /*初始化hash表放在配置恢复处 */ + + /*重定向到认证成功界面-调用web server提供的接口,发送url地址给接口,实现重定向 */ - /*客户端访问认证成功界面时,方法是GET,从HTTP GET报文中获取client 源IP地址 */ + /*客户端访问认证成功界面方法:GET */ char method[10] = {"GET"}; - uint32_t client_ip = 10879032751328; - /*如果method是GET 判断这个用户是否认证过*/ + /*如果method是GET,判断这个用户是否认证过*/ if(0 == strncmp(method, "GET",10)) { struct user_info * uinfo; @@ -97,9 +101,7 @@ ret_code user_auth(pointer content, RESULT *uresult) return ret; } - /*判断用户是否认证过,用户认证过则跳出语句,不访问认证成功界面 */ - printf("client_ip :%d\n", client_ip); - Init_hash(); + /*用户认证过则跳出语句,不访问认证成功界面 */ uinfo = ufind_user(client_ip); if ( NULL != uinfo ) @@ -111,11 +113,15 @@ ret_code user_auth(pointer content, RESULT *uresult) return ret ; } + uadd_user(client_ip,resultinfo->user_id); + uprintf_users(); + uresult->resultcode = resultinfo->ret; uresult->remain_lock_time = time; uresult->message = mes[resultinfo->ret]; printf("resultcode:%d remain_lock_time:%d message:%s\n",uresult->resultcode, uresult->remain_lock_time, uresult->message ); + free(uinfo); cJSON_Delete(cjson); @@ -162,5 +168,3 @@ ret_code user_auth(pointer content, RESULT *uresult) - -