Tor  0.4.7.0-alpha-dev
compress.h
Go to the documentation of this file.
1 /* Copyright (c) 2003, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file compress.h
8  * \brief Headers for compress.c
9  **/
10 
11 #ifndef TOR_COMPRESS_H
12 #define TOR_COMPRESS_H
13 
14 #include <stddef.h>
16 
17 /** Enumeration of what kind of compression to use. Only ZLIB_METHOD and
18  * GZIP_METHOD is guaranteed to be supported by the compress/uncompress
19  * functions here. Call tor_compress_supports_method() to check if a given
20  * compression schema is supported by Tor. */
21 typedef enum compress_method_t {
22  NO_METHOD=0, // This method must be first.
23  GZIP_METHOD=1,
24  ZLIB_METHOD=2,
25  LZMA_METHOD=3,
26  ZSTD_METHOD=4,
27  UNKNOWN_METHOD=5, // This method must be last. Add new ones in the middle.
29 
30 /**
31  * Enumeration to define tradeoffs between memory usage and compression level.
32  * BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
33  * memory.
34  **/
35 typedef enum compression_level_t {
36  BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
38 
39 int tor_compress(char **out, size_t *out_len,
40  const char *in, size_t in_len,
41  compress_method_t method);
42 
43 int tor_uncompress(char **out, size_t *out_len,
44  const char *in, size_t in_len,
45  compress_method_t method,
46  int complete_only,
47  int protocol_warn_level);
48 
49 compress_method_t detect_compression_method(const char *in, size_t in_len);
50 
52  size_t size_out));
53 
59 
61 
63 
65 
66 /** Return values from tor_compress_process; see that function's documentation
67  * for details. */
68 typedef enum {
69  TOR_COMPRESS_OK,
70  TOR_COMPRESS_DONE,
71  TOR_COMPRESS_BUFFER_FULL,
72  TOR_COMPRESS_ERROR
74 
75 /** Internal state for an incremental compression/decompression. */
77 
80  compression_level_t level);
81 
83  char **out, size_t *out_len,
84  const char **in, size_t *in_len,
85  int finish);
87 #define tor_compress_free(st) \
88  FREE_AND_NULL(tor_compress_state_t, tor_compress_free_, (st))
89 
91 
92 int tor_compress_init(void);
94 
95 struct buf_t;
96 int buf_add_compress(struct buf_t *buf, struct tor_compress_state_t *state,
97  const char *data, size_t data_len, int done);
98 
99 #endif /* !defined(TOR_COMPRESS_H) */
int tor_compress_init(void)
Definition: compress.c:666
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)
Definition: compress.c:549
tor_compress_state_t * tor_compress_new(int compress, compress_method_t method, compression_level_t level)
Definition: compress.c:481
int tor_compress_supports_method(compress_method_t method)
Definition: compress.c:304
compress_method_t compression_method_get_by_name(const char *name)
Definition: compress.c:403
int tor_compress_is_compression_bomb(size_t size_in, size_t size_out)
Definition: compress.c:64
const char * compression_method_get_name(compress_method_t method)
Definition: compress.c:364
void tor_compress_free_(tor_compress_state_t *state)
Definition: compress.c:610
tor_compress_output_t
Definition: compress.h:68
const char * tor_compress_header_version_str(compress_method_t method)
Definition: compress.c:438
const char * compression_method_get_human_name(compress_method_t method)
Definition: compress.c:390
unsigned tor_compress_get_supported_method_bitmask(void)
Definition: compress.c:328
size_t tor_compress_state_size(const tor_compress_state_t *state)
Definition: compress.c:639
compress_method_t
Definition: compress.h:21
compression_level_t
Definition: compress.h:35
void tor_compress_log_init_warnings(void)
Definition: compress.c:682
int tor_compress(char **out, size_t *out_len, const char *in, size_t in_len, compress_method_t method)
Definition: compress.c:242
const char * tor_compress_version_str(compress_method_t method)
Definition: compress.c:417
int buf_add_compress(struct buf_t *buf, struct tor_compress_state_t *state, const char *data, size_t data_len, int done)
Definition: compress_buf.c:31
compress_method_t detect_compression_method(const char *in, size_t in_len)
Definition: compress.c:284
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)
Definition: compress.c:268
size_t tor_compress_get_total_allocation(void)
Definition: compress.c:458
const char * name
Definition: config.c:2434
compress_method_t method
Definition: compress.c:469
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127