istream.c revision d6684856fb99e51bc22a6346e08b2d81c996f963
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenstatic bool i_stream_is_buffer_invalid(const struct istream_private *stream);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_set_name(struct istream *stream, const char *name)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen stream->real_stream->iostream.name = i_strdup(name);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenconst char *i_stream_get_name(struct istream *stream)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen while (stream->real_stream->iostream.name == NULL) {
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenstatic void i_stream_close_full(struct istream *stream, bool close_parents)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_close(&stream->real_stream->iostream, close_parents);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_ref(&stream->real_stream->iostream);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen struct istream_private *_stream = (*stream)->real_stream;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen if (!io_stream_unref(&(*stream)->real_stream->iostream)) {
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_stream_unref(&(*stream)->real_stream->parent);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_free(&(*stream)->real_stream->iostream);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_add_destroy_callback(struct istream *stream,
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_add_destroy_callback(&stream->real_stream->iostream,
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_remove_destroy_callback(struct istream *stream,
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_remove_destroy_callback(&stream->real_stream->iostream,
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen struct istream_private *_stream = stream->real_stream;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenconst char *i_stream_get_error(struct istream *stream)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen /* we'll only return errors for streams that have stream_errno set or
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen that have reached EOF. we might be returning unintended error
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen otherwise. */
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen for (s = stream; s != NULL; s = s->real_stream->parent) {
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenconst char *i_stream_get_disconnect_reason(struct istream *stream)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen return io_stream_get_disconnect_reason(stream, NULL);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_set_init_buffer_size(struct istream *stream, size_t size)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_set_max_buffer_size(struct istream *stream, size_t max_size)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen io_stream_set_max_buffer_size(&stream->real_stream->iostream, max_size);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainensize_t i_stream_get_max_buffer_size(struct istream *stream)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen if (max_size < stream->real_stream->max_buffer_size)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen max_size = stream->real_stream->max_buffer_size;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_set_return_partial_line(struct istream *stream, bool set)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenvoid i_stream_set_persistent_buffers(struct istream *stream, bool set)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen stream->real_stream->nonpersistent_buffers = !set;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainenstatic void i_stream_update(struct istream_private *stream)
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen stream->parent_expected_offset = stream->parent->v_offset;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen struct istream_private *_stream = stream->real_stream;
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen if (unlikely(stream->closed || stream->stream_errno != 0)) {
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_stream_seek(_stream->parent, _stream->parent_expected_offset);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_assert(old_size <= _stream->pos - _stream->skip);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen /* error handling should be easier if we now just
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen assume the stream is now at EOF */
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_assert(old_size == _stream->pos - _stream->skip);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_assert((size_t)ret+old_size == _stream->pos - _stream->skip);
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen /* error handling should be easier if we now just
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen assume the stream is now at EOF. Note that we could get here
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen even if read() didn't return -1, although that's a little
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen bit sloppy istream implementation. */
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen /* verify that parents' access_counters are valid. the parent's
1537d20b852cbbf0d6971790b84e0cce5ca61307Timo Sirainen i_stream_read() should guarantee this. */
return ret;
ret = 0;
return ret;
return TRUE;
return FALSE;
int ret;
return ret;
return abs_offset;
char *ret;
end = i;
return ret;
return NULL;
const unsigned char *pos;
return NULL;
char *line;
return NULL;
return NULL;
return line;
return FALSE;
return FALSE;
return TRUE;
*size_r = 0;
return uchar_empty_ptr;
*size_r = 0;
return uchar_empty_ptr;
return size;
*size_r = 0;
return NULL;
if (ret > 0)
} while (ret > 0);
if (ret == 0) {
if (read_more) {
return *size_r > 0;
return FALSE;
return TRUE;
if (!pending)
bool close_parent)
if (available == 0) {
struct istream *
struct istream *
return input;