bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomio_stream_escaped_send_outbuf(struct escaped_ostream *estream)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi ret = o_stream_send(estream->ostream.parent, str_data(estream->buf), str_len(estream->buf));
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi o_stream_copy_error_from_parent(&estream->ostream);
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi /* move data */
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomio_stream_escaped_send_chunk(struct escaped_ostream *estream,
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi max_buffer_size = I_MIN(o_stream_get_max_buffer_size(estream->ostream.parent),
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi /* avoid using up too much memory in case of large buffers */
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi for (i = 0; i < len; i++) {
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi if (str_len(estream->buf) + 2 > max_buffer_size) { /* escaping takes at least two bytes */
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomio_stream_escaped_sendv(struct ostream_private *stream,
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi const struct const_iovec *iov, unsigned int iov_count)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi struct escaped_ostream *estream = (struct escaped_ostream *)stream;
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi for (iov_cur = 0; iov_cur < iov_count; iov_cur++) {
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomio_stream_escaped_flush(struct ostream_private *stream)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi struct escaped_ostream *estream = (struct escaped_ostream *)stream;
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi if ((ret = o_stream_escaped_send_outbuf(estream)) <= 0)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomistatic void o_stream_escaped_destroy(struct iostream_private *stream)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi struct escaped_ostream *estream = (struct escaped_ostream *)stream;
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomivoid ostream_escaped_hex_format(string_t *dest, unsigned char chr)
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi estream->ostream.max_buffer_size = o_stream_get_max_buffer_size(output);
662bb64be818407c6719a69780411f7ca8d6c96fAki Tuomi estream->ostream.iostream.destroy = o_stream_escaped_destroy;