istream-crlf.c revision 1a266561b099269bef75eee1a3742e61130ef780
183bea41fa640dc8117f3eb45ff935cd81377a84Timo Sirainen/* Copyright (c) 2007 Dovecot authors, see the included COPYING file */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic void i_stream_crlf_destroy(struct iostream_private *stream)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen struct crlf_istream *cstream = (struct crlf_istream *)stream;
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Siraineni_stream_crlf_set_max_buffer_size(struct iostream_private *stream,
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen struct crlf_istream *cstream = (struct crlf_istream *)stream;
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen i_stream_set_max_buffer_size(cstream->input, max_size);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic ssize_t i_stream_crlf_read(struct istream_private *stream)
af1f4b17a92ca7b2661737e65c7849df289d3070Timo Sirainen struct crlf_istream *cstream = (struct crlf_istream *)stream;
af1f4b17a92ca7b2661737e65c7849df289d3070Timo Sirainen const unsigned char *data;
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen data = i_stream_get_data(cstream->input, &size);
d22301419109ed4a38351715e6760011421dadecTimo Sirainen if (ret <= 0 && (ret != -2 || stream->skip == 0)) {
b12a6d0e54318273acf0d0fb8b3f4c29f67b62b0Timo Sirainen data = i_stream_get_data(cstream->input, &size);
b12a6d0e54318273acf0d0fb8b3f4c29f67b62b0Timo Sirainen if (!i_stream_get_buffer_space(stream, size, NULL))
73247459cf41eb1e5ae5bc61354db46d3b05ee75Timo Sirainen /* @UNSAFE */
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen /* CR without LF */
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen for (; i < size && dest < stream->buffer_size; i++) {
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen /* CR without LF */
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen i_assert(cstream->last_char == '\r' && size == 1);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Siraineni_stream_crlf_seek(struct istream_private *stream ATTR_UNUSED,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen uoff_t v_offset ATTR_UNUSED, bool mark ATTR_UNUSED)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen i_panic("crlf-istream: seeking unsupported currently");
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic const struct stat *
4b41116563110d00330896a568eff1078c382827Timo Siraineni_stream_crlf_stat(struct istream_private *stream, bool exact)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen struct crlf_istream *cstream = (struct crlf_istream *)stream;
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainenstatic struct istream *
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Siraineni_stream_create_crlf_full(struct istream *input, bool crlf)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen cstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen cstream->istream.iostream.destroy = i_stream_crlf_destroy;
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen cstream->istream.iostream.set_max_buffer_size =
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen cstream->istream.istream.blocking = input->blocking;
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen cstream->istream.istream.seekable = input->seekable;
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen return i_stream_create(&cstream->istream, i_stream_get_fd(input), 0);
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainenstruct istream *i_stream_create_crlf(struct istream *input)
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainen return i_stream_create_crlf_full(input, TRUE);
5daa12cc1c862eec4f63df42227812d3514da2ccTimo Sirainenstruct istream *i_stream_create_lf(struct istream *input)