~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/mysql/plugin.h

Renamed more stuff to drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_PLUGIN_H
21
 
#define DRIZZLED_PLUGIN_H
22
 
 
23
 
#include "drizzled/module/manifest.h"
24
 
#include "drizzled/module/module.h"
25
 
#include "drizzled/plugin/version.h"
26
 
#include "drizzled/module/context.h"
27
 
#include "drizzled/definitions.h"
28
 
 
29
 
#include "drizzled/lex_string.h"
30
 
#include "drizzled/xid.h"
31
 
#include <boost/program_options.hpp>
32
 
 
33
 
namespace drizzled
34
 
{
35
 
 
36
 
class Session;
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef _my_plugin_h
 
17
#define _my_plugin_h
 
18
 
 
19
#ifdef __cplusplus
 
20
class THD;
37
21
class Item;
38
 
struct charset_info_st;
 
22
#define MYSQL_THD THD*
 
23
#else
 
24
#define MYSQL_THD void*
 
25
#endif
 
26
 
 
27
#include <stdint.h>
 
28
 
 
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
 
 
39
#define MYSQL_XIDDATASIZE 128
 
40
/**
 
41
  struct st_mysql_xid is binary compatible with the XID structure as
 
42
  in the X/Open CAE Specification, Distributed Transaction Processing:
 
43
  The XA Specification, X/Open Company Ltd., 1991.
 
44
  http://www.opengroup.org/bookstore/catalog/c193.htm
 
45
 
 
46
  @see XID in sql/handler.h
 
47
*/
 
48
struct st_mysql_xid {
 
49
  long formatID;
 
50
  long gtrid_length;
 
51
  long bqual_length;
 
52
  char data[MYSQL_XIDDATASIZE];  /* Not \0-terminated */
 
53
};
 
54
typedef struct st_mysql_xid MYSQL_XID;
39
55
 
40
56
/*************************************************************************
41
57
  Plugin API. Common for all plugin types.
42
58
*/
43
59
 
44
 
 
45
 
class sys_var;
46
 
typedef drizzle_lex_string LEX_STRING;
47
 
struct option;
48
 
 
49
 
extern char *opt_plugin_dir_ptr;
50
 
extern char opt_plugin_dir[FN_REFLEN];
51
 
 
52
 
namespace plugin { class StorageEngine; }
53
 
 
54
 
/*
55
 
  Macros for beginning and ending plugin declarations. Between
56
 
  DRIZZLE_DECLARE_PLUGIN and DRIZZLE_DECLARE_PLUGIN_END there should
57
 
  be a module::Manifest for each plugin to be declared.
58
 
*/
59
 
 
60
 
 
61
 
#define PANDORA_CPP_NAME(x) _drizzled_ ## x ## _plugin_
62
 
#define PANDORA_PLUGIN_NAME(x) PANDORA_CPP_NAME(x)
63
 
#define DRIZZLE_DECLARE_PLUGIN \
64
 
  ::drizzled::module::Manifest PANDORA_PLUGIN_NAME(PANDORA_MODULE_NAME)= 
65
 
 
66
 
 
67
 
#define DRIZZLE_DECLARE_PLUGIN_END
68
 
#define DRIZZLE_PLUGIN(init,system,options) \
69
 
  DRIZZLE_DECLARE_PLUGIN \
70
 
  { \
71
 
    DRIZZLE_VERSION_ID, \
72
 
    STRINGIFY_ARG(PANDORA_MODULE_NAME), \
73
 
    STRINGIFY_ARG(PANDORA_MODULE_VERSION), \
74
 
    STRINGIFY_ARG(PANDORA_MODULE_AUTHOR), \
75
 
    STRINGIFY_ARG(PANDORA_MODULE_TITLE), \
76
 
    PANDORA_MODULE_LICENSE, \
77
 
    init, system, options \
78
 
  } 
79
 
 
 
60
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0100
 
61
 
 
62
/*
 
63
  The allowable types of plugins
 
64
*/
 
65
#define MYSQL_UDF_PLUGIN             0  /* User-defined function        */
 
66
#define MYSQL_STORAGE_ENGINE_PLUGIN  1  /* Storage Engine               */
 
67
#define MYSQL_FTPARSER_PLUGIN        2  /* Full-text parser plugin      */
 
68
#define MYSQL_DAEMON_PLUGIN          3  /* The daemon/raw plugin type */
 
69
#define MYSQL_INFORMATION_SCHEMA_PLUGIN  4  /* The I_S plugin type */
 
70
#define MYSQL_AUDIT_PLUGIN           5  /* The Audit plugin type        */
 
71
#define MYSQL_MAX_PLUGIN_TYPE_NUM    6  /* The number of plugin types   */
 
72
 
 
73
/* We use the following strings to define licenses for plugins */
 
74
#define PLUGIN_LICENSE_PROPRIETARY 0
 
75
#define PLUGIN_LICENSE_GPL 1
 
76
#define PLUGIN_LICENSE_BSD 2
 
77
 
 
78
#define PLUGIN_LICENSE_PROPRIETARY_STRING "PROPRIETARY"
 
79
#define PLUGIN_LICENSE_GPL_STRING "GPL"
 
80
#define PLUGIN_LICENSE_BSD_STRING "BSD"
 
81
 
 
82
/*
 
83
  Macros for beginning and ending plugin declarations.  Between
 
84
  mysql_declare_plugin and mysql_declare_plugin_end there should
 
85
  be a st_mysql_plugin struct for each plugin to be declared.
 
86
*/
 
87
 
 
88
 
 
89
#ifndef MYSQL_DYNAMIC_PLUGIN
 
90
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                   \
 
91
int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION;                                  \
 
92
int PSIZE= sizeof(struct st_mysql_plugin);                                    \
 
93
struct st_mysql_plugin DECLS[]= {
 
94
#else
 
95
#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                   \
 
96
int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION;         \
 
97
int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin);          \
 
98
struct st_mysql_plugin _mysql_plugin_declarations_[]= {
 
99
#endif
 
100
 
 
101
#define mysql_declare_plugin(NAME) \
 
102
__MYSQL_DECLARE_PLUGIN(NAME, \
 
103
                 builtin_ ## NAME ## _plugin_interface_version, \
 
104
                 builtin_ ## NAME ## _sizeof_struct_st_plugin, \
 
105
                 builtin_ ## NAME ## _plugin)
 
106
 
 
107
#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0}}
80
108
 
81
109
/*
82
110
  declarations for SHOW STATUS support in plugins
85
113
{
86
114
  SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG,
87
115
  SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
88
 
  SHOW_FUNC,
89
 
  SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS,
90
 
  SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_INT_NOFLUSH,
91
 
  SHOW_LONGLONG_STATUS, SHOW_DOUBLE, SHOW_SIZE
 
116
  SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE
92
117
};
93
118
 
94
 
struct drizzle_show_var {
 
119
struct st_mysql_show_var {
95
120
  const char *name;
96
121
  char *value;
97
122
  enum enum_mysql_show_type type;
98
123
};
99
124
 
100
 
typedef enum enum_mysql_show_type SHOW_TYPE;
101
 
 
102
125
 
103
126
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
104
 
typedef int (*mysql_show_var_func)(drizzle_show_var *, char *);
 
127
typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *);
105
128
 
106
 
struct st_show_var_func_container {
107
 
  mysql_show_var_func func;
108
 
};
109
129
/*
110
130
  declarations for server variables and command line options
111
131
*/
116
136
#define PLUGIN_VAR_LONG         0x0003
117
137
#define PLUGIN_VAR_LONGLONG     0x0004
118
138
#define PLUGIN_VAR_STR          0x0005
 
139
#define PLUGIN_VAR_ENUM         0x0006
 
140
#define PLUGIN_VAR_SET          0x0007
119
141
#define PLUGIN_VAR_UNSIGNED     0x0080
120
 
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
 
142
#define PLUGIN_VAR_THDLOCAL     0x0100 /* Variable is per-connection */
121
143
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
122
144
#define PLUGIN_VAR_NOSYSVAR     0x0400 /* Not a server variable */
123
145
#define PLUGIN_VAR_NOCMDOPT     0x0800 /* Not a command line option */
126
148
#define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
127
149
#define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
128
150
 
129
 
struct drizzle_sys_var;
130
 
struct drizzle_value;
 
151
struct st_mysql_sys_var;
 
152
struct st_mysql_value;
131
153
 
132
154
/*
133
155
  SYNOPSIS
134
156
    (*mysql_var_check_func)()
135
 
      session               thread handle
 
157
      thd               thread handle
136
158
      var               dynamic variable being altered
137
159
      save              pointer to temporary storage
138
160
      value             user provided value
139
161
  RETURN
140
162
    0   user provided value is OK and the update func may be called.
141
163
    any other value indicates error.
142
 
 
 
164
  
143
165
  This function should parse the user provided value and store in the
144
166
  provided temporary storage any data as required by the update func.
145
167
  There is sufficient space in the temporary storage to store a double.
148
170
  automatically at the end of the statement.
149
171
*/
150
172
 
151
 
typedef int (*mysql_var_check_func)(Session *session,
152
 
                                    drizzle_sys_var *var,
153
 
                                    void *save, drizzle_value *value);
 
173
typedef int (*mysql_var_check_func)(MYSQL_THD thd,
 
174
                                    struct st_mysql_sys_var *var,
 
175
                                    void *save, struct st_mysql_value *value);
154
176
 
155
177
/*
156
178
  SYNOPSIS
157
179
    (*mysql_var_update_func)()
158
 
      session               thread handle
 
180
      thd               thread handle
159
181
      var               dynamic variable being altered
160
182
      var_ptr           pointer to dynamic variable
161
183
      save              pointer to temporary storage
162
184
   RETURN
163
185
     NONE
164
 
 
 
186
   
165
187
   This function should use the validated value stored in the temporary store
166
188
   and persist it in the provided pointer to the dynamic variable.
167
189
   For example, strings may require memory to be allocated.
168
190
*/
169
 
typedef void (*mysql_var_update_func)(Session *session,
170
 
                                      drizzle_sys_var *var,
 
191
typedef void (*mysql_var_update_func)(MYSQL_THD thd,
 
192
                                      struct st_mysql_sys_var *var,
171
193
                                      void *var_ptr, const void *save);
172
194
 
173
195
 
179
201
         PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
180
202
         PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
181
203
 
182
 
#define DRIZZLE_PLUGIN_VAR_HEADER \
 
204
#define MYSQL_PLUGIN_VAR_HEADER \
183
205
  int flags;                    \
184
206
  const char *name;             \
185
207
  const char *comment;          \
186
208
  mysql_var_check_func check;   \
187
209
  mysql_var_update_func update
188
210
 
189
 
#define DRIZZLE_SYSVAR_NAME(name) drizzle_sysvar_ ## name
190
 
#define DRIZZLE_SYSVAR(name) \
191
 
  ((drizzle_sys_var *)(&(DRIZZLE_SYSVAR_NAME(name))))
 
211
#define MYSQL_SYSVAR_NAME(name) mysql_sysvar_ ## name
 
212
#define MYSQL_SYSVAR(name) \
 
213
  ((struct st_mysql_sys_var *)&(MYSQL_SYSVAR_NAME(name)))
192
214
 
193
215
/*
194
216
  for global variables, the value pointer is the first
196
218
  for thread variables, the value offset is the first
197
219
  element after the header, the default value is the second.
198
220
*/
199
 
 
200
 
 
201
 
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
202
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
221
   
 
222
 
 
223
#define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
 
224
  MYSQL_PLUGIN_VAR_HEADER;      \
203
225
  type *value;                  \
204
226
  const type def_val;           \
205
 
} DRIZZLE_SYSVAR_NAME(name)
 
227
} MYSQL_SYSVAR_NAME(name)
206
228
 
207
 
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
208
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
229
#define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
 
230
  MYSQL_PLUGIN_VAR_HEADER;      \
209
231
  type *value; type def_val;    \
210
232
  type min_val; type max_val;   \
211
233
  type blk_sz;                  \
212
 
} DRIZZLE_SYSVAR_NAME(name)
213
 
 
214
 
#define DECLARE_SessionVAR_FUNC(type) \
215
 
  type *(*resolve)(Session *session, int offset)
216
 
 
217
 
#define DECLARE_DRIZZLE_SessionVAR_BASIC(name, type) struct { \
218
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
234
} MYSQL_SYSVAR_NAME(name)
 
