diff --git a/include/maxscale/session.h b/include/maxscale/session.h index d44179d41..9c5f32f48 100644 --- a/include/maxscale/session.h +++ b/include/maxscale/session.h @@ -13,33 +13,18 @@ */ /** - * @file session.h - * - * @verbatim - * Revision History - * - * Date Who Description - * 01-06-2013 Mark Riddoch Initial implementation - * 14-06-2013 Massimiliano Pinto Added void *data to session - * for session specific data - * 01-07-2013 Massimiliano Pinto Removed backends pointer - * from struct session - * 02-09-2013 Massimiliano Pinto Added session ref counter - * 29-05-2014 Mark Riddoch Support for filter mechanism - * added - * 20-02-2015 Markus Mäkelä Added session timeouts - * 27/06/2016 Martin Brampton Modify session struct for list manager - * - * @endverbatim + * @file include/maxscale/session.h - The public session interface */ #include + #include + #include #include -#include -#include #include +#include +#include MXS_BEGIN_DECLS @@ -48,16 +33,6 @@ struct service; struct mxs_filter_def; struct server; -/** - * The session statistics structure - */ -typedef struct -{ - time_t connect; /**< Time when the session was started */ -} SESSION_STATS; - -#define SESSION_STATS_INIT {0} - typedef enum { SESSION_STATE_ALLOC, /*< for all sessions */ @@ -92,39 +67,12 @@ typedef enum } mxs_session_trx_state_t; /** - * Convert transaction state to string representation. - * - * @param state A transaction state. - * @return String representation of the state. + * The session statistics structure */ -const char* session_trx_state_to_string(mxs_session_trx_state_t state); - -/** - * The downstream element in the filter chain. This may refer to - * another filter or to a router. - */ -typedef struct mxs_downstream +typedef struct { - void *instance; - void *session; - int32_t (*routeQuery)(void *instance, void *session, GWBUF *request); -} MXS_DOWNSTREAM; - -#define MXS_DOWNSTREAM_INIT {0} - -/** - * The upstream element in the filter chain. This may refer to - * another filter or to the protocol implementation. - */ -typedef struct mxs_upstream -{ - void *instance; - void *session; - int32_t (*clientReply)(void *instance, void *session, GWBUF *response); - int32_t (*error)(void *instance, void *session, void *); -} MXS_UPSTREAM; - -#define MXS_UPSTREAM_INIT {0} + time_t connect; /**< Time when the session was started */ +} MXS_SESSION_STATS; /** * Structure used to track the filter instances and sessions of the filters @@ -137,16 +85,28 @@ typedef struct void *session; } SESSION_FILTER; -#define SESSION_FILTER_INIT {0} +/** + * The downstream element in the filter chain. This may refer to + * another filter or to a router. + */ +typedef struct mxs_downstream +{ + void *instance; + void *session; + int32_t (*routeQuery)(void *instance, void *session, GWBUF *request); +} MXS_DOWNSTREAM; /** - * Filter type for the sessionGetList call + * The upstream element in the filter chain. This may refer to + * another filter or to the protocol implementation. */ -typedef enum +typedef struct mxs_upstream { - SESSION_LIST_ALL, - SESSION_LIST_CONNECTION -} SESSIONLISTFILTER; + void *instance; + void *session; + int32_t (*clientReply)(void *instance, void *session, GWBUF *response); + int32_t (*error)(void *instance, void *session, void *); +} MXS_UPSTREAM; /** * The session status block @@ -167,7 +127,7 @@ typedef struct session int enabled_log_priorities; /*< Bitfield of enabled syslog priorities */ struct dcb *client_dcb; /*< The client connection */ void *router_session; /*< The router instance data */ - SESSION_STATS stats; /*< Session statistics */ + MXS_SESSION_STATS stats; /*< Session statistics */ struct service *service; /*< The service this session is using */ int n_filters; /*< Number of filter sessions */ SESSION_FILTER *filters; /*< The filters in use within this session */ @@ -185,12 +145,6 @@ typedef struct session skygw_chk_t ses_chk_tail; } MXS_SESSION; -#define SESSION_INIT {.ses_chk_top = CHK_NUM_SESSION, .ses_lock = SPINLOCK_INIT, \ - .stats = SESSION_STATS_INIT, .head = MXS_DOWNSTREAM_INIT, .tail = MXS_UPSTREAM_INIT, \ - .state = SESSION_STATE_ALLOC, .ses_chk_tail = CHK_NUM_SESSION} - -#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client_dcb, type) - /** * A convenience macro that can be used by the protocol modules to route * the incoming data to the first element in the pipeline of filters and @@ -210,21 +164,20 @@ typedef struct session MXS_SESSION *session_alloc(struct service *, struct dcb *); MXS_SESSION *session_set_dummy(struct dcb *); -int session_isvalid(MXS_SESSION *); -int session_reply(void *inst, void *session, GWBUF *data); + const char *session_get_remote(const MXS_SESSION *); const char *session_get_user(const MXS_SESSION *); -void printAllSessions(); -void printSession(MXS_SESSION *); -void dprintSessionList(DCB *pdcb); -void dprintAllSessions(struct dcb *); -void dprintSession(struct dcb *, MXS_SESSION *); -void dListSessions(struct dcb *); -char *session_state(mxs_session_state_t); -bool session_link_dcb(MXS_SESSION *, struct dcb *); + void session_enable_log_priority(MXS_SESSION* ses, int priority); void session_disable_log_priority(MXS_SESSION* ses, int priority); -RESULTSET *sessionGetList(SESSIONLISTFILTER); + +/** + * Convert transaction state to string representation. + * + * @param state A transaction state. + * @return String representation of the state. + */ +const char* session_trx_state_to_string(mxs_session_trx_state_t state); /** * Get the transaction state of the session. @@ -356,22 +309,11 @@ static inline bool session_set_autocommit(MXS_SESSION* ses, bool autocommit) */ MXS_SESSION* session_get_by_id(int id); -/** - * @brief Get a session reference - * - * This creates an additional reference to a session which allows it to live - * as long as it is needed. - * - * @param session Session reference to get - * @return Reference to a MXS_SESSION - * - * @note The caller must free the session reference by calling session_put_ref - */ -MXS_SESSION* session_get_ref(MXS_SESSION *sessoin); - /** * @brief Release a session reference * + * This function is public only because the tee-filter uses it. + * * @param session Session reference to release */ void session_put_ref(MXS_SESSION *session); diff --git a/server/core/dcb.c b/server/core/dcb.c index 949b4fefe..1b9a34707 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -63,20 +63,21 @@ * * @endverbatim */ -#include +#include + +#include #include +#include #include #include -#include #include -#include +#include + #include #include -#include #include #include #include -#include #include #include #include @@ -93,6 +94,8 @@ #include #include +#include "maxscale/session.h" + /* A DCB with null values, used for initialization */ static DCB dcb_initialized = DCB_INIT; diff --git a/server/core/maxscale/session.h b/server/core/maxscale/session.h new file mode 100644 index 000000000..5508ae97c --- /dev/null +++ b/server/core/maxscale/session.h @@ -0,0 +1,71 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +/** + * @file core/maxscale/session.h - The private session interface + */ + +#include + +MXS_BEGIN_DECLS + +#define SESSION_STATS_INIT {0} +#define MXS_DOWNSTREAM_INIT {0} +#define MXS_UPSTREAM_INIT {0} +#define SESSION_FILTER_INIT {0} + +#define SESSION_INIT {.ses_chk_top = CHK_NUM_SESSION, .ses_lock = SPINLOCK_INIT, \ + .stats = SESSION_STATS_INIT, .head = MXS_DOWNSTREAM_INIT, .tail = MXS_UPSTREAM_INIT, \ + .state = SESSION_STATE_ALLOC, .ses_chk_tail = CHK_NUM_SESSION} + +#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client_dcb, type) + +/** + * Filter type for the sessionGetList call + */ +typedef enum +{ + SESSION_LIST_ALL, + SESSION_LIST_CONNECTION +} SESSIONLISTFILTER; + +int session_isvalid(MXS_SESSION *); +int session_reply(void *inst, void *session, GWBUF *data); +char *session_state(mxs_session_state_t); +bool session_link_dcb(MXS_SESSION *, struct dcb *); + +RESULTSET *sessionGetList(SESSIONLISTFILTER); + +void printAllSessions(); +void printSession(MXS_SESSION *); + +void dprintSessionList(DCB *pdcb); +void dprintAllSessions(struct dcb *); +void dprintSession(struct dcb *, MXS_SESSION *); +void dListSessions(struct dcb *); + +/** + * @brief Get a session reference + * + * This creates an additional reference to a session which allows it to live + * as long as it is needed. + * + * @param session Session reference to get + * @return Reference to a MXS_SESSION + * + * @note The caller must free the session reference by calling session_put_ref + */ +MXS_SESSION* session_get_ref(MXS_SESSION *sessoin); + +MXS_END_DECLS diff --git a/server/core/session.c b/server/core/session.c index 5b6387ea3..d1b2e0548 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -28,11 +28,13 @@ * @endverbatim */ #include + #include #include #include #include #include + #include #include #include @@ -42,6 +44,8 @@ #include #include #include + +#include "maxscale/session.h" #include "maxscale/filter.h" /* A session with null values, used for initialization */ @@ -230,7 +234,7 @@ session_set_dummy(DCB *client_dcb) session->service = NULL; session->client_dcb = NULL; session->n_filters = 0; - memset(&session->stats, 0, sizeof(SESSION_STATS)); + memset(&session->stats, 0, sizeof(MXS_SESSION_STATS)); session->stats.connect = 0; session->state = SESSION_STATE_DUMMY; session->refcount = 1; @@ -688,7 +692,7 @@ session_setup_filters(MXS_SESSION *session) } /** - * Entry point for the final element int he upstream filter, i.e. the writing + * Entry point for the final element in the upstream filter, i.e. the writing * of the data to the client. * * @param instance The "instance" data diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 102dd8b5c..610803df0 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -78,6 +77,8 @@ #include #include +#include "../../../core/maxscale/session.h" + #define MAXARGS 12 #define ARG_TYPE_NONE 0 diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.c index c54b3d1b6..2c47e57df 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -53,6 +52,8 @@ #include #include +#include "../../../core/maxscale/session.h" + extern char *create_hex_sha1_sha1_passwd(char *passwd); static int maxinfo_statistics(INFO_INSTANCE *, INFO_SESSION *, GWBUF *); diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index 12c4b7ebf..41f54a510 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,8 @@ #include #include +#include "../../../core/maxscale/session.h" + static void exec_show(DCB *dcb, MAXINFO_TREE *tree); static void exec_select(DCB *dcb, MAXINFO_TREE *tree); static void exec_show_variables(DCB *dcb, MAXINFO_TREE *filter);