139.1.1
by Stewart Smith
Move MD5() into a 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 |
||
243.1.14
by Jay Pipes
* Ensured all drizzled/field/x.cc files to include mysql_priv.h |
16 |
#include <drizzled/common_includes.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. |
17 |
#include <drizzled/sql_udf.h> |
584.4.6
by Monty Taylor
Moved stuff into item/ |
18 |
#include <drizzled/item/func.h> |
19 |
#include <drizzled/item/strfunc.h> |
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
20 |
|
139.1.1
by Stewart Smith
Move MD5() into a UDF |
21 |
#include <openssl/md5.h> |
22 |
||
520.4.44
by mordred
A whole bunch of solaris/sun studio compile fixes. |
23 |
#include <stdio.h> |
24 |
||
25 |
using namespace std; |
|
26 |
||
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
27 |
class Item_func_md5 : public Item_str_func |
28 |
{
|
|
29 |
public: |
|
30 |
const char *func_name() const { return "md5"; } |
|
31 |
String *val_str(String*); |
|
32 |
void fix_length_and_dec() { |
|
33 |
max_length=32; |
|
34 |
args[0]->collation.set( |
|
35 |
get_charset_by_csname(args[0]->collation.collation->csname, |
|
36 |
MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE); |
|
37 |
}
|
|
38 |
||
39 |
};
|
|
40 |
||
41 |
||
42 |
String *Item_func_md5::val_str(String *str) |
|
43 |
{
|
|
44 |
assert(fixed == 1); |
|
45 |
String * sptr= args[0]->val_str(str); |
|
46 |
str->set_charset(&my_charset_bin); |
|
47 |
if (sptr) |
|
48 |
{
|
|
49 |
MD5_CTX context; |
|
481
by Brian Aker
Remove all of uchar. |
50 |
unsigned char digest[16]; |
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
51 |
|
52 |
null_value=0; |
|
53 |
MD5_Init (&context); |
|
481
by Brian Aker
Remove all of uchar. |
54 |
MD5_Update (&context,(unsigned char *) sptr->ptr(), sptr->length()); |
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
55 |
MD5_Final (digest, &context); |
56 |
if (str->alloc(32)) // Ensure that memory is free |
|
57 |
{
|
|
58 |
null_value=1; |
|
59 |
return 0; |
|
60 |
}
|
|
61 |
snprintf((char *) str->ptr(), 33, |
|
62 |
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
|
63 |
digest[0], digest[1], digest[2], digest[3], |
|
64 |
digest[4], digest[5], digest[6], digest[7], |
|
65 |
digest[8], digest[9], digest[10], digest[11], |
|
66 |
digest[12], digest[13], digest[14], digest[15]); |
|
67 |
str->length((uint) 32); |
|
68 |
return str; |
|
69 |
}
|
|
70 |
null_value=1; |
|
139.1.1
by Stewart Smith
Move MD5() into a UDF |
71 |
return 0; |
72 |
}
|
|
73 |
||
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
74 |
|
75 |
Item_func* create_md5udf_item(MEM_ROOT* m) |
|
76 |
{
|
|
77 |
return new (m) Item_func_md5(); |
|
78 |
}
|
|
79 |
||
80 |
struct udf_func md5udf = { |
|
81 |
{ C_STRING_WITH_LEN("md5") }, |
|
82 |
create_md5udf_item
|
|
83 |
};
|
|
139.1.1
by Stewart Smith
Move MD5() into a UDF |
84 |
|
85 |
static int md5udf_plugin_init(void *p) |
|
86 |
{
|
|
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
87 |
udf_func **f = (udf_func**) p; |
88 |
||
89 |
*f= &md5udf; |
|
139.1.1
by Stewart Smith
Move MD5() into a UDF |
90 |
|
91 |
return 0; |
|
92 |
}
|
|
93 |
||
94 |
static int md5udf_plugin_deinit(void *p) |
|
95 |
{
|
|
96 |
udf_func *udff = (udf_func *) p; |
|
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
97 |
(void)udff; |
139.1.1
by Stewart Smith
Move MD5() into a UDF |
98 |
return 0; |
99 |
}
|
|
100 |
||
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
101 |
mysql_declare_plugin(md5) |
139.1.1
by Stewart Smith
Move MD5() into a UDF |
102 |
{
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
103 |
DRIZZLE_UDF_PLUGIN, |
139.1.1
by Stewart Smith
Move MD5() into a UDF |
104 |
"md5", |
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
105 |
"1.0", |
139.1.1
by Stewart Smith
Move MD5() into a UDF |
106 |
"Stewart Smith", |
139.1.4
by Stewart Smith
merge mainline and update md5 and crc32 plugins to new interface |
107 |
"UDF for computing md5sum", |
139.1.1
by Stewart Smith
Move MD5() into a UDF |
108 |
PLUGIN_LICENSE_GPL, |
109 |
md5udf_plugin_init, /* Plugin Init */ |
|
110 |
md5udf_plugin_deinit, /* Plugin Deinit */ |
|
111 |
NULL, /* status variables */ |
|
112 |
NULL, /* system variables */ |
|
113 |
NULL /* config options */ |
|
114 |
}
|
|
115 |
mysql_declare_plugin_end; |