1 #ifndef EL__ENCODING_ENCODING_H
2 #define EL__ENCODING_ENCODING_H
4 #include "network/state.h"
5 #include "util/string.h"
14 /* Max. number of known encoding including ENCODING_NONE. */
18 struct stream_encoded
{
19 enum stream_encoding encoding
;
23 struct decoding_backend
{
24 const unsigned char *name
;
25 const unsigned char *const *extensions
;
26 int (*open
)(struct stream_encoded
*stream
, int fd
);
27 int (*read
)(struct stream_encoded
*stream
, unsigned char *data
, int len
);
28 unsigned char *(*decode_buffer
)(struct stream_encoded
*stream
, unsigned char *data
, int len
, int *new_len
);
29 void (*close
)(struct stream_encoded
*stream
);
32 struct stream_encoded
*open_encoded(int, enum stream_encoding
);
33 int read_encoded(struct stream_encoded
*, unsigned char *, int);
34 unsigned char *decode_encoded_buffer(struct stream_encoded
*stream
, enum stream_encoding encoding
, unsigned char *data
, int len
, int *new_len
);
35 void close_encoded(struct stream_encoded
*);
37 const unsigned char *const *listext_encoded(enum stream_encoding
);
38 enum stream_encoding
guess_encoding(unsigned char *filename
);
39 const unsigned char *get_encoding_name(enum stream_encoding encoding
);
41 /* Read from open @stream into the @page string */
42 struct connection_state
43 read_file(struct stream_encoded
*stream
, int readsize
, struct string
*page
);
45 /* Reads the file with the given @filename into the string @source. */
46 struct connection_state
read_encoded_file(struct string
*filename
, struct string
*source
);