8d96d5b3a759119baa5937624b8716c8abb4d572jroberts#ifndef ISTREAM_HEADER_FILTER_H
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts#define ISTREAM_HEADER_FILTER_H
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts
8d96d5b3a759119baa5937624b8716c8abb4d572jrobertsstruct header_filter_istream;
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts
8d96d5b3a759119baa5937624b8716c8abb4d572jrobertsenum header_filter_flags {
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* Include only specified headers in output.*/
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_INCLUDE = 0x01,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* Exclude specified headers from output. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_EXCLUDE = 0x02,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* Use LF linefeeds instead of CRLF. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_NO_CR = 0x04,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* Return EOF at the beginning of message body. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_HIDE_BODY = 0x08,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* If the empty "end of headers" line doesn't exist, add it. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_ADD_MISSING_EOH = 0x10,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* If body doesn't end with [CR]LF, add it/them. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_END_BODY_WITH_LF = 0x20,
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts /* Preserve the original LF or CRLF. */
8d96d5b3a759119baa5937624b8716c8abb4d572jroberts HEADER_FILTER_CRLF_PRESERVE = 0x40
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro};
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbelorostruct message_header_line;
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbelorotypedef void header_filter_callback(struct header_filter_istream *input,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro struct message_header_line *hdr,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro bool *matched, void *context);
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloroextern header_filter_callback *null_header_filter_callback;
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro/* NOTE: headers list must be sorted. */
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbelorostruct istream *
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloroi_stream_create_header_filter(struct istream *input,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro enum header_filter_flags flags,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro const char *const *headers,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro unsigned int headers_count,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro header_filter_callback *callback, void *context)
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro ATTR_NULL(6);
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro#define i_stream_create_header_filter(input, flags, headers, headers_count, \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro callback, context) \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro i_stream_create_header_filter(input, flags, headers, headers_count + \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro CALLBACK_TYPECHECK(callback, void (*)( \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro struct header_filter_istream *, \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro struct message_header_line *, bool *, typeof(context))), \
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro (header_filter_callback *)callback, context)
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro/* Add more data to headers. Should called from the filter callback. */
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbelorovoid i_stream_header_filter_add(struct header_filter_istream *input,
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro const void *data, size_t size);
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro#endif
d58fda4376e4bf67072ce2e69f6f47036f9dbb68jbeloro