getdns/src/getdns/getdns_extra.h

144 lines
5.3 KiB
C

/*
* Copyright (c) 2013, NLNet Labs, Verisign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETDNS_EXTRA_H_
#define _GETDNS_EXTRA_H_
#include <getdns/getdns.h>
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Enable the return_dnssec_status extension on every request.
value is either GETDNS_EXTENSION_TRUE or GETDNS_EXTENSION_FALSE
returns GETDNS_RETURN_GOOD on success or GETDNS_RETURN_INVALID_PARAMETER
if context or value is invalid */
getdns_return_t getdns_context_set_return_dnssec_status(
getdns_context *context, int enabled);
/* dict util */
/* set a string as bindata */
getdns_return_t getdns_dict_util_set_string(struct getdns_dict * dict,
char *name, const char *value);
/* get a string from a dict. the result must be freed if valid */
getdns_return_t getdns_dict_util_get_string(struct getdns_dict * dict,
char *name, char **result);
/* get the fd */
int getdns_context_fd(getdns_context* context);
/* tells underlying unbound to use background threads or fork */
getdns_return_t getdns_context_set_use_threads(getdns_context* context,
int use_threads);
/* Async support */
uint32_t getdns_context_get_num_pending_requests(getdns_context* context,
struct timeval* next_timeout);
/* process async reqs */
getdns_return_t getdns_context_process_async(getdns_context* context);
/***************** functions for eventloop extensions ******************/
typedef void (*getdns_eventloop_callback)(void *userarg);
/* context extension event data */
typedef struct getdns_eventloop_event {
void *userarg;
getdns_eventloop_callback read_cb;
getdns_eventloop_callback timeout_cb;
/* Pointer to the underlying event
* that the eventloop extension will create and free.
*/
void *ev;
} getdns_eventloop_event;
typedef struct getdns_eventloop_functions getdns_eventloop_functions;
typedef struct getdns_eventloop {
getdns_eventloop_functions *functions;
} getdns_eventloop;
/* Call the extension to clean up data allocated on initialization. */
typedef getdns_return_t (*getdns_eventloop_cleanup)(getdns_eventloop *loop);
/* Call the extension to schedule an event that will trigger when
* file descriptor fd will become readble.
*
* The getdns_eventloop_event must be provided by the caller with the callbacks
* and userarg therein already supplied (by the caller). This function must set
* the ev pointer (in the getdns_eventloop_event) to refer to the underlying
* (extension) event.
*/
typedef getdns_return_t (*getdns_eventloop_schedule_read)(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *ev);
/* Call the extension to free a read event. */
typedef getdns_return_t (*getdns_eventloop_clear_read)
(getdns_eventloop *loop, getdns_eventloop_event *ev);
/* Call the extension to schedule a timer.
*
* The getdns_eventloop_event must be provided by the caller with the timeout
* callback and userarg therein already supplied (by the caller).
* This function must set the ev pointer (in the getdns_eventloop_event)
* to refer to the underlying (extension) event.
*/
typedef getdns_return_t (*getdns_eventloop_schedule_timeout)
(getdns_eventloop *loop, uint64_t timeout, getdns_eventloop_event *ev);
/* Call the extension to free a timer. */
typedef getdns_return_t (*getdns_eventloop_clear_timeout)
(getdns_eventloop *loop, getdns_eventloop_event *ev);
struct getdns_eventloop_functions {
getdns_eventloop_cleanup cleanup;
getdns_eventloop_schedule_read schedule_read;
getdns_eventloop_clear_read clear_read;
getdns_eventloop_schedule_timeout schedule_timeout;
getdns_eventloop_clear_timeout clear_timeout;
};
/* set an event loop extension on the context */
getdns_return_t
getdns_context_set_eventloop(getdns_context* context,
getdns_eventloop *eventloop);
/* detach the eventloop from the context */
getdns_return_t
getdns_context_detach_eventloop(getdns_context *context);
#ifdef __cplusplus
}
#endif
#endif