istream-hash.c revision 202a34580f6204672d9b0d6a0756f35a3c4cdef6
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Siraineni_stream_hash_read(struct istream_private *stream)
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen struct hash_istream *hstream = (struct hash_istream *)stream;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen const unsigned char *data;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen i_stream_seek(stream->parent, stream->parent_start_offset +
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen ret = i_stream_read_copy_from_parent(&stream->istream);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen if (ret > 0 && hstream->hash_context != NULL) {
373492be949e159fda651807b3acda2c5c077027Timo Sirainen data = i_stream_get_data(&stream->istream, &size);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen i_assert(stream->istream.v_offset <= hstream->high_offset);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen skip = hstream->high_offset - stream->istream.v_offset;
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen } else if (ret < 0) {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* we finished hashing it. don't access it anymore, because
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen the memory pointed by the hash may be freed before the
635df5b4cbcd7b24c825e01d9dd66d3a4274c4c7Timo Sirainen istream itself */
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Siraineni_stream_hash_seek(struct istream_private *stream,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen struct hash_istream *hstream = (struct hash_istream *)stream;
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen /* we support seeking only after the hash is finished */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Siraineni_stream_create_hash(struct istream *input, const struct hash_method *method,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen hstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen hstream->istream.stream_size_passthrough = TRUE;
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen hstream->istream.istream.blocking = input->blocking;
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen hstream->istream.istream.seekable = input->seekable;