MySQL 8.0.40
Source Code Documentation
mysql_connection_options.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_CONNECTION_OPTIONS_INCLUDED
27#define MYSQL_CONNECTION_OPTIONS_INCLUDED
28
29#include <optional>
30#include <vector>
31
35#include "client/client_priv.h"
36#include "my_compiler.h"
37#include "my_inttypes.h"
38
39namespace Mysql {
40namespace Tools {
41namespace Base {
42namespace Options {
43
44/**
45 Options provider providing options to specify connection to MySQL server.
46 */
49 private:
50 /**
51 Options provider enclosing options related to SSL settings of connection
52 to MySQL server.
53 */
55 public:
56 /**
57 Creates all options that will be provided.
58 Implementation of Abstract_options_provider virtual method.
59 */
60 void create_options() override;
61
62 /**
63 Applies option values to MYSQL connection structure.
64 */
65 bool apply_for_connection(MYSQL *connection);
66
67 /**
68 Checks the connection for SSL validity
69 */
70 bool check_connection(MYSQL *connection);
71
72 private:
73 std::optional<std::string> m_ssl_mode_string;
74 std::optional<std::string> m_ssl_fips_mode_string;
75
76 void ca_option_callback(char *argument);
77 void mode_option_callback(char *argument);
78 void fips_mode_option_callback(char *argument);
79 };
80
81 public:
82 /**
83 Constructs new MySQL server connection options provider. Calling this
84 function from multiple threads simultaneously is not thread safe.
85 @param program Pointer to main program class.
86 */
88
89 /**
90 Creates all options that will be provided.
91 Implementation of Abstract_options_provider virtual method.
92 */
93 void create_options() override;
94
95 /**
96 Provides new connection to MySQL database server based on option values.
97 Implementation of I_connection_factory interface.
98 */
99 MYSQL *create_connection() override;
100
101 /**
102 Retrieves charset that will be used in new MySQL connections.. Can be NULL
103 if none was set explicitly.
104 */
106
107 /**
108 Sets charset that will be used in new MySQL connections.
109 */
111
112 private:
113 /**
114 Returns pointer to constant array containing specified string or NULL
115 value if string has length 0.
116 */
117 const char *get_null_or_string(std::optional<std::string> &maybeString);
118
119 /**
120 Prints database connection error and exits program.
121 */
122 void db_error(MYSQL *connection, const char *when);
123#ifdef _WIN32
124 void pipe_protocol_callback(char *not_used [[maybe_unused]]);
125#endif
126 void protocol_callback(char *not_used [[maybe_unused]]);
127
128 static bool mysql_inited;
129
132 std::optional<std::string> m_protocol_string;
134 std::optional<std::string> m_bind_addr;
135 std::optional<std::string> m_host;
137 std::optional<std::string> m_mysql_unix_port;
138#if defined(_WIN32)
139 std::optional<std::string> m_shared_memory_base_name;
140#endif
141 std::optional<std::string> m_default_auth;
142 std::optional<std::string> m_plugin_dir;
146 std::optional<std::string> m_user;
147 std::optional<std::string> m_password[3];
148 std::optional<std::string> m_default_charset;
149 std::optional<std::string> m_server_public_key;
152 std::optional<std::string> m_compress_algorithm;
153};
154
155} // namespace Options
156} // namespace Base
157} // namespace Tools
158} // namespace Mysql
159
160#endif
Base class for all MySQL client tools.
Definition: abstract_program.h:47
Interface for classes that are capable of creating connection to MySQL database server.
Definition: i_connection_factory.h:39
Common abstract class for options providers.
Definition: abstract_options_provider.h:55
Provider that aggregates options from other providers.
Definition: composite_options_provider.h:41
Options provider enclosing options related to SSL settings of connection to MySQL server.
Definition: mysql_connection_options.h:54
std::optional< std::string > m_ssl_mode_string
Definition: mysql_connection_options.h:73
bool check_connection(MYSQL *connection)
Checks the connection for SSL validity.
Definition: ssl_options.cc:108
void fips_mode_option_callback(char *argument)
Definition: ssl_options.cc:93
void create_options() override
Creates all options that will be provided.
Definition: ssl_options.cc:38
void ca_option_callback(char *argument)
Definition: ssl_options.cc:82
std::optional< std::string > m_ssl_fips_mode_string
Definition: mysql_connection_options.h:74
void mode_option_callback(char *argument)
Definition: ssl_options.cc:87
bool apply_for_connection(MYSQL *connection)
Applies option values to MYSQL connection structure.
Definition: ssl_options.cc:99
Options provider providing options to specify connection to MySQL server.
Definition: mysql_connection_options.h:48
uint32 m_max_allowed_packet
Definition: mysql_connection_options.h:144
std::optional< std::string > m_mysql_unix_port
Definition: mysql_connection_options.h:137
bool m_get_server_public_key
Definition: mysql_connection_options.h:150
Abstract_program * m_program
Definition: mysql_connection_options.h:131
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:247
uint m_zstd_compress_level
Definition: mysql_connection_options.h:151
CHARSET_INFO * get_current_charset() const
Retrieves charset that will be used in new MySQL connections.
Definition: mysql_connection_options.cc:236
Mysql_connection_options(Abstract_program *program)
Constructs new MySQL server connection options provider.
Definition: mysql_connection_options.cc:53
std::optional< std::string > m_default_auth
Definition: mysql_connection_options.h:141
std::optional< std::string > m_server_public_key
Definition: mysql_connection_options.h:149
std::optional< std::string > m_protocol_string
Definition: mysql_connection_options.h:132
std::optional< std::string > m_password[3]
Definition: mysql_connection_options.h:147
std::optional< std::string > m_user
Definition: mysql_connection_options.h:146
static bool mysql_inited
Definition: mysql_connection_options.h:128
uint32 m_mysql_port
Definition: mysql_connection_options.h:136
uint32 m_protocol
Definition: mysql_connection_options.h:133
std::optional< std::string > m_compress_algorithm
Definition: mysql_connection_options.h:152
void db_error(MYSQL *connection, const char *when)
Prints database connection error and exits program.
Definition: mysql_connection_options.cc:269
void set_current_charset(CHARSET_INFO *charset)
Sets charset that will be used in new MySQL connections.
Definition: mysql_connection_options.cc:243
std::optional< std::string > m_default_charset
Definition: mysql_connection_options.h:148
std::optional< std::string > m_bind_addr
Definition: mysql_connection_options.h:134
std::optional< std::string > m_plugin_dir
Definition: mysql_connection_options.h:142
MYSQL * create_connection() override
Provides new connection to MySQL database server based on option values.
Definition: mysql_connection_options.cc:158
std::optional< std::string > m_host
Definition: mysql_connection_options.h:135
void create_options() override
Creates all options that will be provided.
Definition: mysql_connection_options.cc:64
Ssl_options m_ssl_options_provider
Definition: mysql_connection_options.h:130
uint32 m_net_buffer_length
Definition: mysql_connection_options.h:143
bool m_compress
Definition: mysql_connection_options.h:145
void protocol_callback(char *not_used)
Definition: mysql_connection_options.cc:263
Header for compiler-dependent features.
Some integer typedefs for easier portability.
uint32_t uint32
Definition: my_inttypes.h:67
constexpr pos_type Options
Definition: http_request.h:261
Definition: abstract_connection_program.h:38
const std::string charset("charset")
Definition: m_ctype.h:385
Definition: mysql.h:299
unsigned int uint
Definition: uca9-dump.cc:75