Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Functions | Variables
compress_zlib.c File Reference

Compression backend for gzip and zlib. More...

#include "orconfig.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/compress/compress.h"
#include "lib/compress/compress_zlib.h"
#include "lib/thread/threads.h"
#include <zlib.h>

Go to the source code of this file.

Data Structures

struct  tor_zlib_compress_state_t
 

Macros

#define _LARGEFILE64_SOURCE   0
 
#define _LFS64_LARGEFILE   0
 
#define _FILE_OFFSET_BITS   0
 
#define off64_t   int64_t
 
#define A_FEW_KILOBYTES   2048
 

Functions

static size_t tor_zlib_state_size_precalc (int inflate, int windowbits, int memlevel)
 
static int memory_level (compression_level_t level)
 
static int method_bits (compress_method_t method, compression_level_t level)
 
int tor_zlib_method_supported (void)
 
const char * tor_zlib_get_version_str (void)
 
const char * tor_zlib_get_header_version_str (void)
 
tor_zlib_compress_state_ttor_zlib_compress_new (int compress_, compress_method_t method, compression_level_t compression_level)
 
tor_compress_output_t tor_zlib_compress_process (tor_zlib_compress_state_t *state, char **out, size_t *out_len, const char **in, size_t *in_len, int finish)
 
void tor_zlib_compress_free_ (tor_zlib_compress_state_t *state)
 
size_t tor_zlib_compress_state_size (const tor_zlib_compress_state_t *state)
 
size_t tor_zlib_get_total_allocation (void)
 
void tor_zlib_init (void)
 

Variables

static atomic_counter_t total_zlib_allocation
 

Detailed Description

Compression backend for gzip and zlib.

This module should never be invoked directly. Use the compress module instead.

Definition in file compress_zlib.c.

Function Documentation

◆ memory_level()

static int memory_level ( compression_level_t  level)
static

Given level return the memory level.

Definition at line 56 of file compress_zlib.c.

◆ method_bits()

static int method_bits ( compress_method_t  method,
compression_level_t  level 
)
inlinestatic

Return the 'bits' value to tell zlib to use method.

Definition at line 69 of file compress_zlib.c.

◆ tor_zlib_compress_free_()

void tor_zlib_compress_free_ ( tor_zlib_compress_state_t state)

Deallocate state.

Definition at line 269 of file compress_zlib.c.

◆ tor_zlib_compress_new()

tor_zlib_compress_state_t* tor_zlib_compress_new ( int  compress_,
compress_method_t  method,
compression_level_t  compression_level 
)

Construct and return a tor_zlib_compress_state_t object using method. If compress, it's for compression; otherwise it's for decompression.

Definition at line 158 of file compress_zlib.c.

◆ tor_zlib_compress_process()

tor_compress_output_t tor_zlib_compress_process ( tor_zlib_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 210 of file compress_zlib.c.

◆ tor_zlib_compress_state_size()

size_t tor_zlib_compress_state_size ( const tor_zlib_compress_state_t state)

Return the approximate number of bytes allocated for state.

Definition at line 286 of file compress_zlib.c.

◆ tor_zlib_get_header_version_str()

const char* tor_zlib_get_header_version_str ( void  )

Return a string representation of the version of the version of zlib used at compilation.

Definition at line 103 of file compress_zlib.c.

◆ tor_zlib_get_total_allocation()

size_t tor_zlib_get_total_allocation ( void  )

Return the approximate number of bytes allocated for all zlib states.

Definition at line 294 of file compress_zlib.c.

Referenced by tor_compress_get_total_allocation().

◆ tor_zlib_get_version_str()

const char* tor_zlib_get_version_str ( void  )

Return a string representation of the version of the currently running version of zlib.

Definition at line 95 of file compress_zlib.c.

◆ tor_zlib_init()

void tor_zlib_init ( void  )

Set up global state for the zlib module

Definition at line 301 of file compress_zlib.c.

Referenced by tor_compress_init().

◆ tor_zlib_method_supported()

int tor_zlib_method_supported ( void  )

Return 1 if zlib/gzip compression is supported; otherwise 0.

Definition at line 84 of file compress_zlib.c.

◆ tor_zlib_state_size_precalc()

static size_t tor_zlib_state_size_precalc ( int  inflate_,
int  windowbits,
int  memlevel 
)
static

Return an approximate number of bytes used in RAM to hold a state with window bits windowBits and compression level 'memlevel'

Definition at line 126 of file compress_zlib.c.

Variable Documentation

◆ total_zlib_allocation

atomic_counter_t total_zlib_allocation
static

Total number of bytes allocated for zlib state

Definition at line 52 of file compress_zlib.c.

Referenced by tor_zlib_compress_free_(), and tor_zlib_get_total_allocation().