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 license; /* the plugin license (PLUGIN_LICENSE_XXX) */
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;
void * __reserved1; /* placeholder for system variables */
void * __reserved2; /* placeholder for config options */
};
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 21.2.3.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.
The plugin license type. The value can be one of
PLUGIN_LICENSE_PROPRIETARY,
PLUGIN_LICENSE_GPL, or
PLUGIN_LICENSE_BSD.
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 nonzero 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 nonzero 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. The value includes major and minor numbers. If you
write the value as a hex constant, the format is
0x,
where MMNNMM and
NN are the major and minor numbers,
respectively. For example, 0x0302
represents version 3.2.
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.
__reserved1,
__reserved2
These are placeholders for the future. Currently, they
should be set to NULL.
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.
| Type | Meaning |
SHOW_BOOL |
Pointer to a boolean variable |
SHOW_INT |
Pointer to an integer variable |
SHOW_LONG |
Pointer to a long integer variable |
SHOW_LONGLONG |
Pointer to a longlong integer variable |
SHOW_CHAR |
A string |
SHOW_CHAR_PTR |
Pointer to a string |
SHOW_ARRAY |
Pointer to another st_mysql_show_var array |
SHOW_FUNC |
Pointer to a function |
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 signature:
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
typedef int (*mysql_show_var_func) (void *thd,
struct st_mysql_show_var *out,
char *buf);
Plugins should consider the thd parameter
to be read only.

User Comments
Add your own comment.