Implementation of the users table and a generic hashtable mechanism

This commit is contained in:
Mark Riddoch
2013-06-24 11:35:40 +02:00
parent b9e079ce17
commit 69de408d8a
6 changed files with 302 additions and 15 deletions

View File

@ -38,25 +38,38 @@
* The next pointer is the overflow chain for this hashentry.
*/
typedef struct hashentry {
void *key; /**< The value of the key or NULL if empty entry */
void *value; /**< The value associated with key */
struct hashentry *next; /**< The overflow chain */
void *key; /**< The value of the key or NULL if empty entry */
void *value; /**< The value associated with key */
struct hashentry *next; /**< The overflow chain */
} HASHENTRIES;
/**
* The type definition for the memory allocation functions
*/
typedef void *(*HASHMEMORYFN)(void *);
/**
* The general purpose hashtable struct.
*/
typedef struct hashtable {
int hashsize; /**< The number of HASHENTRIES */
HASHENTRIES *entries; /**< The entries themselves */
HASHENTRIES **entries; /**< The entries themselves */
int (*hashfn)(void *); /**< The hash function */
int (*cmpfn)(void *, void *); /**< The key comparison function */
HASHMEMORYFN copyfn; /**< Optional copy function */
HASHMEMORYFN freefn; /**< Optional free function */
} HASHTABLE;
extern HASHTABLE *hashtable_alloc(int, int (*hashfn)(),
int (*cmpfn)()); /**< Allocate a hashtable */
extern HASHTABLE *hashtable_alloc(int, int (*hashfn)(), int (*cmpfn)());
/**< Allocate a hashtable */
extern void hashtable_memory_fns(HASHTABLE *, HASHMEMORYFN, HASHMEMORYFN);
/**< Provide an interface to control key/value memory
* manipulation
*/
extern void hashtable_free(HASHTABLE *); /**< Free a hashtable */
extern int hashtable_add(HASHTABLE *, char *, void *); /**< Add an entry */
extern int hashtable_delete(HASHTABLE *, char *); /**< Delete an entry table */
extern void *hashtable_fetch(HASHTABLE *, char *); /**< Fetch the data for a given key */
extern int hashtable_add(HASHTABLE *, void *, void *); /**< Add an entry */
extern int hashtable_delete(HASHTABLE *, void *);
/**< Delete an entry table */
extern void *hashtable_fetch(HASHTABLE *, void *);
/**< Fetch the data for a given key */
#endif

View File

@ -31,12 +31,26 @@
* @endverbatim
*/
/**
* The users table statistics structure
*/
typedef struct {
int n_entries; /**< The number of entries */
int n_adds; /**< The number of inserts */
int n_deletes; /**< The number of deletes */
int n_fetches; /**< The number of fetchs */
} USERS_STATS;
/**
* The user table, this contains the username and authentication data required
* for the authentication implementation within the gateway.
*/
typedef struct users {
HASHTABLE *data;
HASHTABLE *data; /**< The hashtable containing the actual data */
USERS_STATS stats; /**< The statistics for the users table */
} USERS;
extern USERS *users_alloc(); /**< Allocate a users table */
extern users_free(USERS *); /**< Free a users table */
extern void users_free(USERS *); /**< Free a users table */
extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */
extern int users_delete(USERS *, char *); /**< Delete a user from the users table */
extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */