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 */
24
#include <drizzled/charset.h>
25
#include <drizzled/charset_info.h>
17
#include <drizzled/server_includes.h>
18
#include <drizzled/plugin/function.h>
19
#include <drizzled/item/func.h>
26
20
#include <drizzled/function/str/strfunc.h>
27
#include <drizzled/item/func.h>
28
#include <drizzled/plugin/function.h>
22
#if defined(HAVE_LIBGNUTLS_OPENSSL)
23
# include <gnutls/openssl.h>
25
# include <openssl/md5.h>
26
#endif /* HAVE_GNUTLS_OPENSSL */
30
30
using namespace std;
31
31
using namespace drizzled;
72
unsigned char digest[16];
72
73
str->set_charset(&my_charset_bin);
74
gcry_md_hd_t md5_context;
75
gcry_md_open(&md5_context, GCRY_MD_MD5, 0);
76
gcry_md_write(md5_context, sptr->ptr(), sptr->length());
77
unsigned char *digest= gcry_md_read(md5_context, 0);
76
MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
77
MD5_Final(digest, &context);
79
79
snprintf((char *) str->ptr(), 33,
80
80
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
84
84
digest[12], digest[13], digest[14], digest[15]);
85
85
str->length((uint32_t) 32);
87
gcry_md_close(md5_context);
93
91
plugin::Create_function<Md5Function> *md5udf= NULL;
95
static int initialize(module::Context &context)
93
static int initialize(plugin::Registry ®istry)
97
/* Initialize libgcrypt */
98
if (not gcry_check_version(GCRYPT_VERSION))
100
errmsg_printf(error::ERROR, _("libgcrypt library version mismatch"));
103
/* Disable secure memory. */
104
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
106
/* Tell Libgcrypt that initialization has completed. */
107
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
109
95
md5udf= new plugin::Create_function<Md5Function>("md5");
114
DRIZZLE_DECLARE_PLUGIN
100
static int finalize(plugin::Registry ®istry)
102
registry.remove(md5udf);
107
drizzle_declare_plugin(md5)
120
112
"UDF for computing md5sum",
121
113
PLUGIN_LICENSE_GPL,
122
114
initialize, /* Plugin Init */
115
finalize, /* Plugin Deinit */
116
NULL, /* status variables */
117
NULL, /* system variables */
124
118
NULL /* config options */
126
DRIZZLE_DECLARE_PLUGIN_END;
120
drizzle_declare_plugin_end;