MySQL 8.2.0
Source Code Documentation
mysql_connection_options.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014, 2023, 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 MYSQL_CONNECTION_OPTIONS_INCLUDED
26#define MYSQL_CONNECTION_OPTIONS_INCLUDED
27
28#include <optional>
29#include <vector>
30
34#include "client/client_priv.h"
35#include "my_compiler.h"
36#include "my_inttypes.h"
37
38struct CHARSET_INFO;
39
40namespace Mysql {
41namespace Tools {
42namespace Base {
43namespace Options {
44
45/**
46 Options provider providing options to specify connection to MySQL server.
47 */
50 private:
51 /**
52 Options provider enclosing options related to SSL settings of connection
53 to MySQL server.
54 */
56 public:
57 /**
58 Creates all options that will be provided.
59 Implementation of Abstract_options_provider virtual method.
60 */
61 void create_options() override;
62
63 /**
64 Applies option values to MYSQL connection structure.
65 */
66 bool apply_for_connection(MYSQL *connection);
67
68 /**
69 Checks the connection for SSL validity
70 */
71 bool check_connection(MYSQL *connection);
72
73 private:
74 std::optional<std::string> m_ssl_mode_string;
75 std::optional<std::string> m_ssl_fips_mode_string;
76
77 void ca_option_callback(char *argument);
78 void mode_option_callback(char *argument);
79 void fips_mode_option_callback(char *argument);
80 };
81
82 public:
83 /**
84 Constructs new MySQL server connection options provider. Calling this
85 function from multiple threads simultaneously is not thread safe.
86 @param program Pointer to main program class.
87 */
89
90 /**
91 Creates all options that will be provided.
92 Implementation of Abstract_options_provider virtual method.
93 */
94 void create_options() override;
95
96 /**
97 Provides new connection to MySQL database server based on option values.
98 Implementation of I_connection_factory interface.
99 */
100 MYSQL *create_connection() override;
101
102 /**
103 Retrieves charset that will be used in new MySQL connections.. Can be NULL
104 if none was set explicitly.
105 */
107
108 /**
109 Sets charset that will be used in new MySQL connections.
110 */
112
113 private:
114 /**
115 Returns pointer to constant array containing specified string or NULL
116 value if string has length 0.
117 */
118 const char *get_null_or_string(std::optional<std::string> &maybeString);
119
120 /**
121 Prints database connection error and exits program.
122 */
123 void db_error(MYSQL *connection, const char *when);
124#ifdef _WIN32
125 void pipe_protocol_callback(char *not_used [[maybe_unused]]);
126#endif
127 void protocol_callback(char *not_used [[maybe_unused]]);
128
129 static bool mysql_inited;
130
133 std::optional<std::string> m_protocol_string;
135 std::optional<std::string> m_bind_addr;
136 std::optional<std::string> m_host;
138 std::optional<std::string> m_mysql_unix_port;
139#if defined(_WIN32)
140 std::optional<std::string> m_shared_memory_base_name;
141#endif
142 std::optional<std::string> m_default_auth;
143 std::optional<std::string> m_plugin_dir;
147 std::optional<std::string> m_user;
148 std::optional<std::string> m_password[3];
149 std::optional<std::string> m_default_charset;
150 std::optional<std::string> m_server_public_key;
153 std::optional<std::string> m_compress_algorithm;
154};
155
156} // namespace Options
157} // namespace Base
158} // namespace Tools
159} // namespace Mysql
160
161#endif
Base class for all MySQL client tools.
Definition: abstract_program.h:46
Interface for classes that are capable of creating connection to MySQL database server.
Definition: i_connection_factory.h:38
Common abstract class for options providers.
Definition: abstract_options_provider.h:54
Provider that aggregates options from other providers.
Definition: composite_options_provider.h:40
Options provider enclosing options related to SSL settings of connection to MySQL server.
Definition: mysql_connection_options.h:55
std::optional< std::string > m_ssl_mode_string
Definition: mysql_connection_options.h:74
bool check_connection(MYSQL *connection)
Checks the connection for SSL validity.
Definition: ssl_options.cc:109
void fips_mode_option_callback(char *argument)
Definition: ssl_options.cc:94
void create_options() override
Creates all options that will be provided.
Definition: ssl_options.cc:37
void ca_option_callback(char *argument)
Definition: ssl_options.cc:83
std::optional< std::string > m_ssl_fips_mode_string
Definition: mysql_connection_options.h:75
void mode_option_callback(char *argument)
Definition: ssl_options.cc:88
bool apply_for_connection(MYSQL *connection)
Applies option values to MYSQL connection structure.
Definition: ssl_options.cc:100
Options provider providing options to specify connection to MySQL server.
Definition: mysql_connection_options.h:49
uint32 m_max_allowed_packet
Definition: mysql_connection_options.h:145
std::optional< std::string > m_mysql_unix_port
Definition: mysql_connection_options.h:138
bool m_get_server_public_key
Definition: mysql_connection_options.h:151
Abstract_program * m_program
Definition: mysql_connection_options.h:132
const char * get_null_or_string(std::optional< std::string > &maybeString)
Returns pointer to constant array containing specified string or NULL value if string has length 0.
Definition: mysql_connection_options.cc:248
uint m_zstd_compress_level
Definition: mysql_connection_options.h:152
CHARSET_INFO * get_current_charset() const
Retrieves charset that will be used in new MySQL connections.
Definition: mysql_connection_options.cc:237
Mysql_connection_options(Abstract_program *program)
Constructs new MySQL server connection options provider.
Definition: mysql_connection_options.cc:54
std::optional< std::string > m_default_auth
Definition: mysql_connection_options.h:142
std::optional< std::string > m_server_public_key
Definition: mysql_connection_options.h:150
std::optional< std::string > m_protocol_string
Definition: mysql_connection_options.h:133
std::optional< std::string > m_password[3]
Definition: mysql_connection_options.h:148
std::optional< std::string > m_user
Definition: mysql_connection_options.h:147
static bool mysql_inited
Definition: mysql_connection_options.h:129
uint32 m_mysql_port
Definition: mysql_connection_options.h:137
uint32 m_protocol
Definition: mysql_connection_options.h:134
std::optional< std::string > m_compress_algorithm
Definition: mysql_connection_options.h:153
void db_error(MYSQL *connection, const char *when)
Prints database connection error and exits program.
Definition: mysql_connection_options.cc:270
void set_current_charset(CHARSET_INFO *charset)
Sets charset that will be used in new MySQL connections.
Definition: mysql_connection_options.cc:244
std::optional< std::string > m_default_charset
Definition: mysql_connection_options.h:149
std::optional< std::string > m_bind_addr
Definition: mysql_connection_options.h:135
std::optional< std::string > m_plugin_dir
Definition: mysql_connection_options.h:143
MYSQL * create_connection() override
Provides new connection to MySQL database server based on option values.
Definition: mysql_connection_options.cc:159
std::optional< std::string > m_host
Definition: mysql_connection_options.h:136
void create_options() override
Creates all options that will be provided.
Definition: mysql_connection_options.cc:65
Ssl_options m_ssl_options_provider
Definition: mysql_connection_options.h:131
uint32 m_net_buffer_length
Definition: mysql_connection_options.h:144
bool m_compress
Definition: mysql_connection_options.h:146
void protocol_callback(char *not_used)
Definition: mysql_connection_options.cc:264
Header for compiler-dependent features.
Some integer typedefs for easier portability.
uint32_t uint32
Definition: my_inttypes.h:66
constexpr pos_type Options
Definition: http_request.h:260
Definition: abstract_connection_program.h:39
const std::string charset("charset")
Definition: m_ctype.h:422
Definition: mysql.h:299