xref: /haiku/src/bin/network/telnet/ring.h (revision 8d5a60482cbe1021cba28bb5ea607cb52713e0c3)
1*8d5a6048SAxel Dörfler /*
2*8d5a6048SAxel Dörfler  * Copyright (c) 1988, 1993
3*8d5a6048SAxel Dörfler  *	The Regents of the University of California.  All rights reserved.
4*8d5a6048SAxel Dörfler  *
5*8d5a6048SAxel Dörfler  * Redistribution and use in source and binary forms, with or without
6*8d5a6048SAxel Dörfler  * modification, are permitted provided that the following conditions
7*8d5a6048SAxel Dörfler  * are met:
8*8d5a6048SAxel Dörfler  * 1. Redistributions of source code must retain the above copyright
9*8d5a6048SAxel Dörfler  *    notice, this list of conditions and the following disclaimer.
10*8d5a6048SAxel Dörfler  * 2. Redistributions in binary form must reproduce the above copyright
11*8d5a6048SAxel Dörfler  *    notice, this list of conditions and the following disclaimer in the
12*8d5a6048SAxel Dörfler  *    documentation and/or other materials provided with the distribution.
13*8d5a6048SAxel Dörfler  * 3. All advertising materials mentioning features or use of this software
14*8d5a6048SAxel Dörfler  *    must display the following acknowledgement:
15*8d5a6048SAxel Dörfler  *	This product includes software developed by the University of
16*8d5a6048SAxel Dörfler  *	California, Berkeley and its contributors.
17*8d5a6048SAxel Dörfler  * 4. Neither the name of the University nor the names of its contributors
18*8d5a6048SAxel Dörfler  *    may be used to endorse or promote products derived from this software
19*8d5a6048SAxel Dörfler  *    without specific prior written permission.
20*8d5a6048SAxel Dörfler  *
21*8d5a6048SAxel Dörfler  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*8d5a6048SAxel Dörfler  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*8d5a6048SAxel Dörfler  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*8d5a6048SAxel Dörfler  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*8d5a6048SAxel Dörfler  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*8d5a6048SAxel Dörfler  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*8d5a6048SAxel Dörfler  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*8d5a6048SAxel Dörfler  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*8d5a6048SAxel Dörfler  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*8d5a6048SAxel Dörfler  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*8d5a6048SAxel Dörfler  * SUCH DAMAGE.
32*8d5a6048SAxel Dörfler  *
33*8d5a6048SAxel Dörfler  *	@(#)ring.h	8.1 (Berkeley) 6/6/93
34*8d5a6048SAxel Dörfler  * $FreeBSD: src/contrib/telnet/telnet/ring.h,v 1.4 2001/11/30 22:28:07 markm Exp $
35*8d5a6048SAxel Dörfler  */
36*8d5a6048SAxel Dörfler 
37*8d5a6048SAxel Dörfler #if defined(P)
38*8d5a6048SAxel Dörfler # undef P
39*8d5a6048SAxel Dörfler #endif
40*8d5a6048SAxel Dörfler 
41*8d5a6048SAxel Dörfler #if defined(__STDC__) || defined(LINT_ARGS)
42*8d5a6048SAxel Dörfler # define	P(x)	x
43*8d5a6048SAxel Dörfler #else
44*8d5a6048SAxel Dörfler # define	P(x)	()
45*8d5a6048SAxel Dörfler #endif
46*8d5a6048SAxel Dörfler 
47*8d5a6048SAxel Dörfler /*
48*8d5a6048SAxel Dörfler  * This defines a structure for a ring buffer.
49*8d5a6048SAxel Dörfler  *
50*8d5a6048SAxel Dörfler  * The circular buffer has two parts:
51*8d5a6048SAxel Dörfler  *(((
52*8d5a6048SAxel Dörfler  *	full:	[consume, supply)
53*8d5a6048SAxel Dörfler  *	empty:	[supply, consume)
54*8d5a6048SAxel Dörfler  *]]]
55*8d5a6048SAxel Dörfler  *
56*8d5a6048SAxel Dörfler  */
57*8d5a6048SAxel Dörfler typedef struct {
58*8d5a6048SAxel Dörfler     unsigned char	*consume,	/* where data comes out of */
59*8d5a6048SAxel Dörfler 			*supply,	/* where data comes in to */
60*8d5a6048SAxel Dörfler 			*bottom,	/* lowest address in buffer */
61*8d5a6048SAxel Dörfler 			*top,		/* highest address+1 in buffer */
62*8d5a6048SAxel Dörfler 			*mark;		/* marker (user defined) */
63*8d5a6048SAxel Dörfler #ifdef	ENCRYPTION
64*8d5a6048SAxel Dörfler     unsigned char	*clearto;	/* Data to this point is clear text */
65*8d5a6048SAxel Dörfler     unsigned char	*encryyptedto;	/* Data is encrypted to here */
66*8d5a6048SAxel Dörfler #endif	/* ENCRYPTION */
67*8d5a6048SAxel Dörfler     int		size;		/* size in bytes of buffer */
68*8d5a6048SAxel Dörfler     u_long	consumetime,	/* help us keep straight full, empty, etc. */
69*8d5a6048SAxel Dörfler 		supplytime;
70*8d5a6048SAxel Dörfler } Ring;
71*8d5a6048SAxel Dörfler 
72*8d5a6048SAxel Dörfler /* Here are some functions and macros to deal with the ring buffer */
73*8d5a6048SAxel Dörfler 
74*8d5a6048SAxel Dörfler /* Initialization routine */
75*8d5a6048SAxel Dörfler extern int
76*8d5a6048SAxel Dörfler 	ring_init(Ring *ring, unsigned char *buffer, int count);
77*8d5a6048SAxel Dörfler 
78*8d5a6048SAxel Dörfler /* Data movement routines */
79*8d5a6048SAxel Dörfler extern void
80*8d5a6048SAxel Dörfler 	ring_supply_data(Ring *ring, unsigned char *buffer, int count);
81*8d5a6048SAxel Dörfler #ifdef notdef
82*8d5a6048SAxel Dörfler extern void
83*8d5a6048SAxel Dörfler 	ring_consume_data(Ring *ring, unsigned char *buffer, int count);
84*8d5a6048SAxel Dörfler #endif
85*8d5a6048SAxel Dörfler 
86*8d5a6048SAxel Dörfler /* Buffer state transition routines */
87*8d5a6048SAxel Dörfler extern void
88*8d5a6048SAxel Dörfler 	ring_supplied(Ring *ring, int count),
89*8d5a6048SAxel Dörfler 	ring_consumed(Ring *ring, int count);
90*8d5a6048SAxel Dörfler 
91*8d5a6048SAxel Dörfler /* Buffer state query routines */
92*8d5a6048SAxel Dörfler extern int
93*8d5a6048SAxel Dörfler 	ring_at_mark(Ring *),
94*8d5a6048SAxel Dörfler 	ring_empty_count(Ring *ring),
95*8d5a6048SAxel Dörfler 	ring_empty_consecutive(Ring *ring),
96*8d5a6048SAxel Dörfler 	ring_full_count(Ring *ring),
97*8d5a6048SAxel Dörfler 	ring_full_consecutive(Ring *ring);
98*8d5a6048SAxel Dörfler 
99*8d5a6048SAxel Dörfler #ifdef	ENCRYPTION
100*8d5a6048SAxel Dörfler extern void
101*8d5a6048SAxel Dörfler 	ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)),
102*8d5a6048SAxel Dörfler 	ring_clearto(Ring *ring);
103*8d5a6048SAxel Dörfler #endif	/* ENCRYPTION */
104*8d5a6048SAxel Dörfler 
105*8d5a6048SAxel Dörfler extern void
106*8d5a6048SAxel Dörfler 	ring_clear_mark(Ring *),
107*8d5a6048SAxel Dörfler 	ring_mark(Ring *);
108