#include #include #include #include "../config.h" #include "compression.h" #include "logging.h" static void zlib_err(int status) { switch (status) { case Z_OK: case Z_STREAM_END: break; case Z_MEM_ERROR: err(1, "zlib error: out of memory"); break; case Z_VERSION_ERROR: err(1, "zlib error: incompatible library version"); break; case Z_STREAM_ERROR: err(1, "zlib error: invalid stream"); break; case Z_NEED_DICT: err(1, "zlib error: need dictionary"); break; case Z_DATA_ERROR: err(1, "zlib error: corrupted data"); break; case Z_BUF_ERROR: err(1, "zlib error: buffer error"); break; default: err(1, "zlib error: unknown"); break; } } void decompress(char *src, size_t src_len, char *dest, size_t dest_len) { z_stream d_stream; d_stream.zalloc = Z_NULL; d_stream.zfree = Z_NULL; d_stream.opaque = Z_NULL; d_stream.next_in = (Bytef *) src; d_stream.avail_in = src_len; d_stream.next_out = (Bytef *) dest; d_stream.avail_out = dest_len; #ifdef DEBUG_COMPRESSION debug("Initializing inflation stream..."); #endif zlib_err(inflateInit2(&d_stream, 15 + 32)); #ifdef DEBUG_COMPRESSION debug("Inflating %d bytes into up to %d bytes...", src_len, dest_len); #endif zlib_err(inflate(&d_stream, Z_NO_FLUSH)); #ifdef DEBUG_COMPRESSION debug("Ending inflation stream..."); #endif zlib_err(inflateEnd(&d_stream)); } #if 0 #include #include "base64.h" int main() { char decoded_data[4801], compressed_data[4801], decompressed_data[4801]; base64_decode( "TwAAAFAAAABPAAAAUAAAAE8AAABQAAAATwAAAFAAAABPAAAA" "UAAAAE8AAABQAAAATwAAAFAAAAAcAAAAHQAAAB0AAAAeAAAA" "TwAAAFAAAABPAAAAUAAAAE8AAABQAAAATwAAAFAAAABPAAAA" "UAAAAE8AAABQAAAAXwAAAGAAAABfAAAAYAAAAF8AAABgAAAA" "XwAAAGAAAABfAAAAYAAAAF8AAABgAAAAXwAAAGAAAAAcAAAA" "HQAAAB0AAAAeAAAAXwAAAGAAAABfAAAAYAAAAF8AAABgAAAA" "XwAAAGAAAABfAAAAYAAAAF8AAABgAAAATwAAAFAAAABPAAAA" "UAAA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BE/+XRPrA+jeVu8qA97PvYM8qI+7NW5t876sFfn3jrbpxW8" "kT7tvN/zPsT3IG++YnhRZfEyeVnek9g9G5E1X0V5s2OUNzt2" "3hre5f/t9XcFHzJvZL4nMm9k8k7i9/da9bsGb+Q/+zfeGUt8" "RgE=", compressed_data, 4801); decompress(compressed_data, decompressed_data, 4801); decoded_data[4800] = '\0'; compressed_data[4800] = '\0'; decompressed_data[4800] = '\0'; if (strncmp(decoded_data, decompressed_data, 4800) == 0) { puts("Matched!"); } else { puts("No match. :("); } return 0; } #endif