Compile server, service and session as C++

This commit is contained in:
Johan Wikman
2017-03-24 10:52:09 +02:00
parent ec39b54dea
commit bb1b7f9755
11 changed files with 54 additions and 48 deletions

View File

@ -267,9 +267,9 @@ extern SERVER *server_find_by_unique_name(const char *name);
extern int server_find_by_unique_names(char **server_names, int size, SERVER*** output); extern int server_find_by_unique_names(char **server_names, int size, SERVER*** output);
extern SERVER *server_find(const char *servname, unsigned short port); extern SERVER *server_find(const char *servname, unsigned short port);
extern char *server_status(const SERVER *); extern char *server_status(const SERVER *);
extern void server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set); extern void server_clear_set_status(SERVER *server, unsigned specified_bits, unsigned bits_to_set);
extern void server_set_status_nolock(SERVER *server, int bit); extern void server_set_status_nolock(SERVER *server, unsigned bit);
extern void server_clear_status_nolock(SERVER *server, int bit); extern void server_clear_status_nolock(SERVER *server, unsigned bit);
extern void server_transfer_status(SERVER *dest_server, const SERVER *source_server); extern void server_transfer_status(SERVER *dest_server, const SERVER *source_server);
extern void server_add_mon_user(SERVER *server, const char *user, const char *passwd); extern void server_add_mon_user(SERVER *server, const char *user, const char *passwd);
extern const char *server_get_parameter(const SERVER *server, char *name); extern const char *server_get_parameter(const SERVER *server, char *name);

View File

@ -38,7 +38,7 @@
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
struct server; struct server;
struct router; struct mxs_router;
struct mxs_router_object; struct mxs_router_object;
struct users; struct users;
@ -126,7 +126,7 @@ typedef struct service
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 mxs_router_object *router; /**< The router we are using */ struct mxs_router_object *router; /**< The router we are using */
void *router_instance; /**< The router instance for this service */ struct mxs_router *router_instance;/**< The router instance for this service */
char *version_string; /**< version string for this service listeners */ char *version_string; /**< version string for this service listeners */
SERVER_REF *dbref; /**< server references */ SERVER_REF *dbref; /**< server references */
int n_dbref; /**< Number of server references */ int n_dbref; /**< Number of server references */

View File

@ -31,6 +31,9 @@ MXS_BEGIN_DECLS
struct dcb; struct dcb;
struct service; struct service;
struct mxs_filter_def; struct mxs_filter_def;
struct mxs_filter;
struct mxs_filter_session;
struct mxs_router_session;
struct server; struct server;
typedef enum typedef enum
@ -86,8 +89,8 @@ typedef struct
typedef struct typedef struct
{ {
struct mxs_filter_def *filter; struct mxs_filter_def *filter;
void *instance; struct mxs_filter *instance;
void *session; struct mxs_filter_session *session;
} SESSION_FILTER; } SESSION_FILTER;
/** /**
@ -132,7 +135,7 @@ typedef struct session
mxs_session_state_t state; /*< Current descriptor state */ mxs_session_state_t state; /*< Current descriptor state */
size_t ses_id; /*< Unique session identifier */ size_t ses_id; /*< Unique session identifier */
struct dcb *client_dcb; /*< The client connection */ struct dcb *client_dcb; /*< The client connection */
void *router_session; /*< The router instance data */ struct mxs_router_session *router_session; /*< The router instance data */
MXS_SESSION_STATS stats; /*< Session statistics */ MXS_SESSION_STATS stats; /*< Session statistics */
struct service *service; /*< The service this session is using */ struct service *service; /*< The service this session is using */
int n_filters; /*< Number of filter sessions */ int n_filters; /*< Number of filter sessions */

View File

@ -58,7 +58,7 @@ typedef struct ssl_listener
SSL_METHOD *method; /*< SSLv3 or TLS1.0/1.1/1.2 methods SSL_METHOD *method; /*< SSLv3 or TLS1.0/1.1/1.2 methods
* see: https://www.openssl.org/docs/ssl/SSL_CTX_new.html */ * see: https://www.openssl.org/docs/ssl/SSL_CTX_new.html */
int ssl_cert_verify_depth; /*< SSL certificate verification depth */ int ssl_cert_verify_depth; /*< SSL certificate verification depth */
int ssl_method_type; /*< Which of the SSLv3 or TLS1.0/1.1/1.2 methods to use */ ssl_method_type_t ssl_method_type; /*< Which of the SSLv3 or TLS1.0/1.1/1.2 methods to use */
char *ssl_cert; /*< SSL certificate */ char *ssl_cert; /*< SSL certificate */
char *ssl_key; /*< SSL private key */ char *ssl_key; /*< SSL private key */
char *ssl_ca_cert; /*< SSL CA certificate */ char *ssl_ca_cert; /*< SSL CA certificate */

