15
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
16
#include <drizzled/server_includes.h>
18
#include <drizzled/plugin/function.h>
17
#include <drizzled/sql_udf.h>
19
18
#include <drizzled/item/func.h>
20
19
#include <drizzled/function/str/strfunc.h>
22
#if defined(HAVE_LIBGNUTLS_OPENSSL)
21
#if defined(HAVE_GNUTLS_OPENSSL)
23
22
# include <gnutls/openssl.h>
25
24
# include <openssl/md5.h>
30
29
using namespace std;
31
using namespace drizzled;
33
class Md5Function : public Item_str_func
31
class Item_func_md5 : public Item_str_func
36
Md5Function() : Item_str_func() {}
34
Item_func_md5() : Item_str_func() {}
35
const char *func_name() const { return "md5"; }
37
36
String *val_str(String*);
39
void fix_length_and_dec()
37
void fix_length_and_dec() {
42
39
args[0]->collation.set(
43
40
get_charset_by_csname(args[0]->collation.collation->csname,
44
41
MY_CS_BINSORT), DERIVATION_COERCIBLE);
47
const char *func_name() const
52
bool check_argument_count(int n)
43
bool check_argument_count(int n) { return (n==1); }
59
String *Md5Function::val_str(String *str)
47
String *Item_func_md5::val_str(String *str)
61
assert(fixed == true);
63
String *sptr= args[0]->val_str(str);
64
if (sptr == NULL || str->alloc(32))
72
unsigned char digest[16];
50
String * sptr= args[0]->val_str(str);
73
51
str->set_charset(&my_charset_bin);
76
MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
77
MD5_Final(digest, &context);
79
snprintf((char *) str->ptr(), 33,
80
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
81
digest[0], digest[1], digest[2], digest[3],
82
digest[4], digest[5], digest[6], digest[7],
83
digest[8], digest[9], digest[10], digest[11],
84
digest[12], digest[13], digest[14], digest[15]);
85
str->length((uint32_t) 32);
91
plugin::Create_function<Md5Function> *md5udf= NULL;
93
static int initialize(plugin::Registry ®istry)
95
md5udf= new plugin::Create_function<Md5Function>("md5");
55
unsigned char digest[16];
59
MD5_Update (&context,(unsigned char *) sptr->ptr(), sptr->length());
60
MD5_Final (digest, &context);
61
if (str->alloc(32)) // Ensure that memory is free
66
snprintf((char *) str->ptr(), 33,
67
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
68
digest[0], digest[1], digest[2], digest[3],
69
digest[4], digest[5], digest[6], digest[7],
70
digest[8], digest[9], digest[10], digest[11],
71
digest[12], digest[13], digest[14], digest[15]);
72
str->length((uint) 32);
100
static int finalize(plugin::Registry ®istry)
80
Create_function<Item_func_md5> md5udf(string("md5"));
82
static int md5udf_plugin_init(PluginRegistry ®istry)
102
registry.remove(md5udf);
84
registry.add(&md5udf);
112
93
"UDF for computing md5sum",
113
94
PLUGIN_LICENSE_GPL,
114
initialize, /* Plugin Init */
115
finalize, /* Plugin Deinit */
95
md5udf_plugin_init, /* Plugin Init */
96
NULL, /* Plugin Deinit */
116
97
NULL, /* status variables */
117
98
NULL, /* system variables */
118
99
NULL /* config options */