summaryrefslogtreecommitdiff
path: root/src/common/torgzip.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-01-19 22:40:33 +0000
committerNick Mathewson <nickm@torproject.org>2005-01-19 22:40:33 +0000
commit69fa5be7b624fcda98c7d2e7e8f678f8ee592404 (patch)
tree7d19255140ded00fd9599a858a366654b2a1bb88 /src/common/torgzip.c
parente0bf5976658ea76cd8b61d67f957b3c4f68e9108 (diff)
downloadtor-69fa5be7b624fcda98c7d2e7e8f678f8ee592404.tar.gz
tor-69fa5be7b624fcda98c7d2e7e8f678f8ee592404.zip
Workaround for webservers that lie about Content-Encoding: Tor now tries to autodetect compressed directories and compression itself. (resolves bug 65)
svn:r3374
Diffstat (limited to 'src/common/torgzip.c')
-rw-r--r--src/common/torgzip.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 12af332b70..1705e6bc9b 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -134,6 +134,7 @@ tor_gzip_compress(char **out, size_t *out_len,
return -1;
}
+/* DOCDOC -- sets *out to NULL on failure. */
int
tor_gzip_uncompress(char **out, size_t *out_len,
const char *in, size_t in_len,
@@ -224,3 +225,18 @@ tor_gzip_uncompress(char **out, size_t *out_len,
return -1;
}
+/** Try to tell whether the <b>in_len</b>-byte string in <b>in</b> is likely
+ * to be compressed or not. If it is, return the likeliest compression method.
+ * Otherwise, return 0.
+ */
+int detect_compression_method(const char *in, size_t in_len)
+{
+ if (in_len > 2 && in[0] == 0x1f && in[1] == 0x8b) {
+ return GZIP_METHOD;
+ } else if (in_len > 2 && (in[0] & 0x0f) == 8 &&
+ get_uint16(in) % 31 == 0) {
+ return ZLIB_METHOD;
+ } else {
+ return 0;
+ }
+}