torgzip.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file torgzip.h
  7. * \brief Headers for torgzip.h
  8. **/
  9. #ifndef TOR_TORGZIP_H
  10. #define TOR_TORGZIP_H
  11. /** Enumeration of what kind of compression to use. Only ZLIB_METHOD is
  12. * guaranteed to be supported by the compress/uncompress functions here;
  13. * GZIP_METHOD may be supported if we built against zlib version 1.2 or later
  14. * and is_gzip_supported() returns true. */
  15. typedef enum {
  16. NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3
  17. } compress_method_t;
  18. /**
  19. * Enumeration to define tradeoffs between memory usage and compression level.
  20. * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
  21. * memory.
  22. **/
  23. typedef enum {
  24. HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
  25. } zlib_compression_level_t;
  26. int
  27. tor_gzip_compress(char **out, size_t *out_len,
  28. const char *in, size_t in_len,
  29. compress_method_t method);
  30. int
  31. tor_gzip_uncompress(char **out, size_t *out_len,
  32. const char *in, size_t in_len,
  33. compress_method_t method,
  34. int complete_only,
  35. int protocol_warn_level);
  36. int is_gzip_supported(void);
  37. const char *
  38. tor_zlib_get_version_str(void);
  39. const char *
  40. tor_zlib_get_header_version_str(void);
  41. compress_method_t detect_compression_method(const char *in, size_t in_len);
  42. /** Return values from tor_zlib_process; see that function's documentation for
  43. * details. */
  44. typedef enum {
  45. TOR_ZLIB_OK, TOR_ZLIB_DONE, TOR_ZLIB_BUF_FULL, TOR_ZLIB_ERR
  46. } tor_zlib_output_t;
  47. /** Internal state for an incremental zlib compression/decompression. */
  48. typedef struct tor_zlib_state_t tor_zlib_state_t;
  49. tor_zlib_state_t *tor_zlib_new(int compress, compress_method_t method,
  50. zlib_compression_level_t level);
  51. tor_zlib_output_t tor_zlib_process(tor_zlib_state_t *state,
  52. char **out, size_t *out_len,
  53. const char **in, size_t *in_len,
  54. int finish);
  55. void tor_zlib_free(tor_zlib_state_t *state);
  56. size_t tor_zlib_state_size(const tor_zlib_state_t *state);
  57. size_t tor_zlib_get_total_allocation(void);
  58. #endif