diff options
author | Dave Parks <davep@lindenlab.com> | 2010-09-24 23:52:49 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2010-09-24 23:52:49 -0500 |
commit | cd9d1685e952c762c55aee62c1e8c98ae7e26f68 (patch) | |
tree | 4852dd56a25b1f64e90500ac5b8c7023cda7bfb6 /indra/llcommon | |
parent | 36f25e43a9f9aca6625a8ead6fadf58261a6a937 (diff) | |
parent | 35c81f75ac9c134052debb21f6467012859a1fc6 (diff) |
merge
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-x | indra/llcommon/llsdserialize.cpp | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index fdeb93e27f..03d2b9c3fe 100755 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -2001,6 +2001,8 @@ std::string zip_llsd(LLSD& data) LLSDSerialize::serialize(data, llsd_strm, LLSDSerialize::LLSD_BINARY); + const U32 CHUNK = 65536; + z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -2015,24 +2017,55 @@ 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 (strm.avail_out == 0); - 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); + + std::istringstream test(result); + LLSD test_sd; + if (!unzip_llsd(test_sd, test, result.size())) + { + llerrs << "Invalid compression result!" << llendl; + } return result; } |