2023-01-11 11:21:55 +08:00
|
|
|
#ifndef _SESSION_TABLE_H
|
|
|
|
|
#define _SESSION_TABLE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
#include "uthash.h"
|
|
|
|
|
#include "addr_tuple4.h"
|
|
|
|
|
|
|
|
|
|
// Note: session_addr must be initialized by memset(0) before use !!!
|
|
|
|
|
|
|
|
|
|
typedef void fn_free_cb(void *args);
|
|
|
|
|
|
|
|
|
|
struct session_node
|
|
|
|
|
{
|
|
|
|
|
uint64_t session_id; /* first key */
|
|
|
|
|
struct addr_tuple4 session_addr; /* second key */
|
|
|
|
|
|
2023-03-14 16:10:44 +08:00
|
|
|
void *value;
|
|
|
|
|
fn_free_cb *value_free_cb;
|
2023-01-11 11:21:55 +08:00
|
|
|
|
|
|
|
|
UT_hash_handle hh1; /* handle for first hash table */
|
|
|
|
|
UT_hash_handle hh2; /* handle for second hash table */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct session_table;
|
|
|
|
|
|
|
|
|
|
struct session_table *session_table_create();
|
|
|
|
|
void session_table_destory(struct session_table *table);
|
2023-02-17 17:45:39 +08:00
|
|
|
void session_table_reset(struct session_table *table);
|
2023-01-11 11:21:55 +08:00
|
|
|
uint64_t session_table_count(struct session_table *table);
|
|
|
|
|
|
|
|
|
|
// session_addr : deep copy
|
2023-03-14 16:10:44 +08:00
|
|
|
// value : shallow copy (malloc by user, free by value_free_cb)
|
2023-01-11 11:21:55 +08:00
|
|
|
// return 0 : suceess
|
|
|
|
|
// return -1 : key exists
|
2023-03-14 16:10:44 +08:00
|
|
|
int session_table_insert(struct session_table *table, uint64_t session_id, const struct addr_tuple4 *session_addr, void *value, const fn_free_cb *value_free_cb);
|
2023-01-11 11:21:55 +08:00
|
|
|
|
|
|
|
|
// return 0 : success
|
|
|
|
|
// return -1 : key not exists
|
|
|
|
|
int session_table_delete_by_id(struct session_table *table, uint64_t session_id);
|
|
|
|
|
int session_table_delete_by_addr(struct session_table *table, const struct addr_tuple4 *session_addr);
|
|
|
|
|
|
|
|
|
|
// return NULL : key not exists
|
|
|
|
|
// return UnNULL : success
|
|
|
|
|
struct session_node *session_table_search_by_id(struct session_table *table, uint64_t session_id);
|
|
|
|
|
struct session_node *session_table_search_by_addr(struct session_table *table, const struct addr_tuple4 *session_addr);
|
|
|
|
|
|
|
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|