Damien Miller | 8922106 | 2010-02-12 09:23:40 +1100 | [diff] [blame] | 1 | /* $OpenBSD: buffer.h,v 1.19 2010/02/09 03:56:28 djm Exp $ */ |
Ben Lindstrom | 05764b9 | 2002-03-05 01:53:02 +0000 | [diff] [blame] | 2 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 3 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 6 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 7 | * Code for manipulating FIFO buffers. |
Damien Miller | 5f05637 | 2000-04-16 12:31:48 +1000 | [diff] [blame] | 8 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 9 | * 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 14 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 16 | #ifndef BUFFER_H |
| 17 | #define BUFFER_H |
| 18 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 19 | typedef struct { |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 20 | u_char *buf; /* Buffer for data. */ |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 21 | 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 24 | } Buffer; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 25 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 26 | void buffer_init(Buffer *); |
| 27 | void buffer_clear(Buffer *); |
| 28 | void buffer_free(Buffer *); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 29 | |
Damien Miller | 8922106 | 2010-02-12 09:23:40 +1100 | [diff] [blame] | 30 | u_int buffer_len(const Buffer *); |
| 31 | void *buffer_ptr(const Buffer *); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 32 | |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 33 | void buffer_append(Buffer *, const void *, u_int); |
| 34 | void *buffer_append_space(Buffer *, u_int); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 35 | |
Damien Miller | 499a0d5 | 2006-04-23 12:06:03 +1000 | [diff] [blame] | 36 | int buffer_check_alloc(Buffer *, u_int); |
| 37 | |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 38 | void buffer_get(Buffer *, void *, u_int); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 39 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 40 | void buffer_consume(Buffer *, u_int); |
| 41 | void buffer_consume_end(Buffer *, u_int); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 42 | |
Damien Miller | 8922106 | 2010-02-12 09:23:40 +1100 | [diff] [blame] | 43 | void buffer_dump(const Buffer *); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 44 | |
Darren Tucker | 50dbe83 | 2004-11-05 20:41:24 +1100 | [diff] [blame] | 45 | int buffer_get_ret(Buffer *, void *, u_int); |
| 46 | int buffer_consume_ret(Buffer *, u_int); |
| 47 | int buffer_consume_end_ret(Buffer *, u_int); |
| 48 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 49 | #include <openssl/bn.h> |
| 50 | |
| 51 | void buffer_put_bignum(Buffer *, const BIGNUM *); |
| 52 | void buffer_put_bignum2(Buffer *, const BIGNUM *); |
| 53 | void buffer_get_bignum(Buffer *, BIGNUM *); |
| 54 | void buffer_get_bignum2(Buffer *, BIGNUM *); |
| 55 | |
| 56 | u_short buffer_get_short(Buffer *); |
| 57 | void buffer_put_short(Buffer *, u_short); |
| 58 | |
| 59 | u_int buffer_get_int(Buffer *); |
| 60 | void buffer_put_int(Buffer *, u_int); |
| 61 | |
| 62 | u_int64_t buffer_get_int64(Buffer *); |
| 63 | void buffer_put_int64(Buffer *, u_int64_t); |
| 64 | |
| 65 | int buffer_get_char(Buffer *); |
| 66 | void buffer_put_char(Buffer *, int); |
| 67 | |
| 68 | void *buffer_get_string(Buffer *, u_int *); |
Damien Miller | db255ca | 2008-05-19 14:59:37 +1000 | [diff] [blame] | 69 | void *buffer_get_string_ptr(Buffer *, u_int *); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 70 | void buffer_put_string(Buffer *, const void *, u_int); |
| 71 | void buffer_put_cstring(Buffer *, const char *); |
| 72 | |
| 73 | #define buffer_skip_string(b) \ |
| 74 | do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0) |
| 75 | |
| 76 | int buffer_put_bignum_ret(Buffer *, const BIGNUM *); |
| 77 | int buffer_get_bignum_ret(Buffer *, BIGNUM *); |
| 78 | int buffer_put_bignum2_ret(Buffer *, const BIGNUM *); |
| 79 | int buffer_get_bignum2_ret(Buffer *, BIGNUM *); |
| 80 | int buffer_get_short_ret(u_short *, Buffer *); |
| 81 | int buffer_get_int_ret(u_int *, Buffer *); |
| 82 | int buffer_get_int64_ret(u_int64_t *, Buffer *); |
| 83 | void *buffer_get_string_ret(Buffer *, u_int *); |
Darren Tucker | ebc71d9 | 2010-01-12 19:45:59 +1100 | [diff] [blame] | 84 | void *buffer_get_string_ptr_ret(Buffer *, u_int *); |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 85 | int buffer_get_char_ret(char *, Buffer *); |
| 86 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 87 | #endif /* BUFFER_H */ |