blob: 2b20eed52acf29e6c68c1d47fbd6e17384f058bd [file] [log] [blame]
Darren Tucker11327cc2005-03-14 23:22:25 +11001/* $OpenBSD: buffer.h,v 1.13 2005/03/14 11:46:56 markus Exp $ */
Ben Lindstrom05764b92002-03-05 01:53:02 +00002
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11005 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11007 * Code for manipulating FIFO buffers.
Damien Miller5f056372000-04-16 12:31:48 +10008 *
Damien Millere4340be2000-09-16 13:29:08 +11009 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose. Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is
12 * incompatible with the protocol description in the RFC file, it must be
13 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110014 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016#ifndef BUFFER_H
17#define BUFFER_H
18
Damien Miller95def091999-11-25 00:26:21 +110019typedef struct {
Damien Miller5a6b4fe2001-12-21 14:56:54 +110020 u_char *buf; /* Buffer for data. */
Ben Lindstrom4cc240d2001-07-04 04:46:56 +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
Darren Tucker11327cc2005-03-14 23:22:25 +110026#define BUFFER_MAX_CHUNK 0x100000
27#define BUFFER_MAX_LEN 0xa00000
28
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000029void buffer_init(Buffer *);
30void buffer_clear(Buffer *);
31void buffer_free(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000033u_int buffer_len(Buffer *);
Damien Miller5a6b4fe2001-12-21 14:56:54 +110034void *buffer_ptr(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100035
Damien Miller5a6b4fe2001-12-21 14:56:54 +110036void buffer_append(Buffer *, const void *, u_int);
37void *buffer_append_space(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100038
Damien Miller5a6b4fe2001-12-21 14:56:54 +110039void buffer_get(Buffer *, void *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100040
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000041void buffer_consume(Buffer *, u_int);
42void buffer_consume_end(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100043
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000044void buffer_dump(Buffer *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045
Darren Tucker50dbe832004-11-05 20:41:24 +110046int buffer_get_ret(Buffer *, void *, u_int);
47int buffer_consume_ret(Buffer *, u_int);
48int buffer_consume_end_ret(Buffer *, u_int);
49
Damien Miller95def091999-11-25 00:26:21 +110050#endif /* BUFFER_H */