Clone of PhatAC @ https://github.com/floaterxk/PhatAC

plugin.h 26KB

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