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. 1329088Smarkm * 3. All advertising materials mentioning features or use of this software 1429088Smarkm * must display the following acknowledgement: 1529088Smarkm * This product includes software developed by the University of 1629088Smarkm * California, Berkeley and its contributors. 1729088Smarkm * 4. Neither the name of the University nor the names of its contributors 1829088Smarkm * may be used to endorse or promote products derived from this software 1929088Smarkm * without specific prior written permission. 2029088Smarkm * 2129088Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2229088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2329088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2429088Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2529088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2629088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2729088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2829088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2929088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3029088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3129088Smarkm * SUCH DAMAGE. 3229088Smarkm * 3329088Smarkm * @(#)ring.h 8.1 (Berkeley) 6/6/93 3481965Smarkm * $FreeBSD: releng/10.3/contrib/telnet/telnet/ring.h 87155 2001-11-30 22:28:07Z markm $ 3529088Smarkm */ 3629088Smarkm 3729088Smarkm#if defined(P) 3829088Smarkm# undef P 3929088Smarkm#endif 4029088Smarkm 4129088Smarkm#if defined(__STDC__) || defined(LINT_ARGS) 4229088Smarkm# define P(x) x 4329088Smarkm#else 4429088Smarkm# define P(x) () 4529088Smarkm#endif 4629088Smarkm 4729088Smarkm/* 4829088Smarkm * This defines a structure for a ring buffer. 4929088Smarkm * 5029088Smarkm * The circular buffer has two parts: 5129088Smarkm *((( 5229088Smarkm * full: [consume, supply) 5329088Smarkm * empty: [supply, consume) 5429088Smarkm *]]] 5529088Smarkm * 5629088Smarkm */ 5729088Smarkmtypedef struct { 5829088Smarkm unsigned char *consume, /* where data comes out of */ 5929088Smarkm *supply, /* where data comes in to */ 6029088Smarkm *bottom, /* lowest address in buffer */ 6129088Smarkm *top, /* highest address+1 in buffer */ 6229088Smarkm *mark; /* marker (user defined) */ 6329088Smarkm#ifdef ENCRYPTION 6429088Smarkm unsigned char *clearto; /* Data to this point is clear text */ 6529088Smarkm unsigned char *encryyptedto; /* Data is encrypted to here */ 6629088Smarkm#endif /* ENCRYPTION */ 6729088Smarkm int size; /* size in bytes of buffer */ 6829088Smarkm u_long consumetime, /* help us keep straight full, empty, etc. */ 6929088Smarkm supplytime; 7029088Smarkm} Ring; 7129088Smarkm 7229088Smarkm/* Here are some functions and macros to deal with the ring buffer */ 7329088Smarkm 7429088Smarkm/* Initialization routine */ 7529088Smarkmextern int 7687155Smarkm ring_init(Ring *ring, unsigned char *buffer, int count); 7729088Smarkm 7829088Smarkm/* Data movement routines */ 7929088Smarkmextern void 8087155Smarkm ring_supply_data(Ring *ring, unsigned char *buffer, int count); 8129088Smarkm#ifdef notdef 8229088Smarkmextern void 8387155Smarkm ring_consume_data(Ring *ring, unsigned char *buffer, int count); 8429088Smarkm#endif 8529088Smarkm 8629088Smarkm/* Buffer state transition routines */ 8729088Smarkmextern void 8887155Smarkm ring_supplied(Ring *ring, int count), 8987155Smarkm ring_consumed(Ring *ring, int count); 9029088Smarkm 9129088Smarkm/* Buffer state query routines */ 9229088Smarkmextern int 9387155Smarkm ring_at_mark(Ring *), 9487155Smarkm ring_empty_count(Ring *ring), 9587155Smarkm ring_empty_consecutive(Ring *ring), 9687155Smarkm ring_full_count(Ring *ring), 9787155Smarkm ring_full_consecutive(Ring *ring); 9829088Smarkm 9929088Smarkm#ifdef ENCRYPTION 10029088Smarkmextern void 10187155Smarkm ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)), 10287155Smarkm ring_clearto(Ring *ring); 10329088Smarkm#endif /* ENCRYPTION */ 10429088Smarkm 10529088Smarkmextern void 10687155Smarkm ring_clear_mark(Ring *), 10787155Smarkm ring_mark(Ring *); 108