version 1.2, 1996/03/27 19:33:05 |
version 1.3, 1998/03/12 04:57:38 |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
#ifndef lint |
#include "telnet_locl.h" |
#if 0 |
|
static char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95"; |
|
static char rcsid[] = "$NetBSD: ring.c,v 1.7 1996/02/28 21:04:07 thorpej Exp $"; |
|
#else |
|
static char rcsid[] = "$OpenBSD$"; |
|
#endif |
|
#endif /* not lint */ |
|
|
|
/* |
/* |
* This defines a structure for a ring buffer. |
* This defines a structure for a ring buffer. |
|
|
* |
* |
*/ |
*/ |
|
|
#include <stdio.h> |
|
#ifndef NO_STRING_H |
|
#include <string.h> |
|
#endif |
|
#include <strings.h> |
|
#include <errno.h> |
|
|
|
#ifdef size_t |
|
#undef size_t |
|
#endif |
|
|
|
#include <sys/types.h> |
|
#ifndef FILIO_H |
|
#include <sys/ioctl.h> |
|
#endif |
|
#include <sys/socket.h> |
|
|
|
#include "ring.h" |
|
#include "general.h" |
|
|
|
/* Internal macros */ |
/* Internal macros */ |
|
|
#if !defined(MIN) |
#if !defined(MIN) |
|
|
|
|
ring->top = ring->bottom+ring->size; |
ring->top = ring->bottom+ring->size; |
|
|
|
#if defined(ENCRYPTION) |
|
ring->clearto = 0; |
|
#endif |
|
|
return 1; |
return 1; |
} |
} |
|
|
(ring_subtract(ring, ring->mark, ring->consume) < count)) { |
(ring_subtract(ring, ring->mark, ring->consume) < count)) { |
ring->mark = 0; |
ring->mark = 0; |
} |
} |
|
#if defined(ENCRYPTION) |
|
if (ring->consume < ring->clearto && |
|
ring->clearto <= ring->consume + count) |
|
ring->clearto = 0; |
|
else if (ring->consume + count > ring->top && |
|
ring->bottom <= ring->clearto && |
|
ring->bottom + ((ring->consume + count) - ring->top)) |
|
ring->clearto = 0; |
|
#endif |
ring->consume = ring_increment(ring, ring->consume, count); |
ring->consume = ring_increment(ring, ring->consume, count); |
ring->consumetime = ++ring_clock; |
ring->consumetime = ++ring_clock; |
/* |
/* |
|
|
count -= i; |
count -= i; |
buffer += i; |
buffer += i; |
} |
} |
|
} |
|
#endif |
|
|
|
#if defined(ENCRYPTION) |
|
void |
|
ring_encrypt(Ring *ring, void (*encryptor)()) |
|
{ |
|
unsigned char *s, *c; |
|
|
|
if (ring_empty(ring) || ring->clearto == ring->supply) |
|
return; |
|
|
|
if (!(c = ring->clearto)) |
|
c = ring->consume; |
|
|
|
s = ring->supply; |
|
|
|
if (s <= c) { |
|
(*encryptor)(c, ring->top - c); |
|
(*encryptor)(ring->bottom, s - ring->bottom); |
|
} else |
|
(*encryptor)(c, s - c); |
|
|
|
ring->clearto = ring->supply; |
|
} |
|
|
|
void |
|
ring_clearto(Ring *ring) |
|
{ |
|
if (!ring_empty(ring)) |
|
ring->clearto = ring->supply; |
|
else |
|
ring->clearto = 0; |
} |
} |
#endif |
#endif |
|
|