compress.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 compress.h
  7. * \brief Headers for compress.c
  8. **/
  9. #ifndef TOR_COMPRESS_H
  10. #define TOR_COMPRESS_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,
  16. GZIP_METHOD=1,
  17. ZLIB_METHOD=2,
  18. LZMA_METHOD=3,
  19. UNKNOWN_METHOD=4
  20. } compress_method_t;
  21. /**
  22. * Enumeration to define tradeoffs between memory usage and compression level.
  23. * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
  24. * memory.
  25. **/
  26. typedef enum {
  27. HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
  28. } compression_level_t;
  29. int
  30. tor_compress(char **out, size_t *out_len,
  31. const char *in, size_t in_len,
  32. compress_method_t method);
  33. int
  34. tor_uncompress(char **out, size_t *out_len,
  35. const char *in, size_t in_len,
  36. compress_method_t method,
  37. int complete_only,
  38. int protocol_warn_level);
  39. compress_method_t detect_compression_method(const char *in, size_t in_len);
  40. int
  41. tor_compress_memory_level(compression_level_t level);
  42. int
  43. tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
  44. /** Return values from tor_compress_process; see that function's documentation
  45. * for details. */
  46. typedef enum {
  47. TOR_COMPRESS_OK,
  48. TOR_COMPRESS_DONE,
  49. TOR_COMPRESS_BUFFER_FULL,
  50. TOR_COMPRESS_ERROR
  51. } tor_compress_output_t;
  52. /** Internal state for an incremental compression/decompression. */
  53. typedef struct tor_compress_state_t tor_compress_state_t;
  54. tor_compress_state_t *tor_compress_new(int compress,
  55. compress_method_t method,
  56. compression_level_t level);
  57. tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
  58. char **out, size_t *out_len,
  59. const char **in, size_t *in_len,
  60. int finish);
  61. void tor_compress_free(tor_compress_state_t *state);
  62. size_t tor_compress_state_size(const tor_compress_state_t *state);
  63. #endif // TOR_COMPRESS_H.