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 */
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>
22
26
class Item_func_uncompress: public Item_str_func
46
50
/* If length is less than 4 bytes, data is corrupt */
47
51
if (res->length() <= 4)
49
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
51
ER(ER_ZLIB_Z_DATA_ERROR));
53
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
55
ER(ER_ZLIB_Z_DATA_ERROR));
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)
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);
65
69
if (buffer.realloc((uint32_t)new_size))
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)
71
75
buffer.length((uint32_t) new_size);
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));
85
Item_func* create_uncompressudf_item(MEM_ROOT* m)
87
return new (m) Item_func_uncompress();
90
static struct udf_func uncompressudf = {
91
{ C_STRING_WITH_LEN("uncompress") },
92
create_uncompressudf_item
88
Create_function<Item_func_uncompress> uncompressudf(string("uncompress"));
95
91
static int uncompressudf_plugin_init(void *p)
97
udf_func **f = (udf_func**) p;
93
Function_builder **f = (Function_builder**) p;
99
95
*f= &uncompressudf;