torgzip.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2012, 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. int
  19. tor_gzip_compress(char **out, size_t *out_len,
  20. const char *in, size_t in_len,
  21. compress_method_t method);
  22. int
  23. tor_gzip_uncompress(char **out, size_t *out_len,
  24. const char *in, size_t in_len,
  25. compress_method_t method,
  26. int complete_only,
  27. int protocol_warn_level);
  28. int is_gzip_supported(void);
  29. compress_method_t detect_compression_method(const char *in, size_t in_len);
  30. /** Return values from tor_zlib_process; see that function's documentation for
  31. * details. */
  32. typedef enum {
  33. TOR_ZLIB_OK, TOR_ZLIB_DONE, TOR_ZLIB_BUF_FULL, TOR_ZLIB_ERR
  34. } tor_zlib_output_t;
  35. /** Internal state for an incremental zlib compression/decompression. */
  36. typedef struct tor_zlib_state_t tor_zlib_state_t;
  37. tor_zlib_state_t *tor_zlib_new(int compress, compress_method_t method);
  38. tor_zlib_output_t tor_zlib_process(tor_zlib_state_t *state,
  39. char **out, size_t *out_len,
  40. const char **in, size_t *in_len,
  41. int finish);
  42. void tor_zlib_free(tor_zlib_state_t *state);
  43. #endif