1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/error.h>
23
#include <drizzled/function/str/strfunc.h>
24
#include <drizzled/session.h>
26
#include <plugin/compression/uncompress.h>
32
using namespace drizzled;
34
String *Item_func_uncompress::val_str(String *str)
37
String *res= args[0]->val_str(str);
40
drizzled::error_t code;
48
/* If length is less than 4 bytes, data is corrupt */
49
if (res->length() <= 4)
51
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR,
53
ER(ER_ZLIB_Z_DATA_ERROR));
57
/* Size of uncompressed data is stored as first 4 bytes of field */
58
new_size= uint4korr(res->ptr()) & 0x3FFFFFFF;
59
if (new_size > getSession().variables.max_allowed_packet)
61
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR,
62
ER_TOO_BIG_FOR_UNCOMPRESS,
63
ER(ER_TOO_BIG_FOR_UNCOMPRESS),
64
getSession().variables.max_allowed_packet);
68
if (buffer.realloc((uint32_t)new_size))
71
if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
72
((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
74
buffer.length((uint32_t) new_size);
78
code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
79
((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
80
push_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));