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

[tor-commits] [tor/master] Rename `tor_gzip_{compress, uncompress}` to `tor_{compress, uncompress}`.



commit 44cb86adbe2e9b9fef7bf5fd64b52a8e44441be5
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
Date:   Mon Apr 17 14:29:10 2017 +0200

    Rename `tor_gzip_{compress,uncompress}` to `tor_{compress,uncompress}`.
    
    To allow us to use the API name `tor_compress` and `tor_uncompress` as
    the main entry-point for all compression/uncompression and not just gzip
    and zlib.
    
    See https://bugs.torproject.org/21663
---
 src/common/torgzip.c           | 16 +++++++-------
 src/common/torgzip.h           | 16 +++++++-------
 src/or/directory.c             |  8 +++----
 src/or/dirserv.c               |  4 ++--
 src/test/test_buffers.c        | 17 ++++++++-------
 src/test/test_dir_handle_get.c |  4 ++--
 src/test/test_util.c           | 48 +++++++++++++++++++++---------------------
 7 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index a6909ce..cbfcabd 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -132,9 +132,9 @@ is_compression_bomb(size_t size_in, size_t size_out)
  * Return 0 on success, -1 on failure.
  */
 int
-tor_gzip_compress(char **out, size_t *out_len,
-                  const char *in, size_t in_len,
-                  compress_method_t method)
+tor_compress(char **out, size_t *out_len,
+             const char *in, size_t in_len,
+             compress_method_t method)
 {
   struct z_stream_s *stream = NULL;
   size_t out_size, old_size;
@@ -252,11 +252,11 @@ tor_gzip_compress(char **out, size_t *out_len,
  * or corrupt inputs at <b>protocol_warn_level</b>.
  */
 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 protocol_warn_level)
+tor_uncompress(char **out, size_t *out_len,
+               const char *in, size_t in_len,
+               compress_method_t method,
+               int complete_only,
+               int protocol_warn_level)
 {
   struct z_stream_s *stream = NULL;
   size_t out_size, old_size;
diff --git a/src/common/torgzip.h b/src/common/torgzip.h
index cbcbb99..ac9763e 100644
--- a/src/common/torgzip.h
+++ b/src/common/torgzip.h
@@ -28,15 +28,15 @@ typedef enum {
 } compression_level_t;
 
 int
-tor_gzip_compress(char **out, size_t *out_len,
-                  const char *in, size_t in_len,
-                  compress_method_t method);
+tor_compress(char **out, size_t *out_len,
+             const char *in, size_t in_len,
+             compress_method_t method);
 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 protocol_warn_level);
+tor_uncompress(char **out, size_t *out_len,
+               const char *in, size_t in_len,
+               compress_method_t method,
+               int complete_only,
+               int protocol_warn_level);
 
 const char *
 tor_zlib_get_version_str(void);
diff --git a/src/or/directory.c b/src/or/directory.c
index bbe071b..e7a71dd 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2096,15 +2096,15 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
     }
     /* Try declared compression first if we can. */
     if (compression == GZIP_METHOD  || compression == ZLIB_METHOD)
-      tor_gzip_uncompress(&new_body, &new_len, body, body_len, compression,
-                          !allow_partial, LOG_PROTOCOL_WARN);
+      tor_uncompress(&new_body, &new_len, body, body_len, compression,
+                     !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 == GZIP_METHOD || guessed == ZLIB_METHOD) &&
         compression != guessed)
