~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Brian Aker
  • Date: 2008-08-01 19:01:50 UTC
  • Revision ID: brian@tangent.org-20080801190150-003gpp2343cn7cfz
Removed final trace of crypt() lock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <config.h>
17
 
 
18
 
#include CSTDINT_H
19
 
#include <drizzled/common_includes.h>
20
 
#include <drizzled/item_func.h>
 
16
#include <drizzled/mysql_priv.h>
 
17
#include <stdlib.h>
 
18
#include <ctype.h>
 
19
#include <drizzled/plugin.h>
21
20
#include <zlib.h>
22
21
 
23
 
class Item_func_crc32 :public Item_int_func
24
 
{
25
 
  String value;
26
 
public:
27
 
  Item_func_crc32() :Item_int_func() { unsigned_flag= 1; }
28
 
  const char *func_name() const { return "crc32"; }
29
 
  void fix_length_and_dec() { max_length=10; }
30
 
  int64_t val_int();
31
 
};
32
 
 
33
 
int64_t Item_func_crc32::val_int()
34
 
{
35
 
  assert(fixed == 1);
36
 
  String *res=args[0]->val_str(&value);
37
 
  if (!res)
38
 
  {
39
 
    null_value=1;
40
 
    return 0; /* purecov: inspected */
41
 
  }
42
 
  null_value=0;
43
 
  return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
44
 
}
45
 
 
46
 
Item_func* create_crc32udf_item(MEM_ROOT* m)
47
 
{
48
 
  return  new (m) Item_func_crc32();
49
 
}
50
 
 
51
 
static struct udf_func crc32udf = {
52
 
  { C_STRING_WITH_LEN("crc32") },
53
 
  create_crc32udf_item
54
 
};
 
22
bool udf_init_crc32udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
 
23
{
 
24
  /* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
 
25
  initid->ptr= NULL;
 
26
 
 
27
  if (args->arg_count != 1)
 
28
   {
 
29
      strcpy(message,"CRC32() requires one arguments");
 
30
      return 1;
 
31
   }
 
32
 
 
33
   if (args->arg_type[0] != STRING_RESULT)
 
34
   {
 
35
      strcpy(message,"CRC32() requires a string");
 
36
      return 1;
 
37
   }
 
38
 
 
39
  return 0;
 
40
}
 
41
 
 
42
long long udf_doit_crc32(UDF_INIT *initid, UDF_ARGS *args, char *result,
 
43
                         unsigned long *length, char *is_null, char *error)
 
44
{
 
45
  (void)initid;
 
46
  (void)result;
 
47
  (void)length;
 
48
  (void)is_null;
 
49
  (void)error;
 
50
  return (long long) crc32(0L, (uchar*)args->args[0], args->lengths[0]);
 
51
}
 
52
 
 
53
void udf_deinit_crc32udf(UDF_INIT *initid)
 
54
{
 
55
  (void)initid;
 
56
  /* if we allocated initid->ptr, free it here */
 
57
  return;
 
58
}
 
59
 
55
60
 
56
61
static int crc32udf_plugin_init(void *p)
57
62
{
58
 
  udf_func **f = (udf_func**) p;
59
 
 
60
 
  *f= &crc32udf;
 
63
  udf_func *udff= (udf_func *) p;
 
64
  static char crc32str[6];
 
65
 
 
66
  strcpy(crc32str,"crc32");
 
67
 
 
68
  udff->name.str= crc32str;
 
69
  udff->name.length= strlen("crc32");
 
70
  udff->type= UDFTYPE_FUNCTION;
 
71
  udff->returns= INT_RESULT;
 
72
  udff->func_init= udf_init_crc32udf;
 
73
  udff->func_deinit= udf_deinit_crc32udf;
 
74
  udff->func= (Udf_func_any) udf_doit_crc32;
61
75
 
62
76
  return 0;
63
77
}
71
85
 
72
86
mysql_declare_plugin(crc32)
73
87
{
74
 
  DRIZZLE_UDF_PLUGIN,
 
88
  MYSQL_UDF_PLUGIN,
75
89
  "crc32",
76
90
  "1.0",
77
91
  "Stewart Smith",