~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/md5/md5.cc

  • Committer: Brian Aker
  • Date: 2009-10-07 16:55:53 UTC
  • mfrom: (1161.2.1 bug444827)
  • Revision ID: brian@gaz-20091007165553-9tnp7liw1k9g6gvc
Merge Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
16
16
 
17
 
#include "config.h"
18
 
 
19
 
#include <cstdio>
20
 
#include <cstddef>
21
 
 
22
 
#include <gcrypt.h>
23
 
 
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>
 
21
 
 
22
#if defined(HAVE_LIBGNUTLS_OPENSSL)
 
23
# include <gnutls/openssl.h>
 
24
#else
 
25
# include <openssl/md5.h>
 
26
#endif /* HAVE_GNUTLS_OPENSSL */
 
27
 
 
28
#include <stdio.h>
29
29
 
30
30
using namespace std;
31
31
using namespace drizzled;
69
69
 
70
70
  null_value= false;
71
71
 
 
72
  unsigned char digest[16];
72
73
  str->set_charset(&my_charset_bin);
73
 
 
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);
 
74
  MD5_CTX context;
 
75
  MD5_Init(&context);
 
76
  MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
 
77
  MD5_Final(digest, &context);
78
78
 
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);
86
86
 
87
 
  gcry_md_close(md5_context);
88
 
 
89
87
  return str;
90
88
}
91
89
 
92
90
 
93
91
plugin::Create_function<Md5Function> *md5udf= NULL;
94
92
 
95
 
static int initialize(module::Context &context)
 
93
static int initialize(plugin::Registry &registry)
96
94
{
97
 
  /* Initialize libgcrypt */
98
 
  if (not gcry_check_version(GCRYPT_VERSION))
99
 
  {
100
 
    errmsg_printf(error::ERROR, _("libgcrypt library version mismatch"));
101
 
    return 1;
102
 
  }
103
 
  /* Disable secure memory.  */
104
 
  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
105
 
 
106
 
  /* Tell Libgcrypt that initialization has completed. */
107
 
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
108
 
 
109
95
  md5udf= new plugin::Create_function<Md5Function>("md5");
110
 
  context.add(md5udf);
111
 
  return 0;
112
 
}
113
 
 
114
 
DRIZZLE_DECLARE_PLUGIN
115
 
{
116
 
  DRIZZLE_VERSION_ID,
 
96
  registry.add(md5udf);
 
97
  return 0;
 
98
}
 
99
 
 
100
static int finalize(plugin::Registry &registry)
 
101
{
 
102
  registry.remove(md5udf);
 
103
  delete md5udf;
 
104
  return 0;
 
105
}
 
106
 
 
107
drizzle_declare_plugin(md5)
 
108
{
117
109
  "md5",
118
110
  "1.0",
119
111
  "Stewart Smith",
120
112
  "UDF for computing md5sum",
121
113
  PLUGIN_LICENSE_GPL,
122
114
  initialize, /* Plugin Init */
123
 
  NULL,   /* depends */
 
115
  finalize,   /* Plugin Deinit */
 
116
  NULL,   /* status variables */
 
117
  NULL,   /* system variables */
124
118
  NULL    /* config options */
125
119
}
126
 
DRIZZLE_DECLARE_PLUGIN_END;
 
120
drizzle_declare_plugin_end;