1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef LWRES_CONTEXT_H
13 #define LWRES_CONTEXT_H 1
14 
15 /*! \file lwres/context.h */
16 
17 #include <inttypes.h>
18 #include <stddef.h>
19 
20 #include <lwres/lang.h>
21 #include <lwres/result.h>
22 
23 /*!
24  * Used to set various options such as timeout, authentication, etc
25  */
26 typedef struct lwres_context lwres_context_t;
27 
28 LWRES_LANG_BEGINDECLS
29 
30 typedef void *(*lwres_malloc_t)(void *arg, size_t length);
31 typedef void (*lwres_free_t)(void *arg, void *mem, size_t length);
32 
33 /*
34  * XXXMLG
35  *
36  * Make the server reload /etc/resolv.conf periodically.
37  *
38  * Make the server do sortlist/searchlist.
39  *
40  * Client side can disable the search/sortlist processing.
41  *
42  * Use an array of addresses/masks and searchlist for client-side, and
43  * if added to the client disable the processing on the server.
44  *
45  * Share /etc/resolv.conf data between contexts.
46  */
47 
48 /*!
49  * _SERVERMODE
50  *	Don't allocate and connect a socket to the server, since the
51  *	caller _is_ a server.
52  *
53  * _USEIPV4, _USEIPV6
54  *	Use IPv4 and IPv6 transactions with remote servers, respectively.
55  *	For backward compatibility, regard both flags as being set when both
56  *	are cleared.
57  */
58 #define LWRES_CONTEXT_SERVERMODE	0x00000001U
59 #define LWRES_CONTEXT_USEIPV4		0x00000002U
60 #define LWRES_CONTEXT_USEIPV6		0x00000004U
61 
62 lwres_result_t
63 lwres_context_create(lwres_context_t **contextp, void *arg,
64 		     lwres_malloc_t malloc_function,
65 		     lwres_free_t free_function,
66 		     unsigned int flags);
67 /**<
68  * Allocate a lwres context.  This is used in all lwres calls.
69  *
70  * Memory management can be replaced here by passing in two functions.
71  * If one is non-NULL, they must both be non-NULL.  "arg" is passed to
72  * these functions.
73  *
74  * Contexts are not thread safe.  Document at the top of the file.
75  * XXXMLG
76  *
77  * If they are NULL, the standard malloc() and free() will be used.
78  *
79  *\pre	contextp != NULL && contextp == NULL.
80  *
81  *\return	Returns 0 on success, non-zero on failure.
82  */
83 
84 void
85 lwres_context_destroy(lwres_context_t **contextp);
86 /**<
87  * Frees all memory associated with a lwres context.
88  *
89  *\pre	contextp != NULL && contextp == NULL.
90  */
91 
92 uint32_t
93 lwres_context_nextserial(lwres_context_t *ctx);
94 /**<
95  * XXXMLG Document
96  */
97 
98 void
99 lwres_context_initserial(lwres_context_t *ctx, uint32_t serial);
100 
101 void
102 lwres_context_freemem(lwres_context_t *ctx, void *mem, size_t len);
103 
104 void *
105 lwres_context_allocmem(lwres_context_t *ctx, size_t len);
106 
107 int
108 lwres_context_getsocket(lwres_context_t *ctx);
109 
110 lwres_result_t
111 lwres_context_send(lwres_context_t *ctx,
112 		   void *sendbase, int sendlen);
113 
114 lwres_result_t
115 lwres_context_recv(lwres_context_t *ctx,
116 		   void *recvbase, int recvlen,
117 		   int *recvd_len);
118 
119 lwres_result_t
120 lwres_context_sendrecv(lwres_context_t *ctx,
121 		       void *sendbase, int sendlen,
122 		       void *recvbase, int recvlen,
123 		       int *recvd_len);
124 
125 LWRES_LANG_ENDDECLS
126 
127 #endif /* LWRES_CONTEXT_H */
128