torgzip.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_compress_process; see that function's documentation
  41. * for details. */
  42. typedef enum {
  43. TOR_COMPRESS_OK,
  44. TOR_COMPRESS_DONE,
  45. TOR_COMPRESS_BUFFER_FULL,
  46. TOR_COMPRESS_ERROR
  47. } tor_compress_output_t;
  48. /** Internal state for an incremental zlib compression/decompression. */
  49. typedef struct tor_compress_state_t tor_compress_state_t;
  50. tor_compress_state_t *tor_compress_new(int compress,
  51. compress_method_t method,
  52. compression_level_t level);
  53. tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
  54. char **out, size_t *out_len,
  55. const char **in, size_t *in_len,
  56. int finish);
  57. void tor_compress_free(tor_compress_state_t *state);
  58. size_t tor_compress_state_size(const tor_compress_state_t *state);
  59. size_t tor_zlib_get_total_allocation(void);
  60. #endif