1#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
2/* Copyright (c) 2010, 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 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#if defined(_MSC_VER)
49#if defined(MYSQL_DYNAMIC_CLIENT_PLUGIN)
50#ifdef __cplusplus
51#define MYSQL_CLIENT_PLUGIN_EXPORT extern "C" __declspec(dllexport)
52#else
53#define MYSQL_CLIENT_PLUGIN_EXPORT __declspec(dllexport)
54#endif
55#else /* MYSQL_DYNAMIC_CLIENT_PLUGIN */
56#ifdef __cplusplus
57#define MYSQL_CLIENT_PLUGIN_EXPORT extern "C"
58#else
59#define MYSQL_CLIENT_PLUGIN_EXPORT
60#endif
61#endif /*MYSQL_DYNAMIC_CLIENT_PLUGIN */
62#else /*_MSC_VER */
63
64#if defined(MYSQL_DYNAMIC_CLIENT_PLUGIN)
65#define MYSQL_CLIENT_PLUGIN_EXPORT MY_ATTRIBUTE((visibility("default")))
66#else
67#define MYSQL_CLIENT_PLUGIN_EXPORT
68#endif
69
70#endif
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76/* known plugin types */
77#define MYSQL_CLIENT_reserved1 0
78#define MYSQL_CLIENT_reserved2 1
79#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
80#define MYSQL_CLIENT_TRACE_PLUGIN 3
81
82#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0200
83#define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0200
84
85#define MYSQL_CLIENT_MAX_PLUGINS 4
86
87#define MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE "Oracle Corporation"
88
89#define mysql_declare_client_plugin(X) \
90 MYSQL_CLIENT_PLUGIN_EXPORT st_mysql_client_plugin_##X \
91 _mysql_client_plugin_declaration_ = { \
92 MYSQL_CLIENT_##X##_PLUGIN, \
93 MYSQL_CLIENT_##X##_PLUGIN_INTERFACE_VERSION,
94#define mysql_end_client_plugin }
95
96/* generic plugin header structure */
97#define MYSQL_CLIENT_PLUGIN_HEADER \
98 int type; \
99 unsigned int interface_version; \
100 const char *name; \
101 const char *author; \
102 const char *desc; \
103 unsigned int version[3]; \
104 const char *license; \
105 void *mysql_api; \
106 int (*init)(char *, size_t, int, va_list); \
107 int (*deinit)(void); \
108 int (*options)(const char *option, const void *); \
109 int (*get_options)(const char *option, void *);
110
111struct st_mysql_client_plugin {
112 MYSQL_CLIENT_PLUGIN_HEADER
113};
114
115struct MYSQL;
116
117/******** authentication plugin specific declarations *********/
118#include "plugin_auth_common.h"
119
120struct auth_plugin_t {
121 MYSQL_CLIENT_PLUGIN_HEADER
122 int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct MYSQL *mysql);
123 enum net_async_status (*authenticate_user_nonblocking)(MYSQL_PLUGIN_VIO *vio,
124 struct MYSQL *mysql,
125 int *result);
126};
127
128// Needed for the mysql_declare_client_plugin() macro. Do not use elsewhere.
129typedef struct auth_plugin_t st_mysql_client_plugin_AUTHENTICATION;
130
131/******** using plugins ************/
132
133/**
134 loads a plugin and initializes it
135
136 @param mysql MYSQL structure.
137 @param name a name of the plugin to load
138 @param type type of plugin that should be loaded, -1 to disable type check
139 @param argc number of arguments to pass to the plugin initialization
140 function
141 @param ... arguments for the plugin initialization function
142
143 @retval
144 a pointer to the loaded plugin, or NULL in case of a failure
145*/
146struct st_mysql_client_plugin *mysql_load_plugin(struct MYSQL *mysql,
147 const char *name, int type,
148 int argc, ...);
149
150/**
151 loads a plugin and initializes it, taking va_list as an argument
152
153 This is the same as mysql_load_plugin, but take va_list instead of
154 a list of arguments.
155
156 @param mysql MYSQL structure.
157 @param name a name of the plugin to load
158 @param type type of plugin that should be loaded, -1 to disable type check
159 @param argc number of arguments to pass to the plugin initialization
160 function
161 @param args arguments for the plugin initialization function
162
163 @retval
164 a pointer to the loaded plugin, or NULL in case of a failure
165*/
166struct st_mysql_client_plugin *mysql_load_plugin_v(struct MYSQL *mysql,
167 const char *name, int type,
168 int argc, va_list args);
169
170/**
171 finds an already loaded plugin by name, or loads it, if necessary
172
173 @param mysql MYSQL structure.
174 @param name a name of the plugin to load
175 @param type type of plugin that should be loaded
176
177 @retval
178 a pointer to the plugin, or NULL in case of a failure
179*/
180struct st_mysql_client_plugin *mysql_client_find_plugin(struct MYSQL *mysql,
181 const char *name,
182 int type);
183
184/**
185 adds a plugin structure to the list of loaded plugins
186
187 This is useful if an application has the necessary functionality
188 (for example, a special load data handler) statically linked into
189 the application binary. It can use this function to register the plugin
190 directly, avoiding the need to factor it out into a shared object.
191
192 @param mysql MYSQL structure. It is only used for error reporting
193 @param plugin an st_mysql_client_plugin structure to register
194
195 @retval
196 a pointer to the plugin, or NULL in case of a failure
197*/
198struct st_mysql_client_plugin *mysql_client_register_plugin(
199 struct MYSQL *mysql, struct st_mysql_client_plugin *plugin);
200
201/**
202 set plugin options
203
204 Can be used to set extra options and affect behavior for a plugin.
205 This function may be called multiple times to set several options
206
207 @param plugin an st_mysql_client_plugin structure
208 @param option a string which specifies the option to set
209 @param value value for the option.
210
211 @retval 0 on success, 1 in case of failure
212**/
213int mysql_plugin_options(struct st_mysql_client_plugin *plugin,
214 const char *option, const void *value);
215
216/**
217 get plugin options
218
219 Can be used to get options from a plugin.
220 This function may be called multiple times to get several options
221
222 @param plugin an st_mysql_client_plugin structure
223 @param option a string which specifies the option to get
224 @param[out] value value for the option.
225
226 @retval 0 on success, 1 in case of failure
227**/
228int mysql_plugin_get_option(struct st_mysql_client_plugin *plugin,
229 const char *option, void *value);
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif
236

source code of include/mysql/client_plugin.h