Reindent server/core/service.c

This commit is contained in:
Johan Wikman
2015-11-30 19:36:44 +02:00
parent ed06d4f14c
commit 8601068dc2
2 changed files with 1540 additions and 1410 deletions

File diff suppressed because it is too large Load Diff

View File

@ -65,19 +65,20 @@ struct users;
* that should be loaded to support the client connection and the port that the * that should be loaded to support the client connection and the port that the
* protocol should use to listen for incoming client connections. * protocol should use to listen for incoming client connections.
*/ */
typedef struct servprotocol { typedef struct servprotocol
{
char *protocol; /**< Protocol module to load */ char *protocol; /**< Protocol module to load */
unsigned short port; /**< Port to listen on */ unsigned short port; /**< Port to listen on */
char *address; /**< Address to listen with */ char *address; /**< Address to listen with */
DCB *listener; /**< The DCB for the listener */ DCB *listener; /**< The DCB for the listener */
struct servprotocol struct servprotocol *next; /**< Next service protocol */
*next; /**< Next service protocol */
} SERV_PROTOCOL; } SERV_PROTOCOL;
/** /**
* The service statistics structure * The service statistics structure
*/ */
typedef struct { typedef struct
{
time_t started; /**< The time when the service was started */ time_t started; /**< The time when the service was started */
int n_failed_starts; /**< Number of times this service has failed to start */ int n_failed_starts; /**< Number of times this service has failed to start */
int n_sessions; /**< Number of sessions created on service since start */ int n_sessions; /**< Number of sessions created on service since start */
@ -89,8 +90,9 @@ typedef struct {
for this service to allow the gateway to login to the backend for this service to allow the gateway to login to the backend
database and extact information such as the user table or other database and extact information such as the user table or other
database status or configuration data. database status or configuration data.
*/ */
typedef struct { typedef struct
{
char *name; /**< The user name to use to extract information */ char *name; /**< The user name to use to extract information */
char *authdata; /**< The authentication data requied */ char *authdata; /**< The authentication data requied */
} SERVICE_USER; } SERVICE_USER;
@ -98,24 +100,28 @@ typedef struct {
/** /**
* The service refresh rate holds the counter and last load time_t * The service refresh rate holds the counter and last load time_t
for this service to load users data from the backend database for this service to load users data from the backend database
*/ */
typedef struct { typedef struct
{
int nloads; int nloads;
time_t last; time_t last;
} SERVICE_REFRESH_RATE; } SERVICE_REFRESH_RATE;
typedef struct server_ref_t{ typedef struct server_ref_t
{
struct server_ref_t *next; struct server_ref_t *next;
SERVER* server; SERVER* server;
}SERVER_REF; }SERVER_REF;
typedef enum { typedef enum
{
SSL_DISABLED, SSL_DISABLED,
SSL_ENABLED, SSL_ENABLED,
SSL_REQUIRED SSL_REQUIRED
} ssl_mode_t; } ssl_mode_t;
enum{ enum
{
SERVICE_SSLV3, SERVICE_SSLV3,
SERVICE_TLS10, SERVICE_TLS10,
#ifdef OPENSSL_1_0 #ifdef OPENSSL_1_0
@ -142,19 +148,18 @@ enum{
* and a set of client side protocol/port pairs used to listen for new connections * and a set of client side protocol/port pairs used to listen for new connections
* to the service. * to the service.
*/ */
typedef struct service { typedef struct service
{
char *name; /**< The service name */ char *name; /**< The service name */
int state; /**< The service state */ int state; /**< The service state */
SERV_PROTOCOL *ports; /**< Linked list of ports and protocols SERV_PROTOCOL *ports; /**< Linked list of ports and protocols
* that this service will listen on. * that this service will listen on.
*/ */
char *routerModule; /**< Name of router module to use */ char *routerModule; /**< Name of router module to use */
char **routerOptions;/**< Router specific option strings */ char **routerOptions; /**< Router specific option strings */
struct router_object struct router_object *router; /**< The router we are using */
*router; /**< The router we are using */ void *router_instance; /**< The router instance for this service */
void *router_instance; char *version_string; /** version string for this service listeners */
/**< The router instance for this service */
char *version_string;/** version string for this service listeners */
SERVER_REF *dbref; /** server references */ SERVER_REF *dbref; /** server references */
SERVICE_USER credentials; /**< The cedentials of the service user */ SERVICE_USER credentials; /**< The cedentials of the service user */
SPINLOCK spin; /**< The service spinlock */ SPINLOCK spin; /**< The service spinlock */
@ -163,8 +168,7 @@ typedef struct service {
int enable_root; /**< Allow root user access */ int enable_root; /**< Allow root user access */
int localhost_match_wildcard_host; /**< Match localhost against wildcard */ int localhost_match_wildcard_host; /**< Match localhost against wildcard */
HASHTABLE *resources; /**< hastable for service resources, i.e. database names */ HASHTABLE *resources; /**< hastable for service resources, i.e. database names */
CONFIG_PARAMETER* CONFIG_PARAMETER* svc_config_param;/*< list of config params and values */
svc_config_param; /*< list of config params and values */
int svc_config_version; /*< Version number of configuration */ int svc_config_version; /*< Version number of configuration */
bool svc_do_shutdown; /*< tells the service to exit loops etc. */ bool svc_do_shutdown; /*< tells the service to exit loops etc. */
bool users_from_all; /*< Load users from one server or all of them */ bool users_from_all; /*< Load users from one server or all of them */
@ -172,10 +176,8 @@ typedef struct service {
* when querying them from the server. MySQL Workbench seems * when querying them from the server. MySQL Workbench seems
* to escape at least the underscore character. */ * to escape at least the underscore character. */
bool optimize_wildcard; /*< Convert wildcard grants to individual database grants */ bool optimize_wildcard; /*< Convert wildcard grants to individual database grants */
SPINLOCK SPINLOCK users_table_spin; /**< The spinlock for users data refresh */
users_table_spin; /**< The spinlock for users data refresh */ SERVICE_REFRESH_RATE rate_limit; /**< The refresh rate limit for users table */
SERVICE_REFRESH_RATE
rate_limit; /**< The refresh rate limit for users table */
FILTER_DEF **filters; /**< Ordered list of filters */ FILTER_DEF **filters; /**< Ordered list of filters */
int n_filters; /**< Number of filters */ int n_filters; /**< Number of filters */
int conn_timeout; /*< Session timeout in seconds */ int conn_timeout; /*< Session timeout in seconds */
@ -195,7 +197,13 @@ typedef struct service {
bool log_auth_warnings; /*< Log authentication failures and warnings */ bool log_auth_warnings; /*< Log authentication failures and warnings */
} SERVICE; } SERVICE;
typedef enum count_spec_t {COUNT_NONE=0, COUNT_ATLEAST, COUNT_EXACT, COUNT_ATMOST} count_spec_t; typedef enum count_spec_t
{
COUNT_NONE = 0,
COUNT_ATLEAST,
COUNT_EXACT,
COUNT_ATMOST
} count_spec_t;
#define SERVICE_STATE_ALLOC 1 /**< The service has been allocated */ #define SERVICE_STATE_ALLOC 1 /**< The service has been allocated */
#define SERVICE_STATE_STARTED 2 /**< The service has been started */ #define SERVICE_STATE_STARTED 2 /**< The service has been started */
@ -231,28 +239,26 @@ extern void serviceSetRetryOnFailure(SERVICE *service, char* value);
extern void serviceWeightBy(SERVICE *, char *); extern void serviceWeightBy(SERVICE *, char *);
extern char *serviceGetWeightingParameter(SERVICE *); extern char *serviceGetWeightingParameter(SERVICE *);
extern int serviceEnableLocalhostMatchWildcardHost(SERVICE *, int); extern int serviceEnableLocalhostMatchWildcardHost(SERVICE *, int);
int serviceStripDbEsc(SERVICE* service, int action); extern int serviceStripDbEsc(SERVICE* service, int action);
int serviceAuthAllServers(SERVICE *service, int action); extern int serviceAuthAllServers(SERVICE *service, int action);
int serviceOptimizeWildcard(SERVICE *service, int action); extern int serviceOptimizeWildcard(SERVICE *service, int action);
extern void service_update(SERVICE *, char *, char *, char *); extern void service_update(SERVICE *, char *, char *, char *);
extern int service_refresh_users(SERVICE *); extern int service_refresh_users(SERVICE *);
extern void printService(SERVICE *); extern void printService(SERVICE *);
extern void printAllServices(); extern void printAllServices();
extern void dprintAllServices(DCB *); extern void dprintAllServices(DCB *);
extern bool service_set_param_value(SERVICE* service,
bool service_set_param_value (
SERVICE* service,
CONFIG_PARAMETER* param, CONFIG_PARAMETER* param,
char* valstr, char* valstr,
count_spec_t count_spec, count_spec_t count_spec,
config_param_type_t type); config_param_type_t type);
extern void dprintService(DCB *, SERVICE *); extern void dprintService(DCB *, SERVICE *);
extern void dListServices(DCB *); extern void dListServices(DCB *);
extern void dListListeners(DCB *); extern void dListListeners(DCB *);
char* service_get_name(SERVICE* svc); extern char* service_get_name(SERVICE* svc);
void service_shutdown(); extern void service_shutdown();
extern int serviceSessionCountAll(); extern int serviceSessionCountAll();
extern RESULTSET *serviceGetList(); extern RESULTSET *serviceGetList();
extern RESULTSET *serviceGetListenerList(); extern RESULTSET *serviceGetListenerList();
#endif #endif