Some changes Bob suggested, including a lwres_context_t that is opaque, and is used to set options.

This commit is contained in:
Michael Graff 2000-01-12 00:19:04 +00:00
parent 3231b400f3
commit 123d63ebb2
2 changed files with 189 additions and 9 deletions

View file

@ -23,6 +23,11 @@
#include <isc/lang.h>
#include <isc/int.h>
/*
* Used to set various options such as timeout, authentication, etc
*/
typedef struct lwres_context lwres_context_t;
#define LWRES_OPCODE_NOOP 0x00000000U
typedef struct {
/* public */
@ -42,9 +47,9 @@ typedef struct {
typedef struct {
/* public */
isc_uint32_t result;
unsigned char *real_name;
char *real_name;
unsigned int naliases;
unsigned char **aliases;
char **aliases;
unsigned int naddrs;
lwres_addr_t **addrs;
/* private */
@ -57,9 +62,9 @@ typedef struct {
typedef struct {
/* public */
isc_uint32_t result;
unsigned char *real_name;
char *real_name;
unsigned int naliases;
unsigned char **aliases;
char **aliases;
/* private */
unsigned int buflen;
void *buffer; /* must be last to keep alignment */
@ -71,14 +76,20 @@ typedef struct {
ISC_LANG_BEGINDECLS
typedef void *(*lwres_malloc_t)(void *arg, unsigned int length);
typedef void (*lwres_free_t)(void *arg, unsigned int length, void *mem);
unsigned int
lwres_getaddrsbyname(unsigned char *name, unsigned int addrtypes,
lwres_getaddrsbyname(lwres_context_t *context,
char *name, unsigned int addrtypes,
lwres_getaddrsbyname_t **structp);
/*
* Makes a lwres call to look up all addresses associated with "name".
*
* Requires:
*
* context != NULL, and be a context returned via lwres_contextcreate().
*
* structp != NULL && *structp == NULL.
*
* name != NULL, and be a null-terminated string.
@ -97,12 +108,15 @@ lwres_getaddrsbyname(unsigned char *name, unsigned int addrtypes,
*/
void
lwres_freegetaddrsbyname(lwres_getaddrsbyname_t **structp);
lwres_freegetaddrsbyname(lwres_context_t *context,
lwres_getaddrsbyname_t **structp);
/*
* Frees any dynamically allocated memory for this structure.
*
* Requires:
*
* context != NULL, and be a context returned via lwres_contextcreate().
*
* structp != NULL && *structp != NULL.
*
* Ensures:
@ -114,13 +128,16 @@ lwres_freegetaddrsbyname(lwres_getaddrsbyname_t **structp);
*/
unsigned int
lwres_getnamebyaddr(unsigned int addrlen, unsigned char *addr,
unsigned int addrtype, lwres_getnamebyaddr_t **structp);
lwres_getnamebyaddr(lwres_context_t *context, unsigned int addrtype,
unsigned int addrlen, unsigned char *addr,
lwres_getnamebyaddr_t **structp);
/*
* Makes a lwres call to look up the hostnames associated with the address.
*
* Requires:
*
* context != NULL, and be a context returned via lwres_contextcreate().
*
* structp != NULL && *structp == NULL.
*
* addr != NULL, and points to an address of length "addrlen"
@ -138,12 +155,15 @@ lwres_getnamebyaddr(unsigned int addrlen, unsigned char *addr,
*/
void
lwres_freegetnamebyaddr(lwres_getnamebyaddr_t **structp);
lwres_freegetnamebyaddr(lwres_context_t *context,
lwres_getnamebyaddr_t **structp);
/*
* Frees any dynamically allocated memory for this structure.
*
* Requires:
*
* context != NULL, and be a context returned via lwres_contextcreate().
*
* structp != NULL && *structp != NULL.
*
* Ensures:
@ -154,6 +174,40 @@ lwres_freegetnamebyaddr(lwres_getnamebyaddr_t **structp);
* system via free().
*/
unsigned int
lwres_contextcreate(lwres_context_t **contextp, void *arg,
lwres_malloc_t malloc_function,
lwres_free_t free_function);
/*
* Allocated 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_contextfree(lwres_context_t **contextp);
/*
* Frees all memory associated with a lwres context.
*
* Requires:
*
* contextp != NULL && contextp == NULL.
*/
ISC_LANG_ENDDECLS
#endif /* LWRES_LWRES_H */

126
lib/lwres/lwres.c Normal file
View file

@ -0,0 +1,126 @@
/*
* Copyright (C) 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.
*/
/* XXXMLG */
#define REQUIRE(x)
#include <config.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <lwres/lwbuffer.h>
#include <lwres/lwpacket.h>
#include <lwres/lwres.h>
static void *lwres_malloc(void *, size_t);
static void lwres_free(void *, size_t, void *);
/*
* Not all the attributes here are actually settable by the application at
* this time.
*/
struct lwres_context {
/*
* Function pointers for allocating memory.
*/
lwres_malloc_t malloc;
lwres_free_t free;
void *arg;
};
unsigned int
lwres_contextcreate(lwres_context_t **contextp, void *arg,
lwres_malloc_t malloc_function,
lwres_free_t free_function)
{
lwres_context_t *context;
if (malloc_function == NULL) {
malloc_function = lwres_malloc;
free_function = lwres_free;
}
context = malloc_function(arg, sizeof(lwres_context_t));
if (context == NULL) {
errno = ENOMEM;
return (-1);
}
context->free = lwres_free;
context->malloc = lwres_malloc;
context->arg = arg;
*contextp = context;
return (0);
}
void
lwres_contextfree(lwres_context_t **contextp)
{
lwres_context_t *context;
context = *contextp;
*contextp = NULL;
/* This is always allocated via malloc() for now... */
context->free(context->arg, sizeof(lwres_context_t), context);
}
unsigned int
lwres_getaddrsbyname(lwres_context_t *contextp,
char *name, unsigned int addrtypes,
lwres_getaddrsbyname_t **structp)
{
}
void
lwres_freegetaddrsbyname(lwres_context_t *contextp,
lwres_getaddrsbyname_t **structp)
{
}
unsigned int
lwres_getnamebyaddr(lwres_context_t *contextp, unsigned int addrtype,
unsigned int addrlen, unsigned char *addr,
lwres_getnamebyaddr_t **structp)
{
}
void
lwres_freegetnamebyaddr(lwres_context_t *contextp,
lwres_getnamebyaddr_t **structp)
{
}
static void *
lwres_malloc(void *arg, size_t len)
{
(void)arg;
return (malloc(len));
}
static void
lwres_free(void *arg, size_t len, void *mem)
{
(void)arg;
(void)len;
free(mem);
}