mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
Move the "supported compression bitmask" into compress.[ch]
This commit is contained in:
parent
65ff0f8267
commit
2903c329aa
@ -277,6 +277,26 @@ tor_compress_supports_method(compress_method_t method)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bitmask of the supported compression types, where 1<<m is
|
||||
* set in the bitmask if and only if compression with method <b>m</b> is
|
||||
* supported.
|
||||
*/
|
||||
unsigned
|
||||
tor_compress_get_supported_method_bitmask(void)
|
||||
{
|
||||
static unsigned supported = 0;
|
||||
if (supported == 0) {
|
||||
compress_method_t m;
|
||||
for (m = NO_METHOD; m <= UNKNOWN_METHOD; ++m) {
|
||||
if (tor_compress_supports_method(m)) {
|
||||
supported |= (1u << m);
|
||||
}
|
||||
}
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
/** Table of compression method names. These should have an "x-" prefix,
|
||||
* if they are not listed in the IANA content coding registry. */
|
||||
static const struct {
|
||||
|
@ -16,12 +16,12 @@
|
||||
* functions here. Call tor_compress_supports_method() to check if a given
|
||||
* compression schema is supported by Tor. */
|
||||
typedef enum {
|
||||
NO_METHOD=0,
|
||||
NO_METHOD=0, // This method must be first.
|
||||
GZIP_METHOD=1,
|
||||
ZLIB_METHOD=2,
|
||||
LZMA_METHOD=3,
|
||||
ZSTD_METHOD=4,
|
||||
UNKNOWN_METHOD=5
|
||||
UNKNOWN_METHOD=5, // This method must be last. Add new ones in the middle.
|
||||
} compress_method_t;
|
||||
|
||||
/**
|
||||
@ -48,6 +48,7 @@ compress_method_t detect_compression_method(const char *in, size_t in_len);
|
||||
int tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
|
||||
|
||||
int tor_compress_supports_method(compress_method_t method);
|
||||
unsigned tor_compress_get_supported_method_bitmask(void);
|
||||
const char * compression_method_get_name(compress_method_t method);
|
||||
compress_method_t compression_method_get_by_name(const char *name);
|
||||
|
||||
|
@ -2814,20 +2814,6 @@ parse_accept_encoding_header(const char *h)
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Bitmask of supported compression types, to use in a bitwise "and"
|
||||
* with the results of parse_accept_encoding_header */
|
||||
static const unsigned SUPPORTED_COMPRESSION_MASK =
|
||||
(1u << NO_METHOD)
|
||||
| (1u << ZLIB_METHOD)
|
||||
| (1u << GZIP_METHOD)
|
||||
#ifdef HAVE_ZSTD
|
||||
| (1u << ZSTD_METHOD)
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
| (1u << LZMA_METHOD)
|
||||
#endif
|
||||
;
|
||||
|
||||
/** Decide whether a client would accept the consensus we have.
|
||||
*
|
||||
* Clients can say they only want a consensus if it's signed by more
|
||||
@ -3028,7 +3014,7 @@ directory_handle_command_get,(dir_connection_t *conn, const char *headers,
|
||||
}
|
||||
|
||||
/* Remove all methods that we don't both support. */
|
||||
compression_methods_supported &= SUPPORTED_COMPRESSION_MASK;
|
||||
compression_methods_supported &= tor_compress_get_supported_method_bitmask();
|
||||
|
||||
get_handler_args_t args;
|
||||
args.url = url;
|
||||
|
Loading…
Reference in New Issue
Block a user