[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] backport compression-detection code to maintenance branch s...



Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv30729/src/common

Modified Files:
      Tag: tor-0_0_9-patches
	torgzip.c torgzip.h 
Log Message:
backport compression-detection code to maintenance branch so 0093 can handle directories from sources that are confused about content-encoding.

Index: torgzip.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/torgzip.c,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -d -r1.9 -r1.9.2.1
--- torgzip.c	29 Nov 2004 22:25:28 -0000	1.9
+++ torgzip.c	21 Jan 2005 02:06:27 -0000	1.9.2.1
@@ -224,3 +224,18 @@
   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 && !memcmp(in, "\x1f\x8b", 2)) {
+    return GZIP_METHOD;
+  } else if (in_len > 2 && (in[0] & 0x0f) == 8 &&
+             (ntohs(get_uint16(in)) % 31) == 0) {
+    return ZLIB_METHOD;
+  } else {
+    return 0;
+  }
+}

Index: torgzip.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/torgzip.h,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- torgzip.h	29 Nov 2004 22:25:28 -0000	1.4
+++ torgzip.h	21 Jan 2005 02:06:27 -0000	1.4.2.1
@@ -24,4 +24,6 @@
 
 int is_gzip_supported(void);
 
+int detect_compression_method(const char *in, size_t in_len);
+
 #endif