MySQL 8.4.3
Source Code Documentation
client_plugin.h
Go to the documentation of this file.
1#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
2/* Copyright (c) 2010, 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 Without limiting anything contained in the foregoing, this file,
17 which is part of C Driver for MySQL (Connector/C), is also subject to the
18 Universal FOSS Exception, version 1.0, a copy of which can be found at
19 http://oss.oracle.com/licenses/universal-foss-exception.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License, version 2.0, for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
29
30/**
31 @file include/mysql/client_plugin.h
32 MySQL Client Plugin API.
33 This file defines the API for plugins that work on the client side
34*/
35#define MYSQL_CLIENT_PLUGIN_INCLUDED
36
37#ifndef MYSQL_ABI_CHECK
38#include <stdarg.h>
39#include <stdlib.h>
40#endif
41
42/*
43 On Windows, exports from DLL need to be declared.
44 Also, plugin needs to be declared as extern "C" because MSVC
45 unlike other compilers, uses C++ mangling for variables not only
46 for functions.
47*/
48
49#if defined(_MSC_VER)
50#if defined(MYSQL_DYNAMIC_CLIENT_PLUGIN)
51#ifdef __cplusplus
52#define MYSQL_CLIENT_PLUGIN_EXPORT extern "C" __declspec(dllexport)
53#else
54#define MYSQL_CLIENT_PLUGIN_EXPORT __declspec(dllexport)
55#endif
56#else /* MYSQL_DYNAMIC_CLIENT_PLUGIN */
57#ifdef __cplusplus
58#define MYSQL_CLIENT_PLUGIN_EXPORT extern "C"
59#else
60#define MYSQL_CLIENT_PLUGIN_EXPORT
61#endif
62#endif /*MYSQL_DYNAMIC_CLIENT_PLUGIN */
63#else /*_MSC_VER */
64
65#if defined(MYSQL_DYNAMIC_CLIENT_PLUGIN)
66#define MYSQL_CLIENT_PLUGIN_EXPORT MY_ATTRIBUTE((visibility("default")))
67#else
68#define MYSQL_CLIENT_PLUGIN_EXPORT
69#endif
70
71#endif
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77/* known plugin types */
78#define MYSQL_CLIENT_reserved1 0
79#define MYSQL_CLIENT_reserved2 1
80#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
81#define MYSQL_CLIENT_TRACE_PLUGIN 3
82#define MYSQL_CLIENT_TELEMETRY_PLUGIN 4
83
84#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0200
85#define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0200
86#define MYSQL_CLIENT_TELEMETRY_PLUGIN_INTERFACE_VERSION 0x0200
87
88#define MYSQL_CLIENT_MAX_PLUGINS 5
89
90#define MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE "Oracle Corporation"
91
92#define mysql_declare_client_plugin(X) \
93 MYSQL_CLIENT_PLUGIN_EXPORT st_mysql_client_plugin_##X \
94 _mysql_client_plugin_declaration_ = { \
95 MYSQL_CLIENT_##X##_PLUGIN, \
96 MYSQL_CLIENT_##X##_PLUGIN_INTERFACE_VERSION,
97#define mysql_end_client_plugin }
98
99/* generic plugin header structure */
100#define MYSQL_CLIENT_PLUGIN_HEADER \
101 int type; \
102 unsigned int interface_version; \
103 const char *name; \
104 const char *author; \
105 const char *desc; \
106 unsigned int version[3]; \
107 const char *license; \
108 void *mysql_api; \
109 int (*init)(char *, size_t, int, va_list); \
110 int (*deinit)(void); \
111 int (*options)(const char *option, const void *); \
112 int (*get_options)(const char *option, void *);
113
116};
117
118struct MYSQL;
119
120/******** authentication plugin specific declarations *********/
121#include "plugin_auth_common.h"
122
127 struct MYSQL *mysql,
128 int *result);
129};
130
131// Needed for the mysql_declare_client_plugin() macro. Do not use elsewhere.
133
134/******** using plugins ************/
135
136/**
137 loads a plugin and initializes it
138
139 @param mysql MYSQL structure.
140 @param name a name of the plugin to load
141 @param type type of plugin that should be loaded, -1 to disable type check
142 @param argc number of arguments to pass to the plugin initialization
143 function
144 @param ... arguments for the plugin initialization function
145
146 @retval
147 a pointer to the loaded plugin, or NULL in case of a failure
148*/
150 const char *name, int type,
151 int argc, ...);
152
153/**
154 loads a plugin and initializes it, taking va_list as an argument
155
156 This is the same as mysql_load_plugin, but take va_list instead of
157 a list of arguments.
158
159 @param mysql MYSQL structure.
160 @param name a name of the plugin to load
161 @param type type of plugin that should be loaded, -1 to disable type check
162 @param argc number of arguments to pass to the plugin initialization
163 function
164 @param args arguments for the plugin initialization function
165
166 @retval
167 a pointer to the loaded plugin, or NULL in case of a failure
168*/
170 const char *name, int type,
171 int argc, va_list args);
172
173/**
174 finds an already loaded plugin by name, or loads it, if necessary
175
176 @param mysql MYSQL structure.
177 @param name a name of the plugin to load
178 @param type type of plugin that should be loaded
179
180 @retval
181 a pointer to the plugin, or NULL in case of a failure
182*/
184 const char *name,
185 int type);
186
187/**
188 adds a plugin structure to the list of loaded plugins
189
190 This is useful if an application has the necessary functionality
191 (for example, a special load data handler) statically linked into
192 the application binary. It can use this function to register the plugin
193 directly, avoiding the need to factor it out into a shared object.
194
195 @param mysql MYSQL structure. It is only used for error reporting
196 @param plugin an st_mysql_client_plugin structure to register
197
198 @retval
199 a pointer to the plugin, or NULL in case of a failure
200*/
202 struct MYSQL *mysql, struct st_mysql_client_plugin *plugin);
203
204/**
205 set plugin options
206
207 Can be used to set extra options and affect behavior for a plugin.
208 This function may be called multiple times to set several options
209
210 @param plugin an st_mysql_client_plugin structure
211 @param option a string which specifies the option to set
212 @param value value for the option.
213
214 @retval 0 on success, 1 in case of failure
215**/
217 const char *option, const void *value);
218
219/**
220 get plugin options
221
222 Can be used to get options from a plugin.
223 This function may be called multiple times to get several options
224
225 @param plugin an st_mysql_client_plugin structure
226 @param option a string which specifies the option to get
227 @param[out] value value for the option.
228
229 @retval 0 on success, 1 in case of failure
230**/
232 const char *option, void *value);
233
234#ifdef __cplusplus
235}
236#endif
237
238#endif
struct st_mysql_client_plugin * mysql_load_plugin(struct MYSQL *mysql, const char *name, int type, int argc,...)
loads a plugin and initializes it
Definition: client_plugin.cc:619
struct st_mysql_client_plugin * mysql_load_plugin_v(struct MYSQL *mysql, const char *name, int type, int argc, va_list args)
loads a plugin and initializes it, taking va_list as an argument
Definition: client_plugin.cc:475
int mysql_plugin_get_option(struct st_mysql_client_plugin *plugin, const char *option, void *value)
get plugin options
Definition: client_plugin.cc:666
struct st_mysql_client_plugin * mysql_client_register_plugin(struct MYSQL *mysql, struct st_mysql_client_plugin *plugin)
adds a plugin structure to the list of loaded plugins
Definition: client_plugin.cc:397
int mysql_plugin_options(struct st_mysql_client_plugin *plugin, const char *option, const void *value)
set plugin options
Definition: client_plugin.cc:657
struct st_mysql_client_plugin * mysql_client_find_plugin(struct MYSQL *mysql, const char *name, int type)
finds an already loaded plugin by name, or loads it, if necessary
Definition: client_plugin.cc:630
#define MYSQL_CLIENT_PLUGIN_HEADER
Definition: client_plugin.h:100
static MYSQL * mysql
Definition: mysqldump.cc:147
Definition: instrumented_condition_variable.h:32
struct result result
Definition: result.h:34
This file defines constants and data structures that are the same for both client- and server-side au...
net_async_status
Definition: plugin_auth_common.h:136
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:146
Definition: mysql.h:300
Definition: client_plugin.h:123
enum net_async_status(* authenticate_user_nonblocking)(MYSQL_PLUGIN_VIO *vio, struct MYSQL *mysql, int *result)
Definition: client_plugin.h:126
MYSQL_CLIENT_PLUGIN_HEADER int(* authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct MYSQL *mysql)
Definition: client_plugin.h:125
Definition: client_plugin.h:114