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 */
8 * \brief Headers for compress.c
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. */
19 NO_METHOD
=0, // This method must be first.
24 UNKNOWN_METHOD
=5, // This method must be last. Add new ones in the middle.
28 * Enumeration to define tradeoffs between memory usage and compression level.
29 * BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
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
,
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
67 TOR_COMPRESS_BUFFER_FULL
,
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
,
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.