~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/md5/md5.cc

Style cleanup

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
 
 
 
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>
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
31
using namespace drizzled;
31
32
 
68
69
 
69
70
  null_value= false;
70
71
 
 
72
  unsigned char digest[16];
71
73
  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);
 
74
  MD5_CTX context;
 
75
  MD5_Init(&context);
 
76
  MD5_Update(&context, (unsigned char *) sptr->ptr(), sptr->length());
 
77
  MD5_Final(digest, &context);
77
78
 
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);
85
86
 
86
 
  gcry_md_close(md5_context);
87
 
 
88
87
  return str;
89
88
}
90
89
 
91
90
 
92
91
plugin::Create_function<Md5Function> *md5udf= NULL;
93
92
 
94
 
static int initialize(module::Context &context)
 
93
static int initialize(plugin::Registry &registry)
95
94
{
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
95
  md5udf= new plugin::Create_function<Md5Function>("md5");
109
 
  context.add(md5udf);
110
 
  return 0;
111
 
}
112
 
 
113
 
DRIZZLE_DECLARE_PLUGIN
114
 
{
115
 
  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
{
116
109
  "md5",
117
110
  "1.0",
118
111
  "Stewart Smith",
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 */
124
119
}
125
 
DRIZZLE_DECLARE_PLUGIN_END;
 
120
drizzle_declare_plugin_end;