From 64bed6c54393c2d213db83e9b171fb7c318cfc8e Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Fri, 14 Jan 2000 17:28:54 +0000 Subject: [PATCH] Checkpoint yesterday's work --- lib/lwres/Makefile.in | 6 +- lib/lwres/assert_p.h | 27 +++ lib/lwres/context.c | 143 +++++++++++++ lib/lwres/context_p.h | 46 +++++ lib/lwres/include/lwres/context.h | 83 ++++++++ lib/lwres/include/lwres/lwbuffer.h | 2 - lib/lwres/include/lwres/lwpacket.h | 8 +- lib/lwres/include/lwres/lwres.h | 318 ++++++++++++++++++----------- lib/lwres/lwpacket.c | 42 ++++ lib/lwres/lwres.c | 215 ------------------- lib/lwres/lwres_gabn.c | 227 ++++++++++++++++++++ lib/lwres/lwres_gnba.c | 64 ++++++ lib/lwres/lwres_noop.c | 201 ++++++++++++++++++ 13 files changed, 1040 insertions(+), 342 deletions(-) create mode 100644 lib/lwres/assert_p.h create mode 100644 lib/lwres/context.c create mode 100644 lib/lwres/context_p.h create mode 100644 lib/lwres/include/lwres/context.h create mode 100644 lib/lwres/lwpacket.c delete mode 100644 lib/lwres/lwres.c create mode 100644 lib/lwres/lwres_gabn.c create mode 100644 lib/lwres/lwres_gnba.c create mode 100644 lib/lwres/lwres_noop.c diff --git a/lib/lwres/Makefile.in b/lib/lwres/Makefile.in index cfdc83e69a..a9ccbe988e 100644 --- a/lib/lwres/Makefile.in +++ b/lib/lwres/Makefile.in @@ -26,10 +26,12 @@ CDEFINES = CWARNINGS = # Alphabetically -OBJS = lwbuffer.@O@ lwres.@O@ +OBJS = context.@O@ lwbuffer.@O@ \ + lwres_gabn.@O@ lwres_gnba.@O@ lwres_noop.@O@ # Alphabetically -SRCS = lwbuffer.c lwres.c +SRCS = context.c lwbuffer.c \ + lwres_gabn.c lwres_gnba.c lwres_noop.c LIBS = @LIBS@ diff --git a/lib/lwres/assert_p.h b/lib/lwres/assert_p.h new file mode 100644 index 0000000000..41d1b319e7 --- /dev/null +++ b/lib/lwres/assert_p.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2000 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. + */ + +#ifndef LWRES_ASSERT_P_H +#define LWRES_ASSERT_P_H 1 + +/* XXXMLG */ +#define REQUIRE(x) assert(x) +#define INSIST(x) assert(x) + +#define SPACE_OK(b, s) (LWRES_BUFFER_AVAILABLECOUNT(b) >= s) + +#endif /* LWRES_ASSERT_P_H */ diff --git a/lib/lwres/context.c b/lib/lwres/context.c new file mode 100644 index 0000000000..1160aaccaa --- /dev/null +++ b/lib/lwres/context.c @@ -0,0 +1,143 @@ + +/* + * Copyright (C) 2000 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. + */ + +#include + +#include +#include +#include +#include + +#include + +#include "context_p.h" +#include "assert_p.h" + +static void *lwres_malloc(void *, size_t); +static void lwres_free(void *, void *, size_t); + +int +lwres_context_create(lwres_context_t **contextp, void *arg, + lwres_malloc_t malloc_function, + lwres_free_t free_function) +{ + lwres_context_t *ctx; + + REQUIRE(contextp != NULL && *contextp == NULL); + + /* + * If we were not given anything special to use, use our own + * functions. These are just wrappers around malloc() and free(). + */ + if (malloc_function == NULL || free_function == NULL) { + REQUIRE(malloc_function == NULL); + REQUIRE(free_function == NULL); + malloc_function = lwres_malloc; + free_function = lwres_free; + } + + ctx = malloc_function(arg, sizeof(lwres_context_t)); + if (ctx == NULL) { + errno = ENOMEM; + return (-1); + } + + /* + * Set up the context. + */ + ctx->malloc = malloc_function; + ctx->free = free_function; + ctx->arg = arg; + + ctx->timeout = LWRES_DEFAULT_TIMEOUT; + ctx->serial = (isc_uint32_t)ctx; /* XXXMLG */ + + *contextp = ctx; + return (0); +} + +void +lwres_context_free(lwres_context_t **contextp) +{ + lwres_context_t *ctx; + + REQUIRE(contextp != NULL && *contextp != NULL); + + ctx = *contextp; + *contextp = NULL; + + CTXFREE(ctx, sizeof(lwres_context_t)); +} + +isc_uint32_t +lwres_context_nextserial(lwres_context_t *ctx) +{ + REQUIRE(ctx != NULL); + + return (ctx->serial++); +} + +void +lwres_context_initserial(lwres_context_t *ctx, isc_uint32_t serial) +{ + REQUIRE(ctx != NULL); + + ctx->serial = serial; +} + +void +lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len) +{ + REQUIRE(mem != NULL); + REQUIRE(len != 0); + + CTXFREE(mem, len); +} + +void * +lwres_context_allocmem(lwres_context_t *ctx, size_t len) +{ + REQUIRE(len != 0); + + return (CTXMALLOC(len)); +} + +static void * +lwres_malloc(void *arg, size_t len) +{ + void *mem; + + (void)arg; + + mem = malloc(len); + if (mem == NULL) + return (NULL); + + memset(mem, 0xe5, len); + + return (mem); +} + +static void +lwres_free(void *arg, void *mem, size_t len) +{ + (void)arg; + + memset(mem, 0xa9, len); + free(mem); +} diff --git a/lib/lwres/context_p.h b/lib/lwres/context_p.h new file mode 100644 index 0000000000..41f1ae9d07 --- /dev/null +++ b/lib/lwres/context_p.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2000 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. + */ + +#ifndef LWRES_CONTEXT_P_H +#define LWRES_CONTEXT_P_H 1 + +/* + * Helper functions, assuming the context is always called "ctx" in + * the scope these functions are called from. + */ +#define CTXMALLOC(len) ctx->malloc(ctx->arg, (len)) +#define CTXFREE(addr, len) ctx->free(ctx->arg, (addr), (len)) + +#define LWRES_DEFAULT_TIMEOUT 30 /* 30 seconds for a reply */ + +/* + * Not all the attributes here are actually settable by the application at + * this time. + */ +struct lwres_context { + unsigned int timeout; /* time to wait for reply */ + isc_uint32_t serial; /* serial number state */ + + /* + * Function pointers for allocating memory. + */ + lwres_malloc_t malloc; + lwres_free_t free; + void *arg; +}; + +#endif /* LWRES_CONTEXT_P_H */ diff --git a/lib/lwres/include/lwres/context.h b/lib/lwres/include/lwres/context.h new file mode 100644 index 0000000000..499574bd4c --- /dev/null +++ b/lib/lwres/include/lwres/context.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2000 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. + */ + +#ifndef LWRES_CONTEXT_H +#define LWRES_CONTEXT_H 1 + +#include + +#include +#include + +/* + * Used to set various options such as timeout, authentication, etc + */ +typedef struct lwres_context lwres_context_t; + +ISC_LANG_BEGINDECLS + +typedef void *(*lwres_malloc_t)(void *arg, size_t length); +typedef void (*lwres_free_t)(void *arg, void *mem, size_t length); + +int +lwres_context_create(lwres_context_t **contextp, void *arg, + lwres_malloc_t malloc_function, + lwres_free_t free_function); +/* + * Allocate a lwres context. This is used in all lwres calls. + * + * Memory management can be replaced here by passing in two functions. + * If one is non-NULL, they must both be non-NULL. "arg" is passed to + * these functions. + * + * If they are NULL, the standard malloc() and free() will be used. + * + * Requires: + * + * contextp != NULL && contextp == NULL. + * + * Returns: + * + * Returns 0 on success, non-zero on failure. + */ + +void +lwres_context_free(lwres_context_t **contextp); +/* + * Frees all memory associated with a lwres context. + * + * Requires: + * + * contextp != NULL && contextp == NULL. + */ + +isc_uint32_t +lwres_context_nextserial(lwres_context_t *ctx); + +void +lwres_context_initserial(lwres_context_t *ctx, isc_uint32_t serial); + +void +lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len); + +void * +lwres_context_allocmem(lwres_context_t *ctx, size_t len); + +ISC_LANG_ENDDECLS + +#endif /* LWRES_CONTEXT_H */ + diff --git a/lib/lwres/include/lwres/lwbuffer.h b/lib/lwres/include/lwres/lwbuffer.h index 0a5d895575..2285bcb917 100644 --- a/lib/lwres/include/lwres/lwbuffer.h +++ b/lib/lwres/include/lwres/lwbuffer.h @@ -130,8 +130,6 @@ ISC_LANG_BEGINDECLS * Get the length of the available region of buffer "b" */ #define LWRES_BUFFER_AVAILABLECOUNT(b) ((b)->length - (b)->used) -#define LWRES_BUFFER_AVAILABLECHECK(b, bytes) \ - (LWRES_BUFFER_AVAILABLECOUNT(b) >= (bytes)) /* * Note that the buffer structure is public. This is principally so buffer diff --git a/lib/lwres/include/lwres/lwpacket.h b/lib/lwres/include/lwres/lwpacket.h index 37a42a393b..031ab84c95 100644 --- a/lib/lwres/include/lwres/lwpacket.h +++ b/lib/lwres/include/lwres/lwpacket.h @@ -114,10 +114,10 @@ struct lwres_lwpacket { ISC_LANG_BEGINDECLS int -lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt, - isc_uint32_t buflen, isc_uint16_t flags, - isc_uint32_t serial, isc_uint32_t opcode, - isc_uint32_t result, isc_uint32_t recvlength); +lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt); + +int +lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt); ISC_LANG_ENDDECLS diff --git a/lib/lwres/include/lwres/lwres.h b/lib/lwres/include/lwres/lwres.h index a50be68dc9..335705587a 100644 --- a/lib/lwres/include/lwres/lwres.h +++ b/lib/lwres/include/lwres/lwres.h @@ -23,10 +23,67 @@ #include #include +#include + /* - * Used to set various options such as timeout, authentication, etc + * Design notes: + * + * Each opcode has two structures and three functions which operate on each + * structure. For example, using the "no operation/ping" opcode as an + * example: + * + * lwres_nooprequest_t: + * + * lwres_nooprequest_render() takes a lwres_nooprequest_t and + * and renders it into wire format, storing the allocated + * buffer information in a passed-in buffer. When this buffer + * is no longer needed, it must be freed by + * lwres_context_freemem(). All other memory used by the + * caller must be freed manually, including the + * lwres_nooprequest_t passed in. + * + * lwres_nooprequest_parse() takes a wire format message and + * breaks it out into a lwres_nooprequest_t. The structure + * must be freed via lwres_nooprequest_free() when it is no longer + * needed. + * + * lwres_nooprequest_free() releases into the lwres_context_t + * any space allocated during parsing. + * + * lwres_noopresponse_t: + * + * The functions used are similar to the three used for + * requests, just with different names. + * + * Typically, the client will use request_render, response_parse, and + * response_free, while the daemon will use request_parse, response_render, + * and request_free. + * + * The basic flow of a typical client is: + * + * fill in a request_t, and call the render function. + * + * Transmit the buffer returned to the daemon. + * + * Wait for a response. + * + * When a response is received, parse it into a response_t. + * + * free the request buffer using lwres_context_freemem(). + * + * free the response structure and its associated buffer using + * response_free(). */ -typedef struct lwres_context lwres_context_t; + +/* + * Helper macro to calculate a string's length. Strings are encoded + * using a 16-bit length, the string itself, and a trailing NUL. The + * length does not include this NUL character -- it is there merely to + * help reduce copying on the receive side, since most strings are + * printable character strings, and C needs the trailing NUL. + */ + +#define LWRES_STRING_LENGTH(x) (sizeof(isc_uint16_t) + strlen(x) + 1) /* * NO-OP @@ -34,14 +91,27 @@ typedef struct lwres_context lwres_context_t; #define LWRES_OPCODE_NOOP 0x00000000U typedef struct { + /* header info */ + isc_uint32_t serial; /* public */ - isc_uint32_t result; isc_uint16_t datalength; unsigned char *data; - /* private */ + /* if buffer == NULL, not freed by free routines */ isc_uint32_t buflen; void *buffer; -} lwres_noop_t; +} lwres_nooprequest_t; + +typedef struct { + /* header info */ + isc_uint32_t serial; + isc_uint32_t result; + /* public */ + isc_uint16_t datalength; + unsigned char *data; + /* if buffer == NULL, not freed by free routines */ + isc_uint32_t buflen; + void *buffer; +} lwres_noopresponse_t; /* * GET ADDRESSES BY NAME @@ -55,74 +125,156 @@ typedef struct { } lwres_addr_t; typedef struct { + /* header info */ + isc_uint32_t serial; /* public */ + char *name; + /* if buffer == NULL, not freed by free routines */ + isc_uint32_t buflen; + void *buffer; /* must be last to keep alignment */ +} lwres_gabnrequest_t; + +typedef struct { + /* header info */ + isc_uint32_t serial; isc_uint32_t result; + /* public */ isc_uint16_t naliases; isc_uint16_t naddrs; char *real_name; char **aliases; lwres_addr_t **addrs; - /* private */ + /* if buffer == NULL, not freed by free routines */ isc_uint32_t buflen; void *buffer; /* must be last to keep alignment */ /* variable length data follows */ -} lwres_getaddrsbyname_t; +} lwres_gabnresponse_t; /* * GET NAME BY ADDRESS */ #define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U typedef struct { + /* header info */ + isc_uint32_t serial; /* public */ + lwres_addr_t addr; + /* if buffer == NULL, not freed by free routines */ + isc_uint32_t buflen; + void *buffer; /* must be last to keep alignment */ +} lwres_gnbarequest_t; + +typedef struct { + /* header info */ + isc_uint32_t serial; isc_uint32_t result; + /* public */ isc_uint16_t naliases; char *real_name; char **aliases; - /* private */ + /* if buffer == NULL, not freed by free routines */ isc_uint32_t buflen; void *buffer; /* must be last to keep alignment */ /* variable length data follows */ -} lwres_getnamebyaddr_t; +} lwres_gnbaresponse_t; #define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */ #define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */ ISC_LANG_BEGINDECLS -typedef void *(*lwres_malloc_t)(void *arg, size_t length); -typedef void (*lwres_free_t)(void *arg, void *mem, size_t length); +int +lwres_gabnrequest_render(lwres_context_t *ctx, + lwres_gabnrequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); int -lwres_getaddrsbyname(lwres_context_t *ctx, - char *name, isc_uint32_t addrtypes, - lwres_getaddrsbyname_t **structp); +lwres_gabnresponse_render(lwres_context_t *ctx, + lwres_gabnresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); + +int +lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_gabnrequest_t **structp); + +int +lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_gabnresponse_t **structp); + +void +lwres_gabnrequest_free(lwres_context_t *ctx, lwres_gabnrequest_t **structp); /* - * Makes a lwres call to look up all addresses associated with "name". + * Frees any dynamically allocated memory for this structure. * * Requires: * * ctx != NULL, and be a context returned via lwres_contextcreate(). * - * structp != NULL && *structp == NULL. + * structp != NULL && *structp != NULL. * - * name != NULL, and be a null-terminated string. + * Ensures: * - * addrtypes be a bitmask of the LWRES_ADDRTYPE_* constants representing - * the type of addresses wanted. + * *structp == NULL. * - * Returns: - * - * Returns 0 on success, non-zero on failure. - * - * On successful return, *structp will be non-NULL, and will point to - * an allocated structure returning the data requested. This structure - * must be freed using lwres_freegetaddrsbyname() when it is no longer - * needed. + * All memory allocated by this structure will be returned to the + * system via the context's free function. */ void -lwres_freegetaddrsbyname(lwres_context_t *ctx, - lwres_getaddrsbyname_t **structp); +lwres_gabnresponse_free(lwres_context_t *ctx, lwres_gabnresponse_t **structp); +/* + * Frees any dynamically allocated memory for this structure. + * + * Requires: + * + * ctx != NULL, and be a context returned via lwres_contextcreate(). + * + * structp != NULL && *structp != NULL. + * + * Ensures: + * + * *structp == NULL. + * + * All memory allocated by this structure will be returned to the + * system via the context's free function. + */ + + +int +lwres_gnbarequest_render(lwres_context_t *ctx, + lwres_gnbarequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); + +int +lwres_gnbaresponse_render(lwres_context_t *ctx, + lwres_gnbaresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); + +int +lwres_gnbarequest_parse(lwres_context_t *ctx, lwres_gnbarequest_t **structp); + +int +lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_gnbaresponse_t **structp); + +void +lwres_gnbarequest_free(lwres_context_t *ctx, lwres_gnbarequest_t **structp); +/* + * Frees any dynamically allocated memory for this structure. + * + * Requires: + * + * ctx != NULL, and be a context returned via lwres_contextcreate(). + * + * structp != NULL && *structp != NULL. + * + * Ensures: + * + * *structp == NULL. + * + * All memory allocated by this structure will be returned to the + * system via the context's free function. + */ + +void +lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp); /* * Frees any dynamically allocated memory for this structure. * @@ -141,63 +293,8 @@ lwres_freegetaddrsbyname(lwres_context_t *ctx, */ int -lwres_getaddrsbyname_fromstruct(lwres_context_t *ctx, - isc_uint8_t *buf, size_t len, - lwres_getaddrsbyname_t *gabn); -/* - * XXXMLG document - */ - -int -lwres_getnamebyaddr(lwres_context_t *ctx, isc_uint32_t addrtype, - isc_uint16_t addrlen, unsigned char *addr, - lwres_getnamebyaddr_t **structp); -/* - * Makes a lwres call to look up the hostnames associated with the address. - * - * Requires: - * - * ctx != NULL, and be a context returned via lwres_contextcreate(). - * - * structp != NULL && *structp == NULL. - * - * addr != NULL, and points to an address of length "addrlen" - * - * addrtype have exactly one bit set, from the LWRES_ADDRTYPE_* constants. - * - * Returns: - * - * Returns 0 on success, non-zero on failure. - * - * On successful return, *structp will be non-NULL, and will point to - * an allocated structure returning the data requested. This structure - * must be freed using lwres_freegetnamebyaddr() when it is no longer - * needed. - */ - -void -lwres_freegetnamebyaddr(lwres_context_t *ctx, - lwres_getnamebyaddr_t **structp); -/* - * Frees any dynamically allocated memory for this structure. - * - * Requires: - * - * ctx != NULL, and be a context returned via lwres_contextcreate(). - * - * structp != NULL && *structp != NULL. - * - * Ensures: - * - * *structp == NULL. - * - * All memory allocated by this structure will be returned to the - * system via the ctx's free function. - */ - -int -lwres_noop_render(lwres_context_t *ctx, isc_uint16_t datalength, - void *data, lwres_buffer_t *b); +lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); /* * Allocate space and render into wire format a noop request packet. * @@ -217,8 +314,23 @@ lwres_noop_render(lwres_context_t *ctx, isc_uint16_t datalength, * packet. It can be transmitted in any way, including lwres_sendblock(). */ +int +lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b); + +int +lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b, + lwres_nooprequest_t **structp); + +int +lwres_noopresponse_parse(lwres_context_t *ctx, lwres_noopresponse_t **structp); + void -lwres_freenoop(lwres_context_t *ctx, lwres_noop_t **structp); +lwres_nooprequest_free(lwres_context_t *ctx, lwres_nooprequest_t **structp); + +void +lwres_noopresponse_free(lwres_context_t *ctx, lwres_noopresponse_t **structp); + /* * Frees any dynamically allocated memory for this structure. * @@ -236,38 +348,6 @@ lwres_freenoop(lwres_context_t *ctx, lwres_noop_t **structp); * system via the context's free function. */ -int -lwres_contextcreate(lwres_context_t **contextp, void *arg, - lwres_malloc_t malloc_function, - lwres_free_t free_function); -/* - * Allocate a lwres context. This is used in all lwres calls. - * - * Memory management can be replaced here by passing in two functions. - * If one is non-NULL, they must both be non-NULL. "arg" is passed to - * these functions. - * - * If they are NULL, the standard malloc() and free() will be used. - * - * Requires: - * - * contextp != NULL && contextp == NULL. - * - * Returns: - * - * Returns 0 on success, non-zero on failure. - */ - -void -lwres_freecontext(lwres_context_t **contextp); -/* - * Frees all memory associated with a lwres context. - * - * Requires: - * - * contextp != NULL && contextp == NULL. - */ - ISC_LANG_ENDDECLS #endif /* LWRES_LWRES_H */ diff --git a/lib/lwres/lwpacket.c b/lib/lwres/lwpacket.c new file mode 100644 index 0000000000..74a60f99a5 --- /dev/null +++ b/lib/lwres/lwpacket.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2000 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "assert_p.h" + +int +lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt) +{ + REQUIRE(b != NULL); + REQUIRE(pkt != NULL); +} + +int +lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt) +{ + REQUIRE(b != NULL); + REQUIRE(pkt != NULL); +} diff --git a/lib/lwres/lwres.c b/lib/lwres/lwres.c deleted file mode 100644 index 261d50650c..0000000000 --- a/lib/lwres/lwres.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2000 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. - */ - -/* XXXMLG */ -#define REQUIRE(x) - -#include - -#include -#include -#include - -#include -#include -#include - -static void *lwres_malloc(void *, size_t); -static void lwres_free(void *, void *, size_t); - -/* - * Helper functions, assuming the context is always called "ctx" in - * the scope these functions are called from. - */ -#define CTXMALLOC(len) ctx->malloc(ctx->arg, (len)) -#define CTXFREE(addr, len) ctx->free(ctx->arg, (addr), (len)) - -#define LWRES_DEFAULT_TIMEOUT 30 /* 30 seconds for a reply */ - -/* - * Not all the attributes here are actually settable by the application at - * this time. - */ -struct lwres_context { - unsigned int timeout; /* time to wait for reply */ - isc_uint32_t serial; /* serial number state */ - - /* - * Function pointers for allocating memory. - */ - lwres_malloc_t malloc; - lwres_free_t free; - void *arg; -}; - -int -lwres_contextcreate(lwres_context_t **contextp, void *arg, - lwres_malloc_t malloc_function, - lwres_free_t free_function) -{ - lwres_context_t *ctx; - - /* - * If we were not given anything special to use, use our own - * functions. These are just wrappers around malloc() and free(). - */ - if (malloc_function == NULL || free_function == NULL) { - malloc_function = lwres_malloc; - free_function = lwres_free; - } - - ctx = malloc_function(arg, sizeof(lwres_context_t)); - if (ctx == NULL) { - errno = ENOMEM; - return (-1); - } - - /* - * Set up the context. - */ - ctx->malloc = malloc_function; - ctx->free = free_function; - ctx->arg = arg; - - ctx->timeout = LWRES_DEFAULT_TIMEOUT; - ctx->serial = (isc_uint32_t)ctx; /* XXXMLG */ - - *contextp = ctx; - return (0); -} - -void -lwres_freecontext(lwres_context_t **contextp) -{ - lwres_context_t *ctx; - - ctx = *contextp; - *contextp = NULL; - - CTXFREE(sizeof(lwres_context_t), ctx); -} - -int -lwres_getaddrsbyname(lwres_context_t *contextp, - char *name, isc_uint32_t addrtypes, - lwres_getaddrsbyname_t **structp) -{ - lwres_lwpacket_t pkt; - unsigned char *buf; - unsigned char buflen; - - buflen = sizeof(lwres_lwpacket_t) + strlen(name) + 1 + 1 + 4; -} - -void -lwres_freegetaddrsbyname(lwres_context_t *contextp, - lwres_getaddrsbyname_t **structp) -{ -} - -int -lwres_getaddrsbyname_fromstruct(lwres_context_t *contextp, - isc_uint8_t *buf, size_t len, - lwres_getaddrsbyname_t *gabn) -{ -} - -int -lwres_noop_render(lwres_context_t *ctx, isc_uint16_t datalength, void *data, - lwres_buffer_t *b) -{ - lwres_lwpacket_t pkt; - unsigned char *buf; - size_t buflen; - int ret; - - buflen = sizeof(lwres_lwpacket_t) + sizeof(isc_uint16_t) + datalength; - buf = CTXMALLOC(buflen); - if (buf == NULL) { - errno = ENOMEM; - return (-1); - } - lwres_buffer_init(b, buf, buflen); - - ret = lwres_lwpacket_renderheader(b, &pkt, buflen, 0, ctx->serial++, - LWRES_OPCODE_NOOP, 0, buflen); - if (ret != 0) { - lwres_buffer_invalidate(b); - CTXFREE(buf, buflen); - return (ret); - } - - if (!LWRES_BUFFER_AVAILABLECHECK(b, - datalength + sizeof(isc_uint16_t))) { - CTXFREE(buf, buflen); - lwres_buffer_invalidate(b); - errno = EOVERFLOW; /* this is a programmer botch! */ - return (-1); - } - - /* - * Put the length and the data. We know this will fit because we - * just checked for it. - */ - lwres_buffer_putuint16(b, datalength); - lwres_buffer_putmem(b, data, datalength); - - return (0); -} - -void -lwres_freenoop(lwres_context_t *ctx, lwres_noop_t **structp) -{ -} - -int -lwres_getnamebyaddr(lwres_context_t *ctx, isc_uint32_t addrtype, - isc_uint16_t addrlen, unsigned char *addr, - lwres_getnamebyaddr_t **structp) -{ -} - -void -lwres_freegetnamebyaddr(lwres_context_t *ctx, - lwres_getnamebyaddr_t **structp) -{ -} - -static void * -lwres_malloc(void *arg, size_t len) -{ - void *mem; - - (void)arg; - - mem = malloc(len); - if (mem == NULL) - return (NULL); - - memset(mem, 0xe5, len); - - return (mem); -} - -static void -lwres_free(void *arg, void *mem, size_t len) -{ - (void)arg; - - memset(mem, 0xa9, len); - free(mem); -} diff --git a/lib/lwres/lwres_gabn.c b/lib/lwres/lwres_gabn.c new file mode 100644 index 0000000000..1ae6701fb6 --- /dev/null +++ b/lib/lwres/lwres_gabn.c @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2000 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "context_p.h" +#include "assert_p.h" + +int +lwres_gabnrequest_render(lwres_context_t *ctx, lwres_gabnrequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ + lwres_lwpacket_t pkt; + unsigned char *buf; + size_t buflen; + int ret; + size_t payload_length; + isc_uint16_t datalen; + + REQUIRE(ctx != NULL); + REQUIRE(req != NULL); + REQUIRE(req->name != NULL); + REQUIRE(b != NULL); + + datalen = strlen(req->name); + + payload_length = LWRES_STRING_LENGTH(req->name); + + buflen = sizeof(lwres_lwpacket_t) + payload_length; + buf = CTXMALLOC(buflen); + if (buf == NULL) { + errno = ENOMEM; + return (-1); + } + lwres_buffer_init(b, buf, buflen); + + pkt.length = buflen; + pkt.version = LWRES_LWPACKETVERSION_0; + pkt.flags = 0; + pkt.serial = req->serial; + pkt.opcode = LWRES_OPCODE_GETADDRSBYNAME; + pkt.result = 0; + pkt.recvlength = maxrecv; + pkt.authtype = 0; + pkt.authlength = 0; + + ret = lwres_lwpacket_renderheader(b, &pkt); + if (ret != 0) { + lwres_buffer_invalidate(b); + CTXFREE(buf, buflen); + return (ret); + } + + INSIST(SPACE_OK(b, payload_length)); + + /* + * Put the length and the data. We know this will fit because we + * just checked for it. + */ + lwres_buffer_putuint16(b, datalen); + lwres_buffer_putmem(b, req->name, datalen + 1); /* trailing NUL */ + + INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0); + + return (0); +} + +int +lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ + lwres_lwpacket_t pkt; + unsigned char *buf; + size_t buflen; + int ret; + size_t payload_length; + isc_uint16_t datalen; + int x; + + REQUIRE(ctx != NULL); + REQUIRE(req != NULL); + REQUIRE(b != NULL); + + /* naliases, naddrs */ + payload_length = sizeof(isc_uint16_t) * 2; + /* real name encoding */ + payload_length += LWRES_STRING_LENGTH(req->real_name); + /* each alias */ + for (x = 0 ; x < req->naliases ; x++) + payload_length += LWRES_STRING_LENGTH(req->aliases[x]); + /* each address */ + for (x = 0 ; x < req->naddrs ; x++) { + payload_length += sizeof(isc_uint32_t) + sizeof(isc_uint16_t); + payload_length += req->addrs[x]->length; + } + + buflen = sizeof(lwres_lwpacket_t) + payload_length; + buf = CTXMALLOC(buflen); + if (buf == NULL) { + errno = ENOMEM; + return (-1); + } + lwres_buffer_init(b, buf, buflen); + + pkt.length = buflen; + pkt.version = LWRES_LWPACKETVERSION_0; + pkt.flags = LWRES_LWPACKETFLAG_RESPONSE; + pkt.serial = req->serial; + pkt.opcode = LWRES_OPCODE_GETADDRSBYNAME; + pkt.result = req->result; + pkt.recvlength = maxrecv; + pkt.authtype = 0; + pkt.authlength = 0; + + ret = lwres_lwpacket_renderheader(b, &pkt); + if (ret != 0) { + lwres_buffer_invalidate(b); + CTXFREE(buf, buflen); + return (ret); + } + + /* encode naliases and naddrs */ + + INSIST(SPACE_OK(b, sizeof(isc_uint16_t) * 2)); + lwres_buffer_putuint16(b, req->naliases); + lwres_buffer_putuint16(b, req->naddrs); + + /* encode the real name */ + datalen = strlen(req->real_name); + INSIST(SPACE_OK(b, LWRES_STRING_LENGTH(req->real_name))); + lwres_buffer_putuint16(b, datalen); + lwres_buffer_putmem(b, req->real_name, datalen + 1); + + /* encode the aliases */ + for (x = 0 ; x < req->naliases ; x++) { + datalen = strlen(req->aliases[x]); + INSIST(SPACE_OK(b, LWRES_STRING_LENGTH(req->aliases[x]))); + lwres_buffer_putuint16(b, datalen); + lwres_buffer_putmem(b, req->aliases[x], datalen + 1); + } + + /* encode the addresses */ + for (x = 0 ; x < req->naddrs ; x++) { + datalen = req->addrs[x]->length + sizeof(isc_uint16_t) + + sizeof(isc_uint32_t); + INSIST(SPACE_OK(b, datalen)); + lwres_buffer_putuint32(b, req->addrs[x]->family); + lwres_buffer_putuint16(b, req->addrs[x]->length); + lwres_buffer_putmem(b, req->addrs[x]->address, + req->addrs[x]->length); + } + + INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0); + + return (0); +} + +int +lwres_gabnrequest_parse(lwres_context_t *ctx, lwres_gabnrequest_t **structp) +{ + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp == NULL); + +} + +int +lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_gabnresponse_t **structp) +{ + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp == NULL); + +} + +void +lwres_gabnrequest_free(lwres_context_t *ctx, lwres_gabnrequest_t **structp) +{ + lwres_gabnrequest_t *gabn; + + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp != NULL); + + gabn = *structp; + *structp = NULL; + + if (gabn->buffer != NULL) + CTXFREE(gabn->buffer, gabn->buflen); + CTXFREE(gabn, sizeof(lwres_gabnrequest_t)); +} + +void +lwres_gabnresponse_free(lwres_context_t *ctx, lwres_gabnresponse_t **structp) +{ + lwres_gabnresponse_t *gabn; + + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp != NULL); + + gabn = *structp; + *structp = NULL; + + if (gabn->buffer != NULL) + CTXFREE(gabn->buffer, gabn->buflen); + CTXFREE(gabn, sizeof(lwres_gabnresponse_t)); +} diff --git a/lib/lwres/lwres_gnba.c b/lib/lwres/lwres_gnba.c new file mode 100644 index 0000000000..5dbe6af0ca --- /dev/null +++ b/lib/lwres/lwres_gnba.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2000 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "context_p.h" +#include "assert_p.h" + +int +lwres_gnbarequest_render(lwres_context_t *ctx, + lwres_gnbarequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ +} + +int +lwres_gnbaresponse_render(lwres_context_t *ctx, + lwres_gnbaresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ +} + +int +lwres_gnbarequest_parse(lwres_context_t *ctx, lwres_gnbarequest_t **structp) +{ +} + +int +lwres_gnbaresponse_parse(lwres_context_t *ctx, lwres_gnbaresponse_t **structp) +{ +} + +void +lwres_gnbarequest_free(lwres_context_t *ctx, lwres_gnbarequest_t **structp) +{ +} + +void +lwres_gnbaresponse_free(lwres_context_t *ctx, lwres_gnbaresponse_t **structp) +{ +} diff --git a/lib/lwres/lwres_noop.c b/lib/lwres/lwres_noop.c new file mode 100644 index 0000000000..c597666ea4 --- /dev/null +++ b/lib/lwres/lwres_noop.c @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2000 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. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "context_p.h" +#include "assert_p.h" + +int +lwres_nooprequest_render(lwres_context_t *ctx, lwres_nooprequest_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ + lwres_lwpacket_t pkt; + unsigned char *buf; + size_t buflen; + int ret; + size_t payload_length; + + REQUIRE(ctx != NULL); + REQUIRE(req != NULL); + REQUIRE(b != NULL); + + payload_length = sizeof(isc_uint16_t) + req->datalength; + + buflen = sizeof(lwres_lwpacket_t) + payload_length; + buf = CTXMALLOC(buflen); + if (buf == NULL) { + errno = ENOMEM; + return (-1); + } + lwres_buffer_init(b, buf, buflen); + + pkt.length = buflen; + pkt.version = LWRES_LWPACKETVERSION_0; + pkt.flags = 0; + pkt.serial = req->serial; + pkt.opcode = LWRES_OPCODE_NOOP; + pkt.result = 0; + pkt.recvlength = maxrecv; + pkt.authtype = 0; + pkt.authlength = 0; + + ret = lwres_lwpacket_renderheader(b, &pkt); + if (ret != 0) { + lwres_buffer_invalidate(b); + CTXFREE(buf, buflen); + return (ret); + } + + INSIST(SPACE_OK(b, payload_length)); + + /* + * Put the length and the data. We know this will fit because we + * just checked for it. + */ + lwres_buffer_putuint16(b, req->datalength); + lwres_buffer_putmem(b, req->data, req->datalength); + + INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0); + + return (0); +} + +int +lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req, + isc_uint32_t maxrecv, lwres_buffer_t *b) +{ + lwres_lwpacket_t pkt; + unsigned char *buf; + size_t buflen; + int ret; + size_t payload_length; + + REQUIRE(ctx != NULL); + REQUIRE(req != NULL); + REQUIRE(b != NULL); + + payload_length = sizeof(isc_uint16_t) + req->datalength; + + buflen = sizeof(lwres_lwpacket_t) + payload_length; + buf = CTXMALLOC(buflen); + if (buf == NULL) { + errno = ENOMEM; + return (-1); + } + lwres_buffer_init(b, buf, buflen); + + pkt.length = buflen; + pkt.version = LWRES_LWPACKETVERSION_0; + pkt.flags = LWRES_LWPACKETFLAG_RESPONSE; + pkt.serial = req->serial; + pkt.opcode = LWRES_OPCODE_NOOP; + pkt.result = req->result; + pkt.recvlength = maxrecv; + pkt.authtype = 0; + pkt.authlength = 0; + + ret = lwres_lwpacket_renderheader(b, &pkt); + if (ret != 0) { + lwres_buffer_invalidate(b); + CTXFREE(buf, buflen); + return (ret); + } + + INSIST(SPACE_OK(b, payload_length)); + + /* + * Put the length and the data. We know this will fit because we + * just checked for it. + */ + lwres_buffer_putuint16(b, req->datalength); + lwres_buffer_putmem(b, req->data, req->datalength); + + INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0); + + return (0); +} + +int +lwres_nooprequest_parse(lwres_context_t *ctx, lwres_buffer_t *b, + lwres_nooprequest_t **structp) +{ + lwres_lwpacket_t pkt; + int ret; + + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp == NULL); + REQUIRE(b != NULL); + + /* + * First, parse out the header. + */ + ret = lwres_lwpacket_parseheader(&pkt, b); + if (ret != 0) + return (ret); + + +} + +int +lwres_noopresponse_parse(lwres_context_t *ctx, lwres_noopresponse_t **structp) +{ + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp == NULL); + +} + +void +lwres_noopresponse_free(lwres_context_t *ctx, lwres_noopresponse_t **structp) +{ + lwres_noopresponse_t *noop; + + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp != NULL); + + noop = *structp; + *structp = NULL; + + if (noop->buffer != NULL) + CTXFREE(noop->buffer, noop->buflen); + CTXFREE(noop, sizeof(lwres_noopresponse_t)); +} + +void +lwres_nooprequest_free(lwres_context_t *ctx, lwres_nooprequest_t **structp) +{ + lwres_nooprequest_t *noop; + + REQUIRE(ctx != NULL); + REQUIRE(structp != NULL && *structp != NULL); + + noop = *structp; + *structp = NULL; + + if (noop->buffer != NULL) + CTXFREE(noop->buffer, noop->buflen); + CTXFREE(noop, sizeof(lwres_nooprequest_t)); +}