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