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>
32
#include <drizzled/lex_string.h>
33
#include <drizzled/sys_var.h>
34
#include <drizzled/xid.h>
36
#include <drizzled/visibility.h>
23
#include <drizzled/global.h>
43
struct charset_info_st;
28
#define DRIZZLE_XIDDATASIZE 128
30
struct st_mysql_xid is binary compatible with the XID structure as
31
in the X/Open CAE Specification, Distributed Transaction Processing:
32
The XA Specification, X/Open Company Ltd., 1991.
33
http://www.opengroup.org/bookstore/catalog/c193.htm
35
@see XID in sql/handler.h
41
char data[DRIZZLE_XIDDATASIZE]; /* Not \0-terminated */
43
typedef struct st_mysql_xid DRIZZLE_XID;
45
45
/*************************************************************************
46
46
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), \
50
The allowable types of plugins
52
enum drizzle_plugin_type {
53
DRIZZLE_DAEMON_PLUGIN, /* Daemon / Raw */
54
DRIZZLE_STORAGE_ENGINE_PLUGIN, /* Storage Engine */
55
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, /* Information Schema */
56
DRIZZLE_UDF_PLUGIN, /* User-Defined Function */
57
DRIZZLE_UDA_PLUGIN, /* User-Defined Aggregate Function */
58
DRIZZLE_AUDIT_PLUGIN, /* Audit */
59
DRIZZLE_LOGGER_PLUGIN, /* Query Logging */
60
DRIZZLE_ERRMSG_PLUGIN, /* Error Messages */
61
DRIZZLE_AUTH_PLUGIN, /* Authorization */
62
DRIZZLE_CONFIGVAR_PLUGIN, /* Configuration Variables */
63
DRIZZLE_QCACHE_PLUGIN, /* Query Cache */
64
DRIZZLE_PARSER_PLUGIN, /* Language Parser */
65
DRIZZLE_SCHEDULING_PLUGIN, /* Thread and Session Scheduling */
66
DRIZZLE_PLUGIN_MAX=DRIZZLE_SCHEDULING_PLUGIN
69
/* The number of plugin types */
70
const uint32_t DRIZZLE_MAX_PLUGIN_TYPE_NUM=DRIZZLE_PLUGIN_MAX+1;
72
/* We use the following strings to define licenses for plugins */
73
enum plugin_license_type {
74
PLUGIN_LICENSE_PROPRIETARY,
77
PLUGIN_LICENSE_MAX=PLUGIN_LICENSE_BSD
80
const char * const PLUGIN_LICENSE_PROPRIETARY_STRING="PROPRIETARY";
81
const char * const PLUGIN_LICENSE_GPL_STRING="GPL";
82
const char * const PLUGIN_LICENSE_BSD_STRING="BSD";
85
Macros for beginning and ending plugin declarations. Between
86
mysql_declare_plugin and mysql_declare_plugin_end there should
87
be a st_mysql_plugin struct for each plugin to be declared.
91
#ifndef DRIZZLE_DYNAMIC_PLUGIN
92
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
93
struct st_mysql_plugin DECLS[]= {
95
#define __DRIZZLE_DECLARE_PLUGIN(NAME, DECLS) \
96
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
99
#define mysql_declare_plugin(NAME) \
100
__DRIZZLE_DECLARE_PLUGIN(NAME, \
101
builtin_ ## NAME ## _plugin)
103
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0}}
106
declarations for SHOW STATUS support in plugins
108
enum enum_mysql_show_type
110
SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
111
SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
112
SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
115
struct st_mysql_show_var {
118
enum enum_mysql_show_type type;
122
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
123
typedef int (*mysql_show_var_func)(Session *, struct st_mysql_show_var *, char *);
125
struct st_show_var_func_container {
126
mysql_show_var_func func;
87
129
declarations for server variables and command line options
125
169
automatically at the end of the statement.
128
typedef int (*var_check_func)(Session *session,
129
drizzle_sys_var *var,
130
void *save, drizzle_value *value);
172
typedef int (*mysql_var_check_func)(Session *session,
173
struct st_mysql_sys_var *var,
174
void *save, struct st_mysql_value *value);
178
(*mysql_var_update_func)()
135
179
session thread handle
136
180
var dynamic variable being altered
137
181
var_ptr pointer to dynamic variable
138
182
save pointer to temporary storage
142
186
This function should use the validated value stored in the temporary store
143
187
and persist it in the provided pointer to the dynamic variable.
144
188
For example, strings may require memory to be allocated.
146
typedef void (*var_update_func)(Session *session,
147
drizzle_sys_var *var,
190
typedef void (*mysql_var_update_func)(Session *session,
191
struct st_mysql_sys_var *var,
148
192
void *var_ptr, const void *save);
153
skeleton of a plugin variable - portion of structure common to all.
155
struct drizzle_sys_var
195
/* the following declarations are for internal use only */
198
#define PLUGIN_VAR_MASK \
199
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
200
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
201
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
203
#define DRIZZLE_PLUGIN_VAR_HEADER \
206
const char *comment; \
207
mysql_var_check_func check; \
208
mysql_var_update_func update
210
#define DRIZZLE_SYSVAR_NAME(name) mysql_sysvar_ ## name
211
#define DRIZZLE_SYSVAR(name) \
212
((struct st_mysql_sys_var *)&(DRIZZLE_SYSVAR_NAME(name)))
215
for global variables, the value pointer is the first
216
element after the header, the default value is the second.
217
for thread variables, the value offset is the first
218
element after the header, the default value is the second.
222
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
223
DRIZZLE_PLUGIN_VAR_HEADER; \
225
const type def_val; \
226
} DRIZZLE_SYSVAR_NAME(name)
228
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
229
DRIZZLE_PLUGIN_VAR_HEADER; \
230
type *value; type def_val; \
231
type min_val; type max_val; \
233
} DRIZZLE_SYSVAR_NAME(name)
235
#define DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, type) struct { \
236
DRIZZLE_PLUGIN_VAR_HEADER; \
237
type *value; type def_val; \
239
} DRIZZLE_SYSVAR_NAME(name)
241
#define DECLARE_SessionVAR_FUNC(type) \
242
type *(*resolve)(Session *session, int offset)
244
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
245
DRIZZLE_PLUGIN_VAR_HEADER; \
247
const type def_val; \
248
DECLARE_SessionVAR_FUNC(type); \
249
} DRIZZLE_SYSVAR_NAME(name)
251
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
252
DRIZZLE_PLUGIN_VAR_HEADER; \
254
type def_val; type min_val; \
255
type max_val; type blk_sz; \
256
DECLARE_SessionVAR_FUNC(type); \
257
} DRIZZLE_SYSVAR_NAME(name)
259
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
260
DRIZZLE_PLUGIN_VAR_HEADER; \
263
DECLARE_SessionVAR_FUNC(type); \
265
} DRIZZLE_SYSVAR_NAME(name)
269
the following declarations are for use by plugin implementors
272
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
273
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
274
PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
275
#name, comment, check, update, &varname, def}
277
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
278
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
279
PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
280
#name, comment, check, update, &varname, def}
282
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
283
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
284
PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
285
#name, comment, check, update, &varname, def, min, max, blk }
287
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
288
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
289
PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
290
#name, comment, check, update, &varname, def, min, max, blk }
292
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
293
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
294
PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
295
#name, comment, check, update, &varname, def, min, max, blk }
297
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
298
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
299
PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
300
#name, comment, check, update, &varname, def, min, max, blk }
302
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
303
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
304
PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
305
#name, comment, check, update, &varname, def, min, max, blk }
307
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
308
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
309
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
310
#name, comment, check, update, &varname, def, min, max, blk }
312
#define DRIZZLE_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
313
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, unsigned long) = { \
314
PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
315
#name, comment, check, update, &varname, def, typelib }
317
#define DRIZZLE_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
318
DECLARE_DRIZZLE_SYSVAR_TYPELIB(name, uint64_t) = { \
319
PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
320
#name, comment, check, update, &varname, def, typelib }
322
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
323
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
324
PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
325
#name, comment, check, update, -1, def, NULL}
327
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
328
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
329
PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
330
#name, comment, check, update, -1, def, NULL}
332
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
333
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
334
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
335
#name, comment, check, update, -1, def, min, max, blk, NULL }
337
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
338
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
339
PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
340
#name, comment, check, update, -1, def, min, max, blk, NULL }
342
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
343
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
344
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
345
#name, comment, check, update, -1, def, min, max, blk, NULL }
347
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
348
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
349
PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
350
#name, comment, check, update, -1, def, min, max, blk, NULL }
352
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
353
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
354
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
355
#name, comment, check, update, -1, def, min, max, blk, NULL }
357
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
358
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
359
PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
360
#name, comment, check, update, -1, def, min, max, blk, NULL }
362
#define DRIZZLE_SessionVAR_ENUM(name, opt, comment, check, update, def, typelib) \
363
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, unsigned long) = { \
364
PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
365
#name, comment, check, update, -1, def, NULL, typelib }
367
#define DRIZZLE_SessionVAR_SET(name, opt, comment, check, update, def, typelib) \
368
DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, uint64_t) = { \
369
PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
370
#name, comment, check, update, -1, def, NULL, typelib }
372
/* accessor macros */
374
#define SYSVAR(name) \
375
(*(DRIZZLE_SYSVAR_NAME(name).value))
377
/* when session == null, result points to global value */
378
#define SessionVAR(session, name) \
379
(*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
383
Plugin description structure.
386
struct st_mysql_plugin
388
uint32_t type; /* the plugin type (a DRIZZLE_XXX_PLUGIN value) */
389
const char *name; /* plugin name (for SHOW PLUGINS) */
390
const char *version; /* plugin version (for SHOW PLUGINS) */
391
const char *author; /* plugin author (for SHOW PLUGINS) */
392
const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
393
int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
394
int (*init)(void *); /* the function to invoke when plugin is loaded */
395
int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
396
struct st_mysql_show_var *status_vars;
397
struct st_mysql_sys_var **system_vars;
398
void * __reserved1; /* reserved for dependency checking */
159
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
404
/*************************************************************************
405
st_mysql_value struct for reading values from mysqld.
406
Used by server variables framework to parse user-provided values.
407
Will be used for arguments when implementing UDFs.
409
Note that val_str() returns a string in temporary memory
410
that will be freed at the end of statement. Copy the string
411
if you need it to persist.
414
#define DRIZZLE_VALUE_TYPE_STRING 0
415
#define DRIZZLE_VALUE_TYPE_REAL 1
416
#define DRIZZLE_VALUE_TYPE_INT 2
418
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);
420
int (*value_type)(struct st_mysql_value *);
421
const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
422
int (*val_real)(struct st_mysql_value *, double *realbuf);
423
int (*val_int)(struct st_mysql_value *, int64_t *intbuf);