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