r8967@totoro: nickm | 2006-10-08 23:38:50 -0400

Fix some test and warn failures in last commit


svn:r8665
This commit is contained in:
Nick Mathewson 2006-10-09 03:39:06 +00:00
parent c6f2d725d0
commit e618c15aff
5 changed files with 18 additions and 17 deletions

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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));