1156230Smux/*-
2156230Smux * Copyright (c) 2003-2006, Maxime Henrion <mux@FreeBSD.org>
3156230Smux * All rights reserved.
4156230Smux *
5156230Smux * Redistribution and use in source and binary forms, with or without
6156230Smux * modification, are permitted provided that the following conditions
7156230Smux * are met:
8156230Smux * 1. Redistributions of source code must retain the above copyright
9156230Smux *    notice, this list of conditions and the following disclaimer.
10156230Smux * 2. Redistributions in binary form must reproduce the above copyright
11156230Smux *    notice, this list of conditions and the following disclaimer in the
12156230Smux *    documentation and/or other materials provided with the distribution.
13156230Smux *
14156230Smux * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15156230Smux * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16156230Smux * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17156230Smux * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18156230Smux * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19156230Smux * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20156230Smux * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21156230Smux * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22156230Smux * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23156230Smux * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24156230Smux * SUCH DAMAGE.
25156230Smux *
26156230Smux * $FreeBSD$
27156230Smux */
28156230Smux#ifndef _STREAM_H_
29156230Smux#define _STREAM_H_
30156230Smux
31156230Smux#include "misc.h"
32156230Smux
33156230Smux/* Stream filters. */
34156230Smuxtypedef enum {
35156230Smux	STREAM_FILTER_NULL,
36156230Smux	STREAM_FILTER_ZLIB,
37186781Slulf	STREAM_FILTER_MD5,
38186781Slulf	STREAM_FILTER_MD5RCS
39156230Smux} stream_filter_t;
40156230Smux
41156230Smuxstruct stream;
42186781Slulfstruct buf;
43156230Smux
44156230Smuxtypedef ssize_t	stream_readfn_t(void *, void *, size_t);
45156230Smuxtypedef ssize_t	stream_writefn_t(void *, const void *, size_t);
46156230Smuxtypedef int	stream_closefn_t(void *);
47156230Smux
48156230Smux/* Convenience functions for handling file descriptors. */
49156230Smuxstream_readfn_t		stream_read_fd;
50156230Smuxstream_writefn_t	stream_write_fd;
51156230Smuxstream_closefn_t	stream_close_fd;
52156230Smux
53186781Slulf/* Convenience functions for handling character buffers. */
54186781Slulfstream_readfn_t		stream_read_buf;
55186781Slulfstream_writefn_t	stream_append_buf;
56186781Slulfstream_closefn_t	stream_close_buf;
57186781Slulf
58156230Smuxstruct stream	*stream_open(void *, stream_readfn_t *, stream_writefn_t *,
59156230Smux		     stream_closefn_t *);
60156230Smuxstruct stream	*stream_open_fd(int, stream_readfn_t *, stream_writefn_t *,
61156230Smux		     stream_closefn_t *);
62186781Slulfstruct stream	*stream_open_buf(struct buf *);
63156230Smuxstruct stream	*stream_open_file(const char *, int, ...);
64156230Smuxint		 stream_fileno(struct stream *);
65156230Smuxssize_t		 stream_read(struct stream *, void *, size_t);
66186781Slulfssize_t		 stream_read_blocking(struct stream *, void *, size_t);
67156230Smuxssize_t		 stream_write(struct stream *, const void *, size_t);
68156230Smuxchar		*stream_getln(struct stream *, size_t *);
69156230Smuxint		 stream_printf(struct stream *, const char *, ...)
70156230Smux		     __printflike(2, 3);
71156230Smuxint		 stream_flush(struct stream *);
72156230Smuxint		 stream_sync(struct stream *);
73156230Smuxint		 stream_truncate(struct stream *, off_t);
74186781Slulfvoid		 stream_truncate_buf(struct buf *, off_t);
75156230Smuxint		 stream_truncate_rel(struct stream *, off_t);
76156230Smuxint		 stream_rewind(struct stream *);
77156230Smuxint		 stream_eof(struct stream *);
78156230Smuxint		 stream_close(struct stream *);
79156230Smuxint		 stream_filter_start(struct stream *, stream_filter_t, void *);
80156230Smuxvoid		 stream_filter_stop(struct stream *);
81156230Smux
82186781Slulfstruct buf	*buf_new(size_t);
83186781Slulfvoid		 buf_free(struct buf *);
84156230Smux#endif /* !_STREAM_H_ */
85