2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__ENCODING_ENCODING_H
|
|
|
|
#define EL__ENCODING_ENCODING_H
|
|
|
|
|
|
|
|
#include "network/state.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
enum stream_encoding {
|
|
|
|
ENCODING_NONE = 0,
|
|
|
|
ENCODING_GZIP,
|
|
|
|
ENCODING_BZIP2,
|
2006-03-24 06:30:54 -05:00
|
|
|
ENCODING_LZMA,
|
2015-10-12 17:18:23 -04:00
|
|
|
ENCODING_BROTLI,
|
2019-07-14 12:54:39 -04:00
|
|
|
ENCODING_ZSTD,
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Max. number of known encoding including ENCODING_NONE. */
|
|
|
|
ENCODINGS_KNOWN,
|
|
|
|
};
|
|
|
|
|
2022-01-28 10:17:25 -05:00
|
|
|
typedef unsigned char stream_encoding_T;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct stream_encoded {
|
2022-01-28 10:17:25 -05:00
|
|
|
stream_encoding_T encoding;
|
2005-09-15 09:58:31 -04:00
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct decoding_backend {
|
2021-01-02 10:20:27 -05:00
|
|
|
const char *name;
|
|
|
|
const char *const *extensions;
|
2022-05-09 12:53:36 -04:00
|
|
|
int (*eopen)(struct stream_encoded *stream, int fd);
|
|
|
|
int (*eread)(struct stream_encoded *stream, char *data, int len);
|
2021-01-02 10:20:27 -05:00
|
|
|
char *(*decode_buffer)(struct stream_encoded *stream, char *data, int len, int *new_len);
|
2022-05-09 12:53:36 -04:00
|
|
|
void (*eclose)(struct stream_encoded *stream);
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
2022-01-28 10:17:25 -05:00
|
|
|
struct stream_encoded *open_encoded(int, stream_encoding_T);
|
2021-01-02 10:20:27 -05:00
|
|
|
int read_encoded(struct stream_encoded *, char *, int);
|
2022-01-28 10:17:25 -05:00
|
|
|
char *decode_encoded_buffer(struct stream_encoded *stream, stream_encoding_T encoding, char *data, int len, int *new_len);
|
2005-09-15 09:58:31 -04:00
|
|
|
void close_encoded(struct stream_encoded *);
|
|
|
|
|
2022-01-28 10:17:25 -05:00
|
|
|
const char *const *listext_encoded(stream_encoding_T);
|
|
|
|
stream_encoding_T guess_encoding(char *filename);
|
|
|
|
const char *get_encoding_name(stream_encoding_T encoding);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Read from open @stream into the @page string */
|
2008-08-03 08:24:26 -04:00
|
|
|
struct connection_state
|
2019-04-21 06:27:40 -04:00
|
|
|
read_file(struct stream_encoded *stream, int readsize, struct string *page);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Reads the file with the given @filename into the string @source. */
|
2019-04-21 06:27:40 -04:00
|
|
|
struct connection_state read_encoded_file(struct string *filename, struct string *source);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|