MySQL 8.0.31
Source Code Documentation
builtin_plugins.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2022, 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 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_HARNESS_BUILTIN_PLUGINS_INCLUDED
26#define MYSQL_HARNESS_BUILTIN_PLUGINS_INCLUDED
27
28#include "mysql/harness/plugin.h"
29
30#include "harness_export.h"
31
32#include <map>
33#include <string>
34
35namespace mysql_harness {
36
37/**
38 * @brief Singleton class implementing registry of the built-in MySQLRouter
39 * plugins.
40 *
41 * Built-in plugin is statically linked to the harness library (does not have
42 * dedicated .so or .dll file) but implements the same API as the external
43 * plugin (init(), start(), etc.) that is called by the Loader.
44 */
45class HARNESS_EXPORT BuiltinPlugins {
46 public:
47 /**
48 * @brief Gets the singleton instance.
49 */
50 static BuiltinPlugins &instance();
51
52 /**
53 * It's a singleton so we disable copying.
54 */
55 BuiltinPlugins(const BuiltinPlugins &) = delete;
57
58 /**
59 * Stores the information about a single built-in plugin.
60 */
61 struct PluginInfo {
62 /**
63 * pointer to the plugin struct (used by the Loader to run init(),
64 * start(), etc on the plugin)
65 */
67
68 /** if true the plugin should ALWAYS be loaded even if it does not have
69 * its section in the configuration
70 */
72 };
73
74 using PluginsMap = std::map<std::string, PluginInfo>;
75
76 /** @brief Checks if there is a built-in plugin with a specified name
77 *
78 * @param plugin_name plugin name to check
79 * @return true if there is a built-in plugin with a given name in the
80 * registry, false otherwise
81 */
82 bool has(const std::string &plugin_name) noexcept;
83
84 /** @brief Returns the map containing information about all built-in plugins
85 * in the registry
86 *
87 * @return map containing information about all built-in plugins in the
88 * registry
89 */
90 const PluginsMap *get() noexcept { return &plugins_; }
91
92 /** @brief Returns pointer to the Plugin struct for the plugin with
93 * selected name
94 *
95 * @throw std::out_of_range if there is no info about the plugin with a given
96 * name.
97 *
98 * @param plugin_name name of the plugin queried for the Plugin struct
99 * @return Plugin struct for the plugin with selected name
100 */
101 Plugin *get_plugin(const std::string &plugin_name) {
102 return plugins_.at(plugin_name).plugin;
103 }
104
105 /**
106 * add plugin to the built in plugins.
107 */
108 void add(std::string name, PluginInfo plugin_info);
109
110 private:
113};
114
115} // namespace mysql_harness
116
117#endif
Singleton class implementing registry of the built-in MySQLRouter plugins.
Definition: builtin_plugins.h:45
BuiltinPlugins & operator=(const BuiltinPlugins &)=delete
Plugin * get_plugin(const std::string &plugin_name)
Returns pointer to the Plugin struct for the plugin with selected name.
Definition: builtin_plugins.h:101
const PluginsMap * get() noexcept
Returns the map containing information about all built-in plugins in the registry.
Definition: builtin_plugins.h:90
PluginsMap plugins_
Definition: builtin_plugins.h:112
std::map< std::string, PluginInfo > PluginsMap
Definition: builtin_plugins.h:74
BuiltinPlugins(const BuiltinPlugins &)=delete
It's a singleton so we disable copying.
Fido Client Authentication Plugin
Definition: fido_client_plugin.cc:220
Definition: common.h:41
static MYSQL_PLUGIN plugin_info
Definition: rewriter_plugin.cc:88
LEX_CSTRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:94
case opt name
Definition: sslopt-case.h:32
Stores the information about a single built-in plugin.
Definition: builtin_plugins.h:61
Plugin * plugin
pointer to the plugin struct (used by the Loader to run init(), start(), etc on the plugin)
Definition: builtin_plugins.h:66
bool always_load
if true the plugin should ALWAYS be loaded even if it does not have its section in the configuration
Definition: builtin_plugins.h:71