[tor-commits] [tor/master] Expose `tor_compress_memory_level()` as a public function in the compression module.

nickm at torproject.org nickm at torproject.org
Tue Apr 25 12:18:24 UTC 2017


commit 6b5172bcf2018f858d38f5dea13753b8238b15ae
Author: Alexander Færøy <ahf at torproject.org>
Date:   Tue Apr 18 02:23:25 2017 +0200

    Expose `tor_compress_memory_level()` as a public function in the compression module.
    
    This patch makes the internal `get_memlevel()` a part of the public
    compression API as `tor_compress_memory_level()`.
    
    See https://bugs.torproject.org/21663
---
 src/common/torgzip.c | 24 ++++++++++++++----------
 src/common/torgzip.h |  3 +++
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index af4bbc5..09f3806 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -86,16 +86,6 @@ method_bits(compress_method_t method, compression_level_t level)
   }
 }
 
-static inline int
-get_memlevel(compression_level_t level)
-{
-  switch (level) {
-    default:
-    case HIGH_COMPRESSION: return 8;
-    case MEDIUM_COMPRESSION: return 7;
-    case LOW_COMPRESSION: return 6;
-  }
-}
 
 /** @{ */
 /* These macros define the maximum allowable compression factor.  Anything of
@@ -126,6 +116,20 @@ is_compression_bomb(size_t size_in, size_t size_out)
   return (size_out / size_in > MAX_UNCOMPRESSION_FACTOR);
 }
 
+/** Given <b>level</b> return the memory level.  The memory level is needed for
+ * the various compression backends used in Tor.
+ */
+int
+tor_compress_memory_level(compression_level_t level)
+{
+  switch (level) {
+    default:
+    case HIGH_COMPRESSION: return 8;
+    case MEDIUM_COMPRESSION: return 7;
+    case LOW_COMPRESSION: return 6;
+  }
+}
+
 /** Given <b>in_len</b> bytes at <b>in</b>, compress them into a newly
  * allocated buffer, using the method described in <b>method</b>.  Store the
  * compressed string in *<b>out</b>, and its length in *<b>out_len</b>.
diff --git a/src/common/torgzip.h b/src/common/torgzip.h
index 2b0504e..8f2363a 100644
--- a/src/common/torgzip.h
+++ b/src/common/torgzip.h
@@ -46,6 +46,9 @@ tor_zlib_get_header_version_str(void);
 
 compress_method_t detect_compression_method(const char *in, size_t in_len);
 
+int
+tor_compress_memory_level(compression_level_t level);
+
 /** Return values from tor_compress_process; see that function's documentation
  * for details. */
 typedef enum {





More information about the tor-commits mailing list