MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_plugin.h
1 /* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
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 Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #ifndef _sql_plugin_h
17 #define _sql_plugin_h
18 
19 #include <my_global.h>
20 #include <vector>
21 
26 #define SHOW_always_last SHOW_KEY_CACHE_LONG, \
27  SHOW_KEY_CACHE_LONGLONG, SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \
28  SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \
29  SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING, \
30  SHOW_SIGNED_LONG
31 #include <mysql/plugin.h>
32 #undef SHOW_always_last
33 
34 #include "m_string.h" /* LEX_STRING */
35 #include "my_alloc.h" /* MEM_ROOT */
36 #include "my_getopt.h" /* my_option */
37 
38 class sys_var;
39 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
40 enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE,
41  PLUGIN_FORCE_PLUS_PERMANENT };
42 extern const char *global_plugin_typelib_names[];
43 
44 #include <my_sys.h>
45 #include "sql_list.h"
46 
47 #ifdef DBUG_OFF
48 #define plugin_ref_to_int(A) A
49 #define plugin_int_to_ref(A) A
50 #else
51 #define plugin_ref_to_int(A) (A ? A[0] : NULL)
52 #define plugin_int_to_ref(A) &(A)
53 #endif
54 
55 /*
56  the following flags are valid for plugin_init()
57 */
58 #define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
59 #define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
60 #define PLUGIN_INIT_SKIP_INITIALIZATION 4
61 
62 #define INITIAL_LEX_PLUGIN_LIST_SIZE 16
63 
64 typedef enum enum_mysql_show_type SHOW_TYPE;
65 typedef struct st_mysql_show_var SHOW_VAR;
66 typedef struct st_mysql_lex_string LEX_STRING;
67 
68 #define MYSQL_ANY_PLUGIN -1
69 
70 /*
71  different values of st_plugin_int::state
72  though they look like a bitmap, plugin may only
73  be in one of those eigenstates, not in a superposition of them :)
74  It's a bitmap, because it makes it easier to test
75  "whether the state is one of those..."
76 */
77 #define PLUGIN_IS_FREED 1
78 #define PLUGIN_IS_DELETED 2
79 #define PLUGIN_IS_UNINITIALIZED 4
80 #define PLUGIN_IS_READY 8
81 #define PLUGIN_IS_DYING 16
82 #define PLUGIN_IS_DISABLED 32
83 
84 /* A handle for the dynamic library containing a plugin or plugins. */
85 
87 {
88  LEX_STRING dl;
89  void *handle;
90  struct st_mysql_plugin *plugins;
91  int version;
92  uint ref_count; /* number of plugins loaded from the library */
93 };
94 
95 /* A handle of a plugin */
96 
98 {
99  LEX_STRING name;
100  struct st_mysql_plugin *plugin;
101  struct st_plugin_dl *plugin_dl;
102  uint state;
103  uint ref_count; /* number of threads using the plugin */
104  void *data; /* plugin type specific, e.g. handlerton */
105  MEM_ROOT mem_root; /* memory for dynamic plugin structures */
106  sys_var *system_vars; /* server variables for this plugin */
107  enum enum_plugin_load_option load_option; /* OFF, ON, FORCE, F+PERMANENT */
108 };
109 
110 
111 /*
112  See intern_plugin_lock() for the explanation for the
113  conditionally defined plugin_ref type
114 */
115 #ifdef DBUG_OFF
116 typedef struct st_plugin_int *plugin_ref;
117 #define plugin_decl(pi) ((pi)->plugin)
118 #define plugin_dlib(pi) ((pi)->plugin_dl)
119 #define plugin_data(pi,cast) ((cast)((pi)->data))
120 #define plugin_name(pi) (&((pi)->name))
121 #define plugin_state(pi) ((pi)->state)
122 #define plugin_load_option(pi) ((pi)->load_option)
123 #define plugin_equals(p1,p2) ((p1) == (p2))
124 #else
125 typedef struct st_plugin_int **plugin_ref;
126 #define plugin_decl(pi) ((pi)[0]->plugin)
127 #define plugin_dlib(pi) ((pi)[0]->plugin_dl)
128 #define plugin_data(pi,cast) ((cast)((pi)[0]->data))
129 #define plugin_name(pi) (&((pi)[0]->name))
130 #define plugin_state(pi) ((pi)[0]->state)
131 #define plugin_load_option(pi) ((pi)[0]->load_option)
132 #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
133 #endif
134 
135 typedef int (*plugin_type_init)(struct st_plugin_int *);
136 
137 extern I_List<i_string> *opt_plugin_load_list_ptr;
138 extern char *opt_plugin_dir_ptr;
139 extern char opt_plugin_dir[FN_REFLEN];
140 extern const LEX_STRING plugin_type_names[];
141 
142 extern int plugin_init(int *argc, char **argv, int init_flags);
143 extern void plugin_shutdown(void);
144 extern void memcached_shutdown(void);
145 void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
146 extern bool plugin_is_ready(const LEX_STRING *name, int type);
147 #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C)
148 #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C)
149 #define my_plugin_lock(A,B) plugin_lock(A,B)
150 #define my_plugin_lock_ci(A,B) plugin_lock(A,B)
151 extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
152 extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
153  int type);
154 extern void plugin_unlock(THD *thd, plugin_ref plugin);
155 extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
156 extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
157  const LEX_STRING *dl);
158 extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
159 extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
160 extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
161 extern void plugin_thdvar_cleanup(THD *thd);
162 extern SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type);
163 extern bool check_valid_path(const char *path, size_t length);
164 
165 typedef my_bool (plugin_foreach_func)(THD *thd,
166  plugin_ref plugin,
167  void *arg);
168 #define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
169 extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
170  int type, uint state_mask, void *arg);
171 
172 /* interface to randomly access plugin data */
173 struct st_plugin_int *plugin_find_by_type(LEX_STRING *plugin, int type);
174 int lock_plugin_data();
175 int unlock_plugin_data();
176 #endif