~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/md5/md5.cc

  • Committer: Stewart Smith
  • Date: 2010-03-18 12:01:34 UTC
  • mto: (1666.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: stewart@flamingspork.com-20100318120134-45fdnsw8g3j6c7oy
move RAND() into a plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "config.h"
18
18
 
 
19
/* Include these before the openssl headers, because they are BROKEN AS CRAP */
19
20
#include <cstdio>
20
21
#include <cstddef>
21
22
 
22
 
#include <gcrypt.h>
 
23
#if defined(HAVE_LIBGNUTLS_OPENSSL)
 
24
# include <gnutls/openssl.h>
 
25
#else
 
26
# include <openssl/md5.h>
 
27
#endif /* HAVE_GNUTLS_OPENSSL */
23
28
 
24
29
#include <drizzled/plugin/function.h>
25
30
#include <drizzled/item/func.h>
68
73
 
69
74
  null_value= false;
70
75
 
 
76
  unsigned char digest[16];
71
77
  str->set_charset(&my_charset_bin);
72
 
 
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);
 
78
  MD5_CTX context;
 
79
  MD5_Init(&context);
 
80
  MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
 
81
  MD5_Final(digest, &context);
77
82
 
78
83
  snprintf((char *) str->ptr(), 33,
79
84
    "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
83
88
    digest[12], digest[13], digest[14], digest[15]);
84
89
  str->length((uint32_t) 32);
85
90
 
86
 
  gcry_md_close(md5_context);
87
 
 
88
91
  return str;
89
92
}
90
93
 
91
94
 
92
95
plugin::Create_function<Md5Function> *md5udf= NULL;
93
96
 
94
 
static int initialize(module::Context &context)
 
97
static int initialize(plugin::Registry &registry)
95
98
{
96
 
  /* Initialize libgcrypt */
97
 
  if (not gcry_check_version(GCRYPT_VERSION))
98
 
  {
99
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("libgcrypt library version mismatch\n"));
100
 
    return 1;
101
 
  }
102
 
  /* Disable secure memory.  */
103
 
  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
104
 
 
105
 
  /* Tell Libgcrypt that initialization has completed. */
106
 
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
107
 
 
108
99
  md5udf= new plugin::Create_function<Md5Function>("md5");
109
 
  context.add(md5udf);
 
100
  registry.add(md5udf);
 
101
  return 0;
 
102
}
 
103
 
 
104
static int finalize(plugin::Registry &registry)
 
105
{
 
106
  registry.remove(md5udf);
 
107
  delete md5udf;
110
108
  return 0;
111
109
}
112
110
 
119
117
  "UDF for computing md5sum",
120
118
  PLUGIN_LICENSE_GPL,
121
119
  initialize, /* Plugin Init */
 
120
  finalize,   /* Plugin Deinit */
122
121
  NULL,   /* system variables */
123
122
  NULL    /* config options */
124
123
}