~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uncompress/uncompressudf.cc

  • Committer: Brian Aker
  • Date: 2009-02-12 22:45:08 UTC
  • Revision ID: brian@tangent.org-20090212224508-mrd9jwgn1zjdpqdk
Minor refactoring (we will need to disconnect the code from the include
file).

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>
21
22
 
46
47
  /* If length is less than 4 bytes, data is corrupt */
47
48
  if (res->length() <= 4)
48
49
  {
49
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
50
 
                        ER_ZLIB_Z_DATA_ERROR,
51
 
                        ER(ER_ZLIB_Z_DATA_ERROR));
 
50
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
51
                        ER_ZLIB_Z_DATA_ERROR,
 
52
                        ER(ER_ZLIB_Z_DATA_ERROR));
52
53
    goto err;
53
54
  }
54
55
 
55
56
  /* Size of uncompressed data is stored as first 4 bytes of field */
56
57
  new_size= uint4korr(res->ptr()) & 0x3FFFFFFF;
57
 
  if (new_size > current_thd->variables.max_allowed_packet)
 
58
  if (new_size > current_session->variables.max_allowed_packet)
58
59
  {
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);
 
60
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
61
                        ER_TOO_BIG_FOR_UNCOMPRESS,
 
62
                        ER(ER_TOO_BIG_FOR_UNCOMPRESS),
 
63
                        current_session->variables.max_allowed_packet);
63
64
    goto err;
64
65
  }
65
66
  if (buffer.realloc((uint32_t)new_size))
66
67
    goto err;
67
68
 
68
69
  if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
69
 
                       ((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
 
70
                       ((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
70
71
  {
71
72
    buffer.length((uint32_t) new_size);
72
73
    return &buffer;
74
75
 
75
76
  code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
76
77
         ((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));
 
78
  push_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
78
79
 
79
80
err:
80
81
  null_value= 1;
108
109
  return 0;
109
110
}
110
111
 
111
 
mysql_declare_plugin(uncompress)
 
112
drizzle_declare_plugin(uncompress)
112
113
{
113
114
  DRIZZLE_UDF_PLUGIN,
114
115
  "uncompress",
122
123
  NULL,   /* system variables */
123
124
  NULL    /* config options */
124
125
}
125
 
mysql_declare_plugin_end;
 
126
drizzle_declare_plugin_end;