235
 
 
236
#define DECLARE_MYSQL_SYSVAR_TYPELIB(name, type) struct { \
 
237
  MYSQL_PLUGIN_VAR_HEADER;      \
 
238
  type *value; type def_val;    \
 
239
  TYPELIB *typelib;             \
 
240
} MYSQL_SYSVAR_NAME(name)
 
241
 
 
242
#define DECLARE_THDVAR_FUNC(type) \
 
243
  type *(*resolve)(MYSQL_THD thd, int offset)
 
244
 
 
245
#define DECLARE_MYSQL_THDVAR_BASIC(name, type) struct { \
 
246
  MYSQL_PLUGIN_VAR_HEADER;      \
219
247
  int offset;                   \
220
248
  const type def_val;           \
221
 
  DECLARE_SessionVAR_FUNC(type);    \
222
 
} DRIZZLE_SYSVAR_NAME(name)
 
249
  DECLARE_THDVAR_FUNC(type);    \
 
250
} MYSQL_SYSVAR_NAME(name)
223
251
 
224
 
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
225
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
252
#define DECLARE_MYSQL_THDVAR_SIMPLE(name, type) struct { \
 
253
  MYSQL_PLUGIN_VAR_HEADER;      \
226
254
  int offset;                   \
227
255
  type def_val; type min_val;   \
