summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsdserialize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llsdserialize.cpp')
-rw-r--r--indra/llcommon/llsdserialize.cpp74
1 files changed, 59 insertions, 15 deletions
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index fdeb93e27f..fe7072d01a 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -78,7 +78,7 @@ void LLSDSerialize::serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize
break;
default:
- llwarns << "serialize request for unkown ELLSD_Serialize" << llendl;
+ llwarns << "serialize request for unknown ELLSD_Serialize" << llendl;
}
if (f.notNull())
@@ -1999,7 +1999,9 @@ std::string zip_llsd(LLSD& data)
{
std::stringstream llsd_strm;
- LLSDSerialize::serialize(data, llsd_strm, LLSDSerialize::LLSD_BINARY);
+ LLSDSerialize::toBinary(data, llsd_strm);
+
+ const U32 CHUNK = 65536;
z_stream strm;
strm.zalloc = Z_NULL;
@@ -2015,24 +2017,57 @@ std::string zip_llsd(LLSD& data)
std::string source = llsd_strm.str();
+ U8 out[CHUNK];
+
strm.avail_in = source.size();
strm.next_in = (U8*) source.data();
- U8* output = new U8[strm.avail_in];
- strm.avail_out = strm.avail_in;
- strm.next_out = output;
- ret = deflate(&strm, Z_FINISH);
- if (ret != Z_STREAM_END)
+ U8* output = NULL;
+
+ U32 cur_size = 0;
+
+ U32 have = 0;
+
+ do
{
- delete [] output;
- llwarns << "Failed to compress LLSD block." << llendl;
- return std::string();
+ strm.avail_out = CHUNK;
+ strm.next_out = out;
+
+ ret = deflate(&strm, Z_FINISH);
+ if (ret == Z_OK || ret == Z_STREAM_END)
+ { //copy result into output
+ if (strm.avail_out >= CHUNK)
+ {
+ llerrs << "WTF?" << llendl;
+ }
+
+ have = CHUNK-strm.avail_out;
+ output = (U8*) realloc(output, cur_size+have);
+ memcpy(output+cur_size, out, have);
+ cur_size += have;
+ }
+ else
+ {
+ free(output);
+ llwarns << "Failed to compress LLSD block." << llendl;
+ return std::string();
+ }
}
+ while (ret == Z_OK);
- std::string::size_type size = source.size()-strm.avail_out;
+ std::string::size_type size = cur_size;
std::string result((char*) output, size);
deflateEnd(&strm);
- delete [] output;
+ free(output);
+
+#if 0 //verify results work with unzip_llsd
+ std::istringstream test(result);
+ LLSD test_sd;
+ if (!unzip_llsd(test_sd, test, result.size()))
+ {
+ llerrs << "Invalid compression result!" << llendl;
+ }
+#endif
return result;
}
@@ -2098,7 +2133,7 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size)
memcpy(result+cur_size, out, have);
cur_size += have;
- } while (strm.avail_out == 0);
+ } while (ret == Z_OK);
inflateEnd(&strm);
delete [] in;
@@ -2112,9 +2147,18 @@ bool unzip_llsd(LLSD& data, std::istream& is, S32 size)
//result now points to the decompressed LLSD block
{
std::string res_str((char*) result, cur_size);
- std::istringstream istr(res_str);
- if (!LLSDSerialize::deserialize(data, istr, cur_size))
+ std::string deprecated_header("<? LLSD/Binary ?>");
+
+ if (res_str.substr(0, deprecated_header.size()) == deprecated_header)
+ {
+ res_str = res_str.substr(deprecated_header.size()+1, cur_size);
+ }
+ cur_size = res_str.size();
+
+ std::istringstream istr(res_str);
+
+ if (!LLSDSerialize::fromBinary(data, istr, cur_size))
{
llwarns << "Failed to unzip LLSD block" << llendl;
free(result);