9
3

plugin.h 27 KB

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