971.1.64
by Monty Taylor
Merged compress, uncompress and uncompressed_length into one plugin lib. Yay new plugin registration! |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
971.1.64
by Monty Taylor
Merged compress, uncompress and uncompressed_length into one plugin lib. Yay new plugin registration! |
5 |
*
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
19 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
21 |
|
549
by Monty Taylor
Took gettext.h out of header files. |
22 |
#include <drizzled/error.h> |
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
23 |
#include <drizzled/function/str/strfunc.h> |
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
24 |
#include <drizzled/session.h> |
2241.3.2
by Olaf van der Spek
Refactor Session::variables |
25 |
#include <drizzled/system_variables.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
26 |
#include <plugin/compression/uncompress.h> |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
27 |
|
28 |
#include <zlib.h> |
|
942.1.12
by Monty Taylor
Converted udf_func into a factory. |
29 |
#include <string> |
30 |
||
31 |
using namespace std; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
32 |
using namespace drizzled; |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
33 |
|
34 |
String *Item_func_uncompress::val_str(String *str) |
|
35 |
{
|
|
36 |
assert(fixed == 1); |
|
37 |
String *res= args[0]->val_str(str); |
|
38 |
ulong new_size; |
|
39 |
int err; |
|
2087.3.1
by Brian Aker
Entire convert over to time_t. |
40 |
drizzled::error_t code; |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
41 |
|
42 |
if (!res) |
|
43 |
goto err; |
|
44 |
null_value= 0; |
|
2318.7.11
by Olaf van der Spek
Use String::c_str() instead of c_ptr_safe() |
45 |
if (res->empty()) |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
46 |
return res; |
47 |
||
48 |
/* If length is less than 4 bytes, data is corrupt */
|
|
49 |
if (res->length() <= 4) |
|
50 |
{
|
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
51 |
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
52 |
ER_ZLIB_Z_DATA_ERROR, |
53 |
ER(ER_ZLIB_Z_DATA_ERROR)); |
|
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
54 |
goto err; |
55 |
}
|
|
56 |
||
57 |
/* Size of uncompressed data is stored as first 4 bytes of field */
|
|
58 |
new_size= uint4korr(res->ptr()) & 0x3FFFFFFF; |
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
59 |
if (new_size > getSession().variables.max_allowed_packet) |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
60 |
{
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
61 |
push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
62 |
ER_TOO_BIG_FOR_UNCOMPRESS, |
63 |
ER(ER_TOO_BIG_FOR_UNCOMPRESS), |
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
64 |
getSession().variables.max_allowed_packet); |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
65 |
goto err; |
66 |
}
|
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
67 |
|
2281.6.3
by Olaf van der Spek
Return void |
68 |
buffer.realloc(new_size); |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
69 |
|
70 |
if ((err= uncompress((Byte*)buffer.ptr(), &new_size, |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
71 |
((const Bytef*)res->ptr())+4,res->length())) == Z_OK) |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
72 |
{
|
73 |
buffer.length((uint32_t) new_size); |
|
74 |
return &buffer; |
|
75 |
}
|
|
76 |
||
77 |
code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR : |
|
942.1.12
by Monty Taylor
Converted udf_func into a factory. |
78 |
((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR)); |
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
79 |
push_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code)); |
139.1.9
by Stewart Smith
Move compression functions (compress, uncompress and compressed_length) out into modules and fix test |
80 |
|
81 |
err: |
|
82 |
null_value= 1; |
|
83 |
return 0; |
|
84 |
}
|
|
85 |