-      tor_gzip_uncompress(&new_body, &new_len, body, body_len, guessed,
-                          !allow_partial, LOG_PROTOCOL_WARN);
+      tor_uncompress(&new_body, &new_len, body, body_len, guessed,
+                     !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) {
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 70b0b22..87afd69 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1176,8 +1176,8 @@ new_cached_dir(char *s, time_t published)
   d->dir = s;
   d->dir_len = strlen(s);
   d->published = published;
-  if (tor_gzip_compress(&(d->dir_z), &(d->dir_z_len), d->dir, d->dir_len,
-                        ZLIB_METHOD)) {
+  if (tor_compress(&(d->dir_z), &(d->dir_z_len), d->dir, d->dir_len,
+                   ZLIB_METHOD)) {
     log_warn(LD_BUG, "Error compressing directory");
   }
   return d;
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c
index d14165c..f0edd42 100644
--- a/src/test/test_buffers.c
+++ b/src/test/test_buffers.c
@@ -607,10 +607,10 @@ test_buffers_zlib_impl(int finalize_with_nil)
 
   tt_int_op(fetch_from_buf(contents, in_len, buf), OP_EQ, 0);
 
-  tt_int_op(0, OP_EQ, tor_gzip_uncompress(&expanded, &out_len,
-                                       contents, in_len,
-                                       ZLIB_METHOD, 1,
-                                       LOG_WARN));
+  tt_int_op(0, OP_EQ, tor_uncompress(&expanded, &out_len,
+                                     contents, in_len,
+                                     ZLIB_METHOD, 1,
+                                     LOG_WARN));
 
   tt_int_op(out_len, OP_GE, 128);
   tt_mem_op(msg, OP_EQ, expanded, 128);
@@ -676,10 +676,11 @@ test_buffers_zlib_fin_at_chunk_end(void *arg)
 
   tt_uint_op(in_len, OP_GT, headerjunk);
 
-  tt_int_op(0, OP_EQ, tor_gzip_uncompress(&expanded, &out_len,
-                                  contents + headerjunk, in_len - headerjunk,
-                                  ZLIB_METHOD, 1,
-                                  LOG_WARN));
+  tt_int_op(0, OP_EQ, tor_uncompress(&expanded, &out_len,
+                                     contents + headerjunk,
+                                     in_len - headerjunk,
+                                     ZLIB_METHOD, 1,
+                                     LOG_WARN));
 
   tt_int_op(out_len, OP_EQ, 0);
   tt_assert(expanded);
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index cfda314..ed8ea2f 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -1832,8 +1832,8 @@ test_dir_handle_get_status_vote_current_consensus_ns(void* data)
                                                             comp_body_used);
   tt_int_op(ZLIB_METHOD, OP_EQ, compression);
 
-  tor_gzip_uncompress(&body, &body_used, comp_body, comp_body_used,
-                      compression, 0, LOG_PROTOCOL_WARN);
+  tor_uncompress(&body, &body_used, comp_body, comp_body_used,
+                 compression, 0, LOG_PROTOCOL_WARN);
 
   tt_str_op(NETWORK_STATUS, OP_EQ, body);
   tt_int_op(strlen(NETWORK_STATUS), OP_EQ, body_used);
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 19d1c79..7e24279 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2255,14 +2255,14 @@ test_util_gzip(void *arg)
   buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
   tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
 
-  tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
-                               GZIP_METHOD));
+  tt_assert(!tor_compress(&buf2, &len1, buf1, strlen(buf1)+1,
+                          GZIP_METHOD));
   tt_assert(buf2 != NULL);
   tt_int_op(len1, OP_LT, strlen(buf1));
   tt_int_op(detect_compression_method(buf2, len1), OP_EQ, GZIP_METHOD);
 
-  tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
-                                 GZIP_METHOD, 1, LOG_INFO));
+  tt_assert(!tor_uncompress(&buf3, &len2, buf2, len1,
+                            GZIP_METHOD, 1, LOG_INFO));
   tt_assert(buf3 != NULL);
   tt_int_op(strlen(buf1) + 1, OP_EQ, len2);
   tt_str_op(buf1, OP_EQ, buf3);
@@ -2270,13 +2270,13 @@ test_util_gzip(void *arg)
   tor_free(buf2);
   tor_free(buf3);
 
-  tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
-                                 ZLIB_METHOD));
+  tt_assert(!tor_compress(&buf2, &len1, buf1, strlen(buf1)+1,
+                          ZLIB_METHOD));
   tt_assert(buf2);
   tt_int_op(detect_compression_method(buf2, len1), OP_EQ, ZLIB_METHOD);
 
-  tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1,
-                                   ZLIB_METHOD, 1, LOG_INFO));
+  tt_assert(!tor_uncompress(&buf3, &len2, buf2, len1,
+                            ZLIB_METHOD, 1, LOG_INFO));
   tt_assert(buf3 != NULL);
   tt_int_op(strlen(buf1) + 1, OP_EQ, len2);
   tt_str_op(buf1, OP_EQ, buf3);
