20
20
#ifndef DRIZZLED_PLUGIN_H
21
21
#define DRIZZLED_PLUGIN_H
23
#include <boost/program_options.hpp>
24
#include <boost/filesystem.hpp>
26
#include <drizzled/module/manifest.h>
27
#include <drizzled/module/module.h>
28
#include <drizzled/plugin/version.h>
29
#include <drizzled/module/context.h>
30
#include <drizzled/definitions.h>
23
#include <drizzled/global.h>
32
24
#include <drizzled/lex_string.h>
33
#include <drizzled/sys_var.h>
34
25
#include <drizzled/xid.h>
36
#include <drizzled/visibility.h>
43
struct charset_info_st;
45
30
/*************************************************************************
46
31
Plugin API. Common for all plugin types.
53
extern boost::filesystem::path plugin_dir;
55
namespace plugin { class StorageEngine; }
58
Macros for beginning and ending plugin declarations. Between
59
DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
60
be a module::Manifest for each plugin to be declared.
64
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
65
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
66
#define DRIZZLE_DECLARE_PLUGIN \
67
DRIZZLED_API ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)=
70
#define DRIZZLE_DECLARE_PLUGIN_END
71
#define DRIZZLE_PLUGIN(init,system,options) \
72
DRIZZLE_DECLARE_PLUGIN \
75
STRINGIFY_ARG(PANDORA_MODULE_NAME), \
76
STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
77
STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
78
STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
79
PANDORA_MODULE_LICENSE, \
81
STRINGIFY_ARG(PANDORA_MODULE_DEPENDENCIES), \
35
The allowable types of plugins
37
enum drizzle_plugin_type {
38
DRIZZLE_DAEMON_PLUGIN, /* Daemon / Raw */
39
DRIZZLE_STORAGE_ENGINE_PLUGIN, /* Storage Engine */
40
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, /* Information Schema */
41
DRIZZLE_UDF_PLUGIN, /* User-Defined Function */
42
DRIZZLE_UDA_PLUGIN, /* User-Defined Aggregate Function */
43
DRIZZLE_AUDIT_PLUGIN, /* Audit */
44
DRIZZLE_LOGGER_PLUGIN, /* Query Logging */
45
DRIZZLE_ERRMSG_PLUGIN, /* Error Messages */
46
DRIZZLE_AUTH_PLUGIN, /* Authorization */
47
DRIZZLE_CONFIGVAR_PLUGIN, /* Configuration Variables */
48
DRIZZLE_QCACHE_PLUGIN, /* Query Cache */
49
DRIZZLE_PARSER_PLUGIN, /* Language Parser */
50
DRIZZLE_SCHEDULING_PLUGIN, /* Thread and Session Scheduling */
51
DRIZZLE_REPLICATOR_PLUGIN, /* Database Replication */
52
DRIZZLE_PLUGIN_MAX=DRIZZLE_REPLICATOR_PLUGIN
55
/* The number of plugin types */
56
const uint32_t DRIZZLE_MAX_PLUGIN_TYPE_NUM=DRIZZLE_PLUGIN_MAX+1;
58
/* We use the following strings to define licenses for plugins */
59
enum plugin_license_type {
60
PLUGIN_LICENSE_PROPRIETARY,
63
PLUGIN_LICENSE_MAX=PLUGIN_LICENSE_BSD
66
const char * const PLUGIN_LICENSE_PROPRIETARY_STRING="PROPRIETARY";
67
const char * const PLUGIN_LICENSE_GPL_STRING="GPL";
68
const char * const PLUGIN_LICENSE_BSD_STRING="BSD";
71
Macros for beginning and ending plugin declarations. Between
72
mysql_declare_plugin and mysql_declare_plugin_end there should
73
be a st_mysql_plugin struct for each plugin to be declared.
77
#ifndef DRIZZLE_DYNAMIC_PLUGIN
78
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
79
struct st_mysql_plugin DECLS[]= {
81
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
82
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
85
#define mysql_declare_plugin(NAME) \
86
__DRIZZLE_DECLARE_PLUGIN(NAME, \
87
builtin_ ## NAME ## _plugin)
89
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0}}
92
declarations for SHOW STATUS support in plugins
94
enum enum_mysql_show_type
96
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
97
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
98
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, SHOW_SIZE
101
struct st_mysql_show_var {
104
enum enum_mysql_show_type type;
108
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
109
typedef int (*mysql_show_var_func)(Session *, struct st_mysql_show_var *, char *);
111
struct st_show_var_func_container {
112
mysql_show_var_func func;
87
115
declarations for server variables and command line options
143
173
and persist it in the provided pointer to the dynamic variable.
144
174
For example, strings may require memory to be allocated.
146
typedef void (*var_update_func)(Session *session,
147
drizzle_sys_var *var,
176
typedef void (*mysql_var_update_func)(Session *session,
177
struct st_mysql_sys_var *var,
148
178
void *var_ptr, const void *save);
153
skeleton of a plugin variable - portion of structure common to all.
155
struct drizzle_sys_var
181
/* the following declarations are for internal use only */
184
#define PLUGIN_VAR_MASK \
185
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
186
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
187
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
189
#define DRIZZLE_PLUGIN_VAR_HEADER \
192
const char *comment; \
193
mysql_var_check_func check; \
194
mysql_var_update_func update
196
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
197
#define DRIZZLE_SYSVAR(name) \
198
((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
201
for global variables, the value pointer is the first
202
element after the header, the default value is the second.
203
for thread variables, the value offset is the first
204
element after the header, the default value is the second.
208
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
209
DRIZZLE_PLUGIN_VAR_HEADER; \
211
const type def_val; \
212
} DRIZZLE_SYSVAR_NAME(name)
214
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
215
DRIZZLE_PLUGIN_VAR_HEADER; \
216
type *value; type def_val; \
217
type min_val; type max_val; \
219
} DRIZZLE_SYSVAR_NAME(name)
221
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
222
DRIZZLE_PLUGIN_VAR_HEADER; \
223
type *value; type def_val; \
225
} DRIZZLE_SYSVAR_NAME(name)
227
#define DECLARE_SessionVAR_FUNC(type) \
228
type *(*resolve)(Session *session, int offset)
230
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
231
DRIZZLE_PLUGIN_VAR_HEADER; \
233
const type def_val; \
234
DECLARE_SessionVAR_FUNC(type); \
235
} DRIZZLE_SYSVAR_NAME(name)
237
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
238
DRIZZLE_PLUGIN_VAR_HEADER; \
240
type def_val; type min_val; \
241
type max_val; type blk_sz; \
242
DECLARE_SessionVAR_FUNC(type); \
243
} DRIZZLE_SYSVAR_NAME(name)
245
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
246
DRIZZLE_PLUGIN_VAR_HEADER; \
249
DECLARE_SessionVAR_FUNC(type); \
251
} DRIZZLE_SYSVAR_NAME(name)
255
the following declarations are for use by plugin implementors
258
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
259
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
260
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
261
#name, comment, check, update, &varname, def}
263
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
264
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
265
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
266
#name, comment, check, update, &varname, def}
268
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
269
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
270
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
271
#name, comment, check, update, &varname, def, min, max, blk }
273
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
274
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
275
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
276
#name, comment, check, update, &varname, def, min, max, blk }
278
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
279
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
280
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
281
#name, comment, check, update, &varname, def, min, max, blk }
283
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
284
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
285
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
286
#name, comment, check, update, &varname, def, min, max, blk }
288
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
289
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
290
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
291
#name, comment, check, update, &varname, def, min, max, blk }
293
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
294
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
295
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
296
#name, comment, check, update, &varname, def, min, max, blk }
298
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
299
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
300
PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
301
#name, comment, check, update, &varname, def, typelib }
303
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
304
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
305
PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
306
#name, comment, check, update, &varname, def, typelib }
308
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
309
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
310
PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
311
#name, comment, check, update, -1, def, NULL}
313
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
314
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
315
PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
316
#name, comment, check, update, -1, def, NULL}
318
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
319
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
320
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
321
#name, comment, check, update, -1, def, min, max, blk, NULL }
323
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
324
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
325
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
326
#name, comment, check, update, -1, def, min, max, blk, NULL }
328
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
329
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
330
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
331
#name, comment, check, update, -1, def, min, max, blk, NULL }
333
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
334
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
335
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
336
#name, comment, check, update, -1, def, min, max, blk, NULL }
338
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
339
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
340
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
341
#name, comment, check, update, -1, def, min, max, blk, NULL }
343
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
344
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
345
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
346
#name, comment, check, update, -1, def, min, max, blk, NULL }
348
#define DRIZZLE_SessionVAR_ENUM(name, opt, comment, check, update, def, typelib) \
349
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, unsigned long) = { \
350
PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
351
#name, comment, check, update, -1, def, NULL, typelib }
353
#define DRIZZLE_SessionVAR_SET(name, opt, comment, check, update, def, typelib) \
354
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, uint64_t) = { \
355
PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
356
#name, comment, check, update, -1, def, NULL, typelib }
358
/* accessor macros */
360
#define SYSVAR(name) \
361
(*(DRIZZLE_SYSVAR_NAME(name).value))
363
/* when session == null, result points to global value */
364
#define SessionVAR(session, name) \
365
(*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
369
Plugin description structure.
372
struct st_mysql_plugin
374
uint32_t type; /* the plugin type (a DRIZZLE_XXX_PLUGIN value) */
375
const char *name; /* plugin name (for SHOW PLUGINS) */
376
const char *version; /* plugin version (for SHOW PLUGINS) */
377
const char *author; /* plugin author (for SHOW PLUGINS) */
378
const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
379
int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
380
int (*init)(void *); /* the function to invoke when plugin is loaded */
381
int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
382
struct st_mysql_show_var *status_vars;
383
struct st_mysql_sys_var **system_vars;
384
void *reserved1; /* reserved for dependency checking */
159
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
390
/*************************************************************************
391
st_mysql_value struct for reading values from mysqld.
392
Used by server variables framework to parse user-provided values.
393
Will be used for arguments when implementing UDFs.
395
Note that val_str() returns a string in temporary memory
396
that will be freed at the end of statement. Copy the string
397
if you need it to persist.
400
#define DRIZZLE_VALUE_TYPE_STRING 0
401
#define DRIZZLE_VALUE_TYPE_REAL 1
402
#define DRIZZLE_VALUE_TYPE_INT 2
404
struct st_mysql_value
163
int (*value_type)(drizzle_value *);
164
const char *(*val_str)(drizzle_value *, char *buffer, int *length);
165
int (*val_real)(drizzle_value *, double *realbuf);
166
int (*val_int)(drizzle_value *, int64_t *intbuf);
406
int (*value_type)(struct st_mysql_value *);
407
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
408
int (*val_real)(struct st_mysql_value *, double *realbuf);
409
int (*val_int)(struct st_mysql_value *, int64_t *intbuf);