~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/mysql/plugin.h

  • Committer: Monty Taylor
  • Date: 2008-07-11 15:23:55 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 134.
  • Revision ID: monty@inaugust.com-20080711152355-o92cod4mg0u9ck03
More const-correctness.

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
129
struct st_show_var_func_container {
107
130
  mysql_show_var_func func;
116
139
#define PLUGIN_VAR_LONG         0x0003
117
140
#define PLUGIN_VAR_LONGLONG     0x0004
118
141
#define PLUGIN_VAR_STR          0x0005
 
142
#define PLUGIN_VAR_ENUM         0x0006
 
143
#define PLUGIN_VAR_SET          0x0007
119
144
#define PLUGIN_VAR_UNSIGNED     0x0080
120
 
#define PLUGIN_VAR_SessionLOCAL     0x0100 /* Variable is per-connection */
 
145
#define PLUGIN_VAR_THDLOCAL     0x0100 /* Variable is per-connection */
121
146
#define PLUGIN_VAR_READONLY     0x0200 /* Server variable is read only */
122
147
#define PLUGIN_VAR_NOSYSVAR     0x0400 /* Not a server variable */
123
148
#define PLUGIN_VAR_NOCMDOPT     0x0800 /* Not a command line option */
126
151
#define PLUGIN_VAR_OPCMDARG     0x2000 /* Argument optional for cmd line */
127
152
#define PLUGIN_VAR_MEMALLOC     0x8000 /* String needs memory allocated */
128
153
 
129
 
struct drizzle_sys_var;
130
 
struct drizzle_value;
 
154
struct st_mysql_sys_var;
 
155
struct st_mysql_value;
131
156
 
132
157
/*
133
158
  SYNOPSIS
134
159
    (*mysql_var_check_func)()
135
 
      session               thread handle
 
160
      thd               thread handle
136
161
      var               dynamic variable being altered
137
162
      save              pointer to temporary storage
138
163
      value             user provided value
139
164
  RETURN
140
165
    0   user provided value is OK and the update func may be called.
141
166
    any other value indicates error.
142
 
 
 
167
  
143
168
  This function should parse the user provided value and store in the
144
169
  provided temporary storage any data as required by the update func.
145
170
  There is sufficient space in the temporary storage to store a double.
148
173
  automatically at the end of the statement.
149
174
*/
150
175
 
151
 
typedef int (*mysql_var_check_func)(Session *session,
152
 
                                    drizzle_sys_var *var,
153
 
                                    void *save, drizzle_value *value);
 
176
typedef int (*mysql_var_check_func)(MYSQL_THD thd,
 
177
                                    struct st_mysql_sys_var *var,
 
178
                                    void *save, struct st_mysql_value *value);
154
179
 
155
180
/*
156
181
  SYNOPSIS
157
182
    (*mysql_var_update_func)()
158
 
      session               thread handle
 
183
      thd               thread handle
159
184
      var               dynamic variable being altered
160
185
      var_ptr           pointer to dynamic variable
161
186
      save              pointer to temporary storage
162
187
   RETURN
163
188
     NONE
164
 
 
 
189
   
165
190
   This function should use the validated value stored in the temporary store
166
191
   and persist it in the provided pointer to the dynamic variable.
167
192
   For example, strings may require memory to be allocated.
168
193
*/
169
 
typedef void (*mysql_var_update_func)(Session *session,
170
 
                                      drizzle_sys_var *var,
 
194
typedef void (*mysql_var_update_func)(MYSQL_THD thd,
 
195
                                      struct st_mysql_sys_var *var,
171
196
                                      void *var_ptr, const void *save);
172
197
 
173
198
 
179
204
         PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
180
205
         PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
181
206
 
182
 
#define DRIZZLE_PLUGIN_VAR_HEADER \
 
207
#define MYSQL_PLUGIN_VAR_HEADER \
183
208
  int flags;                    \
184
209
  const char *name;             \
185
210
  const char *comment;          \
186
211
  mysql_var_check_func check;   \
187
212
  mysql_var_update_func update
188
213
 
189
 
#define DRIZZLE_SYSVAR_NAME(name) drizzle_sysvar_ ## name
190
 
#define DRIZZLE_SYSVAR(name) \
191
 
  ((drizzle_sys_var *)(&(DRIZZLE_SYSVAR_NAME(name))))
 
214
#define MYSQL_SYSVAR_NAME(name) mysql_sysvar_ ## name
 
215
#define MYSQL_SYSVAR(name) \
 
216
  ((struct st_mysql_sys_var *)&(MYSQL_SYSVAR_NAME(name)))
192
217
 
193
218
/*
194
219
  for global variables, the value pointer is the first
196
221
  for thread variables, the value offset is the first
197
222
  element after the header, the default value is the second.
198
223
*/
199
 
 
200
 
 
201
 
#define DECLARE_DRIZZLE_SYSVAR_BASIC(name, type) struct { \
202
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
224
   
 
225
 
 
226
#define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \
 
227
  MYSQL_PLUGIN_VAR_HEADER;      \
203
228
  type *value;                  \
204
229
  const type def_val;           \
205
 
} DRIZZLE_SYSVAR_NAME(name)
 
230
} MYSQL_SYSVAR_NAME(name)
206
231
 
