Merge branch 'develop' of https://github.com/verisign/getdns into develop

Pulling Glen and Neel's updates down
This commit is contained in:
Melinda Shore 2013-08-28 13:28:40 -08:00
commit 3becc43502
43 changed files with 1984 additions and 15411 deletions

3
.gitignore vendored
View File

@ -1,4 +1,6 @@
*~
.DS_Store
Makefile.in
getdns*.tar.gz
*.o
.*.swp
@ -9,6 +11,7 @@ aclocal.m4
depcomp
*.lo
*.la
configure
config.guess
config.sub
config.status

14708
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
AC_PREREQ([2.68])
AC_INIT([getdns], [0.320], [melinda.shore@nomountain.net])
AC_CONFIG_SRCDIR([src/common/getdns_general.c])
AC_CONFIG_SRCDIR([src/getdns/getdns.h])
AM_INIT_AUTOMAKE
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
@ -20,7 +20,7 @@ found_all_libs=1
AC_MSG_NOTICE([Checking for dependencies ldns and libevent])
AC_CHECK_LIB([event_core], [event_base_new], [], [found_all_libs=0])
AC_CHECK_LIB([ldns], [ldns_dname_new_frm_str], [], [found_all_libs=0])
AC_CHECK_LIB([pthread], [pthread_create], [], [found_all_libs=0])
if test $found_all_libs == 0
then
AC_MSG_ERROR([One more dependencies is missing])
@ -37,6 +37,6 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CONFIG_FILES([Makefile src/Makefile src/common/Makefile src/example/Makefile src/test/Makefile])
AC_CONFIG_SUBDIRS([src/ src/common/ src/example/ src/test/])
AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile])
AC_CONFIG_SUBDIRS([src/ src/getdns/ src/example/ src/test/])
AC_OUTPUT

View File

@ -1 +1,8 @@
SUBDIRS = common example test
SUBDIRS = . getdns example test
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I /usr/local/include -std=c99
lib_LTLIBRARIES = libgetdns.la
libgetdns_la_SOURCES = context.c convert.c \
dict.c general.c hostname.c list.c \
service.c sync.c validate_dnssec.c \
request-internal.c nameserver-internal.c \
util-internal.c

BIN
src/common/.DS_Store vendored

Binary file not shown.

View File

@ -1,7 +0,0 @@
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I /usr/local/include -std=c99
lib_LTLIBRARIES = libgetdns.la
libgetdns_la_SOURCES = getdns_address.c getdns_context.c getdns_convert.c \
getdns_dict.c getdns_general.c getdns_hostname.c getdns_list.c \
getdns_service.c getdns_sync.c getdns_validate_dnssec.c \
getdns_core_only.h getdns_libevent.h
include_HEADERS = getdns_core_only.h

View File

