129088Smarkm/*
229088Smarkm * Copyright (c) 1988, 1993
329088Smarkm *	The Regents of the University of California.  All rights reserved.
429088Smarkm *
529088Smarkm * Redistribution and use in source and binary forms, with or without
629088Smarkm * modification, are permitted provided that the following conditions
729088Smarkm * are met:
829088Smarkm * 1. Redistributions of source code must retain the above copyright
929088Smarkm *    notice, this list of conditions and the following disclaimer.
1029088Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1129088Smarkm *    notice, this list of conditions and the following disclaimer in the
1229088Smarkm *    documentation and/or other materials provided with the distribution.
13351432Semaste * 3. Neither the name of the University nor the names of its contributors
1429088Smarkm *    may be used to endorse or promote products derived from this software
1529088Smarkm *    without specific prior written permission.
1629088Smarkm *
1729088Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1829088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1929088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2029088Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2129088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2229088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2329088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2429088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2529088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2629088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2729088Smarkm * SUCH DAMAGE.
2829088Smarkm *
2929088Smarkm *	@(#)ring.h	8.1 (Berkeley) 6/6/93
3081965Smarkm * $FreeBSD: stable/11/contrib/telnet/telnet/ring.h 351432 2019-08-23 17:40:47Z emaste $
3129088Smarkm */
3229088Smarkm
3329088Smarkm#if defined(P)
3429088Smarkm# undef P
3529088Smarkm#endif
3629088Smarkm
3729088Smarkm#if defined(__STDC__) || defined(LINT_ARGS)
3829088Smarkm# define	P(x)	x
3929088Smarkm#else
4029088Smarkm# define	P(x)	()
4129088Smarkm#endif
4229088Smarkm
4329088Smarkm/*
4429088Smarkm * This defines a structure for a ring buffer.
4529088Smarkm *
4629088Smarkm * The circular buffer has two parts:
4729088Smarkm *(((
4829088Smarkm *	full:	[consume, supply)
4929088Smarkm *	empty:	[supply, consume)
5029088Smarkm *]]]
5129088Smarkm *
5229088Smarkm */
5329088Smarkmtypedef struct {
5429088Smarkm    unsigned char	*consume,	/* where data comes out of */
5529088Smarkm			*supply,	/* where data comes in to */
5629088Smarkm			*bottom,	/* lowest address in buffer */
5729088Smarkm			*top,		/* highest address+1 in buffer */
5829088Smarkm			*mark;		/* marker (user defined) */
5929088Smarkm#ifdef	ENCRYPTION
6029088Smarkm    unsigned char	*clearto;	/* Data to this point is clear text */
6129088Smarkm    unsigned char	*encryyptedto;	/* Data is encrypted to here */
6229088Smarkm#endif	/* ENCRYPTION */
6329088Smarkm    int		size;		/* size in bytes of buffer */
6429088Smarkm    u_long	consumetime,	/* help us keep straight full, empty, etc. */
6529088Smarkm		supplytime;
6629088Smarkm} Ring;
6729088Smarkm
6829088Smarkm/* Here are some functions and macros to deal with the ring buffer */
6929088Smarkm
7029088Smarkm/* Initialization routine */
7129088Smarkmextern int
7287155Smarkm	ring_init(Ring *ring, unsigned char *buffer, int count);
7329088Smarkm
7429088Smarkm/* Data movement routines */
7529088Smarkmextern void
7687155Smarkm	ring_supply_data(Ring *ring, unsigned char *buffer, int count);
7729088Smarkm#ifdef notdef
7829088Smarkmextern void
7987155Smarkm	ring_consume_data(Ring *ring, unsigned char *buffer, int count);
8029088Smarkm#endif
8129088Smarkm
8229088Smarkm/* Buffer state transition routines */
8329088Smarkmextern void
8487155Smarkm	ring_supplied(Ring *ring, int count),
8587155Smarkm	ring_consumed(Ring *ring, int count);
8629088Smarkm
8729088Smarkm/* Buffer state query routines */
8829088Smarkmextern int
8987155Smarkm	ring_at_mark(Ring *),
9087155Smarkm	ring_empty_count(Ring *ring),
9187155Smarkm	ring_empty_consecutive(Ring *ring),
9287155Smarkm	ring_full_count(Ring *ring),
9387155Smarkm	ring_full_consecutive(Ring *ring);
9429088Smarkm
9529088Smarkm#ifdef	ENCRYPTION
9629088Smarkmextern void
9787155Smarkm	ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)),
9887155Smarkm	ring_clearto(Ring *ring);
9929088Smarkm#endif	/* ENCRYPTION */
10029088Smarkm
10129088Smarkmextern void
10287155Smarkm	ring_clear_mark(Ring *),
10387155Smarkm	ring_mark(Ring *);
104