# # # add_file "botan/zlib.cpp" # content [cd044ddd594a23b2ae617105889b0ece9c0f36cb] # # add_file "botan/zlib.h" # content [7dbbc22ac933791c1d8b478ec8262121739af1cf] # # patch "ChangeLog" # from [dc14494232e69b6d137d331021d844d319ef80f5] # to [13157c0eb81440ce17398fa65631f0c207d2e23b] # # patch "Makefile.am" # from [73bbbf9fadf07f9f85d194f011de6671b8dbbbda] # to [2542cb2d688241b61a971202c27fe03b85c1a282] # # patch "constants.cc" # from [c7bc2142cf0e9861c9fd744f458da6e8c7a0323e] # to [4862e4dd40e839549ea232c4a5ff5667f3db60eb] # # patch "constants.hh" # from [528788cf84a56e076de55706b0fb989f570a6e9f] # to [cb9a90123c2e04eb14599794e2a305b716c4592a] # # patch "database.cc" # from [17b289e6695148195c7d6d1157d8a019bbd660c1] # to [0cc12271e2e7757c3c800a8b32862cafbe19cacf] # # patch "netcmd.cc" # from [9ac3f6b7a08c59615bfd86fcad7ca931fb1b8758] # to [68a5ee198fd9f10703a25563d7eb18bf378f7ff9] # # patch "packet.cc" # from [06b93709b49bc581a5274afc7762f503abf89dc2] # to [e02a6d049117f765e9866bfd45700de7983b1b5c] # # patch "schema_migration.cc" # from [a373ed3f47b83178d5bd34d8252e4733fb272075] # to [82468c4527b9eefa898e88ebf08450c7bfc0981e] # # patch "transforms.cc" # from [1f17068bcfa0609f9962200eb33920168f10e7be] # to [6049875a935c0de87a6bb5f0c3d46f48cf091b10] # # patch "transforms.hh" # from [20649bff0b21dec65062baa1de4b11ab1f05d950] # to [15778b0b0621946b1168d06670c137b4513e609b] # # patch "vocab_terms.hh" # from [3e28281bce1cc56b544dd17c356ba139f9bd5e22] # to [1cd89c8f6b40cab5c80be3861faa0f69fc319d70] # ============================================================ --- botan/zlib.cpp cd044ddd594a23b2ae617105889b0ece9c0f36cb +++ botan/zlib.cpp cd044ddd594a23b2ae617105889b0ece9c0f36cb @@ -0,0 +1,266 @@ +/************************************************* +* Zlib Compressor Source File * +* (C) 1999-2005 The Botan Project * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Allocation Information for Zlib * +*************************************************/ +class Zlib_Alloc_Info + { + public: + std::map current_allocs; + Allocator* alloc; + + Zlib_Alloc_Info() { alloc = get_allocator(); } + }; + +/************************************************* +* Allocation Function for Zlib * +*************************************************/ +void* zlib_malloc(void* info_ptr, unsigned int n, unsigned int size) + { + Zlib_Alloc_Info* info = static_cast(info_ptr); + void* ptr = info->alloc->allocate(n * size); + info->current_allocs[ptr] = n * size; + return ptr; + } + +/************************************************* +* Allocation Function for Zlib * +*************************************************/ +void zlib_free(void* info_ptr, void* ptr) + { + Zlib_Alloc_Info* info = static_cast(info_ptr); + std::map::const_iterator i = info->current_allocs.find(ptr); + if(i == info->current_allocs.end()) + throw Invalid_Argument("zlib_free: Got pointer not allocated by us"); + info->alloc->deallocate(ptr, i->second); + } + +} + +/************************************************* +* Wrapper Type for Zlib z_stream * +*************************************************/ +class Zlib_Stream + { + public: + z_stream stream; + + Zlib_Stream() + { + std::memset(&stream, 0, sizeof(z_stream)); + stream.zalloc = zlib_malloc; + stream.zfree = zlib_free; + stream.opaque = new Zlib_Alloc_Info; + } + ~Zlib_Stream() + { + Zlib_Alloc_Info* info = static_cast(stream.opaque); + delete info; + std::memset(&stream, 0, sizeof(z_stream)); + } + }; + +/************************************************* +* Zlib_Compression Constructor * +*************************************************/ +Zlib_Compression::Zlib_Compression(u32bit l) : + level((l >= 9) ? 9 : l), buffer(DEFAULT_BUFFERSIZE) + { + zlib = 0; + } + +/************************************************* +* Start Compressing with Zlib * +*************************************************/ +void Zlib_Compression::start_msg() + { + clear(); + zlib = new Zlib_Stream; + if(deflateInit(&(zlib->stream), level) != Z_OK) + throw Exception("Zlib_Compression: Memory allocation error"); + } + +/************************************************* +* Compress Input with Zlib * +*************************************************/ +void Zlib_Compression::write(const byte input[], u32bit length) + { + zlib->stream.next_in = (Bytef*)input; + zlib->stream.avail_in = length; + + while(zlib->stream.avail_in != 0) + { + zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.avail_out = buffer.size(); + deflate(&(zlib->stream), Z_NO_FLUSH); + send(buffer.begin(), buffer.size() - zlib->stream.avail_out); + } + } + +/************************************************* +* Finish Compressing with Zlib * +*************************************************/ +void Zlib_Compression::end_msg() + { + zlib->stream.next_in = 0; + zlib->stream.avail_in = 0; + + int rc = Z_OK; + while(rc != Z_STREAM_END) + { + zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.avail_out = buffer.size(); + rc = deflate(&(zlib->stream), Z_FINISH); + send(buffer.begin(), buffer.size() - zlib->stream.avail_out); + } + clear(); + } + +/************************************************* +* Flush the Zlib Compressor * +*************************************************/ +void Zlib_Compression::flush() + { + zlib->stream.next_in = 0; + zlib->stream.avail_in = 0; + + while(true) + { + zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.avail_out = buffer.size(); + deflate(&(zlib->stream), Z_FULL_FLUSH); + send(buffer.begin(), buffer.size() - zlib->stream.avail_out); + if(zlib->stream.avail_out == buffer.size()) break; + } + } + +/************************************************* +* Clean up Compression Context * +*************************************************/ +void Zlib_Compression::clear() + { + if(zlib) + { + deflateEnd(&(zlib->stream)); + delete zlib; + zlib = 0; + } + + buffer.clear(); + } + +/************************************************* +* Zlib_Decompression Constructor * +*************************************************/ +Zlib_Decompression::Zlib_Decompression() : buffer(DEFAULT_BUFFERSIZE) + { + zlib = 0; + no_writes = true; + } + +/************************************************* +* Start Decompressing with Zlib * +*************************************************/ +void Zlib_Decompression::start_msg() + { + clear(); + zlib = new Zlib_Stream; + if(inflateInit(&(zlib->stream)) != Z_OK) + throw Exception("Zlib_Decompression: Memory allocation error"); + } + +/************************************************* +* Decompress Input with Zlib * +*************************************************/ +void Zlib_Decompression::write(const byte input[], u32bit length) + { + if(length) no_writes = false; + + zlib->stream.next_in = (Bytef*)input; + zlib->stream.avail_in = length; + + while(zlib->stream.avail_in != 0) + { + zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.avail_out = buffer.size(); + + int rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); + if(rc != Z_OK && rc != Z_STREAM_END) + { + clear(); + if(rc == Z_DATA_ERROR) + throw Decoding_Error("Zlib_Decompression: Data integrity error"); + if(rc == Z_NEED_DICT) + throw Decoding_Error("Zlib_Decompression: Need preset dictionary"); + if(rc == Z_MEM_ERROR) + throw Exception("Zlib_Decompression: Memory allocation error"); + throw Exception("Zlib_Decompression: Unknown decompress error"); + } + send(buffer.begin(), buffer.size() - zlib->stream.avail_out); + if(rc == Z_STREAM_END) + { + u32bit read_from_block = length - zlib->stream.avail_in; + start_msg(); + zlib->stream.next_in = (Bytef*)input + read_from_block; + zlib->stream.avail_in = length - read_from_block; + input += read_from_block; + length -= read_from_block; + } + } + } + +/************************************************* +* Finish Decompressing with Zlib * +*************************************************/ +void Zlib_Decompression::end_msg() + { + if(no_writes) return; + zlib->stream.next_in = 0; + zlib->stream.avail_in = 0; + + int rc = Z_OK; + while(rc != Z_STREAM_END) + { + zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.avail_out = buffer.size(); + rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); + if(rc != Z_OK && rc != Z_STREAM_END) + { + clear(); + throw Exception("Zlib_Decompression: Error finalizing decompression"); + } + send(buffer.begin(), buffer.size() - zlib->stream.avail_out); + } + clear(); + } + +/************************************************* +* Clean up Decompression Context * +*************************************************/ +void Zlib_Decompression::clear() + { + no_writes = true; + + if(zlib) + { + inflateEnd(&(zlib->stream)); + delete zlib; + zlib = 0; + } + + buffer.clear(); + } + +} ============================================================ --- botan/zlib.h 7dbbc22ac933791c1d8b478ec8262121739af1cf +++ botan/zlib.h 7dbbc22ac933791c1d8b478ec8262121739af1cf @@ -0,0 +1,55 @@ +/************************************************* +* Zlib Compressor Header File * +* (C) 1999-2005 The Botan Project * +*************************************************/ + +#ifndef BOTAN_EXT_ZLIB_H__ +#define BOTAN_EXT_ZLIB_H__ + +#include + +namespace Botan { + +/************************************************* +* Zlib Compression Filter * +*************************************************/ +class Zlib_Compression : public Filter + { + public: + void write(const byte input[], u32bit length); + void start_msg(); + void end_msg(); + + void flush(); + + Zlib_Compression(u32bit = 6); + ~Zlib_Compression() { clear(); } + private: + void clear(); + const u32bit level; + SecureVector buffer; + class Zlib_Stream* zlib; + }; + +/************************************************* +* Zlib Decompression Filter * +*************************************************/ +class Zlib_Decompression : public Filter + { + public: + void write(const byte input[], u32bit length); + void start_msg(); + void end_msg(); + + Zlib_Decompression(); + ~Zlib_Decompression() { clear(); } + private: + void clear(); + SecureVector buffer; + class Zlib_Stream* zlib; + bool no_writes; + }; + +} + +#endif ============================================================ --- ChangeLog dc14494232e69b6d137d331021d844d319ef80f5 +++ ChangeLog 13157c0eb81440ce17398fa65631f0c207d2e23b @@ -1,3 +1,8 @@ +2006-01-19 Matt Johnston + + * switch from using gzip to zlib everywhere, add to the + sqlite binary migration code. + 2006-01-18 Nathaniel Smith * configure.ac: s/TRY_RUN/TRY_COMPILE/ a few places, for general ============================================================ --- Makefile.am 73bbbf9fadf07f9f85d194f011de6671b8dbbbda +++ Makefile.am 2542cb2d688241b61a971202c27fe03b85c1a282 @@ -123,6 +123,7 @@ botan/x509self.cpp botan/x509stor.cpp \ botan/def_alg.cpp botan/def_mode.cpp botan/sha256.cpp \ botan/x931_rng.cpp botan/out_buf.cpp botan/bit_ops.cpp \ + botan/zlib.cpp \ \ botan/aes.h botan/botan.h botan/def_eng.h botan/es_win32.h \ botan/lookup.h botan/randpool.h botan/version.h \ @@ -157,7 +158,7 @@ botan/util.h botan/charset.h botan/hash_id.h \ botan/des.h botan/pkcs5.h \ botan/x931_rng.h botan/sha256.h \ - botan/parsing.h botan/out_buf.h botan/bit_ops.h + botan/parsing.h botan/out_buf.h botan/bit_ops.h botan/zlib.h ============================================================ --- constants.cc c7bc2142cf0e9861c9fd744f458da6e8c7a0323e +++ constants.cc 4862e4dd40e839549ea232c4a5ff5667f3db60eb @@ -141,9 +141,9 @@ BOOST_STATIC_ASSERT(merkle_bitmap_length_in_bits > 0); BOOST_STATIC_ASSERT((merkle_bitmap_length_in_bits % 8) == 0); - u8 const netcmd_current_protocol_version = 6; + u8 const netcmd_current_protocol_version = 7; - size_t const netcmd_minimum_bytes_to_bother_with_gzip = 0xfff; + size_t const netcmd_minimum_bytes_to_bother_with_zlib = 0xfff; size_t const netsync_session_key_length_in_bytes = 20; // 160 bits size_t const netsync_hmac_value_length_in_bytes = 20; // 160 bits ============================================================ --- constants.hh 528788cf84a56e076de55706b0fb989f570a6e9f +++ constants.hh cb9a90123c2e04eb14599794e2a305b716c4592a @@ -125,8 +125,8 @@ // maximum size of any netcmd on the wire, including payload static size_t const netcmd_maxsz = netcmd_minsz + netcmd_payload_limit; - // netsync fragments larger than this are gzipped - extern size_t const netcmd_minimum_bytes_to_bother_with_gzip; + // netsync fragments larger than this are zlibbed + extern size_t const netcmd_minimum_bytes_to_bother_with_zlib; // TCP port to listen on / connect to when doing netsync static size_t const netsync_default_port = 4691; ============================================================ --- database.cc 17b289e6695148195c7d6d1157d8a019bbd660c1 +++ database.cc 0cc12271e2e7757c3c800a8b32862cafbe19cacf @@ -661,7 +661,7 @@ // we can use SQLITE_STATIC since the array is destructed after // fetching the parameters (and sqlite3_reset) - if (args[param-1].binary) + if (args[param-1].blob) sqlite3_bind_blob(stmt.stmt(), param, args[param-1].data(), args[param-1].size(), SQLITE_STATIC); else sqlite3_bind_text(stmt.stmt(), param, args[param-1].c_str(), -1, SQLITE_STATIC); @@ -823,9 +823,9 @@ fetch(res, one_col, one_row, query.c_str(), ident().c_str()); // consistency check - gzip rdata(res[0][0]); + zlib rdata(res[0][0]); data rdata_unpacked; - decode_gzip(rdata,rdata_unpacked); + decode_zlib(rdata, rdata_unpacked); hexenc tid; calculate_ident(rdata_unpacked, tid); @@ -847,8 +847,8 @@ fetch(res, one_col, one_row, query.c_str(), ident().c_str(), base().c_str()); - gzip del_packed(res[0][0]); - decode_gzip(del_packed, del); + zlib del_packed(res[0][0]); + decode_zlib(del_packed, del); } void @@ -864,8 +864,8 @@ MM(tid); I(tid == ident); - gzip dat_packed; - encode_gzip(dat, dat_packed); + zlib dat_packed; + encode_zlib(dat, dat_packed); string insert = "INSERT INTO " + table + " VALUES(?, ?)"; std::vector args; @@ -883,8 +883,8 @@ I(ident() != ""); I(base() != ""); - gzip del_packed; - encode_gzip(del, del_packed); + zlib del_packed; + encode_zlib(del, del_packed); std::vector args; args.push_back(ident()); @@ -1450,9 +1450,9 @@ "SELECT data FROM revisions WHERE id = ?", id.inner()().c_str()); - gzip gzdata(res[0][0]); + zlib gzdata(res[0][0]); data rdat; - decode_gzip(gzdata,rdat); + decode_zlib(gzdata,rdat); // verify that we got a revision with the right id { @@ -1544,8 +1544,8 @@ std::vector args; args.push_back(new_id.inner()()); - gzip d_packed; - encode_gzip(d.inner(), d_packed); + zlib d_packed; + encode_zlib(d.inner(), d_packed); args.push_back(queryarg(d_packed(), true)); execute(std::string("INSERT INTO revisions VALUES(?, ?)"), args); ============================================================ --- netcmd.cc 9ac3f6b7a08c59615bfd86fcad7ca931fb1b8758 +++ netcmd.cc 68a5ee198fd9f10703a25563d7eb18bf378f7ff9 @@ -414,9 +414,9 @@ "data netcmd, data payload"); if (compressed_p == 1) { - gzip zdat(dat); + zlib zdat(dat); data tdat; - decode_gzip(zdat, tdat); + decode_zlib(zdat, tdat); dat = tdat(); } assert_end_of_buffer(payload, pos, "data netcmd payload"); @@ -431,10 +431,10 @@ I(item().size() == constants::merkle_hash_length_in_bytes); payload += static_cast(type); payload += item(); - if (dat.size() > constants::netcmd_minimum_bytes_to_bother_with_gzip) + if (dat.size() > constants::netcmd_minimum_bytes_to_bother_with_zlib) { - gzip zdat; - encode_gzip(dat, zdat); + zlib zdat; + encode_zlib(dat, zdat); payload += static_cast(1); // compressed flag insert_variable_length_string(zdat(), payload); } @@ -467,8 +467,8 @@ "delta netcmd, delta payload"); if (compressed_p == 1) { - gzip zdel(tmp); - decode_gzip(zdel, del); + zlib zdel(tmp); + decode_zlib(zdel, del); } else { @@ -491,11 +491,11 @@ string tmp; - if (tmp.size() > constants::netcmd_minimum_bytes_to_bother_with_gzip) + if (tmp.size() > constants::netcmd_minimum_bytes_to_bother_with_zlib) { payload += static_cast(1); // compressed flag - gzip zdel; - encode_gzip(del, zdel); + zlib zdel; + encode_zlib(del, zdel); tmp = zdel(); } else ============================================================ --- packet.cc 06b93709b49bc581a5274afc7762f503abf89dc2 +++ packet.cc e02a6d049117f765e9866bfd45700de7983b1b5c @@ -262,7 +262,7 @@ packet_writer::consume_file_data(file_id const & ident, file_data const & dat) { - base64 > packed; + base64 > packed; pack(dat.inner(), packed); ost << "[fdata " << ident.inner()() << "]" << endl << trim_ws(packed()) << endl @@ -274,7 +274,7 @@ file_id const & new_id, file_delta const & del) { - base64 > packed; + base64 > packed; pack(del.inner(), packed); ost << "[fdelta " << old_id.inner()() << endl << " " << new_id.inner()() << "]" << endl @@ -286,7 +286,7 @@ packet_writer::consume_revision_data(revision_id const & ident, revision_data const & dat) { - base64 > packed; + base64 > packed; pack(dat.inner(), packed); ost << "[rdata " << ident.inner()() << "]" << endl << trim_ws(packed()) << endl @@ -365,7 +365,7 @@ L(FL("read data packet")); require(regex_match(args, regex(ident))); require(regex_match(body, regex(base))); - base64 > body_packed(trim_ws(body)); + base64 > body_packed(trim_ws(body)); data contents; unpack(body_packed, contents); if (type == "rdata") @@ -385,7 +385,7 @@ string src_id(matches[1].first, matches[1].second); string dst_id(matches[2].first, matches[2].second); require(regex_match(body, regex(base))); - base64 > body_packed(trim_ws(body)); + base64 > body_packed(trim_ws(body)); delta contents; unpack(body_packed, contents); cons.consume_file_delta(file_id(hexenc(src_id)), ============================================================ --- schema_migration.cc a373ed3f47b83178d5bd34d8252e4733fb272075 +++ schema_migration.cc 82468c4527b9eefa898e88ebf08450c7bfc0981e @@ -59,6 +59,7 @@ const char *sqlite3_value_text_s(sqlite3_value *v); } +/* static string lowercase(string const & in) { @@ -70,6 +71,7 @@ use_facet< ctype >(loc).tolower(buf, buf+sz); return string(buf,sz); } +*/ static void massage_sql_tokens(string const & in, @@ -919,9 +921,28 @@ } data decoded; decode_base64(base64(string(sqlite3_value_text_s(args[0]))), decoded); - sqlite3_result_blob(f, decoded().c_str(), decoded().size(), SQLITE_TRANSIENT); + sqlite3_result_blob(f, decoded().data(), decoded().size(), SQLITE_TRANSIENT); } +// this function expects a blob, since gzip and zlib data are both binary +static void +sqlite3_gzip_to_zlib_fn(sqlite3_context *f, int nargs, sqlite3_value ** args) +{ + if (nargs != 1) + { + sqlite3_result_error(f, "need exactly 1 arg to gzip_to_zlib()", -1); + return; + } + data decoded; + MM(decoded); + const char* blob = (const char*)sqlite3_value_blob(args[0]); + int bytes = sqlite3_value_bytes(args[0]); + decode_gzip(gzip(string(blob, bytes)), decoded); + zlib zlibbed; + encode_zlib(decoded, zlibbed); + sqlite3_result_blob(f, zlibbed().data(), zlibbed().size(), SQLITE_TRANSIENT); +} + // I wish I had a form of ALTER TABLE COMMENT on sqlite3 static bool migrate_files_BLOB(sqlite3 * sql, @@ -933,6 +954,10 @@ SQLITE_UTF8, NULL, &sqlite3_unbase64_fn, NULL, NULL) == 0); + I(sqlite3_create_function(sql, "gzip_to_zlib", -1, + SQLITE_UTF8, NULL, + &sqlite3_gzip_to_zlib_fn, + NULL, NULL) == 0); // change the encoding of file(_delta)s if (!move_table(sql, errmsg, "files", @@ -952,7 +977,7 @@ return false; res = logged_sqlite3_exec(sql, "INSERT INTO files " - "SELECT id, unbase64(data) " + "SELECT id, gzip_to_zlib(unbase64(data)) " "FROM tmp", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; @@ -982,7 +1007,7 @@ return false; res = logged_sqlite3_exec(sql, "INSERT INTO file_deltas " - "SELECT id, base, unbase64(delta) " + "SELECT id, base, gzip_to_zlib(unbase64(delta)) " "FROM tmp", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; @@ -992,20 +1017,20 @@ return false; // migrate other contents which are accessed by get|put_version - res = logged_sqlite3_exec(sql, "UPDATE manifests SET data=unbase64(data)", + res = logged_sqlite3_exec(sql, "UPDATE manifests SET data=gzip_to_zlib(unbase64(data))", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; res = logged_sqlite3_exec(sql, "UPDATE manifest_deltas " - "SET delta=unbase64(delta)", NULL, NULL, errmsg); + "SET delta=gzip_to_zlib(unbase64(delta))", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; - res = logged_sqlite3_exec(sql, "UPDATE rosters SET data=unbase64(data) ", + res = logged_sqlite3_exec(sql, "UPDATE rosters SET data=gzip_to_zlib(unbase64(data)) ", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; res = logged_sqlite3_exec(sql, "UPDATE roster_deltas " - "SET delta=unbase64(delta)", NULL, NULL, errmsg); + "SET delta=gzip_to_zlib(unbase64(delta))", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; @@ -1028,7 +1053,7 @@ if (res != SQLITE_OK) return false; res = logged_sqlite3_exec(sql, "UPDATE revisions " - "SET data=unbase64(data)", NULL, NULL, errmsg); + "SET data=gzip_to_zlib(unbase64(data))", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; res = logged_sqlite3_exec(sql, "UPDATE branch_epochs " ============================================================ --- transforms.cc 1f17068bcfa0609f9962200eb33920168f10e7be +++ transforms.cc 6049875a935c0de87a6bb5f0c3d46f48cf091b10 @@ -18,6 +18,7 @@ #include "botan/botan.h" #include "botan/gzip.h" +#include "botan/zlib.h" #include "botan/sha160.h" #include "idna/idna.h" @@ -64,9 +65,16 @@ template string xform(string const & in) { string out; - Botan::Pipe pipe(new XFM()); - pipe.process_msg(in); - out = pipe.read_all_as_string(); + try + { + Botan::Pipe pipe(new XFM()); + pipe.process_msg(in); + out = pipe.read_all_as_string(); + } + catch (Botan::Exception & e) + { + throw informative_failure((FL("Failure transforming: %s") % e.what()).str());; + } return out; } @@ -75,7 +83,8 @@ template string xform(string const &); template string xform(string const &); template string xform(string const &); -template string xform(string const &); +template string xform(string const &); +template string xform(string const &); template string xform(string const &); // for use in hexenc encoding @@ -154,24 +163,24 @@ } template -void pack(T const & in, base64< gzip > & out) +void pack(T const & in, base64< zlib > & out) { string tmp; tmp.reserve(in().size()); // FIXME: do some benchmarking and make this a constant:: - Botan::Pipe pipe(new Botan::Gzip_Compression(), new Botan::Base64_Encoder); + Botan::Pipe pipe(new Botan::Zlib_Compression(), new Botan::Base64_Encoder); pipe.process_msg(in()); tmp = pipe.read_all_as_string(); out = tmp; } template -void unpack(base64< gzip > const & in, T & out) +void unpack(base64< zlib > const & in, T & out) { string tmp; tmp.reserve(in().size()); // FIXME: do some benchmarking and make this a constant:: - Botan::Pipe pipe(new Botan::Base64_Decoder(), new Botan::Gzip_Decompression()); + Botan::Pipe pipe(new Botan::Base64_Decoder(), new Botan::Zlib_Decompression()); pipe.process_msg(in()); tmp = pipe.read_all_as_string(); @@ -179,10 +188,10 @@ } // specialise them -template void pack(data const &, base64< gzip > &); -template void pack(delta const &, base64< gzip > &); -template void unpack(base64< gzip > const &, data &); -template void unpack(base64< gzip > const &, delta &); +template void pack(data const &, base64< zlib > &); +template void pack(delta const &, base64< zlib > &); +template void unpack(base64< zlib > const &, data &); +template void unpack(base64< zlib > const &, delta &); // diffing and patching @@ -220,13 +229,13 @@ } void -calculate_ident(base64< gzip > const & dat, +calculate_ident(base64< zlib > const & dat, hexenc & ident) { - gzip data_decoded; + zlib data_decoded; data data_decompressed; decode_base64(dat, data_decoded); - decode_gzip(data_decoded, data_decompressed); + decode_zlib(data_decoded, data_decompressed); calculate_ident(data_decompressed, ident); } @@ -798,13 +807,13 @@ enc_test() { data d2, d1("the rain in spain"); - gzip gzd1, gzd2; - base64< gzip > bgzd; - encode_gzip(d1, gzd1); + zlib gzd1, gzd2; + base64< zlib > bgzd; + encode_zlib(d1, gzd1); encode_base64(gzd1, bgzd); decode_base64(bgzd, gzd2); BOOST_CHECK(gzd2 == gzd1); - decode_gzip(gzd2, d2); + decode_zlib(gzd2, d2); BOOST_CHECK(d2 == d1); } ============================================================ --- transforms.hh 20649bff0b21dec65062baa1de4b11ab1f05d950 +++ transforms.hh 15778b0b0621946b1168d06670c137b4513e609b @@ -23,7 +23,8 @@ class Base64_Decoder; class Hex_Encoder; class Hex_Decoder; - class Gzip_Compression; + class Zlib_Compression; + class Zlib_Decompression; class Gzip_Decompression; } @@ -38,7 +39,8 @@ EXTERN template std::string xform(std::string const &); EXTERN template std::string xform(std::string const &); EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); +EXTERN template std::string xform(std::string const &); +EXTERN template std::string xform(std::string const &); EXTERN template std::string xform(std::string const &); // base64 encoding @@ -69,32 +71,38 @@ { out = encode_hexenc(in()); } -// gzip +// zlib template -void encode_gzip(T const & in, gzip & out) -{ out = xform(in()); } +void encode_zlib(T const & in, zlib & out) +{ out = xform(in()); } template +void decode_zlib(zlib const & in, T & out) +{ out = xform(in()); } + +// gzip, for migration + +template void decode_gzip(gzip const & in, T & out) { out = xform(in()); } // string variant for netsync template -void encode_gzip(std::string const & in, gzip & out) -{ out = xform(in); } +void encode_zlib(std::string const & in, zlib & out) +{ out = xform(in); } // both at once (this is relatively common) template -void pack(T const & in, base64< gzip > & out); -EXTERN template void pack(data const &, base64< gzip > &); -EXTERN template void pack(delta const &, base64< gzip > &); +void pack(T const & in, base64< zlib > & out); +EXTERN template void pack(data const &, base64< zlib > &); +EXTERN template void pack(delta const &, base64< zlib > &); template -void unpack(base64< gzip > const & in, T & out); -EXTERN template void unpack(base64< gzip > const &, data &); -EXTERN template void unpack(base64< gzip > const &, delta &); +void unpack(base64< zlib > const & in, T & out); +EXTERN template void unpack(base64< zlib > const &, data &); +EXTERN template void unpack(base64< zlib > const &, delta &); // diffing and patching @@ -113,7 +121,7 @@ void calculate_ident(data const & dat, hexenc & ident); -void calculate_ident(base64< gzip > const & dat, +void calculate_ident(base64< zlib > const & dat, hexenc & ident); void calculate_ident(file_data const & dat, ============================================================ --- vocab_terms.hh 3e28281bce1cc56b544dd17c356ba139f9bd5e22 +++ vocab_terms.hh 1cd89c8f6b40cab5c80be3861faa0f69fc319d70 @@ -47,7 +47,8 @@ DECORATE(key); // thing associated with a key DECORATE(epoch); // thing associated with an epoch -ENCODING(gzip); // thing which is gzipped +ENCODING(zlib); // thing which is zlibbed +ENCODING(gzip); // thing which is gzipped (for migration) ENCODING(hexenc); // thing which is hex-encoded ENCODING(base64); // thing which is base64-encoded ENCODING(arc4); // thing which is arc4-encrypted @@ -69,15 +70,18 @@ EXTERN template class hexenc; EXTERN template class epoch< hexenc >; +EXTERN template class zlib; +EXTERN template class base64< zlib >; + +// for migration EXTERN template class gzip; -EXTERN template class base64< gzip >; EXTERN template class revision< data >; EXTERN template class manifest< data >; EXTERN template class file< data >; -EXTERN template class gzip; -EXTERN template class base64< gzip >; +EXTERN template class zlib; +EXTERN template class base64< zlib >; EXTERN template class manifest< delta >; EXTERN template class file< delta >; @@ -111,16 +115,16 @@ EXTERN template std::ostream & operator<< <>(std::ostream &, hexenc const &); EXTERN template std::ostream & operator<< <>(std::ostream &, epoch< hexenc > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, gzip const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, base64< gzip > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, revision< base64< gzip > > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, manifest< base64< gzip > > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, file< base64< gzip > > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, zlib const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, base64< zlib > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, revision< base64< zlib > > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, manifest< base64< zlib > > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, file< base64< zlib > > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, gzip const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, base64< gzip > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, manifest< base64< gzip > > const &); -EXTERN template std::ostream & operator<< <>(std::ostream &, file< base64< gzip > > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, zlib const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, base64< zlib > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, manifest< base64< zlib > > const &); +EXTERN template std::ostream & operator<< <>(std::ostream &, file< base64< zlib > > const &); EXTERN template std::ostream & operator<< <>(std::ostream &, arc4 const &); EXTERN template std::ostream & operator<< <>(std::ostream &, base64< arc4 > const &);