@ -1,417 +0,0 @@
/**
*
* /brief getdns contect management 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.
*
* 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.
*/
#include <getdns_libevent.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/*
* getdns_context_create
*
* call this to initialize the context that is used in other getdns calls
*/
getdns_return_t
getdns_context_create(
getdns_context_t *context,
bool set_from_os
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(set_from_os);
return GETDNS_RETURN_GOOD;
} /* getdns_context_create */
/*
* getdns_context_destroy
*
* call this to dispose of resources associated with a context once you
* are done with it
*/
void
getdns_context_destroy(
getdns_context_t context
)
{
UNUSED_PARAM(context);
} /* getdns_context_destroy */
/*
* getdns_context_set_context_update_callback
*
*/
getdns_return_t
getdns_context_set_context_update_callback(
getdns_context_t context,
void (*value)(getdns_context_t context, uint16_t changed_item)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_context_update_callback */
/*
* getdns_context_set_context_update
*
*/
getdns_return_t
getdns_context_set_context_update(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_context_update */
/*
* getdns_context_set_resolution_type
*
*/
getdns_return_t
getdns_context_set_resolution_type(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_resolution_type */
/*
* getdns_context_set_namespaces
*
*/
getdns_return_t
getdns_context_set_namespaces(
getdns_context_t context,
size_t namespace_count,
uint16_t *namespaces
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(namespace_count);
UNUSED_PARAM(namespaces);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_namespaces */
/*
* getdns_context_set_dns_transport
*
*/
getdns_return_t
getdns_context_set_dns_transport(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dns_transport */
/*
* getdns_context_set_limit_outstanding_queries
*
*/
getdns_return_t
getdns_context_set_limit_outstanding_queries(
getdns_context_t context,
uint16_t limit
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(limit);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_limit_outstanding_queries */
/*
* getdns_context_set_timeout
*
*/
getdns_return_t
getdns_context_set_timeout(
getdns_context_t context,
uint16_t timeout
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(timeout);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_timeout */
/*
* getdns_context_set_follow_redirects
*
*/
getdns_return_t
getdns_context_set_follow_redirects(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_follow_redirects */
/*
* getdns_context_set_dns_root_servers
*
*/
getdns_return_t
getdns_context_set_dns_root_servers(
getdns_context_t context,
struct getdns_list *addresses
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(addresses);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dns_root_servers */
/*
* getdns_context_set_append_name
*
*/
getdns_return_t
getdns_context_set_append_name(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_append_name */
/*
* getdns_context_set_suffix
*
*/
getdns_return_t
getdns_context_set_suffix(
getdns_context_t context,
struct getdns_list *value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_suffix */
/*
* getdns_context_set_dnssec_trust_anchors
*
*/
getdns_return_t
getdns_context_set_dnssec_trust_anchors(
getdns_context_t context,
struct getdns_list *value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dnssec_trust_anchors */
/*
* getdns_context_set_dnssec_allowed_skew
*
*/
getdns_return_t
getdns_context_set_dnssec_allowed_skew(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dnssec_allowed_skew */
/*
* getdns_context_set_stub_resolution
*
*/
getdns_return_t
getdns_context_set_stub_resolution(
getdns_context_t context,
struct getdns_list *upstream_list
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(upstream_list);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_stub_resolution */
/*
* getdns_context_set_edns_maximum_udp_payload_size
*
*/
getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_maximum_udp_payload_size */
/*
* getdns_context_set_edns_extended_rcode
*
*/
getdns_return_t
getdns_context_set_edns_extended_rcode(
getdns_context_t context,
uint8_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_extended_rcode */
/*
* getdns_context_set_edns_version
*
*/
getdns_return_t
getdns_context_set_edns_version(
getdns_context_t context,
uint8_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_version */
/*
* getdns_context_set_edns_do_bit
*
*/
getdns_return_t
getdns_context_set_edns_do_bit(
getdns_context_t context,
uint8_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_do_bit */
/*
* getdns_context_set_memory_allocator
*
*/
getdns_return_t
getdns_context_set_memory_allocator(
getdns_context_t context,
void (*value)(size_t somesize)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_memory_allocator */
/*
* getdns_context_set_memory_deallocator
*
*/
getdns_return_t
getdns_context_set_memory_deallocator(
getdns_context_t context,
void (*value)(void*)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_memory_deallocator */
/*
* getdns_context_set_memory_reallocator
*
*/
getdns_return_t
getdns_context_set_memory_reallocator(
getdns_context_t context,
void (*value)(void*)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_memory_reallocator */
/*
* getdns_extension_set_libevent_base
*
*/
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(this_event_base);
return GETDNS_RETURN_GOOD;
} /* getdns_extension_set_libevent_base */
/*
* getdns_cancel_callback
*
*/
getdns_return_t
getdns_cancel_callback(
getdns_context_t context,
getdns_transaction_t transaction_id
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(transaction_id);
return GETDNS_RETURN_GOOD;
} /* getdns_cancel_callback */
/* getdns_context.c */

View File

@ -1,60 +0,0 @@
/**
*
* /brief getdns core 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.
*
* 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.
*/
#include <getdns_core_only.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/*
* getdns_general
*/
getdns_return_t
getdns_general(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(name);
UNUSED_PARAM(request_type);
UNUSED_PARAM(extensions);
UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id);
UNUSED_PARAM(callback);
return GETDNS_RETURN_GOOD;
} /* getdns_general */
/* getdns_general.c */

View File

@ -1,9 +0,0 @@
#include <event2/event.h>
#include <getdns_core_only.h>
/* For libevent, which we are using for these examples */
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
);

View File

@ -1,87 +0,0 @@
/**
*
* /brief getdns core functions for synchronous use
*
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* 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.
*/
#include <getdns_core_only.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
getdns_return_t
getdns_general_sync(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(request_type); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_address_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_hostname_sync(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(address); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_service_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
void
getdns_free_sync_request_memory(
struct getdns_dict *response
)
{ UNUSED_PARAM(response); }
/* getdns_core_sync.c */

View File

@ -1,22 +0,0 @@
rm -rf *.o *.dylib
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
gcc -std=c89 -shared -fPIC -levent_core -o libgetdns.so getdns_core_only.o
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
gcc -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
gcc -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
gcc -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
gcc -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous
rm -rf *.o *.dylib
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
clang -std=c89 -shared -fPIC -levent_core -o libgetdns.so getdns_core_only.o
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
clang -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
clang -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
clang -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
clang -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous

View File

@ -1,22 +0,0 @@
rm -rf *.o *.dylib
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
gcc -std=c89 -dynamiclib -fPIC -levent_core -o libgetdns.dylib getdns_core_only.o
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
gcc -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
gcc -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
gcc -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
gcc -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous
rm -rf *.o *.dylib
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
clang -std=c89 -dynamiclib -fPIC -levent_core -o libgetdns.dylib getdns_core_only.o
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
clang -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
clang -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
clang -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
clang -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous

691
src/context.c Normal file
View File

@ -0,0 +1,691 @@
/**
*
* /brief getdns contect management 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.
*
* 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.
*/
#include <string.h>
#include "context.h"
#include "util-internal.h"
#include <ldns/ldns.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/**
* Helper to get default lookup namespaces.
* TODO: Determine from OS
*/
static uint16_t* create_default_namespaces() {
uint16_t *result = malloc(2 * sizeof(uint16_t));
result[0] = GETDNS_CONTEXT_NAMESPACE_LOCALNAMES;
result[1] = GETDNS_CONTEXT_NAMESPACE_DNS;
return result;
}
/**
* Helper to get the default root servers.
* TODO: Implement
*/
static struct getdns_list* create_default_root_servers() {
return NULL;
}
static struct getdns_dict* create_ipaddr_dict_from_rdf(ldns_rdf* rdf) {
ldns_rdf_type rt = ldns_rdf_get_type(rdf);
size_t sz = ldns_rdf_size(rdf);
getdns_dict *result = getdns_dict_create();
/* set type */
if (rt == LDNS_RDF_TYPE_A) {
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV4);
} else {
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV6);
}
/* set data */
getdns_bindata data_bin = { sz, ldns_rdf_data(rdf) };
getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA, &data_bin);
return result;
}
static struct getdns_list* create_from_ldns_list(ldns_rdf** ldns_list, size_t count) {
size_t i = 0;
size_t idx = 0;
struct getdns_list *result = getdns_list_create();
for (i = 0; i < count; ++i) {
ldns_rdf* rdf = ldns_list[i];
switch (ldns_rdf_get_type(rdf)) {
case LDNS_RDF_TYPE_A:
case LDNS_RDF_TYPE_AAAA:
{
getdns_dict *ipaddr = create_ipaddr_dict_from_rdf(rdf);
getdns_list_add_item(result, &idx);
getdns_list_set_dict(result, idx, ipaddr);
getdns_dict_destroy(ipaddr);
}
break;
case LDNS_RDF_TYPE_DNAME:
{
getdns_bindata item;
char* srch = ldns_rdf2str(rdf);
item.size = strlen(srch);
item.data = (uint8_t*) srch;
getdns_list_add_item(result, &idx);
getdns_list_set_bindata(result, idx, &item);
free(srch);
}
break;
default:
break;
}
}
return result;
}
static getdns_return_t set_os_defaults(getdns_context_t context) {
ldns_resolver *lr = NULL;
if (ldns_resolver_new_frm_file(&lr, NULL) != LDNS_STATUS_OK) {
return GETDNS_RETURN_GENERIC_ERROR;
}
ldns_rdf **rdf_list= ldns_resolver_nameservers(lr);
size_t rdf_list_sz = ldns_resolver_nameserver_count(lr);
if (rdf_list_sz > 0) {
context->upstream_list = create_from_ldns_list(rdf_list, rdf_list_sz);
}
rdf_list = ldns_resolver_searchlist(lr);
rdf_list_sz = ldns_resolver_searchlist_count(lr);
if (rdf_list_sz > 0) {
context->suffix = create_from_ldns_list(rdf_list, rdf_list_sz);
}
/** cleanup **/
ldns_resolver_free(lr);
return GETDNS_RETURN_GOOD;
}
/*
* getdns_context_create
*
* call this to initialize the context that is used in other getdns calls
*/
getdns_return_t getdns_context_create(
getdns_context_t *context,
int set_from_os
)
{
getdns_context_t result = NULL;
if (context == NULL) {
return GETDNS_RETURN_GENERIC_ERROR;
}
getdns_dict *outbound_reqs = getdns_dict_create();
if (outbound_reqs == NULL) {
return GETDNS_RETURN_GENERIC_ERROR;
}
/** default init **/
result = malloc(sizeof(struct getdns_context_t));
result->resolution_type = GETDNS_CONTEXT_RECURSING;
result->namespaces = create_default_namespaces();
result->dns_transport = GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP;
result->limit_outstanding_queries = 0;
result->timeout = 5000;
result->follow_redirects = GETDNS_CONTEXT_FOLLOW_REDIRECTS;
result->dns_root_servers = create_default_root_servers();
result->append_name = GETDNS_CONTEXT_APPEND_NAME_ALWAYS;
result->suffix = NULL;
result->dnssec_trust_anchors = NULL;
result->dnssec_allow_skew = 0;
result->upstream_list = NULL;
result->edns_maximum_udp_payload_size = 512;
result->edns_extended_rcode = 0;
result->edns_version = 0;
result->edns_do_bit = 0;
result->event_base = NULL;
result->resolver_socket = 0;
result->outbound_reqs = outbound_reqs;
result->update_callback = NULL;
result->memory_allocator = malloc;
result->memory_deallocator = free;
result->memory_reallocator = realloc;
if (set_from_os) {
if (GETDNS_RETURN_GOOD != set_os_defaults(result)) {
getdns_context_destroy(result);
return GETDNS_RETURN_GENERIC_ERROR;
}
}
*context = result;
return GETDNS_RETURN_GOOD;
} /* getdns_context_create */
/*
* getdns_context_destroy
*
* call this to dispose of resources associated with a context once you
* are done with it
*/
void
getdns_context_destroy(
getdns_context_t context
)
{
if (context == NULL) {
return;
}
if (context->namespaces) {
context->memory_deallocator(context->namespaces);
}
getdns_list_destroy(context->dns_root_servers);
getdns_list_destroy(context->suffix);
getdns_list_destroy(context->dnssec_trust_anchors);
getdns_list_destroy(context->upstream_list);
getdns_dict_destroy(context->outbound_reqs);
/* TODO: cancel all events */
if (context->resolver_socket != 0) {
evutil_closesocket(context->resolver_socket);
}
free(context);
return;
} /* getdns_context_destroy */
/*
* getdns_context_set_context_update_callback
*
*/
getdns_return_t
getdns_context_set_context_update_callback(
getdns_context_t context,
void (*value)(getdns_context_t context, uint16_t changed_item)
)
{
context->update_callback = value;
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_context_update_callback */
/*
* getdns_context_set_context_update
*
*/
getdns_return_t
getdns_context_set_context_update(
getdns_context_t context,
uint16_t value
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_context_update */
/**
* Helper to dispatch the updated callback
*/
static void dispatch_updated(getdns_context_t context,
uint16_t item) {
if (context->update_callback) {
context->update_callback(context, item);
}
}
/*
* getdns_context_set_resolution_type
*
*/
getdns_return_t
getdns_context_set_resolution_type(
getdns_context_t context,
uint16_t value
)
{
if (value != GETDNS_CONTEXT_STUB &&
value != GETDNS_CONTEXT_RECURSING) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
context->resolution_type = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_RESOLUTION_TYPE);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_resolution_type */
/*
* getdns_context_set_namespaces
*
*/
getdns_return_t
getdns_context_set_namespaces(
getdns_context_t context,
size_t namespace_count,
uint16_t *namespaces
)
{
size_t namespaces_size;
if (namespace_count == 0 || namespaces == NULL) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
/** clean up old namespaces **/
context->memory_deallocator(context->namespaces);
/** duplicate **/
namespaces_size = namespace_count * sizeof(uint16_t);
context->namespaces = context->memory_allocator(namespaces_size);
memcpy(context->namespaces, namespaces, namespaces_size);
dispatch_updated(context, GETDNS_CONTEXT_CODE_NAMESPACES);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_namespaces */
/*
* getdns_context_set_dns_transport
*
*/
getdns_return_t
getdns_context_set_dns_transport(
getdns_context_t context,
uint16_t value
)
{
if (value != GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP &&
value != GETDNS_CONTEXT_UDP_ONLY &&
value != GETDNS_CONTEXT_TCP_ONLY &&
value != GETDNS_CONTEXT_TCP_ONLY_KEEP_CONNECTIONS_OPEN) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
context->dns_transport = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_DNS_TRANSPORT);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dns_transport */
/*
* getdns_context_set_limit_outstanding_queries
*
*/
getdns_return_t
getdns_context_set_limit_outstanding_queries(
getdns_context_t context,
uint16_t limit
)
{
context->limit_outstanding_queries = limit;
dispatch_updated(context, GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_limit_outstanding_queries */
/*
* getdns_context_set_timeout
*
*/
getdns_return_t
getdns_context_set_timeout(
getdns_context_t context,
uint16_t timeout
)
{
context->timeout = timeout;
dispatch_updated(context, GETDNS_CONTEXT_CODE_TIMEOUT);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_timeout */
/*
* getdns_context_set_follow_redirects
*
*/
getdns_return_t
getdns_context_set_follow_redirects(
getdns_context_t context,
uint16_t value
)
{
context->follow_redirects = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_follow_redirects */
/*
* getdns_context_set_dns_root_servers
*
*/
getdns_return_t
getdns_context_set_dns_root_servers(
getdns_context_t context,
struct getdns_list *addresses
)
{
getdns_list *copy = NULL;
if (addresses != NULL) {
if (getdns_list_copy(addresses, &copy) != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
addresses = copy;
}
getdns_list_destroy(context->dns_root_servers);
context->dns_root_servers = addresses;
dispatch_updated(context, GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dns_root_servers */
/*
* getdns_context_set_append_name
*
*/
getdns_return_t
getdns_context_set_append_name(
getdns_context_t context,
uint16_t value
)
{
if (value != GETDNS_CONTEXT_APPEND_NAME_ALWAYS &&
value != GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE &&
value != GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE &&
value != GETDNS_CONTEXT_DO_NOT_APPEND_NAMES) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
context->append_name = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_APPEND_NAME);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_append_name */
/*
* getdns_context_set_suffix
*
*/
getdns_return_t
getdns_context_set_suffix(
getdns_context_t context,
struct getdns_list *value
)
{
getdns_list *copy = NULL;
if (value != NULL) {
if (getdns_list_copy(value, &copy) != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
value = copy;
}
getdns_list_destroy(context->suffix);
context->suffix = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_SUFFIX);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_suffix */
/*
* getdns_context_set_dnssec_trust_anchors
*
*/
getdns_return_t
getdns_context_set_dnssec_trust_anchors(
getdns_context_t context,
struct getdns_list *value
)
{
getdns_list *copy = NULL;
if (value != NULL) {
if (getdns_list_copy(value, &copy) != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
value = copy;
}
getdns_list_destroy(context->dnssec_trust_anchors);
context->dnssec_trust_anchors = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dnssec_trust_anchors */
/*
* getdns_context_set_dnssec_allowed_skew
*
*/
getdns_return_t
getdns_context_set_dnssec_allowed_skew(
getdns_context_t context,
uint16_t value
)
{
context->dnssec_allow_skew = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_dnssec_allowed_skew */
/*
* getdns_context_set_stub_resolution
*
*/
getdns_return_t
getdns_context_set_stub_resolution(
getdns_context_t context,
struct getdns_list *upstream_list
)
{
if (upstream_list == NULL) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
getdns_list *copy = NULL;
if (getdns_list_copy(upstream_list, &copy) != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
upstream_list = copy;
getdns_context_set_resolution_type(context, GETDNS_CONTEXT_STUB);
getdns_list_destroy(context->upstream_list);
context->upstream_list = upstream_list;
dispatch_updated(context, GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_stub_resolution */
/*
* getdns_context_set_edns_maximum_udp_payload_size
*
*/
getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size(
getdns_context_t context,
uint16_t value
)
{
/* check for < 512. uint16_t won't let it go above max) */
if (value < 512) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
context->edns_maximum_udp_payload_size = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_maximum_udp_payload_size */
/*
* getdns_context_set_edns_extended_rcode
*
*/
getdns_return_t
getdns_context_set_edns_extended_rcode(
getdns_context_t context,
uint8_t value
)
{
context->edns_extended_rcode = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_extended_rcode */
/*
* getdns_context_set_edns_version
*
*/
getdns_return_t
getdns_context_set_edns_version(
getdns_context_t context,
uint8_t value
)
{
context->edns_version = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_EDNS_VERSION);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_version */
/*
* getdns_context_set_edns_do_bit
*
*/
getdns_return_t
getdns_context_set_edns_do_bit(
getdns_context_t context,
uint8_t value
)
{
/* 0 or 1 */
if (value > 1) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
}
context->edns_do_bit = value;
dispatch_updated(context, GETDNS_CONTEXT_CODE_EDNS_DO_BIT);
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_do_bit */
/*
* getdns_context_set_memory_allocator
*
*/
getdns_return_t
getdns_context_set_memory_allocator(
getdns_context_t context,
void (*value)(size_t somesize)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} /* getdns_context_set_memory_allocator */
/*
* getdns_context_set_memory_deallocator
*
*/
getdns_return_t
getdns_context_set_memory_deallocator(
getdns_context_t context,
void (*value)(void*)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} /* getdns_context_set_memory_deallocator */
/*
* getdns_context_set_memory_reallocator
*
*/
getdns_return_t
getdns_context_set_memory_reallocator(
getdns_context_t context,
void (*value)(void*)
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(value);
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} /* getdns_context_set_memory_reallocator */
/*
* getdns_extension_set_libevent_base
*
*/
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
)
{
/* TODO: cancel anything on an existing event base */
context->event_base = this_event_base;
return GETDNS_RETURN_GOOD;
} /* getdns_extension_set_libevent_base */
/*
* getdns_cancel_callback
*
*/
getdns_return_t
getdns_cancel_callback(
getdns_context_t context,
getdns_transaction_t transaction_id
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(transaction_id);
return GETDNS_RETURN_GOOD;
} /* getdns_cancel_callback */
/* getdns_context.c */

77
src/context.h Normal file
View File

@ -0,0 +1,77 @@
/**
*
* /brief getdns contect management 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.
*
* 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_CONTEXT_H_
#define _GETDNS_CONTEXT_H_
#include <getdns/getdns.h>
/** function pointer typedefs */
typedef void (*getdns_update_callback)(getdns_context_t context, uint16_t changed_item);
typedef void* (*getdns_memory_allocator)(size_t size);
typedef void (*getdns_memory_deallocator)(void*);
typedef void* (*getdns_memory_reallocator)(void* ptr, size_t size);
struct getdns_context_t {
/* Context values */
uint16_t resolution_type;
uint16_t *namespaces;
uint16_t dns_transport;
uint16_t limit_outstanding_queries;
uint16_t timeout;
uint16_t follow_redirects;
struct getdns_list *dns_root_servers;
uint16_t append_name;
struct getdns_list *suffix;
struct getdns_list *dnssec_trust_anchors;
uint16_t dnssec_allow_skew;
struct getdns_list *upstream_list;
uint16_t edns_maximum_udp_payload_size;
uint8_t edns_extended_rcode;
uint8_t edns_version;
uint8_t edns_do_bit;
getdns_update_callback update_callback;
getdns_memory_allocator memory_allocator;
getdns_memory_deallocator memory_deallocator;
getdns_memory_reallocator memory_reallocator;
/* Event loop */
struct event_base* event_base;
/* outbound request dict (transaction -> req struct) */
getdns_dict *outbound_reqs;
/* socket */
evutil_socket_t resolver_socket;
} ;
#endif

View File

@ -28,7 +28,7 @@
* THE SOFTWARE.
*/
#include <getdns_core_only.h>
#include <getdns/getdns.h>
#include <stdio.h>
/* stuff to make it compile pedantically */

View File

@ -32,7 +32,7 @@
#include <stdio.h>
#include <search.h>
#include <string.h>
#include <getdns_core_only.h>
#include <getdns/getdns.h>
/* TODO: change this to make the walk safe for reentrant/multi-thread calls */
struct getdns_list *walkresultlist;
@ -508,7 +508,7 @@ getdns_dict_set_bindata(struct getdns_dict *dict, char *name, struct getdns_bind
item->data.bindata = (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
if(item->data.bindata != NULL)
{
item->data.bindata->data = (void *) malloc(item->data.bindata->size);
item->data.bindata->data = (void *) malloc(child_bindata->size);
if(item->data.bindata->data != NULL)
{
item->data.bindata->size = child_bindata->size;

View File

@ -1,5 +1,5 @@
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I/usr/local/include -I../common -std=c99
AM_LDFLAGS = -L../common -L/usr/local/lib -lgetdns -lldns -levent
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I/usr/local/include -I$(top_srcdir)/src -std=c99
AM_LDFLAGS =-L$(top_srcdir)/src -L/usr/local/lib -lgetdns -lldns -levent -lpthread
bin_PROGRAMS = example_all_functions example_synchronous \
example_simple_answers example_tree
example_all_functions_SOURCES = example_all_functions.c

View File

@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <getdns_core_only.h>
#include <getdns/getdns.h>
#define UNUSED_PARAM(x) ((void)(x))

View File

@ -31,7 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#include <getdns/getdns.h>
#define UNUSED_PARAM(x) ((void)(x))

View File

@ -30,7 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_core_only.h>
#include <getdns/getdns.h>
int
main()

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#include <getdns/getdns.h>
#define UNUSED_PARAM(x) ((void)(x))

229
src/general.c Normal file
View File

@ -0,0 +1,229 @@
/**
*
* /brief getdns core 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.
*
* 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.
*/
/**
* Much of this is based on / duplicated code from libevent evdns. Credits to
* Nick Mathewson and Niels Provos
*
* https://github.com/libevent/libevent/
*
* libevent dns is based on software by Adam Langly. Adam's original message:
*
* Async DNS Library
* Adam Langley <agl@imperialviolet.org>
* http://www.imperialviolet.org/eventdns.html
* Public Domain code
*
* This software is Public Domain. To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
* I ask and expect, but do not require, that all derivative works contain an
* attribution similar to:
* Parts developed by Adam Langley <agl@imperialviolet.org>
*
* You may wish to replace the word "Parts" with something else depending on
* the amount of original code.
*
* (Derivative works does not include programs which link against, run or include
* the source verbatim in their source distributions)
*
* Version: 0.1b
*/
#include "types-internal.h"
#include "util-internal.h"
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/* libevent callback for a network request */
static void dns_req_callback(int fd, short events, void *arg) {
getdns_dns_req *request = (getdns_dns_req*) arg;
uint8_t data[1500];
if (events & EV_READ) {
while (1) {
ssize_t r = recv(fd, data, sizeof(data), MSG_DONTWAIT);
if (r < 0) {
if (errno == EAGAIN) return;
/* otherwise failed */
request->user_callback(request->context,
GETDNS_CALLBACK_ERROR,
NULL, request->user_pointer,
request->trans_id);
}
/* parse a packet */
ldns_pkt* pkt = NULL;
ldns_wire2pkt(&pkt, data, r);
if (pkt == NULL) {
/* otherwise failed */
request->user_callback(request->context,
GETDNS_CALLBACK_ERROR,
NULL, request->user_pointer,
request->trans_id);
} else {
/* success */
getdns_dict* response = create_getdns_response(pkt);
ldns_pkt_free(pkt);
request->user_callback(request->context, GETDNS_CALLBACK_COMPLETE,
response, request->user_pointer,
request->trans_id);
}
}
} else if (events & EV_TIMEOUT) {
request->user_callback(request->context, GETDNS_CALLBACK_TIMEOUT,
NULL, request->user_pointer, request->trans_id);
}
/* clean up ns since right now it's 1:1 with the request */
nameserver_free(request->current_req->ns);
/* cleanup the request */
dns_req_free(request);
}
/* submit a new request to the event loop */
static getdns_return_t submit_new_dns_req(getdns_dns_req *request) {
getdns_dict *ip_dict = NULL;
getdns_context_t context = request->context;
uint8_t* data = NULL;
size_t data_len = 0;
struct timeval timeout = { 5, 0 };
/* get first upstream server */
getdns_list_get_dict(context->upstream_list, 0, &ip_dict);
if (!ip_dict) {
return GETDNS_RETURN_GENERIC_ERROR;
}
/* get the nameserver */
getdns_nameserver *ns = nameserver_new_from_ip_dict(context, ip_dict);
if (!ns) {
return GETDNS_RETURN_GENERIC_ERROR;
}
request->current_req->ns = ns;
/* schedule on the loop */
ns->event = event_new(context->event_base, request->current_req->ns->socket,
EV_READ | EV_TIMEOUT,
dns_req_callback, request);
event_add(ns->event, &timeout);
/* send data */
ldns_pkt *pkt = request->current_req->pkt;
ldns_pkt2wire(&data, pkt, &data_len);
send(ns->socket, data, data_len, MSG_DONTWAIT);
free(data);
return GETDNS_RETURN_GOOD;
}
/*
* getdns_general
*/
getdns_return_t
getdns_general(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{
/* Default to zero */
if (transaction_id != NULL) {
*transaction_id = 0;
}
if (!context || context->event_base == NULL ||
callback == NULL ||
context->resolution_type != GETDNS_CONTEXT_STUB) {
/* Can't do async without an event loop
* or callback
*
* Only supports stub right now.
*/
return GETDNS_RETURN_BAD_CONTEXT;
}
/* create a req */
getdns_dns_req *dns_req = dns_req_new(context, name, request_type,
extensions, transaction_id);
if (dns_req == NULL) {
return GETDNS_RETURN_GENERIC_ERROR;
}
dns_req->user_callback = callback;
dns_req->user_pointer = userarg;
/* submit it */
submit_new_dns_req(dns_req);
return GETDNS_RETURN_GOOD;
} /* getdns_general */
/*
* getdns_address
*
*/
getdns_return_t
getdns_address(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{
int cleanup_extensions = 0;
if (!extensions) {
extensions = getdns_dict_create();
cleanup_extensions = 1;
}
getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6,
GETDNS_EXTENSION_TRUE);
getdns_return_t result =
getdns_general(context, name, GETDNS_RRTYPE_A,
extensions, userarg, transaction_id,
callback);
if (cleanup_extensions) {
getdns_dict_destroy(extensions);
}
return result;
}
/* getdns_general.c */

1
src/getdns/Makefile.am Normal file
View File

@ -0,0 +1 @@
pkginclude_HEADERS = getdns.h

View File

@ -33,6 +33,7 @@
#include <stdlib.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <event.h>
#define GETDNS_COMPILATION_COMMENT The API implementation should fill in something here, such as a compilation version string and date, and change it each time the API is compiled.
@ -120,8 +121,8 @@
#define GETDNS_CONTEXT_APPEND_NAME_ALWAYS_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE 514
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE 515
#define GETDNS_CONTEXT_GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE 515
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_DO_NOT_APPEND_NAMES 516
#define GETDNS_CONTEXT_DO_NOT_APPEND_NAMES_TEXT See getdns_context_set_append_name()
/** @}
@ -141,8 +142,8 @@
#define GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS_TEXT Change related to getdns_context_set_upstream_recursive_servers
#define GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS 604
#define GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS_TEXT Change related to getdns_context_set_dns_root_servers
#define GETDNS_CONTEXT_CODE_USE_UDP_TCP 605
#define GETDNS_CONTEXT_CODE_USE_UDP_TCP_TEXT Change related to getdns_context_set_use_udp_tcp
#define GETDNS_CONTEXT_CODE_DNS_TRANSPORT 605
#define GETDNS_CONTEXT_CODE_DNS_TRANSPORT_TEXT Change related to getdns_context_set_dns_transport
#define GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES 606
#define GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES_TEXT Change related to getdns_context_set_limit_outstanding_queries
#define GETDNS_CONTEXT_CODE_APPEND_NAME 607
@ -167,6 +168,8 @@
#define GETDNS_CONTEXT_CODE_MEMORY_DEALLOCATOR_TEXT Change related to getdns_context_set_memory_deallocator
#define GETDNS_CONTEXT_CODE_MEMORY_REALLOCATOR 617
#define GETDNS_CONTEXT_CODE_MEMORY_REALLOCATOR_TEXT Change related to getdns_context_set_memory_reallocator
#define GETDNS_CONTEXT_CODE_TIMEOUT 618
#define GETDNS_CONTEXT_CODE_TIMEOUT_TEXT Change related to getdns_context_set_timeout
/** @}
*/
@ -215,9 +218,9 @@
* \defgroup extvals Values Associated With Extensions
* @{
*/
#define GETDNS_EXTENSION_TRUE 1000
#define GETDNS_EXTENSION_TRUE 1
#define GETDNS_EXTENSION_TRUE_TEXT Turn on the extension
#define GETDNS_EXTENSION_FALSE 1001
#define GETDNS_EXTENSION_FALSE 0
#define GETDNS_EXTENSION_FALSE_TEXT Do not turn on the extension
/** @}
*/
@ -232,6 +235,20 @@
#define GETDNS_BAD_DNS_ALL_NUMERIC_LABEL_TEXT One or more labels in a returned domain name is all-numeric; this is not legal for a hostname
#define GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE 1102
#define GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE_TEXT A DNS query for a type other than CNAME returned a CNAME response
/** @}
*/
/**
* \defgroup strings String Constants
* @{
*/
#define GETDNS_STR_IPV4 "IPv4"
#define GETDNS_STR_IPV6 "IPv6"
#define GETDNS_STR_ADDRESS_TYPE "address_type"
#define GETDNS_STR_ADDRESS_DATA "address_data"
#define GETDNS_STR_PORT "port"
#define GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6 "return_both_v4_and_v6"
/** @}
*/
@ -681,10 +698,9 @@ getdns_service(
getdns_callback_t callbackfn
);
getdns_return_t
getdns_context_create(
getdns_return_t getdns_context_create(
getdns_context_t *context,
bool set_from_os
int set_from_os
);
void
@ -724,7 +740,7 @@ getdns_general_sync(
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
struct getdns_dict **response
);
/**
@ -742,7 +758,7 @@ getdns_address_sync(
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
struct getdns_dict **response
);
/**
@ -760,7 +776,7 @@ getdns_hostname_sync(
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
struct getdns_dict **response
);
/**
@ -778,7 +794,7 @@ getdns_service_sync(
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
struct getdns_dict **response
);
void
@ -952,4 +968,12 @@ getdns_context_set_memory_reallocator(
void (*value)(void*)
);
/* Extension - refactor to abstract async evt loop */
/* For libevent, which we are using for these examples */
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
);
#endif /* GETDNS_H */

View File

@ -28,7 +28,7 @@
* THE SOFTWARE.
*/
#include <getdns_core_only.h>
#include <getdns/getdns.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))

View File

@ -29,7 +29,7 @@
*/
#include <string.h>
#include <getdns_core_only.h>
#include <getdns/getdns.h>
/*---------------------------------------- getdns_list_get_length */
getdns_return_t

101
src/nameserver-internal.c Normal file
View File

@ -0,0 +1,101 @@
/**
*
* /brief getdns contect management 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.
*
* 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.
*/
#include "types-internal.h"
#include "util-internal.h"
/* useful macros */
#define gd_malloc(sz) context->memory_allocator(sz)
#define gd_free(ptr) context->memory_deallocator(ptr)
getdns_nameserver* nameserver_new_from_ip_dict(getdns_context_t context,
getdns_dict* ip_dict) {
if (!context || !ip_dict) {
return NULL;
}
struct sockaddr_storage sockdata;
/* setup socket */
if (dict_to_sockaddr(ip_dict, &sockdata) != GETDNS_RETURN_GOOD) {
return NULL;
}
getdns_nameserver *result = gd_malloc(sizeof(getdns_nameserver));
if (!result) {
return NULL;
}
memset(result, 0, sizeof(getdns_nameserver));
result->context = context;
/* create socket */
evutil_socket_t sock = socket(sockdata.ss_family, SOCK_DGRAM, 0);
evutil_make_socket_closeonexec(sock);
evutil_make_socket_nonblocking(sock);
result->address = sockdata;
result->socket = sock;
int connected = -1;
if (sockdata.ss_family == AF_INET) {
connected = connect(sock, (struct sockaddr *) &sockdata, sizeof(struct sockaddr_in));
} else if (sockdata.ss_family == AF_INET6) {
connected = connect(sock, (struct sockaddr *) &sockdata, sizeof(struct sockaddr_in6));
}
if (connected != 0) {
// sad
nameserver_free(result);
result= NULL;
}
return result;
}
void nameserver_free(getdns_nameserver* nameserver) {
if (!nameserver) {
return;
}
if (nameserver->event) {
event_del(nameserver->event);
event_free(nameserver->event);
}
getdns_context_t context = nameserver->context;
evutil_closesocket(nameserver->socket);
gd_free(nameserver);
}
getdns_dict* nameserver_to_dict(getdns_nameserver* nameserver) {
if (!nameserver) {
return NULL;
}
getdns_dict* result = NULL;
sockaddr_to_dict(&nameserver->address, &result);
return result;
}

119
src/request-internal.c Normal file
View File

@ -0,0 +1,119 @@
/**
*
* /brief getdns contect management 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.
*
* 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.
*/
#include "types-internal.h"
#include "util-internal.h"
/* useful macros */
#define gd_malloc(sz) context->memory_allocator(sz)
#define gd_free(ptr) context->memory_deallocator(ptr)
void network_req_free(getdns_network_req* net_req) {
if (!net_req) {
return;
}
getdns_context_t context = net_req->context;
if (net_req->pkt) {
ldns_pkt_free(net_req->pkt);
}
gd_free(net_req);
}
getdns_network_req* network_req_new(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict* extensions) {
getdns_network_req *net_req = NULL;
ldns_pkt *pkt = NULL;
net_req = gd_malloc(sizeof(getdns_network_req));
if (!net_req) {
return NULL;
}
net_req->ns = NULL;
net_req->pkt = NULL;
net_req->context = context;
net_req->request_type = request_type;
/* create ldns packet */
pkt = create_new_pkt(context, name, request_type, extensions);
if (!pkt) {
/* free up the req */
network_req_free(net_req);
return NULL;
}
net_req->pkt = pkt;
return net_req;
}
void dns_req_free(getdns_dns_req* req) {
if (!req) {
return;
}
getdns_context_t context = req->context;
network_req_free(req->current_req);
gd_free(req);
}
/* create a new dns req to be submitted */
getdns_dns_req* dns_req_new(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict *extensions,
getdns_transaction_t *transaction_id) {
getdns_dns_req *result = NULL;
getdns_network_req *net_req = NULL;
result = gd_malloc(sizeof(getdns_dns_req));
if (result == NULL) {
return NULL;
}
result->context = context;
result->current_req = NULL;
result->pending_cb = 0;
result->resolver_type = context->resolution_type;
/* create the initial network request */
net_req = network_req_new(context, name, request_type,
extensions);
if (!net_req) {
dns_req_free(result);
result = NULL;
}
result->trans_id = ldns_pkt_id(net_req->pkt);
if (transaction_id) {
*transaction_id = result->trans_id;
}
result->current_req = net_req;
net_req->owner = result;
return result;
}

View File

@ -28,7 +28,7 @@
* THE SOFTWARE.
*/
#include <getdns_core_only.h>
#include <getdns/getdns.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
@ -47,14 +47,9 @@ getdns_service(
getdns_callback_t callback
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(name);
UNUSED_PARAM(extensions);
UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id);
UNUSED_PARAM(callback);
return GETDNS_RETURN_GOOD;
return getdns_general(context, name, GETDNS_RRTYPE_SRV,
extensions, userarg, transaction_id,
callback);
} /* getdns_service */
/* getdns_core_only.c */

179
src/sync.c Normal file
View File

@ -0,0 +1,179 @@
/**
*
* /brief getdns core functions for synchronous use
*
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* 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.
*/
#include <getdns/getdns.h>
#include <pthread.h>
#include "types-internal.h"
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/* struct used for the request */
typedef struct sync_request_data {
getdns_context_t context;
const char* name;
uint16_t request_type;
getdns_dict *extensions;
getdns_return_t response_status;
getdns_dict **response;
} sync_request_data;
static void sync_callback_func(getdns_context_t context,
uint16_t callback_type,
struct getdns_dict *response,
void *userarg,
getdns_transaction_t transaction_id) {
sync_request_data* req_data = userarg;
*(req_data->response) = response;
}
static void * request_thread_start(void *arg) {
struct sync_request_data *req_data = arg;
struct event_base *event_base = event_base_new();
getdns_extension_set_libevent_base(req_data->context, event_base);
req_data->response_status = getdns_general(req_data->context,
req_data->name,
req_data->request_type,
req_data->extensions,
req_data,
NULL,
sync_callback_func);
event_base_dispatch(event_base);
return NULL;
}
getdns_return_t
getdns_general_sync(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
)
{
/* we will cheat and spawn a thread */
/* get the old event base */
struct event_base* orig_base = context->event_base;
pthread_t thread;
pthread_attr_t attr;
sync_request_data req_data = {
context, name, request_type,
extensions,
GETDNS_RETURN_GOOD,
response
};
/* create the thread */
int ret = pthread_attr_init(&attr);
if (ret != 0) {
return GETDNS_RETURN_GENERIC_ERROR;
}
ret = pthread_create(&thread, &attr, request_thread_start, &req_data);
if (ret != 0) {
pthread_attr_destroy(&attr);
return GETDNS_RETURN_GENERIC_ERROR;
}
/* wait for the thread */
ret = pthread_join(thread, NULL);
/* delete attr */
pthread_attr_destroy(&attr);
if (ret != 0) {
return GETDNS_RETURN_GENERIC_ERROR;
}
/* set the old event loop */
getdns_extension_set_libevent_base(context, orig_base);
return req_data.response_status;
}
getdns_return_t
getdns_address_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
)
{
int cleanup_extensions = 0;
if (!extensions) {
extensions = getdns_dict_create();
cleanup_extensions = 1;
}
getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6,
GETDNS_EXTENSION_TRUE);
getdns_return_t result =
getdns_general_sync(context, name, GETDNS_RRTYPE_A,
extensions, response_length, response);
if (cleanup_extensions) {
getdns_dict_destroy(extensions);
}
return result;
}
getdns_return_t
getdns_hostname_sync(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(address); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_service_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
)
{
return getdns_general_sync(context, name, GETDNS_RRTYPE_SRV, extensions,
response_length, response);
}
void
getdns_free_sync_request_memory(
struct getdns_dict *response
)
{ UNUSED_PARAM(response); }
/* getdns_core_sync.c */

View File

@ -1,5 +1,7 @@
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I/usr/local/include -I../common -std=c99
AM_LDFLAGS = -L../common -L/usr/local/lib -lgetdns
bin_PROGRAMS = tests_list tests_dict
AM_CPPFLAGS = -Wall -Werror -g -fPIC -I$(srcdir)/ -I/usr/local/include -I$(top_srcdir)/src -std=c99
AM_LDFLAGS =-L$(top_srcdir)/src -L/usr/local/lib -lgetdns -lldns -lpthread -levent
noinst_PROGRAMS = tests_list tests_dict tests_stub_async tests_stub_sync
tests_list_SOURCES = tests_list.c testmessages.c
tests_dict_SOURCES = tests_dict.c testmessages.c
tests_stub_async_SOURCES = tests_stub_async.c testmessages.c
tests_stub_sync_SOURCES = tests_stub_sync.c

View File

@ -30,7 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include "testmessages.h"
#include "getdns_core_only.h"
#include <getdns/getdns.h>
#define TSTMSGBUF 80

View File

@ -30,7 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include "testmessages.h"
#include "getdns_core_only.h"
#include <getdns/getdns.h>
#define TSTMSGBUF 80
@ -45,7 +45,7 @@ void
tst_bindatasetget(void)
{
char msg[TSTMSGBUF];
size_t index;
size_t index = 0;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_bindata *new_bindata = NULL;
@ -123,7 +123,7 @@ void
tst_dictsetget(void)
{
char msg[TSTMSGBUF];
size_t index;
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;
@ -199,7 +199,7 @@ void
tst_listsetget(void)
{
char msg[TSTMSGBUF];
size_t index;
size_t index = 0;
getdns_return_t retval;
uint32_t ans_int;
struct getdns_list *list = NULL;
@ -276,7 +276,7 @@ void
tst_intsetget(void)
{
char msg[TSTMSGBUF];
size_t index;
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;

113
src/test/tests_stub_async.c Normal file
View File

@ -0,0 +1,113 @@
/**
* \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
*/
/* 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.
*/
#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_t *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 */
{
getdns_bindata* bindata = NULL;
getdns_dict_get_bindata(this_response, "pkt", &bindata);
if (bindata) {
char* data = (char*) bindata->data;
data[bindata->size] = 0;
memcpy(data, bindata->data, bindata->size);
fprintf(stdout, "The packet %s\n", data);
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %lld was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
}
int
main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
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_resolution_type(this_context, GETDNS_CONTEXT_STUB);
/* 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.");
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 = "www.google.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,
NULL, 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);
return(GETDNS_RETURN_GENERIC_ERROR);
}
dns_request_return = getdns_service(this_context, this_name, NULL, 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);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
event_base_dispatch(this_event_base);
// TODO: check the return value above
}
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */
/* example-simple-answers.c */

View File

@ -0,0 +1,84 @@
/**
* \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
*/
/* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "testmessages.h"
#include <getdns/getdns.h>
static void print_response(getdns_dict* response) {
getdns_bindata* bindata = NULL;
getdns_dict_get_bindata(response, "pkt", &bindata);
if (bindata) {
char* data = (char*) bindata->data;
data[bindata->size] = 0;
memcpy(data, bindata->data, bindata->size);
fprintf(stdout, "The packet %s\n", data);
}
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
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_resolution_type(this_context, GETDNS_CONTEXT_STUB);
getdns_dict* response = NULL;
uint32_t responseLen = 0;
getdns_return_t ret = getdns_address_sync(this_context, "www.google.com", NULL, &responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Address sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
ret = getdns_service_sync(this_context, "www.google.com", NULL, &responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Service sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */
/* example-simple-answers.c */

141
src/types-internal.h Normal file
View File

@ -0,0 +1,141 @@
/**
*
* /brief getdns contect management 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.
*
* 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 TYPES_INTERNAL_H_
#define TYPES_INTERNAL_H_
#include "context.h"
#include <ldns/ldns.h>
/* declarations */
struct getdns_dns_req;
struct getdns_nameserver;
struct getdns_network_req;
typedef struct getdns_nameserver {
evutil_socket_t socket; /* a connected UDP socket */
struct sockaddr_storage address;
ev_socklen_t addrlen;
int failed_times; /* number of times which we have given this server a chance */
int timedout; /* number of times in a row a request has timed out */
struct event* event;
/* when we next probe this server. */
/* Valid if state == 0 */
/* Outstanding probe request for this nameserver, if any */
struct getdns_dns_req *probe_request;
char state; /* zero if we think that this server is down */
char choked; /* true if we have an EAGAIN from this server's socket */
char write_waiting; /* true if we are waiting for EV_WRITE events */
/* getdns context */
getdns_context_t context;
/* Number of currently inflight requests: used
* to track when we should add/del the event. */
int requests_inflight;
} getdns_nameserver;
/* network request - state for a single network request and referenced
* by the the outbound_req
*/
typedef struct getdns_network_req {
ldns_pkt *pkt; /* the dns packet data */
uint16_t request_type; /* query type */
int reissue_count;
int tx_count; /* the number of times that this packet has been sent */
/* not owned */
getdns_nameserver *ns; /* the server which we sent to */
unsigned transmit_me :1; /* needs to be transmitted */
getdns_context_t context;
struct getdns_dns_req *owner;
} getdns_network_req;
/* outbound request - manages recursion and stub reqs */
typedef struct getdns_dns_req {
struct getdns_network_req *current_req;
getdns_context_t context;
uint16_t resolver_type;
/* callback data */
getdns_callback_t user_callback;
void *user_pointer;
getdns_transaction_t trans_id; /* the transaction id */
int pending_cb; /* Waiting for its callback to be invoked; not
* owned by event base any more. */
/* search not supported.. yet */
} getdns_dns_req;
/* utility methods */
/* network request utilities */
void network_req_free(getdns_network_req* net_req);
getdns_network_req* network_req_new(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict* extensions);
/* dns request utils */
getdns_dns_req* dns_req_new(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict *extensions,
getdns_transaction_t *transaction_id);
void dns_req_free(getdns_dns_req* req);
/* nameserver utils */
getdns_nameserver* nameserver_new_from_ip_dict(getdns_context_t context,
getdns_dict* ip_dict);
void nameserver_free(getdns_nameserver* nameserver);
getdns_dict* nameserver_to_dict(getdns_nameserver* nameserver);
#endif

147
src/util-internal.c Normal file
View File

@ -0,0 +1,147 @@
/**
*
* /brief getdns contect management 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.
*
* 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.
*/
#include "util-internal.h"
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
char* value) {
/* account for the null term */
getdns_bindata type_bin = { strlen(value) + 1, (uint8_t*) value };
return getdns_dict_set_bindata(dict, name, &type_bin);
}
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
char** result) {
struct getdns_bindata *bindata = NULL;
if (!result) {
return GETDNS_RETURN_GENERIC_ERROR;
}
*result = NULL;
getdns_dict_get_bindata(dict, name, &bindata);
if (!bindata) {
return GETDNS_RETURN_GENERIC_ERROR;
}
*result = (char*) bindata->data;
return GETDNS_RETURN_GOOD;
}
getdns_return_t dict_to_sockaddr(getdns_dict* ns, struct sockaddr_storage* output) {
char* address_type = NULL;
struct getdns_bindata *address_data = NULL;
uint32_t port = 53;
memset(output, 0, sizeof(struct sockaddr_storage));
output->ss_family = AF_UNSPEC;
uint32_t prt = 0;
if (getdns_dict_get_int(ns, GETDNS_STR_PORT, &prt) == GETDNS_RETURN_GOOD) {
port = prt;
}
getdns_dict_util_get_string(ns, GETDNS_STR_ADDRESS_TYPE, &address_type);
getdns_dict_get_bindata(ns, GETDNS_STR_ADDRESS_DATA, &address_data);
if (!address_type || !address_data) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (strncmp(GETDNS_STR_IPV4, address_type, strlen(GETDNS_STR_IPV4)) == 0) {
/* data is an in_addr_t */
struct sockaddr_in* addr = (struct sockaddr_in*) output;
addr->sin_family = AF_INET;
addr->sin_port = htons((uint16_t)port);
memcpy(&(addr->sin_addr), address_data->data, address_data->size);
} else {
/* data is a v6 addr in host order */
struct sockaddr_in6* addr = (struct sockaddr_in6*) output;
addr->sin6_family = AF_INET6;
addr->sin6_port = htons((uint16_t)port);
memcpy(&(addr->sin6_addr), address_data->data, address_data->size);
}
return GETDNS_RETURN_GOOD;
}
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* address, getdns_dict** output) {
if (!output || !address) {
return GETDNS_RETURN_GENERIC_ERROR;
}
getdns_bindata addr_data;
*output = NULL;
getdns_dict* result = getdns_dict_create();
if (address->ss_family == AF_INET) {
struct sockaddr_in* addr = (struct sockaddr_in*) address;
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV4);
addr_data.size = sizeof(addr->sin_addr);
addr_data.data = (uint8_t*) &(addr->sin_addr);
getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA, &addr_data);
} else if (address->ss_family == AF_INET6) {
struct sockaddr_in6* addr = (struct sockaddr_in6*) address;
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV6);
addr_data.size = sizeof(addr->sin6_addr);
addr_data.data = (uint8_t*) &(addr->sin6_addr);
getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA, &addr_data);
} else {
// invalid
getdns_dict_destroy(result);
return GETDNS_RETURN_GENERIC_ERROR;
}
*output = result;
return GETDNS_RETURN_GOOD;
}
/* TODO: flags */
ldns_pkt *create_new_pkt(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict* extensions) {
ldns_pkt *pkt = NULL;
ldns_rr_type type = (ldns_rr_type) request_type;
uint16_t flags = 0;
if (context->resolution_type == GETDNS_CONTEXT_STUB) {
flags |= LDNS_RD;
}
ldns_pkt_query_new_frm_str(&pkt, name,
type,
LDNS_RR_CLASS_IN, flags);
if (pkt) {
/* id */
ldns_pkt_set_id(pkt, ldns_get_random());
}
return pkt;
}
getdns_dict *create_getdns_response(ldns_pkt* pkt) {
char* data = ldns_pkt2str(pkt);
getdns_dict* result = getdns_dict_create();
getdns_bindata bindata = {
strlen(data), (uint8_t*) data
};
getdns_dict_set_bindata(result, "pkt", &bindata);
free(data);
return result;
}

View File

@ -1,7 +1,7 @@
/**
*
* /brief getdns core functions
*
* /brief getdns contect management functions
*
* This is the meat of the API
* Originally taken from the getdns API description pseudo implementation.
*
@ -15,10 +15,10 @@
* 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
@ -28,33 +28,25 @@
* THE SOFTWARE.
*/
#include <getdns_core_only.h>
#include "types-internal.h"
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
/* convert an ip address dict to a sock storage */
getdns_return_t dict_to_sockaddr(getdns_dict* ns, struct sockaddr_storage* output);
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* sockaddr, getdns_dict** output);
/*
* getdns_address
*
*/
getdns_return_t
getdns_address(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(name);
UNUSED_PARAM(extensions);
UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id);
UNUSED_PARAM(callback);
return GETDNS_RETURN_GOOD;
} /* getdns_address */
/* create a dns packet for the given request type and extensions */
ldns_pkt *create_new_pkt(getdns_context_t context,
const char* name,
uint16_t request_type,
struct getdns_dict* extensions);
/* getdns_address.c */
getdns_dict *create_getdns_response(ldns_pkt* pkt);
/* dict util */
/* set a string as bindata */
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
char* value);
/* get a string from a dict. result is valid as long as dict is valid */
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
char** result);

View File

@ -28,7 +28,7 @@
* THE SOFTWARE.
*/
#include <getdns_core_only.h>
#include <getdns/getdns.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))