diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/Makefile.am | 28 | ||||
-rw-r--r-- | plugin/daemon_example/AUTHORS | 1 | ||||
-rw-r--r-- | plugin/daemon_example/ChangeLog | 2 | ||||
-rw-r--r-- | plugin/daemon_example/Makefile.am | 41 | ||||
-rw-r--r-- | plugin/daemon_example/NEWS | 2 | ||||
-rw-r--r-- | plugin/daemon_example/README | 8 | ||||
-rw-r--r-- | plugin/daemon_example/configure.in | 9 | ||||
-rw-r--r-- | plugin/daemon_example/daemon_example.cc | 202 | ||||
-rw-r--r-- | plugin/daemon_example/plug.in | 3 | ||||
-rw-r--r-- | plugin/fulltext/AUTHORS | 1 | ||||
-rw-r--r-- | plugin/fulltext/ChangeLog | 1 | ||||
-rw-r--r-- | plugin/fulltext/Makefile.am | 27 | ||||
-rw-r--r-- | plugin/fulltext/NEWS | 1 | ||||
-rw-r--r-- | plugin/fulltext/README | 1 | ||||
-rw-r--r-- | plugin/fulltext/configure.in | 9 | ||||
-rw-r--r-- | plugin/fulltext/plug.in | 3 | ||||
-rw-r--r-- | plugin/fulltext/plugin_example.c | 273 |
17 files changed, 612 insertions, 0 deletions
diff --git a/plugin/Makefile.am b/plugin/Makefile.am new file mode 100644 index 00000000000..22f6bfd88b2 --- /dev/null +++ b/plugin/Makefile.am @@ -0,0 +1,28 @@ +# Copyright (C) 2005-2006 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# 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 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 + +# Process this file with automake to create Makefile.in + +AUTOMAKE_OPTIONS = foreign + +# extra plugin example files are listed here, to +# keep its Makefile.am cleaner as a template +EXTRA_DIST = fulltext/configure.in + +SUBDIRS = @mysql_pg_dirs@ +DIST_SUBDIRS = daemon_example fulltext + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/plugin/daemon_example/AUTHORS b/plugin/daemon_example/AUTHORS new file mode 100644 index 00000000000..fe992df1360 --- /dev/null +++ b/plugin/daemon_example/AUTHORS @@ -0,0 +1 @@ +Brian Aker <brian@mysql.com> diff --git a/plugin/daemon_example/ChangeLog b/plugin/daemon_example/ChangeLog new file mode 100644 index 00000000000..c4b09806f83 --- /dev/null +++ b/plugin/daemon_example/ChangeLog @@ -0,0 +1,2 @@ +0.1 + - Added diff --git a/plugin/daemon_example/Makefile.am b/plugin/daemon_example/Makefile.am new file mode 100644 index 00000000000..92b1ab040fb --- /dev/null +++ b/plugin/daemon_example/Makefile.am @@ -0,0 +1,41 @@ +# Copyright (C) 2006 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# 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 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 + +#Makefile.am example for a daemon +MYSQLDATAdir = $(localstatedir) +MYSQLSHAREdir = $(pkgdatadir) +MYSQLBASEdir= $(prefix) +MYSQLLIBdir= $(pkglibdir) +INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include \ + -I$(top_srcdir)/regex \ + -I$(top_srcdir)/sql \ + -I$(srcdir) @ZLIB_INCLUDES@ + +EXTRA_LTLIBRARIES = libdaemon_example.la +pkglib_LTLIBRARIES = @plugin_daemon_example_shared_target@ +libdaemon_example_la_LDFLAGS = -module -rpath $(MYSQLLIBdir) +libdaemon_example_la_CXXFLAGS= $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN +libdaemon_example_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN +libdaemon_example_la_SOURCES = daemon_example.cc + + +EXTRA_LIBRARIES = libdaemon_example.a +noinst_LIBRARIES = @plugin_daemon_example_static_target@ +libdaemon_example_a_CXXFLAGS = $(AM_CFLAGS) +libdaemon_example_a_CFLAGS = $(AM_CFLAGS) +libdaemon_example_a_SOURCES= daemon_example.cc + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/plugin/daemon_example/NEWS b/plugin/daemon_example/NEWS new file mode 100644 index 00000000000..ddae9fc3297 --- /dev/null +++ b/plugin/daemon_example/NEWS @@ -0,0 +1,2 @@ +0.1 - Tue Nov 7 12:08:03 PST 2006 + * Added Example to test interface diff --git a/plugin/daemon_example/README b/plugin/daemon_example/README new file mode 100644 index 00000000000..d3c67be6f52 --- /dev/null +++ b/plugin/daemon_example/README @@ -0,0 +1,8 @@ +Hi! + +This is an example of a daemon plugin. These are generic plugins that +only hook ino the startup and shutdown of the database. + +Cheers, + -Brian + Seattle, WA diff --git a/plugin/daemon_example/configure.in b/plugin/daemon_example/configure.in new file mode 100644 index 00000000000..8924b7f5bc4 --- /dev/null +++ b/plugin/daemon_example/configure.in @@ -0,0 +1,9 @@ +# configure.in example for a daemon + +AC_INIT(daemon_example, 0.1) +AM_INIT_AUTOMAKE +AC_DISABLE_STATIC +AC_PROG_LIBTOOL +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT + diff --git a/plugin/daemon_example/daemon_example.cc b/plugin/daemon_example/daemon_example.cc new file mode 100644 index 00000000000..af585bb4302 --- /dev/null +++ b/plugin/daemon_example/daemon_example.cc @@ -0,0 +1,202 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +#include <mysql_priv.h> +#include <stdlib.h> +#include <ctype.h> +#include <mysql_version.h> +#include <mysql/plugin.h> +#include <my_global.h> +#include <my_dir.h> + +/* + Disable __attribute__() on non-gcc compilers. +*/ +#if !defined(__attribute__) && !defined(__GNUC__) +#define __attribute__(A) +#endif + + +#define HEART_STRING_BUFFER 100 + +struct mysql_heartbeat_context +{ + pthread_t heartbeat_thread; + File heartbeat_file; +}; + +pthread_handler_t mysql_heartbeat(void *p) +{ + DBUG_ENTER("mysql_heartbeat"); + struct mysql_heartbeat_context *con= (struct mysql_heartbeat_context *)p; + char buffer[HEART_STRING_BUFFER]; + unsigned int x= 0; + time_t result; + struct tm tm_tmp; + + while(1) + { + sleep(5); + + result= time(NULL); + localtime_r(&result, &tm_tmp); + my_snprintf(buffer, sizeof(buffer), + "Heartbeat at %02d%02d%02d %2d:%02d:%02d\n", + tm_tmp.tm_year % 100, + tm_tmp.tm_mon+1, + tm_tmp.tm_mday, + tm_tmp.tm_hour, + tm_tmp.tm_min, + tm_tmp.tm_sec); + my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0)); + x++; + } + + DBUG_RETURN(0); +} + +/* + Initialize the daemon example at server start or plugin installation. + + SYNOPSIS + daemon_example_plugin_init() + + DESCRIPTION + Starts up heartbeatbeat thread + + RETURN VALUE + 0 success + 1 failure (cannot happen) +*/ + +static int daemon_example_plugin_init(void *p) +{ + + DBUG_ENTER("daemon_example_plugin_init"); + struct mysql_heartbeat_context *con; + pthread_attr_t attr; /* Thread attributes */ + char heartbeat_filename[FN_REFLEN]; + char buffer[HEART_STRING_BUFFER]; + time_t result= time(NULL); + struct tm tm_tmp; + + struct st_plugin_int *plugin= (struct st_plugin_int *)p; + + con= (struct mysql_heartbeat_context *) + my_malloc(sizeof(struct mysql_heartbeat_context), MYF(0)); + + fn_format(heartbeat_filename, "mysql-heartbeat", "", ".log", + MY_REPLACE_EXT | MY_UNPACK_FILENAME); + unlink(heartbeat_filename); + con->heartbeat_file= my_open(heartbeat_filename, O_CREAT|O_RDWR, MYF(0)); + + /* + No threads exist at this point in time, so this is thread safe. + */ + localtime_r(&result, &tm_tmp); + my_snprintf(buffer, sizeof(buffer), + "Starting up at %02d%02d%02d %2d:%02d:%02d\n", + tm_tmp.tm_year % 100, + tm_tmp.tm_mon+1, + tm_tmp.tm_mday, + tm_tmp.tm_hour, + tm_tmp.tm_min, + tm_tmp.tm_sec); + my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0)); + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, + PTHREAD_CREATE_JOINABLE); + + + /* now create the thread */ + if (pthread_create(&con->heartbeat_thread, &attr, mysql_heartbeat, + (void *)con) != 0) + { + fprintf(stderr,"Could not create heartbeat thread!\n"); + exit(0); + } + plugin->data= (void *)con; + + DBUG_RETURN(0); +} + + +/* + Terminate the daemon example at server shutdown or plugin deinstallation. + + SYNOPSIS + daemon_example_plugin_deinit() + Does nothing. + + RETURN VALUE + 0 success + 1 failure (cannot happen) + +*/ + +static int daemon_example_plugin_deinit(void *p) +{ + DBUG_ENTER("daemon_example_plugin_deinit"); + char buffer[HEART_STRING_BUFFER]; + struct st_plugin_int *plugin= (struct st_plugin_int *)p; + struct mysql_heartbeat_context *con= + (struct mysql_heartbeat_context *)plugin->data; + time_t result= time(NULL); + struct tm tm_tmp; + + pthread_cancel(con->heartbeat_thread); + + localtime_r(&result, &tm_tmp); + my_snprintf(buffer, sizeof(buffer), + "Shutting down at %02d%02d%02d %2d:%02d:%02d\n", + tm_tmp.tm_year % 100, + tm_tmp.tm_mon+1, + tm_tmp.tm_mday, + tm_tmp.tm_hour, + tm_tmp.tm_min, + tm_tmp.tm_sec); + my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0)); + my_close(con->heartbeat_file, MYF(0)); + + my_free((char *)con, MYF(0)); + + DBUG_RETURN(0); +} + + +struct st_mysql_daemon daemon_example_plugin= +{ MYSQL_DAEMON_INTERFACE_VERSION }; + +/* + Plugin library descriptor +*/ + +mysql_declare_plugin(daemon_example) +{ + MYSQL_DAEMON_PLUGIN, + &daemon_example_plugin, + "daemon_example", + "Brian Aker", + "Daemon example, creates a heartbeat beat file in mysql-heartbeat.log", + PLUGIN_LICENSE_GPL, + daemon_example_plugin_init, /* Plugin Init */ + daemon_example_plugin_deinit, /* Plugin Deinit */ + 0x0100 /* 1.0 */, + NULL, /* status variables */ + NULL, /* system variables */ + NULL /* config options */ +} +mysql_declare_plugin_end; diff --git a/plugin/daemon_example/plug.in b/plugin/daemon_example/plug.in new file mode 100644 index 00000000000..72e87a70f59 --- /dev/null +++ b/plugin/daemon_example/plug.in @@ -0,0 +1,3 @@ +MYSQL_PLUGIN(daemon_example,[Daemon Example Plugin], + [This is an example plugin daemon.]) +MYSQL_PLUGIN_DYNAMIC(daemon_example, [libdaemon_example.la]) diff --git a/plugin/fulltext/AUTHORS b/plugin/fulltext/AUTHORS new file mode 100644 index 00000000000..9c4567884af --- /dev/null +++ b/plugin/fulltext/AUTHORS @@ -0,0 +1 @@ +AUTHORS file example for a plugin diff --git a/plugin/fulltext/ChangeLog b/plugin/fulltext/ChangeLog new file mode 100644 index 00000000000..1faaaad618a --- /dev/null +++ b/plugin/fulltext/ChangeLog @@ -0,0 +1 @@ +ChangeLog file example for a plugin diff --git a/plugin/fulltext/Makefile.am b/plugin/fulltext/Makefile.am new file mode 100644 index 00000000000..ec033018a00 --- /dev/null +++ b/plugin/fulltext/Makefile.am @@ -0,0 +1,27 @@ +# Copyright (C) 2005-2006 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# 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 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 + +#Makefile.am example for a plugin + +pkglibdir=$(libdir)/mysql +INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include +#noinst_LTLIBRARIES= mypluglib.la +pkglib_LTLIBRARIES= mypluglib.la +mypluglib_la_SOURCES= plugin_example.c +mypluglib_la_LDFLAGS= -module -rpath $(pkglibdir) +mypluglib_la_CFLAGS= -DMYSQL_DYNAMIC_PLUGIN + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/plugin/fulltext/NEWS b/plugin/fulltext/NEWS new file mode 100644 index 00000000000..e5b6cbd50a2 --- /dev/null +++ b/plugin/fulltext/NEWS @@ -0,0 +1 @@ +NEWS file example for a plugin diff --git a/plugin/fulltext/README b/plugin/fulltext/README new file mode 100644 index 00000000000..e4d01f2afb7 --- /dev/null +++ b/plugin/fulltext/README @@ -0,0 +1 @@ +README file example for a plugin diff --git a/plugin/fulltext/configure.in b/plugin/fulltext/configure.in new file mode 100644 index 00000000000..2fefa68727c --- /dev/null +++ b/plugin/fulltext/configure.in @@ -0,0 +1,9 @@ +# configure.in example for a plugin + +AC_INIT(plugin_example, 0.1) +AM_INIT_AUTOMAKE +AC_DISABLE_STATIC +AC_PROG_LIBTOOL +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT + diff --git a/plugin/fulltext/plug.in b/plugin/fulltext/plug.in new file mode 100644 index 00000000000..5bfc401f805 --- /dev/null +++ b/plugin/fulltext/plug.in @@ -0,0 +1,3 @@ +MYSQL_PLUGIN(ftexample, [Simple Parser], + [Simple full-text parser plugin]) +MYSQL_PLUGIN_DYNAMIC(ftexample, [mypluglib.la]) diff --git a/plugin/fulltext/plugin_example.c b/plugin/fulltext/plugin_example.c new file mode 100644 index 00000000000..70022da2cc4 --- /dev/null +++ b/plugin/fulltext/plugin_example.c @@ -0,0 +1,273 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +#include <stdlib.h> +#include <ctype.h> +#include <mysql/plugin.h> + +#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8) +#define __attribute__(A) +#endif + +static long number_of_calls= 0; /* for SHOW STATUS, see below */ + +/* + Simple full-text parser plugin that acts as a replacement for the + built-in full-text parser: + - All non-whitespace characters are significant and are interpreted as + "word characters." + - Whitespace characters are space, tab, CR, LF. + - There is no minimum word length. Non-whitespace sequences of one + character or longer are words. + - Stopwords are used in non-boolean mode, not used in boolean mode. +*/ + +/* + simple_parser interface functions: + + Plugin declaration functions: + - simple_parser_plugin_init() + - simple_parser_plugin_deinit() + + Parser descriptor functions: + - simple_parser_parse() + - simple_parser_init() + - simple_parser_deinit() +*/ + + +/* + Initialize the parser plugin at server start or plugin installation. + + SYNOPSIS + simple_parser_plugin_init() + + DESCRIPTION + Does nothing. + + RETURN VALUE + 0 success + 1 failure (cannot happen) +*/ + +static int simple_parser_plugin_init(void *arg __attribute__((unused))) +{ + return(0); +} + + +/* + Terminate the parser plugin at server shutdown or plugin deinstallation. + + SYNOPSIS + simple_parser_plugin_deinit() + Does nothing. + + RETURN VALUE + 0 success + 1 failure (cannot happen) + +*/ + +static int simple_parser_plugin_deinit(void *arg __attribute__((unused))) +{ + return(0); +} + + +/* + Initialize the parser on the first use in the query + + SYNOPSIS + simple_parser_init() + + DESCRIPTION + Does nothing. + + RETURN VALUE + 0 success + 1 failure (cannot happen) +*/ + +static int simple_parser_init(MYSQL_FTPARSER_PARAM *param + __attribute__((unused))) +{ + return(0); +} + + +/* + Terminate the parser at the end of the query + + SYNOPSIS + simple_parser_deinit() + + DESCRIPTION + Does nothing. + + RETURN VALUE + 0 success + 1 failure (cannot happen) +*/ + +static int simple_parser_deinit(MYSQL_FTPARSER_PARAM *param + __attribute__((unused))) +{ + return(0); +} + + +/* + Pass a word back to the server. + + SYNOPSIS + add_word() + param parsing context of the plugin + word a word + len word length + + DESCRIPTION + Fill in boolean metadata for the word (if parsing in boolean mode) + and pass the word to the server. The server adds the word to + a full-text index when parsing for indexing, or adds the word to + the list of search terms when parsing a search string. +*/ + +static void add_word(MYSQL_FTPARSER_PARAM *param, char *word, size_t len) +{ + MYSQL_FTPARSER_BOOLEAN_INFO bool_info= + { FT_TOKEN_WORD, 0, 0, 0, 0, ' ', 0 }; + + param->mysql_add_word(param, word, len, &bool_info); +} + +/* + Parse a document or a search query. + + SYNOPSIS + simple_parser_parse() + param parsing context + + DESCRIPTION + This is the main plugin function which is called to parse + a document or a search query. The call mode is set in + param->mode. This function simply splits the text into words + and passes every word to the MySQL full-text indexing engine. +*/ + +static int simple_parser_parse(MYSQL_FTPARSER_PARAM *param) +{ + char *end, *start, *docend= param->doc + param->length; + + number_of_calls++; + + for (end= start= param->doc;; end++) + { + if (end == docend) + { + if (end > start) + add_word(param, start, end - start); + break; + } + else if (isspace(*end)) + { + if (end > start) + add_word(param, start, end - start); + start= end + 1; + } + } + return(0); +} + + +/* + Plugin type-specific descriptor +*/ + +static struct st_mysql_ftparser simple_parser_descriptor= +{ + MYSQL_FTPARSER_INTERFACE_VERSION, /* interface version */ + simple_parser_parse, /* parsing function */ + simple_parser_init, /* parser init function */ + simple_parser_deinit /* parser deinit function */ +}; + +/* + Plugin status variables for SHOW STATUS +*/ + +static struct st_mysql_show_var simple_status[]= +{ + {"static", (char *)"just a static text", SHOW_CHAR}, + {"called", (char *)&number_of_calls, SHOW_LONG}, + {0,0,0} +}; + +/* + Plugin system variables. +*/ + +static long sysvar_one_value; +static char *sysvar_two_value; + +static MYSQL_SYSVAR_LONG(simple_sysvar_one, sysvar_one_value, + PLUGIN_VAR_RQCMDARG, + "Simple fulltext parser example system variable number one. Give a number.", + NULL, NULL, 77L, 7L, 777L, 0); + +static MYSQL_SYSVAR_STR(simple_sysvar_two, sysvar_two_value, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC, + "Simple fulltext parser example system variable number two. Give a string.", + NULL, NULL, "simple sysvar two default"); + +static MYSQL_THDVAR_LONG(simple_thdvar_one, + PLUGIN_VAR_RQCMDARG, + "Simple fulltext parser example thread variable number one. Give a number.", + NULL, NULL, 88L, 8L, 888L, 0); + +static MYSQL_THDVAR_STR(simple_thdvar_two, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC, + "Simple fulltext parser example thread variable number two. Give a string.", + NULL, NULL, "simple thdvar two default"); + +static struct st_mysql_sys_var* simple_system_variables[]= { + MYSQL_SYSVAR(simple_sysvar_one), + MYSQL_SYSVAR(simple_sysvar_two), + MYSQL_SYSVAR(simple_thdvar_one), + MYSQL_SYSVAR(simple_thdvar_two), + NULL +}; + +/* + Plugin library descriptor +*/ + +mysql_declare_plugin(ftexample) +{ + MYSQL_FTPARSER_PLUGIN, /* type */ + &simple_parser_descriptor, /* descriptor */ + "simple_parser", /* name */ + "MySQL AB", /* author */ + "Simple Full-Text Parser", /* description */ + PLUGIN_LICENSE_GPL, + simple_parser_plugin_init, /* init function (when loaded) */ + simple_parser_plugin_deinit,/* deinit function (when unloaded) */ + 0x0001, /* version */ + simple_status, /* status variables */ + simple_system_variables, /* system variables */ + NULL +} +mysql_declare_plugin_end; + |