1238106Sdes/*
2238106Sdes * unbound.h - unbound validating resolver public API
3238106Sdes *
4238106Sdes * Copyright (c) 2007, NLnet Labs. All rights reserved.
5238106Sdes *
6238106Sdes * This software is open source.
7238106Sdes *
8238106Sdes * Redistribution and use in source and binary forms, with or without
9238106Sdes * modification, are permitted provided that the following conditions
10238106Sdes * are met:
11238106Sdes *
12238106Sdes * Redistributions of source code must retain the above copyright notice,
13238106Sdes * this list of conditions and the following disclaimer.
14238106Sdes *
15238106Sdes * Redistributions in binary form must reproduce the above copyright notice,
16238106Sdes * this list of conditions and the following disclaimer in the documentation
17238106Sdes * and/or other materials provided with the distribution.
18238106Sdes *
19238106Sdes * Neither the name of the NLNET LABS nor the names of its contributors may
20238106Sdes * be used to endorse or promote products derived from this software without
21238106Sdes * specific prior written permission.
22238106Sdes *
23238106Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24238106Sdes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25238106Sdes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26238106Sdes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27238106Sdes * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28238106Sdes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29238106Sdes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30238106Sdes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31238106Sdes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32238106Sdes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33238106Sdes * POSSIBILITY OF SUCH DAMAGE.
34238106Sdes */
35238106Sdes
36238106Sdes/**
37238106Sdes * \file
38238106Sdes *
39238106Sdes * This file contains functions to resolve DNS queries and
40238106Sdes * validate the answers. Synchonously and asynchronously.
41238106Sdes *
42238106Sdes * Several ways to use this interface from an application wishing
43238106Sdes * to perform (validated) DNS lookups.
44238106Sdes *
45238106Sdes * All start with
46238106Sdes *	ctx = ub_ctx_create();
47238106Sdes *	err = ub_ctx_add_ta(ctx, "...");
48238106Sdes *	err = ub_ctx_add_ta(ctx, "...");
49238106Sdes *	... some lookups
50238106Sdes *	... call ub_ctx_delete(ctx); when you want to stop.
51238106Sdes *
52238106Sdes * Application not threaded. Blocking.
53238106Sdes *	int err = ub_resolve(ctx, "www.example.com", ...
54238106Sdes *	if(err) fprintf(stderr, "lookup error: %s\n", ub_strerror(err));
55238106Sdes *	... use the answer
56238106Sdes *
57238106Sdes * Application not threaded. Non-blocking ('asynchronous').
58238106Sdes *      err = ub_resolve_async(ctx, "www.example.com", ... my_callback);
59238106Sdes *	... application resumes processing ...
60238106Sdes *	... and when either ub_poll(ctx) is true
61238106Sdes *	... or when the file descriptor ub_fd(ctx) is readable,
62238106Sdes *	... or whenever, the app calls ...
63238106Sdes *	ub_process(ctx);
64238106Sdes *	... if no result is ready, the app resumes processing above,
65238106Sdes *	... or process() calls my_callback() with results.
66238106Sdes *
67238106Sdes *      ... if the application has nothing more to do, wait for answer
68238106Sdes *      ub_wait(ctx);
69238106Sdes *
70238106Sdes * Application threaded. Blocking.
71238106Sdes *	Blocking, same as above. The current thread does the work.
72238106Sdes *	Multiple threads can use the *same context*, each does work and uses
73238106Sdes *	shared cache data from the context.
74238106Sdes *
75238106Sdes * Application threaded. Non-blocking ('asynchronous').
76238106Sdes *	... setup threaded-asynchronous config option
77238106Sdes *	err = ub_ctx_async(ctx, 1);
78238106Sdes *	... same as async for non-threaded
79238106Sdes *	... the callbacks are called in the thread that calls process(ctx)
80238106Sdes *
81238106Sdes * If no threading is compiled in, the above async example uses fork(2) to
82238106Sdes * create a process to perform the work. The forked process exits when the
83238106Sdes * calling process exits, or ctx_delete() is called.
84238106Sdes * Otherwise, for asynchronous with threading, a worker thread is created.
85238106Sdes *
86238106Sdes * The blocking calls use shared ctx-cache when threaded. Thus
87238106Sdes * ub_resolve() and ub_resolve_async() && ub_wait() are
88238106Sdes * not the same. The first makes the current thread do the work, setting
89238106Sdes * up buffers, etc, to perform the work (but using shared cache data).
90238106Sdes * The second calls another worker thread (or process) to perform the work.
91238106Sdes * And no buffers need to be set up, but a context-switch happens.
92238106Sdes */
93238106Sdes#ifndef _UB_UNBOUND_H
94238106Sdes#define _UB_UNBOUND_H
95238106Sdes
96238106Sdes#ifdef __cplusplus
97238106Sdesextern "C" {
98238106Sdes#endif
99238106Sdes
100238106Sdes/**
101238106Sdes * The validation context is created to hold the resolver status,
102238106Sdes * validation keys and a small cache (containing messages, rrsets,
103238106Sdes * roundtrip times, trusted keys, lameness information).
104238106Sdes *
105238106Sdes * Its contents are internally defined.
106238106Sdes */
107238106Sdesstruct ub_ctx;
108238106Sdes
109238106Sdes/**
110238106Sdes * The validation and resolution results.
111238106Sdes * Allocated by the resolver, and need to be freed by the application
112238106Sdes * with ub_resolve_free().
113238106Sdes */
114238106Sdesstruct ub_result {
115238106Sdes	/** The original question, name text string. */
116238106Sdes	char* qname;
117238106Sdes	/** the type asked for */
118238106Sdes	int qtype;
119238106Sdes	/** the class asked for */
120238106Sdes	int qclass;
121238106Sdes
122238106Sdes	/**
123238106Sdes	 * a list of network order DNS rdata items, terminated with a
124238106Sdes	 * NULL pointer, so that data[0] is the first result entry,
125238106Sdes	 * data[1] the second, and the last entry is NULL.
126238106Sdes	 * If there was no data, data[0] is NULL.
127238106Sdes	 */
128238106Sdes	char** data;
129238106Sdes
130238106Sdes	/** the length in bytes of the data items, len[i] for data[i] */
131238106Sdes	int* len;
132238106Sdes
133238106Sdes	/**
134238106Sdes	 * canonical name for the result (the final cname).
135238106Sdes	 * zero terminated string.
136238106Sdes	 * May be NULL if no canonical name exists.
137238106Sdes	 */
138238106Sdes	char* canonname;
139238106Sdes
140238106Sdes	/**
141238106Sdes	 * DNS RCODE for the result. May contain additional error code if
142238106Sdes	 * there was no data due to an error. 0 (NOERROR) if okay.
143238106Sdes	 */
144238106Sdes	int rcode;
145238106Sdes
146238106Sdes	/**
147238106Sdes	 * The DNS answer packet. Network formatted. Can contain DNSSEC types.
148238106Sdes	 */
149238106Sdes	void* answer_packet;
150238106Sdes	/** length of the answer packet in octets. */
151238106Sdes	int answer_len;
152238106Sdes
153238106Sdes	/**
154238106Sdes	 * If there is any data, this is true.
155238106Sdes	 * If false, there was no data (nxdomain may be true, rcode can be set).
156238106Sdes	 */
157238106Sdes	int havedata;
158238106Sdes
159238106Sdes	/**
160238106Sdes	 * If there was no data, and the domain did not exist, this is true.
161238106Sdes	 * If it is false, and there was no data, then the domain name
162238106Sdes	 * is purported to exist, but the requested data type is not available.
163238106Sdes	 */
164238106Sdes	int nxdomain;
165238106Sdes
166238106Sdes	/**
167238106Sdes	 * True, if the result is validated securely.
168238106Sdes	 * False, if validation failed or domain queried has no security info.
169238106Sdes	 *
170238106Sdes	 * It is possible to get a result with no data (havedata is false),
171238106Sdes	 * and secure is true. This means that the non-existance of the data
172238106Sdes	 * was cryptographically proven (with signatures).
173238106Sdes	 */
174238106Sdes	int secure;
175238106Sdes
176238106Sdes	/**
177238106Sdes	 * If the result was not secure (secure==0), and this result is due
178238106Sdes	 * to a security failure, bogus is true.
179238106Sdes	 * This means the data has been actively tampered with, signatures
180238106Sdes	 * failed, expected signatures were not present, timestamps on
181238106Sdes	 * signatures were out of date and so on.
182238106Sdes	 *
183238106Sdes	 * If !secure and !bogus, this can happen if the data is not secure
184238106Sdes	 * because security is disabled for that domain name.
185238106Sdes	 * This means the data is from a domain where data is not signed.
186238106Sdes	 */
187238106Sdes	int bogus;
188238106Sdes
189238106Sdes	/**
190238106Sdes	 * If the result is bogus this contains a string (zero terminated)
191238106Sdes	 * that describes the failure.  There may be other errors as well
192238106Sdes	 * as the one described, the description may not be perfectly accurate.
193238106Sdes	 * Is NULL if the result is not bogus.
194238106Sdes	 */
195238106Sdes	char* why_bogus;
196249141Sdes
197249141Sdes	/**
198249141Sdes	 * TTL for the result, in seconds.  If the security is bogus, then
199249141Sdes	 * you also cannot trust this value.
200249141Sdes	 */
201249141Sdes	int ttl;
202238106Sdes};
203238106Sdes
204238106Sdes/**
205238106Sdes * Callback for results of async queries.
206238106Sdes * The readable function definition looks like:
207238106Sdes * void my_callback(void* my_arg, int err, struct ub_result* result);
208238106Sdes * It is called with
209238106Sdes *	void* my_arg: your pointer to a (struct of) data of your choice,
210238106Sdes *		or NULL.
211238106Sdes *	int err: if 0 all is OK, otherwise an error occured and no results
212238106Sdes *	     are forthcoming.
213238106Sdes *	struct result: pointer to more detailed result structure.
214238106Sdes *		This structure is allocated on the heap and needs to be
215238106Sdes *		freed with ub_resolve_free(result);
216238106Sdes */
217238106Sdestypedef void (*ub_callback_t)(void*, int, struct ub_result*);
218238106Sdes
219238106Sdes/**
220238106Sdes * Create a resolving and validation context.
221238106Sdes * The information from /etc/resolv.conf and /etc/hosts is not utilised by
222238106Sdes * default. Use ub_ctx_resolvconf and ub_ctx_hosts to read them.
223238106Sdes * @return a new context. default initialisation.
224238106Sdes * 	returns NULL on error.
225238106Sdes */
226238106Sdesstruct ub_ctx* ub_ctx_create(void);
227238106Sdes
228238106Sdes/**
229238106Sdes * Destroy a validation context and free all its resources.
230238106Sdes * Outstanding async queries are killed and callbacks are not called for them.
231238106Sdes * @param ctx: context to delete.
232238106Sdes */
233238106Sdesvoid ub_ctx_delete(struct ub_ctx* ctx);
234238106Sdes
235238106Sdes/**
236238106Sdes * Set an option for the context.
237238106Sdes * @param ctx: context.
238238106Sdes * @param opt: option name from the unbound.conf config file format.
239238106Sdes *	(not all settings applicable). The name includes the trailing ':'
240238106Sdes *	for example ub_ctx_set_option(ctx, "logfile:", "mylog.txt");
241238106Sdes * 	This is a power-users interface that lets you specify all sorts
242238106Sdes * 	of options.
243238106Sdes * 	For some specific options, such as adding trust anchors, special
244238106Sdes * 	routines exist.
245238106Sdes * @param val: value of the option.
246238106Sdes * @return: 0 if OK, else error.
247238106Sdes */
248255584Sdesint ub_ctx_set_option(struct ub_ctx* ctx, const char* opt, const char* val);
249238106Sdes
250238106Sdes/**
251238106Sdes * Get an option from the context.
252238106Sdes * @param ctx: context.
253238106Sdes * @param opt: option name from the unbound.conf config file format.
254238106Sdes *	(not all settings applicable). The name excludes the trailing ':'
255238106Sdes *	for example ub_ctx_get_option(ctx, "logfile", &result);
256238106Sdes * 	This is a power-users interface that lets you specify all sorts
257238106Sdes * 	of options.
258238106Sdes * @param str: the string is malloced and returned here. NULL on error.
259238106Sdes * 	The caller must free() the string.  In cases with multiple
260238106Sdes * 	entries (auto-trust-anchor-file), a newline delimited list is
261238106Sdes * 	returned in the string.
262238106Sdes * @return 0 if OK else an error code (malloc failure, syntax error).
263238106Sdes */
264255584Sdesint ub_ctx_get_option(struct ub_ctx* ctx, const char* opt, char** str);
265238106Sdes
266238106Sdes/**
267238106Sdes * setup configuration for the given context.
268238106Sdes * @param ctx: context.
269238106Sdes * @param fname: unbound config file (not all settings applicable).
270238106Sdes * 	This is a power-users interface that lets you specify all sorts
271238106Sdes * 	of options.
272238106Sdes * 	For some specific options, such as adding trust anchors, special
273238106Sdes * 	routines exist.
274238106Sdes * @return: 0 if OK, else error.
275238106Sdes */
276255584Sdesint ub_ctx_config(struct ub_ctx* ctx, const char* fname);
277238106Sdes
278238106Sdes/**
279238106Sdes * Set machine to forward DNS queries to, the caching resolver to use.
280238106Sdes * IP4 or IP6 address. Forwards all DNS requests to that machine, which
281238106Sdes * is expected to run a recursive resolver. If the proxy is not
282238106Sdes * DNSSEC-capable, validation may fail. Can be called several times, in
283238106Sdes * that case the addresses are used as backup servers.
284238106Sdes *
285238106Sdes * To read the list of nameservers from /etc/resolv.conf (from DHCP or so),
286238106Sdes * use the call ub_ctx_resolvconf.
287238106Sdes *
288238106Sdes * @param ctx: context.
289238106Sdes *	At this time it is only possible to set configuration before the
290238106Sdes *	first resolve is done.
291238106Sdes * @param addr: address, IP4 or IP6 in string format.
292238106Sdes * 	If the addr is NULL, forwarding is disabled.
293238106Sdes * @return 0 if OK, else error.
294238106Sdes */
295255584Sdesint ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr);
296238106Sdes
297238106Sdes/**
298238106Sdes * Read list of nameservers to use from the filename given.
299238106Sdes * Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
300238106Sdes * If they do not support DNSSEC, validation may fail.
301238106Sdes *
302238106Sdes * Only nameservers are picked up, the searchdomain, ndots and other
303238106Sdes * settings from resolv.conf(5) are ignored.
304238106Sdes *
305238106Sdes * @param ctx: context.
306238106Sdes *	At this time it is only possible to set configuration before the
307238106Sdes *	first resolve is done.
308238106Sdes * @param fname: file name string. If NULL "/etc/resolv.conf" is used.
309238106Sdes * @return 0 if OK, else error.
310238106Sdes */
311255584Sdesint ub_ctx_resolvconf(struct ub_ctx* ctx, const char* fname);
312238106Sdes
313238106Sdes/**
314238106Sdes * Read list of hosts from the filename given.
315238106Sdes * Usually "/etc/hosts".
316238106Sdes * These addresses are not flagged as DNSSEC secure when queried for.
317238106Sdes *
318238106Sdes * @param ctx: context.
319238106Sdes *	At this time it is only possible to set configuration before the
320238106Sdes *	first resolve is done.
321238106Sdes * @param fname: file name string. If NULL "/etc/hosts" is used.
322238106Sdes * @return 0 if OK, else error.
323238106Sdes */
324255584Sdesint ub_ctx_hosts(struct ub_ctx* ctx, const char* fname);
325238106Sdes
326238106Sdes/**
327238106Sdes * Add a trust anchor to the given context.
328238106Sdes * The trust anchor is a string, on one line, that holds a valid DNSKEY or
329238106Sdes * DS RR.
330238106Sdes * @param ctx: context.
331238106Sdes *	At this time it is only possible to add trusted keys before the
332238106Sdes *	first resolve is done.
333238106Sdes * @param ta: string, with zone-format RR on one line.
334238106Sdes * 	[domainname] [TTL optional] [type] [class optional] [rdata contents]
335238106Sdes * @return 0 if OK, else error.
336238106Sdes */
337255584Sdesint ub_ctx_add_ta(struct ub_ctx* ctx, const char* ta);
338238106Sdes
339238106Sdes/**
340238106Sdes * Add trust anchors to the given context.
341238106Sdes * Pass name of a file with DS and DNSKEY records (like from dig or drill).
342238106Sdes * @param ctx: context.
343238106Sdes *	At this time it is only possible to add trusted keys before the
344238106Sdes *	first resolve is done.
345238106Sdes * @param fname: filename of file with keyfile with trust anchors.
346238106Sdes * @return 0 if OK, else error.
347238106Sdes */
348255584Sdesint ub_ctx_add_ta_file(struct ub_ctx* ctx, const char* fname);
349238106Sdes
350238106Sdes/**
351238106Sdes * Add trust anchors to the given context.
352238106Sdes * Pass the name of a bind-style config file with trusted-keys{}.
353238106Sdes * @param ctx: context.
354238106Sdes *	At this time it is only possible to add trusted keys before the
355238106Sdes *	first resolve is done.
356238106Sdes * @param fname: filename of file with bind-style config entries with trust
357238106Sdes * 	anchors.
358238106Sdes * @return 0 if OK, else error.
359238106Sdes */
360255584Sdesint ub_ctx_trustedkeys(struct ub_ctx* ctx, const char* fname);
361238106Sdes
362238106Sdes/**
363238106Sdes * Set debug output (and error output) to the specified stream.
364238106Sdes * Pass NULL to disable. Default is stderr.
365238106Sdes * @param ctx: context.
366238106Sdes * @param out: FILE* out file stream to log to.
367238106Sdes * 	Type void* to avoid stdio dependency of this header file.
368238106Sdes * @return 0 if OK, else error.
369238106Sdes */
370238106Sdesint ub_ctx_debugout(struct ub_ctx* ctx, void* out);
371238106Sdes
372238106Sdes/**
373238106Sdes * Set debug verbosity for the context
374238106Sdes * Output is directed to stderr.
375238106Sdes * @param ctx: context.
376238106Sdes * @param d: debug level, 0 is off, 1 is very minimal, 2 is detailed,
377238106Sdes *	and 3 is lots.
378238106Sdes * @return 0 if OK, else error.
379238106Sdes */
380238106Sdesint ub_ctx_debuglevel(struct ub_ctx* ctx, int d);
381238106Sdes
382238106Sdes/**
383238106Sdes * Set a context behaviour for asynchronous action.
384238106Sdes * @param ctx: context.
385238106Sdes * @param dothread: if true, enables threading and a call to resolve_async()
386238106Sdes *	creates a thread to handle work in the background.
387238106Sdes *	If false, a process is forked to handle work in the background.
388238106Sdes *	Changes to this setting after async() calls have been made have
389238106Sdes *	no effect (delete and re-create the context to change).
390238106Sdes * @return 0 if OK, else error.
391238106Sdes */
392238106Sdesint ub_ctx_async(struct ub_ctx* ctx, int dothread);
393238106Sdes
394238106Sdes/**
395238106Sdes * Poll a context to see if it has any new results
396238106Sdes * Do not poll in a loop, instead extract the fd below to poll for readiness,
397238106Sdes * and then check, or wait using the wait routine.
398238106Sdes * @param ctx: context.
399238106Sdes * @return: 0 if nothing to read, or nonzero if a result is available.
400238106Sdes * 	If nonzero, call ctx_process() to do callbacks.
401238106Sdes */
402238106Sdesint ub_poll(struct ub_ctx* ctx);
403238106Sdes
404238106Sdes/**
405238106Sdes * Wait for a context to finish with results. Calls ub_process() after
406238106Sdes * the wait for you. After the wait, there are no more outstanding
407238106Sdes * asynchronous queries.
408238106Sdes * @param ctx: context.
409238106Sdes * @return: 0 if OK, else error.
410238106Sdes */
411238106Sdesint ub_wait(struct ub_ctx* ctx);
412238106Sdes
413238106Sdes/**
414238106Sdes * Get file descriptor. Wait for it to become readable, at this point
415238106Sdes * answers are returned from the asynchronous validating resolver.
416238106Sdes * Then call the ub_process to continue processing.
417238106Sdes * This routine works immediately after context creation, the fd
418238106Sdes * does not change.
419238106Sdes * @param ctx: context.
420238106Sdes * @return: -1 on error, or file descriptor to use select(2) with.
421238106Sdes */
422238106Sdesint ub_fd(struct ub_ctx* ctx);
423238106Sdes
424238106Sdes/**
425238106Sdes * Call this routine to continue processing results from the validating
426238106Sdes * resolver (when the fd becomes readable).
427238106Sdes * Will perform necessary callbacks.
428238106Sdes * @param ctx: context
429238106Sdes * @return: 0 if OK, else error.
430238106Sdes */
431238106Sdesint ub_process(struct ub_ctx* ctx);
432238106Sdes
433238106Sdes/**
434238106Sdes * Perform resolution and validation of the target name.
435238106Sdes * @param ctx: context.
436238106Sdes *	The context is finalized, and can no longer accept config changes.
437238106Sdes * @param name: domain name in text format (a zero terminated text string).
438238106Sdes * @param rrtype: type of RR in host order, 1 is A (address).
439238106Sdes * @param rrclass: class of RR in host order, 1 is IN (for internet).
440238106Sdes * @param result: the result data is returned in a newly allocated result
441238106Sdes * 	structure. May be NULL on return, return value is set to an error
442238106Sdes * 	in that case (out of memory).
443238106Sdes * @return 0 if OK, else error.
444238106Sdes */
445255584Sdesint ub_resolve(struct ub_ctx* ctx, const char* name, int rrtype,
446238106Sdes	int rrclass, struct ub_result** result);
447238106Sdes
448238106Sdes/**
449238106Sdes * Perform resolution and validation of the target name.
450238106Sdes * Asynchronous, after a while, the callback will be called with your
451238106Sdes * data and the result.
452238106Sdes * @param ctx: context.
453238106Sdes *	If no thread or process has been created yet to perform the
454238106Sdes *	work in the background, it is created now.
455238106Sdes *	The context is finalized, and can no longer accept config changes.
456238106Sdes * @param name: domain name in text format (a string).
457238106Sdes * @param rrtype: type of RR in host order, 1 is A.
458238106Sdes * @param rrclass: class of RR in host order, 1 is IN (for internet).
459238106Sdes * @param mydata: this data is your own data (you can pass NULL),
460238106Sdes * 	and is passed on to the callback function.
461238106Sdes * @param callback: this is called on completion of the resolution.
462238106Sdes * 	It is called as:
463238106Sdes * 	void callback(void* mydata, int err, struct ub_result* result)
464238106Sdes * 	with mydata: the same as passed here, you may pass NULL,
465238106Sdes * 	with err: is 0 when a result has been found.
466238106Sdes * 	with result: a newly allocated result structure.
467238106Sdes *		The result may be NULL, in that case err is set.
468238106Sdes *
469238106Sdes * 	If an error happens during processing, your callback will be called
470238106Sdes * 	with error set to a nonzero value (and result==NULL).
471238106Sdes * @param async_id: if you pass a non-NULL value, an identifier number is
472238106Sdes *	returned for the query as it is in progress. It can be used to
473238106Sdes *	cancel the query.
474238106Sdes * @return 0 if OK, else error.
475238106Sdes */
476255584Sdesint ub_resolve_async(struct ub_ctx* ctx, const char* name, int rrtype,
477238106Sdes	int rrclass, void* mydata, ub_callback_t callback, int* async_id);
478238106Sdes
479238106Sdes/**
480238106Sdes * Cancel an async query in progress.
481238106Sdes * Its callback will not be called.
482238106Sdes *
483238106Sdes * @param ctx: context.
484238106Sdes * @param async_id: which query to cancel.
485238106Sdes * @return 0 if OK, else error.
486238106Sdes * This routine can return an error if the async_id passed does not exist
487238106Sdes * or has already been delivered. If another thread is processing results
488238106Sdes * at the same time, the result may be delivered at the same time and the
489238106Sdes * cancel fails with an error.  Also the cancel can fail due to a system
490238106Sdes * error, no memory or socket failures.
491238106Sdes */
492238106Sdesint ub_cancel(struct ub_ctx* ctx, int async_id);
493238106Sdes
494238106Sdes/**
495238106Sdes * Free storage associated with a result structure.
496238106Sdes * @param result: to free
497238106Sdes */
498238106Sdesvoid ub_resolve_free(struct ub_result* result);
499238106Sdes
500238106Sdes/**
501238106Sdes * Convert error value to a human readable string.
502238106Sdes * @param err: error code from one of the ub_val* functions.
503238106Sdes * @return pointer to constant text string, zero terminated.
504238106Sdes */
505238106Sdesconst char* ub_strerror(int err);
506238106Sdes
507238106Sdes/**
508238106Sdes * Debug routine.  Print the local zone information to debug output.
509238106Sdes * @param ctx: context.  Is finalized by the routine.
510238106Sdes * @return 0 if OK, else error.
511238106Sdes */
512238106Sdesint ub_ctx_print_local_zones(struct ub_ctx* ctx);
513238106Sdes
514238106Sdes/**
515238106Sdes * Add a new zone with the zonetype to the local authority info of the
516238106Sdes * library.
517238106Sdes * @param ctx: context.  Is finalized by the routine.
518238106Sdes * @param zone_name: name of the zone in text, "example.com"
519238106Sdes *	If it already exists, the type is updated.
520238106Sdes * @param zone_type: type of the zone (like for unbound.conf) in text.
521238106Sdes * @return 0 if OK, else error.
522238106Sdes */
523238106Sdesint ub_ctx_zone_add(struct ub_ctx* ctx, char *zone_name, char *zone_type);
524238106Sdes
525238106Sdes/**
526238106Sdes * Remove zone from local authority info of the library.
527238106Sdes * @param ctx: context.  Is finalized by the routine.
528238106Sdes * @param zone_name: name of the zone in text, "example.com"
529238106Sdes *	If it does not exist, nothing happens.
530238106Sdes * @return 0 if OK, else error.
531238106Sdes */
532238106Sdesint ub_ctx_zone_remove(struct ub_ctx* ctx, char *zone_name);
533238106Sdes
534238106Sdes/**
535238106Sdes * Add localdata to the library local authority info.
536238106Sdes * Similar to local-data config statement.
537238106Sdes * @param ctx: context.  Is finalized by the routine.
538238106Sdes * @param data: the resource record in text format, for example
539238106Sdes *	"www.example.com IN A 127.0.0.1"
540238106Sdes * @return 0 if OK, else error.
541238106Sdes */
542238106Sdesint ub_ctx_data_add(struct ub_ctx* ctx, char *data);
543238106Sdes
544238106Sdes/**
545238106Sdes * Remove localdata from the library local authority info.
546238106Sdes * @param ctx: context.  Is finalized by the routine.
547238106Sdes * @param data: the name to delete all data from, like "www.example.com".
548238106Sdes * @return 0 if OK, else error.
549238106Sdes */
550238106Sdesint ub_ctx_data_remove(struct ub_ctx* ctx, char *data);
551238106Sdes
552238106Sdes/**
553238106Sdes * Get a version string from the libunbound implementation.
554238106Sdes * @return a static constant string with the version number.
555238106Sdes */
556238106Sdesconst char* ub_version(void);
557238106Sdes
558238106Sdes#ifdef __cplusplus
559238106Sdes}
560238106Sdes#endif
561238106Sdes
562238106Sdes#endif /* _UB_UNBOUND_H */
563