torgzip.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 and
  12. * GZIP_METHOD is guaranteed to be supported by the compress/uncompress
  13. * functions here. */
  14. typedef enum {
  15. NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3
  16. } compress_method_t;
  17. /**
  18. * Enumeration to define tradeoffs between memory usage and compression level.
  19. * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
  20. * memory.
  21. **/
  22. typedef enum {
  23. HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
  24. } compression_level_t;
  25. int
  26. tor_compress(char **out, size_t *out_len,
  27. const char *in, size_t in_len,
  28. compress_method_t method);
  29. int
  30. tor_uncompress(char **out, size_t *out_len,
  31. const char *in, size_t in_len,
  32. compress_method_t method,
  33. int complete_only,
  34. int protocol_warn_level);
  35. const char *
  36. tor_zlib_get_version_str(void);
  37. const char *
  38. tor_zlib_get_header_version_str(void);
  39. compress_method_t detect_compression_method(const char *in, size_t in_len);
  40. /** Return values from tor_zlib_process; see that function's documentation for
  41. * details. */
  42. typedef enum {
  43. TOR_ZLIB_OK, TOR_ZLIB_DONE, TOR_ZLIB_BUF_FULL, TOR_ZLIB_ERR
  44. } tor_zlib_output_t;
  45. /** Internal state for an incremental zlib compression/decompression. */
  46. typedef struct tor_zlib_state_t tor_zlib_state_t;
  47. tor_zlib_state_t *tor_zlib_new(int compress, compress_method_t method,
  48. compression_level_t level);
  49. tor_zlib_output_t tor_zlib_process(tor_zlib_state_t *state,
  50. char **out, size_t *out_len,
  51. const char **in, size_t *in_len,
  52. int finish);
  53. void tor_zlib_free(tor_zlib_state_t *state);
  54. size_t tor_zlib_state_size(const tor_zlib_state_t *state);
  55. size_t tor_zlib_get_total_allocation(void);
  56. #endif