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