207
 
#define DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, type) struct { \
208
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
232
#define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \
 
233
  MYSQL_PLUGIN_VAR_HEADER;      \
209
234
  type *value; type def_val;    \
210
235
  type min_val; type max_val;   \
211
236
  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;      \
 
237
} MYSQL_SYSVAR_NAME(name)
 
238
 
 
239
#define DECLARE_MYSQL_SYSVAR_TYPELIB(name, type) struct { \
 
240
  MYSQL_PLUGIN_VAR_HEADER;      \
 
241
  type *value; type def_val;    \
 
242
  TYPELIB *typelib;             \
 
243
} MYSQL_SYSVAR_NAME(name)
 
244
 
 
245
#define DECLARE_THDVAR_FUNC(type) \
 
246
  type *(*resolve)(MYSQL_THD thd, int offset)
 
247
 
 
248
#define DECLARE_MYSQL_THDVAR_BASIC(name, type) struct { \
 
249
  MYSQL_PLUGIN_VAR_HEADER;      \
219
250
  int offset;                   \
220
251
  const type def_val;           \
221
 
  DECLARE_SessionVAR_FUNC(type);    \
222
 
} DRIZZLE_SYSVAR_NAME(name)
 
252
  DECLARE_THDVAR_FUNC(type);    \
 
253
} MYSQL_SYSVAR_NAME(name)
223
254
 
224
 
#define DECLARE_DRIZZLE_SessionVAR_SIMPLE(name, type) struct { \
225
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
255
#define DECLARE_MYSQL_THDVAR_SIMPLE(name, type) struct { \
 
256
  MYSQL_PLUGIN_VAR_HEADER;      \
226
257
  int offset;                   \
227
258
  type def_val; type min_val;   \
228
259
  type max_val; type blk_sz;    \
229
 
  DECLARE_SessionVAR_FUNC(type);    \
230
 
} DRIZZLE_SYSVAR_NAME(name)
 
260
  DECLARE_THDVAR_FUNC(type);    \
 
261
} MYSQL_SYSVAR_NAME(name)
231
262
 
232
 
#define DECLARE_DRIZZLE_SessionVAR_TYPELIB(name, type) struct { \
233
 
  DRIZZLE_PLUGIN_VAR_HEADER;      \
 
263
#define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \
 
264
  MYSQL_PLUGIN_VAR_HEADER;      \
234
265
  int offset;                   \
235
266
  type def_val;                 \
236
 
  DECLARE_SessionVAR_FUNC(type);    \
 
267
  DECLARE_THDVAR_FUNC(type);    \
237
268
  TYPELIB *typelib;             \
238
 
} DRIZZLE_SYSVAR_NAME(name)
 
269
} MYSQL_SYSVAR_NAME(name)
239
270
 
240
271
 
241
272
/*
242
273
  the following declarations are for use by plugin implementors
243
274
*/
244
275
 
245
 
#define DRIZZLE_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
246
 
