1/* Copyright (c) 2005, 2013, Oracle and/or its affiliates
2 Copyright (C) 2009, 2017, MariaDB
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 as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#ifndef MYSQL_PLUGIN_INCLUDED
18#define MYSQL_PLUGIN_INCLUDED
19
20/*
21 On Windows, exports from DLL need to be declared
22 Also, plugin needs to be declared as extern "C" because MSVC
23 unlike other compilers, uses C++ mangling for variables not only
24 for functions.
25*/
26#if defined(_MSC_VER)
27 #ifdef __cplusplus
28 #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
29 #else
30 #define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
31 #endif
32#else /*_MSC_VER */
33 #ifdef __cplusplus
34 #define MYSQL_PLUGIN_EXPORT extern "C"
35 #else
36 #define MYSQL_PLUGIN_EXPORT
37 #endif
38#endif
39
40#ifdef __cplusplus
41class THD;
42class Item;
43#define MYSQL_THD THD*
44#else
45#define MYSQL_THD void*
46#endif
47
48typedef char my_bool;
49typedef void * MYSQL_PLUGIN;
50
51#include <mysql/services.h>
52
53#define MYSQL_XIDDATASIZE 128
54/**
55 struct st_mysql_xid is binary compatible with the XID structure as
56 in the X/Open CAE Specification, Distributed Transaction Processing:
57 The XA Specification, X/Open Company Ltd., 1991.
58 http://www.opengroup.org/bookstore/catalog/c193.htm
59
60 @see XID in sql/handler.h
61*/
62struct st_mysql_xid {
63 long formatID;
64 long gtrid_length;
65 long bqual_length;
66 char data[MYSQL_XIDDATASIZE]; /* Not \0-terminated */
67};
68typedef struct st_mysql_xid MYSQL_XID;
69
70/*************************************************************************
71 Plugin API. Common for all plugin types.
72*/
73
74/* MySQL plugin interface version */
75#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0104
76
77/* MariaDB plugin interface version */
78#define MARIA_PLUGIN_INTERFACE_VERSION 0x010d
79
80/*
81 The allowable types of plugins
82*/
83#define MYSQL_UDF_PLUGIN 0 /* not implemented */
84#define MYSQL_STORAGE_ENGINE_PLUGIN 1
85#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */
86#define MYSQL_DAEMON_PLUGIN 3
87#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4
88#define MYSQL_AUDIT_PLUGIN 5
89#define MYSQL_REPLICATION_PLUGIN 6
90#define MYSQL_AUTHENTICATION_PLUGIN 7
91#define MYSQL_MAX_PLUGIN_TYPE_NUM 10 /* The number of plugin types */
92
93/* MariaDB plugin types */
94#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8
95#define MariaDB_ENCRYPTION_PLUGIN 9
96
97/* We use the following strings to define licenses for plugins */
98#define PLUGIN_LICENSE_PROPRIETARY 0
99#define PLUGIN_LICENSE_GPL 1
100#define PLUGIN_LICENSE_BSD 2
101
102#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
103#define PLUGIN_LICENSE_GPL_STRING "GPL"
104#define PLUGIN_LICENSE_BSD_STRING "BSD"
105
106/* definitions of code maturity for plugins */
107#define MariaDB_PLUGIN_MATURITY_UNKNOWN 0
108#define MariaDB_PLUGIN_MATURITY_EXPERIMENTAL 1
109#define MariaDB_PLUGIN_MATURITY_ALPHA 2
110#define MariaDB_PLUGIN_MATURITY_BETA 3
111#define MariaDB_PLUGIN_MATURITY_GAMMA 4
112#define MariaDB_PLUGIN_MATURITY_STABLE 5
113
114/*
115 Macros for beginning and ending plugin declarations. Between
116 mysql_declare_plugin and mysql_declare_plugin_end there should
117 be a st_mysql_plugin struct for each plugin to be declared.
118*/
119
120
121#ifndef MYSQL_DYNAMIC_PLUGIN
122#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
123int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
124int PSIZE= sizeof(struct st_mysql_plugin); \
125struct st_mysql_plugin DECLS[]= {
126
127#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \
128MYSQL_PLUGIN_EXPORT int VERSION; \
129int VERSION= MARIA_PLUGIN_INTERFACE_VERSION; \
130MYSQL_PLUGIN_EXPORT int PSIZE; \
131int PSIZE= sizeof(struct st_maria_plugin); \
132MYSQL_PLUGIN_EXPORT struct st_maria_plugin DECLS[]; \
133struct st_maria_plugin DECLS[]= {
134#else
135
136#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
137MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_; \
138int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
139MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_; \
140int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
141MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]; \
142struct st_mysql_plugin _mysql_plugin_declarations_[]= {
143
144#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \
145MYSQL_PLUGIN_EXPORT int _maria_plugin_interface_version_; \
146int _maria_plugin_interface_version_= MARIA_PLUGIN_INTERFACE_VERSION; \
147MYSQL_PLUGIN_EXPORT int _maria_sizeof_struct_st_plugin_; \
148int _maria_sizeof_struct_st_plugin_= sizeof(struct st_maria_plugin); \
149MYSQL_PLUGIN_EXPORT struct st_maria_plugin _maria_plugin_declarations_[]; \
150struct st_maria_plugin _maria_plugin_declarations_[]= {
151
152#endif
153
154#define mysql_declare_plugin(NAME) \
155__MYSQL_DECLARE_PLUGIN(NAME, \
156 builtin_ ## NAME ## _plugin_interface_version, \
157 builtin_ ## NAME ## _sizeof_struct_st_plugin, \
158 builtin_ ## NAME ## _plugin)
159
160#define maria_declare_plugin(NAME) \
161MARIA_DECLARE_PLUGIN__(NAME, \
162 builtin_maria_ ## NAME ## _plugin_interface_version, \
163 builtin_maria_ ## NAME ## _sizeof_struct_st_plugin, \
164 builtin_maria_ ## NAME ## _plugin)
165
166#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}}
167#define maria_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}}
168
169/*
170 declarations for SHOW STATUS support in plugins
171*/
172enum enum_mysql_show_type
173{
174 SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG,
175 SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
176 SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE,
177 SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
178 SHOW_always_last
179};
180
181/* backward compatibility mapping. */
182#define SHOW_INT SHOW_UINT
183#define SHOW_LONG SHOW_ULONG
184#define SHOW_LONGLONG SHOW_ULONGLONG
185
186enum enum_var_type
187{
188 SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
189};
190
191struct st_mysql_show_var {
192 const char *name;
193 void *value;
194 enum enum_mysql_show_type type;
195};
196
197struct system_status_var;
198
199#define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*))
200typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type);
201
202
203/*
204 Constants for plugin flags.
205 */
206
207#define PLUGIN_OPT_NO_INSTALL 1UL /* Not dynamically loadable */
208#define PLUGIN_OPT_NO_UNINSTALL 2UL /* Not dynamically unloadable */
209
210
211/*
212 declarations for server variables and command line options
213*/
214
215
216#define PLUGIN_VAR_BOOL 0x0001
217#define PLUGIN_VAR_INT 0x0002
218#define PLUGIN_VAR_LONG 0x0003
219#define PLUGIN_VAR_LONGLONG 0x0004
220#define PLUGIN_VAR_STR 0x0005
221#define PLUGIN_VAR_ENUM 0x0006
222#define PLUGIN_VAR_SET 0x0007
223#define PLUGIN_VAR_DOUBLE 0x0008
224#define PLUGIN_VAR_UNSIGNED 0x0080
225#define PLUGIN_VAR_THDLOCAL 0x0100 /* Variable is per-connection */
226#define PLUGIN_VAR_READONLY 0x0200 /* Server variable is read only */
227#define PLUGIN_VAR_NOSYSVAR 0x0400 /* Not a server variable */
228#define PLUGIN_VAR_NOCMDOPT 0x0800 /* Not a command line option */
229#define PLUGIN_VAR_NOCMDARG 0x1000 /* No argument for cmd line */
230#define PLUGIN_VAR_RQCMDARG 0x0000 /* Argument required for cmd line */
231#define PLUGIN_VAR_OPCMDARG 0x2000 /* Argument optional for cmd line */
232#define PLUGIN_VAR_MEMALLOC 0x8000 /* String needs memory allocated */
233
234struct st_mysql_sys_var;
235struct st_mysql_value;
236
237/*
238 SYNOPSIS
239 (*mysql_var_check_func)()
240 thd thread handle
241 var dynamic variable being altered
242 save pointer to temporary storage
243 value user provided value
244 RETURN
245 0 user provided value is OK and the update func may be called.
246 any other value indicates error.
247
248 This function should parse the user provided value and store in the
249 provided temporary storage any data as required by the update func.
250 There is sufficient space in the temporary storage to store a double.
251 Note that the update func may not be called if any other error occurs
252 so any memory allocated should be thread-local so that it may be freed
253 automatically at the end of the statement.
254*/
255
256typedef int (*mysql_var_check_func)(MYSQL_THD thd,
257 struct st_mysql_sys_var *var,
258 void *save, struct st_mysql_value *value);
259
260/*
261 SYNOPSIS
262 (*mysql_var_update_func)()
263 thd thread handle
264 var dynamic variable being altered
265 var_ptr pointer to dynamic variable
266 save pointer to temporary storage
267 RETURN
268 NONE
269
270 This function should use the validated value stored in the temporary store
271 and persist it in the provided pointer to the dynamic variable.
272 For example, strings may require memory to be allocated.
273*/
274typedef void (*mysql_var_update_func)(MYSQL_THD thd,
275 struct st_mysql_sys_var *var,
276 void *var_ptr, const void *save);
277
278
279/* the following declarations are for internal use only */
280
281
282#define PLUGIN_VAR_MASK \
283 (PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
284 PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
285 PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
286
287#define MYSQL_PLUGIN_VAR_HEADER \
288 int flags; \
289 const char *name; \
290 const char *comment; \
291 mysql_var_check_func check; \
292 mysql_var_update_func update
293
294#define MYSQL_SYSVAR_NAME(name) mysql_sysvar_ ## name
295#define MYSQL_SYSVAR(name) \
296 ((struct st_mysql_sys_var *)&(MYSQL_SYSVAR_NAME(name)))
297
298/*
299 for global variables, the value pointer is the first
300 element after the header, the default value is the second.
301 for thread variables, the value offset is the first
302 element after the header, the default value is the second.
303*/
304
305
306#define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
307 MYSQL_PLUGIN_VAR_HEADER; \
308 type *value; \
309 const type def_val; \
310} MYSQL_SYSVAR_NAME(name)
311
312#define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
313 MYSQL_PLUGIN_VAR_HEADER; \
314 type *value; type def_val; \
315 type min_val; type max_val; \
316 type blk_sz; \
317} MYSQL_SYSVAR_NAME(name)
318
319#define DECLARE_MYSQL_SYSVAR_TYPELIB(name, type) struct { \
320 MYSQL_PLUGIN_VAR_HEADER; \
321 type *value; type def_val; \
322 TYPELIB *typelib; \
323} MYSQL_SYSVAR_NAME(name)
324
325#define DECLARE_THDVAR_FUNC(type) \
326 type *(*resolve)(MYSQL_THD thd, int offset)
327
328#define DECLARE_MYSQL_THDVAR_BASIC(name, type) struct { \
329 MYSQL_PLUGIN_VAR_HEADER; \
330 int offset; \
331 const type def_val; \
332 DECLARE_THDVAR_FUNC(type); \
333} MYSQL_SYSVAR_NAME(name)
334
335#define DECLARE_MYSQL_THDVAR_SIMPLE(name, type) struct { \
336 MYSQL_PLUGIN_VAR_HEADER; \
337 int offset; \
338 type def_val; type min_val; \
339 type max_val; type blk_sz; \
340 DECLARE_THDVAR_FUNC(type); \
341} MYSQL_SYSVAR_NAME(name)
342
343#define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
344 MYSQL_PLUGIN_VAR_HEADER; \
345 int offset; \
346 const type def_val; \
347 DECLARE_THDVAR_FUNC(type); \
348 TYPELIB *typelib; \
349} MYSQL_SYSVAR_NAME(name)
350
351
352/*
353 the following declarations are for use by plugin implementors
354*/
355
356#define MYSQL_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
357DECLARE_MYSQL_SYSVAR_BASIC(name, char) = { \
358 PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
359 #name, comment, check, update, &varname, def}
360
361#define MYSQL_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
362DECLARE_MYSQL_SYSVAR_BASIC(name, char *) = { \
363 PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
364 #name, comment, check, update, &varname, def}
365
366#define MYSQL_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
367DECLARE_MYSQL_SYSVAR_SIMPLE(name, int) = { \
368 PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
369 #name, comment, check, update, &varname, def, min, max, blk }
370
371#define MYSQL_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
372DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned int) = { \
373 PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
374 #name, comment, check, update, &varname, def, min, max, blk }
375
376#define MYSQL_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
377DECLARE_MYSQL_SYSVAR_SIMPLE(name, long) = { \
378 PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
379 #name, comment, check, update, &varname, def, min, max, blk }
380
381#define MYSQL_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
382DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long) = { \
383 PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
384 #name, comment, check, update, &varname, def, min, max, blk }
385
386#define MYSQL_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
387DECLARE_MYSQL_SYSVAR_SIMPLE(name, long long) = { \
388 PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
389 #name, comment, check, update, &varname, def, min, max, blk }
390
391#define MYSQL_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
392DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long long) = { \
393 PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
394 #name, comment, check, update, &varname, def, min, max, blk }
395
396#define MYSQL_SYSVAR_UINT64_T(name, varname, opt, comment, check, update, def, min, max, blk) \
397DECLARE_MYSQL_SYSVAR_SIMPLE(name, uint64_t) = { \
398 PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
399 #name, comment, check, update, &varname, def, min, max, blk }
400
401#ifdef _WIN64
402#define MYSQL_SYSVAR_SIZE_T(name, varname, opt, comment, check, update, def, min, max, blk) \
403DECLARE_MYSQL_SYSVAR_SIMPLE(name, size_t) = { \
404 PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
405 #name, comment, check, update, &varname, def, min, max, blk }
406#else
407#define MYSQL_SYSVAR_SIZE_T(name, varname, opt, comment, check, update, def, min, max, blk) \
408DECLARE_MYSQL_SYSVAR_SIMPLE(name, size_t) = { \
409 PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
410 #name, comment, check, update, &varname, def, min, max, blk }
411#endif
412
413#define MYSQL_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
414DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long) = { \
415 PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
416 #name, comment, check, update, &varname, def, typelib }
417
418#define MYSQL_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
419DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long long) = { \
420 PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
421 #name, comment, check, update, &varname, def, typelib }
422
423#define MYSQL_SYSVAR_DOUBLE(name, varname, opt, comment, check, update, def, min, max, blk) \
424DECLARE_MYSQL_SYSVAR_SIMPLE(name, double) = { \
425 PLUGIN_VAR_DOUBLE | ((opt) & PLUGIN_VAR_MASK), \
426 #name, comment, check, update, &varname, def, min, max, blk }
427
428#define MYSQL_THDVAR_BOOL(name, opt, comment, check, update, def) \
429DECLARE_MYSQL_THDVAR_BASIC(name, char) = { \
430 PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
431 #name, comment, check, update, -1, def, NULL}
432
433#define MYSQL_THDVAR_STR(name, opt, comment, check, update, def) \
434DECLARE_MYSQL_THDVAR_BASIC(name, char *) = { \
435 PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
436 #name, comment, check, update, -1, def, NULL}
437
438#define MYSQL_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
439DECLARE_MYSQL_THDVAR_SIMPLE(name, int) = { \
440 PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
441 #name, comment, check, update, -1, def, min, max, blk, NULL }
442
443#define MYSQL_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
444DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned int) = { \
445 PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
446 #name, comment, check, update, -1, def, min, max, blk, NULL }
447
448#define MYSQL_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
449DECLARE_MYSQL_THDVAR_SIMPLE(name, long) = { \
450 PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
451 #name, comment, check, update, -1, def, min, max, blk, NULL }
452
453#define MYSQL_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
454DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long) = { \
455 PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
456 #name, comment, check, update, -1, def, min, max, blk, NULL }
457
458#define MYSQL_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
459DECLARE_MYSQL_THDVAR_SIMPLE(name, long long) = { \
460 PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
461 #name, comment, check, update, -1, def, min, max, blk, NULL }
462
463#define MYSQL_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
464DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long long) = { \
465 PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
466 #name, comment, check, update, -1, def, min, max, blk, NULL }
467
468#define MYSQL_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
469DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long) = { \
470 PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
471 #name, comment, check, update, -1, def, NULL, typelib }
472
473#define MYSQL_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
474DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long long) = { \
475 PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
476 #name, comment, check, update, -1, def, NULL, typelib }
477
478#define MYSQL_THDVAR_DOUBLE(name, opt, comment, check, update, def, min, max, blk) \
479DECLARE_MYSQL_THDVAR_SIMPLE(name, double) = { \
480 PLUGIN_VAR_DOUBLE | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
481 #name, comment, check, update, -1, def, min, max, blk, NULL }
482
483/* accessor macros */
484
485#define SYSVAR(name) \
486 (*(MYSQL_SYSVAR_NAME(name).value))
487
488/* when thd == null, result points to global value */
489#define THDVAR(thd, name) \
490 (*(MYSQL_SYSVAR_NAME(name).resolve(thd, MYSQL_SYSVAR_NAME(name).offset)))
491
492
493/*
494 Plugin description structure.
495*/
496
497struct st_mysql_plugin
498{
499 int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
500 void *info; /* pointer to type-specific plugin descriptor */
501 const char *name; /* plugin name */
502 const char *author; /* plugin author (for I_S.PLUGINS) */
503 const char *descr; /* general descriptive text (for I_S.PLUGINS) */
504 int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
505 int (*init)(void *); /* the function to invoke when plugin is loaded */
506 int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
507 unsigned int version; /* plugin version (for I_S.PLUGINS) */
508 struct st_mysql_show_var *status_vars;
509 struct st_mysql_sys_var **system_vars;
510 void * __reserved1; /* reserved for dependency checking */
511 unsigned long flags; /* flags for plugin */
512};
513
514/*
515 MariaDB extension for plugins declaration structure.
516
517 It also copy current MySQL plugin fields to have more independency
518 in plugins extension
519*/
520
521struct st_maria_plugin
522{
523 int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
524 void *info; /* pointer to type-specific plugin descriptor */
525 const char *name; /* plugin name */
526 const char *author; /* plugin author (for SHOW PLUGINS) */
527 const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
528 int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
529 int (*init)(void *); /* the function to invoke when plugin is loaded */
530 int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
531 unsigned int version; /* plugin version (for SHOW PLUGINS) */
532 struct st_mysql_show_var *status_vars;
533 struct st_mysql_sys_var **system_vars;
534 const char *version_info; /* plugin version string */
535 unsigned int maturity; /* MariaDB_PLUGIN_MATURITY_XXX */
536};
537
538/*************************************************************************
539 API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
540*/
541#include "plugin_ftparser.h"
542
543/*************************************************************************
544 API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
545*/
546
547/* handlertons of different MySQL releases are incompatible */
548#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
549
550/*
551 Here we define only the descriptor structure, that is referred from
552 st_mysql_plugin.
553*/
554
555struct st_mysql_daemon
556{
557 int interface_version;
558};
559
560
561/*************************************************************************
562 API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
563*/
564
565/* handlertons of different MySQL releases are incompatible */
566#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
567
568/*
569 Here we define only the descriptor structure, that is referred from
570 st_mysql_plugin.
571*/
572
573struct st_mysql_information_schema
574{
575 int interface_version;
576};
577
578
579/*************************************************************************
580 API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
581*/
582
583/* handlertons of different MySQL releases are incompatible */
584#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
585
586/*
587 The real API is in the sql/handler.h
588 Here we define only the descriptor structure, that is referred from
589 st_mysql_plugin.
590*/
591
592struct st_mysql_storage_engine
593{
594 int interface_version;
595};
596
597struct handlerton;
598
599
600/*
601 API for Replication plugin. (MYSQL_REPLICATION_PLUGIN)
602*/
603 #define MYSQL_REPLICATION_INTERFACE_VERSION 0x0200
604
605 /**
606 Replication plugin descriptor
607 */
608 struct Mysql_replication {
609 int interface_version;
610 };
611
612/*************************************************************************
613 st_mysql_value struct for reading values from mysqld.
614 Used by server variables framework to parse user-provided values.
615 Will be used for arguments when implementing UDFs.
616
617 Note that val_str() returns a string in temporary memory
618 that will be freed at the end of statement. Copy the string
619 if you need it to persist.
620*/
621
622#define MYSQL_VALUE_TYPE_STRING 0
623#define MYSQL_VALUE_TYPE_REAL 1
624#define MYSQL_VALUE_TYPE_INT 2
625
626struct st_mysql_value
627{
628 int (*value_type)(struct st_mysql_value *);
629 const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
630 int (*val_real)(struct st_mysql_value *, double *realbuf);
631 int (*val_int)(struct st_mysql_value *, long long *intbuf);
632 int (*is_unsigned)(struct st_mysql_value *);
633};
634
635
636/*************************************************************************
637 Miscellaneous functions for plugin implementors
638*/
639
640#ifdef __cplusplus
641extern "C" {
642#endif
643
644int thd_in_lock_tables(const MYSQL_THD thd);
645int thd_tablespace_op(const MYSQL_THD thd);
646long long thd_test_options(const MYSQL_THD thd, long long test_options);
647int thd_sql_command(const MYSQL_THD thd);
648void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
649void thd_storage_lock_wait(MYSQL_THD thd, long long value);
650int thd_tx_isolation(const MYSQL_THD thd);
651int thd_tx_is_read_only(const MYSQL_THD thd);
652/**
653 Create a temporary file.
654
655 @details
656 The temporary file is created in a location specified by the mysql
657 server configuration (--tmpdir option). The caller does not need to
658 delete the file, it will be deleted automatically.
659
660 @param prefix prefix for temporary file name
661 @retval -1 error
662 @retval >= 0 a file handle that can be passed to dup or my_close
663*/
664int mysql_tmpfile(const char *prefix);
665
666/**
667 Return the thread id of a user thread
668
669 @param thd user thread connection handle
670 @return thread id
671*/
672unsigned long thd_get_thread_id(const MYSQL_THD thd);
673
674/**
675 Get the XID for this connection's transaction
676
677 @param thd user thread connection handle
678 @param xid location where identifier is stored
679*/
680void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
681
682/**
683 Invalidate the query cache for a given table.
684
685 @param thd user thread connection handle
686 @param key databasename\\0tablename\\0
687 @param key_length length of key in bytes, including the NUL bytes
688 @param using_trx flag: TRUE if using transactions, FALSE otherwise
689*/
690void mysql_query_cache_invalidate4(MYSQL_THD thd,
691 const char *key, unsigned int key_length,
692 int using_trx);
693
694
695/**
696 Provide a handler data getter to simplify coding
697*/
698void *thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
699
700
701/**
702 Provide a handler data setter to simplify coding
703
704 @details
705 Set ha_data pointer (storage engine per-connection information).
706
707 To avoid unclean deactivation (uninstall) of storage engine plugin
708 in the middle of transaction, additional storage engine plugin
709 lock is acquired.
710
711 If ha_data is not null and storage engine plugin was not locked
712 by thd_set_ha_data() in this connection before, storage engine
713 plugin gets locked.
714
715 If ha_data is null and storage engine plugin was locked by
716 thd_set_ha_data() in this connection before, storage engine
717 plugin lock gets released.
718
719 If handlerton::close_connection() didn't reset ha_data, server does
720 it immediately after calling handlerton::close_connection().
721*/
722void thd_set_ha_data(MYSQL_THD thd, const struct handlerton *hton,
723 const void *ha_data);
724
725
726/**
727 Signal that the first part of handler commit is finished, and that the
728 committed transaction is now visible and has fixed commit ordering with
729 respect to other transactions. The commit need _not_ be durable yet, and
730 typically will not be when this call makes sense.
731
732 This call is optional, if the storage engine does not call it the upper
733 layer will after the handler commit() method is done. However, the storage
734 engine may choose to call it itself to increase the possibility for group
735 commit.
736
737 In-order parallel replication uses this to apply different transaction in
738 parallel, but delay the commits of later transactions until earlier
739 transactions have committed first, thus achieving increased performance on
740 multi-core systems while still preserving full transaction consistency.
741
742 The storage engine can call this from within the commit() method, typically
743 after the commit record has been written to the transaction log, but before
744 the log has been fsync()'ed. This will allow the next replicated transaction
745 to proceed to commit before the first one has done fsync() or similar. Thus,
746 it becomes possible for multiple sequential replicated transactions to share
747 a single fsync() inside the engine in group commit.
748
749 Note that this method should _not_ be called from within the commit_ordered()
750 method, or any other place in the storage engine. When commit_ordered() is
751 used (typically when binlog is enabled), the transaction coordinator takes
752 care of this and makes group commit in the storage engine possible without
753 any other action needed on the part of the storage engine. This function
754 thd_wakeup_subsequent_commits() is only needed when no transaction
755 coordinator is used, meaning a single storage engine and no binary log.
756*/
757void thd_wakeup_subsequent_commits(MYSQL_THD thd, int wakeup_error);
758
759#ifdef __cplusplus
760}
761#endif
762
763#endif
764
765