13
14
along with this program; if not, write to the Free Software
14
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include <drizzled/common_includes.h>
17
#include <openssl/md5.h>
19
bool udf_init_md5udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
21
/* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
24
if (args->arg_count != 1)
26
strcpy(message,"MD5() requires one arguments");
30
if (args->arg_type[0] != STRING_RESULT)
32
strcpy(message,"MD5() requires a string");
39
char *udf_doit_md5(UDF_INIT *initid, UDF_ARGS *args, char *result,
40
unsigned long *length, char *is_null, char *error)
19
/* Include these before the openssl headers, because they are BROKEN AS CRAP */
23
#if defined(HAVE_LIBGNUTLS_OPENSSL)
24
# include <gnutls/openssl.h>
26
# include <openssl/md5.h>
27
#endif /* HAVE_GNUTLS_OPENSSL */
29
#include <drizzled/plugin/function.h>
30
#include <drizzled/item/func.h>
31
#include "drizzled/charset.h"
32
#include <drizzled/function/str/strfunc.h>
35
using namespace drizzled;
37
class Md5Function : public Item_str_func
40
Md5Function() : Item_str_func() {}
41
String *val_str(String*);
43
void fix_length_and_dec()
46
args[0]->collation.set(
47
get_charset_by_csname(args[0]->collation.collation->csname,
48
MY_CS_BINSORT), DERIVATION_COERCIBLE);
51
const char *func_name() const
56
bool check_argument_count(int n)
63
String *Md5Function::val_str(String *str)
65
assert(fixed == true);
67
String *sptr= args[0]->val_str(str);
68
if (sptr == NULL || str->alloc(32))
76
unsigned char digest[16];
77
str->set_charset(&my_charset_bin);
47
79
MD5_Init(&context);
49
MD5_Update(&context, args->args[0], args->lengths[0]);
80
MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
51
81
MD5_Final(digest, &context);
54
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
55
digest[0], digest[1], digest[2], digest[3],
56
digest[4], digest[5], digest[6], digest[7],
57
digest[8], digest[9], digest[10], digest[11],
58
digest[12], digest[13], digest[14], digest[15]);
62
/* is_null is already zero, this is a demonstration */
65
/* error is already zero, this is a demonstration */
71
void udf_deinit_md5udf(UDF_INIT *initid)
74
/* if we allocated initid->ptr, free it here */
79
static int md5udf_plugin_init(void *p)
81
udf_func *udff= (udf_func *) p;
82
static char md5str[4];
84
strcpy(md5str, "md5");
86
udff->name.str= md5str;
87
udff->name.length= strlen("md5");
88
udff->type= UDFTYPE_FUNCTION;
89
udff->returns= STRING_RESULT;
90
udff->func_init= udf_init_md5udf;
91
udff->func_deinit= udf_deinit_md5udf;
92
udff->func= (Udf_func_any) udf_doit_md5;
97
static int md5udf_plugin_deinit(void *p)
99
udf_func *udff = (udf_func *) p;
104
mysql_declare_plugin(md5)
83
snprintf((char *) str->ptr(), 33,
84
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
85
digest[0], digest[1], digest[2], digest[3],
86
digest[4], digest[5], digest[6], digest[7],
87
digest[8], digest[9], digest[10], digest[11],
88
digest[12], digest[13], digest[14], digest[15]);
89
str->length((uint32_t) 32);
95
plugin::Create_function<Md5Function> *md5udf= NULL;
97
static int initialize(plugin::Registry ®istry)
99
md5udf= new plugin::Create_function<Md5Function>("md5");
100
registry.add(md5udf);
104
static int finalize(plugin::Registry ®istry)
106
registry.remove(md5udf);
111
DRIZZLE_DECLARE_PLUGIN
110
117
"UDF for computing md5sum",
111
118
PLUGIN_LICENSE_GPL,
112
md5udf_plugin_init, /* Plugin Init */
113
md5udf_plugin_deinit, /* Plugin Deinit */
119
initialize, /* Plugin Init */
120
finalize, /* Plugin Deinit */
114
121
NULL, /* status variables */
115
122
NULL, /* system variables */
116
123
NULL /* config options */
118
mysql_declare_plugin_end;
125
DRIZZLE_DECLARE_PLUGIN_END;