~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uncompress/uncompressudf.cc

Moved the last of the libdrizzleclient calls into Protocol.

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
 
#define DRIZZLE_SERVER 1 /* for thd variable max_allowed_packet */
17
16
#include <drizzled/server_includes.h>
18
 
#include <drizzled/drizzled_error_messages.h>
 
17
#include <drizzled/session.h>
 
18
#include <drizzled/error.h>
 
19
#include <drizzled/function/str/strfunc.h>
19
20
 
20
21
#include <zlib.h>
 
22
#include <string>
 
23
 
 
24
using namespace std;
21
25
 
22
26
class Item_func_uncompress: public Item_str_func
23
27
{
46
50
  /* If length is less than 4 bytes, data is corrupt */
47
51
  if (res->length() <= 4)
48
52
  {
49
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
50
 
                        ER_ZLIB_Z_DATA_ERROR,
51
 
                        ER(ER_ZLIB_Z_DATA_ERROR));
 
53
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
54
                        ER_ZLIB_Z_DATA_ERROR,
 
55
                        ER(ER_ZLIB_Z_DATA_ERROR));
52
56
    goto err;
53
57
  }
54
58
 
55
59
  /* Size of uncompressed data is stored as first 4 bytes of field */
56
60
  new_size= uint4korr(res->ptr()) & 0x3FFFFFFF;
57
 
  if (new_size > current_thd->variables.max_allowed_packet)
 
61
  if (new_size > current_session->variables.max_allowed_packet)
58
62
  {
59
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
60
 
                        ER_TOO_BIG_FOR_UNCOMPRESS,
61
 
                        ER(ER_TOO_BIG_FOR_UNCOMPRESS),
62
 
                        current_thd->variables.max_allowed_packet);
 
63
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
64
                        ER_TOO_BIG_FOR_UNCOMPRESS,
 
65
                        ER(ER_TOO_BIG_FOR_UNCOMPRESS),
 
66
                        current_session->variables.max_allowed_packet);
63
67
    goto err;
64
68
  }
65
69
  if (buffer.realloc((uint32_t)new_size))
66
70
    goto err;
67
71
 
68
72
  if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
69
 
                       ((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
 
73
                       ((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
70
74
  {
71
75
    buffer.length((uint32_t) new_size);
72
76
    return &buffer;
73
77
  }
74
78
 
75
79
  code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
76
 
         ((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
77
 
  push_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
 
80
         ((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
 
81
  push_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
78
82
 
79
83
err:
80
84
  null_value= 1;
81
85
  return 0;
82
86
}
83
87
 
84
 
 
85
 
Item_func* create_uncompressudf_item(MEM_ROOT* m)
86
 
{
87
 
  return  new (m) Item_func_uncompress();
88
 
}
89
 
 
90
 
static struct udf_func uncompressudf = {
91
 
  { C_STRING_WITH_LEN("uncompress") },
92
 
  create_uncompressudf_item
93
 
};
 
88
Create_function<Item_func_uncompress> uncompressudf(string("uncompress"));
 
89
 
94
90
 
95
91
static int uncompressudf_plugin_init(void *p)
96
92
{
97
 
  udf_func **f = (udf_func**) p;
 
93
  Function_builder **f = (Function_builder**) p;
98
94
 
99
95
  *f= &uncompressudf;
100
96
 
103
99
 
104
100
static int uncompressudf_plugin_deinit(void *p)
105
101
{
106
 
  udf_func *udff = (udf_func *) p;
 
102
  Function_builder *udff = (Function_builder *) p;
107
103
  (void)udff;
108
104
  return 0;
109
105
}
110
106
 
111
 
mysql_declare_plugin(uncompress)
 
107
drizzle_declare_plugin(uncompress)
112
108
{
113
109
  DRIZZLE_UDF_PLUGIN,
114
110
  "uncompress",
122
118
  NULL,   /* system variables */
123
119
  NULL    /* config options */
124
120
}
125
 
mysql_declare_plugin_end;
 
121
drizzle_declare_plugin_end;