Debian Codegraph @

telnet/ring.h

raw
1 /*
2 Copyright (C) 1995-2026 Free Software Foundation, Inc.
3
4 This file is part of GNU Inetutils.
5
6 GNU Inetutils is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Inetutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see `http://www.gnu.org/licenses/'. */
18
19 /*
20 * Copyright (c) 1988, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. Neither the name of the University nor the names of its contributors
32 * may be used to endorse or promote products derived from this software
33 * without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 */
47
48 /*
49 * This defines a structure for a ring buffer.
50 *
51 * The circular buffer has two parts:
52 *(((
53 * full: [consume, supply)
54 * empty: [supply, consume)
55 *]]]
56 *
57 */
58 typedef struct
59 {
60 unsigned char *consume, /* where data comes out of */
61 *supply, /* where data comes in to */
62 *bottom, /* lowest address in buffer */
63 *top, /* highest address+1 in buffer */
64 *mark; /* marker (user defined) */
65 #ifdef ENCRYPTION
66 unsigned char *clearto; /* Data to this point is clear text */
67 unsigned char *encryyptedto; /* Data is encrypted to here */
68 #endif /* ENCRYPTION */
69 int size; /* size in bytes of buffer */
70 unsigned long consumetime, /* help us keep straight full, empty, etc. */
71 supplytime;
72 } Ring;
73
74 /* Here are some functions and macros to deal with the ring buffer */
75
76 /* Initialization routine */
77 extern int ring_init (Ring * ring, unsigned char *buffer, int count);
78
79 /* Data movement routines */
80 extern void ring_supply_data (Ring * ring, unsigned char *buffer, int count);
81
82 /* Buffer state transition routines */
83 extern void
84 ring_supplied (Ring * ring, int count),
85 ring_consumed (Ring * ring, int count);
86
87 /* Buffer state query routines */
88 extern int
89 ring_empty_count (Ring * ring),
90 ring_empty_consecutive (Ring * ring),
91 ring_full_count (Ring * ring), ring_full_consecutive (Ring * ring);
92
93 #ifdef ENCRYPTION
94 extern void
95 ring_encrypt (Ring * ring, void (*encryptor) (unsigned char *, int)),
96 ring_clearto (Ring * ring);
97 #endif /* ENCRYPTION */
98
99 extern void ring_clear_mark (Ring *);
100 extern void ring_mark (Ring *);
101 extern int ring_at_mark (Ring *);