View File

@ -27,7 +27,9 @@ add_library(maxscale-common SHARED
resultset.cc resultset.cc
router.cc router.cc
secrets.cc secrets.cc
server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c) server.cc
service.cc
session.cc spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c)
if(WITH_JEMALLOC) if(WITH_JEMALLOC)
target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES}) target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES})

View File

@ -41,7 +41,7 @@ typedef enum
} SESSIONLISTFILTER; } SESSIONLISTFILTER;
int session_isvalid(MXS_SESSION *); int session_isvalid(MXS_SESSION *);
char *session_state(mxs_session_state_t); const char *session_state(mxs_session_state_t);
bool session_link_dcb(MXS_SESSION *, struct dcb *); bool session_link_dcb(MXS_SESSION *, struct dcb *);
RESULTSET *sessionGetList(SESSIONLISTFILTER); RESULTSET *sessionGetList(SESSIONLISTFILTER);

View File

@ -93,7 +93,7 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
char *my_name = MXS_STRDUP(name); char *my_name = MXS_STRDUP(name);
char *my_protocol = MXS_STRDUP(protocol); char *my_protocol = MXS_STRDUP(protocol);
char *my_authenticator = MXS_STRDUP(authenticator); char *my_authenticator = MXS_STRDUP(authenticator);
DCB **persistent = MXS_CALLOC(nthr, sizeof(*persistent)); DCB **persistent = (DCB**)MXS_CALLOC(nthr, sizeof(*persistent));
if (!server || !my_name || !my_protocol || !my_authenticator || !persistent) if (!server || !my_name || !my_protocol || !my_authenticator || !persistent)
{ {
@ -105,7 +105,7 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
return NULL; return NULL;
} }
if (snprintf(server->name, sizeof(server->name), "%s", address) > sizeof(server->name)) if (snprintf(server->name, sizeof(server->name), "%s", address) > (int)sizeof(server->name))
{ {
MXS_WARNING("Truncated server address '%s' to the maximum size of %lu characters.", MXS_WARNING("Truncated server address '%s' to the maximum size of %lu characters.",
address, sizeof(server->name)); address, sizeof(server->name));
@ -313,7 +313,7 @@ int server_find_by_unique_names(char **server_names, int size, SERVER*** output)
{ {
ss_dassert(server_names && (size > 0)); ss_dassert(server_names && (size > 0));
SERVER **results = MXS_CALLOC(size, sizeof(SERVER*)); SERVER **results = (SERVER**)MXS_CALLOC(size, sizeof(SERVER*));
if (!results) if (!results)
{ {
return 0; return 0;
@ -765,7 +765,7 @@ server_status(const SERVER *server)
* @param bit The bit to set for the server * @param bit The bit to set for the server
*/ */
void void
server_set_status_nolock(SERVER *server, int bit) server_set_status_nolock(SERVER *server, unsigned bit)
{ {
server->status |= bit; server->status |= bit;
@ -786,7 +786,7 @@ server_set_status_nolock(SERVER *server, int bit)
* @param bit The bit to set for the server * @param bit The bit to set for the server
*/ */
void void
server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set) server_clear_set_status(SERVER *server, unsigned specified_bits, unsigned bits_to_set)
{ {
/** clear error logged flag before the next failure */ /** clear error logged flag before the next failure */
if ((bits_to_set & SERVER_MASTER) && ((server->status & SERVER_MASTER) == 0)) if ((bits_to_set & SERVER_MASTER) && ((server->status & SERVER_MASTER) == 0))
@ -807,7 +807,7 @@ server_clear_set_status(SERVER *server, int specified_bits, int bits_to_set)
* @param bit The bit to clear for the server * @param bit The bit to clear for the server
*/ */
void void
server_clear_status_nolock(SERVER *server, int bit) server_clear_status_nolock(SERVER *server, unsigned bit)
{ {
server->status &= ~bit; server->status &= ~bit;
} }
@ -838,14 +838,14 @@ void
server_add_mon_user(SERVER *server, const char *user, const char *passwd) server_add_mon_user(SERVER *server, const char *user, const char *passwd)
{ {
if (user != server->monuser && if (user != server->monuser &&
snprintf(server->monuser, sizeof(server->monuser), "%s", user) > sizeof(server->monuser)) snprintf(server->monuser, sizeof(server->monuser), "%s", user) > (int)sizeof(server->monuser))
{ {
MXS_WARNING("Truncated monitor user for server '%s', maximum username " MXS_WARNING("Truncated monitor user for server '%s', maximum username "
"length is %lu characters.", server->unique_name, sizeof(server->monuser)); "length is %lu characters.", server->unique_name, sizeof(server->monuser));
} }
if (passwd != server->monpw && if (passwd != server->monpw &&
snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > sizeof(server->monpw)) snprintf(server->monpw, sizeof(server->monpw), "%s", passwd) > (int)sizeof(server->monpw))
{ {
MXS_WARNING("Truncated monitor password for server '%s', maximum password " MXS_WARNING("Truncated monitor password for server '%s', maximum password "
"length is %lu characters.", server->unique_name, sizeof(server->monpw)); "length is %lu characters.", server->unique_name, sizeof(server->monpw));
@ -1085,7 +1085,7 @@ server_update_port(SERVER *server, unsigned short port)
static struct static struct
{ {
char *str; const char *str;
unsigned int bit; unsigned int bit;
} ServerBits[] = } ServerBits[] =
{ {

View File

@ -121,7 +121,7 @@ SERVICE* service_alloc(const char *name, const char *router)
return NULL; return NULL;
} }
if ((service->router = load_module(my_router, MODULE_ROUTER)) == NULL) if ((service->router = (MXS_ROUTER_OBJECT*)load_module(my_router, MODULE_ROUTER)) == NULL)
{ {
char* home = get_libdir(); char* home = get_libdir();
char* ldpath = getenv("LD_LIBRARY_PATH"); char* ldpath = getenv("LD_LIBRARY_PATH");
@ -441,7 +441,7 @@ static char** copy_string_array(char** original)
values++; values++;
} }
array = MXS_MALLOC(sizeof(char*) * (values + 1)); array = (char**)MXS_MALLOC(sizeof(char*) * (values + 1));
if (array) if (array)
{ {
@ -814,7 +814,7 @@ bool serviceHasListener(SERVICE *service, const char *protocol,
*/ */
static SERVER_REF* server_ref_create(SERVER *server) static SERVER_REF* server_ref_create(SERVER *server)
{ {
SERVER_REF *sref = MXS_MALLOC(sizeof(SERVER_REF)); SERVER_REF *sref = (SERVER_REF*)MXS_MALLOC(sizeof(SERVER_REF));
if (sref) if (sref)
{ {
@ -1586,11 +1586,11 @@ dListListeners(DCB *dcb)
void void
service_update(SERVICE *service, char *router, char *user, char *auth) service_update(SERVICE *service, char *router, char *user, char *auth)
{ {
void *router_obj; MXS_ROUTER_OBJECT *router_obj;
if (!strcmp(service->routerModule, router)) if (!strcmp(service->routerModule, router))
{ {
if ((router_obj = load_module(router, MODULE_ROUTER)) == NULL) if ((router_obj = (MXS_ROUTER_OBJECT*)load_module(router, MODULE_ROUTER)) == NULL)
{ {
MXS_ERROR("Failed to update router " MXS_ERROR("Failed to update router "
"for service %s to %s.", "for service %s to %s.",

View File

@ -48,9 +48,6 @@
#include "maxscale/session.h" #include "maxscale/session.h"
#include "maxscale/filter.h" #include "maxscale/filter.h"
/* A session with null values, used for initialization */
static MXS_SESSION session_initialized = SESSION_INIT;
/** Global session id; updated safely by use of atomic_add */ /** Global session id; updated safely by use of atomic_add */
static int session_id; static int session_id;
@ -76,19 +73,18 @@ static int session_reply(MXS_FILTER *inst, MXS_FILTER_SESSION *session, GWBUF *d
* @brief Initialize a session * @brief Initialize a session
* *
* This routine puts initial values into the fields of the session pointed to * This routine puts initial values into the fields of the session pointed to
* by the parameter. The parameter has to be passed as void * because the * by the parameter.
* function can be called by the generic list manager, which does not know
* the actual type of the list entries it handles.
*
* All fields can be initialized by the assignment of the static
* initialized session.
* *
* @param *session Pointer to the session to be initialized * @param *session Pointer to the session to be initialized
*/ */
static void static void
session_initialize(void *session) session_initialize(MXS_SESSION *session)
{ {
*(MXS_SESSION *)session = session_initialized; memset(session, 0, sizeof(MXS_SESSION));
session->ses_chk_top = CHK_NUM_SESSION;
session->state = SESSION_STATE_ALLOC;
session->ses_chk_tail = CHK_NUM_SESSION;
} }
/** /**
@ -166,10 +162,15 @@ session_alloc(SERVICE *service, DCB *client_dcb)
* of the chain nearest the router working back to the client * of the chain nearest the router working back to the client
* protocol end of the chain. * protocol end of the chain.
*/ */
session->head.instance = service->router_instance; // NOTE: Here we cast the router instance into a MXS_FILTER and
session->head.session = session->router_session; // NOTE: and the router session into a MXS_FILTER_SESSION and
// NOTE: the router routeQuery into a filter routeQuery. That
session->head.routeQuery = (void *)(service->router->routeQuery); // NOTE: is in order to be able to treat the router as the first
// NOTE: filter.
session->head.instance = (MXS_FILTER*)service->router_instance;
session->head.session = (MXS_FILTER_SESSION*)session->router_session;
session->head.routeQuery =
(int32_t (*)(MXS_FILTER*, MXS_FILTER_SESSION*, GWBUF*))service->router->routeQuery;
// NOTE: Here we cast the session into a MXS_FILTER and MXS_FILTER_SESSION // NOTE: Here we cast the session into a MXS_FILTER and MXS_FILTER_SESSION
// NOTE: and session_reply into a filter clientReply. That's dubious but ok // NOTE: and session_reply into a filter clientReply. That's dubious but ok
@ -326,7 +327,7 @@ void session_close(MXS_SESSION *session)
} }
MXS_ROUTER_OBJECT* router = session->service->router; MXS_ROUTER_OBJECT* router = session->service->router;
void* router_instance = session->service->router_instance; MXS_ROUTER* router_instance = session->service->router_instance;
/** Close router session and all its connections */ /** Close router session and all its connections */
router->closeSession(router_instance, session->router_session); router->closeSession(router_instance, session->router_session);
@ -569,7 +570,7 @@ dListSessions(DCB *dcb)
* @param state The session state * @param state The session state
* @return A string representation of the session state * @return A string representation of the session state
*/ */
char * const char *
session_state(mxs_session_state_t state) session_state(mxs_session_state_t state)
{ {
switch (state) switch (state)
@ -617,7 +618,7 @@ session_setup_filters(MXS_SESSION *session)
MXS_UPSTREAM *tail; MXS_UPSTREAM *tail;
int i; int i;
if ((session->filters = MXS_CALLOC(service->n_filters, if ((session->filters = (SESSION_FILTER*)MXS_CALLOC(service->n_filters,
sizeof(SESSION_FILTER))) == NULL) sizeof(SESSION_FILTER))) == NULL)
{ {
return 0; return 0;
@ -897,7 +898,7 @@ static bool ses_find_id(DCB *dcb, void *data)
{ {
void **params = (void**)data; void **params = (void**)data;
MXS_SESSION **ses = (MXS_SESSION**)params[0]; MXS_SESSION **ses = (MXS_SESSION**)params[0];
int *id = (int*)params[1]; size_t *id = (size_t*)params[1];
bool rval = true; bool rval = true;
if (dcb->session->ses_id == *id) if (dcb->session->ses_id == *id)

View File

@ -40,7 +40,7 @@
// This is pretty ugly but it's required to test internal functions // This is pretty ugly but it's required to test internal functions
#include "../config.cc" #include "../config.cc"
#include "../server.c" #include "../server.cc"
/** /**
* test1 Allocate a server and do lots of other things * test1 Allocate a server and do lots of other things

View File

@ -105,13 +105,13 @@ bool avro_handle_convert(const MODULECMD_ARG *args)
bool rval = false; bool rval = false;
if (strcmp(args->argv[1].value.string, "start") == 0 && if (strcmp(args->argv[1].value.string, "start") == 0 &&
conversion_task_ctl(args->argv[0].value.service->router_instance, true)) conversion_task_ctl((AVRO_INSTANCE*)args->argv[0].value.service->router_instance, true))
{ {
MXS_NOTICE("Started conversion for service '%s'.", args->argv[0].value.service->name); MXS_NOTICE("Started conversion for service '%s'.", args->argv[0].value.service->name);
rval = true; rval = true;
} }
else if (strcmp(args->argv[1].value.string, "stop") == 0 && else if (strcmp(args->argv[1].value.string, "stop") == 0 &&
conversion_task_ctl(args->argv[0].value.service->router_instance, false)) conversion_task_ctl((AVRO_INSTANCE*)args->argv[0].value.service->router_instance, false))
{ {
MXS_NOTICE("Stopped conversion for service '%s'.", args->argv[0].value.service->name); MXS_NOTICE("Stopped conversion for service '%s'.", args->argv[0].value.service->name);
rval = true; rval = true;