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 #include "xpl_system_variables.h"
26
27
28 namespace xpl
29 {
30
31 int Plugin_system_variables::max_connections;
32 unsigned int Plugin_system_variables::port;
33 unsigned int Plugin_system_variables::min_worker_threads;
34 unsigned int Plugin_system_variables::idle_worker_thread_timeout;
35 unsigned int Plugin_system_variables::max_allowed_packet;
36 unsigned int Plugin_system_variables::connect_timeout;
37 char *Plugin_system_variables::socket;
38 unsigned int Plugin_system_variables::port_open_timeout;
39 char *Plugin_system_variables::bind_address;
40
41 Ssl_config Plugin_system_variables::ssl_config;
42
43 std::vector<Plugin_system_variables::Value_changed_callback> Plugin_system_variables::m_callbacks;
44
45
clean_callbacks()46 void Plugin_system_variables::clean_callbacks()
47 {
48 m_callbacks.clear();
49 }
50
registry_callback(Value_changed_callback callback)51 void Plugin_system_variables::registry_callback(Value_changed_callback callback)
52 {
53 m_callbacks.push_back(callback);
54 }
55
get_system_variable_impl(const char * cnf_option,const char * env_variable,const char * compile_option)56 const char *Plugin_system_variables::get_system_variable_impl(const char *cnf_option, const char *env_variable, const char *compile_option)
57 {
58 if (NULL != cnf_option)
59 {
60 return cnf_option;
61 }
62
63 const char *variable_from_env = env_variable ? getenv(env_variable) : NULL;
64
65 if (NULL != variable_from_env)
66 return variable_from_env;
67
68 return compile_option;
69 }
70
setup_system_variable_from_env_or_compile_opt(char * & cnf_option,const char * env_variable,const char * compile_option)71 void Plugin_system_variables::setup_system_variable_from_env_or_compile_opt(char *&cnf_option, const char *env_variable, const char *compile_option)
72 {
73 char *value_old = cnf_option;
74 const char *result = get_system_variable_impl(cnf_option, env_variable, compile_option);
75
76 if (NULL != result)
77 cnf_option = my_strdup(PSI_NOT_INSTRUMENTED, const_cast<char *>(result), MYF(MY_WME));
78 else
79 cnf_option = NULL;
80
81 if (NULL != value_old)
82 my_free(value_old);
83 }
84
85
Ssl_config()86 Ssl_config::Ssl_config()
87 : ssl_key(NULL), ssl_ca(NULL), ssl_capath(NULL), ssl_cert(NULL), ssl_cipher(NULL),
88 ssl_crl(NULL), ssl_crlpath(NULL), m_null_char(0)
89 {
90 }
91
is_configured() const92 bool Ssl_config::is_configured() const
93 {
94 return has_value(ssl_key) ||
95 has_value(ssl_ca) ||
96 has_value(ssl_capath) ||
97 has_value(ssl_cert) ||
98 has_value(ssl_cipher) ||
99 has_value(ssl_crl) ||
100 has_value(ssl_crlpath);
101 }
102
has_value(const char * ptr) const103 bool Ssl_config::has_value(const char *ptr) const
104 {
105 return ptr && *ptr;
106 }
107
108 } // namespace xpl
109