plugin.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /* Copyright (C) 2005 MySQL AB
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #ifndef _my_plugin_h
  13. #define _my_plugin_h
  14. /*
  15. On Windows, exports from DLL need to be declared
  16. */
  17. #if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
  18. #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
  19. #else
  20. #define MYSQL_PLUGIN_EXPORT
  21. #endif
  22. #ifdef __cplusplus
  23. class THD;
  24. class Item;
  25. #define MYSQL_THD THD*
  26. #else
  27. #define MYSQL_THD void*
  28. #endif
  29. #ifndef _m_string_h
  30. /* This definition must match the one given in m_string.h */
  31. struct st_mysql_lex_string
  32. {
  33. char *str;
  34. unsigned int length;
  35. };
  36. #endif /* _m_string_h */
  37. typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
  38. #define MYSQL_XIDDATASIZE 128
  39. /**
  40. struct st_mysql_xid is binary compatible with the XID structure as
  41. in the X/Open CAE Specification, Distributed Transaction Processing:
  42. The XA Specification, X/Open Company Ltd., 1991.
  43. http://www.opengroup.org/bookstore/catalog/c193.htm
  44. @see XID in sql/handler.h
  45. */
  46. struct st_mysql_xid {
  47. long formatID;
  48. long gtrid_length;
  49. long bqual_length;
  50. char data[MYSQL_XIDDATASIZE]; /* Not \0-terminated */
  51. };
  52. typedef struct st_mysql_xid MYSQL_XID;
  53. /*************************************************************************
  54. Plugin API. Common for all plugin types.
  55. */
  56. #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0100
  57. /*
  58. The allowable types of plugins
  59. */
  60. #define MYSQL_UDF_PLUGIN 0 /* User-defined function */
  61. #define MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */
  62. #define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */
  63. #define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */
  64. #define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
  65. #define MYSQL_MAX_PLUGIN_TYPE_NUM 5 /* The number of plugin types */
  66. /* We use the following strings to define licenses for plugins */
  67. #define PLUGIN_LICENSE_PROPRIETARY 0
  68. #define PLUGIN_LICENSE_GPL 1
  69. #define PLUGIN_LICENSE_BSD 2
  70. #define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
  71. #define PLUGIN_LICENSE_GPL_STRING "GPL"
  72. #define PLUGIN_LICENSE_BSD_STRING "BSD"
  73. /*
  74. Macros for beginning and ending plugin declarations. Between
  75. mysql_declare_plugin and mysql_declare_plugin_end there should
  76. be a st_mysql_plugin struct for each plugin to be declared.
  77. */
  78. #ifndef MYSQL_DYNAMIC_PLUGIN
  79. #define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
  80. int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \
  81. int PSIZE= sizeof(struct st_mysql_plugin); \
  82. struct st_mysql_plugin DECLS[]= {
  83. #else
  84. #define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \
  85. MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
  86. MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
  87. MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]= {
  88. #endif
  89. #define mysql_declare_plugin(NAME) \
  90. __MYSQL_DECLARE_PLUGIN(NAME, \
  91. builtin_ ## NAME ## _plugin_interface_version, \
  92. builtin_ ## NAME ## _sizeof_struct_st_plugin, \
  93. builtin_ ## NAME ## _plugin)
  94. #define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0}}
  95. /*
  96. declarations for SHOW STATUS support in plugins
  97. */
  98. enum enum_mysql_show_type
  99. {
  100. SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
  101. SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
  102. SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
  103. };
  104. struct st_mysql_show_var {
  105. const char *name;
  106. char *value;
  107. enum enum_mysql_show_type type;
  108. };
  109. #define SHOW_VAR_FUNC_BUFF_SIZE 1024
  110. typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *);
  111. /*
  112. declarations for server variables and command line options
  113. */
  114. #define PLUGIN_VAR_BOOL 0x0001
  115. #define PLUGIN_VAR_INT 0x0002
  116. #define PLUGIN_VAR_LONG 0x0003
  117. #define PLUGIN_VAR_LONGLONG 0x0004
  118. #define PLUGIN_VAR_STR 0x0005
  119. #define PLUGIN_VAR_ENUM 0x0006
  120. #define PLUGIN_VAR_SET 0x0007
  121. #define PLUGIN_VAR_UNSIGNED 0x0080
  122. #define PLUGIN_VAR_THDLOCAL 0x0100 /* Variable is per-connection */
  123. #define PLUGIN_VAR_READONLY 0x0200 /* Server variable is read only */
  124. #define PLUGIN_VAR_NOSYSVAR 0x0400 /* Not a server variable */
  125. #define PLUGIN_VAR_NOCMDOPT 0x0800 /* Not a command line option */
  126. #define PLUGIN_VAR_NOCMDARG 0x1000 /* No argument for cmd line */
  127. #define PLUGIN_VAR_RQCMDARG 0x0000 /* Argument required for cmd line */
  128. #define PLUGIN_VAR_OPCMDARG 0x2000 /* Argument optional for cmd line */
  129. #define PLUGIN_VAR_MEMALLOC 0x8000 /* String needs memory allocated */
  130. struct st_mysql_sys_var;
  131. struct st_mysql_value;
  132. /*
  133. SYNOPSIS
  134. (*mysql_var_check_func)()
  135. thd thread handle
  136. var dynamic variable being altered
  137. save pointer to temporary storage
  138. value user provided value
  139. RETURN
  140. 0 user provided value is OK and the update func may be called.
  141. any other value indicates error.
  142. This function should parse the user provided value and store in the
  143. provided temporary storage any data as required by the update func.
  144. There is sufficient space in the temporary storage to store a double.
  145. Note that the update func may not be called if any other error occurs
  146. so any memory allocated should be thread-local so that it may be freed
  147. automatically at the end of the statement.
  148. */
  149. typedef int (*mysql_var_check_func)(MYSQL_THD thd,
  150. struct st_mysql_sys_var *var,
  151. void *save, struct st_mysql_value *value);
  152. /*
  153. SYNOPSIS
  154. (*mysql_var_update_func)()
  155. thd thread handle
  156. var dynamic variable being altered
  157. var_ptr pointer to dynamic variable
  158. save pointer to temporary storage
  159. RETURN
  160. NONE
  161. This function should use the validated value stored in the temporary store
  162. and persist it in the provided pointer to the dynamic variable.
  163. For example, strings may require memory to be allocated.
  164. */
  165. typedef void (*mysql_var_update_func)(MYSQL_THD thd,
  166. struct st_mysql_sys_var *var,
  167. void *var_ptr, const void *save);
  168. /* the following declarations are for internal use only */
  169. #define PLUGIN_VAR_MASK \
  170. (PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
  171. PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
  172. PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
  173. #define MYSQL_PLUGIN_VAR_HEADER \
  174. int flags; \
  175. const char *name; \
  176. const char *comment; \
  177. mysql_var_check_func check; \
  178. mysql_var_update_func update
  179. #define MYSQL_SYSVAR_NAME(name) mysql_sysvar_ ## name
  180. #define MYSQL_SYSVAR(name) \
  181. ((struct st_mysql_sys_var *)&(MYSQL_SYSVAR_NAME(name)))
  182. /*
  183. for global variables, the value pointer is the first
  184. element after the header, the default value is the second.
  185. for thread variables, the value offset is the first
  186. element after the header, the default value is the second.
  187. */
  188. #define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
  189. MYSQL_PLUGIN_VAR_HEADER; \
  190. type *value; \
  191. const type def_val; \
  192. } MYSQL_SYSVAR_NAME(name)
  193. #define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
  194. MYSQL_PLUGIN_VAR_HEADER; \
  195. type *value; type def_val; \
  196. type min_val; type max_val; \
  197. type blk_sz; \
  198. } MYSQL_SYSVAR_NAME(name)
  199. #define DECLARE_MYSQL_SYSVAR_TYPELIB(name, type) struct { \
  200. MYSQL_PLUGIN_VAR_HEADER; \
  201. type *value; type def_val; \
  202. TYPELIB *typelib; \
  203. } MYSQL_SYSVAR_NAME(name)
  204. #define DECLARE_THDVAR_FUNC(type) \
  205. type *(*resolve)(MYSQL_THD thd, int offset)
  206. #define DECLARE_MYSQL_THDVAR_BASIC(name, type) struct { \
  207. MYSQL_PLUGIN_VAR_HEADER; \
  208. int offset; \
  209. const type def_val; \
  210. DECLARE_THDVAR_FUNC(type); \
  211. } MYSQL_SYSVAR_NAME(name)
  212. #define DECLARE_MYSQL_THDVAR_SIMPLE(name, type) struct { \
  213. MYSQL_PLUGIN_VAR_HEADER; \
  214. int offset; \
  215. type def_val; type min_val; \
  216. type max_val; type blk_sz; \
  217. DECLARE_THDVAR_FUNC(type); \
  218. } MYSQL_SYSVAR_NAME(name)
  219. #define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
  220. MYSQL_PLUGIN_VAR_HEADER; \
  221. int offset; \
  222. type def_val; \
  223. DECLARE_THDVAR_FUNC(type); \
  224. TYPELIB *typelib; \
  225. } MYSQL_SYSVAR_NAME(name)
  226. /*
  227. the following declarations are for use by plugin implementors
  228. */
  229. #define MYSQL_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
  230. DECLARE_MYSQL_SYSVAR_BASIC(name, char) = { \
  231. PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
  232. #name, comment, check, update, &varname, def}
  233. #define MYSQL_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
  234. DECLARE_MYSQL_SYSVAR_BASIC(name, char *) = { \
  235. PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
  236. #name, comment, check, update, &varname, def}
  237. #define MYSQL_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
  238. DECLARE_MYSQL_SYSVAR_SIMPLE(name, int) = { \
  239. PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
  240. #name, comment, check, update, &varname, def, min, max, blk }
  241. #define MYSQL_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
  242. DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned int) = { \
  243. PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  244. #name, comment, check, update, &varname, def, min, max, blk }
  245. #define MYSQL_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
  246. DECLARE_MYSQL_SYSVAR_SIMPLE(name, long) = { \
  247. PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
  248. #name, comment, check, update, &varname, def, min, max, blk }
  249. #define MYSQL_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
  250. DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long) = { \
  251. PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  252. #name, comment, check, update, &varname, def, min, max, blk }
  253. #define MYSQL_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
  254. DECLARE_MYSQL_SYSVAR_SIMPLE(name, long long) = { \
  255. PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
  256. #name, comment, check, update, &varname, def, min, max, blk }
  257. #define MYSQL_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
  258. DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long long) = { \
  259. PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  260. #name, comment, check, update, &varname, def, min, max, blk }
  261. #define MYSQL_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
  262. DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long) = { \
  263. PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
  264. #name, comment, check, update, &varname, def, typelib }
  265. #define MYSQL_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
  266. DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long long) = { \
  267. PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
  268. #name, comment, check, update, &varname, def, typelib }
  269. #define MYSQL_THDVAR_BOOL(name, opt, comment, check, update, def) \
  270. DECLARE_MYSQL_THDVAR_BASIC(name, char) = { \
  271. PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  272. #name, comment, check, update, -1, def, NULL}
  273. #define MYSQL_THDVAR_STR(name, opt, comment, check, update, def) \
  274. DECLARE_MYSQL_THDVAR_BASIC(name, char *) = { \
  275. PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  276. #name, comment, check, update, -1, def, NULL}
  277. #define MYSQL_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
  278. DECLARE_MYSQL_THDVAR_SIMPLE(name, int) = { \
  279. PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  280. #name, comment, check, update, -1, def, min, max, blk, NULL }
  281. #define MYSQL_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
  282. DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned int) = { \
  283. PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  284. #name, comment, check, update, -1, def, min, max, blk, NULL }
  285. #define MYSQL_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
  286. DECLARE_MYSQL_THDVAR_SIMPLE(name, long) = { \
  287. PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  288. #name, comment, check, update, -1, def, min, max, blk, NULL }
  289. #define MYSQL_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
  290. DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long) = { \
  291. PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  292. #name, comment, check, update, -1, def, min, max, blk, NULL }
  293. #define MYSQL_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
  294. DECLARE_MYSQL_THDVAR_SIMPLE(name, long long) = { \
  295. PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  296. #name, comment, check, update, -1, def, min, max, blk, NULL }
  297. #define MYSQL_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
  298. DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long long) = { \
  299. PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
  300. #name, comment, check, update, -1, def, min, max, blk, NULL }
  301. #define MYSQL_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
  302. DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long) = { \
  303. PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  304. #name, comment, check, update, -1, def, NULL, typelib }
  305. #define MYSQL_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
  306. DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long long) = { \
  307. PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
  308. #name, comment, check, update, -1, def, NULL, typelib }
  309. /* accessor macros */
  310. #define SYSVAR(name) \
  311. (*(MYSQL_SYSVAR_NAME(name).value))
  312. /* when thd == null, result points to global value */
  313. #define THDVAR(thd, name) \
  314. (*(MYSQL_SYSVAR_NAME(name).resolve(thd, MYSQL_SYSVAR_NAME(name).offset)))
  315. /*
  316. Plugin description structure.
  317. */
  318. struct st_mysql_plugin
  319. {
  320. int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
  321. void *info; /* pointer to type-specific plugin descriptor */
  322. const char *name; /* plugin name */
  323. const char *author; /* plugin author (for SHOW PLUGINS) */
  324. const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
  325. int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
  326. int (*init)(void *); /* the function to invoke when plugin is loaded */
  327. int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
  328. unsigned int version; /* plugin version (for SHOW PLUGINS) */
  329. struct st_mysql_show_var *status_vars;
  330. struct st_mysql_sys_var **system_vars;
  331. void * __reserved1; /* reserved for dependency checking */
  332. };
  333. /*************************************************************************
  334. API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
  335. */
  336. #define MYSQL_FTPARSER_INTERFACE_VERSION 0x0100
  337. /* Parsing modes. Set in MYSQL_FTPARSER_PARAM::mode */
  338. enum enum_ftparser_mode
  339. {
  340. /*
  341. Fast and simple mode. This mode is used for indexing, and natural
  342. language queries.
  343. The parser is expected to return only those words that go into the
  344. index. Stopwords or too short/long words should not be returned. The
  345. 'boolean_info' argument of mysql_add_word() does not have to be set.
  346. */
  347. MYSQL_FTPARSER_SIMPLE_MODE= 0,
  348. /*
  349. Parse with stopwords mode. This mode is used in boolean searches for
  350. "phrase matching."
  351. The parser is not allowed to ignore words in this mode. Every word
  352. should be returned, including stopwords and words that are too short
  353. or long. The 'boolean_info' argument of mysql_add_word() does not
  354. have to be set.
  355. */
  356. MYSQL_FTPARSER_WITH_STOPWORDS= 1,
  357. /*
  358. Parse in boolean mode. This mode is used to parse a boolean query string.
  359. The parser should provide a valid MYSQL_FTPARSER_BOOLEAN_INFO
  360. structure in the 'boolean_info' argument to mysql_add_word().
  361. Usually that means that the parser should recognize boolean operators
  362. in the parsing stream and set appropriate fields in
  363. MYSQL_FTPARSER_BOOLEAN_INFO structure accordingly. As for
  364. MYSQL_FTPARSER_WITH_STOPWORDS mode, no word should be ignored.
  365. Instead, use FT_TOKEN_STOPWORD for the token type of such a word.
  366. */
  367. MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2
  368. };
  369. /*
  370. Token types for boolean mode searching (used for the type member of
  371. MYSQL_FTPARSER_BOOLEAN_INFO struct)
  372. FT_TOKEN_EOF: End of data.
  373. FT_TOKEN_WORD: Regular word.
  374. FT_TOKEN_LEFT_PAREN: Left parenthesis (start of group/sub-expression).
  375. FT_TOKEN_RIGHT_PAREN: Right parenthesis (end of group/sub-expression).
  376. FT_TOKEN_STOPWORD: Stopword.
  377. */
  378. enum enum_ft_token_type
  379. {
  380. FT_TOKEN_EOF= 0,
  381. FT_TOKEN_WORD= 1,
  382. FT_TOKEN_LEFT_PAREN= 2,
  383. FT_TOKEN_RIGHT_PAREN= 3,
  384. FT_TOKEN_STOPWORD= 4
  385. };
  386. /*
  387. This structure is used in boolean search mode only. It conveys
  388. boolean-mode metadata to the MySQL search engine for every word in
  389. the search query. A valid instance of this structure must be filled
  390. in by the plugin parser and passed as an argument in the call to
  391. mysql_add_word (the callback function in the MYSQL_FTPARSER_PARAM
  392. structure) when a query is parsed in boolean mode.
  393. type: The token type. Should be one of the enum_ft_token_type values.
  394. yesno: Whether the word must be present for a match to occur:
  395. >0 Must be present
  396. <0 Must not be present
  397. 0 Neither; the word is optional but its presence increases the relevance
  398. With the default settings of the ft_boolean_syntax system variable,
  399. >0 corresponds to the '+' operator, <0 corrresponds to the '-' operator,
  400. and 0 means neither operator was used.
  401. weight_adjust: A weighting factor that determines how much a match
  402. for the word counts. Positive values increase, negative - decrease the
  403. relative word's importance in the query.
  404. wasign: The sign of the word's weight in the query. If it's non-negative
  405. the match for the word will increase document relevance, if it's
  406. negative - decrease (the word becomes a "noise word", the less of it the
  407. better).
  408. trunc: Corresponds to the '*' operator in the default setting of the
  409. ft_boolean_syntax system variable.
  410. */
  411. typedef struct st_mysql_ftparser_boolean_info
  412. {
  413. enum enum_ft_token_type type;
  414. int yesno;
  415. int weight_adjust;
  416. char wasign;
  417. char trunc;
  418. /* These are parser state and must be removed. */
  419. char prev;
  420. char *quot;
  421. } MYSQL_FTPARSER_BOOLEAN_INFO;
  422. /*
  423. The following flag means that buffer with a string (document, word)
  424. may be overwritten by the caller before the end of the parsing (that is
  425. before st_mysql_ftparser::deinit() call). If one needs the string
  426. to survive between two successive calls of the parsing function, she
  427. needs to save a copy of it. The flag may be set by MySQL before calling
  428. st_mysql_ftparser::parse(), or it may be set by a plugin before calling
  429. st_mysql_ftparser_param::mysql_parse() or
  430. st_mysql_ftparser_param::mysql_add_word().
  431. */
  432. #define MYSQL_FTFLAGS_NEED_COPY 1
  433. /*
  434. An argument of the full-text parser plugin. This structure is
  435. filled in by MySQL server and passed to the parsing function of the
  436. plugin as an in/out parameter.
  437. mysql_parse: A pointer to the built-in parser implementation of the
  438. server. It's set by the server and can be used by the parser plugin
  439. to invoke the MySQL default parser. If plugin's role is to extract
  440. textual data from .doc, .pdf or .xml content, it might extract
  441. plaintext from the content, and then pass the text to the default
  442. MySQL parser to be parsed.
  443. mysql_add_word: A server callback to add a new word. When parsing
  444. a document, the server sets this to point at a function that adds
  445. the word to MySQL full-text index. When parsing a search query,
  446. this function will add the new word to the list of words to search
  447. for. The boolean_info argument can be NULL for all cases except
  448. when mode is MYSQL_FTPARSER_FULL_BOOLEAN_INFO.
  449. ftparser_state: A generic pointer. The plugin can set it to point
  450. to information to be used internally for its own purposes.
  451. mysql_ftparam: This is set by the server. It is used by MySQL functions
  452. called via mysql_parse() and mysql_add_word() callback. The plugin
  453. should not modify it.
  454. cs: Information about the character set of the document or query string.
  455. doc: A pointer to the document or query string to be parsed.
  456. length: Length of the document or query string, in bytes.
  457. flags: See MYSQL_FTFLAGS_* constants above.
  458. mode: The parsing mode. With boolean operators, with stopwords, or
  459. nothing. See enum_ftparser_mode above.
  460. */
  461. typedef struct st_mysql_ftparser_param
  462. {
  463. int (*mysql_parse)(struct st_mysql_ftparser_param *,
  464. char *doc, int doc_len);
  465. int (*mysql_add_word)(struct st_mysql_ftparser_param *,
  466. char *word, int word_len,
  467. MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info);
  468. void *ftparser_state;
  469. void *mysql_ftparam;
  470. struct charset_info_st *cs;
  471. char *doc;
  472. int length;
  473. int flags;
  474. enum enum_ftparser_mode mode;
  475. } MYSQL_FTPARSER_PARAM;
  476. /*
  477. Full-text parser descriptor.
  478. interface_version is, e.g., MYSQL_FTPARSER_INTERFACE_VERSION.
  479. The parsing, initialization, and deinitialization functions are
  480. invoked per SQL statement for which the parser is used.
  481. */
  482. struct st_mysql_ftparser
  483. {
  484. int interface_version;
  485. int (*parse)(MYSQL_FTPARSER_PARAM *param);
  486. int (*init)(MYSQL_FTPARSER_PARAM *param);
  487. int (*deinit)(MYSQL_FTPARSER_PARAM *param);
  488. };
  489. /*************************************************************************
  490. API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
  491. */
  492. /* handlertons of different MySQL releases are incompatible */
  493. #define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
  494. /*************************************************************************
  495. API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
  496. */
  497. /* handlertons of different MySQL releases are incompatible */
  498. #define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
  499. /*************************************************************************
  500. API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
  501. */
  502. /* handlertons of different MySQL releases are incompatible */
  503. #define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
  504. /*
  505. The real API is in the sql/handler.h
  506. Here we define only the descriptor structure, that is referred from
  507. st_mysql_plugin.
  508. */
  509. struct st_mysql_storage_engine
  510. {
  511. int interface_version;
  512. };
  513. struct handlerton;
  514. /*
  515. Here we define only the descriptor structure, that is referred from
  516. st_mysql_plugin.
  517. */
  518. struct st_mysql_daemon
  519. {
  520. int interface_version;
  521. };
  522. /*
  523. Here we define only the descriptor structure, that is referred from
  524. st_mysql_plugin.
  525. */
  526. struct st_mysql_information_schema
  527. {
  528. int interface_version;
  529. };
  530. /*
  531. st_mysql_value struct for reading values from mysqld.
  532. Used by server variables framework to parse user-provided values.
  533. Will be used for arguments when implementing UDFs.
  534. Note that val_str() returns a string in temporary memory
  535. that will be freed at the end of statement. Copy the string
  536. if you need it to persist.
  537. */
  538. #define MYSQL_VALUE_TYPE_STRING 0
  539. #define MYSQL_VALUE_TYPE_REAL 1
  540. #define MYSQL_VALUE_TYPE_INT 2
  541. struct st_mysql_value
  542. {
  543. int (*value_type)(struct st_mysql_value *);
  544. const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
  545. int (*val_real)(struct st_mysql_value *, double *realbuf);
  546. int (*val_int)(struct st_mysql_value *, long long *intbuf);
  547. };
  548. /*************************************************************************
  549. Miscellaneous functions for plugin implementors
  550. */
  551. #ifdef __cplusplus
  552. extern "C" {
  553. #endif
  554. int thd_in_lock_tables(const MYSQL_THD thd);
  555. int thd_tablespace_op(const MYSQL_THD thd);
  556. long long thd_test_options(const MYSQL_THD thd, long long test_options);
  557. int thd_sql_command(const MYSQL_THD thd);
  558. const char *thd_proc_info(MYSQL_THD thd, const char *info);
  559. void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
  560. int thd_tx_isolation(const MYSQL_THD thd);
  561. char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
  562. unsigned int max_query_len);
  563. /* Increments the row counter, see THD::row_count */
  564. void thd_inc_row_count(MYSQL_THD thd);
  565. /**
  566. Create a temporary file.
  567. @details
  568. The temporary file is created in a location specified by the mysql
  569. server configuration (--tmpdir option). The caller does not need to
  570. delete the file, it will be deleted automatically.
  571. @param prefix prefix for temporary file name
  572. @retval -1 error
  573. @retval >= 0 a file handle that can be passed to dup or my_close
  574. */
  575. int mysql_tmpfile(const char *prefix);
  576. /**
  577. Check the killed state of a connection
  578. @details
  579. In MySQL support for the KILL statement is cooperative. The KILL
  580. statement only sets a "killed" flag. This function returns the value
  581. of that flag. A thread should check it often, especially inside
  582. time-consuming loops, and gracefully abort the operation if it is
  583. non-zero.
  584. @param thd user thread connection handle
  585. @retval 0 the connection is active
  586. @retval 1 the connection has been killed
  587. */
  588. int thd_killed(const MYSQL_THD thd);
  589. /**
  590. Return the thread id of a user thread
  591. @param thd user thread connection handle
  592. @return thread id
  593. */
  594. unsigned long thd_get_thread_id(const MYSQL_THD thd);
  595. /**
  596. Allocate memory in the connection's local memory pool
  597. @details
  598. When properly used in place of @c my_malloc(), this can significantly
  599. improve concurrency. Don't use this or related functions to allocate
  600. large chunks of memory. Use for temporary storage only. The memory
  601. will be freed automatically at the end of the statement; no explicit
  602. code is required to prevent memory leaks.
  603. @see alloc_root()
  604. */
  605. void *thd_alloc(MYSQL_THD thd, unsigned int size);
  606. /**
  607. @see thd_alloc()
  608. */
  609. void *thd_calloc(MYSQL_THD thd, unsigned int size);
  610. /**
  611. @see thd_alloc()
  612. */
  613. char *thd_strdup(MYSQL_THD thd, const char *str);
  614. /**
  615. @see thd_alloc()
  616. */
  617. char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
  618. /**
  619. @see thd_alloc()
  620. */
  621. void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
  622. /**
  623. Create a LEX_STRING in this connection's local memory pool
  624. @param thd user thread connection handle
  625. @param lex_str pointer to LEX_STRING object to be initialized
  626. @param str initializer to be copied into lex_str
  627. @param size length of str, in bytes
  628. @param allocate_lex_string flag: if TRUE, allocate new LEX_STRING object,
  629. instead of using lex_str value
  630. @return NULL on failure, or pointer to the LEX_STRING object
  631. @see thd_alloc()
  632. */
  633. MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
  634. const char *str, unsigned int size,
  635. int allocate_lex_string);
  636. /**
  637. Get the XID for this connection's transaction
  638. @param thd user thread connection handle
  639. @param xid location where identifier is stored
  640. */
  641. void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
  642. /**
  643. Invalidate the query cache for a given table.
  644. @param thd user thread connection handle
  645. @param key databasename\\0tablename\\0
  646. @param key_length length of key in bytes, including the NUL bytes
  647. @param using_trx flag: TRUE if using transactions, FALSE otherwise
  648. */
  649. void mysql_query_cache_invalidate4(MYSQL_THD thd,
  650. const char *key, unsigned int key_length,
  651. int using_trx);
  652. #ifdef __cplusplus
  653. }
  654. #endif
  655. #ifdef __cplusplus
  656. /**
  657. Provide a handler data getter to simplify coding
  658. */
  659. inline
  660. void *
  661. thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton)
  662. {
  663. return *thd_ha_data(thd, hton);
  664. }
  665. /**
  666. Provide a handler data setter to simplify coding
  667. */
  668. inline
  669. void
  670. thd_set_ha_data(const MYSQL_THD thd, const struct handlerton *hton,
  671. const void *ha_data)
  672. {
  673. *thd_ha_data(thd, hton)= (void*) ha_data;
  674. }
  675. #endif
  676. #endif