tor  0.4.1.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-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
11 #ifndef TOR_COMPRESS_H
12 #define TOR_COMPRESS_H
13 
14 #include <stddef.h>
16 
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 
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 
51 MOCK_DECL(int,tor_compress_is_compression_bomb,(size_t size_in,
52  size_t size_out));
53 
59 
61 
63 
65 
68 typedef enum {
69  TOR_COMPRESS_OK,
70  TOR_COMPRESS_DONE,
71  TOR_COMPRESS_BUFFER_FULL,
72  TOR_COMPRESS_ERROR
74 
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) */
const char * tor_compress_version_str(compress_method_t method)
Definition: compress.c:417
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
compress_method_t method
Definition: compress.c:469
size_t tor_compress_get_total_allocation(void)
Definition: compress.c:458
unsigned tor_compress_get_supported_method_bitmask(void)
Definition: compress.c:328
int tor_compress_supports_method(compress_method_t method)
Definition: compress.c:304
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 * compression_method_get_human_name(compress_method_t method)
Definition: compress.c:390
compress_method_t detect_compression_method(const char *in, size_t in_len)
Definition: compress.c:284
void tor_compress_log_init_warnings(void)
Definition: compress.c:682
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
size_t tor_compress_state_size(const tor_compress_state_t *state)
Definition: compress.c:639
void tor_compress_free_(tor_compress_state_t *state)
Definition: compress.c:610
int tor_compress_init(void)
Definition: compress.c:666
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
compress_method_t compression_method_get_by_name(const char *name)
Definition: compress.c:403
const char * tor_compress_header_version_str(compress_method_t method)
Definition: compress.c:438
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
compression_level_t
Definition: compress.h:35
const char * compression_method_get_name(compress_method_t method)
Definition: compress.c:364
compress_method_t
Definition: compress.h:21
tor_compress_output_t
Definition: compress.h:68