istream-private.h revision e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9e
c977374bd4651cafc1626ebe308aa66dfd8b30e0Timo Sirainen/* inheritance: */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* methods: */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ssize_t (*read)(struct istream_private *stream);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*stat)(struct istream_private *stream, bool exact);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*get_size)(struct istream_private *stream, bool exact, uoff_t *size_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen void (*switch_ioloop)(struct istream_private *stream);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* added by io_add_istream() -> i_stream_set_io() */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen const unsigned char *buffer;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen size_t buffer_size, max_buffer_size, init_buffer_size;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen struct istream *parent; /* for filter streams */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* parent stream's expected offset is kept here. i_stream_read()
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen always seeks parent stream to here before calling read(). */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* increased every time the stream is changed (e.g. seek, read).
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen this way streams can check if their parent streams have been
461ffead9720d1e516b959d5e41f049c73d38c7cTimo Sirainen accessed behind them. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool stream_size_passthrough:1; /* stream is parent's size */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* The stream guarantees that the buffer pointer stays valid when it
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen returns <= 0. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Siraineni_stream_create(struct istream_private *stream, struct istream *parent, int fd,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Initialize parent lazily after i_stream_create() has already been called. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid i_stream_init_parent(struct istream_private *_stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid i_stream_compress(struct istream_private *stream);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid i_stream_grow_buffer(struct istream_private *stream, size_t bytes);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Siraineni_stream_try_alloc(struct istream_private *stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Like i_stream_try_alloc(), but compress only if it's the only way to get
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen more space. This can be useful when stream is marked with
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen i_stream_seek_mark() */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Siraineni_stream_try_alloc_avoid_compress(struct istream_private *stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid *i_stream_alloc(struct istream_private *stream, size_t size);
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainen/* Free memory allocated by i_stream_*alloc() */
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainenvoid i_stream_free_buffer(struct istream_private *stream);
d22301419109ed4a38351715e6760011421dadecTimo Sirainenssize_t i_stream_read_copy_from_parent(struct istream *istream);
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainenvoid i_stream_default_seek_nonseekable(struct istream_private *stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Default snapshot handling: use memarea if it exists, otherwise snapshot
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen parent stream. */
637455ebee0453f860c9bce0626c485e35fb83deTimo Siraineni_stream_default_snapshot(struct istream_private *stream,
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainenvoid i_stream_snapshot_free(struct istream_snapshot **snapshot);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid i_stream_set_io(struct istream *stream, struct io *io);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid i_stream_unset_io(struct istream *stream, struct io *io);
03010dbaa74ec70f062994dfe3cd39bedc99a28bTimo Sirainen/* Filter istreams should be calling this instead of i_stream_read() to avoid
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainen unnecessarily referencing memareas. After this call any pointers to the
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainen parent istream's content must be considered as potentially invalid and have
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainen to be updated, even if the return value is <=0. */
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainenssize_t i_stream_read_memarea(struct istream *stream);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint i_stream_read_more_memarea(struct istream *stream,
637455ebee0453f860c9bce0626c485e35fb83deTimo Sirainen const unsigned char **data_r, size_t *size_r);