DECLARE_DRIZZLE_SYSVAR_BASIC(name, bool) = { \
 
276
#define MYSQL_SYSVAR_BOOL(name, varname, opt, comment, check, update, def) \
 
277
DECLARE_MYSQL_SYSVAR_BASIC(name, char) = { \
247
278
  PLUGIN_VAR_BOOL | ((opt) & PLUGIN_VAR_MASK), \
248
279
  #name, comment, check, update, &varname, def}
249
280
 
250
 
#define DRIZZLE_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
251
 
DECLARE_DRIZZLE_SYSVAR_BASIC(name, char *) = { \
 
281
#define MYSQL_SYSVAR_STR(name, varname, opt, comment, check, update, def) \
 
282
DECLARE_MYSQL_SYSVAR_BASIC(name, char *) = { \
252
283
  PLUGIN_VAR_STR | ((opt) & PLUGIN_VAR_MASK), \
253
284
  #name, comment, check, update, &varname, def}
254
285
 
255
 
#define DRIZZLE_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
256
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int) = { \
 
286
#define MYSQL_SYSVAR_INT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
287
DECLARE_MYSQL_SYSVAR_SIMPLE(name, int) = { \
257
288
  PLUGIN_VAR_INT | ((opt) & PLUGIN_VAR_MASK), \
258
289
  #name, comment, check, update, &varname, def, min, max, blk }
259
290
 
260
 
#define DRIZZLE_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
261
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned int) = { \
 
291
#define MYSQL_SYSVAR_UINT(name, varname, opt, comment, check, update, def, min, max, blk) \
 
292
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned int) = { \
262
293
  PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
263
294
  #name, comment, check, update, &varname, def, min, max, blk }
264
295
 
265
 
#define DRIZZLE_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
266
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, long) = { \
 
296
#define MYSQL_SYSVAR_LONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
297
DECLARE_MYSQL_SYSVAR_SIMPLE(name, long) = { \
267
298
  PLUGIN_VAR_LONG | ((opt) & PLUGIN_VAR_MASK), \
268
299
  #name, comment, check, update, &varname, def, min, max, blk }
269
300
 
270
 
#define DRIZZLE_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
271
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, unsigned long) = { \
 
301
#define MYSQL_SYSVAR_ULONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
302
DECLARE_MYSQL_SYSVAR_SIMPLE(name, unsigned long) = { \
272
303
  PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
273
304
  #name, comment, check, update, &varname, def, min, max, blk }
274
305
 
275
 
#define DRIZZLE_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
276
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, int64_t) = { \
 
306
#define MYSQL_SYSVAR_LONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
307
DECLARE_MYSQL_SYSVAR_SIMPLE(name, int64_t) = { \
277
308
  PLUGIN_VAR_LONGLONG | ((opt) & PLUGIN_VAR_MASK), \
278
309
  #name, comment, check, update, &varname, def, min, max, blk }
279
310
 
280
 
#define DRIZZLE_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
281
 
DECLARE_DRIZZLE_SYSVAR_SIMPLE(name, uint64_t) = { \
 
311
#define MYSQL_SYSVAR_ULONGLONG(name, varname, opt, comment, check, update, def, min, max, blk) \
 
312
DECLARE_MYSQL_SYSVAR_SIMPLE(name, uint64_t) = { \
282
313
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
283
314
  #name, comment, check, update, &varname, def, min, max, blk }
284
315
 
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 }
 
316
#define MYSQL_SYSVAR_ENUM(name, varname, opt, comment, check, update, def, typelib) \
 
317
DECLARE_MYSQL_SYSVAR_TYPELIB(name, unsigned long) = { \
 
318
  PLUGIN_VAR_ENUM | ((opt) & PLUGIN_VAR_MASK), \
 
319
  #name, comment, check, update, &varname, def, typelib }
 
320
 
 
321
#define MYSQL_SYSVAR_SET(name, varname, opt, comment, check, update, def, typelib) \
 
322
DECLARE_MYSQL_SYSVAR_TYPELIB(name, uint64_t) = { \
 
323
  PLUGIN_VAR_SET | ((opt) & PLUGIN_VAR_MASK), \
 
324
  #name, comment, check, update, &varname, def, typelib }
 
325
 
 
326
#define MYSQL_THDVAR_BOOL(name, opt, comment, check, update, def) \
 
327
DECLARE_MYSQL_THDVAR_BASIC(name, char) = { \
 
328
  PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
329
  #name, comment, check, update, -1, def, NULL}
 
330
 
 
331
#define MYSQL_THDVAR_STR(name, opt, comment, check, update, def) \
 
332
DECLARE_MYSQL_THDVAR_BASIC(name, char *) = { \
 
333
  PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
334
  #name, comment, check, update, -1, def, NULL}
 
335
 
 
336
#define MYSQL_THDVAR_INT(name, opt, comment, check, update, def, min, max, blk) \
 
337
DECLARE_MYSQL_THDVAR_SIMPLE(name, int) = { \
 
338
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
339
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
340
 
 
341
#define MYSQL_THDVAR_UINT(name, opt, comment, check, update, def, min, max, blk) \
 
342
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned int) = { \
 
343
  PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
344
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
345
 
 
346
#define MYSQL_THDVAR_LONG(name, opt, comment, check, update, def, min, max, blk) \
 
347
DECLARE_MYSQL_THDVAR_SIMPLE(name, long) = { \
 
348
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
349
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
350
 
 
351
#define MYSQL_THDVAR_ULONG(name, opt, comment, check, update, def, min, max, blk) \
 
352
DECLARE_MYSQL_THDVAR_SIMPLE(name, unsigned long) = { \
 
353
  PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
354
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
355
 
 
356
#define MYSQL_THDVAR_LONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
357
DECLARE_MYSQL_THDVAR_SIMPLE(name, int64_t) = { \
 
358
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
359
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
360
 
 
361
#define MYSQL_THDVAR_ULONGLONG(name, opt, comment, check, update, def, min, max, blk) \
 
362
DECLARE_MYSQL_THDVAR_SIMPLE(name, uint64_t) = { \
 
363
  PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_UNSIGNED | ((opt) & PLUGIN_VAR_MASK), \
 
364
  #name, comment, check, update, -1, def, min, max, blk, NULL }
 
365
 
 
366
#define MYSQL_THDVAR_ENUM(name, opt, comment, check, update, def, typelib) \
 
367
DECLARE_MYSQL_THDVAR_TYPELIB(name, unsigned long) = { \
 
368
  PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
369
  #name, comment, check, update, -1, def, NULL, typelib }
 
370
 
 
371
#define MYSQL_THDVAR_SET(name, opt, comment, check, update, def, typelib) \
 
372
DECLARE_MYSQL_THDVAR_TYPELIB(name, uint64_t) = { \
 
373
  PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL | ((opt) & PLUGIN_VAR_MASK), \
 
374
  #name, comment, check, update, -1, def, NULL, typelib }
324
375
 
325
376
/* accessor macros */
326
377
 
327
378
#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.
 
379
  (*(MYSQL_SYSVAR_NAME(name).value))
 
380
 
 
381
/* when thd == null, result points to global value */
 
382
#define THDVAR(thd, name) \
 
383
  (*(MYSQL_SYSVAR_NAME(name).resolve(thd, MYSQL_SYSVAR_NAME(name).offset)))
 
384
 
 
385
 
 
386
/*
 
387
  Plugin description structure.
 
388
*/
 
389
 
 
390
struct st_mysql_plugin
 
391
{
 
392
  int type;             /* the plugin type (a MYSQL_XXX_PLUGIN value)   */
 
393
  void *info;           /* pointer to type-specific plugin descriptor   */
 
394
  const char *name;     /* plugin name                                  */
 
395
  const char *author;   /* plugin author (for SHOW PLUGINS)             */
 
396
  const char *descr;    /* general descriptive text (for SHOW PLUGINS ) */
 
397
  int license;          /* the plugin license (PLUGIN_LICENSE_XXX)      */
 
398
  int (*init)(void *);  /* the function to invoke when plugin is loaded */
 
399
  int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
 
400
  unsigned int version; /* plugin version (for SHOW PLUGINS)            */
 
401
  struct st_mysql_show_var *status_vars;
 
402
  struct st_mysql_sys_var **system_vars;
 
403
  void * __reserved1;   /* reserved for dependency checking             */
 
404
};
 
405
 
 
406
/*************************************************************************
 
407
  API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN)
 
408
*/
 
409
#include "plugin_ftparser.h"
 
410
 
 
411
/*************************************************************************
 
412
  API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
 
413
*/
 
414
 
 
415
/* handlertons of different MySQL releases are incompatible */
 
416
#define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
417
 
 
418
/*
 
419
  Here we define only the descriptor structure, that is referred from
 
420
  st_mysql_plugin.
 
421
*/
 
422
 
 
423
struct st_mysql_daemon
 
424
{
 
425
  int interface_version;
 
426
};
 
427
 
 
428
 
 
429
/*************************************************************************
 
430
  API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN)
 
431
*/
 
432
 
 
433
/* handlertons of different MySQL releases are incompatible */
 
434
#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
435
 
 
436
/*
 
437
  Here we define only the descriptor structure, that is referred from
 
438
  st_mysql_plugin.
 
439
*/
 
440
 
 
441
struct st_mysql_information_schema
 
442
{
 
443
  int interface_version;
 
444
};
 
445
 
 
446
 
 
447
/*************************************************************************
 
448
  API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
 
449
*/
 
450
 
 
451
/* handlertons of different MySQL releases are incompatible */
 
452
#define MYSQL_HANDLERTON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
 
453
 
 
454
/*
 
455
  The real API is in the sql/handler.h
 
456
  Here we define only the descriptor structure, that is referred from
 
457
  st_mysql_plugin.
 
458
*/
 
459
 
 
460
struct st_mysql_storage_engine
 
461
{
 
462
  int interface_version;
 
463
};
 
464
 
 
465
struct handlerton;
 
466
 
 
467
 
 
468
/*************************************************************************
 
469
  st_mysql_value struct for reading values from mysqld.
337
470
  Used by server variables framework to parse user-provided values.
338
471
  Will be used for arguments when implementing UDFs.
339
472
 
342
475
  if you need it to persist.
343
476
*/
344
477
 
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);
 
478
#define MYSQL_VALUE_TYPE_STRING 0
 
479
#define MYSQL_VALUE_TYPE_REAL   1
 
480
#define MYSQL_VALUE_TYPE_INT    2
 
481
 
 
482
struct st_mysql_value
 
483
{
 
484
  int (*value_type)(struct st_mysql_value *);
 
485
  const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length);
 
486
  int (*val_real)(struct st_mysql_value *, double *realbuf);
 
487
  int (*val_int)(struct st_mysql_value *, int64_t *intbuf);
365
488
};
366
489
 
367
490
 
369
492
  Miscellaneous functions for plugin implementors
370
493
*/
371
494
 
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
 
 
 
495
#ifdef __cplusplus
 
496
extern "C" {
 
497
#endif
 
498
 
 
499
int thd_in_lock_tables(const MYSQL_THD thd);
 
500
int thd_tablespace_op(const MYSQL_THD thd);
 
501
int64_t thd_test_options(const MYSQL_THD thd, int64_t test_options);
 
502
int thd_sql_command(const MYSQL_THD thd);
 
503
const char *thd_proc_info(MYSQL_THD thd, const char *info);
 
504
void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
 
505
int thd_tx_isolation(const MYSQL_THD thd);
 
506
char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length,
 
507
                           unsigned int max_query_len);
 
508
/* Increments the row counter, see THD::row_count */
 
509
void thd_inc_row_count(MYSQL_THD thd);
393
510
 
394
511
/**
395
512
  Create a temporary file.
401
518
 
402
519
  @param prefix  prefix for temporary file name
403
520
  @retval -1    error
404
 
  @retval >= 0  a file handle that can be passed to dup or internal::my_close
 
521
  @retval >= 0  a file handle that can be passed to dup or my_close
405
522
*/
406
523
int mysql_tmpfile(const char *prefix);
407
524
 
415
532
  time-consuming loops, and gracefully abort the operation if it is
416
533
  non-zero.
417
534
 
418
 
  @param session  user thread connection handle
 
535
  @param thd  user thread connection handle
419
536
  @retval 0  the connection is active
420
537
  @retval 1  the connection has been killed
421
538
*/
422
 
int session_killed(const Session *session);
423
 
 
424
 
 
425
 
const charset_info_st *session_charset(Session *session);
 
539
int thd_killed(const MYSQL_THD thd);
 
540
 
 
541
 
 
542
/**
 
543
  Return the thread id of a user thread
 
544
 
 
545
  @param thd  user thread connection handle
 
546
  @return  thread id
 
547
*/
 
548
unsigned long thd_get_thread_id(const MYSQL_THD thd);
 
549
 
 
550
 
 
551
/**
 
552
  Allocate memory in the connection's local memory pool
 
553
 
 
554
  @details
 
555
  When properly used in place of @c my_malloc(), this can significantly
 
556
  improve concurrency. Don't use this or related functions to allocate
 
557
  large chunks of memory. Use for temporary storage only. The memory
 
558
  will be freed automatically at the end of the statement; no explicit
 
559
  code is required to prevent memory leaks.
 
560
 
 
561
  @see alloc_root()
 
562
*/
 
563
void *thd_alloc(MYSQL_THD thd, unsigned int size);
 
564
/**
 
565
  @see thd_alloc()
 
566
*/
 
567
void *thd_calloc(MYSQL_THD thd, unsigned int size);
 
568
/**
 
569
  @see thd_alloc()
 
570
*/
 
571
char *thd_strdup(MYSQL_THD thd, const char *str);
 
572
/**
 
573
  @see thd_alloc()
 
574
*/
 
575
char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size);
 
576
/**
 
577
  @see thd_alloc()
 
578
*/
 
579
void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size);
 
580
 
 
581
/**
 
582
  Create a LEX_STRING in this connection's local memory pool
 
583
 
 
584
  @param thd      user thread connection handle
 
585
  @param lex_str  pointer to LEX_STRING object to be initialized
 
586
  @param str      initializer to be copied into lex_str
 
587
  @param size     length of str, in bytes
 
588
  @param allocate_lex_string  flag: if TRUE, allocate new LEX_STRING object,
 
589
                              instead of using lex_str value
 
590
  @return  NULL on failure, or pointer to the LEX_STRING object
 
591
 
 
592
  @see thd_alloc()
 
593
*/
 
594
MYSQL_LEX_STRING *thd_make_lex_string(MYSQL_THD thd, MYSQL_LEX_STRING *lex_str,
 
595
                                      const char *str, unsigned int size,
 
596
                                      int allocate_lex_string);
 
597
 
 
598
/**
 
599
  Get the XID for this connection's transaction
 
600
 
 
601
  @param thd  user thread connection handle
 
602
  @param xid  location where identifier is stored
 
603
*/
 
604
void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid);
426
605
 
427
606
/**
428
607
  Invalidate the query cache for a given table.
429
608
 
430
 
  @param session         user thread connection handle
 
609
  @param thd         user thread connection handle
431
610
  @param key         databasename\\0tablename\\0
432
611
  @param key_length  length of key in bytes, including the NUL bytes
433
612
  @param using_trx   flag: TRUE if using transactions, FALSE otherwise
434
613
*/
435
 
void mysql_query_cache_invalidate4(Session *session,
 
614
void mysql_query_cache_invalidate4(MYSQL_THD thd,
436
615
                                   const char *key, unsigned int key_length,
437
616
                                   int using_trx);
438
617
 
439
 
} /* namespace drizzled */
440
 
 
441
 
#endif /* DRIZZLED_PLUGIN_H */
 
618
#ifdef __cplusplus
 
619
}
 
620
#endif
 
621
 
 
622
#ifdef __cplusplus
 
623
/**
 
624
  Provide a handler data getter to simplify coding
 
625
*/
 
626
inline
 
627
void *
 
628
thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton)
 
629
{
 
630
  return *thd_ha_data(thd, hton);
 
631
}
 
632
 
 
633
/**
 
634
  Provide a handler data setter to simplify coding
 
635
*/
 
636
inline
 
637
void
 
638
thd_set_ha_data(const MYSQL_THD thd, const struct handlerton *hton,
 
639
                const void *ha_data)
 
640
{
 
641
  *thd_ha_data(thd, hton)= (void*) ha_data;
 
642
}
 
643
#endif
 
644
 
 
645
#endif
442
646