diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-10-09 03:39:06 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-10-09 03:39:06 +0000 |
commit | e618c15aff328b1332edd22db6a949a61d5c0b3b (patch) | |
tree | 34616c4031fc5246b5bd35fbc97b50d71118cc3e | |
parent | c6f2d725d005f912830b523aa1d1a419f4e22ecd (diff) | |
download | tor-e618c15aff328b1332edd22db6a949a61d5c0b3b.tar.gz tor-e618c15aff328b1332edd22db6a949a61d5c0b3b.zip |
r8967@totoro: nickm | 2006-10-08 23:38:50 -0400
Fix some test and warn failures in last commit
svn:r8665
-rw-r--r-- | src/common/torgzip.h | 2 | ||||
-rw-r--r-- | src/or/connection_or.c | 3 | ||||
-rw-r--r-- | src/or/directory.c | 20 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/test.c | 8 |
5 files changed, 18 insertions, 17 deletions
diff --git a/src/common/torgzip.h b/src/common/torgzip.h index ca3f493540..a20106cc35 100644 --- a/src/common/torgzip.h +++ b/src/common/torgzip.h @@ -13,7 +13,7 @@ #define TORGZIP_H_ID "$Id$" typedef enum { - GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3 + NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3 } compress_method_t; int diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 0409791562..9f1119cf40 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -154,7 +154,6 @@ connection_or_read_proxy_response(or_connection_t *or_conn) char *reason=NULL; int status_code; time_t date_header; - int compression; connection_t *conn = TO_CONN(or_conn); switch (fetch_from_buf_http(conn->inbuf, @@ -171,7 +170,7 @@ connection_or_read_proxy_response(or_connection_t *or_conn) } if (parse_http_response(headers, &status_code, &date_header, - &compression, &reason) < 0) { + NULL, &reason) < 0) { log_warn(LD_OR, "Unparseable headers from proxy (connecting to '%s'). Closing.", conn->address); diff --git a/src/or/directory.c b/src/or/directory.c index 210d020584..6a68bf4954 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -717,7 +717,7 @@ http_set_address_origin(const char *headers, connection_t *conn) */ int parse_http_response(const char *headers, int *code, time_t *date, - int *compression, char **reason) + compress_method_t *compression, char **reason) { int n1, n2; char datestr[RFC1123_TIME_LEN+1]; @@ -771,7 +771,7 @@ parse_http_response(const char *headers, int *code, time_t *date, enc = s+18; break; }); if (!enc || !strcmp(enc, "identity")) { - *compression = 0; + *compression = NO_METHOD; } else if (!strcmp(enc, "deflate") || !strcmp(enc, "x-deflate")) { *compression = ZLIB_METHOD; } else if (!strcmp(enc, "gzip") || !strcmp(enc, "x-gzip")) { @@ -779,7 +779,7 @@ parse_http_response(const char *headers, int *code, time_t *date, } else { log_info(LD_HTTP, "Unrecognized content encoding: %s. Trying to deal.", escaped(enc)); - *compression = -1; + *compression = UNKNOWN_METHOD; } } SMARTLIST_FOREACH(parsed_headers, char *, s, tor_free(s)); @@ -834,7 +834,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn) int status_code; time_t now, date_header=0; int delta; - int compression; + compress_method_t compression; int plausible; int skewed=0; int allow_partial = conn->_base.purpose == DIR_PURPOSE_FETCH_SERVERDESC; @@ -909,11 +909,11 @@ connection_dir_client_reached_eof(dir_connection_t *conn) } plausible = body_is_plausible(body, body_len, conn->_base.purpose); - if (compression || !plausible) { + if (compression != NO_METHOD || !plausible) { char *new_body = NULL; size_t new_len = 0; - int guessed = detect_compression_method(body, body_len); - if (compression <= 0 || guessed != compression) { + compress_method_t guessed = detect_compression_method(body, body_len); + if (compression == UNKNOWN_METHOD || guessed != compression) { /* Tell the user if we don't believe what we're told about compression.*/ const char *description1, *description2; if (compression == ZLIB_METHOD) @@ -940,12 +940,14 @@ connection_dir_client_reached_eof(dir_connection_t *conn) (compression>0 && guessed>0)?" Trying both.":""); } /* Try declared compression first if we can. */ - if (compression > 0) + if (compression == GZIP_METHOD || compression == ZLIB_METHOD) tor_gzip_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 > 0 && compression != guessed) + 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); /* If we're pretty sure that we have a compressed directory, and diff --git a/src/or/or.h b/src/or/or.h index 56aba99c6d..679123d75b 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2118,7 +2118,7 @@ void directory_initiate_command_routerstatus(routerstatus_t *status, size_t payload_len); int parse_http_response(const char *headers, int *code, time_t *date, - int *compression, char **response); + compress_method_t *compression, char **response); int connection_dir_reached_eof(dir_connection_t *conn); int connection_dir_process_inbuf(dir_connection_t *conn); diff --git a/src/or/test.c b/src/or/test.c index c25bd189cd..5a7903f09c 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -990,13 +990,13 @@ test_gzip(void) tor_zlib_state_t *state; buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ"); - test_eq(detect_compression_method(buf1, strlen(buf1)), 0); + test_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD); if (is_gzip_supported()) { test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1, GZIP_METHOD)); test_assert(buf2); - test_assert(!memcmp(buf2, "\037\213", 2)); /* Gzip magic. */ - test_eq(detect_compression_method(buf2, len1), GZIP_METHOD); + test_assert(!memcmp(buf2, "\037\213", 2)); /* Gztip magic. */ + test_assert(detect_compression_method(buf2, len1) == GZIP_METHOD); test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, GZIP_METHOD, 1, LOG_INFO)); @@ -1011,7 +1011,7 @@ test_gzip(void) ZLIB_METHOD)); test_assert(buf2); test_assert(!memcmp(buf2, "\x78\xDA", 2)); /* deflate magic. */ - test_eq(detect_compression_method(buf2, len1), ZLIB_METHOD); + test_assert(detect_compression_method(buf2, len1) == ZLIB_METHOD); test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, ZLIB_METHOD, 1, LOG_INFO)); |