Tor
0.4.7.0-alpha-dev
|
Headers for compress.c. More...
Go to the source code of this file.
Macros | |
#define | tor_compress_free(st) FREE_AND_NULL(tor_compress_state_t, tor_compress_free_, (st)) |
Enumerations | |
enum | compress_method_t { NO_METHOD =0 , GZIP_METHOD =1 , ZLIB_METHOD =2 , LZMA_METHOD =3 , ZSTD_METHOD =4 , UNKNOWN_METHOD =5 } |
enum | compression_level_t { BEST_COMPRESSION , HIGH_COMPRESSION , MEDIUM_COMPRESSION , LOW_COMPRESSION } |
enum | tor_compress_output_t { TOR_COMPRESS_OK , TOR_COMPRESS_DONE , TOR_COMPRESS_BUFFER_FULL , TOR_COMPRESS_ERROR } |
Headers for compress.c.
Definition in file compress.h.
enum compress_method_t |
Enumeration of what kind of compression to use. Only ZLIB_METHOD and GZIP_METHOD is guaranteed to be supported by the compress/uncompress functions here. Call tor_compress_supports_method() to check if a given compression schema is supported by Tor.
Definition at line 21 of file compress.h.
enum compression_level_t |
Enumeration to define tradeoffs between memory usage and compression level. BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most memory.
Definition at line 35 of file compress.h.
Return values from tor_compress_process; see that function's documentation for details.
Definition at line 68 of file compress.h.
int buf_add_compress | ( | buf_t * | buf, |
tor_compress_state_t * | state, | ||
const char * | data, | ||
size_t | data_len, | ||
const int | done | ||
) |
Compress or uncompress the data_len bytes in data using the compression state state, appending the result to buf. If done is true, flush the data in the state and finish the compression/uncompression. Return -1 on failure, 0 on success.
Definition at line 31 of file compress_buf.c.
Referenced by connection_write_to_buf_impl_().
compress_method_t compression_method_get_by_name | ( | const char * | name | ) |
Return the compression method represented by the string name, or UNKNOWN_METHOD if the string isn't recognized.
Definition at line 403 of file compress.c.
const char* compression_method_get_human_name | ( | compress_method_t | method | ) |
Return a human readable string representation of the compression method method, or NULL if the method isn't recognized.
Definition at line 390 of file compress.c.
const char* compression_method_get_name | ( | compress_method_t | method | ) |
Return the canonical string representation of the compression method method, or NULL if the method isn't recognized.
Definition at line 364 of file compress.c.
Referenced by consdiffmgr_rescan_flavor_().
compress_method_t detect_compression_method | ( | const char * | in, |
size_t | in_len | ||
) |
Try to tell whether the in_len-byte string in in is likely to be compressed or not. If it is, return the likeliest compression method. Otherwise, return UNKNOWN_METHOD.
Definition at line 284 of file compress.c.
int tor_compress | ( | char ** | out, |
size_t * | out_len, | ||
const char * | in, | ||
size_t | in_len, | ||
compress_method_t | method | ||
) |
Given in_len bytes at in, compress them into a newly allocated buffer, using the method described in method. Store the compressed string in *out, and its length in *out_len. Return 0 on success, -1 on failure.
Definition at line 242 of file compress.c.
void tor_compress_free_ | ( | tor_compress_state_t * | state | ) |
Deallocate state.
Definition at line 610 of file compress.c.
unsigned tor_compress_get_supported_method_bitmask | ( | void | ) |
Return a bitmask of the supported compression types, where 1<<m is set in the bitmask if and only if compression with method m is supported.
Definition at line 328 of file compress.c.
size_t tor_compress_get_total_allocation | ( | void | ) |
Return the approximate number of bytes allocated for all supported compression schemas.
Definition at line 458 of file compress.c.
const char* tor_compress_header_version_str | ( | compress_method_t | method | ) |
Return a string representation of the version of the library, found at compile time, providing the compression method given in method. Returns NULL if method is unknown or unsupported.
Definition at line 438 of file compress.c.
int tor_compress_init | ( | void | ) |
Initialize all compression modules.
Definition at line 666 of file compress.c.
int tor_compress_is_compression_bomb | ( | size_t | size_in, |
size_t | size_out | ||
) |
Return true if uncompressing an input of size in_size to an input of size at least size_out looks like a compression bomb.
Definition at line 64 of file compress.c.
Referenced by tor_lzma_compress_process().
void tor_compress_log_init_warnings | ( | void | ) |
Warn if we had any problems while setting up our compression libraries.
(This isn't part of tor_compress_init, since the logs aren't set up yet.)
Definition at line 682 of file compress.c.
tor_compress_state_t* tor_compress_new | ( | int | compress, |
compress_method_t | method, | ||
compression_level_t | compression_level | ||
) |
Construct and return a tor_compress_state_t object using method. If compress, it's for compression; otherwise it's for decompression.
Definition at line 481 of file compress.c.
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 | ||
) |
Compress/decompress some bytes using state. Read up to *in_len bytes from *in, and write up to *out_len bytes to *out, adjusting the values as we go. If finish is true, we've reached the end of the input.
Return TOR_COMPRESS_DONE if we've finished the entire compression/decompression. Return TOR_COMPRESS_OK if we're processed everything from the input. Return TOR_COMPRESS_BUFFER_FULL if we're out of space on out. Return TOR_COMPRESS_ERROR if the stream is corrupt.
Definition at line 549 of file compress.c.
Referenced by buf_add_compress().
size_t tor_compress_state_size | ( | const tor_compress_state_t * | state | ) |
Return the approximate number of bytes allocated for state.
Definition at line 639 of file compress.c.
int tor_compress_supports_method | ( | compress_method_t | method | ) |
Return 1 if a given method is supported; otherwise 0.
Definition at line 304 of file compress.c.
Referenced by options_init_from_torrc().
const char* tor_compress_version_str | ( | compress_method_t | method | ) |
Return a string representation of the version of the library providing the compression method given in method. Returns NULL if method is unknown or unsupported.
Definition at line 417 of file compress.c.
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 | ||
) |
Given zero or more compressed strings of total length in_len bytes at in, uncompress them into a newly allocated buffer, using the method described in method. Store the uncompressed string in *out, and its length in *out_len. Return 0 on success, -1 on failure.
If any bytes are written to out, an extra byte NUL is always written at the end, but not counted in out_len. This is a safety feature to ensure that the output can be treated as a NUL-terminated string – though of course, callers should check out_len anyway.
If complete_only is true, we consider a truncated input as a failure; otherwise we decompress as much as we can. Warn about truncated or corrupt inputs at protocol_warn_level.
Definition at line 268 of file compress.c.