228
256
  type max_val; type blk_sz;    \
229
 
  DECLARE_SessionVAR_FUNC(type);    \
230
 
} DRIZZLE_SYSVAR_NAME(name)
 
257
  DECLARE_THDVAR_FUNC(type);    \
 
258
} MYSQL_SYSVAR_NAME(name)
231
259
 
232
 
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
233
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
260
#define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
 
261
  MYSQL_PLUGIN_VAR_HEADER;      \
234
262
  int offset;                   \
235
263
  type def_val;                 \
236
 
  DECLARE_SessionVAR_FUNC(type);    \
 
264
  DECLARE_THDVAR_FUNC(type);    \
237
265
  TYPELIB *typelib;             \
238
 
} DRIZZLE_SYSVAR_NAME(name)
 
266
} MYSQL_SYSVAR_NAME(name)
239
267
 
240
268
 
241
269
/*
242
270
  the following declarations are for use by plugin implementors
243
271
*/
244
272
 
245
 
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
246
 
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
 
273
#define MYSQL_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
 
274
DECLARE_MYSQL_SYSVAR_BASIC(name, char) = { \
247
275
  PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
248
276
  #name, comment, check, update, &varname, def}
249
277
 
250
 
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
251
 
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
 
278
#define MYSQL_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
 
279
DECLARE_MYSQL_SYSVAR_BASIC(name, char *) = { \
252
280
  PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
253
281
  #name, comment, check, update, &varname, def}
254
282
 
255
 
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
256
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
 
283
#define MYSQL_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
284
DECLARE_MYSQL_SYSVAR_SIMPLE(name, int) = { \
257
285
  PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
258
286
  #name, comment, check, update, &varname, def, min, max, blk }
259
287
 
260
 
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
261
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
 
288
#define MYSQL_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
289
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned int) = { \
262
290
  PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
263
291
  #name, comment, check, update, &varname, def, min, max, blk }
264
292
 
265
 
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
266
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
 
293
#define MYSQL_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
294
DECLARE_MYSQL_SYSVAR_SIMPLE(name, long) = { \
267
295
  PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
268
296
  #name, comment, check, update, &varname, def, min, max, blk }
269
297
 
270
 
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
271
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
 
298
#define MYSQL_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
299
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long) = { \
272
300
  PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
273
301
  #name, comment, check, update, &varname, def, min, max, blk }
274
302
 
275
 
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
276
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
 
303
#define MYSQL_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
304
DECLARE_MYSQL_SYSVAR_SIMPLE(name, int64_t) = { \
277
305
  PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
278
306
  #name, comment, check, update, &varname, def, min, max, blk }
279
307
 
280
 
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
281
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
 
308
#define MYSQL_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
309
DECLARE_MYSQL_SYSVAR_SIMPLE(name, uint64_t) = { \
282
310
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
283
311
  #name, comment, check, update, &varname, def, min, max, blk }
284
312
 
285
 
#define DRIZZLE_SessionVAR_BOOL(name, opt, comment, check, update, def) \
286
 
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char) = { \
287
 
  PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
288
 
  #name, comment, check, update, -1, def, NULL}
289
 
 
290
 
#define DRIZZLE_SessionVAR_STR(name, opt, comment, check, update, def) \
291
 
DECLARE_DRIZZLE_SessionVAR_BASIC(name, char *) = { \
292
 
  PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
293
 
  #name, comment, check, update, -1, def, NULL}
294
 
 
295
 
#define DRIZZLE_SessionVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
296
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int) = { \
297
 
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
298
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
299
 
 
300
 
#define DRIZZLE_SessionVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
301
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned int) = { \
302
 
  PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
303
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
304
 
 
305
 
#define DRIZZLE_SessionVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
306
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, long) = { \
307
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
308
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
309
 
 
310
 
#define DRIZZLE_SessionVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
311
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, unsigned long) = { \
312
 
  PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
313
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
314
 
 
315
 
#define DRIZZLE_SessionVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
316
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, int64_t) = { \
317
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | ((opt) & PLUGIN_VAR_MASK), \
318
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
319
 
 
320
 
#define DRIZZLE_SessionVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
321
 
DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, uint64_t) = { \
322
 
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
323
 
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
313
#define MYSQL_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
 
314
DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long) = { \
 
315
  PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
 
316
  #name, comment, check, update, &varname, def, typelib }
 
317
 
 
318
#define MYSQL_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
 
319
DECLARE_MYSQL_SYSVAR_TYPELIB(name, uint64_t) = { \
 
320
  PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
 
321
  #name, comment, check, update, &varname, def, typelib }
 
322
 
 
323
#define MYSQL_THDVAR_BOOL(name, opt, comment, check, update, def) \
 
324
DECLARE_MYSQL_THDVAR_BASIC(name, char) = { \
 
325
  PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
326
  #name, comment, check, update, -1, def, NULL}
 
327
 
 
328
#define MYSQL_THDVAR_STR(name, opt, comment, check, update, def) \
 
329
DECLARE_MYSQL_THDVAR_BASIC(name, char *) = { \
 
330
  PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
331
  #name, comment, check, update, -1, def, NULL}
 
332
 
 
333
#define MYSQL_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
 
334
DECLARE_MYSQL_THDVAR_SIMPLE(name, int) = { \
 
335
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
336
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
337
 
 
338
#define MYSQL_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
 
339
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned int) = { \
 
340
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
341
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
342
 
 
343
#define MYSQL_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
 
344
DECLARE_MYSQL_THDVAR_SIMPLE(name, long) = { \
 
345
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
346
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
347
 
 
348
#define MYSQL_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
 
349
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long) = { \
 
350
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
351
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
352
 
 
353
#define MYSQL_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
354
DECLARE_MYSQL_THDVAR_SIMPLE(name, int64_t) = { \
 
355
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
356
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
357
 
 
358
#define MYSQL_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
359
DECLARE_MYSQL_THDVAR_SIMPLE(name, uint64_t) = { \
 
360
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
361
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
362
 
 
363
#define MYSQL_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
 
364
DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long) = { \
 
365
  PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
366
  #name, comment, check, update, -1, def, NULL, typelib }
 
367
 
 
368
#define MYSQL_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
 
369
DECLARE_MYSQL_THDVAR_TYPELIB(name, uint64_t) = { \
 
370
  PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
371
  #name, comment, check, update, -1, def, NULL, typelib }
324
372
 
325
373
/* accessor macros */
326
374
 
327
375
#define SYSVAR(name) \
328
 
  (*(DRIZZLE_SYSVAR_NAME(name).value))
329
 
 
330
 
/* when session == null, result points to global value */
331
 
#define SessionVAR(session, name) \
332
 
  (*(DRIZZLE_SYSVAR_NAME(name).resolve(session, DRIZZLE_SYSVAR_NAME(name).offset)))
333
 
 
334
 
 
335
 
/*************************************************************************
336
 
  drizzle_value struct for reading values from mysqld.
 
376
  (*(MYSQL_SYSVAR_NAME(name).value))
 
377
 
 
378
/* when thd == null, result points to global value */
 
379
#define THDVAR(thd, name) \
 
380
  (*(MYSQL_SYSVAR_NAME(name).resolve(thd, MYSQL_SYSVAR_NAME(name).offset)))
 
381
 
 
382
 
 
383
/*
 
384
  Plugin description structure.
 
385
*/
 
386
 
 
387
struct st_mysql_plugin
 
388
{
 
389
  int type;             /* the plugin type (a MYSQL_XXX_PLUGIN value)   */
 
390
  void *info;           /* pointer to type-specific plugin descriptor   */
 
391
  const char *name;     /* plugin name                                  */
 
392
  const char *author;   /* plugin author (for SHOW PLUGINS)             */
 
393
  const char *descr;    /* general descriptive text (for SHOW PLUGINS ) */
 
394
  int license;          /* the plugin license (PLUGIN_LICENSE_XXX)      */
 
395
  int (*init)(void *);  /* the function to invoke when plugin is loaded */
 
396
  int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
 
397
  unsigned int version; /* plugin version (for SHOW PLUGINS)            */
 
398
  struct st_mysql_show_var *status_vars;
 
399
  struct st_mysql_sys_var **system_vars;
 
400
  void * __reserved1;   /* reserved for dependency checking             */
 
401
};
 
402
 
 
403
/*************************************************************************
 
404
  API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
 
405
*/
 
406
#include "plugin_ftparser.h"
 
407
 
 
408
/*************************************************************************
 
409
  API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
 
410
*/
 
411
 
 
412
/* handlertons of different MySQL releases are incompatible */
 
413
#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
414
 
 
415
/*
 
416
  Here we define only the descriptor structure, that is referred from
 
417
  st_mysql_plugin.
 
418
*/
 
419
 
 
420
struct st_mysql_daemon
 
421
{
 
422
  int interface_version;
 
423
};
 
424
 
 
425
 
 
426
/*************************************************************************
 
427
  API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
 
428
*/
 
429
 
 
430
/* handlertons of different MySQL releases are incompatible */
 
431
#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
432
 
 
433
/*
 
434
  Here we define only the descriptor structure, that is referred from
 
435
  st_mysql_plugin.
 
436
*/
 
437
 
 
438
struct st_mysql_information_schema
 
439
{
 
440
  int interface_version;
 
441
};
 
442
 
 
443
 
 
444
/*************************************************************************
 
445
  API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
 
446
*/
 
447
 
 
448
/* handlertons of different MySQL releases are incompatible */
 
449
#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
450
 
 
451
/*
 
452
  The real API is in the sql/handler.h
 
453
  Here we define only the descriptor structure, that is referred from
 
454
  st_mysql_plugin.
 
455
*/
 
456
 
 
457
struct st_mysql_storage_engine
 
458
{
 
459
  int interface_version;
 
460
};
 
461
 
 
462
struct handlerton;
 
463
 
 
464
 
 
465
/*************************************************************************
 
466
  st_mysql_value struct for reading values from mysqld.
337
467
  Used by server variables framework to parse user-provided values.
338
468
  Will be used for arguments when implementing UDFs.
339
469
 
342
472
  if you need it to persist.
343
473
*/
344
474
 
345
 
#define DRIZZLE_VALUE_TYPE_STRING 0
346
 
#define DRIZZLE_VALUE_TYPE_REAL   1
347
 
#define DRIZZLE_VALUE_TYPE_INT    2
348
 
 
349
 
/*
350
 
  skeleton of a plugin variable - portion of structure common to all.
351
 
*/
352
 
struct drizzle_sys_var
353
 
{
354
 
  DRIZZLE_PLUGIN_VAR_HEADER;
355
 
};
356
 
 
357
 
void plugin_opt_set_limits(option *options, const drizzle_sys_var *opt);
358
 
 
359
 
struct drizzle_value
360
 
{
361
 
  int (*value_type)(drizzle_value *);
362
 
  const char *(*val_str)(drizzle_value *, char *buffer, int *length);
363
 
  int (*val_real)(drizzle_value *, double *realbuf);
364
 
  int (*val_int)(drizzle_value *, int64_t *intbuf);
 
475
#define MYSQL_VALUE_TYPE_STRING 0
 
476
#define MYSQL_VALUE_TYPE_REAL   1
 
477
#define MYSQL_VALUE_TYPE_INT    2
 
478
 
 
479
struct st_mysql_value
 
480
{
 
481
  int (*value_type)(struct st_mysql_value *);
 
482
  const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
 
483
  int (*val_real)(struct st_mysql_value *, double *realbuf);
 
484
  int (*val_int)(struct st_mysql_value *, int64_t *intbuf);
365
485
};
366
486
 
367
487
 
369
489
  Miscellaneous functions for plugin implementors
370
490
*/
371
491
 
372
 
extern bool plugin_init(module::Registry &registry,
373
 
                        boost::program_options::options_description &long_options);
374
 
extern void plugin_finalize(module::Registry &registry);
375
 
extern void my_print_help_inc_plugins(option *options);
376
 
extern bool plugin_is_ready(const LEX_STRING *name, int type);
377
 
extern void plugin_sessionvar_init(Session *session);
378
 
extern void plugin_sessionvar_cleanup(Session *session);
379
 
extern sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error);
380
 
 
381
 
int session_in_lock_tables(const Session *session);
382
 
int session_tablespace_op(const Session *session);
383
 
void set_session_proc_info(Session *session, const char *info);
384
 
const char *get_session_proc_info(Session *session);
385
 
int64_t session_test_options(const Session *session, int64_t test_options);
386
 
int session_sql_command(const Session *session);
387
 
enum_tx_isolation session_tx_isolation(const Session *session);
388
 
 
389
 
void compose_plugin_add(std::vector<std::string> options);
390
 
void compose_plugin_remove(std::vector<std::string> options);
391
 
void notify_plugin_load(std::string in_plugin_load);
392
 
 
 
492
#ifdef __cplusplus
 
493
extern "C" {
 
494
#endif
 
495
 
 
496
int thd_in_lock_tables(const MYSQL_THD thd);
 
497
int thd_tablespace_op(const MYSQL_THD thd);
 
498
int64_t thd_test_options(const MYSQL_THD thd, int64_t test_options);
 
499
int thd_sql_command(const MYSQL_THD thd);
 
500
const char *thd_proc_info(MYSQL_THD thd, const char *info);
 
501
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
 
502
int thd_tx_isolation(const MYSQL_THD thd);
 
503
char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
 
504
                           unsigned int max_query_len);
 
505
/* Increments the row counter, see THD::row_count */
 
506
void thd_inc_row_count(MYSQL_THD thd);
393
507
 
394
508
/**
395
509
  Create a temporary file.
401
515
 
402
516
  @param prefix  prefix for temporary file name
403
517
  @retval -1    error
404
 
  @retval >= 0  a file handle that can be passed to dup or internal::my_close
 
518
  @retval >= 0  a file handle that can be passed to dup or my_close
405
519
*/
406
520
int mysql_tmpfile(const char *prefix);
407
521
 
415
529
  time-consuming loops, and gracefully abort the operation if it is
416
530
  non-zero.
417
531
 
418
 
  @param session  user thread connection handle
 
532
  @param thd  user thread connection handle
419
533
  @retval 0  the connection is active
420
534
  @retval 1  the connection has been killed
421
535
*/
422
 
int session_killed(const Session *session);
423
 
 
424
 
 
425
 
const charset_info_st *session_charset(Session *session);
 
536
int thd_killed(const MYSQL_THD thd);
 
537
 
 
538
 
 
539
/**
 
540
  Return the thread id of a user thread
 
541
 
 
542
  @param thd  user thread connection handle
 
543
  @return  thread id
 
544
*/
 
545
unsigned long thd_get_thread_id(const MYSQL_THD thd);
 
546
 
 
547
 
 
548
/**
 
549
  Allocate memory in the connection's local memory pool
 
550
 
 
551
  @details
 
552
  When properly used in place of @c my_malloc(), this can significantly
 
553
  improve concurrency. Don't use this or related functions to allocate
 
554
  large chunks of memory. Use for temporary storage only. The memory
 
555
  will be freed automatically at the end of the statement; no explicit
 
556
  code is required to prevent memory leaks.
 
557
 
 
558
  @see alloc_root()
 
559
*/
 
560
void *thd_alloc(MYSQL_THD thd, unsigned int size);
 
561
/**
 
562
  @see thd_alloc()
 
563
*/
 
564
void *thd_calloc(MYSQL_THD thd, unsigned int size);
 
565
/**
 
566
  @see thd_alloc()
 
567
*/
 
568
char *thd_strdup(MYSQL_THD thd, const char *str);
 
569
/**
 
570
  @see thd_alloc()
 
571
*/
 
572
char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
 
573
/**
 
574
  @see thd_alloc()
 
575
*/
 
576
void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
 
577
 
 
578
/**
 
579
  Create a LEX_STRING in this connection's local memory pool
 
580
 
 
581
  @param thd      user thread connection handle
 
582
  @param lex_str  pointer to LEX_STRING object to be initialized
 
583
  @param str      initializer to be copied into lex_str
 
584
  @param size     length of str, in bytes
 
585
  @param allocate_lex_string  flag: if TRUE, allocate new LEX_STRING object,
 
586
                              instead of using lex_str value
 
587
  @return  NULL on failure, or pointer to the LEX_STRING object
 
588
 
 
589
  @see thd_alloc()
 
590
*/
 
591
MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
 
592
                                      const char *str, unsigned int size,
 
593
                                      int allocate_lex_string);
 
594
 
 
595
/**
 
596
  Get the XID for this connection's transaction
 
597
 
 
598
  @param thd  user thread connection handle
 
599
  @param xid  location where identifier is stored
 
600
*/
 
601
void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
426
602
 
427
603
/**
428
604
  Invalidate the query cache for a given table.
429
605
 
430
 
  @param session         user thread connection handle
 
606
  @param thd         user thread connection handle
431
607
  @param key         databasename\\0tablename\\0
432
608
  @param key_length  length of key in bytes, including the NUL bytes
433
609
  @param using_trx   flag: TRUE if using transactions, FALSE otherwise
434
610
*/
435
 
void mysql_query_cache_invalidate4(Session *session,
 
611
void mysql_query_cache_invalidate4(MYSQL_THD thd,
436
612
                                   const char *key, unsigned int key_length,
437
613
                                   int using_trx);
438
614
 
439
 
} /* namespace drizzled */
440
 
 
441
 
#endif /* DRIZZLED_PLUGIN_H */
 
615
#ifdef __cplusplus
 
616
}
 
617
#endif
 
618
 
 
619
#ifdef __cplusplus
 
620
/**
 
621
  Provide a handler data getter to simplify coding
 
622
*/
 
623
inline
 
624
void *
 
625
thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton)
 
626
{
 
627
  return *thd_ha_data(thd, hton);
 
628
}
 
629
 
 
630
/**
 
631
  Provide a handler data setter to simplify coding
 
632
*/
 
633
inline
 
634
void
 
635
thd_set_ha_data(const MYSQL_THD thd, const struct handlerton *hton,
 
636
                const void *ha_data)
 
637
{
 
638
  *thd_ha_data(thd, hton)= (void*) ha_data;
 
639
}
 
640
#endif
 
641
 
 
642
#endif
442
643