14
14
along with this program; if not, write to the Free Software
15
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#include <drizzled/server_includes.h>
24
18
#include <drizzled/plugin/function.h>
25
19
#include <drizzled/item/func.h>
26
#include "drizzled/charset.h"
27
20
#include <drizzled/function/str/strfunc.h>
22
#if defined(HAVE_LIBGNUTLS_OPENSSL)
23
# include <gnutls/openssl.h>
25
# include <openssl/md5.h>
26
#endif /* HAVE_GNUTLS_OPENSSL */
29
30
using namespace std;
30
31
using namespace drizzled;
72
unsigned char digest[16];
71
73
str->set_charset(&my_charset_bin);
73
gcry_md_hd_t md5_context;
74
gcry_md_open(&md5_context, GCRY_MD_MD5, 0);
75
gcry_md_write(md5_context, sptr->ptr(), sptr->length());
76
unsigned char *digest= gcry_md_read(md5_context, 0);
76
MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
77
MD5_Final(digest, &context);
78
79
snprintf((char *) str->ptr(), 33,
79
80
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
83
84
digest[12], digest[13], digest[14], digest[15]);
84
85
str->length((uint32_t) 32);
86
gcry_md_close(md5_context);
92
91
plugin::Create_function<Md5Function> *md5udf= NULL;
94
static int initialize(module::Context &context)
93
static int initialize(plugin::Registry ®istry)
96
/* Initialize libgcrypt */
97
if (not gcry_check_version(GCRYPT_VERSION))
99
errmsg_printf(ERRMSG_LVL_ERROR, _("libgcrypt library version mismatch\n"));
102
/* Disable secure memory. */
103
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
105
/* Tell Libgcrypt that initialization has completed. */
106
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
108
95
md5udf= new plugin::Create_function<Md5Function>("md5");
113
DRIZZLE_DECLARE_PLUGIN
100
static int finalize(plugin::Registry ®istry)
102
registry.remove(md5udf);
107
drizzle_declare_plugin(md5)
119
112
"UDF for computing md5sum",
120
113
PLUGIN_LICENSE_GPL,
121
114
initialize, /* Plugin Init */
115
finalize, /* Plugin Deinit */
116
NULL, /* status variables */
122
117
NULL, /* system variables */
123
118
NULL /* config options */
125
DRIZZLE_DECLARE_PLUGIN_END;
120
drizzle_declare_plugin_end;