~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/md5/md5.cc

  • Committer: Brian Aker
  • Date: 2009-08-15 00:59:30 UTC
  • mfrom: (1115.1.7 merge)
  • Revision ID: brian@gaz-20090815005930-q47yenjrq1esiwsz
Merge of Trond + Brian

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/plugin/function.h>
 
17
#include <drizzled/server_includes.h>
 
18
#include <drizzled/sql_udf.h>
25
19
#include <drizzled/item/func.h>
26
 
#include "drizzled/charset.h"
27
20
#include <drizzled/function/str/strfunc.h>
28
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
using namespace std;
30
 
using namespace drizzled;
31
31
 
32
32
class Md5Function : public Item_str_func
33
33
{
70
70
 
71
71
  unsigned char digest[16];
72
72
  str->set_charset(&my_charset_bin);
73
 
 
74
 
  gcry_md_hash_buffer(GCRY_MD_MD5, digest, sptr->ptr(), sptr->length());
 
73
  MD5_CTX context;
 
74
  MD5_Init(&context);
 
75
  MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
 
76
  MD5_Final(digest, &context);
75
77
 
76
78
  snprintf((char *) str->ptr(), 33,
77
79
    "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
85
87
}
86
88
 
87
89
 
88
 
plugin::Create_function<Md5Function> *md5udf= NULL;
 
90
Create_function<Md5Function> md5udf(string("md5"));
89
91
 
90
 
static int initialize(plugin::Context &context)
 
92
static int initialize(drizzled::plugin::Registry &registry)
91
93
{
92
 
  md5udf= new plugin::Create_function<Md5Function>("md5");
93
 
  context.add(md5udf);
 
94
  registry.add(&md5udf);
94
95
  return 0;
95
96
}
96
97
 
97
 
DRIZZLE_DECLARE_PLUGIN
98
 
{
99
 
  DRIZZLE_VERSION_ID,
 
98
static int finalize(drizzled::plugin::Registry &registry)
 
99
{
 
100
   registry.remove(&md5udf);
 
101
   return 0;
 
102
}
 
103
 
 
104
drizzle_declare_plugin(md5)
 
105
{
100
106
  "md5",
101
107
  "1.0",
102
108
  "Stewart Smith",
103
109
  "UDF for computing md5sum",
104
110
  PLUGIN_LICENSE_GPL,
105
111
  initialize, /* Plugin Init */
 
112
  finalize,   /* Plugin Deinit */
 
113
  NULL,   /* status variables */
106
114
  NULL,   /* system variables */
107
115
  NULL    /* config options */
108
116
}
109
 
DRIZZLE_DECLARE_PLUGIN_END;
 
117
drizzle_declare_plugin_end;