1 /* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef CONNECTION_CONTROL_INTERFACES_H
24 #define CONNECTION_CONTROL_INTERFACES_H
25 
26 #include <mysql/plugin_audit.h>         /* mysql_event_connection */
27 
28 #include "connection_control_data.h"    /* Variables and Status */
29 
30 #include <vector>                       /* std::vector */
31 #include <string>                       /* std::string */
32 
33 namespace connection_control
34 {
35   /* Typedefs for convenience */
36   typedef std::string Sql_string;
37 
38   /* Forward declarations */
39   class Connection_event_coordinator_services;
40 
41   class Error_handler
42   {
43   public:
44     virtual void handle_error(const char * error_message)= 0;
~Error_handler()45     virtual ~Error_handler() {}
46   };
47 
48   /**
49     Interface for recording connection events
50   */
51 
52   class Connection_event_records
53   {
54   public:
55     virtual bool create_or_update_entry(const Sql_string &s)= 0;
56     virtual bool remove_entry(const Sql_string &s)= 0;
57     virtual bool match_entry(const Sql_string &s, void *value)= 0;
58     virtual void reset_all()= 0;
~Connection_event_records()59     virtual ~Connection_event_records()
60     { /* Emptiness! */ }
61   };
62 
63 
64   /**
65     Interface for defining action on connection events
66   */
67   class Connection_event_observer
68   {
69   public:
70     virtual bool notify_event(MYSQL_THD thd,
71                               Connection_event_coordinator_services *coordinator,
72                               const mysql_event_connection *connection_event,
73                               Error_handler *error_handler)= 0;
74     virtual bool notify_sys_var(Connection_event_coordinator_services *coordinator,
75                                 opt_connection_control variable,
76                                 void *new_value,
77                                 Error_handler *error_handler)= 0;
~Connection_event_observer()78     virtual ~Connection_event_observer()
79     { /* Nothing to see here! */ }
80   };
81 
82 
83   /* Status variable action enum */
84   typedef enum status_var_action
85   {
86     ACTION_NONE=0,
87     ACTION_INC,
88     ACTION_RESET,
89     ACTION_LAST /* Must be at the end */
90   }status_var_action;
91 
92 
93   /**
94     Interface to provide service to observers
95   */
96 
97   class Connection_event_coordinator_services
98   {
99   public:
100     virtual bool notify_status_var(Connection_event_observer **observer,
101                                    stats_connection_control status_var,
102                                    status_var_action action)= 0;
103     virtual bool register_event_subscriber(Connection_event_observer **subscriber,
104                                            std::vector<opt_connection_control> *sys_vars,
105                                            std::vector<stats_connection_control> *status_vars)= 0;
~Connection_event_coordinator_services()106     virtual ~Connection_event_coordinator_services()
107     { /* go away */ }
108   };
109 }
110 #endif // !CONNECTION_CONTROL_INTERFACES_H
111