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> |
338
by Monty Taylor
Tagged more strings. |
18 |
#include <libdrizzle/gettext.h> |
1
by brian
clean slate |
19 |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
20 |
static bool udf_startup= false; /* We do not lock because startup is single threaded */ |
1
by brian
clean slate |
21 |
static MEM_ROOT mem; |
22 |
static HASH udf_hash; |
|
23 |
||
481
by Brian Aker
Remove all of uchar. |
24 |
extern "C" unsigned char* get_hash_key(const unsigned char *buff, size_t *length, |
146
by Brian Aker
my_bool cleanup. |
25 |
bool not_used __attribute__((unused))) |
1
by brian
clean slate |
26 |
{
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
27 |
udf_func *udf= (udf_func*) buff; |
28 |
*length= (uint) udf->name.length; |
|
481
by Brian Aker
Remove all of uchar. |
29 |
return (unsigned char*) udf->name.str; |
1
by brian
clean slate |
30 |
}
|
31 |
||
32 |
||
33 |
void udf_init() |
|
34 |
{
|
|
35 |
init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0); |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
36 |
|
37 |
if (hash_init(&udf_hash, system_charset_info, 32, 0, 0, get_hash_key, NULL, 0)) |
|
1
by brian
clean slate |
38 |
{
|
338
by Monty Taylor
Tagged more strings. |
39 |
sql_print_error(_("Can't allocate memory for udf structures")); |
1
by brian
clean slate |
40 |
hash_free(&udf_hash); |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
41 |
free_root(&mem, MYF(0)); |
51.2.2
by Patrick Galbraith
Removed DBUGs from |
42 |
return; |
1
by brian
clean slate |
43 |
}
|
44 |
}
|
|
45 |
||
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
46 |
/* called by mysqld.cc clean_up() */
|
1
by brian
clean slate |
47 |
void udf_free() |
48 |
{
|
|
49 |
hash_free(&udf_hash); |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
50 |
free_root(&mem, MYF(0)); |
51 |
}
|
|
1
by brian
clean slate |
52 |
|
53 |
/* This is only called if using_udf_functions != 0 */
|
|
482
by Brian Aker
Remove uint. |
54 |
udf_func *find_udf(const char *name, uint32_t length) |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
55 |
{
|
1
by brian
clean slate |
56 |
udf_func *udf; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
57 |
|
58 |
if (udf_startup == false) |
|
59 |
return NULL; |
|
60 |
||
61 |
udf= (udf_func*) hash_search(&udf_hash, |
|
481
by Brian Aker
Remove all of uchar. |
62 |
(unsigned char*) name, |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
63 |
length ? length : (uint) strlen(name)); |
64 |
||
65 |
return (udf); |
|
66 |
}
|
|
67 |
||
68 |
static bool add_udf(udf_func *udf) |
|
69 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
70 |
if (my_hash_insert(&udf_hash, (unsigned char*) udf)) |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
71 |
return false; |
72 |
||
73 |
using_udf_functions= 1; |
|
74 |
||
75 |
return true; |
|
76 |
}
|
|
77 |
||
78 |
int initialize_udf(st_plugin_int *plugin) |
|
79 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
80 |
udf_func *f; |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
81 |
|
82 |
if (udf_startup == false) |
|
83 |
{
|
|
84 |
udf_init(); |
|
85 |
udf_startup= true; |
|
86 |
}
|
|
87 |
||
88 |
if (plugin->plugin->init) |
|
89 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
90 |
int r; |
91 |
if ((r= plugin->plugin->init((void *)&f))) |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
92 |
{
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
93 |
sql_print_error("Plugin '%s' init function returned error %d.", |
94 |
plugin->name.str, r); |
|
95 |
return r; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
96 |
}
|
97 |
}
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
98 |
else
|
99 |
return 1; |
|
100 |
||
101 |
if(!add_udf(f)) |
|
102 |
return 2; |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
103 |
|
104 |
return 0; |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
105 |
|
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
106 |
}
|
107 |
||
108 |
int finalize_udf(st_plugin_int *plugin) |
|
109 |
{
|
|
110 |
udf_func *udff = (udf_func *)plugin->data; |
|
111 |
||
112 |
/* TODO: Issue warning on failure */
|
|
113 |
if (udff && plugin->plugin->deinit) |
|
114 |
(void)plugin->plugin->deinit(udff); |
|
115 |
||
116 |
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. |
117 |
free(udff); |
134.1.1
by Mark Atwood
more hackery to get plugin UDFs working |
118 |
|
119 |
return 0; |
|
120 |
}
|
|
121 |