bind9/lib/omapi/include/omapi/buffer.h
David Lawrence 0ae0a1f038 checkpoint conversion to ISC (doc/dev/coding.html) style.
* no spaces around " -> " in indirect postfix expression.
  * no space between function name and open parenthesis.
  * no space between array name and open bracket.
  * use NULL not 0 for pointers.
  * explicitly compare pointers to NULL.
  * explicitly compare integers to 0.
  * Do not cast NULL.
  * return type of function declaration on line by itself.
  * open brace of function definition follows close parenthesis if parameters
    all fit on one line.
  * comment-only lines start with /* on line by itself, and end with */
    on line by itself.
  * variable names in structures separated from their types in a column.
  * name the parameters in function prototypes.
  * ifndef multiple header file inclusion.

and other BIND9 conventions not in coding.html:

  * private structures defined in relevant source module, not private header.
  * RCS /* $Id: $ */ comments.
  * Principal Author (Ted Lemon) comments.
  * Updated ISC copyrights.
  * Parenthesize value of return().
  * Parenthesize argument of sizeof().
  * "unsigned int foo" not "unsigned foo".
  * ISC_LANG_(BEGIN|END)DECLS in header files.
  * header files included directly by source/header file that needs them.
  * ... and others I am probably forgetting.

and conversion to some libisc.a modules:

  * use isc/int.h for isc_uintXX_t types, not u_intXX_t.
  * use isc/assertions.h for REQUIRE() and INSIST().
  * use isc/error.h for UNEXPECTED_ERROR.
  * use isc/boolean.h for isc_boolean_t flags instead of int flags.
  * use isc/net.h for networking types.
  * use isc/netdb.h for gethostby*.

STILL TO COME ...

  * more isc_boolean_t.
  * isc/time.h to replace struct timeval.
  * isc/socket.h to replace socket/listen/select/etc.
  * isc/mem.h to replace malloc/free.
  * namespace overhaul & omapi/compatibility.h.

Please collect all your belongings but stand clear of the doors until this
train has come to a complete stop.
1999-11-02 04:01:34 +00:00

98 lines
3.3 KiB
C

/*
* Copyright (C) 1996, 1997, 1998, 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*****
***** Definitions for the object management API protocol buffering.
*****/
/*
* OMAPI buffers are ring buffers, which means that the beginning of the
* buffer and the end of the buffer chase each other around. As long as
* the tail never catches up to the head, there's room in the buffer for
* data.
*
* - If the tail and the head are equal, the buffer is empty.
*
* - If the tail is less than the head, the contents of the buffer
* are the bytes from the head to the end of buffer, and in addition,
* the bytes between the beginning of the buffer and the tail, not
* including the byte addressed by the tail.
*
* - If the tail is greater than the head, then the buffer contains
* valid bytes starting with the byte addressed by the head, and
* ending with the byte before the byte addressed by the tail.
*
* There will always be at least one byte of waste, because the tail can't
* increase so that it's equal to the head (that would represent an empty
* buffer.
*/
#ifndef OMAPI_BUFFER_H
#define OMAPI_BUFFER_H 1
#include <isc/lang.h>
#include <omapi/omapip.h>
ISC_LANG_BEGINDECLS
#define OMAPI_BUFFER_SIZE 4048
typedef struct omapi_buffer {
struct omapi_buffer *next; /* Buffers can be chained. */
isc_uint32_t refcnt; /* Buffers are reference counted. */
isc_uint16_t head, tail; /* Buffers are organized in a ring. */
char data[OMAPI_BUFFER_SIZE]; /* The actual buffer is included in
the buffer data structure. */
} omapi_buffer_t;
#define BUFFER_BYTES_FREE(x) \
((x)->tail > (x)->head \
? sizeof ((x)->data) - ((x)->tail - (x)->head) \
: (x)->head - (x)->tail)
#define BYTES_IN_BUFFER(x) \
((x)->tail > (x)->head \
? (x)->tail - (x)->head - 1 \
: sizeof ((x)->data) - ((x)->head - (x)->tail) - 1)
isc_result_t
omapi_connection_require(omapi_object_t *connection, unsigned int bytes);
isc_result_t
omapi_connection_copyout(unsigned char *data, omapi_object_t *connection,
unsigned int length);
isc_result_t
omapi_connection_copyin(omapi_object_t *connection, const unsigned char *data,
unsigned int length);
isc_result_t
omapi_connection_get_uint32(omapi_object_t *connection, isc_uint32_t *value);
isc_result_t
omapi_connection_put_uint32(omapi_object_t *connection, isc_uint32_t value);
isc_result_t
omapi_connection_get_uint16(omapi_object_t *connection, isc_uint16_t *value);
isc_result_t
omapi_connection_put_uint16(omapi_object_t *connection, isc_uint32_t value);
ISC_LANG_ENDDECLS
#endif /* OMAPI_BUFFER_H */