27.2.5.1. General Plugin Structures and Functions
Every plugin must have a general plugin declaration. The
declaration corresponds to the
st_mysql_plugin
structure in the
plugin.h
file:
struct st_mysql_plugin
{
int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */
void *info; /* pointer to type-specific plugin descriptor */
const char *name; /* plugin name */
const char *author; /* plugin author (for SHOW PLUGINS) */
const char *descr; /* general descriptive text (for SHOW PLUGINS ) */
int (*init)(void); /* the function to invoke when plugin is loaded */
int (*deinit)(void); /* the function to invoke when plugin is unloaded */
unsigned int version; /* plugin version (for SHOW PLUGINS) */
struct st_mysql_show_var *status_vars;
};
The st_mysql_plugin
structure is common to
every type of plugin. Its members should be filled in as
follows:
-
type
The plugin type. This must be one of the plugin-type
values from plugin.h
. For a full-text
parser plugin, the type
value is
MYSQL_FTPARSER_PLUGIN
.
-
info
A pointer to the descriptor for the plugin. Unlike the
general plugin declaration structure, this descriptor's
structure depends on the particular type of plugin. Each
descriptor has a version number that indicates the API
version for that type of plugin, plus any other members
needed. The descriptor for full-text plugins is described
in Section 27.2.5.2, “Type-Specific Plugin Structures and Functions”.
-
name
The plugin name. This is the name that will be listed in
the plugin
table and by which you refer
to the plugin in SQL statements such as INSTALL
PLUGIN
and UNINSTALL PLUGIN
.
-
author
The plugin author. This can be whatever you like.
-
desc
A general description of the plugin. This can be whatever
you like.
-
init
A once-only initialization function. This is executed when
the plugin is loaded, which happens for INSTALL
PLUGIN
or, for plugins listed in the
plugin
table, at server startup. The
function takes no arguments. It returns zero for success
and non-zero for failure. If an init
function is unneeded for a plugin, it can be specified as
0.
-
deinit
A once-only deinitialization function. This is executed
when the plugin is unloaded, which happens for
UNINSTALL PLUGIN
or, for plugins listed
in the plugin
table, at server
shutdown. The function takes no arguments. It returns zero
for success and non-zero for failure. If a
deinit
function is unneeded for a
plugin, it can be specified as 0.
-
version
The plugin version number. When the plugin is installed,
this value can be retrieved from the
INFORMATION_SCHEMA.PLUGINS
table.
-
status_vars
A pointer to a structure for status variables associated
with the plugin, or 0 if there are no such variables. When
the plugin is installed, these variables are displayed in
the output of the SHOW STATUS
statement.
The init
and deinit
functions in the general plugin declaration are invoked only
when loading and unloading the plugin. They have nothing to do
with use of the plugin such as happens when an SQL statement
causes the plugin to be invoked.
The status_vars
member, if not 0, points to
an array of st_mysql_show_var
structures,
each of which describes one status variable, followed by a
structure with all members set to 0. The
st_mysql_show_var
structure has this
definition:
struct st_mysql_show_var {
const char *name;
char *value;
enum enum_mysql_show_type type;
};
When the plugin is installed, the plugin name and the
name
value are joined with an underscore to
form the name displayed by SHOW STATUS
.
The following table shows the allowable status variable
type
values and what the corresponding
variable should be:
For the SHOW_FUNC
type, the function is
called and fills in its out
parameter,
which then provides information about the variable to be
displayed. The function has this calling sequence:
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
typedef int (*mysql_show_var_func) (void *thd,
struct st_mysql_show_var *out,
char *buf);