]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add API entry-point for getting compression method version numbers.
authorAlexander Færøy <ahf@torproject.org>
Thu, 20 Apr 2017 14:20:14 +0000 (16:20 +0200)
committerNick Mathewson <nickm@torproject.org>
Tue, 25 Apr 2017 12:10:10 +0000 (08:10 -0400)
This patch adds `tor_compress_version_str()` and
`tor_compress_header_version_str()` to get the version strings of the
different compression schema providers. Both functions returns `NULL` in
case a given `compress_method_t` is unknown or unsupported.

See: https://bugs.torproject.org/21662

src/common/compress.c
src/common/compress.h
src/common/compress_lzma.c
src/common/compress_zstd.c

index 725dde53e01ae516e3b1f5397ba477af645a1176..e64bbca5d119039439fc34e4923f713f32662d0e 100644 (file)
@@ -173,6 +173,48 @@ tor_compress_supports_method(compress_method_t method)
   }
 }
 
+/** Return a string representation of the version of the library providing the
+ * compression method given in <b>method</b>. Returns NULL if <b>method</b> is
+ * unknown or unsupported. */
+const char *
+tor_compress_version_str(compress_method_t method)
+{
+  switch (method) {
+    case GZIP_METHOD:
+    case ZLIB_METHOD:
+      return tor_zlib_get_version_str();
+    case LZMA_METHOD:
+      return tor_lzma_get_version_str();
+    case ZSTD_METHOD:
+      return tor_zstd_get_version_str();
+    case NO_METHOD:
+    case UNKNOWN_METHOD:
+    default:
+      return NULL;
+  }
+}
+
+/** Return a string representation of the version of the library, found at
+ * compile time, providing the compression method given in <b>method</b>.
+ * Returns NULL if <b>method</b> is unknown or unsupported. */
+const char *
+tor_compress_header_version_str(compress_method_t method)
+{
+  switch (method) {
+    case GZIP_METHOD:
+    case ZLIB_METHOD:
+      return tor_zlib_get_header_version_str();
+    case LZMA_METHOD:
+      return tor_lzma_get_header_version_str();
+    case ZSTD_METHOD:
+      return tor_zstd_get_header_version_str();
+    case NO_METHOD:
+    case UNKNOWN_METHOD:
+    default:
+      return NULL;
+  }
+}
+
 /** Return the approximate number of bytes allocated for all
  * supported compression schemas. */
 size_t
index 87306f5fb9b3249182dec3fb6b8d8efad8e3a7ae..182530fc11ab44e493e4d8126c176f1931d06088 100644 (file)
@@ -55,6 +55,12 @@ tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
 int
 tor_compress_supports_method(compress_method_t method);
 
+const char *
+tor_compress_version_str(compress_method_t method);
+
+const char *
+tor_compress_header_version_str(compress_method_t method);
+
 size_t
 tor_compress_get_total_allocation(void);
 
index c45cb5eb4fb8048abc66555c40c61276e2aa5dae..f2952cccdadd0ec536a91f5453ab9e2117577bbf 100644 (file)
@@ -73,26 +73,26 @@ tor_lzma_method_supported(void)
 }
 
 /** Return a string representation of the version of the currently running
- * version of liblzma. */
+ * version of liblzma. Returns NULL if LZMA is unsupported. */
 const char *
 tor_lzma_get_version_str(void)
 {
 #ifdef HAVE_LZMA
   return lzma_version_string();
 #else
-  return "N/A";
+  return NULL;
 #endif
 }
 
-/** Return a string representation of the version of the version of liblzma
- * used at compilation. */
+/** Return a string representation of the version of liblzma used at
+ * compilation time. Returns NULL if LZMA is unsupported. */
 const char *
 tor_lzma_get_header_version_str(void)
 {
 #ifdef HAVE_LZMA
   return LZMA_VERSION_STRING;
 #else
-  return "N/A";
+  return NULL;
 #endif
 }
 
index dca4dbdab5b966632cb641b4ea4512ea7bdb29b4..c838cd93645264f88eafc6f6e72d92a1641f27a1 100644 (file)
@@ -38,7 +38,7 @@ tor_zstd_method_supported(void)
 }
 
 /** Return a string representation of the version of the currently running
- * version of libzstd. */
+ * version of libzstd. Returns NULL if Zstandard is unsupported. */
 const char *
 tor_zstd_get_version_str(void)
 {
@@ -55,19 +55,19 @@ tor_zstd_get_version_str(void)
 
   return version_str;
 #else
-  return "N/A";
+  return NULL;
 #endif
 }
 
 /** Return a string representation of the version of the version of libzstd
- * used at compilation. */
+ * used at compilation time. Returns NULL if Zstandard is unsupported. */
 const char *
 tor_zstd_get_header_version_str(void)
 {
 #ifdef HAVE_ZSTD
   return ZSTD_VERSION_STRING;
 #else
-  return "N/A";
+  return NULL;
 #endif
 }