torgzip.h File Reference

Headers for torgzip.h. More...

Go to the source code of this file.

Typedefs

typedef struct tor_zlib_state_t tor_zlib_state_t

Enumerations

enum  compress_method_t { NO_METHOD = 0, GZIP_METHOD = 1, ZLIB_METHOD = 2, UNKNOWN_METHOD = 3 }
enum  tor_zlib_output_t { TOR_ZLIB_OK, TOR_ZLIB_DONE, TOR_ZLIB_BUF_FULL, TOR_ZLIB_ERR }

Functions

int tor_gzip_compress (char **out, size_t *out_len, const char *in, size_t in_len, compress_method_t method)
int tor_gzip_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)
int is_gzip_supported (void)
compress_method_t detect_compression_method (const char *in, size_t in_len)
tor_zlib_state_ttor_zlib_new (int compress, compress_method_t method)
tor_zlib_output_t tor_zlib_process (tor_zlib_state_t *state, char **out, size_t *out_len, const char **in, size_t *in_len, int finish)
void tor_zlib_free (tor_zlib_state_t *state)


Detailed Description

Headers for torgzip.h.


Typedef Documentation

Internal state for an incremental zlib compression/decompression.


Enumeration Type Documentation

Enumeration of what kind of compression to use. Only ZLIB_METHOD is guaranteed to be supported by the compress/uncompress functions here; GZIP_METHOD may be supported if we built against zlib version 1.2 or later and is_gzip_supported() returns true.

Return values from tor_zlib_process; see that function's documentation for details.


Function Documentation

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.

References get_uint16().

Referenced by connection_dir_client_reached_eof().

int is_gzip_supported ( void   ) 

Return true iff we support gzip-based compression. Otherwise, we need to use zlib.

References gzip_is_supported, and strcmpstart().

Referenced by tor_gzip_compress(), tor_gzip_uncompress(), and tor_zlib_new().

int tor_gzip_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.

References is_gzip_supported(), LD_BUG, LD_GENERAL, method_bits(), tor_assert, and tor_free.

Referenced by new_cached_dir(), and set_cached_dir().

int tor_gzip_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 zlib-compressed or gzip-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 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.

References is_gzip_supported(), LD_BUG, LD_GENERAL, LD_PROTOCOL, method_bits(), tor_assert, and tor_free.

Referenced by connection_dir_client_reached_eof().

void tor_zlib_free ( tor_zlib_state_t state  ) 

tor_zlib_state_t* tor_zlib_new ( int  compress,
compress_method_t  method 
)

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

References tor_zlib_state_t::compress, is_gzip_supported(), LD_BUG, method_bits(), tor_zlib_state_t::stream, and tor_free.

Referenced by connection_dirserv_add_networkstatus_bytes_to_outbuf(), and directory_handle_command_get().

tor_zlib_output_t tor_zlib_process ( tor_zlib_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_ZLIB_DONE if we've finished the entire compression/decompression. Return TOR_ZLIB_OK if we're processed everything from the input. Return TOR_ZLIB_BUF_FULL if we're out of space on out. Return TOR_ZLIB_ERR if the stream is corrupt.

References tor_zlib_state_t::compress, LD_GENERAL, tor_zlib_state_t::stream, and tor_assert.

Referenced by write_to_buf_zlib().


Generated on Tue May 25 00:31:00 2010 for tor by  doxygen 1.5.6