1 /*
2    Copyright (c) 2015, 2021, Oracle and/or its affiliates.
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 02110-1301  USA
23 */
24 
25 #ifndef XPL_SYSTEM_VARIABLES_H
26 #define XPL_SYSTEM_VARIABLES_H
27 
28 #include "my_global.h"
29 #include "xpl_log.h"
30 #include "ngs_common/bind.h"
31 #include <vector>
32 #include <algorithm>
33 
34 #ifdef max_allowed_packet
35 #undef max_allowed_packet
36 #endif // max_allowed_packet
37 
38 
39 struct st_mysql_sys_var;
40 class THD;
41 
42 namespace xpl
43 {
44 
45 struct Ssl_config
46 {
47   Ssl_config();
48 
49   bool is_configured() const;
50 
51   char *ssl_key;
52   char *ssl_ca;
53   char *ssl_capath;
54   char *ssl_cert;
55   char *ssl_cipher;
56   char *ssl_crl;
57   char *ssl_crlpath;
58 
59 private:
60   bool  has_value(const char *ptr) const;
61 
62   char m_null_char;
63 };
64 
65 class Plugin_system_variables
66 {
67 public:
68   static int          max_connections;
69   static unsigned int port;
70   static unsigned int min_worker_threads;
71   static unsigned int idle_worker_thread_timeout;
72   static unsigned int max_allowed_packet;
73   static unsigned int connect_timeout;
74   static char        *socket;
75   static unsigned int port_open_timeout;
76   static char        *bind_address;
77 
78   static Ssl_config ssl_config;
79 
80 public:
81   typedef ngs::function<void()> Value_changed_callback;
82 
83   static void clean_callbacks();
84   static void registry_callback(Value_changed_callback callcback);
85 
86   template<typename Copy_type>
87   static void update_func(THD *thd, st_mysql_sys_var *var,
88                           void *tgt, const void *save);
89 
90   static void setup_system_variable_from_env_or_compile_opt(char *&cnf_option, const char *env_variable, const char *compile_option);
91 
92 private:
93   struct Executor
94   {
operatorExecutor95     void operator() (const Value_changed_callback & callback) { callback(); };
96   };
97 
98   static const char *get_system_variable_impl(const char *cnf_option, const char *env_variable, const char *compile_option);
99 
100   static std::vector<Value_changed_callback> m_callbacks;
101 };
102 
103 template<typename Copy_type>
update_func(THD * thd,st_mysql_sys_var * var,void * tgt,const void * save)104 void Plugin_system_variables::update_func(THD *thd, st_mysql_sys_var *var, void *tgt, const void *save)
105 {
106   *(Copy_type*)tgt = *(Copy_type*) save;
107 
108   std::for_each(m_callbacks.begin(), m_callbacks.end(), Executor());
109 }
110 
111 } // namespace xpl
112 
113 #endif /* XPL_SYSTEM_VARIABLES_H */
114