1 /* $NetBSD: context.h,v 1.4 2014/12/10 04:38:02 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 2000, 2001 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id: context.h,v 1.23 2008/12/17 23:47:58 tbox Exp */ 21 22 #ifndef LWRES_CONTEXT_H 23 #define LWRES_CONTEXT_H 1 24 25 /*! \file lwres/context.h */ 26 27 #include <stddef.h> 28 29 #include <lwres/lang.h> 30 #include <lwres/int.h> 31 #include <lwres/result.h> 32 33 /*! 34 * Used to set various options such as timeout, authentication, etc 35 */ 36 typedef struct lwres_context lwres_context_t; 37 38 LWRES_LANG_BEGINDECLS 39 40 typedef void *(*lwres_malloc_t)(void *arg, size_t length); 41 typedef void (*lwres_free_t)(void *arg, void *mem, size_t length); 42 43 /* 44 * XXXMLG 45 * 46 * Make the server reload /etc/resolv.conf periodically. 47 * 48 * Make the server do sortlist/searchlist. 49 * 50 * Client side can disable the search/sortlist processing. 51 * 52 * Use an array of addresses/masks and searchlist for client-side, and 53 * if added to the client disable the processing on the server. 54 * 55 * Share /etc/resolv.conf data between contexts. 56 */ 57 58 /*! 59 * _SERVERMODE 60 * Don't allocate and connect a socket to the server, since the 61 * caller _is_ a server. 62 * 63 * _USEIPV4, _USEIPV6 64 * Use IPv4 and IPv6 transactions with remote servers, respectively. 65 * For backward compatibility, regard both flags as being set when both 66 * are cleared. 67 */ 68 #define LWRES_CONTEXT_SERVERMODE 0x00000001U 69 #define LWRES_CONTEXT_USEIPV4 0x00000002U 70 #define LWRES_CONTEXT_USEIPV6 0x00000004U 71 72 lwres_result_t 73 lwres_context_create(lwres_context_t **contextp, void *arg, 74 lwres_malloc_t malloc_function, 75 lwres_free_t free_function, 76 unsigned int flags); 77 /**< 78 * Allocate a lwres context. This is used in all lwres calls. 79 * 80 * Memory management can be replaced here by passing in two functions. 81 * If one is non-NULL, they must both be non-NULL. "arg" is passed to 82 * these functions. 83 * 84 * Contexts are not thread safe. Document at the top of the file. 85 * XXXMLG 86 * 87 * If they are NULL, the standard malloc() and free() will be used. 88 * 89 *\pre contextp != NULL && contextp == NULL. 90 * 91 *\return Returns 0 on success, non-zero on failure. 92 */ 93 94 void 95 lwres_context_destroy(lwres_context_t **contextp); 96 /**< 97 * Frees all memory associated with a lwres context. 98 * 99 *\pre contextp != NULL && contextp == NULL. 100 */ 101 102 lwres_uint32_t 103 lwres_context_nextserial(lwres_context_t *ctx); 104 /**< 105 * XXXMLG Document 106 */ 107 108 void 109 lwres_context_initserial(lwres_context_t *ctx, lwres_uint32_t serial); 110 111 void 112 lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len); 113 114 void * 115 lwres_context_allocmem(lwres_context_t *ctx, size_t len); 116 117 int 118 lwres_context_getsocket(lwres_context_t *ctx); 119 120 lwres_result_t 121 lwres_context_send(lwres_context_t *ctx, 122 void *sendbase, int sendlen); 123 124 lwres_result_t 125 lwres_context_recv(lwres_context_t *ctx, 126 void *recvbase, int recvlen, 127 int *recvd_len); 128 129 lwres_result_t 130 lwres_context_sendrecv(lwres_context_t *ctx, 131 void *sendbase, int sendlen, 132 void *recvbase, int recvlen, 133 int *recvd_len); 134 135 LWRES_LANG_ENDDECLS 136 137 #endif /* LWRES_CONTEXT_H */ 138 139