aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libmysql_r/sql/sql_plugin.h
blob: a194edaabd869179ac1b1b8456385fc0a8f9748a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef _sql_plugin_h
#define _sql_plugin_h

#include <stddef.h>
#include <sys/types.h>
#include <vector>

#include "lex_string.h"
#include "my_io.h"
#include "my_sqlcommand.h"  // enum_sql_command
#include "mysql/components/services/mysql_mutex_bits.h"
#include "sql/sql_cmd.h"         // Sql_cmd
#include "sql/sql_plugin_ref.h"  // plugin_ref

class THD;
class i_string;
struct MEM_ROOT;
struct SYS_VAR;
struct my_option;
template <class T>
class I_List;

extern const char *global_plugin_typelib_names[];
extern mysql_mutex_t LOCK_plugin;
extern mysql_mutex_t LOCK_plugin_delete;

#ifdef DBUG_OFF
#define plugin_ref_to_int(A) A
#define plugin_int_to_ref(A) A
#else
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
#define plugin_int_to_ref(A) &(A)
#endif

/*
  the following flags are valid for plugin_init()
*/
#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
#define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
#define PLUGIN_INIT_SKIP_INITIALIZATION 4

#define MYSQL_ANY_PLUGIN -1

/*
  different values of st_plugin_int::state
  though they look like a bitmap, plugin may only
  be in one of those eigenstates, not in a superposition of them :)
  It's a bitmap, because it makes it easier to test
  "whether the state is one of those..."
*/
#define PLUGIN_IS_FREED 1
#define PLUGIN_IS_DELETED 2
#define PLUGIN_IS_UNINITIALIZED 4
#define PLUGIN_IS_READY 8
#define PLUGIN_IS_DYING 16
#define PLUGIN_IS_DISABLED 32

/* A handle for the dynamic library containing a plugin or plugins. */

struct st_plugin_dl {
  LEX_STRING dl;
  void *handle;
  struct st_mysql_plugin *plugins;
  int version;
  uint ref_count; /* number of plugins loaded from the library */
};

/**
   This class implements the INSTALL PLUGIN statement.
*/

class Sql_cmd_install_plugin : public Sql_cmd {
 public:
  Sql_cmd_install_plugin(const LEX_STRING &comment, const LEX_STRING &ident)
      : m_comment(comment), m_ident(ident) {}

  virtual enum_sql_command sql_command_code() const {
    return SQLCOM_INSTALL_PLUGIN;
  }

  /**
    Install a new plugin by inserting a row into the
    mysql.plugin table, creating a cache entry and
    initializing plugin's internal data.

    @param thd  Thread context

    @returns false if success, true otherwise
  */
  virtual bool execute(THD *thd);

 private:
  LEX_STRING m_comment;
  LEX_STRING m_ident;
};

/**
   This class implements the UNINSTALL PLUGIN statement.
*/

class Sql_cmd_uninstall_plugin : public Sql_cmd {
 public:
  explicit Sql_cmd_uninstall_plugin(const LEX_STRING &comment)
      : m_comment(comment) {}

  virtual enum_sql_command sql_command_code() const {
    return SQLCOM_UNINSTALL_PLUGIN;
  }

  /**
    Uninstall a plugin by removing a row from the
    mysql.plugin table, deleting a cache entry and
    deinitializing plugin's internal data.

    @param thd  Thread context

    @returns false if success, true otherwise
  */
  virtual bool execute(THD *thd);

 private:
  LEX_STRING m_comment;
};

typedef int (*plugin_type_init)(struct st_plugin_int *);

extern I_List<i_string> *opt_plugin_load_list_ptr;
extern I_List<i_string> *opt_early_plugin_load_list_ptr;
extern char *opt_plugin_dir_ptr;
extern char opt_plugin_dir[FN_REFLEN];
extern const LEX_STRING plugin_type_names[];

extern bool plugin_register_early_plugins(int *argc, char **argv, int flags);
extern bool plugin_register_builtin_and_init_core_se(int *argc, char **argv);
extern bool plugin_register_dynamic_and_init_all(int *argc, char **argv,
                                                 int init_flags);
extern bool is_builtin_and_core_se_initialized();
extern void plugin_shutdown(void);
extern void memcached_shutdown(void);
void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
extern bool plugin_is_ready(const LEX_CSTRING &name, int type);
#define my_plugin_lock_by_name(A, B, C) plugin_lock_by_name(A, B, C)
#define my_plugin_lock_by_name_ci(A, B, C) plugin_lock_by_name(A, B, C)
#define my_plugin_lock(A, B) plugin_lock(A, B)
#define my_plugin_lock_ci(A, B) plugin_lock(A, B)
extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_CSTRING &name,
                                      int type);
extern void plugin_unlock(THD *thd, plugin_ref plugin);
extern void plugin_unlock_list(THD *thd, plugin_ref *list, size_t count);
extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
extern void plugin_thdvar_cleanup(THD *thd, bool enable_plugins);
extern void plugin_thdvar_safe_update(THD *thd, SYS_VAR *var, char **dest,
                                      const char *value);
extern bool check_valid_path(const char *path, size_t length);
extern void alloc_and_copy_thd_dynamic_variables(THD *thd, bool global_lock);

typedef bool(plugin_foreach_func)(THD *thd, plugin_ref plugin, void *arg);
#define plugin_foreach(A, B, C, D) \
  plugin_foreach_with_mask(A, B, C, PLUGIN_IS_READY, D)
extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
                                     int type, uint state_mask, void *arg);
extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func **funcs,
                                     int type, uint state_mask, void *arg);
int lock_plugin_data();
int unlock_plugin_data();

bool end_transaction(THD *thd, bool error);

/**
  Initialize one plugin.
*/
bool plugin_early_load_one(int *argc, char **argv, const char *plugin);

#endif