istream-internal.h revision 61e6367a259e2473f33df42fda8ceeb3b8b48416
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainen#ifndef ISTREAM_INTERNAL_H
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#define ISTREAM_INTERNAL_H
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen#include "istream.h"
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#include "iostream-internal.h"
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen#define I_STREAM_MIN_SIZE 4096
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstruct istream_private {
b8835b8a21c617ceb82ddc5a176243faf36aa8f7Timo Sirainen/* inheritance: */
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen struct iostream_private iostream;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen/* methods: */
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen ssize_t (*read)(struct istream_private *stream);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen void (*seek)(struct istream_private *stream,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen uoff_t v_offset, bool mark);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen void (*sync)(struct istream_private *stream);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const struct stat *(*stat)(struct istream_private *stream, bool exact);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen int (*get_size)(struct istream_private *stream, bool exact, uoff_t *size_r);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* data: */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct istream istream;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen int fd;
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen uoff_t abs_start_offset;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct stat statbuf;
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainen
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainen const unsigned char *buffer;
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainen unsigned char *w_buffer; /* may be NULL */
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainen
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainen size_t buffer_size, max_buffer_size;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen size_t skip, pos;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen struct istream *parent; /* for filter streams */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen uoff_t parent_start_offset;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen unsigned int return_nolf_line:1;
0fd246126fece57712566c725d6353f255f5fcfaTimo Sirainen};
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstruct istream *
88dc563319efecd6e68bad16b0d92672da05584aTimo Siraineni_stream_create(struct istream_private *stream, struct istream *parent, int fd);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainenvoid i_stream_compress(struct istream_private *stream);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenvoid i_stream_grow_buffer(struct istream_private *stream, size_t bytes);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenbool i_stream_get_buffer_space(struct istream_private *stream,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen size_t wanted_size, size_t *size_r);
a0c453a8edaec90fb0d945c874de0b1845bc7d7eTimo Sirainenssize_t i_stream_read_copy_from_parent(struct istream *istream);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen#endif
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen