~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/md5/md5.cc

  • Committer: Djellel E. Difallah
  • Date: 2010-03-27 10:10:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1429.
  • Revision ID: ded@ubuntu-20100327101049-oo3arvatjoyku124
merge my_decimal and decimal

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>
 
17
#include "config.h"
18
18
 
19
19
#include <cstdio>
20
20
#include <cstddef>
21
21
 
22
22
#include <gcrypt.h>
23
23
 
24
 
#include <drizzled/charset.h>
25
 
#include <drizzled/charset_info.h>
 
24
#include <drizzled/plugin/function.h>
 
25
#include <drizzled/item/func.h>
 
26
#include "drizzled/charset.h"
26
27
#include <drizzled/function/str/strfunc.h>
27
 
#include <drizzled/item/func.h>
28
 
#include <drizzled/plugin/function.h>
29
28
 
30
29
using namespace std;
31
30
using namespace drizzled;
69
68
 
70
69
  null_value= false;
71
70
 
 
71
  unsigned char digest[16];
72
72
  str->set_charset(&my_charset_bin);
73
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
  gcry_md_hash_buffer(GCRY_MD_MD5, digest, sptr->ptr(), sptr->length());
78
75
 
79
76
  snprintf((char *) str->ptr(), 33,
80
77
    "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
84
81
    digest[12], digest[13], digest[14], digest[15]);
85
82
  str->length((uint32_t) 32);
86
83
 
87
 
  gcry_md_close(md5_context);
88
 
 
89
84
  return str;
90
85
}
91
86
 
92
87
 
93
88
plugin::Create_function<Md5Function> *md5udf= NULL;
94
89
 
95
 
static int initialize(module::Context &context)
 
90
static int initialize(plugin::Context &context)
96
91
{
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
92
  md5udf= new plugin::Create_function<Md5Function>("md5");
110
93
  context.add(md5udf);
111
94
  return 0;
120
103
  "UDF for computing md5sum",
121
104
  PLUGIN_LICENSE_GPL,
122
105
  initialize, /* Plugin Init */
123
 
  NULL,   /* depends */
 
106
  NULL,   /* system variables */
124
107
  NULL    /* config options */
125
108
}
126
109
DRIZZLE_DECLARE_PLUGIN_END;