MySQL  8.0.16
Source Code Documentation
sql_plugin.h
Go to the documentation of this file.
1 /* Copyright (c) 2005, 2018, 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, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef _sql_plugin_h
24 #define _sql_plugin_h
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <vector>
29 
30 #include "lex_string.h"
31 #include "my_io.h"
32 #include "my_sqlcommand.h" // enum_sql_command
34 #include "sql/sql_cmd.h" // Sql_cmd
35 #include "sql/sql_plugin_ref.h" // plugin_ref
36 
37 class THD;
38 class i_string;
39 struct MEM_ROOT;
40 struct SYS_VAR;
41 struct my_option;
42 template <class T>
43 class I_List;
44 
45 extern const char *global_plugin_typelib_names[];
48 
49 #ifdef DBUG_OFF
50 #define plugin_ref_to_int(A) A
51 #define plugin_int_to_ref(A) A
52 #else
53 #define plugin_ref_to_int(A) (A ? A[0] : NULL)
54 #define plugin_int_to_ref(A) &(A)
55 #endif
56 
57 /*
58  the following flags are valid for plugin_init()
59 */
60 #define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
61 #define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
62 #define PLUGIN_INIT_SKIP_INITIALIZATION 4
63 
64 #define MYSQL_ANY_PLUGIN -1
65 
66 /*
67  different values of st_plugin_int::state
68  though they look like a bitmap, plugin may only
69  be in one of those eigenstates, not in a superposition of them :)
70  It's a bitmap, because it makes it easier to test
71  "whether the state is one of those..."
72 */
73 #define PLUGIN_IS_FREED 1
74 #define PLUGIN_IS_DELETED 2
75 #define PLUGIN_IS_UNINITIALIZED 4
76 #define PLUGIN_IS_READY 8
77 #define PLUGIN_IS_DYING 16
78 #define PLUGIN_IS_DISABLED 32
79 
80 /* A handle for the dynamic library containing a plugin or plugins. */
81 
82 struct st_plugin_dl {
84  void *handle;
86  int version;
87  uint ref_count; /* number of plugins loaded from the library */
88 };
89 
90 /**
91  This class implements the INSTALL PLUGIN statement.
92 */
93 
95  public:
97  : m_comment(comment), m_ident(ident) {}
98 
100  return SQLCOM_INSTALL_PLUGIN;
101  }
102 
103  /**
104  Install a new plugin by inserting a row into the
105  mysql.plugin table, creating a cache entry and
106  initializing plugin's internal data.
107 
108  @param thd Thread context
109 
110  @returns false if success, true otherwise
111  */
112  virtual bool execute(THD *thd);
113 
114  private:
117 };
118 
119 /**
120  This class implements the UNINSTALL PLUGIN statement.
121 */
122 
124  public:
126  : m_comment(comment) {}
127 
130  }
131 
132  /**
133  Uninstall a plugin by removing a row from the
134  mysql.plugin table, deleting a cache entry and
135  deinitializing plugin's internal data.
136 
137  @param thd Thread context
138 
139  @returns false if success, true otherwise
140  */
141  virtual bool execute(THD *thd);
142 
143  private:
145 };
146 
147 typedef int (*plugin_type_init)(struct st_plugin_int *);
148 
151 extern char *opt_plugin_dir_ptr;
152 extern char opt_plugin_dir[FN_REFLEN];
153 extern const LEX_STRING plugin_type_names[];
154 
155 extern bool plugin_register_early_plugins(int *argc, char **argv, int flags);
156 extern bool plugin_register_builtin_and_init_core_se(int *argc, char **argv);
157 extern bool plugin_register_dynamic_and_init_all(int *argc, char **argv,
158  int init_flags);
160 extern void plugin_shutdown(void);
161 extern void memcached_shutdown(void);
162 void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
163 extern bool plugin_is_ready(const LEX_CSTRING &name, int type);
164 #define my_plugin_lock_by_name(A, B, C) plugin_lock_by_name(A, B, C)
165 #define my_plugin_lock_by_name_ci(A, B, C) plugin_lock_by_name(A, B, C)
166 #define my_plugin_lock(A, B) plugin_lock(A, B)
167 #define my_plugin_lock_ci(A, B) plugin_lock(A, B)
168 extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
170  int type);
171 extern void plugin_unlock(THD *thd, plugin_ref plugin);
172 extern void plugin_unlock_list(THD *thd, plugin_ref *list, size_t count);
173 extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
174 extern void plugin_thdvar_cleanup(THD *thd, bool enable_plugins);
175 extern void plugin_thdvar_safe_update(THD *thd, SYS_VAR *var, char **dest,
176  const char *value);
177 extern bool check_valid_path(const char *path, size_t length);
178 extern void alloc_and_copy_thd_dynamic_variables(THD *thd, bool global_lock);
179 
180 typedef bool(plugin_foreach_func)(THD *thd, plugin_ref plugin, void *arg);
181 #define plugin_foreach(A, B, C, D) \
182  plugin_foreach_with_mask(A, B, C, PLUGIN_IS_READY, D)
183 extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
184  int type, uint state_mask, void *arg);
185 extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func **funcs,
186  int type, uint state_mask, void *arg);
187 int lock_plugin_data();
188 int unlock_plugin_data();
189 
190 bool end_transaction(THD *thd, bool error);
191 
192 /**
193  Initialize one plugin.
194 */
195 bool plugin_early_load_one(int *argc, char **argv, const char *plugin);
196 
197 #endif
uint ref_count
Definition: sql_plugin.h:87
Definition: sql_plugin_ref.h:44
Representation of an SQL command.
Definition: sql_cmd.h:62
void plugin_thdvar_safe_update(THD *thd, SYS_VAR *var, char **dest, const char *value)
Set value for a thread local variable.
Definition: sql_plugin.cc:2976
const LEX_STRING plugin_type_names[]
Definition: sql_plugin.cc:343
void alloc_and_copy_thd_dynamic_variables(THD *thd, bool global_lock)
Allocate memory and copy dynamic variables from global system variables to per-thread system variable...
Definition: sql_plugin.cc:2732
get_options & argc
Definition: do_ctype.cc:51
virtual bool execute(THD *thd)
Install a new plugin by inserting a row into the mysql.plugin table, creating a cache entry and initi...
Definition: sql_plugin.cc:3533
LEX_STRING m_ident
Definition: sql_plugin.h:116
Definition: mysql_lex_string.h:34
void plugin_thdvar_init(THD *thd, bool enable_plugins)
Definition: sql_plugin.cc:2836
ssize_t count
Definition: memcached.c:386
bool check_valid_path(const char *path, size_t length)
Check if the provided path is valid in the sense that it does cause a relative reference outside the ...
Definition: sql_plugin.cc:540
const string name("\ame\)
bool plugin_is_ready(const LEX_CSTRING &name, int type)
Definition: sql_plugin.cc:883
virtual bool execute(THD *thd)
Uninstall a plugin by removing a row from the mysql.plugin table, deleting a cache entry and deinitia...
Definition: sql_plugin.cc:3540
Definition: sql_plugin_var.h:183
bool() plugin_foreach_func(THD *thd, plugin_ref plugin, void *arg)
Definition: sql_plugin.h:180
#define bool
Definition: config_static.h:42
This class implements the INSTALL PLUGIN statement.
Definition: sql_plugin.h:94
Definition: plugin.h:635
enum_sql_command
Definition: my_sqlcommand.h:45
Definition: mysql_lex_string.h:39
const char * global_plugin_typelib_names[]
Definition: sql_plugin.cc:327
class udf_list * list
static struct st_mysql_daemon plugin
Definition: test_services_host_application_signal.cc:130
I_List< i_string > * opt_early_plugin_load_list_ptr
Definition: sql_plugin.cc:336
Representation of an SQL command.
mysql_mutex_t LOCK_plugin
Serializes access to the global plugin memory list.
Definition: sql_plugin.cc:445
bool is_builtin_and_core_se_initialized()
Definition: sql_plugin.cc:1582
void memcached_shutdown(void)
Definition: sql_plugin.cc:1844
void plugin_shutdown(void)
Definition: sql_plugin.cc:1871
int lock_plugin_data()
Locks the plugin strucutres so calls to plugin_find_inner can be issued.
Definition: sql_plugin.cc:3520
Definition: my_sqlcommand.h:161
char * opt_plugin_dir_ptr
Definition: sql_plugin.cc:337
void plugin_thdvar_cleanup(THD *thd, bool enable_plugins)
Definition: sql_plugin.cc:2911
bool plugin_register_builtin_and_init_core_se(int *argc, char **argv)
Register the builtin plugins.
Definition: sql_plugin.cc:1471
This class implements the UNINSTALL PLUGIN statement.
Definition: sql_plugin.h:123
char * argv[]
Definition: example1.cc:2
char opt_plugin_dir[FN_REFLEN]
Definition: sql_plugin.cc:338
struct st_mysql_plugin * plugins
Definition: sql_plugin.h:85
static char * path
Definition: mysqldump.cc:122
Definition: sql_plugin.h:82
int unlock_plugin_data()
Unlocks the plugin strucutres as locked by lock_plugin_data()
Definition: sql_plugin.cc:3528
unsigned int uint
Definition: uca-dump.cc:29
#define FN_REFLEN
Definition: my_io.h:82
Definition: my_getopt.h:90
void plugin_unlock(THD *thd, plugin_ref plugin)
Definition: sql_plugin.cc:1196
int version
Definition: sql_plugin.h:86
bool plugin_register_early_plugins(int *argc, char **argv, int flags)
Register and initialize early plugins.
Definition: sql_plugin.cc:1435
plugin_ref plugin_lock_by_name(THD *thd, const LEX_CSTRING &name, int type)
Definition: sql_plugin.cc:938
Sql_cmd_uninstall_plugin(const LEX_STRING &comment)
Definition: sql_plugin.h:125
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
bool plugin_register_dynamic_and_init_all(int *argc, char **argv, int init_flags)
Register and initialize the dynamic plugins.
Definition: sql_plugin.cc:1596
LEX_STRING m_comment
Definition: sql_plugin.h:115
LEX_STRING dl
Definition: sql_plugin.h:83
LEX_STRING m_comment
Definition: sql_plugin.h:144
int type
Definition: http_common.h:411
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, int type, uint state_mask, void *arg)
Definition: sql_plugin.cc:2552
static const Query_options options
Definition: show_query_builder.cc:48
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
ABI for instrumented mutexes.
mysql_mutex_t LOCK_plugin_delete
Definition: sql_plugin.cc:434
Common #defines and includes for file and socket I/O.
Definition: protocol_classic.h:46
int(* plugin_type_init)(struct st_plugin_int *)
Definition: sql_plugin.h:147
void add_plugin_options(std::vector< my_option > *options, MEM_ROOT *mem_root)
Definition: sql_plugin.cc:3483
virtual enum_sql_command sql_command_code() const
Return the command code for this statement.
Definition: sql_plugin.h:99
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr)
Definition: sql_plugin.cc:928
bool plugin_early_load_one(int *argc, char **argv, const char *plugin)
Initialize one plugin.
Definition: sql_plugin.cc:2033
const string value("\alue\)
Sql_cmd_install_plugin(const LEX_STRING &comment, const LEX_STRING &ident)
Definition: sql_plugin.h:96
virtual enum_sql_command sql_command_code() const
Return the command code for this statement.
Definition: sql_plugin.h:128
I_List< i_string > * opt_plugin_load_list_ptr
Definition: sql_plugin.cc:334
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
static int flags[50]
Definition: hp_test1.cc:39
void * handle
Definition: sql_plugin.h:84
bool end_transaction(THD *thd, bool error)
Helper function to do rollback or commit, depending on error.
Definition: utils.cc:180
Definition: my_sqlcommand.h:162
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
void plugin_unlock_list(THD *thd, plugin_ref *list, size_t count)
Definition: sql_plugin.cc:1211
Definition: sql_list.h:671
#define comment
Definition: lexyy.cc:959
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
Log error(cerr, "ERROR")