plugin.h 26 KB

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