Divide session.h to internal and interface headers

Definitions and function used by core are in
server/core/maxscale/session.h
Definitions and function used by plugins are in
include/maxscale/session.h
This commit is contained in:
Esa Korhonen 2017-01-18 17:55:42 +02:00
parent c9a61fec6d
commit 02a8f7492e
7 changed files with 131 additions and 108 deletions

View File

@ -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 <maxscale/cdefs.h>
#include <time.h>
#include <maxscale/atomic.h>
#include <maxscale/buffer.h>
#include <maxscale/spinlock.h>
#include <maxscale/resultset.h>
#include <maxscale/log_manager.h>
#include <maxscale/resultset.h>
#include <maxscale/spinlock.h>
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);

View File

@ -63,20 +63,21 @@
*
* @endverbatim
*/
#include <stdio.h>
#include <maxscale/dcb.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <maxscale/dcb.h>
#include <time.h>
#include <maxscale/spinlock.h>
#include <maxscale/server.h>
#include <maxscale/session.h>
#include <maxscale/service.h>
#include <maxscale/modules.h>
#include <maxscale/router.h>
#include <errno.h>
#include <maxscale/poll.h>
#include <maxscale/atomic.h>
#include <maxscale/log_manager.h>
@ -93,6 +94,8 @@
#include <maxscale/utils.h>
#include <maxscale/platform.h>
#include "maxscale/session.h"
/* A DCB with null values, used for initialization */
static DCB dcb_initialized = DCB_INIT;

View File

@ -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 <maxscale/session.h>
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

View File

@ -28,11 +28,13 @@
* @endverbatim
*/
#include <maxscale/session.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <maxscale/alloc.h>
#include <maxscale/atomic.h>
#include <maxscale/dcb.h>
@ -42,6 +44,8 @@
#include <maxscale/router.h>
#include <maxscale/service.h>
#include <maxscale/spinlock.h>
#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

View File

@ -53,7 +53,6 @@
#include <errno.h>
#include <maxscale/alloc.h>
#include <maxscale/service.h>
#include <maxscale/session.h>
#include <maxscale/router.h>
#include <maxscale/filter.h>
#include <maxscale/modules.h>
@ -78,6 +77,8 @@
#include <maxscale/log_manager.h>
#include <sys/syslog.h>
#include "../../../core/maxscale/session.h"
#define MAXARGS 12
#define ARG_TYPE_NONE 0

View File

@ -34,7 +34,6 @@
#include <time.h>
#include <maxscale/alloc.h>
#include <maxscale/service.h>
#include <maxscale/session.h>
#include <maxscale/server.h>
#include <maxscale/router.h>
#include <maxscale/modules.h>
@ -53,6 +52,8 @@
#include <maxscale/secrets.h>
#include <maxscale/users.h>
#include "../../../core/maxscale/session.h"
extern char *create_hex_sha1_sha1_passwd(char *passwd);
static int maxinfo_statistics(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);

View File

@ -31,7 +31,6 @@
#include <string.h>
#include <maxscale/alloc.h>
#include <maxscale/service.h>
#include <maxscale/session.h>
#include <maxscale/router.h>
#include <maxscale/modules.h>
#include <maxscale/monitor.h>
@ -47,6 +46,8 @@
#include <maxscale/resultset.h>
#include <maxscale/config.h>
#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);