mirror of https://github.com/getdnsapi/getdns.git
Add timeout support
This commit is contained in:
commit
1f847b0d96
|
@ -31,6 +31,7 @@ tests_dict
|
||||||
tests_list
|
tests_list
|
||||||
tests_stub_async
|
tests_stub_async
|
||||||
tests_stub_sync
|
tests_stub_sync
|
||||||
|
src/test/tests_dnssec
|
||||||
src/example/example-reverse
|
src/example/example-reverse
|
||||||
src/test/check_getdns.log
|
src/test/check_getdns.log
|
||||||
check_getdns
|
check_getdns
|
||||||
|
|
|
@ -86,7 +86,7 @@ example:
|
||||||
clean:
|
clean:
|
||||||
cd test && $(MAKE) $@
|
cd test && $(MAKE) $@
|
||||||
cd example && $(MAKE) $@
|
cd example && $(MAKE) $@
|
||||||
rm -f *.o *.lo $(PROGRAMS) libgetdns.la
|
rm -f *.o *.lo extension/*.lo $(PROGRAMS) libgetdns.la
|
||||||
rm -rf .libs
|
rm -rf .libs
|
||||||
|
|
||||||
distclean : clean
|
distclean : clean
|
||||||
|
|
304
src/context.c
304
src/context.c
|
@ -1,31 +1,37 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns contect management functions
|
* \file context.c
|
||||||
|
* @brief getdns context management functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -54,7 +60,6 @@ static struct getdns_list *create_from_ldns_list(struct getdns_context *,
|
||||||
static getdns_return_t set_os_defaults(struct getdns_context *);
|
static getdns_return_t set_os_defaults(struct getdns_context *);
|
||||||
static int transaction_id_cmp(const void *, const void *);
|
static int transaction_id_cmp(const void *, const void *);
|
||||||
static int timeout_cmp(const void *, const void *);
|
static int timeout_cmp(const void *, const void *);
|
||||||
static int transaction_id_timeout_cmp(const void *, const void *);
|
|
||||||
static void set_ub_string_opt(struct getdns_context *, char *, char *);
|
static void set_ub_string_opt(struct getdns_context *, char *, char *);
|
||||||
static void set_ub_number_opt(struct getdns_context *, char *, uint16_t);
|
static void set_ub_number_opt(struct getdns_context *, char *, uint16_t);
|
||||||
static inline void clear_resolution_type_set_flag(struct getdns_context *, uint16_t);
|
static inline void clear_resolution_type_set_flag(struct getdns_context *, uint16_t);
|
||||||
|
@ -65,14 +70,6 @@ static void cancel_dns_req(getdns_dns_req *);
|
||||||
#define UNUSED_PARAM(x) ((void)(x))
|
#define UNUSED_PARAM(x) ((void)(x))
|
||||||
#define RETURN_IF_NULL(ptr, code) if(ptr == NULL) return code;
|
#define RETURN_IF_NULL(ptr, code) if(ptr == NULL) return code;
|
||||||
|
|
||||||
/* structs */
|
|
||||||
typedef struct getdns_timeout_data {
|
|
||||||
getdns_transaction_t transaction_id;
|
|
||||||
struct timeval timeout_time;
|
|
||||||
getdns_context_timeout_callback callback;
|
|
||||||
void* userarg;
|
|
||||||
} getdns_timeout_data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to get default lookup namespaces.
|
* Helper to get default lookup namespaces.
|
||||||
* TODO: Determine from OS
|
* TODO: Determine from OS
|
||||||
|
@ -215,6 +212,9 @@ set_os_defaults(struct getdns_context *context)
|
||||||
return GETDNS_RETURN_GOOD;
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* compare of transaction ids in DESCENDING order
|
||||||
|
so that 0 comes last
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
transaction_id_cmp(const void *id1, const void *id2)
|
transaction_id_cmp(const void *id1, const void *id2)
|
||||||
{
|
{
|
||||||
|
@ -231,7 +231,7 @@ transaction_id_cmp(const void *id1, const void *id2)
|
||||||
*((const getdns_transaction_t *) id2);
|
*((const getdns_transaction_t *) id2);
|
||||||
if (t1 == t2) {
|
if (t1 == t2) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (t1 < t2) {
|
} else if (t1 > t2) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -247,8 +247,8 @@ static int timeout_cmp(const void *to1, const void *to2) {
|
||||||
} else if (to1 != NULL && to2 == NULL) {
|
} else if (to1 != NULL && to2 == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
const getdns_timeout_data* t1 = (const getdns_timeout_data*) to1;
|
const getdns_timeout_data_t* t1 = (const getdns_timeout_data_t*) to1;
|
||||||
const getdns_timeout_data* t2 = (const getdns_timeout_data*) to2;
|
const getdns_timeout_data_t* t2 = (const getdns_timeout_data_t*) to2;
|
||||||
if (t1->timeout_time.tv_sec < t2->timeout_time.tv_sec) {
|
if (t1->timeout_time.tv_sec < t2->timeout_time.tv_sec) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (t1->timeout_time.tv_sec > t2->timeout_time.tv_sec) {
|
} else if (t1->timeout_time.tv_sec > t2->timeout_time.tv_sec) {
|
||||||
|
@ -260,42 +260,12 @@ static int timeout_cmp(const void *to1, const void *to2) {
|
||||||
} else if (t1->timeout_time.tv_usec > t2->timeout_time.tv_usec) {
|
} else if (t1->timeout_time.tv_usec > t2->timeout_time.tv_usec) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
// compare the transactions
|
return transaction_id_cmp(&t1->transaction_id, &t2->transaction_id);
|
||||||
const getdns_timeout_data* t1 = (const getdns_timeout_data*) to1;
|
|
||||||
const getdns_timeout_data* t2 = (const getdns_timeout_data*) to2;
|
|
||||||
if (t1->transaction_id == t2->transaction_id) {
|
|
||||||
return 0;
|
|
||||||
} else if (t1->transaction_id < t2->transaction_id) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_id_timeout_cmp(const void *to1, const void *to2) {
|
|
||||||
if (to1 == NULL && to2 == NULL) {
|
|
||||||
return 0;
|
|
||||||
} else if (to1 == NULL && to2 != NULL) {
|
|
||||||
return 1;
|
|
||||||
} else if (to1 != NULL && to2 == NULL) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
const getdns_timeout_data* t1 = (const getdns_timeout_data*) to1;
|
|
||||||
const getdns_timeout_data* t2 = (const getdns_timeout_data*) to2;
|
|
||||||
if (t1->transaction_id == t2->transaction_id) {
|
|
||||||
return 0;
|
|
||||||
} else if (t1->transaction_id < t2->transaction_id) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getdns_context_create
|
* getdns_context_create
|
||||||
*
|
*
|
||||||
|
@ -361,6 +331,8 @@ getdns_context_create_with_extended_memory_functions(
|
||||||
|
|
||||||
result->extension = NULL;
|
result->extension = NULL;
|
||||||
result->extension_data = NULL;
|
result->extension_data = NULL;
|
||||||
|
result->timeouts_by_time = ldns_rbtree_create(timeout_cmp);
|
||||||
|
result->timeouts_by_id = ldns_rbtree_create(transaction_id_cmp);
|
||||||
|
|
||||||
if (set_from_os) {
|
if (set_from_os) {
|
||||||
if (GETDNS_RETURN_GOOD != set_os_defaults(result)) {
|
if (GETDNS_RETURN_GOOD != set_os_defaults(result)) {
|
||||||
|
@ -1153,6 +1125,52 @@ getdns_context_clear_outbound_request(getdns_dns_req * req)
|
||||||
return GETDNS_RETURN_GOOD;
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
getdns_strdup(const struct mem_funcs *mfs, const char *s)
|
||||||
|
{
|
||||||
|
size_t sz = strlen(s) + 1;
|
||||||
|
char *r = GETDNS_XMALLOC(*mfs, char, sz);
|
||||||
|
if (r)
|
||||||
|
return memcpy(r, s, sz);
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct getdns_bindata *
|
||||||
|
getdns_bindata_copy(struct mem_funcs *mfs,
|
||||||
|
const struct getdns_bindata *src)
|
||||||
|
{
|
||||||
|
struct getdns_bindata *dst;
|
||||||
|
|
||||||
|
if (!src)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dst = GETDNS_MALLOC(*mfs, struct getdns_bindata);
|
||||||
|
if (!dst)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dst->size = src->size;
|
||||||
|
dst->data = GETDNS_XMALLOC(*mfs, uint8_t, src->size);
|
||||||
|
if (!dst->data) {
|
||||||
|
GETDNS_FREE(*mfs, dst);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
(void) memcpy(dst->data, src->data, src->size);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
getdns_bindata_destroy(struct mem_funcs *mfs,
|
||||||
|
struct getdns_bindata *bindata)
|
||||||
|
{
|
||||||
|
if (!bindata)
|
||||||
|
return;
|
||||||
|
GETDNS_FREE(*mfs, bindata->data);
|
||||||
|
GETDNS_FREE(*mfs, bindata);
|
||||||
|
}
|
||||||
|
|
||||||
/* get the fd */
|
/* get the fd */
|
||||||
int getdns_context_fd(struct getdns_context* context) {
|
int getdns_context_fd(struct getdns_context* context) {
|
||||||
RETURN_IF_NULL(context, -1);
|
RETURN_IF_NULL(context, -1);
|
||||||
|
@ -1162,58 +1180,48 @@ int getdns_context_fd(struct getdns_context* context) {
|
||||||
/* process async reqs */
|
/* process async reqs */
|
||||||
getdns_return_t getdns_context_process_async(struct getdns_context* context) {
|
getdns_return_t getdns_context_process_async(struct getdns_context* context) {
|
||||||
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
||||||
if (ub_process(context->unbound_ctx) != 0) {
|
if (ub_poll(context->unbound_ctx)) {
|
||||||
/* need an async return code? */
|
if (ub_process(context->unbound_ctx) != 0) {
|
||||||
|
/* need an async return code? */
|
||||||
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (context->extension != NULL) {
|
||||||
|
/* no need to process timeouts since it is delegated
|
||||||
|
* to the extension */
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
|
}
|
||||||
|
getdns_timeout_data_t key;
|
||||||
|
/* set to 0 so it is the last timeout if we have
|
||||||
|
* two with the same time */
|
||||||
|
key.transaction_id = 0;
|
||||||
|
if (gettimeofday(&key.timeout_time, NULL) != 0) {
|
||||||
return GETDNS_RETURN_GENERIC_ERROR;
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
}
|
}
|
||||||
|
ldns_rbnode_t* next_timeout = ldns_rbtree_first(context->timeouts_by_time);
|
||||||
|
while (next_timeout) {
|
||||||
|
getdns_timeout_data_t* timeout_data = (getdns_timeout_data_t*) next_timeout->data;
|
||||||
|
if (timeout_cmp(timeout_data, &key) > 0) {
|
||||||
|
/* no more timeouts need to be fired. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* get the next_timeout */
|
||||||
|
next_timeout = ldns_rbtree_next(next_timeout);
|
||||||
|
/* delete the node */
|
||||||
|
/* timeout data is freed in the clear_timeout */
|
||||||
|
ldns_rbnode_t* to_del = ldns_rbtree_delete(context->timeouts_by_time, timeout_data);
|
||||||
|
if (to_del) {
|
||||||
|
/* should always exist .. */
|
||||||
|
GETDNS_FREE(context->my_mf, to_del);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fire the timeout */
|
||||||
|
timeout_data->callback(timeout_data->userarg);
|
||||||
|
}
|
||||||
|
|
||||||
return GETDNS_RETURN_GOOD;
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
|
||||||
getdns_strdup(const struct mem_funcs *mfs, const char *s)
|
|
||||||
{
|
|
||||||
size_t sz = strlen(s) + 1;
|
|
||||||
char *r = GETDNS_XMALLOC(*mfs, char, sz);
|
|
||||||
if (r)
|
|
||||||
return memcpy(r, s, sz);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct getdns_bindata *
|
|
||||||
getdns_bindata_copy(struct mem_funcs *mfs,
|
|
||||||
const struct getdns_bindata *src)
|
|
||||||
{
|
|
||||||
struct getdns_bindata *dst;
|
|
||||||
|
|
||||||
if (!src)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dst = GETDNS_MALLOC(*mfs, struct getdns_bindata);
|
|
||||||
if (!dst)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dst->size = src->size;
|
|
||||||
dst->data = GETDNS_XMALLOC(*mfs, uint8_t, src->size);
|
|
||||||
if (!dst->data) {
|
|
||||||
GETDNS_FREE(*mfs, dst);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
(void) memcpy(dst->data, src->data, src->size);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
getdns_bindata_destroy(struct mem_funcs *mfs,
|
|
||||||
struct getdns_bindata *bindata)
|
|
||||||
{
|
|
||||||
if (!bindata)
|
|
||||||
return;
|
|
||||||
GETDNS_FREE(*mfs, bindata->data);
|
|
||||||
GETDNS_FREE(*mfs, bindata);
|
|
||||||
}
|
|
||||||
|
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_extension_detach_eventloop(struct getdns_context* context)
|
getdns_extension_detach_eventloop(struct getdns_context* context)
|
||||||
{
|
{
|
||||||
|
@ -1248,15 +1256,85 @@ getdns_extension_set_eventloop(struct getdns_context* context,
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_context_schedule_timeout(struct getdns_context* context,
|
getdns_context_schedule_timeout(struct getdns_context* context,
|
||||||
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
||||||
getdns_free_timeout_userarg_t free_func, void* userarg) {
|
void* userarg) {
|
||||||
|
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
||||||
|
RETURN_IF_NULL(callback, GETDNS_RETURN_INVALID_PARAMETER);
|
||||||
|
getdns_return_t result;
|
||||||
|
/* create a timeout */
|
||||||
|
getdns_timeout_data_t* timeout_data = GETDNS_MALLOC(context->my_mf, getdns_timeout_data_t);
|
||||||
|
if (!timeout_data) {
|
||||||
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
timeout_data->context = context;
|
||||||
|
timeout_data->transaction_id = id;
|
||||||
|
timeout_data->callback = callback;
|
||||||
|
timeout_data->userarg = userarg;
|
||||||
|
timeout_data->extension_timer = NULL;
|
||||||
|
|
||||||
|
/* insert into transaction tree */
|
||||||
|
ldns_rbnode_t *node = GETDNS_MALLOC(context->my_mf, ldns_rbnode_t);
|
||||||
|
if (!node) {
|
||||||
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
node->key = &(timeout_data->transaction_id);
|
||||||
|
node->data = timeout_data;
|
||||||
|
if (!ldns_rbtree_insert(context->timeouts_by_id, node)) {
|
||||||
|
/* free the node */
|
||||||
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
|
GETDNS_FREE(context->my_mf, node);
|
||||||
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->extension) {
|
||||||
|
result = context->extension->schedule_timeout(context, context->extension_data,
|
||||||
|
timeout, timeout_data, &(timeout_data->extension_timer));
|
||||||
|
} else {
|
||||||
|
result = GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
if (gettimeofday(&timeout_data->timeout_time, NULL) == 0) {
|
||||||
|
ldns_rbnode_t* id_node = GETDNS_MALLOC(context->my_mf, ldns_rbnode_t);
|
||||||
|
if (id_node) {
|
||||||
|
id_node->key = timeout_data;
|
||||||
|
id_node->data = timeout_data;
|
||||||
|
if (!ldns_rbtree_insert(context->timeouts_by_time, node)) {
|
||||||
|
GETDNS_FREE(context->my_mf, id_node);
|
||||||
|
} else {
|
||||||
|
result = GETDNS_RETURN_GOOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result != GETDNS_RETURN_GOOD) {
|
||||||
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
|
GETDNS_FREE(context->my_mf, node);
|
||||||
|
}
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_context_clear_timeout(struct getdns_context* context,
|
getdns_context_clear_timeout(struct getdns_context* context,
|
||||||
getdns_transaction_t id) {
|
getdns_transaction_t id) {
|
||||||
|
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
||||||
|
/* find the timeout_data by id */
|
||||||
|
ldns_rbnode_t* node = ldns_rbtree_delete(context->timeouts_by_id, &id);
|
||||||
|
if (!node) {
|
||||||
|
return GETDNS_RETURN_UNKNOWN_TRANSACTION;
|
||||||
|
}
|
||||||
|
getdns_timeout_data_t* timeout_data = (getdns_timeout_data_t*) node->data;
|
||||||
|
GETDNS_FREE(context->my_mf, node);
|
||||||
|
if (context->extension) {
|
||||||
|
context->extension->clear_timeout(context, context->extension,
|
||||||
|
timeout_data->extension_timer);
|
||||||
|
} else {
|
||||||
|
/* make sure it is removed from the timeout node */
|
||||||
|
ldns_rbnode_t* to_del = ldns_rbtree_delete(context->timeouts_by_time, timeout_data);
|
||||||
|
if (to_del) {
|
||||||
|
GETDNS_FREE(context->my_mf, to_del);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* getdns_context.c */
|
/* context.c */
|
||||||
|
|
|
@ -1,32 +1,39 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns contect management functions
|
* /file
|
||||||
|
* /brief getdns context management functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _GETDNS_CONTEXT_H_
|
#ifndef _GETDNS_CONTEXT_H_
|
||||||
#define _GETDNS_CONTEXT_H_
|
#define _GETDNS_CONTEXT_H_
|
||||||
|
|
||||||
|
@ -39,8 +46,6 @@ struct ub_ctx;
|
||||||
|
|
||||||
/** function pointer typedefs */
|
/** function pointer typedefs */
|
||||||
typedef void (*getdns_update_callback) (struct getdns_context *, uint16_t);
|
typedef void (*getdns_update_callback) (struct getdns_context *, uint16_t);
|
||||||
typedef void (*getdns_timeout_callback) (struct getdns_context* context, getdns_transaction_t transaction_id, void* userarg);
|
|
||||||
typedef void (*getdns_free_timeout_userarg_t) (struct getdns_context* context, void* user_arg);
|
|
||||||
|
|
||||||
struct getdns_context {
|
struct getdns_context {
|
||||||
|
|
||||||
|
@ -93,7 +98,7 @@ struct getdns_context {
|
||||||
/*
|
/*
|
||||||
* Timeout info one tree to manage timeout data
|
* Timeout info one tree to manage timeout data
|
||||||
* keyed by transaction id. Second to manage by
|
* keyed by transaction id. Second to manage by
|
||||||
* timeout
|
* timeout time (ascending)
|
||||||
*/
|
*/
|
||||||
struct ldns_rbtree_t *timeouts_by_id;
|
struct ldns_rbtree_t *timeouts_by_id;
|
||||||
struct ldns_rbtree_t *timeouts_by_time;
|
struct ldns_rbtree_t *timeouts_by_time;
|
||||||
|
@ -133,7 +138,7 @@ getdns_return_t getdns_extension_set_eventloop(struct getdns_context* context,
|
||||||
/* timeout scheduling */
|
/* timeout scheduling */
|
||||||
getdns_return_t getdns_context_schedule_timeout(struct getdns_context* context,
|
getdns_return_t getdns_context_schedule_timeout(struct getdns_context* context,
|
||||||
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
||||||
getdns_free_timeout_userarg_t free_func, void* userarg);
|
void* userarg);
|
||||||
|
|
||||||
getdns_return_t getdns_context_clear_timeout(struct getdns_context* context,
|
getdns_return_t getdns_context_clear_timeout(struct getdns_context* context,
|
||||||
getdns_transaction_t id);
|
getdns_transaction_t id);
|
||||||
|
|
|
@ -1,31 +1,35 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns core functions
|
* \file convert.c
|
||||||
*
|
* @brief getdns label conversion functions
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
|
@ -181,4 +185,4 @@ getdns_strerror(getdns_return_t err, char *buf, size_t buflen)
|
||||||
return retval;
|
return retval;
|
||||||
} /* getdns_strerror */
|
} /* getdns_strerror */
|
||||||
|
|
||||||
/* getdns_core_only.c */
|
/* convert.c */
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#include <getdns/getdns_ext_libevent.h>
|
#include <getdns/getdns_ext_libevent.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#ifdef HAVE_EVENT2_EVENT_H
|
#ifdef HAVE_EVENT2_EVENT_H
|
||||||
# include <event2/event.h>
|
# include <event2/event.h>
|
||||||
#else
|
#else
|
||||||
|
@ -64,7 +66,22 @@ struct event_data {
|
||||||
struct event_base* event_base;
|
struct event_base* event_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
static getdns_return_t getdns_libevent_cleanup(struct getdns_context* context, void* data) {
|
/* lib event callbacks */
|
||||||
|
static void
|
||||||
|
getdns_libevent_cb(evutil_socket_t fd, short what, void *userarg) {
|
||||||
|
struct getdns_context* context = (struct getdns_context*) userarg;
|
||||||
|
getdns_context_process_async(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
getdns_libevent_timeout_cb(evutil_socket_t fd, short what, void* userarg) {
|
||||||
|
getdns_timeout_data_t* timeout_data = (getdns_timeout_data_t*) userarg;
|
||||||
|
timeout_data->callback(timeout_data->userarg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* getdns extension functions */
|
||||||
|
static getdns_return_t
|
||||||
|
getdns_libevent_cleanup(struct getdns_context* context, void* data) {
|
||||||
struct event_data *edata = (struct event_data*) data;
|
struct event_data *edata = (struct event_data*) data;
|
||||||
event_del(edata->event);
|
event_del(edata->event);
|
||||||
event_free(edata->event);
|
event_free(edata->event);
|
||||||
|
@ -72,16 +89,42 @@ static getdns_return_t getdns_libevent_cleanup(struct getdns_context* context, v
|
||||||
return GETDNS_RETURN_GOOD;
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getdns_eventloop_extension LIBEVENT_EXT = {
|
static getdns_return_t
|
||||||
getdns_libevent_cleanup
|
getdns_libevent_schedule_timeout(struct getdns_context* context,
|
||||||
};
|
void* eventloop_data, uint16_t timeout,
|
||||||
|
getdns_timeout_data_t* timeout_data,
|
||||||
|
void** eventloop_timer) {
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
struct event* ev = NULL;
|
||||||
|
struct event_data* ev_data = (struct event_data*) eventloop_data;
|
||||||
|
|
||||||
void getdns_libevent_cb(evutil_socket_t fd, short what, void *userarg) {
|
tv.tv_sec = timeout / 1000;
|
||||||
struct getdns_context* context = (struct getdns_context*) userarg;
|
tv.tv_usec = (timeout % 1000) * 1000;
|
||||||
getdns_context_process_async(context);
|
|
||||||
|
ev = evtimer_new(ev_data->event_base, getdns_libevent_timeout_cb, timeout_data);
|
||||||
|
evtimer_add(ev, &tv);
|
||||||
|
|
||||||
|
*eventloop_timer = ev;
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getdns_return_t
|
||||||
|
getdns_libevent_clear_timeout(struct getdns_context* context,
|
||||||
|
void* eventloop_data, void** eventloop_timer) {
|
||||||
|
struct event* ev = (struct event*) eventloop_timer;
|
||||||
|
event_del(ev);
|
||||||
|
event_free(ev);
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static getdns_eventloop_extension LIBEVENT_EXT = {
|
||||||
|
getdns_libevent_cleanup,
|
||||||
|
getdns_libevent_schedule_timeout,
|
||||||
|
getdns_libevent_clear_timeout
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getdns_extension_set_libevent_base
|
* getdns_extension_set_libevent_base
|
||||||
*
|
*
|
||||||
|
|
297
src/general.c
297
src/general.c
|
@ -65,24 +65,24 @@ typedef struct netreq_cb_data
|
||||||
char *bogus;
|
char *bogus;
|
||||||
} netreq_cb_data;
|
} netreq_cb_data;
|
||||||
|
|
||||||
// /* cancel, cleanup and send timeout to callback */
|
/* cancel, cleanup and send timeout to callback */
|
||||||
// static void
|
static void
|
||||||
// ub_resolve_timeout(evutil_socket_t fd, short what, void *arg)
|
ub_resolve_timeout(void *arg)
|
||||||
// {
|
{
|
||||||
// getdns_dns_req *dns_req = (getdns_dns_req *) arg;
|
getdns_dns_req *dns_req = (getdns_dns_req *) arg;
|
||||||
// struct getdns_context *context = dns_req->context;
|
struct getdns_context *context = dns_req->context;
|
||||||
// getdns_transaction_t trans_id = dns_req->trans_id;
|
getdns_transaction_t trans_id = dns_req->trans_id;
|
||||||
// getdns_callback_t cb = dns_req->user_callback;
|
getdns_callback_t cb = dns_req->user_callback;
|
||||||
// void *user_arg = dns_req->user_pointer;
|
void *user_arg = dns_req->user_pointer;
|
||||||
|
|
||||||
// /* cancel the req - also clears it from outbound */
|
/* cancel the req - also clears it from outbound */
|
||||||
// getdns_context_cancel_request(context, trans_id, 0);
|
getdns_context_cancel_request(context, trans_id, 0);
|
||||||
|
|
||||||
// /* cleanup */
|
/* cleanup */
|
||||||
// dns_req_free(dns_req);
|
dns_req_free(dns_req);
|
||||||
|
|
||||||
// cb(context, GETDNS_CALLBACK_TIMEOUT, NULL, user_arg, trans_id);
|
cb(context, GETDNS_CALLBACK_TIMEOUT, NULL, user_arg, trans_id);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// static void
|
// static void
|
||||||
// ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg)
|
// ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg)
|
||||||
|
@ -108,11 +108,9 @@ typedef struct netreq_cb_data
|
||||||
// free(cb_data);
|
// free(cb_data);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* cleanup and send an error to the user callback */
|
static void call_user_callback(getdns_dns_req *dns_req,
|
||||||
static void
|
struct getdns_dict *response)
|
||||||
handle_network_request_error(getdns_network_req * netreq, int err)
|
|
||||||
{
|
{
|
||||||
getdns_dns_req *dns_req = netreq->owner;
|
|
||||||
struct getdns_context *context = dns_req->context;
|
struct getdns_context *context = dns_req->context;
|
||||||
getdns_transaction_t trans_id = dns_req->trans_id;
|
getdns_transaction_t trans_id = dns_req->trans_id;
|
||||||
getdns_callback_t cb = dns_req->user_callback;
|
getdns_callback_t cb = dns_req->user_callback;
|
||||||
|
@ -122,30 +120,249 @@ handle_network_request_error(getdns_network_req * netreq, int err)
|
||||||
getdns_context_clear_outbound_request(dns_req);
|
getdns_context_clear_outbound_request(dns_req);
|
||||||
dns_req_free(dns_req);
|
dns_req_free(dns_req);
|
||||||
|
|
||||||
cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
|
cb(context,
|
||||||
|
(response ? GETDNS_CALLBACK_COMPLETE : GETDNS_CALLBACK_ERROR),
|
||||||
|
response, user_arg, trans_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* cleanup and send an error to the user callback */
|
||||||
|
static void
|
||||||
|
handle_network_request_error(getdns_network_req * netreq, int err)
|
||||||
|
{
|
||||||
|
call_user_callback(netreq->owner, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct validation_chain {
|
||||||
|
ldns_rbtree_t root;
|
||||||
|
struct mem_funcs mf;
|
||||||
|
getdns_dns_req *dns_req;
|
||||||
|
size_t todo;
|
||||||
|
};
|
||||||
|
struct chain_response {
|
||||||
|
int err;
|
||||||
|
ldns_rr_list *result;
|
||||||
|
int sec;
|
||||||
|
char *bogus;
|
||||||
|
struct validation_chain *chain;
|
||||||
|
int unbound_id;
|
||||||
|
};
|
||||||
|
struct chain_link {
|
||||||
|
ldns_rbnode_t node;
|
||||||
|
struct chain_response DNSKEY;
|
||||||
|
struct chain_response DS;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void submit_link(struct validation_chain *chain, char *name);
|
||||||
|
static void callback_on_complete_chain(struct validation_chain *chain);
|
||||||
|
static void
|
||||||
|
//ub_supporting_callback(void *arg, int err, ldns_buffer *result, int sec,
|
||||||
|
// char *bogus)
|
||||||
|
ub_supporting_callback(void* arg, int err, struct ub_result* ub_res)
|
||||||
|
{
|
||||||
|
struct chain_response *response = (struct chain_response *) arg;
|
||||||
|
|
||||||
|
ldns_status r;
|
||||||
|
ldns_pkt *p;
|
||||||
|
ldns_rr_list *answer;
|
||||||
|
ldns_rr_list *keys;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
response->err = err;
|
||||||
|
response->sec = ub_res ? ub_res->secure : 0;
|
||||||
|
response->bogus = ub_res ? ub_res->why_bogus : NULL;
|
||||||
|
|
||||||
|
if (ub_res == NULL)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
r = ldns_wire2pkt(&p, ub_res->answer_packet, ub_res->answer_len);
|
||||||
|
if (r != LDNS_STATUS_OK) {
|
||||||
|
if (err == 0)
|
||||||
|
response->err = r;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys = ldns_rr_list_new();
|
||||||
|
answer = ldns_pkt_answer(p);
|
||||||
|
for (i = 0; i < ldns_rr_list_rr_count(answer); i++) {
|
||||||
|
ldns_rr *rr = ldns_rr_list_rr(answer, i);
|
||||||
|
|
||||||
|
if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_DNSKEY ||
|
||||||
|
ldns_rr_get_type(rr) == LDNS_RR_TYPE_DS) {
|
||||||
|
|
||||||
|
(void) ldns_rr_list_push_rr(keys, ldns_rr_clone(rr));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ldns_read_uint16(ldns_rdf_data(ldns_rr_rdf(rr, 0))) ==
|
||||||
|
LDNS_RR_TYPE_DS)
|
||||||
|
submit_link(response->chain,
|
||||||
|
ldns_rdf2str(ldns_rr_rdf(rr, 7)));
|
||||||
|
|
||||||
|
else if (ldns_read_uint16(ldns_rdf_data(ldns_rr_rdf(rr, 0))) !=
|
||||||
|
LDNS_RR_TYPE_DNSKEY)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
(void) ldns_rr_list_push_rr(keys, ldns_rr_clone(rr));
|
||||||
|
}
|
||||||
|
if (ldns_rr_list_rr_count(keys))
|
||||||
|
response->result = keys;
|
||||||
|
else
|
||||||
|
ldns_rr_list_free(keys);
|
||||||
|
|
||||||
|
ldns_pkt_free(p);
|
||||||
|
|
||||||
|
done: if (response->err == 0 && response->result == NULL)
|
||||||
|
response->err = -1;
|
||||||
|
|
||||||
|
callback_on_complete_chain(response->chain);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void submit_link(struct validation_chain *chain, char *name)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
struct chain_link *link = (struct chain_link *)
|
||||||
|
ldns_rbtree_search((ldns_rbtree_t *)&(chain->root), name);
|
||||||
|
|
||||||
|
if (link) {
|
||||||
|
free(name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
link = GETDNS_MALLOC(chain->mf, struct chain_link);
|
||||||
|
link->node.key = name;
|
||||||
|
|
||||||
|
link->DNSKEY.err = 0;
|
||||||
|
link->DNSKEY.result = NULL;
|
||||||
|
link->DNSKEY.sec = 0;
|
||||||
|
link->DNSKEY.bogus = NULL;
|
||||||
|
link->DNSKEY.chain = chain;
|
||||||
|
link->DNSKEY.unbound_id = -1;
|
||||||
|
|
||||||
|
link->DS.err = 0;
|
||||||
|
link->DS.result = NULL;
|
||||||
|
link->DS.sec = 0;
|
||||||
|
link->DS.bogus = NULL;
|
||||||
|
link->DS.chain = chain;
|
||||||
|
link->DS.unbound_id = -1;
|
||||||
|
|
||||||
|
ldns_rbtree_insert(&(chain->root), (ldns_rbnode_t *)link);
|
||||||
|
/* fprintf(stderr, "submitting for: %s\n", name); */
|
||||||
|
|
||||||
|
r = ub_resolve_async(chain->dns_req->context->unbound_ctx,
|
||||||
|
name, LDNS_RR_TYPE_DNSKEY, LDNS_RR_CLASS_IN, &link->DNSKEY,
|
||||||
|
ub_supporting_callback, &link->DNSKEY.unbound_id);
|
||||||
|
if (r != 0)
|
||||||
|
link->DNSKEY.err = r;
|
||||||
|
|
||||||
|
r = ub_resolve_async(chain->dns_req->context->unbound_ctx,
|
||||||
|
name, LDNS_RR_TYPE_DS, LDNS_RR_CLASS_IN, &link->DS,
|
||||||
|
ub_supporting_callback, &link->DS.unbound_id);
|
||||||
|
if (r != 0)
|
||||||
|
link->DS.err = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_chain_link(ldns_rbnode_t * node, void *arg)
|
||||||
|
{
|
||||||
|
struct chain_link *link = (struct chain_link*) node;
|
||||||
|
struct validation_chain *chain = (struct validation_chain*) arg;
|
||||||
|
|
||||||
|
free((void *)link->node.key);
|
||||||
|
ldns_rr_list_deep_free(link->DNSKEY.result);
|
||||||
|
ldns_rr_list_deep_free(link->DS.result);
|
||||||
|
GETDNS_FREE(chain->mf, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy_chain(struct getdns_context *context,
|
||||||
|
struct validation_chain *chain)
|
||||||
|
{
|
||||||
|
ldns_traverse_postorder(&(chain->root),
|
||||||
|
destroy_chain_link, chain);
|
||||||
|
GETDNS_FREE(chain->mf, chain);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void callback_on_complete_chain(struct validation_chain *chain)
|
||||||
|
{
|
||||||
|
struct getdns_context *context = chain->dns_req->context;
|
||||||
|
struct getdns_dict *response;
|
||||||
|
struct chain_link *link;
|
||||||
|
size_t todo = chain->todo;
|
||||||
|
ldns_rr_list *keys;
|
||||||
|
struct getdns_list *getdns_keys;
|
||||||
|
|
||||||
|
LDNS_RBTREE_FOR(link, struct chain_link *,
|
||||||
|
(ldns_rbtree_t *)&(chain->root)) {
|
||||||
|
if (link->DNSKEY.result == NULL && link->DNSKEY.err == 0)
|
||||||
|
todo++;
|
||||||
|
if (link->DS.result == NULL && link->DS.err == 0 &&
|
||||||
|
(((const char *)link->node.key)[0] != '.' ||
|
||||||
|
((const char *)link->node.key)[1] != '\0' ))
|
||||||
|
todo++;
|
||||||
|
}
|
||||||
|
/* fprintf(stderr, "todo until validation: %d\n", (int)todo); */
|
||||||
|
if (todo == 0) {
|
||||||
|
response = create_getdns_response(chain->dns_req);
|
||||||
|
|
||||||
|
keys = ldns_rr_list_new();
|
||||||
|
LDNS_RBTREE_FOR(link, struct chain_link *,
|
||||||
|
(ldns_rbtree_t *)&(chain->root)) {
|
||||||
|
(void) ldns_rr_list_cat(keys, link->DNSKEY.result);
|
||||||
|
(void) ldns_rr_list_cat(keys, link->DS.result);
|
||||||
|
}
|
||||||
|
getdns_keys = create_list_from_rr_list(context, keys);
|
||||||
|
(void) getdns_dict_set_list(response, "validation_chain",
|
||||||
|
getdns_keys);
|
||||||
|
getdns_list_destroy(getdns_keys);
|
||||||
|
ldns_rr_list_free(keys);
|
||||||
|
destroy_chain(context, chain);
|
||||||
|
call_user_callback(chain->dns_req, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do some additional requests to fetch the complete validation chain */
|
||||||
|
static void get_validation_chain(getdns_dns_req *dns_req)
|
||||||
|
{
|
||||||
|
getdns_network_req *netreq = dns_req->first_req;
|
||||||
|
struct validation_chain *chain = GETDNS_MALLOC(dns_req->context->mf,
|
||||||
|
struct validation_chain);
|
||||||
|
|
||||||
|
ldns_rbtree_init(&(chain->root),
|
||||||
|
(int (*)(const void *, const void *)) strcmp);
|
||||||
|
chain->mf.mf_arg = dns_req->context->mf.mf_arg;
|
||||||
|
chain->mf.mf.ext.malloc = dns_req->context->mf.mf.ext.malloc;
|
||||||
|
chain->mf.mf.ext.realloc = dns_req->context->mf.mf.ext.realloc;
|
||||||
|
chain->mf.mf.ext.free = dns_req->context->mf.mf.ext.free;
|
||||||
|
chain->dns_req = dns_req;
|
||||||
|
chain->todo = 1;
|
||||||
|
|
||||||
|
while (netreq) {
|
||||||
|
size_t i;
|
||||||
|
ldns_rr_list *answer = ldns_pkt_answer(netreq->result);
|
||||||
|
for (i = 0; i < ldns_rr_list_rr_count(answer); i++) {
|
||||||
|
ldns_rr *rr = ldns_rr_list_rr(answer, i);
|
||||||
|
if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_RRSIG)
|
||||||
|
submit_link(chain,
|
||||||
|
ldns_rdf2str(ldns_rr_rdf(rr, 7)));
|
||||||
|
}
|
||||||
|
netreq = netreq->next;
|
||||||
|
}
|
||||||
|
chain->todo--;
|
||||||
|
callback_on_complete_chain(chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup and send the response to the user callback */
|
/* cleanup and send the response to the user callback */
|
||||||
static void
|
static void
|
||||||
handle_dns_request_complete(getdns_dns_req * dns_req)
|
handle_dns_request_complete(getdns_dns_req * dns_req)
|
||||||
{
|
{
|
||||||
struct getdns_dict *response = create_getdns_response(dns_req);
|
uint32_t ret_chain_ext = GETDNS_EXTENSION_FALSE;
|
||||||
|
getdns_return_t r = getdns_dict_get_int(dns_req->extensions,
|
||||||
|
"dnssec_return_validation_chain", &ret_chain_ext);
|
||||||
|
|
||||||
struct getdns_context *context = dns_req->context;
|
if (r == GETDNS_RETURN_GOOD && ret_chain_ext == GETDNS_EXTENSION_TRUE)
|
||||||
getdns_transaction_t trans_id = dns_req->trans_id;
|
|
||||||
getdns_callback_t cb = dns_req->user_callback;
|
|
||||||
void *user_arg = dns_req->user_pointer;
|
|
||||||
|
|
||||||
/* clean up the request */
|
|
||||||
getdns_context_clear_outbound_request(dns_req);
|
|
||||||
dns_req_free(dns_req);
|
|
||||||
if (response) {
|
|
||||||
cb(context,
|
|
||||||
GETDNS_CALLBACK_COMPLETE, response, user_arg, trans_id);
|
|
||||||
} else {
|
|
||||||
cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
get_validation_chain(dns_req);
|
||||||
|
else
|
||||||
|
call_user_callback(dns_req, create_getdns_response(dns_req));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -243,7 +460,6 @@ getdns_general_ub(struct getdns_context *context,
|
||||||
getdns_transaction_t * transaction_id,
|
getdns_transaction_t * transaction_id,
|
||||||
getdns_callback_t callbackfn)
|
getdns_callback_t callbackfn)
|
||||||
{
|
{
|
||||||
/* timeout */
|
|
||||||
getdns_return_t gr;
|
getdns_return_t gr;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -274,13 +490,12 @@ getdns_general_ub(struct getdns_context *context,
|
||||||
|
|
||||||
getdns_context_track_outbound_request(req);
|
getdns_context_track_outbound_request(req);
|
||||||
|
|
||||||
/* TODO: timeout.. */
|
/* assign a timeout */
|
||||||
// /* assign a timeout */
|
|
||||||
// req->ev_base = ev_base;
|
// req->ev_base = ev_base;
|
||||||
// req->timeout = evtimer_new(ev_base, ub_resolve_timeout, req);
|
// req->timeout = evtimer_new(ev_base, ub_resolve_timeout, req);
|
||||||
// tv.tv_sec = context->timeout / 1000;
|
/* schedule the timeout */
|
||||||
// tv.tv_usec = (context->timeout % 1000) * 1000;
|
getdns_context_schedule_timeout(context, req->trans_id,
|
||||||
// evtimer_add(req->timeout, &tv);
|
context->timeout, ub_resolve_timeout, req);
|
||||||
|
|
||||||
/* issue the first network req */
|
/* issue the first network req */
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief defines and data structure for getdns_error_str_by_id()
|
* @brief defines and data structure for getdns_error_str_by_id()
|
||||||
*
|
*
|
||||||
* This source was taken from the original pseudo-implementation by
|
* This source was taken from the original pseudo-implementation by
|
||||||
* Paul Hoffman.
|
* Paul Hoffman.
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GETDNS_ERROR_H
|
#ifndef GETDNS_ERROR_H
|
||||||
#define GETDNS_ERROR_H
|
#define GETDNS_ERROR_H
|
||||||
|
|
|
@ -4,26 +4,31 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The MIT License (MIT)
|
/*
|
||||||
* Copyright (c) 2013 Verisign, Include.
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
|
@ -91,3 +96,5 @@ getdns_get_errorstr_by_id(uint16_t err)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* getdns_error.c */
|
||||||
|
|
|
@ -1,33 +1,40 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns core functions
|
* \file hostname.c
|
||||||
|
* @brief getdns core functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "general.h"
|
#include "general.h"
|
||||||
|
@ -82,4 +89,4 @@ getdns_hostname(struct getdns_context *context,
|
||||||
return retval;
|
return retval;
|
||||||
} /* getdns_hostname */
|
} /* getdns_hostname */
|
||||||
|
|
||||||
/* getdns_hostname.c */
|
/* hostname.c */
|
||||||
|
|
49
src/list.h
49
src/list.h
|
@ -1,32 +1,39 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns contect management functions
|
* \file list.h
|
||||||
|
* @brief getdns list management functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _GETDNS_LIST_H_
|
#ifndef _GETDNS_LIST_H_
|
||||||
#define _GETDNS_LIST_H_
|
#define _GETDNS_LIST_H_
|
||||||
|
|
||||||
|
@ -68,3 +75,5 @@ struct getdns_list
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* list.h */
|
||||||
|
|
|
@ -96,6 +96,8 @@ dns_req_free(getdns_dns_req * req)
|
||||||
net_req = next;
|
net_req = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getdns_context_clear_timeout(context, req->trans_id);
|
||||||
|
|
||||||
/* free strduped name */
|
/* free strduped name */
|
||||||
free(req->name);
|
free(req->name);
|
||||||
|
|
||||||
|
@ -124,9 +126,6 @@ dns_req_new(struct getdns_context *context,
|
||||||
result->current_req = NULL;
|
result->current_req = NULL;
|
||||||
result->first_req = NULL;
|
result->first_req = NULL;
|
||||||
result->trans_id = ldns_get_random();
|
result->trans_id = ldns_get_random();
|
||||||
// result->timeout = NULL;
|
|
||||||
// result->local_cb_timer = NULL;
|
|
||||||
// result->ev_base = NULL;
|
|
||||||
|
|
||||||
getdns_dict_copy(extensions, &result->extensions);
|
getdns_dict_copy(extensions, &result->extensions);
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,41 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns core functions
|
* \file service.c
|
||||||
|
* @brief getdns core functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
|
|
||||||
/* stuff to make it compile pedantically */
|
|
||||||
#define UNUSED_PARAM(x) ((void)(x))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getdns_service
|
* getdns_service
|
||||||
*
|
*
|
||||||
|
@ -48,4 +51,4 @@ getdns_service(struct getdns_context *context,
|
||||||
extensions, userarg, transaction_id, callback);
|
extensions, userarg, transaction_id, callback);
|
||||||
} /* getdns_service */
|
} /* getdns_service */
|
||||||
|
|
||||||
/* getdns_core_only.c */
|
/* service.c */
|
||||||
|
|
|
@ -19,7 +19,7 @@ CC=gcc
|
||||||
CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 $(cflags)
|
CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 $(cflags)
|
||||||
LDFLAGS=@LDFLAGS@ -L. -L.. -L$(srcdir)/../ -L/usr/local/lib
|
LDFLAGS=@LDFLAGS@ -L. -L.. -L$(srcdir)/../ -L/usr/local/lib
|
||||||
LDLIBS=-lgetdns @LIBS@ -lcheck
|
LDLIBS=-lgetdns @LIBS@ -lcheck
|
||||||
PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync check_getdns
|
PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync check_getdns tests_dnssec
|
||||||
|
|
||||||
.SUFFIXES: .c .o .a .lo .h
|
.SUFFIXES: .c .o .a .lo .h
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ check_getdns_common: check_getdns_common.o
|
||||||
check_getdns: check_getdns.o check_getdns_common.o
|
check_getdns: check_getdns.o check_getdns_common.o
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
|
||||||
|
|
||||||
|
tests_dnssec: tests_dnssec.o testmessages.o
|
||||||
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_dnssec.o testmessages.o
|
||||||
|
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
./testscript.sh
|
./testscript.sh
|
||||||
@echo "All tests OK"
|
@echo "All tests OK"
|
||||||
|
|
|
@ -1,27 +1,33 @@
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief display messages to support unit testing
|
* @brief display messages to support unit testing
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -2,26 +2,32 @@
|
||||||
* \file
|
* \file
|
||||||
* \brief display messages to support unit testing
|
* \brief display messages to support unit testing
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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 TESTMESSAGES_H
|
#ifndef TESTMESSAGES_H
|
||||||
|
|
|
@ -4,26 +4,32 @@
|
||||||
* perform regression tests, output must be unchanged from canonical output
|
* perform regression tests, output must be unchanged from canonical output
|
||||||
* stored with the sources
|
* stored with the sources
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, NLNet Labs, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -581,4 +587,4 @@ main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|
||||||
/* end tests_dict.c */
|
/* tests_dict.c */
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* unit tests for getdns_dict helper routines, these should be used to
|
||||||
|
* perform regression tests, output must be unchanged from canonical output
|
||||||
|
* stored with the sources
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, 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 name of the <organization> 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#ifdef HAVE_EVENT2_EVENT_H
|
||||||
|
# include <event2/event.h>
|
||||||
|
#else
|
||||||
|
# include <event.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "testmessages.h"
|
||||||
|
#include <getdns/getdns.h>
|
||||||
|
|
||||||
|
/* Set up the callback function, which will also do the processing of the results */
|
||||||
|
void
|
||||||
|
this_callbackfn(struct getdns_context *this_context,
|
||||||
|
uint16_t this_callback_type,
|
||||||
|
struct getdns_dict *this_response,
|
||||||
|
void *this_userarg, getdns_transaction_t this_transaction_id)
|
||||||
|
{
|
||||||
|
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
|
||||||
|
char *res = getdns_pretty_print_dict(this_response);
|
||||||
|
fprintf(stdout, "%s\n", res);
|
||||||
|
free(res);
|
||||||
|
|
||||||
|
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
|
||||||
|
fprintf(stderr,
|
||||||
|
"The callback with ID %llu was cancelled. Exiting.",
|
||||||
|
(unsigned long long)this_transaction_id);
|
||||||
|
else
|
||||||
|
fprintf(stderr,
|
||||||
|
"The callback got a callback_type of %d. Exiting.",
|
||||||
|
this_callback_type);
|
||||||
|
getdns_dict_destroy(this_response);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
/* Create the DNS context for this call */
|
||||||
|
struct getdns_context *this_context = NULL;
|
||||||
|
getdns_return_t context_create_return =
|
||||||
|
getdns_context_create(&this_context, 1);
|
||||||
|
if (context_create_return != GETDNS_RETURN_GOOD) {
|
||||||
|
fprintf(stderr, "Trying to create the context failed: %d",
|
||||||
|
context_create_return);
|
||||||
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
|
}
|
||||||
|
getdns_context_set_timeout(this_context, 5000);
|
||||||
|
|
||||||
|
struct getdns_dict * this_extensions = getdns_dict_create();
|
||||||
|
getdns_return_t this_ret = getdns_dict_set_int(this_extensions,
|
||||||
|
"dnssec_return_validation_chain", GETDNS_EXTENSION_TRUE);
|
||||||
|
if (this_ret != GETDNS_RETURN_GOOD) {
|
||||||
|
fprintf(stderr, "Setting extension "
|
||||||
|
"\"dnssec_return_validation_chain\" failed: %d\n", this_ret);
|
||||||
|
getdns_dict_destroy(this_extensions);
|
||||||
|
getdns_context_destroy(this_context);
|
||||||
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create an event base and put it in the context using the unknown function name */
|
||||||
|
struct event_base *this_event_base;
|
||||||
|
this_event_base = event_base_new();
|
||||||
|
if (this_event_base == NULL) {
|
||||||
|
fprintf(stderr, "Trying to create the event base failed.");
|
||||||
|
getdns_context_destroy(this_context);
|
||||||
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
|
}
|
||||||
|
(void) getdns_extension_set_libevent_base(this_context,
|
||||||
|
this_event_base);
|
||||||
|
/* Set up the getdns call */
|
||||||
|
const char *this_name = argc > 1 ? argv[1] : "www.example.com";
|
||||||
|
char *this_userarg = "somestring"; // Could add things here to help identify this call
|
||||||
|
getdns_transaction_t this_transaction_id = 0;
|
||||||
|
|
||||||
|
/* Make the call */
|
||||||
|
getdns_return_t dns_request_return =
|
||||||
|
getdns_address(this_context, this_name,
|
||||||
|
this_extensions, this_userarg, &this_transaction_id, this_callbackfn);
|
||||||
|
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
|
||||||
|
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
|
||||||
|
this_name);
|
||||||
|
event_base_free(this_event_base);
|
||||||
|
getdns_context_destroy(this_context);
|
||||||
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Call the event loop */
|
||||||
|
event_base_dispatch(this_event_base);
|
||||||
|
// TODO: check the return value above
|
||||||
|
}
|
||||||
|
/* Clean up */
|
||||||
|
event_base_free(this_event_base);
|
||||||
|
getdns_context_destroy(this_context);
|
||||||
|
/* Assuming we get here, leave gracefully */
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} /* main */
|
||||||
|
|
||||||
|
/* example-simple-answers.c */
|
|
@ -4,26 +4,32 @@
|
||||||
* perform regression tests, output must be unchanged from canonical output
|
* perform regression tests, output must be unchanged from canonical output
|
||||||
* stored with the sources
|
* stored with the sources
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -4,26 +4,32 @@
|
||||||
* perform regression tests, output must be unchanged from canonical output
|
* perform regression tests, output must be unchanged from canonical output
|
||||||
* stored with the sources
|
* stored with the sources
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -59,7 +65,6 @@ this_callbackfn(struct getdns_context *this_context,
|
||||||
"The callback got a callback_type of %d. Exiting.",
|
"The callback got a callback_type of %d. Exiting.",
|
||||||
this_callback_type);
|
this_callback_type);
|
||||||
getdns_dict_destroy(this_response);
|
getdns_dict_destroy(this_response);
|
||||||
getdns_extension_detach_eventloop(this_context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -85,8 +90,12 @@ main(int argc, char** argv)
|
||||||
getdns_context_destroy(this_context);
|
getdns_context_destroy(this_context);
|
||||||
return (GETDNS_RETURN_GENERIC_ERROR);
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
}
|
}
|
||||||
(void) getdns_extension_set_libevent_base(this_context,
|
if (getdns_extension_set_libevent_base(this_context,
|
||||||
this_event_base);
|
this_event_base) != GETDNS_RETURN_GOOD) {
|
||||||
|
fprintf(stderr, "Setting event base failed.");
|
||||||
|
getdns_context_destroy(this_context);
|
||||||
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
|
}
|
||||||
/* Set up the getdns call */
|
/* Set up the getdns call */
|
||||||
const char *this_name = argc > 1 ? argv[1] : "www.google.com";
|
const char *this_name = argc > 1 ? argv[1] : "www.google.com";
|
||||||
char *this_userarg = "somestring"; // Could add things here to help identify this call
|
char *this_userarg = "somestring"; // Could add things here to help identify this call
|
||||||
|
@ -122,4 +131,4 @@ main(int argc, char** argv)
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|
||||||
/* example-simple-answers.c */
|
/* tests_stub_async.c */
|
||||||
|
|
|
@ -4,26 +4,32 @@
|
||||||
* perform regression tests, output must be unchanged from canonical output
|
* perform regression tests, output must be unchanged from canonical output
|
||||||
* stored with the sources
|
* stored with the sources
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* all copies or substantial portions of the Software.
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* THE SOFTWARE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -82,4 +88,4 @@ main()
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|
||||||
/* example-simple-answers.c */
|
/* tests_stub_sync.c */
|
||||||
|
|
|
@ -238,12 +238,25 @@ void dns_req_free(getdns_dns_req * req);
|
||||||
|
|
||||||
|
|
||||||
/* extensions */
|
/* extensions */
|
||||||
typedef getdns_return_t (*getdns_eventloop_cleanup_t)(struct getdns_context* context, void* data);
|
typedef void (*getdns_timeout_callback) (void* userarg);
|
||||||
|
|
||||||
|
/* context timeout data */
|
||||||
|
typedef struct getdns_timeout_data {
|
||||||
|
getdns_transaction_t transaction_id;
|
||||||
|
struct timeval timeout_time;
|
||||||
|
getdns_timeout_callback callback;
|
||||||
|
void* userarg;
|
||||||
|
void* extension_timer;
|
||||||
|
struct getdns_context* context;
|
||||||
|
} getdns_timeout_data_t;
|
||||||
|
|
||||||
|
typedef getdns_return_t (*getdns_eventloop_cleanup_t)(struct getdns_context* context, void* eventloop_data);
|
||||||
typedef getdns_return_t (*getdns_eventloop_schedule_timeout_t)(struct getdns_context* context,
|
typedef getdns_return_t (*getdns_eventloop_schedule_timeout_t)(struct getdns_context* context,
|
||||||
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
void* eventloop_data, uint16_t timeout,
|
||||||
void* userarg, void* data);
|
getdns_timeout_data_t* timeout_data,
|
||||||
|
void** eventloop_timer);
|
||||||
typedef getdns_return_t (*getdns_eventloop_clear_timeout_t)(struct getdns_context* context,
|
typedef getdns_return_t (*getdns_eventloop_clear_timeout_t)(struct getdns_context* context,
|
||||||
getdns_transaction_t id, void* data);
|
void* eventloop_data, void** eventloop_timer);
|
||||||
|
|
||||||
|
|
||||||
typedef struct getdns_eventloop_extension {
|
typedef struct getdns_eventloop_extension {
|
||||||
|
|
|
@ -54,7 +54,7 @@ static getdns_extension_format extformats[] = {
|
||||||
{"add_warning_for_bad_dns", t_int},
|
{"add_warning_for_bad_dns", t_int},
|
||||||
{"dnssec_return_only_secure", t_int},
|
{"dnssec_return_only_secure", t_int},
|
||||||
{"dnssec_return_status", t_int},
|
{"dnssec_return_status", t_int},
|
||||||
{"dnssec_return_supporting_responses", t_int},
|
{"dnssec_return_validation_chain", t_int},
|
||||||
{"return_api_information", t_int},
|
{"return_api_information", t_int},
|
||||||
{"return_both_v4_and_v6", t_int},
|
{"return_both_v4_and_v6", t_int},
|
||||||
{"return_call_debugging", t_int},
|
{"return_call_debugging", t_int},
|
||||||
|
@ -347,7 +347,7 @@ create_dict_from_rr(struct getdns_context *context, ldns_rr * rr)
|
||||||
/* helper to convert an rr_list to getdns_list.
|
/* helper to convert an rr_list to getdns_list.
|
||||||
returns a list of objects where each object
|
returns a list of objects where each object
|
||||||
is a result from create_dict_from_rr */
|
is a result from create_dict_from_rr */
|
||||||
static struct getdns_list *
|
struct getdns_list *
|
||||||
create_list_from_rr_list(struct getdns_context *context, ldns_rr_list * rr_list)
|
create_list_from_rr_list(struct getdns_context *context, ldns_rr_list * rr_list)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
@ -685,12 +685,12 @@ getdns_apply_network_result(getdns_network_req* netreq,
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return GETDNS_RETURN_GENERIC_ERROR;
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
}
|
}
|
||||||
ldns_buffer_new_frm_data(result, ub_res->answer_packet, ub_res->answer_len);
|
|
||||||
ldns_status r =
|
ldns_status r =
|
||||||
ldns_buffer2pkt_wire(&(netreq->result), result);
|
ldns_wire2pkt(&(netreq->result), ub_res->answer_packet, ub_res->answer_len);
|
||||||
ldns_buffer_free(result);
|
|
||||||
if (r != LDNS_STATUS_OK) {
|
if (r != LDNS_STATUS_OK) {
|
||||||
return GETDNS_RETURN_GENERIC_ERROR;
|
return GETDNS_RETURN_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
return GETDNS_RETURN_GOOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,15 @@ getdns_return_t getdns_list_copy(struct getdns_list *srclist,
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
getdns_dict_copy(struct getdns_dict *srcdict, struct getdns_dict **dstdict);
|
getdns_dict_copy(struct getdns_dict *srcdict, struct getdns_dict **dstdict);
|
||||||
|
|
||||||
/* convert an ip address dict to a sock storage */
|
/**
|
||||||
|
* convert an ip address (v4/v6) dict to a sock storage
|
||||||
|
* expects dict to contain keys GETDNS_STR_PORT, GETDNS_STR_ADDRESS_TYPE
|
||||||
|
* GETDNS_STR_ADDRESS_DATA
|
||||||
|
* @param ns pointer to dictionary containing keys listed above
|
||||||
|
* @param output previously allocated storage used to return numeric address
|
||||||
|
* @return GETDNS_RETURN_GOOD on success
|
||||||
|
* @return GETDNS_RETURN_GENERIC_ERROR if keys missing from dictionary
|
||||||
|
*/
|
||||||
getdns_return_t dict_to_sockaddr(struct getdns_dict * ns,
|
getdns_return_t dict_to_sockaddr(struct getdns_dict * ns,
|
||||||
struct sockaddr_storage *output);
|
struct sockaddr_storage *output);
|
||||||
getdns_return_t sockaddr_to_dict(struct getdns_context *context,
|
getdns_return_t sockaddr_to_dict(struct getdns_context *context,
|
||||||
|
@ -115,4 +123,13 @@ getdns_return_t validate_dname(const char* dname);
|
||||||
*/
|
*/
|
||||||
getdns_return_t validate_extensions(struct getdns_dict * extensions);
|
getdns_return_t validate_extensions(struct getdns_dict * extensions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper to convert an rr_list to getdns_list
|
||||||
|
* @param context initialized getdns_context
|
||||||
|
* @param rr_list ldns rr list to be converted
|
||||||
|
* @return a list of objects where each object is a result from create_dict_from_rr
|
||||||
|
*/
|
||||||
|
struct getdns_list *
|
||||||
|
create_list_from_rr_list(struct getdns_context *context, ldns_rr_list * rr_list);
|
||||||
|
|
||||||
/* util-internal.h */
|
/* util-internal.h */
|
||||||
|
|
|
@ -1,31 +1,37 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* /brief getdns core functions
|
* \file validate_dnssec.c
|
||||||
|
* @brief dnssec validation functions
|
||||||
*
|
*
|
||||||
* This is the meat of the API
|
|
||||||
* Originally taken from the getdns API description pseudo implementation.
|
* Originally taken from the getdns API description pseudo implementation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* The MIT License (MIT)
|
|
||||||
* Copyright (c) 2013 Verisign, Inc.
|
/*
|
||||||
|
* Copyright (c) 2013, Versign, Inc.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Redistributions of source code must retain the above copyright
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* furnished to do so, subject to the following conditions:
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
*
|
* documentation and/or other materials provided with the distribution.
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* * Neither the name of the <organization> nor the
|
||||||
* all copies or substantial portions of the Software.
|
* names of its contributors may be used to endorse or promote products
|
||||||
*
|
* derived from this software without specific prior written permission.
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
*
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* THE SOFTWARE.
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
|
@ -48,4 +54,4 @@ getdns_validate_dnssec(struct getdns_bindata * record_to_validate,
|
||||||
return GETDNS_RETURN_GOOD;
|
return GETDNS_RETURN_GOOD;
|
||||||
} /* getdns_validate_dnssec */
|
} /* getdns_validate_dnssec */
|
||||||
|
|
||||||
/* getdns_validate_dnssec.c */
|
/* validate_dnssec.c */
|
||||||
|
|
Loading…
Reference in New Issue