blob: f3c509dfadb8a522559ab0cd07c9c136f8d14706 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * Code for manipulating FIFO buffers.
Damien Miller5f056372000-04-16 12:31:48 +10006 *
Damien Millere4340be2000-09-16 13:29:08 +11007 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
Ben Lindstrom46c16222000-12-22 01:43:59 +000014/* RCSID("$OpenBSD: buffer.h,v 1.7 2000/12/19 23:17:55 markus Exp $"); */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
16#ifndef BUFFER_H
17#define BUFFER_H
18
Damien Miller95def091999-11-25 00:26:21 +110019typedef struct {
20 char *buf; /* Buffer for data. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000021 u_int alloc; /* Number of bytes allocated for data. */
22 u_int offset; /* Offset of first byte containing data. */
23 u_int end; /* Offset of last byte containing data. */
Damien Miller95def091999-11-25 00:26:21 +110024} Buffer;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100025/* Initializes the buffer structure. */
Damien Miller95def091999-11-25 00:26:21 +110026void buffer_init(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027
28/* Frees any memory used for the buffer. */
Damien Miller95def091999-11-25 00:26:21 +110029void buffer_free(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100030
31/* Clears any data from the buffer, making it empty. This does not actually
32 zero the memory. */
Damien Miller95def091999-11-25 00:26:21 +110033void buffer_clear(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100034
35/* Appends data to the buffer, expanding it if necessary. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000036void buffer_append(Buffer * buffer, const char *data, u_int len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037
Damien Miller5428f641999-11-25 11:54:57 +110038/*
39 * Appends space to the buffer, expanding the buffer if necessary. This does
40 * not actually copy the data into the buffer, but instead returns a pointer
41 * to the allocated region.
42 */
Ben Lindstrom46c16222000-12-22 01:43:59 +000043void buffer_append_space(Buffer * buffer, char **datap, u_int len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044
45/* Returns the number of bytes of data in the buffer. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000046u_int buffer_len(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100047
48/* Gets data from the beginning of the buffer. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000049void buffer_get(Buffer * buffer, char *buf, u_int len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050
51/* Consumes the given number of bytes from the beginning of the buffer. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000052void buffer_consume(Buffer * buffer, u_int bytes);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100053
54/* Consumes the given number of bytes from the end of the buffer. */
Ben Lindstrom46c16222000-12-22 01:43:59 +000055void buffer_consume_end(Buffer * buffer, u_int bytes);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100056
57/* Returns a pointer to the first used byte in the buffer. */
Damien Miller95def091999-11-25 00:26:21 +110058char *buffer_ptr(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059
Damien Miller5428f641999-11-25 11:54:57 +110060/*
61 * Dumps the contents of the buffer to stderr in hex. This intended for
62 * debugging purposes only.
63 */
Damien Miller95def091999-11-25 00:26:21 +110064void buffer_dump(Buffer * buffer);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065
Damien Miller95def091999-11-25 00:26:21 +110066#endif /* BUFFER_H */