18d5a6048SAxel Dörfler/*
28d5a6048SAxel Dörfler * Copyright (c) 1988, 1993
38d5a6048SAxel Dörfler *	The Regents of the University of California.  All rights reserved.
48d5a6048SAxel Dörfler *
58d5a6048SAxel Dörfler * Redistribution and use in source and binary forms, with or without
68d5a6048SAxel Dörfler * modification, are permitted provided that the following conditions
78d5a6048SAxel Dörfler * are met:
88d5a6048SAxel Dörfler * 1. Redistributions of source code must retain the above copyright
98d5a6048SAxel Dörfler *    notice, this list of conditions and the following disclaimer.
108d5a6048SAxel Dörfler * 2. Redistributions in binary form must reproduce the above copyright
118d5a6048SAxel Dörfler *    notice, this list of conditions and the following disclaimer in the
128d5a6048SAxel Dörfler *    documentation and/or other materials provided with the distribution.
138d5a6048SAxel Dörfler * 3. All advertising materials mentioning features or use of this software
148d5a6048SAxel Dörfler *    must display the following acknowledgement:
158d5a6048SAxel Dörfler *	This product includes software developed by the University of
168d5a6048SAxel Dörfler *	California, Berkeley and its contributors.
178d5a6048SAxel Dörfler * 4. Neither the name of the University nor the names of its contributors
188d5a6048SAxel Dörfler *    may be used to endorse or promote products derived from this software
198d5a6048SAxel Dörfler *    without specific prior written permission.
208d5a6048SAxel Dörfler *
218d5a6048SAxel Dörfler * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228d5a6048SAxel Dörfler * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238d5a6048SAxel Dörfler * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248d5a6048SAxel Dörfler * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258d5a6048SAxel Dörfler * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268d5a6048SAxel Dörfler * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278d5a6048SAxel Dörfler * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288d5a6048SAxel Dörfler * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298d5a6048SAxel Dörfler * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308d5a6048SAxel Dörfler * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318d5a6048SAxel Dörfler * SUCH DAMAGE.
328d5a6048SAxel Dörfler *
338d5a6048SAxel Dörfler *	@(#)ring.h	8.1 (Berkeley) 6/6/93
348d5a6048SAxel Dörfler * $FreeBSD: src/contrib/telnet/telnet/ring.h,v 1.4 2001/11/30 22:28:07 markm Exp $
358d5a6048SAxel Dörfler */
368d5a6048SAxel Dörfler
378d5a6048SAxel Dörfler#if defined(P)
388d5a6048SAxel Dörfler# undef P
398d5a6048SAxel Dörfler#endif
408d5a6048SAxel Dörfler
418d5a6048SAxel Dörfler#if defined(__STDC__) || defined(LINT_ARGS)
428d5a6048SAxel Dörfler# define	P(x)	x
438d5a6048SAxel Dörfler#else
448d5a6048SAxel Dörfler# define	P(x)	()
458d5a6048SAxel Dörfler#endif
468d5a6048SAxel Dörfler
478d5a6048SAxel Dörfler/*
488d5a6048SAxel Dörfler * This defines a structure for a ring buffer.
498d5a6048SAxel Dörfler *
508d5a6048SAxel Dörfler * The circular buffer has two parts:
518d5a6048SAxel Dörfler *(((
528d5a6048SAxel Dörfler *	full:	[consume, supply)
538d5a6048SAxel Dörfler *	empty:	[supply, consume)
548d5a6048SAxel Dörfler *]]]
558d5a6048SAxel Dörfler *
568d5a6048SAxel Dörfler */
578d5a6048SAxel Dörflertypedef struct {
588d5a6048SAxel Dörfler    unsigned char	*consume,	/* where data comes out of */
598d5a6048SAxel Dörfler			*supply,	/* where data comes in to */
608d5a6048SAxel Dörfler			*bottom,	/* lowest address in buffer */
618d5a6048SAxel Dörfler			*top,		/* highest address+1 in buffer */
628d5a6048SAxel Dörfler			*mark;		/* marker (user defined) */
638d5a6048SAxel Dörfler#ifdef	ENCRYPTION
648d5a6048SAxel Dörfler    unsigned char	*clearto;	/* Data to this point is clear text */
658d5a6048SAxel Dörfler    unsigned char	*encryyptedto;	/* Data is encrypted to here */
668d5a6048SAxel Dörfler#endif	/* ENCRYPTION */
678d5a6048SAxel Dörfler    int		size;		/* size in bytes of buffer */
688d5a6048SAxel Dörfler    u_long	consumetime,	/* help us keep straight full, empty, etc. */
698d5a6048SAxel Dörfler		supplytime;
708d5a6048SAxel Dörfler} Ring;
718d5a6048SAxel Dörfler
728d5a6048SAxel Dörfler/* Here are some functions and macros to deal with the ring buffer */
738d5a6048SAxel Dörfler
748d5a6048SAxel Dörfler/* Initialization routine */
758d5a6048SAxel Dörflerextern int
768d5a6048SAxel Dörfler	ring_init(Ring *ring, unsigned char *buffer, int count);
778d5a6048SAxel Dörfler
788d5a6048SAxel Dörfler/* Data movement routines */
798d5a6048SAxel Dörflerextern void
808d5a6048SAxel Dörfler	ring_supply_data(Ring *ring, unsigned char *buffer, int count);
818d5a6048SAxel Dörfler#ifdef notdef
828d5a6048SAxel Dörflerextern void
838d5a6048SAxel Dörfler	ring_consume_data(Ring *ring, unsigned char *buffer, int count);
848d5a6048SAxel Dörfler#endif
858d5a6048SAxel Dörfler
868d5a6048SAxel Dörfler/* Buffer state transition routines */
878d5a6048SAxel Dörflerextern void
888d5a6048SAxel Dörfler	ring_supplied(Ring *ring, int count),
898d5a6048SAxel Dörfler	ring_consumed(Ring *ring, int count);
908d5a6048SAxel Dörfler
918d5a6048SAxel Dörfler/* Buffer state query routines */
928d5a6048SAxel Dörflerextern int
938d5a6048SAxel Dörfler	ring_at_mark(Ring *),
948d5a6048SAxel Dörfler	ring_empty_count(Ring *ring),
958d5a6048SAxel Dörfler	ring_empty_consecutive(Ring *ring),
968d5a6048SAxel Dörfler	ring_full_count(Ring *ring),
978d5a6048SAxel Dörfler	ring_full_consecutive(Ring *ring);
988d5a6048SAxel Dörfler
998d5a6048SAxel Dörfler#ifdef	ENCRYPTION
1008d5a6048SAxel Dörflerextern void
1018d5a6048SAxel Dörfler	ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)),
1028d5a6048SAxel Dörfler	ring_clearto(Ring *ring);
1038d5a6048SAxel Dörfler#endif	/* ENCRYPTION */
1048d5a6048SAxel Dörfler
1058d5a6048SAxel Dörflerextern void
1068d5a6048SAxel Dörfler	ring_clear_mark(Ring *),
1078d5a6048SAxel Dörfler	ring_mark(Ring *);
108