@@ -2285,8 +2285,8 @@ test_util_gzip(void *arg)
   tor_free(buf3);
   buf2 = tor_reallocarray(buf2, len1, 2);
   memcpy(buf2+len1, buf2, len1);
-  tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1*2,
-                                   ZLIB_METHOD, 1, LOG_INFO));
+  tt_assert(!tor_uncompress(&buf3, &len2, buf2, len1*2,
+                            ZLIB_METHOD, 1, LOG_INFO));
   tt_int_op((strlen(buf1)+1)*2, OP_EQ, len2);
   tt_mem_op(buf3, OP_EQ,
              "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ\0"
@@ -2300,20 +2300,20 @@ test_util_gzip(void *arg)
   /* Check whether we can uncompress partial strings. */
   buf1 =
     tor_strdup("String with low redundancy that won't be compressed much.");
-  tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
-                                 ZLIB_METHOD));
+  tt_assert(!tor_compress(&buf2, &len1, buf1, strlen(buf1)+1,
+                          ZLIB_METHOD));
   tt_int_op(len1, OP_GT, 16);
   /* when we allow an incomplete string, we should succeed.*/
-  tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
-                                  ZLIB_METHOD, 0, LOG_INFO));
+  tt_assert(!tor_uncompress(&buf3, &len2, buf2, len1-16,
+                            ZLIB_METHOD, 0, LOG_INFO));
   tt_assert(len2 > 5);
   buf3[len2]='\0';
   tt_assert(!strcmpstart(buf1, buf3));
 
   /* when we demand a complete string, this must fail. */
   tor_free(buf3);
-  tt_assert(tor_gzip_uncompress(&buf3, &len2, buf2, len1-16,
-                                 ZLIB_METHOD, 1, LOG_INFO));
+  tt_assert(tor_uncompress(&buf3, &len2, buf2, len1-16,
+                           ZLIB_METHOD, 1, LOG_INFO));
   tt_assert(buf3 == NULL);
 
   /* Now, try streaming compression. */
@@ -2338,8 +2338,8 @@ test_util_gzip(void *arg)
   tt_int_op(0, OP_EQ, len2);
   tt_assert(cp1 > cp2); /* Make sure we really added something. */
 
-  tt_assert(!tor_gzip_uncompress(&buf3, &len2, buf1, 1024-len1,
-                                  ZLIB_METHOD, 1, LOG_WARN));
+  tt_assert(!tor_uncompress(&buf3, &len2, buf1, 1024-len1,
+                            ZLIB_METHOD, 1, LOG_WARN));
   /* Make sure it compressed right. */
   tt_str_op(buf3, OP_EQ, "ABCDEFGHIJABCDEFGHIJ");
   tt_int_op(21, OP_EQ, len2);
@@ -2368,9 +2368,9 @@ test_util_gzip_compression_bomb(void *arg)
 
   /* Make sure we can't produce a compression bomb */
   setup_full_capture_of_logs(LOG_WARN);
-  tt_int_op(-1, OP_EQ, tor_gzip_compress(&result, &result_len,
-                                         one_mb, one_million,
-                                         ZLIB_METHOD));
+  tt_int_op(-1, OP_EQ, tor_compress(&result, &result_len,
+                                    one_mb, one_million,
+                                    ZLIB_METHOD));
   expect_single_log_msg_containing(
          "We compressed something and got an insanely high "
          "compression factor; other Tors would think this "
@@ -2381,9 +2381,9 @@ test_util_gzip_compression_bomb(void *arg)
   const char compression_bomb[1039] =
     { 0x78, 0xDA, 0xED, 0xC1, 0x31, 0x01, 0x00, 0x00, 0x00, 0xC2,
       0xA0, 0xF5, 0x4F, 0x6D, 0x08, 0x5F, 0xA0 /* .... */ };
-  tt_int_op(-1, OP_EQ, tor_gzip_uncompress(&result, &result_len,
-                                           compression_bomb, 1039,
-                                           ZLIB_METHOD, 0, LOG_WARN));
+  tt_int_op(-1, OP_EQ, tor_uncompress(&result, &result_len,
+                                      compression_bomb, 1039,
+                                      ZLIB_METHOD, 0, LOG_WARN));
 
   /* Now try streaming that. */
   state = tor_zlib_new(0, ZLIB_METHOD, HIGH_COMPRESSION);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits