2007-12-12 22:09:01 +01:00
|
|
|
/* Copyright (c) 2003, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 21:13:17 +01:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2004-09-02 20:22:51 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
2017-04-18 03:21:53 +02:00
|
|
|
* \file compress.h
|
|
|
|
* \brief Headers for compress.c
|
2004-09-02 20:22:51 +02:00
|
|
|
**/
|
|
|
|
|
2017-04-18 03:21:53 +02:00
|
|
|
#ifndef TOR_COMPRESS_H
|
|
|
|
#define TOR_COMPRESS_H
|
2004-09-02 20:22:51 +02:00
|
|
|
|
2017-04-17 14:11:35 +02:00
|
|
|
/** Enumeration of what kind of compression to use. Only ZLIB_METHOD and
|
|
|
|
* GZIP_METHOD is guaranteed to be supported by the compress/uncompress
|
2017-04-20 15:56:38 +02:00
|
|
|
* functions here. Call tor_compress_supports_method() to check if a given
|
|
|
|
* compression schema is supported by Tor. */
|
2005-01-19 23:40:33 +01:00
|
|
|
typedef enum {
|
2017-04-27 17:30:51 +02:00
|
|
|
NO_METHOD=0, // This method must be first.
|
2017-04-18 14:30:44 +02:00
|
|
|
GZIP_METHOD=1,
|
|
|
|
ZLIB_METHOD=2,
|
|
|
|
LZMA_METHOD=3,
|
2017-04-18 22:19:29 +02:00
|
|
|
ZSTD_METHOD=4,
|
2017-04-27 17:30:51 +02:00
|
|
|
UNKNOWN_METHOD=5, // This method must be last. Add new ones in the middle.
|
2005-01-19 23:40:33 +01:00
|
|
|
} compress_method_t;
|
2004-09-02 20:22:51 +02:00
|
|
|
|
2014-11-17 17:43:50 +01:00
|
|
|
/**
|
|
|
|
* Enumeration to define tradeoffs between memory usage and compression level.
|
2017-04-25 15:54:02 +02:00
|
|
|
* BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
|
2014-11-17 17:43:50 +01:00
|
|
|
* memory.
|
|
|
|
**/
|
|
|
|
typedef enum {
|
2017-04-25 15:54:02 +02:00
|
|
|
BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
|
2017-04-17 14:22:13 +02:00
|
|
|
} compression_level_t;
|
2014-11-17 17:43:50 +01:00
|
|
|
|
2017-04-25 03:36:30 +02:00
|
|
|
int tor_compress(char **out, size_t *out_len,
|
|
|
|
const char *in, size_t in_len,
|
|
|
|
compress_method_t method);
|
|
|
|
|
|
|
|
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);
|
2004-09-02 20:22:51 +02:00
|
|
|
|
2006-10-09 04:35:51 +02:00
|
|
|
compress_method_t detect_compression_method(const char *in, size_t in_len);
|
2005-01-19 23:40:33 +01:00
|
|
|
|
2017-09-28 18:20:02 +02:00
|
|
|
MOCK_DECL(int,tor_compress_is_compression_bomb,(size_t size_in,
|
|
|
|
size_t size_out));
|
2017-04-18 03:12:19 +02:00
|
|
|
|
2017-04-25 03:36:30 +02:00
|
|
|
int tor_compress_supports_method(compress_method_t method);
|
2017-04-27 17:30:51 +02:00
|
|
|
unsigned tor_compress_get_supported_method_bitmask(void);
|
2017-05-17 14:48:16 +02:00
|
|
|
const char *compression_method_get_name(compress_method_t method);
|
2017-05-12 12:45:00 +02:00
|
|
|
const char *compression_method_get_human_name(compress_method_t method);
|
2017-04-25 20:51:44 +02:00
|
|
|
compress_method_t compression_method_get_by_name(const char *name);
|
2017-04-20 16:20:14 +02:00
|
|
|
|
2017-04-25 03:36:30 +02:00
|
|
|
const char *tor_compress_version_str(compress_method_t method);
|
2017-04-20 16:20:14 +02:00
|
|
|
|
2017-04-25 03:36:30 +02:00
|
|
|
const char *tor_compress_header_version_str(compress_method_t method);
|
2017-04-20 15:56:38 +02:00
|
|
|
|
2017-04-25 03:36:30 +02:00
|
|
|
size_t tor_compress_get_total_allocation(void);
|
2017-04-20 15:33:13 +02:00
|
|
|
|
2017-04-17 14:57:37 +02:00
|
|
|
/** Return values from tor_compress_process; see that function's documentation
|
|
|
|
* for details. */
|
2006-06-18 09:24:29 +02:00
|
|
|
typedef enum {
|
2017-04-17 14:57:37 +02:00
|
|
|
TOR_COMPRESS_OK,
|
|
|
|
TOR_COMPRESS_DONE,
|
|
|
|
TOR_COMPRESS_BUFFER_FULL,
|
|
|
|
TOR_COMPRESS_ERROR
|
|
|
|
} tor_compress_output_t;
|
2017-04-18 03:14:36 +02:00
|
|
|
|
|
|
|
/** Internal state for an incremental compression/decompression. */
|
2017-04-17 14:57:37 +02:00
|
|
|
typedef struct tor_compress_state_t tor_compress_state_t;
|
2017-04-18 03:14:36 +02:00
|
|
|
|
2017-04-17 14:57:37 +02:00
|
|
|
tor_compress_state_t *tor_compress_new(int compress,
|
|
|
|
compress_method_t method,
|
|
|
|
compression_level_t level);
|
2006-06-18 09:24:29 +02:00
|
|
|
|
2017-04-17 14:57:37 +02:00
|
|
|
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);
|
2017-11-17 18:27:25 +01:00
|
|
|
void tor_compress_free_(tor_compress_state_t *state);
|
2017-12-04 21:09:18 +01:00
|
|
|
#define tor_compress_free(st) \
|
2017-12-07 16:44:04 +01:00
|
|
|
FREE_AND_NULL(tor_compress_state_t, tor_compress_free_, (st))
|
2006-06-18 09:24:29 +02:00
|
|
|
|
2017-04-17 14:57:37 +02:00
|
|
|
size_t tor_compress_state_size(const tor_compress_state_t *state);
|
2014-08-19 16:59:15 +02:00
|
|
|
|
2017-04-25 16:29:07 +02:00
|
|
|
void tor_compress_init(void);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_COMPRESS_H) */
|
2005-06-09 21:03:31 +02:00
|
|
|
|