From cea2521b91a87414b2f9b0dc78725a90d8d7bc4e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 28 Jan 2022 16:17:25 +0100 Subject: [PATCH] [encoding] enum stream_encoding -> stream_encoding_T --- src/document/renderer.c | 2 +- src/encoding/encoding.c | 14 +++++++------- src/encoding/encoding.h | 14 ++++++++------ src/mime/mime.c | 2 +- src/network/connection.h | 2 +- src/protocol/http/http.c | 2 +- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/document/renderer.c b/src/document/renderer.c index 1f9c529e9..da6749a1a 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -219,7 +219,7 @@ static void render_encoded_document(struct cache_entry *cached, struct document *document) { struct uri *uri = cached->uri; - enum stream_encoding encoding = ENCODING_NONE; + stream_encoding_T encoding = ENCODING_NONE; struct fragment *fragment = get_cache_fragment(cached); struct string buffer = INIT_STRING("", 0); diff --git a/src/encoding/encoding.c b/src/encoding/encoding.c index 43cebd5ae..e5a43d1da 100644 --- a/src/encoding/encoding.c +++ b/src/encoding/encoding.c @@ -106,7 +106,7 @@ static const struct decoding_backend *const decoding_backends[] = { /* Associates encoded stream with a fd. */ struct stream_encoded * -open_encoded(int fd, enum stream_encoding encoding) +open_encoded(int fd, stream_encoding_T encoding) { struct stream_encoded *stream; @@ -134,7 +134,7 @@ read_encoded(struct stream_encoded *stream, char *data, int len) * for parts of files. @data contains the original data, @len bytes * long. The resulting decoded data chunk is *@new_len bytes long. */ char * -decode_encoded_buffer(struct stream_encoded *stream, enum stream_encoding encoding, char *data, int len, +decode_encoded_buffer(struct stream_encoded *stream, stream_encoding_T encoding, char *data, int len, int *new_len) { return decoding_backends[encoding]->decode_buffer(stream, data, len, new_len); @@ -151,12 +151,12 @@ close_encoded(struct stream_encoded *stream) /* Return a list of extensions associated with that encoding. */ -const char *const *listext_encoded(enum stream_encoding encoding) +const char *const *listext_encoded(stream_encoding_T encoding) { return decoding_backends[encoding]->extensions; } -enum stream_encoding +stream_encoding_T guess_encoding(char *filename) { int fname_len = strlen(filename); @@ -180,7 +180,7 @@ guess_encoding(char *filename) } const char * -get_encoding_name(enum stream_encoding encoding) +get_encoding_name(stream_encoding_T encoding) { return decoding_backends[encoding]->name; } @@ -190,7 +190,7 @@ get_encoding_name(enum stream_encoding encoding) /* Tries to open @prefixname with each of the supported encoding extensions * appended. */ -static inline enum stream_encoding +static inline stream_encoding_T try_encoding_extensions(struct string *filename, int *fd) { int length = filename->length; @@ -299,7 +299,7 @@ read_encoded_file(struct string *filename, struct string *page) { struct stream_encoded *stream; struct stat stt; - enum stream_encoding encoding = ENCODING_NONE; + stream_encoding_T encoding = ENCODING_NONE; int fd = open(filename->source, O_RDONLY | O_NOCTTY); struct connection_state state = connection_state_for_errno(errno); diff --git a/src/encoding/encoding.h b/src/encoding/encoding.h index b5711d714..1593368a8 100644 --- a/src/encoding/encoding.h +++ b/src/encoding/encoding.h @@ -20,8 +20,10 @@ enum stream_encoding { ENCODINGS_KNOWN, }; +typedef unsigned char stream_encoding_T; + struct stream_encoded { - enum stream_encoding encoding; + stream_encoding_T encoding; void *data; }; @@ -34,14 +36,14 @@ struct decoding_backend { void (*close)(struct stream_encoded *stream); }; -struct stream_encoded *open_encoded(int, enum stream_encoding); +struct stream_encoded *open_encoded(int, stream_encoding_T); int read_encoded(struct stream_encoded *, char *, int); -char *decode_encoded_buffer(struct stream_encoded *stream, enum stream_encoding encoding, char *data, int len, int *new_len); +char *decode_encoded_buffer(struct stream_encoded *stream, stream_encoding_T encoding, char *data, int len, int *new_len); void close_encoded(struct stream_encoded *); -const char *const *listext_encoded(enum stream_encoding); -enum stream_encoding guess_encoding(char *filename); -const char *get_encoding_name(enum stream_encoding encoding); +const char *const *listext_encoded(stream_encoding_T); +stream_encoding_T guess_encoding(char *filename); +const char *get_encoding_name(stream_encoding_T encoding); /* Read from open @stream into the @page string */ struct connection_state diff --git a/src/mime/mime.c b/src/mime/mime.c index e25bd007b..465803945 100644 --- a/src/mime/mime.c +++ b/src/mime/mime.c @@ -131,7 +131,7 @@ check_extension_type(char *extension) static inline char * check_encoding_type(char *extension) { - enum stream_encoding encoding = guess_encoding(extension); + stream_encoding_T encoding = guess_encoding(extension); const char *const *extension_list; char *last_extension = strrchr(extension, '.'); diff --git a/src/network/connection.h b/src/network/connection.h index 1f5111f80..a1b427628 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -45,7 +45,7 @@ struct connection { off_t received; /* The number of received bytes. */ off_t est_length; /* Estimated number of bytes to transfer. */ - enum stream_encoding content_encoding; + stream_encoding_T content_encoding; struct stream_encoded *stream; /* Called if non NULL when shutting down a connection. */ diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c index 5e1c3db2b..729f196bf 100644 --- a/src/protocol/http/http.c +++ b/src/protocol/http/http.c @@ -1874,7 +1874,7 @@ again: if (d) { #if defined(CONFIG_GZIP) || defined(CONFIG_BZIP2) || defined(CONFIG_LZMA) || defined(CONFIG_BROTLI) || defined(CONFIG_ZSTD) char *extension = get_extension_from_uri(uri); - enum stream_encoding file_encoding; + stream_encoding_T file_encoding; file_encoding = extension ? guess_encoding(extension) : ENCODING_NONE; mem_free_if(extension);