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

[or-cvs] Allow tor_gzip_uncompress to handle multiple concatenated c...



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv8218/src/common

Modified Files:
	torgzip.c 
Log Message:
Allow tor_gzip_uncompress to handle multiple concatenated compressed strings.

Index: torgzip.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/torgzip.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- torgzip.c	13 Jul 2005 05:26:43 -0000	1.20
+++ torgzip.c	29 Aug 2005 18:01:38 -0000	1.21
@@ -30,6 +30,8 @@
 
 static int gzip_is_supported = -1;
 
+/** Return true iff we support gzip-based compression.  Otherwise, we need to
+ * use zlib. */
 int
 is_gzip_supported(void)
 {
@@ -53,6 +55,11 @@
   return method == GZIP_METHOD ? 15+16 : 15;
 }
 
+/** Given <b>in_len</b> bytes at <b>in</b>, compress them into a newly
+ * allocated buffer, using the method described in <b>method</b>.  Store the
+ * compressed string in *<b>out</b>, and its length in *<b>out_len</b>.
+ * Return 0 on success, -1 on failure.
+ */
 int
 tor_gzip_compress(char **out, size_t *out_len,
                   const char *in, size_t in_len,
@@ -138,7 +145,12 @@
   return -1;
 }
 
-/* DOCDOC -- sets *out to NULL on failure. */
+/** Given or more zlib-compressed or gzip-compressed strings of total length
+ * <b>in_len</b> bytes at <b>in</b>, uncompress them into a newly allocated
+ * buffer, using the method described in <b>method</b>.  Store the uncompressed
+ * string in *<b>out</b>, and its length in *<b>out_len</b>.  Return 0 on
+ * success, -1 on failure.
+ */
 int
 tor_gzip_uncompress(char **out, size_t *out_len,
                     const char *in, size_t in_len,
@@ -186,13 +198,20 @@
     switch (inflate(stream, Z_FINISH))
       {
       case Z_STREAM_END:
-        goto done;
+        if (stream->avail_in == 0)
+          goto done;
+        if (inflateInit2(stream, method_bits(method)) != Z_OK) {
+          log_fn(LOG_WARN, "Error from inflateInit2: %s",
+                 stream->msg?stream->msg:"<no message>");
+          goto err;
+        }
+        break;
       case Z_OK:
         /* In case zlib doesn't work as I think.... */
         if (stream->avail_out >= stream->avail_in+16)
           break;
       case Z_BUF_ERROR:
-        offset = stream->next_out - ((unsigned char*)*out);
+        offset = stream->next_out - (unsigned char*)*out;
         out_size *= 2;
         *out = tor_realloc(*out, out_size);
         stream->next_out = (unsigned char*)(*out + offset);
@@ -205,7 +224,7 @@
       }
   }
  done:
-  *out_len = stream->total_out;
+  *out_len = stream->next_out - (unsigned char*)*out;
   r = inflateEnd(stream);
   tor_free(stream);
   if (r != Z_OK) {