torgzip.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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 zlib 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. size_t tor_zlib_get_total_allocation(void);
  64. #endif