1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is also distributed with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have included with MySQL.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License, version 2.0, for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 * 02110-1301 USA
24 */
25
26 #ifndef _XPL_SESSION_H_
27 #define _XPL_SESSION_H_
28
29 #include <string>
30 #include <vector>
31 #include "ngs/client_session.h"
32
33 #include "sql_data_context.h"
34 #include "expect.h"
35 #include "crud_cmd_handler.h"
36 #include "xpl_session_status_variables.h"
37 #include "xpl_global_status_variables.h"
38
39 namespace xpl
40 {
41
42 class Sql_data_context;
43 class Dispatcher;
44 class Cursor_manager;
45 class Client;
46
47 class Session_options
48 {
49 public:
Session_options()50 Session_options()
51 : m_send_warnings(true), m_send_xplugin_deprecation(true)
52 {}
53
set_send_warnings(bool flag)54 void set_send_warnings(bool flag) { m_send_warnings = flag; }
get_send_warnings()55 bool get_send_warnings() const { return m_send_warnings; }
56
set_send_xplugin_deprecation(bool flag)57 void set_send_xplugin_deprecation(bool flag) { m_send_xplugin_deprecation = flag; }
get_send_xplugin_deprecation()58 bool get_send_xplugin_deprecation() const { return m_send_xplugin_deprecation; }
59
60 private:
61 bool m_send_warnings;
62 bool m_send_xplugin_deprecation;
63 };
64
65
66 class Session : public ngs::Session
67 {
68 public:
69 Session(ngs::Client_interface &client, ngs::Protocol_encoder *proto, const Session_id session_id);
70 virtual ~Session();
71
72 public: // impl ngs::Session_interface
73 ngs::Error_code init();
74 virtual void on_auth_success(const ngs::Authentication_handler::Response &response);
75 virtual void on_auth_failure(const ngs::Authentication_handler::Response &response);
76
77 virtual void mark_as_tls_session();
78 virtual bool is_handled_by(const void *handler) const;
79
80 public:
data_context()81 virtual Sql_data_context &data_context() { return m_sql; }
options()82 Session_options &options() { return m_options; }
get_status_variables()83 Session_status_variables &get_status_variables() { return m_status_variables; }
84
85 bool can_see_user(const std::string &user) const;
86
87 template<Common_status_variables::Variable Common_status_variables::*variable>
88 void update_status();
89 template<Common_status_variables::Variable Common_status_variables::*variable>
90 void update_status(long param);
91
92 void update_status(Common_status_variables::Variable
93 Common_status_variables::*variable);
94
95 private: // reimpl ngs::Session
96 virtual void on_kill();
97 virtual bool handle_ready_message(ngs::Request &command);
98
99 private:
100 Sql_data_context m_sql;
101 Crud_command_handler m_crud_handler;
102 Expectation_stack m_expect_stack;
103
104 Session_options m_options;
105 Session_status_variables m_status_variables;
106
107 bool m_was_authenticated;
108 };
109
110
111 template<Common_status_variables::Variable Common_status_variables::*variable>
update_status()112 void Session::update_status()
113 {
114 ++(m_status_variables.*variable);
115 ++(Global_status_variables::instance().*variable);
116 }
117
118
119 template<Common_status_variables::Variable Common_status_variables::*variable>
update_status(long param)120 void Session::update_status(long param)
121 {
122 (m_status_variables.*variable) += param;
123 (Global_status_variables::instance().*variable) += param;
124 }
125 } // namespace xpl
126
127 #endif // _XPL_SESSION_H_
128