blob: 5e9fc278d9f7b09381d222788d1d34347a5a8040 [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 Lindstrom16ae3d02001-07-04 04:02:36 +000014/* RCSID("$OpenBSD: buffer.h,v 1.8 2001/06/26 06:32:48 itojun 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. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000026void buffer_init(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027
28/* Frees any memory used for the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000029void buffer_free(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. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000033void buffer_clear(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100034
35/* Appends data to the buffer, expanding it if necessary. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000036void buffer_append(Buffer *, const char *, u_int);
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 Lindstrom16ae3d02001-07-04 04:02:36 +000043void buffer_append_space(Buffer *, char **, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044
45/* Returns the number of bytes of data in the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000046u_int buffer_len(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100047
48/* Gets data from the beginning of the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000049void buffer_get(Buffer *, char *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050
51/* Consumes the given number of bytes from the beginning of the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000052void buffer_consume(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100053
54/* Consumes the given number of bytes from the end of the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000055void buffer_consume_end(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100056
57/* Returns a pointer to the first used byte in the buffer. */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000058char *buffer_ptr(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 */
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000064void buffer_dump(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100065
Damien Miller95def091999-11-25 00:26:21 +110066#endif /* BUFFER_H */