~mkindahl/drizzle/remove-mem-casts

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Brian Aker
  • Date: 2008-07-26 04:44:25 UTC
  • mfrom: (210.1.1 drizzle)
  • Revision ID: brian@tangent.org-20080726044425-3sju27xc1e25hylr
Merge from Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
15
 
 
16
#include <mysql_priv.h>
 
17
#include <stdlib.h>
 
18
#include <ctype.h>
 
19
#include <drizzle_version.h>
 
20
#include <drizzle/plugin.h>
 
21
#include <my_global.h>
 
22
#include <my_dir.h>
 
23
#include <zlib.h>
 
24
 
 
25
bool udf_init_crc32udf(UDF_INIT *initid, UDF_ARGS *args, char *message)
 
26
{
 
27
  /* initid->ptr keeps state for between udf_init_foo and udf_deinit_foo */
 
28
  initid->ptr= NULL;
 
29
 
 
30
  if (args->arg_count != 1)
 
31
   {
 
32
      strcpy(message,"CRC32() requires one arguments");
 
33
      return 1;
 
34
   }
 
35
 
 
36
   if (args->arg_type[0] != STRING_RESULT)
 
37
   {
 
38
      strcpy(message,"CRC32() requires a string");
 
39
      return 1;
 
40
   }
 
41
 
 
42
  return 0;
 
43
}
 
44
 
 
45
long long udf_doit_crc32(UDF_INIT *initid, UDF_ARGS *args, char *result,
 
46
                         unsigned long *length, char *is_null, char *error)
 
47
{
 
48
  (void)initid;
 
49
  (void)result;
 
50
  (void)length;
 
51
  (void)is_null;
 
52
  (void)error;
 
53
  return (long long) crc32(0L, (uchar*)args->args[0], args->lengths[0]);
 
54
}
 
55
 
 
56
void udf_deinit_crc32udf(UDF_INIT *initid)
 
57
{
 
58
  (void)initid;
 
59
  /* if we allocated initid->ptr, free it here */
 
60
  return;
 
61
}
 
62
 
 
63
 
 
64
static int crc32udf_plugin_init(void *p)
 
65
{
 
66
  udf_func *udff= (udf_func *) p;
 
67
  static char crc32str[6];
 
68
 
 
69
  strcpy(crc32str,"crc32");
 
70
 
 
71
  udff->name.str= crc32str;
 
72
  udff->name.length= strlen("crc32");
 
73
  udff->type= UDFTYPE_FUNCTION;
 
74
  udff->returns= INT_RESULT;
 
75
  udff->func_init= udf_init_crc32udf;
 
76
  udff->func_deinit= udf_deinit_crc32udf;
 
77
  udff->func= (Udf_func_any) udf_doit_crc32;
 
78
 
 
79
  return 0;
 
80
}
 
81
 
 
82
static int crc32udf_plugin_deinit(void *p)
 
83
{
 
84
  udf_func *udff = (udf_func *) p;
 
85
  (void)udff;
 
86
  return 0;
 
87
}
 
88
 
 
89
mysql_declare_plugin(crc32)
 
90
{
 
91
  MYSQL_UDF_PLUGIN,
 
92
  "crc32",
 
93
  "1.0",
 
94
  "Stewart Smith",
 
95
  "UDF for computing CRC32",
 
96
  PLUGIN_LICENSE_GPL,
 
97
  crc32udf_plugin_init, /* Plugin Init */
 
98
  crc32udf_plugin_deinit, /* Plugin Deinit */
 
99
  NULL,   /* status variables */
 
100
  NULL,   /* system variables */
 
101
  NULL    /* config options */
 
102
}
 
103
mysql_declare_plugin_end;