Browse Source

and don't warn when it happens here either, unless the user
wants to hear it.


svn:r5990

Roger Dingledine 19 years ago
parent
commit
b99f903e34
4 changed files with 18 additions and 13 deletions
  1. 4 2
      src/common/torgzip.c
  2. 2 1
      src/common/torgzip.h
  3. 5 5
      src/or/directory.c
  4. 7 5
      src/or/test.c

+ 4 - 2
src/common/torgzip.c

@@ -157,7 +157,8 @@ int
 tor_gzip_uncompress(char **out, size_t *out_len,
                     const char *in, size_t in_len,
                     compress_method_t method,
-                    int complete_only)
+                    int complete_only,
+                    int protocol_warn_level)
 {
   struct z_stream_s *stream = NULL;
   size_t out_size;
@@ -218,7 +219,8 @@ tor_gzip_uncompress(char **out, size_t *out_len,
           break;
       case Z_BUF_ERROR:
         if (stream->avail_out > 0) {
-          warn(LD_PROTOCOL, "possible truncated or corrupt zlib data");
+          log_fn(protocol_warn_level, LD_PROTOCOL,
+                 "possible truncated or corrupt zlib data");
           goto err;
         }
         offset = stream->next_out - (unsigned char*)*out;

+ 2 - 1
src/common/torgzip.h

@@ -24,7 +24,8 @@ int
 tor_gzip_uncompress(char **out, size_t *out_len,
                     const char *in, size_t in_len,
                     compress_method_t method,
-                    int complete_only);
+                    int complete_only,
+                    int protocol_warn_level);
 
 int is_gzip_supported(void);
 

+ 5 - 5
src/or/directory.c

@@ -945,18 +945,18 @@ connection_dir_client_reached_eof(connection_t *conn)
     /* Try declared compression first if we can. */
     if (compression > 0)
       tor_gzip_uncompress(&new_body, &new_len, body, body_len, compression,
-                          allow_partial);
+                          allow_partial, LOG_PROTOCOL_WARN);
     /* Okay, if that didn't work, and we think that it was compressed
      * differently, try that. */
     if (!new_body && guessed > 0 && compression != guessed)
       tor_gzip_uncompress(&new_body, &new_len, body, body_len, guessed,
-                          allow_partial);
+                          allow_partial, LOG_PROTOCOL_WARN);
     /* If we're pretty sure that we have a compressed directory, and
      * we didn't manage to uncompress it, then warn and bail. */
     if (!plausible && !new_body) {
-      log(LOG_PROTOCOL_WARN, LD_HTTP,
-          "Unable to decompress HTTP body (server '%s:%d').",
-           conn->address, conn->port);
+      log_fn(LOG_PROTOCOL_WARN, LD_HTTP,
+             "Unable to decompress HTTP body (server '%s:%d').",
+             conn->address, conn->port);
       tor_free(body); tor_free(headers); tor_free(reason);
       return -1;
     }

+ 7 - 5
src/or/test.c

@@ -928,7 +928,7 @@ test_gzip(void)
     test_eq(detect_compression_method(buf2, len1), GZIP_METHOD);
 
     test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
-                                     GZIP_METHOD, 1));
+                                     GZIP_METHOD, 1, LOG_INFO));
     test_assert(buf3);
     test_streq(buf1,buf3);
 
@@ -942,7 +942,8 @@ test_gzip(void)
   test_assert(!memcmp(buf2, "\x78\xDA", 2)); /* deflate magic. */
   test_eq(detect_compression_method(buf2, len1), ZLIB_METHOD);
 
-  test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, ZLIB_METHOD, 1));
+  test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
+                                   ZLIB_METHOD, 1, LOG_INFO));
   test_assert(buf3);
   test_streq(buf1,buf3);
 
@@ -951,7 +952,7 @@ test_gzip(void)
   buf2 = tor_realloc(buf2, len1*2);
   memcpy(buf2+len1, buf2, len1);
   test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1*2,
-                                   ZLIB_METHOD, 1));
+                                   ZLIB_METHOD, 1, LOG_INFO));
   test_eq(len2, (strlen(buf1)+1)*2);
   test_memeq(buf3,
              "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ\0"
@@ -970,14 +971,15 @@ test_gzip(void)
   tor_assert(len1>16);
   /* when we allow an uncomplete string, we should succeed.*/
   tor_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
-                                  ZLIB_METHOD, 0));
+                                  ZLIB_METHOD, 0, LOG_INFO));
   buf3[len2]='\0';
   tor_assert(len2 > 5);
   tor_assert(!strcmpstart(buf1, buf3));
 
   /* when we demand a complete string, this must fail. */
   tor_free(buf3);
-  tor_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16, ZLIB_METHOD, 1));
+  tor_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
+                                 ZLIB_METHOD, 1, LOG_INFO));
   tor_assert(!buf3);
 
   tor_free(buf2);