139.1.2
by Stewart Smith
CRC32() as UDF |
1 |
/* Copyright (C) 2006 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
212.5.39
by Monty Taylor
Phew. Moved my_base and my_global. |
16 |
#include <drizzled/mysql_priv.h> |
139.1.2
by Stewart Smith
CRC32() as UDF |
17 |
#include <stdlib.h> |
18 |
#include <ctype.h> |
|
212.5.10
by Monty Taylor
Moved drizzle/plugin*h to drizzled |
19 |
#include <drizzled/plugin.h> |
139.1.2
by Stewart Smith
CRC32() as UDF |
20 |
#include <zlib.h> |
21 |
||
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
22 |
bool udf_init_crc32udf(UDF_INIT *initid, UDF_ARGS *args, char *message) |
139.1.2
by Stewart Smith
CRC32() as UDF |
23 |
{
|
24 |
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
|
|
25 |
initid->ptr= NULL; |
|
26 |
||
27 |
if (args->arg_count != 1) |
|
28 |
{
|
|
29 |
strcpy(message,"CRC32() requires one arguments"); |
|
30 |
return 1; |
|
31 |
}
|
|
32 |
||
33 |
if (args->arg_type[0] != STRING_RESULT) |
|
34 |
{
|
|
35 |
strcpy(message,"CRC32() requires a string"); |
|
36 |
return 1; |
|
37 |
}
|
|
38 |
||
39 |
return 0; |
|
40 |
}
|
|
41 |
||
42 |
long long udf_doit_crc32(UDF_INIT *initid, UDF_ARGS *args, char *result, |
|
43 |
unsigned long *length, char *is_null, char *error) |
|
44 |
{
|
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
45 |
(void)initid; |
46 |
(void)result; |
|
47 |
(void)length; |
|
48 |
(void)is_null; |
|
49 |
(void)error; |
|
50 |
return (long long) crc32(0L, (uchar*)args->args[0], args->lengths[0]); |
|
139.1.2
by Stewart Smith
CRC32() as UDF |
51 |
}
|
52 |
||
53 |
void udf_deinit_crc32udf(UDF_INIT *initid) |
|
54 |
{
|
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
55 |
(void)initid; |
139.1.2
by Stewart Smith
CRC32() as UDF |
56 |
/* if we allocated initid->ptr, free it here */
|
57 |
return; |
|
58 |
}
|
|
59 |
||
60 |
||
61 |
static int crc32udf_plugin_init(void *p) |
|
62 |
{
|
|
63 |
udf_func *udff= (udf_func *) p; |
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
64 |
static char crc32str[6]; |
65 |
||
66 |
strcpy(crc32str,"crc32"); |
|
67 |
||
68 |
udff->name.str= crc32str; |
|
139.1.2
by Stewart Smith
CRC32() as UDF |
69 |
udff->name.length= strlen("crc32"); |
70 |
udff->type= UDFTYPE_FUNCTION; |
|
71 |
udff->returns= INT_RESULT; |
|
72 |
udff->func_init= udf_init_crc32udf; |
|
73 |
udff->func_deinit= udf_deinit_crc32udf; |
|
74 |
udff->func= (Udf_func_any) udf_doit_crc32; |
|
75 |
||
76 |
return 0; |
|
77 |
}
|
|
78 |
||
79 |
static int crc32udf_plugin_deinit(void *p) |
|
80 |
{
|
|
81 |
udf_func *udff = (udf_func *) p; |
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
82 |
(void)udff; |
139.1.2
by Stewart Smith
CRC32() as UDF |
83 |
return 0; |
84 |
}
|
|
85 |
||
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
86 |
mysql_declare_plugin(crc32) |
139.1.2
by Stewart Smith
CRC32() as UDF |
87 |
{
|
88 |
MYSQL_UDF_PLUGIN, |
|
89 |
"crc32", |
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
90 |
"1.0", |
139.1.2
by Stewart Smith
CRC32() as UDF |
91 |
"Stewart Smith", |
92 |
"UDF for computing CRC32", |
|
93 |
PLUGIN_LICENSE_GPL, |
|
94 |
crc32udf_plugin_init, /* Plugin Init */ |
|
95 |
crc32udf_plugin_deinit, /* Plugin Deinit */ |
|
96 |
NULL, /* status variables */ |
|
97 |
NULL, /* system variables */ |
|
98 |
NULL /* config options */ |
|
99 |
}
|
|
100 |
mysql_declare_plugin_end; |