aboutsummaryrefslogtreecommitdiff
path: root/src/common/compress.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-04-20 16:20:14 +0200
committerNick Mathewson <nickm@torproject.org>2017-04-25 08:10:10 -0400
commit6b905b38bb850d0530ba6f6d02c10b1fb19aef9a (patch)
tree554986cb82ac4703d749a9422e475fe5e0ab5c34 /src/common/compress.c
parent1c77d8690caa1ad80b9d9581cac8eddae95e82d1 (diff)
downloadtor-6b905b38bb850d0530ba6f6d02c10b1fb19aef9a.tar.gz
tor-6b905b38bb850d0530ba6f6d02c10b1fb19aef9a.zip
Add API entry-point for getting compression method version numbers.
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
Diffstat (limited to 'src/common/compress.c')
-rw-r--r--src/common/compress.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index 725dde53e0..e64bbca5d1 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -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