1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
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 as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* This implements 'user defined functions' */
|
|
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
17 |
#include <drizzled/server_includes.h> |
538
by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib. |
18 |
#include <drizzled/gettext.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
19 |
#include <mysys/hash.h> |
20 |
#include <drizzled/sql_udf.h> |
|
1
by brian
clean slate |
21 |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
22 |
static bool udf_startup= false; /* We do not lock because startup is single threaded */ |
1
by brian
clean slate |
23 |
static MEM_ROOT mem; |
24 |
static HASH udf_hash; |
|
25 |
||
481
by Brian Aker
Remove all of uchar. |
26 |
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
27 |
bool ) |
1
by brian
clean slate |
28 |
{
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
29 |
udf_func *udf= (udf_func*) buff; |
30 |
*length= (uint) udf->name.length; |
|
481
by Brian Aker
Remove all of uchar. |
31 |
return (unsigned char*) udf->name.str; |
1
by brian
clean slate |
32 |
}
|
33 |
||
34 |
||
35 |
void udf_init() |
|
36 |
{
|
|
37 |
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0); |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
38 |
|
39 |
if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0)) |
|
1
by brian
clean slate |
40 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
41 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't allocate memory for udf structures")); |
1
by brian
clean slate |
42 |
hash_free(&udf_hash); |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
43 |
free_root(&mem, MYF(0)); |
51.2.2
by Patrick Galbraith
Removed DBUGs from |
44 |
return; |
1
by brian
clean slate |
45 |
}
|
46 |
}
|
|
47 |
||
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
48 |
/* called by mysqld.cc clean_up() */
|
1
by brian
clean slate |
49 |
void udf_free() |
50 |
{
|
|
51 |
hash_free(&udf_hash); |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
52 |
free_root(&mem, MYF(0)); |
53 |
}
|
|
1
by brian
clean slate |
54 |
|
55 |
/* This is only called if using_udf_functions != 0 */
|
|
482
by Brian Aker
Remove uint. |
56 |
udf_func *find_udf(const char *name, uint32_t length) |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
57 |
{
|
1
by brian
clean slate |
58 |
udf_func *udf; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
59 |
|
60 |
if (udf_startup == false) |
|
61 |
return NULL; |
|
62 |
||
63 |
udf= (udf_func*) hash_search(&udf_hash, |
|
481
by Brian Aker
Remove all of uchar. |
64 |
(unsigned char*) name, |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
65 |
length ? length : (uint) strlen(name)); |
66 |
||
67 |
return (udf); |
|
68 |
}
|
|
69 |
||
70 |
static bool add_udf(udf_func *udf) |
|
71 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
72 |
if (my_hash_insert(&udf_hash, (unsigned char*) udf)) |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
73 |
return false; |
74 |
||
75 |
using_udf_functions= 1; |
|
76 |
||
77 |
return true; |
|
78 |
}
|
|
79 |
||
80 |
int initialize_udf(st_plugin_int *plugin) |
|
81 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
82 |
udf_func *f; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
83 |
|
84 |
if (udf_startup == false) |
|
85 |
{
|
|
86 |
udf_init(); |
|
87 |
udf_startup= true; |
|
88 |
}
|
|
89 |
||
90 |
if (plugin->plugin->init) |
|
91 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
92 |
int r; |
93 |
if ((r= plugin->plugin->init((void *)&f))) |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
94 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
95 |
errmsg_printf(ERRMSG_LVL_ERROR, "Plugin '%s' init function returned error %d.", |
96 |
plugin->name.str, r); |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
97 |
return r; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
98 |
}
|
99 |
}
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
100 |
else
|
101 |
return 1; |
|
102 |
||
810
by Brian Aker
Fix for making sure I_S has good information about which plugins are |
103 |
if (!add_udf(f)) |
104 |
return 1; |
|
105 |
||
106 |
plugin->state= PLUGIN_IS_READY; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
107 |
|
108 |
return 0; |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
109 |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
110 |
}
|
111 |
||
112 |
int finalize_udf(st_plugin_int *plugin) |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
113 |
{
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
114 |
udf_func *udff = (udf_func *)plugin->data; |
115 |
||
116 |
/* TODO: Issue warning on failure */
|
|
117 |
if (udff && plugin->plugin->deinit) |
|
118 |
(void)plugin->plugin->deinit(udff); |
|
119 |
||
120 |
if (udff) |
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
121 |
free(udff); |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
122 |
|
123 |
return 0; |
|
124 |
}
|
|
125 |