1
/* Copyright (C) 2006 MySQL AB
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.
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.
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 */
19
#include <drizzled/mysql_priv.h>
20
#include <drizzled/plugin.h>
21
#include <openssl/md5.h>
23
bool udf_init_md5udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
25
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
28
if (args->arg_count != 1)
30
strcpy(message,"MD5() requires one arguments");
34
if (args->arg_type[0] != STRING_RESULT)
36
strcpy(message,"MD5() requires a string");
43
char *udf_doit_md5(UDF_INIT *initid, UDF_ARGS *args, char *result,
44
unsigned long *length, char *is_null, char *error)
53
MD5_Update(&context, args->args[0], args->lengths[0]);
55
MD5_Final(digest, &context);
58
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
59
digest[0], digest[1], digest[2], digest[3],
60
digest[4], digest[5], digest[6], digest[7],
61
digest[8], digest[9], digest[10], digest[11],
62
digest[12], digest[13], digest[14], digest[15]);
66
/* is_null is already zero, this is a demonstration */
69
/* error is already zero, this is a demonstration */
75
void udf_deinit_md5udf(UDF_INIT *initid)
78
/* if we allocated initid->ptr, free it here */
83
static int md5udf_plugin_init(void *p)
85
udf_func *udff= (udf_func *) p;
86
static char md5str[4];
88
strcpy(md5str, "md5");
90
udff->name.str= md5str;
91
udff->name.length= strlen("md5");
92
udff->type= UDFTYPE_FUNCTION;
93
udff->returns= STRING_RESULT;
94
udff->func_init= udf_init_md5udf;
95
udff->func_deinit= udf_deinit_md5udf;
96
udff->func= (Udf_func_any) udf_doit_md5;
101
static int md5udf_plugin_deinit(void *p)
103
udf_func *udff = (udf_func *) p;
108
mysql_declare_plugin(md5)
114
"UDF for computing md5sum",
116
md5udf_plugin_init, /* Plugin Init */
117
md5udf_plugin_deinit, /* Plugin Deinit */
118
NULL, /* status variables */
119
NULL, /* system variables */
120
NULL /* config options */
122
mysql_declare_plugin_end;