Addition of the administration user in the service

Addition of general purpose hashtable (not complete) and users table (not complete)
This commit is contained in:
Mark Riddoch
2013-06-24 00:59:12 +02:00
parent 0b7803a122
commit b9e079ce17
9 changed files with 340 additions and 3 deletions

62
include/hashtable.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef _HASTABLE_H
#define _HASTABLE_H
/*
* This file is distributed as part of the SkySQL Gateway. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright SkySQL Ab 2013
*/
/**
* @file hashtable.h A general purpose hashtable mechanism for use within the
* gateway
*
* @verbatim
* Revision History
*
* Date Who Description
* 23/06/13 Mark Riddoch Initial implementation
*
* @endverbatim
*/
/**
* The entries within a hashtable.
*
* A NULL value for key indicates an empty entry.
* 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 */
} HASHENTRIES;
/**
* The general purpose hashtable struct.
*/
typedef struct hashtable {
int hashsize; /**< The number of HASHENTRIES */
HASHENTRIES *entries; /**< The entries themselves */
int (*hashfn)(void *); /**< The hash function */
int (*cmpfn)(void *, void *); /**< The key comparison function */
} HASHTABLE;
extern HASHTABLE *hashtable_alloc(int, int (*hashfn)(),
int (*cmpfn)()); /**< Allocate a hashtable */
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 */
#endif

View File

@ -35,12 +35,14 @@
* 14/06/13 Mark Riddoch Initial implementation
* 18/06/13 Mark Riddoch Addition of statistics and function
* prototypes
* 23/06/13 Mark Riddoch Added service user and users
*
* @endverbatim
*/
struct server;
struct router;
struct router_object;
struct users;
/**
* The servprotocol structure is used to link a service to the protocols that
@ -64,6 +66,17 @@ typedef struct {
int n_sessions; /**< Number of sessions created on service since start */
int n_current; /**< Current number of sessions */
} SERVICE_STATS;
/**
* The service user structure holds the information that is needed for this service to
* allow the gateway to login to the backend database and extact information such as
* the user table or other database status or configuration data.
*/
typedef struct {
char *name; /**< The user name to use to extract information */
char *authdata; /**< The authentication data requied */
} SERVICE_USER;
/**
* Defines a service within the gateway.
*
@ -83,8 +96,10 @@ typedef struct service {
void *router_instance;
/**< The router instance for this service */
struct server *databases; /**< The set of servers in the backend */
SERVICE_USER credentials; /**< The cedentials of the service user */
SPINLOCK spin; /**< The service spinlock */
SERVICE_STATS stats; /**< The service statistics */
struct users *users; /**< The user data for this service */
struct service *next; /**< The next service in the linked list */
} SERVICE;
@ -97,6 +112,8 @@ extern int serviceAddProtocol(SERVICE *, char *, unsigned short);
extern void serviceAddBackend(SERVICE *, SERVER *);
extern int serviceStart(SERVICE *);
extern int serviceStartAll();
extern int serviceSetUser(SERVICE *, char *, char *);
extern int serviceGetUser(SERVICE *, char **, char **);
extern void printService(SERVICE *);
extern void printAllServices();
extern void dprintAllServices(DCB *);

43
include/users.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef _USERS_H
#define _USERS_H
/*
* This file is distributed as part of the SkySQL Gateway. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright SkySQL Ab 2013
*/
#include <hashtable.h>
/**
* @file users.h The functions to manipulate the table of users maintained
* for each service
*
* @verbatim
* Revision History
*
* Date Who Description
* 23/06/13 Mark Riddoch Initial implementation
*
* @endverbatim
*/
typedef struct users {
HASHTABLE *data;
} USERS;
extern USERS *users_alloc(); /**< Allocate a users table */
extern 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 */
#endif