Fix whitespace issue.
[tor.git] / src / common / compress.h
blob59c8b7b9b562d60f1820cdfb1fa64808e7f29692
1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2017, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 /**
7 * \file compress.h
8 * \brief Headers for compress.c
9 **/
11 #ifndef TOR_COMPRESS_H
12 #define TOR_COMPRESS_H
14 /** Enumeration of what kind of compression to use. Only ZLIB_METHOD and
15 * GZIP_METHOD is guaranteed to be supported by the compress/uncompress
16 * functions here. Call tor_compress_supports_method() to check if a given
17 * compression schema is supported by Tor. */
18 typedef enum {
19 NO_METHOD=0, // This method must be first.
20 GZIP_METHOD=1,
21 ZLIB_METHOD=2,
22 LZMA_METHOD=3,
23 ZSTD_METHOD=4,
24 UNKNOWN_METHOD=5, // This method must be last. Add new ones in the middle.
25 } compress_method_t;
27 /**
28 * Enumeration to define tradeoffs between memory usage and compression level.
29 * BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
30 * memory.
31 **/
32 typedef enum {
33 BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
34 } compression_level_t;
36 int tor_compress(char **out, size_t *out_len,
37 const char *in, size_t in_len,
38 compress_method_t method);
40 int tor_uncompress(char **out, size_t *out_len,
41 const char *in, size_t in_len,
42 compress_method_t method,
43 int complete_only,
44 int protocol_warn_level);
46 compress_method_t detect_compression_method(const char *in, size_t in_len);
48 int tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
50 int tor_compress_supports_method(compress_method_t method);
51 unsigned tor_compress_get_supported_method_bitmask(void);
52 const char *compression_method_get_name(compress_method_t method);
53 const char *compression_method_get_human_name(compress_method_t method);
54 compress_method_t compression_method_get_by_name(const char *name);
56 const char *tor_compress_version_str(compress_method_t method);
58 const char *tor_compress_header_version_str(compress_method_t method);
60 size_t tor_compress_get_total_allocation(void);
62 /** Return values from tor_compress_process; see that function's documentation
63 * for details. */
64 typedef enum {
65 TOR_COMPRESS_OK,
66 TOR_COMPRESS_DONE,
67 TOR_COMPRESS_BUFFER_FULL,
68 TOR_COMPRESS_ERROR
69 } tor_compress_output_t;
71 /** Internal state for an incremental compression/decompression. */
72 typedef struct tor_compress_state_t tor_compress_state_t;
74 tor_compress_state_t *tor_compress_new(int compress,
75 compress_method_t method,
76 compression_level_t level);
78 tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
79 char **out, size_t *out_len,
80 const char **in, size_t *in_len,
81 int finish);
82 void tor_compress_free(tor_compress_state_t *state);
84 size_t tor_compress_state_size(const tor_compress_state_t *state);
86 void tor_compress_init(void);
88 #endif // TOR_COMPRESS_H.