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
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
21
#include <drizzled/session.h>
22
#include <drizzled/error.h>
23
#include <drizzled/function/str/strfunc.h>
24
#include "plugin/compression/uncompress.h"
31
String *Item_func_uncompress::val_str(String *str)
34
String *res= args[0]->val_str(str);
45
/* If length is less than 4 bytes, data is corrupt */
46
if (res->length() <= 4)
48
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
50
ER(ER_ZLIB_Z_DATA_ERROR));
54
/* Size of uncompressed data is stored as first 4 bytes of field */
55
new_size= uint4korr(res->ptr()) & 0x3FFFFFFF;
56
if (new_size > current_session->variables.max_allowed_packet)
58
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
59
ER_TOO_BIG_FOR_UNCOMPRESS,
60
ER(ER_TOO_BIG_FOR_UNCOMPRESS),
61
current_session->variables.max_allowed_packet);
64
if (buffer.realloc((uint32_t)new_size))
67
if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
68
((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
70
buffer.length((uint32_t) new_size);
74
code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
75
((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
76
push_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));