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