Tor 0.4.9.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. */
21typedef 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 **/
35typedef enum compression_level_t {
36 BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
38
39int tor_compress(char **out, size_t *out_len,
40 const char *in, size_t in_len,
41 compress_method_t method);
42
43int 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
49compress_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. */
68typedef 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
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
92int tor_compress_init(void);
94
95struct buf_t;
96int 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:425
int tor_compress_init(void)
Definition: compress.c:674
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:557
int tor_compress_supports_method(compress_method_t method)
Definition: compress.c:312
compress_method_t compression_method_get_by_name(const char *name)
Definition: compress.c:411
int tor_compress_is_compression_bomb(size_t size_in, size_t size_out)
Definition: compress.c:64
tor_compress_state_t * tor_compress_new(int compress, compress_method_t method, compression_level_t level)
Definition: compress.c:489
const char * tor_compress_header_version_str(compress_method_t method)
Definition: compress.c:446
void tor_compress_free_(tor_compress_state_t *state)
Definition: compress.c:618
tor_compress_output_t
Definition: compress.h:68
unsigned tor_compress_get_supported_method_bitmask(void)
Definition: compress.c:336
size_t tor_compress_state_size(const tor_compress_state_t *state)
Definition: compress.c:647
compress_method_t
Definition: compress.h:21
compression_level_t
Definition: compress.h:35
void tor_compress_log_init_warnings(void)
Definition: compress.c:690
int tor_compress(char **out, size_t *out_len, const char *in, size_t in_len, compress_method_t method)
Definition: compress.c:250
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:292
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:276
const char * compression_method_get_name(compress_method_t method)
Definition: compress.c:372
size_t tor_compress_get_total_allocation(void)
Definition: compress.c:466
const char * compression_method_get_human_name(compress_method_t method)
Definition: compress.c:398
const char * name
Definition: config.c:2462
compress_method_t method
Definition: compress.c:477
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127