summaryrefslogtreecommitdiff
path: root/src/common/compress.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-05-12 12:45:00 +0200
committerAlexander Færøy <ahf@torproject.org>2017-05-12 17:18:45 +0200
commit3a05687c6d4c1ed11707e53b5dbec1b81e2a9c0a (patch)
tree5df19c68cdd7ec8a988eae8f9ce763153a99d503 /src/common/compress.c
parentf8218b5adaa54c61c3b79ad7f055e1a4a433daa0 (diff)
downloadtor-3a05687c6d4c1ed11707e53b5dbec1b81e2a9c0a.tar.gz
tor-3a05687c6d4c1ed11707e53b5dbec1b81e2a9c0a.zip
Add API for getting human readable descriptions of a compress_method_t
See: https://bugs.torproject.org/21667
Diffstat (limited to 'src/common/compress.c')
-rw-r--r--src/common/compress.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index 6fe4569868..6513029f9c 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -343,6 +343,32 @@ compression_method_get_name(compress_method_t method)
return NULL;
}
+/** Table of compression human readable method names. */
+static const struct {
+ compress_method_t method;
+ const char *name;
+} compression_method_human_names[] = {
+ { NO_METHOD, "uncompressed" },
+ { GZIP_METHOD, "gzipped" },
+ { ZLIB_METHOD, "deflated" },
+ { LZMA_METHOD, "LZMA compressed" },
+ { ZSTD_METHOD, "Zstandard compressed" },
+ { UNKNOWN_METHOD, "unknown encoding" },
+};
+
+/** Return a human readable string representation of the compression method
+ * <b>method</b>, or NULL if the method isn't recognized. */
+const char *
+compression_method_get_human_name(compress_method_t method)
+{
+ unsigned i;
+ for (i = 0; i < ARRAY_LENGTH(compression_method_human_names); ++i) {
+ if (method == compression_method_human_names[i].method)
+ return compression_method_human_names[i].name;
+ }
+ return NULL;
+}
+
/** Return the compression method represented by the string <b>name</b>, or
* UNKNOWN_METHOD if the string isn't recognized. */
compress_method_t