diff options
author | Alexander Færøy <ahf@torproject.org> | 2017-04-18 03:21:53 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-25 08:06:01 -0400 |
commit | 04583df4520705bc171be9b720344167029292cb (patch) | |
tree | 21d5ce9cfe8eac60cf07e877e038d3a6becb5fee /src/common/compress.h | |
parent | 9d5bc1a9354637aa59025f61e577c6d42f8c53ba (diff) | |
download | tor-04583df4520705bc171be9b720344167029292cb.tar.gz tor-04583df4520705bc171be9b720344167029292cb.zip |
Rename the `torgzip` module to `compress`.
See https://bugs.torproject.org/21663
Diffstat (limited to 'src/common/compress.h')
-rw-r--r-- | src/common/compress.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/common/compress.h b/src/common/compress.h new file mode 100644 index 0000000000..c347e1c184 --- /dev/null +++ b/src/common/compress.h @@ -0,0 +1,74 @@ +/* Copyright (c) 2003, Roger Dingledine + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file compress.h + * \brief Headers for compress.c + **/ + +#ifndef TOR_COMPRESS_H +#define TOR_COMPRESS_H + +/** Enumeration of what kind of compression to use. Only ZLIB_METHOD and + * GZIP_METHOD is guaranteed to be supported by the compress/uncompress + * functions here. */ +typedef enum { + NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3 +} compress_method_t; + +/** + * Enumeration to define tradeoffs between memory usage and compression level. + * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most + * memory. + **/ +typedef enum { + HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION +} compression_level_t; + +int +tor_compress(char **out, size_t *out_len, + const char *in, size_t in_len, + compress_method_t method); +int +tor_uncompress(char **out, size_t *out_len, + const char *in, size_t in_len, + compress_method_t method, + int complete_only, + int protocol_warn_level); + +compress_method_t detect_compression_method(const char *in, size_t in_len); + +int +tor_compress_memory_level(compression_level_t level); + +int +tor_compress_is_compression_bomb(size_t size_in, size_t size_out); + +/** Return values from tor_compress_process; see that function's documentation + * for details. */ +typedef enum { + TOR_COMPRESS_OK, + TOR_COMPRESS_DONE, + TOR_COMPRESS_BUFFER_FULL, + TOR_COMPRESS_ERROR +} tor_compress_output_t; + +/** Internal state for an incremental compression/decompression. */ +typedef struct tor_compress_state_t tor_compress_state_t; + +tor_compress_state_t *tor_compress_new(int compress, + compress_method_t method, + compression_level_t level); + +tor_compress_output_t tor_compress_process(tor_compress_state_t *state, + char **out, size_t *out_len, + const char **in, size_t *in_len, + int finish); +void tor_compress_free(tor_compress_state_t *state); + +size_t tor_compress_state_size(const tor_compress_state_t *state); + +#endif // TOR_COMPRESS_H. + |