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 |
|
873.2.22
by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs. |
22 |
#include <map> |
23 |
#include <string> |
|
24 |
||
25 |
using namespace std; |
|
26 |
||
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
27 |
static bool udf_startup= false; /* We do not lock because startup is single threaded */ |
1
by brian
clean slate |
28 |
static MEM_ROOT mem; |
873.2.22
by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs. |
29 |
static map<string, udf_func *> udf_map; |
1
by brian
clean slate |
30 |
|
481
by Brian Aker
Remove all of uchar. |
31 |
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. |
32 |
bool ) |
1
by brian
clean slate |
33 |
{
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
34 |
udf_func *udf= (udf_func*) buff; |
35 |
*length= (uint) udf->name.length; |
|
481
by Brian Aker
Remove all of uchar. |
36 |
return (unsigned char*) udf->name.str; |
1
by brian
clean slate |
37 |
}
|
38 |
||
39 |
||
40 |
void udf_init() |
|
41 |
{
|
|
42 |
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0); |
|
43 |
}
|
|
44 |
||
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
45 |
/* called by mysqld.cc clean_up() */
|
1
by brian
clean slate |
46 |
void udf_free() |
47 |
{
|
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
48 |
free_root(&mem, MYF(0)); |
49 |
}
|
|
1
by brian
clean slate |
50 |
|
51 |
/* This is only called if using_udf_functions != 0 */
|
|
482
by Brian Aker
Remove uint. |
52 |
udf_func *find_udf(const char *name, uint32_t length) |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
53 |
{
|
873.2.22
by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs. |
54 |
udf_func *udf= NULL; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
55 |
|
56 |
if (udf_startup == false) |
|
57 |
return NULL; |
|
58 |
||
873.2.22
by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs. |
59 |
string find_str(name, length); |
60 |
transform(find_str.begin(), find_str.end(), |
|
61 |
find_str.begin(), ::tolower); |
|
62 |
||
63 |
map<string, udf_func *>::iterator find_iter; |
|
64 |
find_iter= udf_map.find(find_str); |
|
65 |
if (find_iter != udf_map.end()) |
|
66 |
udf= (*find_iter).second; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
67 |
|
68 |
return (udf); |
|
69 |
}
|
|
70 |
||
71 |
static bool add_udf(udf_func *udf) |
|
72 |
{
|
|
873.2.22
by Monty Taylor
Got rid of my_hash_sort_utf8mb4 for udfs. |
73 |
string add_str(udf->name.str, udf->name.length); |
74 |
transform(add_str.begin(), add_str.end(), |
|
75 |
add_str.begin(), ::tolower); |
|
76 |
||
77 |
udf_map[add_str]= udf; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
78 |
|
79 |
using_udf_functions= 1; |
|
80 |
||
81 |
return true; |
|
82 |
}
|
|
83 |
||
84 |
int initialize_udf(st_plugin_int *plugin) |
|
85 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
86 |
udf_func *f; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
87 |
|
88 |
if (udf_startup == false) |
|
89 |
{
|
|
90 |
udf_init(); |
|
91 |
udf_startup= true; |
|
92 |
}
|
|
93 |
||
94 |
if (plugin->plugin->init) |
|
95 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
96 |
int r; |
97 |
if ((r= plugin->plugin->init((void *)&f))) |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
98 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
99 |
errmsg_printf(ERRMSG_LVL_ERROR, "Plugin '%s' init function returned error %d.", |
100 |
plugin->name.str, r); |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
101 |
return r; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
102 |
}
|
103 |
}
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
104 |
else
|
105 |
return 1; |
|
106 |
||
810
by Brian Aker
Fix for making sure I_S has good information about which plugins are |
107 |
if (!add_udf(f)) |
108 |
return 1; |
|
109 |
||
110 |
plugin->state= PLUGIN_IS_READY; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
111 |
|
112 |
return 0; |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
113 |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
114 |
}
|
115 |
||
116 |
int finalize_udf(st_plugin_int *plugin) |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
117 |
{
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
118 |
udf_func *udff = (udf_func *)plugin->data; |
119 |
||
120 |
/* TODO: Issue warning on failure */
|
|
121 |
if (udff && plugin->plugin->deinit) |
|
122 |
(void)plugin->plugin->deinit(udff); |
|
123 |
||
124 |
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. |
125 |
free(udff); |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
126 |
|
127 |
return 0; |
|
128 |
}
|
|
129 |