Reindent server/core/session.c

This commit is contained in:
Johan Wikman
2015-11-30 19:59:34 +02:00
parent 8601068dc2
commit 15df33a93f
2 changed files with 638 additions and 630 deletions

File diff suppressed because it is too large Load Diff

View File

@ -24,15 +24,15 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 01-06-2013 Mark Riddoch Initial implementation * 01-06-2013 Mark Riddoch Initial implementation
* 14-06-2013 Massimiliano Pinto Added void *data to session * 14-06-2013 Massimiliano Pinto Added void *data to session
* for session specific data * for session specific data
* 01-07-2013 Massimiliano Pinto Removed backends pointer * 01-07-2013 Massimiliano Pinto Removed backends pointer
* from struct session * from struct session
* 02-09-2013 Massimiliano Pinto Added session ref counter * 02-09-2013 Massimiliano Pinto Added session ref counter
* 29-05-2014 Mark Riddoch Support for filter mechanism * 29-05-2014 Mark Riddoch Support for filter mechanism
* added * added
* 20-02-2015 Markus Mäkelä Added session timeouts * 20-02-2015 Markus Mäkelä Added session timeouts
* *
* @endverbatim * @endverbatim
@ -52,18 +52,20 @@ struct filter_def;
/** /**
* The session statistics structure * The session statistics structure
*/ */
typedef struct { typedef struct
time_t connect; /**< Time when the session was started */ {
time_t connect; /**< Time when the session was started */
} SESSION_STATS; } SESSION_STATS;
typedef enum { typedef enum
{
SESSION_STATE_ALLOC, /*< for all sessions */ SESSION_STATE_ALLOC, /*< for all sessions */
SESSION_STATE_READY, /*< for router session */ SESSION_STATE_READY, /*< for router session */
SESSION_STATE_ROUTER_READY, /*< for router session */ SESSION_STATE_ROUTER_READY, /*< for router session */
SESSION_STATE_STOPPING, /*< session and router are being closed */ SESSION_STATE_STOPPING, /*< session and router are being closed */
SESSION_STATE_LISTENER, /*< for listener session */ SESSION_STATE_LISTENER, /*< for listener session */
SESSION_STATE_LISTENER_STOPPED, /*< for listener session */ SESSION_STATE_LISTENER_STOPPED, /*< for listener session */
SESSION_STATE_TO_BE_FREED, /*< ready to be freed as soon as there are no references */ SESSION_STATE_TO_BE_FREED, /*< ready to be freed as soon as there are no references */
SESSION_STATE_FREE, /*< for all sessions */ SESSION_STATE_FREE, /*< for all sessions */
SESSION_STATE_DUMMY /*< dummy session for consistency */ SESSION_STATE_DUMMY /*< dummy session for consistency */
} session_state_t; } session_state_t;
@ -72,42 +74,43 @@ typedef enum {
* The downstream element in the filter chain. This may refer to * The downstream element in the filter chain. This may refer to
* another filter or to a router. * another filter or to a router.
*/ */
typedef struct { typedef struct
void *instance; {
void *session; void *instance;
int (*routeQuery)(void *instance, void *session, void *session;
GWBUF *request); int (*routeQuery)(void *instance, void *session, GWBUF *request);
} DOWNSTREAM; } DOWNSTREAM;
/** /**
* The upstream element in the filter chain. This may refer to * The upstream element in the filter chain. This may refer to
* another filter or to the protocol implementation. * another filter or to the protocol implementation.
*/ */
typedef struct { typedef struct
void *instance; {
void *session; void *instance;
int (*clientReply)(void *instance, void *session;
void *session, GWBUF *response); int (*clientReply)(void *instance, void *session, GWBUF *response);
int (*error)(void *instance, void *session, void *); int (*error)(void *instance, void *session, void *);
} UPSTREAM; } UPSTREAM;
/** /**
* Structure used to track the filter instances and sessions of the filters * Structure used to track the filter instances and sessions of the filters
* that are in use within a session. * that are in use within a session.
*/ */
typedef struct { typedef struct
struct filter_def {
*filter; struct filter_def *filter;
void *instance; void *instance;
void *session; void *session;
} SESSION_FILTER; } SESSION_FILTER;
/** /**
* Filter type for the sessionGetList call * Filter type for the sessionGetList call
*/ */
typedef enum { typedef enum
SESSION_LIST_ALL, {
SESSION_LIST_CONNECTION SESSION_LIST_ALL,
SESSION_LIST_CONNECTION
} SESSIONLISTFILTER; } SESSIONLISTFILTER;
/** /**
@ -117,70 +120,71 @@ typedef enum {
* to the database, it links the descriptors, routing implementation * to the database, it links the descriptors, routing implementation
* and originating service together for the client session. * and originating service together for the client session.
*/ */
typedef struct session { typedef struct session
{
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t ses_chk_top; skygw_chk_t ses_chk_top;
#endif #endif
SPINLOCK ses_lock; SPINLOCK ses_lock;
session_state_t state; /*< Current descriptor state */ session_state_t state; /*< Current descriptor state */
size_t ses_id; /*< Unique session identifier */ size_t ses_id; /*< Unique session identifier */
int enabled_log_priorities; /*< Bitfield of enabled syslog priorities */ int enabled_log_priorities; /*< Bitfield of enabled syslog priorities */
struct dcb *client; /*< The client connection */ struct dcb *client; /*< The client connection */
void *data; /*< The session data */ void *data; /*< The session data */
void *router_session; /*< The router instance data */ void *router_session; /*< The router instance data */
SESSION_STATS stats; /*< Session statistics */ 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 */
SESSION_FILTER *filters; /*< The filters in use within this session */ SESSION_FILTER *filters; /*< The filters in use within this session */
DOWNSTREAM head; /*< Head of the filter chain */ DOWNSTREAM head; /*< Head of the filter chain */
UPSTREAM tail; /*< The tail of the filter chain */ UPSTREAM tail; /*< The tail of the filter chain */
struct session *next; /*< Linked list of all sessions */ struct session *next; /*< Linked list of all sessions */
int refcount; /*< Reference count on the session */ int refcount; /*< Reference count on the session */
bool ses_is_child; /*< this is a child session */ bool ses_is_child; /*< this is a child session */
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t ses_chk_tail; skygw_chk_t ses_chk_tail;
#endif #endif
} SESSION; } SESSION;
#define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client, type) #define SESSION_PROTOCOL(x, type) DCB_PROTOCOL((x)->client, type)
/** /**
* A convenience macro that can be used by the protocol modules to route * 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 * the incoming data to the first element in the pipeline of filters and
* routers. * routers.
*/ */
#define SESSION_ROUTE_QUERY(sess, buf) \ #define SESSION_ROUTE_QUERY(sess, buf) \
((sess)->head.routeQuery)((sess)->head.instance, \ ((sess)->head.routeQuery)((sess)->head.instance, \
(sess)->head.session, (buf)) (sess)->head.session, (buf))
/** /**
* A convenience macro that can be used by the router modules to route * A convenience macro that can be used by the router modules to route
* the replies to the first element in the pipeline of filters and * the replies to the first element in the pipeline of filters and
* the protocol. * the protocol.
*/ */
#define SESSION_ROUTE_REPLY(sess, buf) \ #define SESSION_ROUTE_REPLY(sess, buf) \
((sess)->tail.clientReply)((sess)->tail.instance, \ ((sess)->tail.clientReply)((sess)->tail.instance, \
(sess)->tail.session, (buf)) (sess)->tail.session, (buf))
SESSION *get_all_sessions(); SESSION *get_all_sessions();
SESSION *session_alloc(struct service *, struct dcb *); SESSION *session_alloc(struct service *, struct dcb *);
SESSION *session_set_dummy(struct dcb *); SESSION *session_set_dummy(struct dcb *);
bool session_free(SESSION *); bool session_free(SESSION *);
int session_isvalid(SESSION *); int session_isvalid(SESSION *);
int session_reply(void *inst, void *session, GWBUF *data); int session_reply(void *inst, void *session, GWBUF *data);
char *session_get_remote(SESSION *); char *session_get_remote(SESSION *);
char *session_getUser(SESSION *); char *session_getUser(SESSION *);
void printAllSessions(); void printAllSessions();
void printSession(SESSION *); void printSession(SESSION *);
void dprintAllSessions(struct dcb *); void dprintAllSessions(struct dcb *);
void dprintSession(struct dcb *, SESSION *); void dprintSession(struct dcb *, SESSION *);
void dListSessions(struct dcb *); void dListSessions(struct dcb *);
char *session_state(int); char *session_state(int);
bool session_link_dcb(SESSION *, struct dcb *); bool session_link_dcb(SESSION *, struct dcb *);
int session_unlink_dcb(SESSION*, DCB*); int session_unlink_dcb(SESSION*, DCB*);
SESSION* get_session_by_router_ses(void* rses); SESSION* get_session_by_router_ses(void* rses);
void session_enable_log_priority(SESSION* ses, int priority); void session_enable_log_priority(SESSION* ses, int priority);
void session_disable_log_priority(SESSION* ses, int priority); void session_disable_log_priority(SESSION* ses, int priority);
void session_close_timeouts(void* data); void session_close_timeouts(void* data);
RESULTSET *sessionGetList(SESSIONLISTFILTER); RESULTSET *sessionGetList(SESSIONLISTFILTER);
#endif #endif