Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / isc-dhcp / includes / omapip / buffer.h
1 /* buffer.h
2
3    Definitions for the object management API protocol buffering... */
4
5 /*
6  * Copyright (c) 1996-1999 Internet Software Consortium.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of The Internet Software Consortium nor the names
19  *    of its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * This software has been written for the Internet Software Consortium
37  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38  * To learn more about the Internet Software Consortium, see
39  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
40  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
41  * ``http://www.nominum.com''.
42  */
43
44 /* OMAPI buffers are ring buffers, which means that the beginning of the
45    buffer and the end of the buffer chase each other around.   As long as
46    the tail never catches up to the head, there's room in the buffer for
47    data.
48
49         - If the tail and the head are equal, the buffer is empty.
50
51         - If the tail is less than the head, the contents of the buffer
52           are the bytes from the head to the end of buffer, and in addition,
53           the bytes between the beginning of the buffer and the tail, not
54           including the byte addressed by the tail.
55
56         - If the tail is greater than the head, then the buffer contains
57           valid bytes starting with the byte addressed by the head, and
58           ending with the byte before the byte addressed by the tail.
59
60    There will always be at least one byte of waste, because the tail can't
61    increase so that it's equal to the head (that would represent an empty
62    buffer. */
63 #define OMAPI_BUF_SIZE 4048
64 typedef struct _omapi_buffer {
65         struct _omapi_buffer *next;     /* Buffers can be chained. */
66         u_int32_t refcnt;               /* Buffers are reference counted. */
67         u_int16_t head, tail;           /* Buffers are organized in a ring. */
68         char buf [OMAPI_BUF_SIZE];      /* The actual buffer is included in
69                                            the buffer data structure. */
70 } omapi_buffer_t;       
71
72 #define BUFFER_BYTES_FREE(x)    \
73         ((x) -> tail > (x) -> head \
74           ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \
75           : (x) -> head - (x) -> tail)
76
77 #define BYTES_IN_BUFFER(x)      \
78         ((x) -> tail > (x) -> head \
79          ? (x) -> tail - (x) -> head - 1 \
80          : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1)
81
82 isc_result_t omapi_connection_require (omapi_object_t *, unsigned);
83 isc_result_t omapi_connection_copyout (unsigned char *,
84                                        omapi_object_t *, unsigned);
85 isc_result_t omapi_connection_copyin (omapi_object_t *,
86                                       const unsigned char *, unsigned);
87 isc_result_t omapi_connection_flush (omapi_object_t *);
88 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *);
89 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t);
90 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *);
91 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t);
92