Ran indent with the indent.pro committed

This commit is contained in:
Neel Goyal 2013-11-05 15:03:44 -05:00
parent eb14f1212d
commit f8380ff862
30 changed files with 3842 additions and 3838 deletions

19
.indent.pro vendored Normal file
View File

@ -0,0 +1,19 @@
-bap
-br
-ce
-ci4
-cli0
-d0
-di0
-i8
-ip0
-l79
-nbc
-ncdb
-ndj
-nfc1
-nlp
-npcs
-psl
-sc
-sob

View File

@ -47,7 +47,9 @@
* Helper to get default lookup namespaces. * Helper to get default lookup namespaces.
* TODO: Determine from OS * TODO: Determine from OS
*/ */
static uint16_t* create_default_namespaces() { static uint16_t *
create_default_namespaces()
{
uint16_t *result = malloc(2 * sizeof(uint16_t)); uint16_t *result = malloc(2 * sizeof(uint16_t));
result[0] = GETDNS_CONTEXT_NAMESPACE_LOCALNAMES; result[0] = GETDNS_CONTEXT_NAMESPACE_LOCALNAMES;
result[1] = GETDNS_CONTEXT_NAMESPACE_DNS; result[1] = GETDNS_CONTEXT_NAMESPACE_DNS;
@ -58,11 +60,15 @@ static uint16_t* create_default_namespaces() {
* Helper to get the default root servers. * Helper to get the default root servers.
* TODO: Implement * TODO: Implement
*/ */
static struct getdns_list* create_default_root_servers() { static struct getdns_list *
create_default_root_servers()
{
return NULL; return NULL;
} }
static getdns_return_t add_ip_str(getdns_dict* ip) { static getdns_return_t
add_ip_str(getdns_dict * ip)
{
struct sockaddr_storage storage; struct sockaddr_storage storage;
char buff[256]; char buff[256];
getdns_return_t r = dict_to_sockaddr(ip, &storage); getdns_return_t r = dict_to_sockaddr(ip, &storage);
@ -70,19 +76,23 @@ static getdns_return_t add_ip_str(getdns_dict* ip) {
return r; return r;
} }
if (storage.ss_family == AF_INET) { if (storage.ss_family == AF_INET) {
struct sockaddr_in* addr = (struct sockaddr_in*) &storage; struct sockaddr_in *addr = (struct sockaddr_in *) &storage;
const char* ipStr = inet_ntop(AF_INET, &(addr->sin_addr), buff, 256); const char *ipStr =
inet_ntop(AF_INET, &(addr->sin_addr), buff, 256);
if (!ipStr) { if (!ipStr) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
getdns_dict_util_set_string(ip, GETDNS_STR_ADDRESS_STRING, ipStr); getdns_dict_util_set_string(ip, GETDNS_STR_ADDRESS_STRING,
ipStr);
} else if (storage.ss_family == AF_INET6) { } else if (storage.ss_family == AF_INET6) {
struct sockaddr_in6* addr = (struct sockaddr_in6*) &storage; struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &storage;
const char* ipStr = inet_ntop(AF_INET6, &(addr->sin6_addr), buff, 256); const char *ipStr =
inet_ntop(AF_INET6, &(addr->sin6_addr), buff, 256);
if (!ipStr) { if (!ipStr) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
getdns_dict_util_set_string(ip, GETDNS_STR_ADDRESS_STRING, ipStr); getdns_dict_util_set_string(ip, GETDNS_STR_ADDRESS_STRING,
ipStr);
} else { } else {
/* unknown */ /* unknown */
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
@ -90,15 +100,19 @@ static getdns_return_t add_ip_str(getdns_dict* ip) {
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
static struct getdns_dict* create_ipaddr_dict_from_rdf(ldns_rdf* rdf) { static struct getdns_dict *
create_ipaddr_dict_from_rdf(ldns_rdf * rdf)
{
ldns_rdf_type rt = ldns_rdf_get_type(rdf); ldns_rdf_type rt = ldns_rdf_get_type(rdf);
size_t sz = ldns_rdf_size(rdf); size_t sz = ldns_rdf_size(rdf);
getdns_dict *result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
/* set type */ /* set type */
if (rt == LDNS_RDF_TYPE_A) { if (rt == LDNS_RDF_TYPE_A) {
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV4); getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE,
GETDNS_STR_IPV4);
} else { } else {
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV6); getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE,
GETDNS_STR_IPV6);
} }
/* set data */ /* set data */
getdns_bindata data_bin = { sz, ldns_rdf_data(rdf) }; getdns_bindata data_bin = { sz, ldns_rdf_data(rdf) };
@ -107,17 +121,20 @@ static struct getdns_dict* create_ipaddr_dict_from_rdf(ldns_rdf* rdf) {
return result; return result;
} }
static struct getdns_list* create_from_ldns_list(ldns_rdf** ldns_list, size_t count) { static struct getdns_list *
create_from_ldns_list(ldns_rdf ** ldns_list, size_t count)
{
size_t i = 0; size_t i = 0;
size_t idx = 0; size_t idx = 0;
struct getdns_list *result = getdns_list_create(); struct getdns_list *result = getdns_list_create();
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
ldns_rdf* rdf = ldns_list[i]; ldns_rdf *rdf = ldns_list[i];
switch (ldns_rdf_get_type(rdf)) { switch (ldns_rdf_get_type(rdf)) {
case LDNS_RDF_TYPE_A: case LDNS_RDF_TYPE_A:
case LDNS_RDF_TYPE_AAAA: case LDNS_RDF_TYPE_AAAA:
{ {
getdns_dict *ipaddr = create_ipaddr_dict_from_rdf(rdf); getdns_dict *ipaddr =
create_ipaddr_dict_from_rdf(rdf);
getdns_list_add_item(result, &idx); getdns_list_add_item(result, &idx);
getdns_list_set_dict(result, idx, ipaddr); getdns_list_set_dict(result, idx, ipaddr);
getdns_dict_destroy(ipaddr); getdns_dict_destroy(ipaddr);
@ -127,9 +144,9 @@ static struct getdns_list* create_from_ldns_list(ldns_rdf** ldns_list, size_t co
case LDNS_RDF_TYPE_DNAME: case LDNS_RDF_TYPE_DNAME:
{ {
getdns_bindata item; getdns_bindata item;
char* srch = ldns_rdf2str(rdf); char *srch = ldns_rdf2str(rdf);
item.size = strlen(srch); item.size = strlen(srch);
item.data = (uint8_t*) srch; item.data = (uint8_t *) srch;
getdns_list_add_item(result, &idx); getdns_list_add_item(result, &idx);
getdns_list_set_bindata(result, idx, &item); getdns_list_set_bindata(result, idx, &item);
free(srch); free(srch);
@ -143,15 +160,18 @@ static struct getdns_list* create_from_ldns_list(ldns_rdf** ldns_list, size_t co
return result; return result;
} }
static getdns_return_t set_os_defaults(getdns_context_t context) { static getdns_return_t
set_os_defaults(getdns_context_t context)
{
ldns_resolver *lr = NULL; ldns_resolver *lr = NULL;
if (ldns_resolver_new_frm_file(&lr, NULL) != LDNS_STATUS_OK) { if (ldns_resolver_new_frm_file(&lr, NULL) != LDNS_STATUS_OK) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
ldns_rdf **rdf_list= ldns_resolver_nameservers(lr); ldns_rdf **rdf_list = ldns_resolver_nameservers(lr);
size_t rdf_list_sz = ldns_resolver_nameserver_count(lr); size_t rdf_list_sz = ldns_resolver_nameserver_count(lr);
if (rdf_list_sz > 0) { if (rdf_list_sz > 0) {
context->upstream_list = create_from_ldns_list(rdf_list, rdf_list_sz); context->upstream_list =
create_from_ldns_list(rdf_list, rdf_list_sz);
} }
rdf_list = ldns_resolver_searchlist(lr); rdf_list = ldns_resolver_searchlist(lr);
rdf_list_sz = ldns_resolver_searchlist_count(lr); rdf_list_sz = ldns_resolver_searchlist_count(lr);
@ -163,7 +183,9 @@ static getdns_return_t set_os_defaults(getdns_context_t context) {
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
static int transaction_id_cmp(const void* id1, const void* id2) { static int
transaction_id_cmp(const void *id1, const void *id2)
{
if (id1 == NULL && id2 == NULL) { if (id1 == NULL && id2 == NULL) {
return 0; return 0;
} else if (id1 == NULL && id2 != NULL) { } else if (id1 == NULL && id2 != NULL) {
@ -171,8 +193,10 @@ static int transaction_id_cmp(const void* id1, const void* id2) {
} else if (id1 != NULL && id2 == NULL) { } else if (id1 != NULL && id2 == NULL) {
return -1; return -1;
} else { } else {
getdns_transaction_t t1 = *((const getdns_transaction_t*) id1); getdns_transaction_t t1 =
getdns_transaction_t t2 = *((const getdns_transaction_t*) id2); *((const getdns_transaction_t *) id1);
getdns_transaction_t t2 =
*((const getdns_transaction_t *) id2);
if (t1 == t2) { if (t1 == t2) {
return 0; return 0;
} else if (t1 < t2) { } else if (t1 < t2) {
@ -188,10 +212,8 @@ static int transaction_id_cmp(const void* id1, const void* id2) {
* *
* call this to initialize the context that is used in other getdns calls * call this to initialize the context that is used in other getdns calls
*/ */
getdns_return_t getdns_context_create( getdns_return_t
getdns_context_t *context, getdns_context_create(getdns_context_t * context, int set_from_os)
int set_from_os
)
{ {
getdns_context_t result = NULL; getdns_context_t result = NULL;
@ -248,8 +270,8 @@ getdns_return_t getdns_context_create(
/* other opts */ /* other opts */
getdns_context_set_dnssec_allowed_skew(result, 0); getdns_context_set_dnssec_allowed_skew(result, 0);
getdns_context_set_edns_maximum_udp_payload_size(result, 512); getdns_context_set_edns_maximum_udp_payload_size(result, 512);
getdns_context_set_dns_transport(result, GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP); getdns_context_set_dns_transport(result,
GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} /* getdns_context_create */ } /* getdns_context_create */
@ -261,9 +283,7 @@ getdns_return_t getdns_context_create(
* are done with it * are done with it
*/ */
void void
getdns_context_destroy( getdns_context_destroy(getdns_context_t context)
getdns_context_t context
)
{ {
if (context == NULL) { if (context == NULL) {
return; return;
@ -293,10 +313,9 @@ getdns_context_destroy(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_context_update_callback( getdns_context_set_context_update_callback(getdns_context_t context,
getdns_context_t context, void (*value) (getdns_context_t context, uint16_t changed_item)
void (*value)(getdns_context_t context, uint16_t changed_item) )
)
{ {
context->update_callback = value; context->update_callback = value;
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
@ -306,12 +325,16 @@ getdns_context_set_context_update_callback(
* Helpers to set options on the unbound ctx * Helpers to set options on the unbound ctx
*/ */
static void set_ub_string_opt(getdns_context_t ctx, char* opt, char* value) { static void
set_ub_string_opt(getdns_context_t ctx, char *opt, char *value)
{
ub_ctx_set_option(ctx->unbound_sync, opt, value); ub_ctx_set_option(ctx->unbound_sync, opt, value);
ub_ctx_set_option(ctx->unbound_async, opt, value); ub_ctx_set_option(ctx->unbound_async, opt, value);
} }
static void set_ub_number_opt(getdns_context_t ctx, char* opt, uint16_t value) { static void
set_ub_number_opt(getdns_context_t ctx, char *opt, uint16_t value)
{
char buffer[64]; char buffer[64];
snprintf(buffer, 64, "%hu", value); snprintf(buffer, 64, "%hu", value);
set_ub_string_opt(ctx, opt, buffer); set_ub_string_opt(ctx, opt, buffer);
@ -320,7 +343,9 @@ static void set_ub_number_opt(getdns_context_t ctx, char* opt, uint16_t value) {
/* /*
* Clear the resolution type set flag if needed * Clear the resolution type set flag if needed
*/ */
static inline void clear_resolution_type_set_flag(getdns_context_t context, uint16_t type) { static inline void
clear_resolution_type_set_flag(getdns_context_t context, uint16_t type)
{
if (context->resolution_type_set == type) { if (context->resolution_type_set == type) {
context->resolution_type_set = 0; context->resolution_type_set = 0;
} }
@ -331,10 +356,7 @@ static inline void clear_resolution_type_set_flag(getdns_context_t context, uint
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_context_update( getdns_context_set_context_update(getdns_context_t context, uint16_t value)
getdns_context_t context,
uint16_t value
)
{ {
UNUSED_PARAM(context); UNUSED_PARAM(context);
UNUSED_PARAM(value); UNUSED_PARAM(value);
@ -344,8 +366,9 @@ getdns_context_set_context_update(
/** /**
* Helper to dispatch the updated callback * Helper to dispatch the updated callback
*/ */
static void dispatch_updated(getdns_context_t context, static void
uint16_t item) { dispatch_updated(getdns_context_t context, uint16_t item)
{
if (context->update_callback) { if (context->update_callback) {
context->update_callback(context, item); context->update_callback(context, item);
} }
@ -356,13 +379,9 @@ static void dispatch_updated(getdns_context_t context,
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_resolution_type( getdns_context_set_resolution_type(getdns_context_t context, uint16_t value)
getdns_context_t context,
uint16_t value
)
{ {
if (value != GETDNS_CONTEXT_STUB && if (value != GETDNS_CONTEXT_STUB && value != GETDNS_CONTEXT_RECURSING) {
value != GETDNS_CONTEXT_RECURSING) {
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL; return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} }
@ -378,11 +397,8 @@ getdns_context_set_resolution_type(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_namespaces( getdns_context_set_namespaces(getdns_context_t context,
getdns_context_t context, size_t namespace_count, uint16_t * namespaces)
size_t namespace_count,
uint16_t *namespaces
)
{ {
size_t namespaces_size; size_t namespaces_size;
if (namespace_count == 0 || namespaces == NULL) { if (namespace_count == 0 || namespaces == NULL) {
@ -407,10 +423,7 @@ getdns_context_set_namespaces(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_dns_transport( getdns_context_set_dns_transport(getdns_context_t context, uint16_t value)
getdns_context_t context,
uint16_t value
)
{ {
switch (value) { switch (value) {
@ -441,15 +454,14 @@ getdns_context_set_dns_transport(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_limit_outstanding_queries( getdns_context_set_limit_outstanding_queries(getdns_context_t context,
getdns_context_t context, uint16_t limit)
uint16_t limit
)
{ {
/* num-queries-per-thread */ /* num-queries-per-thread */
set_ub_number_opt(context, "num-queries-per-thread", limit); set_ub_number_opt(context, "num-queries-per-thread", limit);
dispatch_updated(context, GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES); dispatch_updated(context,
GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} /* getdns_context_set_limit_outstanding_queries */ } /* getdns_context_set_limit_outstanding_queries */
@ -459,10 +471,7 @@ getdns_context_set_limit_outstanding_queries(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_timeout( getdns_context_set_timeout(getdns_context_t context, uint16_t timeout)
getdns_context_t context,
uint16_t timeout
)
{ {
context->timeout = timeout; context->timeout = timeout;
@ -476,10 +485,7 @@ getdns_context_set_timeout(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_follow_redirects( getdns_context_set_follow_redirects(getdns_context_t context, uint16_t value)
getdns_context_t context,
uint16_t value
)
{ {
context->follow_redirects = value; context->follow_redirects = value;
@ -494,10 +500,8 @@ getdns_context_set_follow_redirects(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_dns_root_servers( getdns_context_set_dns_root_servers(getdns_context_t context,
getdns_context_t context, struct getdns_list * addresses)
struct getdns_list *addresses
)
{ {
getdns_list *copy = NULL; getdns_list *copy = NULL;
size_t count = 0; size_t count = 0;
@ -515,7 +519,7 @@ getdns_context_set_dns_root_servers(
getdns_return_t r = GETDNS_RETURN_GOOD; getdns_return_t r = GETDNS_RETURN_GOOD;
/* validate and add ip str */ /* validate and add ip str */
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
getdns_dict* dict = NULL; getdns_dict *dict = NULL;
getdns_list_get_dict(addresses, i, &dict); getdns_list_get_dict(addresses, i, &dict);
r = add_ip_str(dict); r = add_ip_str(dict);
if (r != GETDNS_RETURN_GOOD) { if (r != GETDNS_RETURN_GOOD) {
@ -544,15 +548,14 @@ getdns_context_set_dns_root_servers(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_append_name( getdns_context_set_append_name(getdns_context_t context, uint16_t value)
getdns_context_t context,
uint16_t value
)
{ {
if (value != GETDNS_CONTEXT_APPEND_NAME_ALWAYS && if (value != GETDNS_CONTEXT_APPEND_NAME_ALWAYS &&
value != GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE && value !=
value != GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE && GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE
value != GETDNS_CONTEXT_DO_NOT_APPEND_NAMES) { && 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; return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} }
@ -568,10 +571,7 @@ getdns_context_set_append_name(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_suffix( getdns_context_set_suffix(getdns_context_t context, struct getdns_list * value)
getdns_context_t context,
struct getdns_list *value
)
{ {
getdns_list *copy = NULL; getdns_list *copy = NULL;
if (value != NULL) { if (value != NULL) {
@ -595,10 +595,8 @@ getdns_context_set_suffix(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_dnssec_trust_anchors( getdns_context_set_dnssec_trust_anchors(getdns_context_t context,
getdns_context_t context, struct getdns_list * value)
struct getdns_list *value
)
{ {
getdns_list *copy = NULL; getdns_list *copy = NULL;
if (value != NULL) { if (value != NULL) {
@ -620,10 +618,8 @@ getdns_context_set_dnssec_trust_anchors(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_dnssec_allowed_skew( getdns_context_set_dnssec_allowed_skew(getdns_context_t context,
getdns_context_t context, uint16_t value)
uint16_t value
)
{ {
set_ub_number_opt(context, "val-sig-skew-min", value); set_ub_number_opt(context, "val-sig-skew-min", value);
set_ub_number_opt(context, "val-sig-skew-max", value); set_ub_number_opt(context, "val-sig-skew-max", value);
@ -637,10 +633,8 @@ getdns_context_set_dnssec_allowed_skew(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_stub_resolution( getdns_context_set_stub_resolution(getdns_context_t context,
getdns_context_t context, struct getdns_list * upstream_list)
struct getdns_list *upstream_list
)
{ {
size_t count = 0; size_t count = 0;
size_t i = 0; size_t i = 0;
@ -655,7 +649,7 @@ getdns_context_set_stub_resolution(
upstream_list = copy; upstream_list = copy;
/* validate and add ip str */ /* validate and add ip str */
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
getdns_dict* dict = NULL; getdns_dict *dict = NULL;
getdns_list_get_dict(upstream_list, i, &dict); getdns_list_get_dict(upstream_list, i, &dict);
r = add_ip_str(dict); r = add_ip_str(dict);
if (r != GETDNS_RETURN_GOOD) { if (r != GETDNS_RETURN_GOOD) {
@ -673,7 +667,8 @@ getdns_context_set_stub_resolution(
clear_resolution_type_set_flag(context, GETDNS_CONTEXT_STUB); clear_resolution_type_set_flag(context, GETDNS_CONTEXT_STUB);
dispatch_updated(context, GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS); dispatch_updated(context,
GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} /* getdns_context_set_stub_resolution */ } /* getdns_context_set_stub_resolution */
@ -683,10 +678,8 @@ getdns_context_set_stub_resolution(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size( getdns_context_set_edns_maximum_udp_payload_size(getdns_context_t context,
getdns_context_t context, uint16_t value)
uint16_t value
)
{ {
/* check for < 512. uint16_t won't let it go above max) */ /* check for < 512. uint16_t won't let it go above max) */
if (value < 512) { if (value < 512) {
@ -696,7 +689,8 @@ getdns_context_set_edns_maximum_udp_payload_size(
/* max-udp-size */ /* max-udp-size */
set_ub_number_opt(context, "max-udp-size", value); set_ub_number_opt(context, "max-udp-size", value);
dispatch_updated(context, GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE); dispatch_updated(context,
GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} /* getdns_context_set_edns_maximum_udp_payload_size */ } /* getdns_context_set_edns_maximum_udp_payload_size */
@ -706,10 +700,7 @@ getdns_context_set_edns_maximum_udp_payload_size(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_edns_extended_rcode( getdns_context_set_edns_extended_rcode(getdns_context_t context, uint8_t value)
getdns_context_t context,
uint8_t value
)
{ {
context->edns_extended_rcode = value; context->edns_extended_rcode = value;
@ -723,10 +714,7 @@ getdns_context_set_edns_extended_rcode(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_edns_version( getdns_context_set_edns_version(getdns_context_t context, uint8_t value)
getdns_context_t context,
uint8_t value
)
{ {
context->edns_version = value; context->edns_version = value;
@ -740,10 +728,7 @@ getdns_context_set_edns_version(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_edns_do_bit( getdns_context_set_edns_do_bit(getdns_context_t context, uint8_t value)
getdns_context_t context,
uint8_t value
)
{ {
/* 0 or 1 */ /* 0 or 1 */
if (value > 1) { if (value > 1) {
@ -762,10 +747,9 @@ getdns_context_set_edns_do_bit(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_memory_allocator( getdns_context_set_memory_allocator(getdns_context_t context,
getdns_context_t context, void (*value) (size_t somesize)
void (*value)(size_t somesize) )
)
{ {
UNUSED_PARAM(context); UNUSED_PARAM(context);
UNUSED_PARAM(value); UNUSED_PARAM(value);
@ -777,10 +761,9 @@ getdns_context_set_memory_allocator(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_memory_deallocator( getdns_context_set_memory_deallocator(getdns_context_t context,
getdns_context_t context, void (*value) (void *)
void (*value)(void*) )
)
{ {
UNUSED_PARAM(context); UNUSED_PARAM(context);
UNUSED_PARAM(value); UNUSED_PARAM(value);
@ -792,10 +775,9 @@ getdns_context_set_memory_deallocator(
* *
*/ */
getdns_return_t getdns_return_t
getdns_context_set_memory_reallocator( getdns_context_set_memory_reallocator(getdns_context_t context,
getdns_context_t context, void (*value) (void *)
void (*value)(void*) )
)
{ {
UNUSED_PARAM(context); UNUSED_PARAM(context);
UNUSED_PARAM(value); UNUSED_PARAM(value);
@ -807,24 +789,25 @@ getdns_context_set_memory_reallocator(
* *
*/ */
getdns_return_t getdns_return_t
getdns_extension_set_libevent_base( getdns_extension_set_libevent_base(getdns_context_t context,
getdns_context_t context, struct event_base * this_event_base)
struct event_base *this_event_base
)
{ {
if (this_event_base) { if (this_event_base) {
ub_ctx_set_event(context->unbound_async, this_event_base); ub_ctx_set_event(context->unbound_async, this_event_base);
context->event_base_async = this_event_base; context->event_base_async = this_event_base;
} else { } else {
ub_ctx_set_event(context->unbound_async, context->event_base_sync); ub_ctx_set_event(context->unbound_async,
context->event_base_sync);
context->event_base_async = NULL; context->event_base_async = NULL;
} }
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} /* getdns_extension_set_libevent_base */ } /* getdns_extension_set_libevent_base */
/* cancel the request */ /* cancel the request */
static void cancel_dns_req(getdns_dns_req* req) { static void
getdns_network_req* netreq = req->first_req; cancel_dns_req(getdns_dns_req * req)
{
getdns_network_req *netreq = req->first_req;
while (netreq) { while (netreq) {
if (netreq->state == NET_REQ_IN_FLIGHT) { if (netreq->state == NET_REQ_IN_FLIGHT) {
/* for ev based ub, this should always prevent /* for ev based ub, this should always prevent
@ -839,26 +822,27 @@ static void cancel_dns_req(getdns_dns_req* req) {
req->canceled = 1; req->canceled = 1;
} }
getdns_return_t getdns_context_cancel_request(getdns_context_t context, getdns_return_t
getdns_transaction_t transaction_id, getdns_context_cancel_request(getdns_context_t context,
int fire_callback) { getdns_transaction_t transaction_id, int fire_callback)
{
getdns_dns_req *req = NULL; getdns_dns_req *req = NULL;
/* delete the node from the tree */ /* delete the node from the tree */
ldns_rbnode_t* node = ldns_rbtree_delete(context->outbound_requests, ldns_rbnode_t *node = ldns_rbtree_delete(context->outbound_requests,
&transaction_id); &transaction_id);
if (!node) { if (!node) {
return GETDNS_RETURN_UNKNOWN_TRANSACTION; return GETDNS_RETURN_UNKNOWN_TRANSACTION;
} }
req = (getdns_dns_req*) node->data; req = (getdns_dns_req *) node->data;
/* do the cancel */ /* do the cancel */
cancel_dns_req(req); cancel_dns_req(req);
if (fire_callback) { if (fire_callback) {
getdns_callback_t cb = NULL; getdns_callback_t cb = NULL;
void* user_pointer = NULL; void *user_pointer = NULL;
cb = req->user_callback; cb = req->user_callback;
user_pointer = req->user_pointer; user_pointer = req->user_pointer;
@ -870,9 +854,7 @@ getdns_return_t getdns_context_cancel_request(getdns_context_t context,
/* fire callback */ /* fire callback */
cb(context, cb(context,
GETDNS_CALLBACK_CANCEL, GETDNS_CALLBACK_CANCEL,
NULL, NULL, user_pointer, transaction_id);
user_pointer,
transaction_id);
} }
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
@ -882,28 +864,31 @@ getdns_return_t getdns_context_cancel_request(getdns_context_t context,
* *
*/ */
getdns_return_t getdns_return_t
getdns_cancel_callback( getdns_cancel_callback(getdns_context_t context,
getdns_context_t context, getdns_transaction_t transaction_id)
getdns_transaction_t transaction_id
)
{ {
return getdns_context_cancel_request(context, transaction_id, 1); return getdns_context_cancel_request(context, transaction_id, 1);
} /* getdns_cancel_callback */ } /* getdns_cancel_callback */
static void ub_setup_stub(struct ub_ctx* ctx, getdns_list* upstreams, size_t count) { static void
ub_setup_stub(struct ub_ctx *ctx, getdns_list * upstreams, size_t count)
{
size_t i; size_t i;
/* reset forwarding servers */ /* reset forwarding servers */
ub_ctx_set_fwd(ctx, NULL); ub_ctx_set_fwd(ctx, NULL);
for (i = 0 ; i < count; ++i) { for (i = 0; i < count; ++i) {
getdns_dict* dict = NULL; getdns_dict *dict = NULL;
char* ip_str = NULL; char *ip_str = NULL;
getdns_list_get_dict(upstreams, i, &dict); getdns_list_get_dict(upstreams, i, &dict);
getdns_dict_util_get_string(dict, GETDNS_STR_ADDRESS_STRING, &ip_str); getdns_dict_util_get_string(dict, GETDNS_STR_ADDRESS_STRING,
&ip_str);
ub_ctx_set_fwd(ctx, ip_str); ub_ctx_set_fwd(ctx, ip_str);
} }
} }
getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context) { getdns_return_t
getdns_context_prepare_for_resolution(getdns_context_t context)
{
if (context->resolution_type_set == context->resolution_type) { if (context->resolution_type_set == context->resolution_type) {
/* already set and no config changes have caused this to be /* already set and no config changes have caused this to be
* bad. * bad.
@ -912,13 +897,17 @@ getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context)
} }
if (context->resolution_type == GETDNS_CONTEXT_STUB) { if (context->resolution_type == GETDNS_CONTEXT_STUB) {
size_t upstream_len = 0; size_t upstream_len = 0;
getdns_return_t r = getdns_list_get_length(context->upstream_list, &upstream_len); getdns_return_t r =
getdns_list_get_length(context->upstream_list,
&upstream_len);
if (r != GETDNS_RETURN_GOOD || upstream_len == 0) { if (r != GETDNS_RETURN_GOOD || upstream_len == 0) {
return GETDNS_RETURN_BAD_CONTEXT; return GETDNS_RETURN_BAD_CONTEXT;
} }
/* set upstreams */ /* set upstreams */
ub_setup_stub(context->unbound_async, context->upstream_list, upstream_len); ub_setup_stub(context->unbound_async, context->upstream_list,
ub_setup_stub(context->unbound_sync, context->upstream_list, upstream_len); upstream_len);
ub_setup_stub(context->unbound_sync, context->upstream_list,
upstream_len);
/* use /etc/hosts */ /* use /etc/hosts */
ub_ctx_hosts(context->unbound_sync, NULL); ub_ctx_hosts(context->unbound_sync, NULL);
ub_ctx_hosts(context->unbound_async, NULL); ub_ctx_hosts(context->unbound_async, NULL);
@ -937,12 +926,14 @@ getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context)
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
getdns_return_t getdns_context_track_outbound_request(getdns_dns_req* req) { getdns_return_t
getdns_context_track_outbound_request(getdns_dns_req * req)
{
if (!req) { if (!req) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
getdns_context_t context = req->context; getdns_context_t context = req->context;
ldns_rbnode_t* node = context->memory_allocator(sizeof(ldns_rbnode_t)); ldns_rbnode_t *node = context->memory_allocator(sizeof(ldns_rbnode_t));
if (!node) { if (!node) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
@ -956,12 +947,14 @@ getdns_return_t getdns_context_track_outbound_request(getdns_dns_req* req) {
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
getdns_return_t getdns_context_clear_outbound_request(getdns_dns_req* req) { getdns_return_t
getdns_context_clear_outbound_request(getdns_dns_req * req)
{
if (!req) { if (!req) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
getdns_context_t context = req->context; getdns_context_t context = req->context;
ldns_rbnode_t* node = ldns_rbtree_delete(context->outbound_requests, ldns_rbnode_t *node = ldns_rbtree_delete(context->outbound_requests,
&(req->trans_id)); &(req->trans_id));
if (node) { if (node) {
context->memory_deallocator(node); context->memory_deallocator(node);

View File

@ -38,12 +38,14 @@ struct ldns_rbtree_t;
struct getdns_dns_req; struct getdns_dns_req;
/** function pointer typedefs */ /** function pointer typedefs */
typedef void (*getdns_update_callback)(getdns_context_t context, uint16_t changed_item); typedef void (*getdns_update_callback) (getdns_context_t context,
typedef void* (*getdns_memory_allocator)(size_t size); uint16_t changed_item);
typedef void (*getdns_memory_deallocator)(void*); typedef void *(*getdns_memory_allocator) (size_t size);
typedef void* (*getdns_memory_reallocator)(void* ptr, size_t size); typedef void (*getdns_memory_deallocator) (void *);
typedef void *(*getdns_memory_reallocator) (void *ptr, size_t size);
struct getdns_context_t { struct getdns_context_t
{
/* Context values */ /* Context values */
uint16_t resolution_type; uint16_t resolution_type;
@ -66,12 +68,12 @@ struct getdns_context_t {
getdns_memory_reallocator memory_reallocator; getdns_memory_reallocator memory_reallocator;
/* Event loop for sync requests */ /* Event loop for sync requests */
struct event_base* event_base_sync; struct event_base *event_base_sync;
/* Event loop for async requests */ /* Event loop for async requests */
struct event_base* event_base_async; struct event_base *event_base_async;
/* The underlying unbound contexts that do /* The underlying unbound contexts that do
the real work */ * the real work */
struct ub_ctx *unbound_sync; struct ub_ctx *unbound_sync;
struct ub_ctx *unbound_async; struct ub_ctx *unbound_async;
@ -83,24 +85,25 @@ struct getdns_context_t {
/* /*
* outbound requests -> transaction to getdns_dns_req * outbound requests -> transaction to getdns_dns_req
*/ */
struct ldns_rbtree_t* outbound_requests; struct ldns_rbtree_t *outbound_requests;
} ; };
/** internal functions **/ /** internal functions **/
/** /**
* Sets up the unbound contexts with stub or recursive behavior * Sets up the unbound contexts with stub or recursive behavior
* if needed. * if needed.
*/ */
getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t context); getdns_return_t getdns_context_prepare_for_resolution(getdns_context_t
context);
/* track an outbound request */ /* track an outbound request */
getdns_return_t getdns_context_track_outbound_request(struct getdns_dns_req* req); getdns_return_t getdns_context_track_outbound_request(struct getdns_dns_req
*req);
/* clear the outbound request from being tracked - does not cancel it */ /* clear the outbound request from being tracked - does not cancel it */
getdns_return_t getdns_context_clear_outbound_request(struct getdns_dns_req* req); getdns_return_t getdns_context_clear_outbound_request(struct getdns_dns_req
*req);
/* cancel callback internal - flag to indicate if req should be freed and callback fired */ /* cancel callback internal - flag to indicate if req should be freed and callback fired */
getdns_return_t getdns_context_cancel_request(getdns_context_t context, getdns_return_t getdns_context_cancel_request(getdns_context_t context,
getdns_transaction_t transaction_id, getdns_transaction_t transaction_id, int fire_callback);
int fire_callback);
#endif #endif

View File

@ -38,33 +38,36 @@
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
char * char *
getdns_convert_dns_name_to_fqdn( getdns_convert_dns_name_to_fqdn(char *name_from_dns_response)
char *name_from_dns_response {
) UNUSED_PARAM(name_from_dns_response);
{ UNUSED_PARAM(name_from_dns_response); return NULL; } return NULL;
}
char * char *
getdns_convert_fqdn_to_dns_name( getdns_convert_fqdn_to_dns_name(char *fqdn_as_string)
char *fqdn_as_string {
) UNUSED_PARAM(fqdn_as_string);
{ UNUSED_PARAM(fqdn_as_string); return NULL; } return NULL;
}
char * char *
getdns_convert_ulabel_to_alabel( getdns_convert_ulabel_to_alabel(char *ulabel)
char *ulabel {
) UNUSED_PARAM(ulabel);
{ UNUSED_PARAM(ulabel); return NULL; } return NULL;
}
char * char *
getdns_convert_alabel_to_ulabel( getdns_convert_alabel_to_ulabel(char *alabel)
char *alabel {
) UNUSED_PARAM(alabel);
{ UNUSED_PARAM(alabel); return NULL; } return NULL;
}
char * char *
getdns_display_ip_address( getdns_display_ip_address(struct getdns_bindata
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address *bindata_of_ipv4_or_ipv6_address)
)
{ {
char buff[256]; char buff[256];
if (!bindata_of_ipv4_or_ipv6_address || if (!bindata_of_ipv4_or_ipv6_address ||
@ -73,7 +76,7 @@ getdns_display_ip_address(
return NULL; return NULL;
} }
if (bindata_of_ipv4_or_ipv6_address->size == 4) { if (bindata_of_ipv4_or_ipv6_address->size == 4) {
const char* ipStr = inet_ntop(AF_INET, const char *ipStr = inet_ntop(AF_INET,
bindata_of_ipv4_or_ipv6_address->data, bindata_of_ipv4_or_ipv6_address->data,
buff, buff,
256); 256);
@ -81,7 +84,7 @@ getdns_display_ip_address(
return strdup(ipStr); return strdup(ipStr);
} }
} else if (bindata_of_ipv4_or_ipv6_address->size == 16) { } else if (bindata_of_ipv4_or_ipv6_address->size == 16) {
const char* ipStr = inet_ntop(AF_INET6, const char *ipStr = inet_ntop(AF_INET6,
bindata_of_ipv4_or_ipv6_address->data, bindata_of_ipv4_or_ipv6_address->data,
buff, buff,
256); 256);
@ -97,7 +100,7 @@ getdns_strerror(getdns_return_t err, char *buf, size_t buflen)
{ {
getdns_return_t retval = GETDNS_RETURN_GOOD; getdns_return_t retval = GETDNS_RETURN_GOOD;
const char* err_str = getdns_get_errorstr_by_id(err); const char *err_str = getdns_get_errorstr_by_id(err);
if (!err_str) { if (!err_str) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }

View File

@ -53,17 +53,20 @@ getdns_dict_find(struct getdns_dict *dict, char *key, bool addifnotfnd)
{ {
struct getdns_dict_item *item = NULL; struct getdns_dict_item *item = NULL;
if(dict != NULL && key != NULL) if (dict != NULL && key != NULL) {
{ item =
item = (struct getdns_dict_item *)ldns_rbtree_search(&(dict->root), key); (struct getdns_dict_item *) ldns_rbtree_search(&(dict->
if(addifnotfnd == true && item == NULL) root), key);
{ if (addifnotfnd == true && item == NULL) {
/* tsearch will add a node automatically for us */ /* tsearch will add a node automatically for us */
item = (struct getdns_dict_item *) malloc(sizeof(struct getdns_dict_item)); item =
(struct getdns_dict_item *) malloc(sizeof(struct
getdns_dict_item));
item->node.key = strdup(key); item->node.key = strdup(key);
item->dtype = t_invalid; item->dtype = t_invalid;
item->data.n = 0; item->data.n = 0;
ldns_rbtree_insert(&(dict->root), (ldns_rbnode_t *)item); ldns_rbtree_insert(&(dict->root),
(ldns_rbnode_t *) item);
} }
} }
return item; return item;
@ -72,24 +75,24 @@ getdns_dict_find(struct getdns_dict *dict, char *key, bool addifnotfnd)
/*---------------------------------------- getdns_dict_get_names /*---------------------------------------- getdns_dict_get_names
*/ */
getdns_return_t getdns_return_t
getdns_dict_get_names(struct getdns_dict *dict, struct getdns_list **answer) getdns_dict_get_names(struct getdns_dict * dict, struct getdns_list ** answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
struct getdns_dict_item *item; struct getdns_dict_item *item;
size_t index; size_t index;
if(dict != NULL && answer != NULL) if (dict != NULL && answer != NULL) {
{
*answer = getdns_list_create(); *answer = getdns_list_create();
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root)) LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root))
{ {
if(getdns_list_add_item(*answer, &index) == GETDNS_RETURN_GOOD) if (getdns_list_add_item(*answer,
{ &index) == GETDNS_RETURN_GOOD) {
struct getdns_bindata bindata; struct getdns_bindata bindata;
bindata.size = strlen(item->node.key); bindata.size = strlen(item->node.key);
bindata.data = (void *)item->node.key; bindata.data = (void *) item->node.key;
getdns_list_set_bindata(*answer, index, &bindata); getdns_list_set_bindata(*answer, index,
&bindata);
} }
} }
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
@ -99,16 +102,15 @@ getdns_dict_get_names(struct getdns_dict *dict, struct getdns_list **answer)
/*---------------------------------------- getdns_dict_get_data_type */ /*---------------------------------------- getdns_dict_get_data_type */
getdns_return_t getdns_return_t
getdns_dict_get_data_type(struct getdns_dict *dict, char *name, getdns_data_type *answer) getdns_dict_get_data_type(struct getdns_dict * dict, char *name,
getdns_data_type * answer)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && answer != NULL) if (dict != NULL && name != NULL && answer != NULL) {
{
item = getdns_dict_find(dict, name, false); item = getdns_dict_find(dict, name, false);
if(item != NULL) if (item != NULL) {
{
*answer = item->dtype; *answer = item->dtype;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -119,20 +121,18 @@ getdns_dict_get_data_type(struct getdns_dict *dict, char *name, getdns_data_type
/*---------------------------------------- getdns_dict_get_dict */ /*---------------------------------------- getdns_dict_get_dict */
getdns_return_t getdns_return_t
getdns_dict_get_dict(struct getdns_dict *dict, char *name, struct getdns_dict **answer) getdns_dict_get_dict(struct getdns_dict * dict, char *name,
struct getdns_dict ** answer)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && answer != NULL) if (dict != NULL && name != NULL && answer != NULL) {
{
item = getdns_dict_find(dict, name, false); item = getdns_dict_find(dict, name, false);
if(item != NULL) if (item != NULL) {
{ if (item->dtype != t_dict)
if(item->dtype != t_dict)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = item->data.dict; *answer = item->data.dict;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -144,20 +144,18 @@ getdns_dict_get_dict(struct getdns_dict *dict, char *name, struct getdns_dict **
/*---------------------------------------- getdns_dict_get_list */ /*---------------------------------------- getdns_dict_get_list */
getdns_return_t getdns_return_t
getdns_dict_get_list(struct getdns_dict *dict, char *name, struct getdns_list **answer) getdns_dict_get_list(struct getdns_dict * dict, char *name,
struct getdns_list ** answer)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && answer != NULL) if (dict != NULL && name != NULL && answer != NULL) {
{
item = getdns_dict_find(dict, name, false); item = getdns_dict_find(dict, name, false);
if(item != NULL) if (item != NULL) {
{ if (item->dtype != t_list)
if(item->dtype != t_list)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = item->data.list; *answer = item->data.list;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -169,20 +167,18 @@ getdns_dict_get_list(struct getdns_dict *dict, char *name, struct getdns_list **
/*---------------------------------------- getdns_dict_get_bindata */ /*---------------------------------------- getdns_dict_get_bindata */
getdns_return_t getdns_return_t
getdns_dict_get_bindata(struct getdns_dict *dict, char *name, struct getdns_bindata **answer) getdns_dict_get_bindata(struct getdns_dict * dict, char *name,
struct getdns_bindata ** answer)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && answer != NULL) if (dict != NULL && name != NULL && answer != NULL) {
{
item = getdns_dict_find(dict, name, false); item = getdns_dict_find(dict, name, false);
if(item != NULL) if (item != NULL) {
{ if (item->dtype != t_bindata)
if(item->dtype != t_bindata)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = item->data.bindata; *answer = item->data.bindata;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -194,20 +190,17 @@ getdns_dict_get_bindata(struct getdns_dict *dict, char *name, struct getdns_bind
/*---------------------------------------- getdns_dict_get_int */ /*---------------------------------------- getdns_dict_get_int */
getdns_return_t getdns_return_t
getdns_dict_get_int(struct getdns_dict *dict, char *name, uint32_t *answer) getdns_dict_get_int(struct getdns_dict * dict, char *name, uint32_t * answer)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && answer != NULL) if (dict != NULL && name != NULL && answer != NULL) {
{
item = getdns_dict_find(dict, name, false); item = getdns_dict_find(dict, name, false);
if(item != NULL) if (item != NULL) {
{ if (item->dtype != t_int)
if(item->dtype != t_int)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = item->data.n; *answer = item->data.n;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -224,7 +217,8 @@ getdns_dict_create()
struct getdns_dict *dict; struct getdns_dict *dict;
dict = (struct getdns_dict *) malloc(sizeof(struct getdns_dict)); dict = (struct getdns_dict *) malloc(sizeof(struct getdns_dict));
ldns_rbtree_init(&(dict->root), (int (*)(const void *, const void *))strcmp); ldns_rbtree_init(&(dict->root), (int (*)(const void *,
const void *)) strcmp);
return dict; return dict;
} /* getdns_dict_create */ } /* getdns_dict_create */
@ -238,35 +232,38 @@ getdns_dict_create()
* @return NULL on error (out of memory, invalid srcdict) * @return NULL on error (out of memory, invalid srcdict)
*/ */
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)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
struct getdns_dict_item *item; struct getdns_dict_item *item;
char *key; char *key;
if(srcdict != NULL && dstdict != NULL) if (srcdict != NULL && dstdict != NULL) {
{
*dstdict = getdns_dict_create(); *dstdict = getdns_dict_create();
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(srcdict->root)) LDNS_RBTREE_FOR(item, struct getdns_dict_item *,
{ &(srcdict->root))
key = (char *)item->node.key;
switch(item->dtype)
{ {
key = (char *) item->node.key;
switch (item->dtype) {
case t_bindata: case t_bindata:
getdns_dict_set_bindata(*dstdict, key, item->data.bindata); getdns_dict_set_bindata(*dstdict, key,
item->data.bindata);
break; break;
case t_dict: case t_dict:
getdns_dict_set_dict(*dstdict, key, item->data.dict); getdns_dict_set_dict(*dstdict, key,
item->data.dict);
break; break;
case t_int: case t_int:
getdns_dict_set_int(*dstdict, key, item->data.n); getdns_dict_set_int(*dstdict, key,
item->data.n);
break; break;
case t_list: case t_list:
getdns_dict_set_list(*dstdict, key, item->data.list); getdns_dict_set_list(*dstdict, key,
item->data.list);
break; break;
case t_invalid: case t_invalid:
@ -288,29 +285,23 @@ getdns_dict_copy(struct getdns_dict *srcdict, struct getdns_dict **dstdict)
* @return void * @return void
*/ */
void void
getdns_dict_item_free(ldns_rbnode_t *node, void *arg) getdns_dict_item_free(ldns_rbnode_t * node, void *arg)
{ {
(void) arg; (void) arg;
struct getdns_dict_item *item = (struct getdns_dict_item *)node; struct getdns_dict_item *item = (struct getdns_dict_item *) node;
if(item != NULL) if (item != NULL) {
{ if (item->dtype == t_bindata) {
if(item->dtype == t_bindata) if (item->data.bindata->size > 0)
{
if(item->data.bindata->size > 0)
free(item->data.bindata->data); free(item->data.bindata->data);
free(item->data.bindata); free(item->data.bindata);
} } else if (item->dtype == t_dict) {
else if(item->dtype == t_dict)
{
getdns_dict_destroy(item->data.dict); getdns_dict_destroy(item->data.dict);
} } else if (item->dtype == t_list) {
else if(item->dtype == t_list)
{
getdns_list_destroy(item->data.list); getdns_list_destroy(item->data.list);
} }
if(item->node.key != NULL) if (item->node.key != NULL)
free((char *)item->node.key); free((char *) item->node.key);
free(item); free(item);
} }
} /* getdns_dict_item_free */ } /* getdns_dict_item_free */
@ -319,9 +310,9 @@ getdns_dict_item_free(ldns_rbnode_t *node, void *arg)
void void
getdns_dict_destroy(struct getdns_dict *dict) getdns_dict_destroy(struct getdns_dict *dict)
{ {
if(dict != NULL) if (dict != NULL) {
{ ldns_traverse_postorder(&(dict->root), getdns_dict_item_free,
ldns_traverse_postorder(&(dict->root), getdns_dict_item_free, NULL); NULL);
free(dict); free(dict);
} }
@ -330,24 +321,21 @@ getdns_dict_destroy(struct getdns_dict *dict)
/*---------------------------------------- getdns_dict_set_dict */ /*---------------------------------------- getdns_dict_set_dict */
getdns_return_t getdns_return_t
getdns_dict_set_dict(struct getdns_dict *dict, char *name, struct getdns_dict *child_dict) getdns_dict_set_dict(struct getdns_dict * dict, char *name,
struct getdns_dict * child_dict)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
struct getdns_dict *newdict; struct getdns_dict *newdict;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL) if (dict != NULL && name != NULL) {
{
item = getdns_dict_find(dict, name, true); item = getdns_dict_find(dict, name, true);
if(item != NULL) if (item != NULL) {
{
retval = getdns_dict_copy(child_dict, &newdict); retval = getdns_dict_copy(child_dict, &newdict);
if(retval == GETDNS_RETURN_GOOD) if (retval == GETDNS_RETURN_GOOD) {
{
item->dtype = t_dict; item->dtype = t_dict;
item->data.dict = newdict; item->data.dict = newdict;
} } else
else
item->dtype = t_invalid; item->dtype = t_invalid;
} }
} }
@ -357,24 +345,21 @@ getdns_dict_set_dict(struct getdns_dict *dict, char *name, struct getdns_dict *c
/*---------------------------------------- getdns_dict_set_list */ /*---------------------------------------- getdns_dict_set_list */
getdns_return_t getdns_return_t
getdns_dict_set_list(struct getdns_dict *dict, char *name, struct getdns_list *child_list) getdns_dict_set_list(struct getdns_dict * dict, char *name,
struct getdns_list * child_list)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
struct getdns_list *newlist; struct getdns_list *newlist;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL) if (dict != NULL && name != NULL) {
{
item = getdns_dict_find(dict, name, true); item = getdns_dict_find(dict, name, true);
if(item != NULL) if (item != NULL) {
{
retval = getdns_list_copy(child_list, &newlist); retval = getdns_list_copy(child_list, &newlist);
if(retval == GETDNS_RETURN_GOOD) if (retval == GETDNS_RETURN_GOOD) {
{
item->dtype = t_list; item->dtype = t_list;
item->data.list = newlist; item->data.list = newlist;
} } else
else
item->dtype = t_invalid; item->dtype = t_invalid;
} }
} }
@ -384,25 +369,28 @@ getdns_dict_set_list(struct getdns_dict *dict, char *name, struct getdns_list *c
/*---------------------------------------- getdns_dict_set_bindata */ /*---------------------------------------- getdns_dict_set_bindata */
getdns_return_t getdns_return_t
getdns_dict_set_bindata(struct getdns_dict *dict, char *name, struct getdns_bindata *child_bindata) getdns_dict_set_bindata(struct getdns_dict * dict, char *name,
struct getdns_bindata * child_bindata)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL && child_bindata != NULL) if (dict != NULL && name != NULL && child_bindata != NULL) {
{
item = getdns_dict_find(dict, name, true); item = getdns_dict_find(dict, name, true);
if(item != NULL) if (item != NULL) {
{
item->dtype = t_bindata; item->dtype = t_bindata;
item->data.bindata = (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata)); item->data.bindata =
if(item->data.bindata != NULL) (struct getdns_bindata *) malloc(sizeof(struct
{ getdns_bindata));
item->data.bindata->data = (void *) malloc(child_bindata->size); if (item->data.bindata != NULL) {
if(item->data.bindata->data != NULL) item->data.bindata->data =
{ (void *) malloc(child_bindata->size);
item->data.bindata->size = child_bindata->size; if (item->data.bindata->data != NULL) {
memcpy(item->data.bindata->data, child_bindata->data, child_bindata->size); item->data.bindata->size =
child_bindata->size;
memcpy(item->data.bindata->data,
child_bindata->data,
child_bindata->size);
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
} }
@ -414,16 +402,15 @@ getdns_dict_set_bindata(struct getdns_dict *dict, char *name, struct getdns_bind
/*---------------------------------------- getdns_dict_set_int */ /*---------------------------------------- getdns_dict_set_int */
getdns_return_t getdns_return_t
getdns_dict_set_int(struct getdns_dict *dict, char *name, uint32_t child_uint32) getdns_dict_set_int(struct getdns_dict * dict, char *name,
uint32_t child_uint32)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
if(dict != NULL && name != NULL) if (dict != NULL && name != NULL) {
{
item = getdns_dict_find(dict, name, true); item = getdns_dict_find(dict, name, true);
if(item != NULL) if (item != NULL) {
{
item->dtype = t_int; item->dtype = t_int;
item->data.n = child_uint32; item->data.n = child_uint32;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
@ -457,44 +444,45 @@ getdns_indent(size_t indent)
* if an output error is encountered, a negative value * if an output error is encountered, a negative value
*/ */
static int static int
getdns_pp_bindata(ldns_buffer *buf, size_t indent, struct getdns_bindata *bindata) getdns_pp_bindata(ldns_buffer * buf, size_t indent,
struct getdns_bindata *bindata)
{ {
size_t i, p = ldns_buffer_position(buf); size_t i, p = ldns_buffer_position(buf);
uint8_t *dptr; uint8_t *dptr;
if(ldns_buffer_printf(buf, " <bindata ") < 0) if (ldns_buffer_printf(buf, " <bindata ") < 0)
return -1; return -1;
/* Walk through all printable characters */ /* Walk through all printable characters */
i = 0; i = 0;
if(bindata->size && bindata->data[bindata->size - 1] == 0) if (bindata->size && bindata->data[bindata->size - 1] == 0)
while(i < bindata->size - 1 && isprint(bindata->data[i])) while (i < bindata->size - 1 && isprint(bindata->data[i]))
i++; i++;
if(i >= bindata->size - 1) { /* all chars were printable */ if (i >= bindata->size - 1) { /* all chars were printable */
if(ldns_buffer_printf(buf, "for \"%s\">", bindata->data) < 0) if (ldns_buffer_printf(buf, "for \"%s\">", bindata->data) < 0)
return -1; return -1;
} else { } else {
if(ldns_buffer_printf(buf, "of 0x") < 0) if (ldns_buffer_printf(buf, "of 0x") < 0)
return -1; return -1;
for(dptr = bindata->data; dptr < bindata->data + bindata->size; dptr++) { for (dptr = bindata->data;
if(dptr - bindata->data >= 16) { dptr < bindata->data + bindata->size; dptr++) {
if(ldns_buffer_printf(buf, "...") < 0) if (dptr - bindata->data >= 16) {
if (ldns_buffer_printf(buf, "...") < 0)
return -1; return -1;
break; break;
} }
if(ldns_buffer_printf(buf, "%.2x", *dptr) < 0) if (ldns_buffer_printf(buf, "%.2x", *dptr) < 0)
return -1; return -1;
} }
if(ldns_buffer_printf(buf, ">") < 0) if (ldns_buffer_printf(buf, ">") < 0)
return -1; return -1;
} }
return ldns_buffer_position(buf) - p; return ldns_buffer_position(buf) - p;
} /* getdns_pp_bindata */ } /* getdns_pp_bindata */
static int static int
getdns_pp_dict(ldns_buffer *buf, size_t indent, struct getdns_dict *dict); getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict);
/*---------------------------------------- getdns_pp_list */ /*---------------------------------------- getdns_pp_list */
/** /**
@ -506,7 +494,7 @@ getdns_pp_dict(ldns_buffer *buf, size_t indent, struct getdns_dict *dict);
* if an output error is encountered, a negative value * if an output error is encountered, a negative value
*/ */
static int static int
getdns_pp_list(ldns_buffer *buf, size_t indent, struct getdns_list *list) getdns_pp_list(ldns_buffer * buf, size_t indent, struct getdns_list *list)
{ {
size_t i, length, p = ldns_buffer_position(buf); size_t i, length, p = ldns_buffer_position(buf);
getdns_data_type dtype; getdns_data_type dtype;
@ -515,47 +503,52 @@ getdns_pp_list(ldns_buffer *buf, size_t indent, struct getdns_list *list)
struct getdns_bindata *bindata_item; struct getdns_bindata *bindata_item;
uint32_t int_item; uint32_t int_item;
if(list == NULL) if (list == NULL)
return 0; return 0;
if(ldns_buffer_printf(buf, "[") < 0) if (ldns_buffer_printf(buf, "[") < 0)
return -1; return -1;
if (getdns_list_get_length(list, &length) != GETDNS_RETURN_GOOD) if (getdns_list_get_length(list, &length) != GETDNS_RETURN_GOOD)
return -1; return -1;
indent += 2; indent += 2;
for(i = 0; i < length; i++) for (i = 0; i < length; i++) {
{ if (ldns_buffer_printf(buf, "%s\n%s", (i ? "," : ""),
if(ldns_buffer_printf(buf, "%s\n%s", (i ? "," : ""),
getdns_indent(indent)) < 0) getdns_indent(indent)) < 0)
return -1; return -1;
if(getdns_list_get_data_type(list, i, &dtype) != GETDNS_RETURN_GOOD) if (getdns_list_get_data_type(list, i,
&dtype) != GETDNS_RETURN_GOOD)
return -1; return -1;
switch(dtype) { switch (dtype) {
case t_int : if (getdns_list_get_int(list, i, &int_item) != case t_int:
if (getdns_list_get_int(list, i, &int_item) !=
GETDNS_RETURN_GOOD) GETDNS_RETURN_GOOD)
if(ldns_buffer_printf(buf, " %d", (int)int_item) < 0) if (ldns_buffer_printf(buf, " %d",
(int) int_item) < 0)
return -1; return -1;
break; break;
case t_bindata: if (getdns_list_get_bindata(list, i, &bindata_item) != case t_bindata:
if (getdns_list_get_bindata(list, i, &bindata_item) !=
GETDNS_RETURN_GOOD) GETDNS_RETURN_GOOD)
return -1; return -1;
if (getdns_pp_bindata(buf, indent, bindata_item) < 0) if (getdns_pp_bindata(buf, indent, bindata_item) < 0)
return -1; return -1;
break; break;
case t_list : if (getdns_list_get_list(list, i, &list_item) != case t_list:
if (getdns_list_get_list(list, i, &list_item) !=
GETDNS_RETURN_GOOD) GETDNS_RETURN_GOOD)
return -1; return -1;
if (getdns_pp_list(buf, indent, list_item) < 0) if (getdns_pp_list(buf, indent, list_item) < 0)
return -1; return -1;
break; break;
case t_dict : if (getdns_list_get_dict(list, i, &dict_item) != case t_dict:
if (getdns_list_get_dict(list, i, &dict_item) !=
GETDNS_RETURN_GOOD) GETDNS_RETURN_GOOD)
return -1; return -1;
if (getdns_pp_dict(buf, indent, dict_item) < 0) if (getdns_pp_dict(buf, indent, dict_item) < 0)
@ -563,19 +556,20 @@ getdns_pp_list(ldns_buffer *buf, size_t indent, struct getdns_list *list)
break; break;
case t_invalid: case t_invalid:
default : if(ldns_buffer_printf(buf, " <invalid>") < 0) default:
if (ldns_buffer_printf(buf, " <invalid>") < 0)
return -1; return -1;
} }
i++; i++;
} }
indent -= 2; indent -= 2;
if (ldns_buffer_printf(buf, i ? "\n%s]" : "]", getdns_indent(indent)) < 0) if (ldns_buffer_printf(buf, i ? "\n%s]" : "]",
getdns_indent(indent)) < 0)
return -1; return -1;
return ldns_buffer_position(buf) - p; return ldns_buffer_position(buf) - p;
} /* getdns_pp_list */ } /* getdns_pp_list */
/*---------------------------------------- getdns_pp_dict */ /*---------------------------------------- getdns_pp_dict */
/** /**
* private function to pretty print dict to a ldns_buffer * private function to pretty print dict to a ldns_buffer
@ -586,72 +580,77 @@ getdns_pp_list(ldns_buffer *buf, size_t indent, struct getdns_list *list)
* if an output error is encountered, a negative value * if an output error is encountered, a negative value
*/ */
static int static int
getdns_pp_dict(ldns_buffer *buf, size_t indent, struct getdns_dict *dict) getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict)
{ {
size_t i, length, p = ldns_buffer_position(buf); size_t i, length, p = ldns_buffer_position(buf);
struct getdns_dict_item *item; struct getdns_dict_item *item;
if(dict == NULL) if (dict == NULL)
return 0; return 0;
if(ldns_buffer_printf(buf, "{") < 0) if (ldns_buffer_printf(buf, "{") < 0)
return -1; return -1;
i = 0; i = 0;
indent += 2; indent += 2;
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root)) LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root)) {
{ if (ldns_buffer_printf(buf, "%s\n%s\"%s\":", (i ? "," : "")
if(ldns_buffer_printf(buf, "%s\n%s\"%s\":", (i ? "," : "")
, getdns_indent(indent) , getdns_indent(indent)
, item->node.key) < 0) , item->node.key) < 0)
return -1; return -1;
switch(item->dtype) { switch (item->dtype) {
case t_int : if(ldns_buffer_printf(buf, " %d", item->data.n) < 0) case t_int:
if (ldns_buffer_printf(buf, " %d", item->data.n) < 0)
return -1; return -1;
break; break;
case t_bindata: if (getdns_pp_bindata(buf, indent, case t_bindata:
if (getdns_pp_bindata(buf, indent,
item->data.bindata) < 0) item->data.bindata) < 0)
return -1; return -1;
break; break;
case t_list : /* Don't put empty lists on a new line */ case t_list: /* Don't put empty lists on a new line */
if(getdns_list_get_length(item->data.list, if (getdns_list_get_length(item->data.list,
&length) != GETDNS_RETURN_GOOD) &length) != GETDNS_RETURN_GOOD)
return -1; return -1;
if(length == 0) { if (length == 0) {
if(ldns_buffer_printf(buf, " []") < 0) if (ldns_buffer_printf(buf, " []") < 0)
return -1; return -1;
break; break;
} }
if(ldns_buffer_printf(buf, "\n%s", getdns_indent(indent)) < 0) if (ldns_buffer_printf(buf, "\n%s",
getdns_indent(indent)) < 0)
return -1; return -1;
if(getdns_pp_list(buf, indent, item->data.list) < 0) if (getdns_pp_list(buf, indent, item->data.list) < 0)
return -1; return -1;
break; break;
case t_dict : if(ldns_buffer_printf(buf, "\n%s", getdns_indent(indent)) < 0) case t_dict:
if (ldns_buffer_printf(buf, "\n%s",
getdns_indent(indent)) < 0)
return -1; return -1;
if(getdns_pp_dict(buf, indent, item->data.dict) < 0) if (getdns_pp_dict(buf, indent, item->data.dict) < 0)
return -1; return -1;
break; break;
case t_invalid: case t_invalid:
default : if(ldns_buffer_printf(buf, " <invalid>") < 0) default:
if (ldns_buffer_printf(buf, " <invalid>") < 0)
return -1; return -1;
} }
i++; i++;
} }
indent -= 2; indent -= 2;
if (ldns_buffer_printf(buf, i ? "\n%s}" : "}", getdns_indent(indent)) < 0) if (ldns_buffer_printf(buf, i ? "\n%s}" : "}",
getdns_indent(indent)) < 0)
return -1; return -1;
return ldns_buffer_position(buf) - p; return ldns_buffer_position(buf) - p;
} /* getdns_pp_dict */ } /* getdns_pp_dict */
/*---------------------------------------- getdns_pretty_print_dict */ /*---------------------------------------- getdns_pretty_print_dict */
/** /**
* Return a character string containing a "human readable" representation * Return a character string containing a "human readable" representation
@ -671,14 +670,14 @@ getdns_pretty_print_dict(struct getdns_dict *dict)
} }
buf = ldns_buffer_new(100); buf = ldns_buffer_new(100);
if (! buf) if (!buf)
return NULL; return NULL;
if (getdns_pp_dict(buf, 0, dict) < 0) { if (getdns_pp_dict(buf, 0, dict) < 0) {
ldns_buffer_free(buf); ldns_buffer_free(buf);
return NULL; return NULL;
} }
ret = (char *)ldns_buffer_export(buf); ret = (char *) ldns_buffer_export(buf);
ldns_buffer_free(buf); ldns_buffer_free(buf);
return ret; return ret;
} /* getdns_pretty_print_dict */ } /* getdns_pretty_print_dict */

View File

@ -38,7 +38,8 @@
#include <getdns/getdns.h> #include <getdns/getdns.h>
#include <ldns/rbtree.h> #include <ldns/rbtree.h>
union getdns_item { union getdns_item
{
struct getdns_list *list; struct getdns_list *list;
struct getdns_dict *dict; struct getdns_dict *dict;
uint32_t n; uint32_t n;
@ -48,7 +49,8 @@ union getdns_item {
/** /**
* this structure represents a single item in a dictionary type * this structure represents a single item in a dictionary type
*/ */
struct getdns_dict_item { struct getdns_dict_item
{
ldns_rbnode_t node; ldns_rbnode_t node;
getdns_data_type dtype; getdns_data_type dtype;
union getdns_item data; union getdns_item data;
@ -61,11 +63,11 @@ struct getdns_dict_item {
* trees in the std library. The internal implementation may change so the * trees in the std library. The internal implementation may change so the
* application should stick to the helper functions. * application should stick to the helper functions.
*/ */
struct getdns_dict { struct getdns_dict
{
ldns_rbtree_t root; ldns_rbtree_t root;
}; };
#endif #endif
/* dict.h */ /* dict.h */

View File

@ -10,285 +10,187 @@
/* The return values */ /* The return values */
getdns_return_t retregular; getdns_return_t retregular;
char * retcharstar; char *retcharstar;
/* The args */ /* The args */
bool boolarg; bool boolarg;
char * charstararg; char *charstararg;
getdns_callback_t callbackarg; getdns_callback_t callbackarg;
uint16_t regulararg; uint16_t regulararg;
uint16_t *regularptrarg; uint16_t *regularptrarg;
getdns_transaction_t txidarg; getdns_transaction_t txidarg;
getdns_transaction_t * txidptrarg; getdns_transaction_t *txidptrarg;
getdns_data_type * datatypeptrarg; getdns_data_type *datatypeptrarg;
struct getdns_bindata ** bindataptrarg; struct getdns_bindata **bindataptrarg;
struct getdns_dict * dictarg; struct getdns_dict *dictarg;
struct getdns_bindata * bindataarg; struct getdns_bindata *bindataarg;
struct getdns_list * listarg; struct getdns_list *listarg;
struct getdns_dict ** dictptrarg; struct getdns_dict **dictptrarg;
struct getdns_list ** listptrarg; struct getdns_list **listptrarg;
size_t sizetarg; size_t sizetarg;
size_t * sizetptrarg; size_t *sizetptrarg;
getdns_context_t contextarg = NULL; getdns_context_t contextarg = NULL;
uint8_t uint8arg; uint8_t uint8arg;
uint16_t uint16arg; uint16_t uint16arg;
uint32_t uint32arg; uint32_t uint32arg;
uint8_t * uint8ptrarg; uint8_t *uint8ptrarg;
uint16_t * uint16ptrarg; uint16_t *uint16ptrarg;
uint32_t * uint32ptrarg; uint32_t *uint32ptrarg;
void * arrayarg; void *arrayarg;
void allocfunctionarg(size_t foo) {UNUSED_PARAM(foo);} void
void deallocfunctionarg(void* foo) {UNUSED_PARAM(foo);} allocfunctionarg(size_t foo)
void setcallbackfunctionarg(struct getdns_context_t *foo1, uint16_t foo2) {
{UNUSED_PARAM(foo1);UNUSED_PARAM(foo2);} UNUSED_PARAM(foo);
}
int main() void
deallocfunctionarg(void *foo)
{
UNUSED_PARAM(foo);
}
void
setcallbackfunctionarg(struct getdns_context_t *foo1, uint16_t foo2)
{
UNUSED_PARAM(foo1);
UNUSED_PARAM(foo2);
}
int
main()
{ {
retregular = getdns_general( retregular = getdns_general(contextarg,
contextarg,
charstararg, charstararg,
uint16arg, uint16arg, dictarg, arrayarg, txidptrarg, callbackarg);
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_address( retregular = getdns_address(contextarg,
contextarg, charstararg, dictarg, arrayarg, txidptrarg, callbackarg);
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_hostname( retregular = getdns_hostname(contextarg,
contextarg, dictarg, dictarg, arrayarg, txidptrarg, callbackarg);
dictarg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_service( retregular = getdns_service(contextarg,
contextarg, charstararg, dictarg, arrayarg, txidptrarg, callbackarg);
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_context_create( retregular = getdns_context_create(&contextarg, boolarg);
&contextarg,
boolarg
);
retregular = getdns_cancel_callback( retregular = getdns_cancel_callback(contextarg, txidarg);
contextarg,
txidarg
);
retregular = getdns_general_sync( retregular = getdns_general_sync(contextarg,
contextarg, charstararg, uint16arg, dictarg, uint32ptrarg, &dictarg);
charstararg,
uint16arg,
dictarg,
uint32ptrarg,
&dictarg
);
retregular = getdns_address_sync( retregular = getdns_address_sync(contextarg,
contextarg, charstararg, dictarg, uint32ptrarg, &dictarg);
charstararg,
dictarg,
uint32ptrarg,
&dictarg
);
retregular = getdns_hostname_sync( retregular = getdns_hostname_sync(contextarg,
contextarg, dictarg, dictarg, uint32ptrarg, &dictarg);
dictarg,
dictarg,
uint32ptrarg,
&dictarg
);
retregular = getdns_service_sync( retregular = getdns_service_sync(contextarg,
contextarg, charstararg, dictarg, uint32ptrarg, &dictarg);
charstararg,
dictarg,
uint32ptrarg,
&dictarg
);
getdns_free_sync_request_memory( getdns_free_sync_request_memory(dictarg);
dictarg
);
retregular = getdns_list_get_length(listarg, sizetptrarg); retregular = getdns_list_get_length(listarg, sizetptrarg);
retregular = getdns_list_get_data_type(listarg, sizetarg, datatypeptrarg); retregular =
retregular = getdns_list_get_dict(listarg, sizetarg, dictptrarg); getdns_list_get_data_type(listarg, sizetarg, datatypeptrarg);
retregular = getdns_list_get_list(listarg, sizetarg, listptrarg); retregular = getdns_list_get_dict(listarg, sizetarg, dictptrarg);
retregular = getdns_list_get_bindata(listarg, sizetarg, bindataptrarg); retregular = getdns_list_get_list(listarg, sizetarg, listptrarg);
retregular = getdns_list_get_int(listarg, sizetarg, uint32ptrarg); retregular = getdns_list_get_bindata(listarg, sizetarg, bindataptrarg);
retregular = getdns_list_get_int(listarg, sizetarg, uint32ptrarg);
retregular = getdns_dict_get_names(dictarg, listptrarg); retregular = getdns_dict_get_names(dictarg, listptrarg);
retregular = getdns_dict_get_data_type(dictarg, charstararg, datatypeptrarg); retregular =
retregular = getdns_dict_get_dict(dictarg, charstararg, dictptrarg); getdns_dict_get_data_type(dictarg, charstararg, datatypeptrarg);
retregular = getdns_dict_get_list(dictarg, charstararg, listptrarg); retregular = getdns_dict_get_dict(dictarg, charstararg, dictptrarg);
retregular = getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg); retregular = getdns_dict_get_list(dictarg, charstararg, listptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg); retregular =
getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg);
listarg = getdns_list_create(); listarg = getdns_list_create();
retregular = getdns_list_set_dict(listarg, sizetarg, dictarg); retregular = getdns_list_set_dict(listarg, sizetarg, dictarg);
retregular = getdns_list_set_list(listarg, sizetarg, listarg); retregular = getdns_list_set_list(listarg, sizetarg, listarg);
retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg); retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg);
retregular = getdns_list_set_int(listarg, sizetarg, uint32arg); retregular = getdns_list_set_int(listarg, sizetarg, uint32arg);
dictarg = getdns_dict_create(); dictarg = getdns_dict_create();
retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg); retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg);
retregular = getdns_dict_set_list(dictarg, charstararg, listarg); retregular = getdns_dict_set_list(dictarg, charstararg, listarg);
retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg); retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg);
retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg); retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg);
retcharstar = getdns_pretty_print_dict( retcharstar = getdns_pretty_print_dict(dictarg);
dictarg
);
retcharstar = getdns_convert_fqdn_to_dns_name( retcharstar = getdns_convert_fqdn_to_dns_name(charstararg);
charstararg
);
retcharstar = getdns_convert_dns_name_to_fqdn( retcharstar = getdns_convert_dns_name_to_fqdn(charstararg);
charstararg
);
retcharstar = getdns_convert_ulabel_to_alabel( retcharstar = getdns_convert_ulabel_to_alabel(charstararg);
charstararg
);
retcharstar = getdns_convert_alabel_to_ulabel( retcharstar = getdns_convert_alabel_to_ulabel(charstararg);
charstararg
);
retregular = getdns_validate_dnssec( retregular = getdns_validate_dnssec(bindataarg, listarg, listarg);
bindataarg,
listarg,
listarg
);
retcharstar = getdns_display_ip_address( retcharstar = getdns_display_ip_address(bindataarg);
bindataarg
);
retregular = getdns_context_set_context_update_callback( retregular = getdns_context_set_context_update_callback(contextarg,
contextarg, setcallbackfunctionarg);
setcallbackfunctionarg
);
retregular = getdns_context_set_resolution_type( retregular = getdns_context_set_resolution_type(contextarg,
contextarg, regulararg);
regulararg
);
retregular = getdns_context_set_namespaces( retregular = getdns_context_set_namespaces(contextarg,
contextarg, sizetarg, regularptrarg);
sizetarg,
regularptrarg
);
retregular = getdns_context_set_dns_transport( retregular = getdns_context_set_dns_transport(contextarg, regulararg);
contextarg,
regulararg
);
retregular = getdns_context_set_limit_outstanding_queries( retregular = getdns_context_set_limit_outstanding_queries(contextarg,
contextarg, uint16arg);
uint16arg
);
retregular = getdns_context_set_timeout( retregular = getdns_context_set_timeout(contextarg, uint16arg);
contextarg,
uint16arg
);
retregular = getdns_context_set_follow_redirects( retregular = getdns_context_set_follow_redirects(contextarg,
contextarg, regulararg);
regulararg
);
retregular = getdns_context_set_dns_root_servers( retregular = getdns_context_set_dns_root_servers(contextarg, listarg);
contextarg,
listarg
);
retregular = getdns_context_set_append_name( retregular = getdns_context_set_append_name(contextarg, regulararg);
contextarg,
regulararg
);
retregular = getdns_context_set_suffix( retregular = getdns_context_set_suffix(contextarg, listarg);
contextarg,
listarg
);
retregular = getdns_context_set_dnssec_trust_anchors( retregular = getdns_context_set_dnssec_trust_anchors(contextarg,
contextarg, listarg);
listarg
);
retregular = getdns_context_set_dnssec_allowed_skew( retregular = getdns_context_set_dnssec_allowed_skew(contextarg,
contextarg, uint16arg);
uint16arg
);
retregular = getdns_context_set_stub_resolution( retregular = getdns_context_set_stub_resolution(contextarg, listarg);
contextarg,
listarg
);
retregular = getdns_context_set_edns_maximum_udp_payload_size( retregular =
contextarg, getdns_context_set_edns_maximum_udp_payload_size(contextarg,
uint16arg uint16arg);
);
retregular = getdns_context_set_edns_extended_rcode( retregular = getdns_context_set_edns_extended_rcode(contextarg,
contextarg, uint8arg);
uint8arg
);
retregular = getdns_context_set_edns_version( retregular = getdns_context_set_edns_version(contextarg, uint8arg);
contextarg,
uint8arg
);
retregular = getdns_context_set_edns_do_bit( retregular = getdns_context_set_edns_do_bit(contextarg, uint8arg);
contextarg,
uint8arg
);
retregular = getdns_context_set_memory_allocator( retregular = getdns_context_set_memory_allocator(contextarg,
contextarg, allocfunctionarg);
allocfunctionarg
);
retregular = getdns_context_set_memory_deallocator( retregular = getdns_context_set_memory_deallocator(contextarg,
contextarg, deallocfunctionarg);
deallocfunctionarg
);
retregular = getdns_context_set_memory_reallocator( retregular = getdns_context_set_memory_reallocator(contextarg,
contextarg, deallocfunctionarg);
deallocfunctionarg
);
getdns_list_destroy(listarg); getdns_list_destroy(listarg);
getdns_dict_destroy(dictarg); getdns_dict_destroy(dictarg);
getdns_context_destroy(contextarg); getdns_context_destroy(contextarg);
return(0); } /* End of main() */ return (0);
} /* End of main() */

View File

@ -37,31 +37,36 @@
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */ /* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context, void
this_callbackfn(struct getdns_context_t *this_context,
uint16_t this_callback_type, uint16_t this_callback_type,
struct getdns_dict *this_response, struct getdns_dict *this_response,
void *this_userarg, void *this_userarg, getdns_transaction_t this_transaction_id)
getdns_transaction_t this_transaction_id)
{ {
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */ UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */ UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */ getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */ if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
{
/* Be sure the search returned something */ /* Be sure the search returned something */
uint32_t this_error; uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good" if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{ {
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error); fprintf(stderr,
"The search had no results, and a return value of %d. Exiting.\n",
this_error);
getdns_dict_destroy(this_response); getdns_dict_destroy(this_response);
return; return;
} }
struct getdns_list * just_the_addresses_ptr; struct getdns_list *just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); this_ret =
getdns_dict_get_list(this_response, "just_address_answers",
&just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic" if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
{ {
fprintf(stderr, "Trying to get the answers failed: %d\n", this_ret); fprintf(stderr,
"Trying to get the answers failed: %d\n",
this_ret);
getdns_dict_destroy(this_response); getdns_dict_destroy(this_response);
return; return;
} }
@ -73,20 +78,23 @@ void this_callbackfn(struct getdns_context_t *this_context,
getdns_dict_destroy(this_response); getdns_dict_destroy(this_response);
return; return;
} }
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count ) for (size_t rec_count = 0; rec_count < num_addresses;
{ ++rec_count) {
struct getdns_bindata * this_address_data; struct getdns_bindata *this_address_data;
char* ipAddr = NULL; char *ipAddr = NULL;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
ipAddr = getdns_display_ip_address(this_address_data); ipAddr = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", ipAddr); printf("The address is %s\n", ipAddr);
free(ipAddr); free(ipAddr);
} }
} } else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
else if (this_callback_type == GETDNS_CALLBACK_CANCEL) fprintf(stderr,
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id); "The callback with ID %" PRIu64
" was cancelled. Exiting.\n", this_transaction_id);
else else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.\n", this_callback_type); fprintf(stderr,
"The callback got a callback_type of %d. Exiting.\n",
this_callback_type);
/* clean up */ /* clean up */
getdns_dict_destroy(this_response); getdns_dict_destroy(this_response);
@ -97,41 +105,41 @@ main()
{ {
/* Create the DNS context for this call */ /* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL; struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true); getdns_return_t context_create_return =
if (context_create_return != GETDNS_RETURN_GOOD) 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); fprintf(stderr, "Trying to create the context failed: %d",
return(GETDNS_RETURN_GENERIC_ERROR); context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
/* Create an event base and put it in the context using the unknown function name */ /* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base; struct event_base *this_event_base;
this_event_base = event_base_new(); this_event_base = event_base_new();
if (this_event_base == NULL) if (this_event_base == NULL) {
{
fprintf(stderr, "Trying to create the event base failed.\n"); fprintf(stderr, "Trying to create the event base failed.\n");
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} }
(void)getdns_extension_set_libevent_base(this_context, this_event_base); (void) getdns_extension_set_libevent_base(this_context,
this_event_base);
/* Set up the getdns call */ /* Set up the getdns call */
const char * this_name = "www.example.com"; const char *this_name = "www.example.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
getdns_transaction_t this_transaction_id = 0; getdns_transaction_t this_transaction_id = 0;
// getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB); // getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
/* Make the call */ /* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name, getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn); NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
{ fprintf(stderr, "A bad domain name was used: %s. Exiting.\n",
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name); this_name);
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} else if (dns_request_return != GETDNS_RETURN_GOOD) { } else if (dns_request_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "The context is not setup properly.\n"); fprintf(stderr, "The context is not setup properly.\n");
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} } else {
else
{
/* Call the event loop */ /* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base); int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return); UNUSED_PARAM(dispatch_return);

View File

@ -51,50 +51,56 @@ main()
/* Create the DNS context for this call */ /* Create the DNS context for this call */
context_create_return = getdns_context_create(&this_context, true); context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD) if (context_create_return != GETDNS_RETURN_GOOD) {
{ fprintf(stderr, "Trying to create the context failed: %d",
fprintf(stderr, "Trying to create the context failed: %d", context_create_return); context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} }
/* Set up the getdns_sync_request call */ /* Set up the getdns_sync_request call */
/* Get the A and AAAA records */ /* Get the A and AAAA records */
this_extensions = getdns_dict_create(); this_extensions = getdns_dict_create();
this_ret = getdns_dict_set_int(this_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE); this_ret =
if (this_ret != GETDNS_RETURN_GOOD) getdns_dict_set_int(this_extensions, "return_both_v4_and_v6",
{ GETDNS_EXTENSION_TRUE);
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d", this_ret); if (this_ret != GETDNS_RETURN_GOOD) {
return(GETDNS_RETURN_GENERIC_ERROR); fprintf(stderr,
"Trying to set an extension do both IPv4 and IPv6 failed: %d",
this_ret);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
/* Make the call */ /* Make the call */
getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type, getdns_return_t dns_request_return =
getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response_length, &this_response); this_extensions, &this_response_length, &this_response);
/* free the extensions */ /* free the extensions */
getdns_dict_destroy(this_extensions); getdns_dict_destroy(this_extensions);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
{ fprintf(stderr, "A bad domain name was used: %s. Exiting.",
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name); this_name);
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} } else {
else
{
/* Be sure the search returned something */ /* Be sure the search returned something */
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good" if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{ {
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", this_error); fprintf(stderr,
return(GETDNS_RETURN_GENERIC_ERROR); "The search had no results, and a return value of %d. Exiting.",
this_error);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */ /* Go through each record */
if (num_addresses > 0) { if (num_addresses > 0) {
for (rec_count = 0; rec_count < num_addresses; ++rec_count ) for (rec_count = 0; rec_count < num_addresses;
{ ++rec_count) {
char * display; char *display;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
display = getdns_display_ip_address(this_address_data); display =
getdns_display_ip_address
(this_address_data);
/* Just print the address */ /* Just print the address */
printf("The address is %s\n", display); printf("The address is %s\n", display);
if (display) { if (display) {

View File

@ -9,124 +9,143 @@
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */ /* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context, void
this_callbackfn(struct getdns_context_t *this_context,
getdns_return_t this_callback_type, getdns_return_t this_callback_type,
struct getdns_dict *this_response, struct getdns_dict *this_response,
void *this_userarg, void *this_userarg, getdns_transaction_t this_transaction_id)
getdns_transaction_t this_transaction_id)
{ {
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */ UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */ UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */ getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */ if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
{
/* Be sure the search returned something */ /* Be sure the search returned something */
uint32_t this_error; uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good" if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{ {
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", this_error); fprintf(stderr,
"The search had no results, and a return value of %d. Exiting.",
this_error);
return; return;
} }
/* Find all the answers returned */ /* Find all the answers returned */
struct getdns_list * these_answers; struct getdns_list *these_answers;
this_ret = getdns_dict_get_list(this_response, "replies_tree", &these_answers); this_ret =
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME) getdns_dict_get_list(this_response, "replies_tree",
{ &these_answers);
fprintf(stderr, "Weird: the response had no error, but also no replies_tree. Exiting."); if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the response had no error, but also no replies_tree. Exiting.");
return; return;
} }
size_t num_answers; size_t num_answers;
this_ret = getdns_list_get_length(these_answers, &num_answers); this_ret = getdns_list_get_length(these_answers, &num_answers);
/* Go through each answer */ /* Go through each answer */
for ( size_t rec_count = 0; rec_count < num_answers; ++rec_count ) for (size_t rec_count = 0; rec_count < num_answers;
{ ++rec_count) {
struct getdns_dict * this_record; struct getdns_dict *this_record;
this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error
/* Get the answer section */ /* Get the answer section */
struct getdns_list * this_answer; struct getdns_list *this_answer;
this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error
/* Get each RR in the answer section */ /* Get each RR in the answer section */
size_t num_rrs_ptr; size_t num_rrs_ptr;
this_ret = getdns_list_get_length(this_answer, &num_rrs_ptr); this_ret =
for ( size_t rr_count = 0; rr_count < num_rrs_ptr; ++rr_count ) getdns_list_get_length(this_answer, &num_rrs_ptr);
{ for (size_t rr_count = 0; rr_count < num_rrs_ptr;
struct getdns_dict * this_rr = NULL; ++rr_count) {
struct getdns_dict *this_rr = NULL;
this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error
/* Get the RDATA */ /* Get the RDATA */
struct getdns_dict * this_rdata = NULL; struct getdns_dict *this_rdata = NULL;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
/* Get the RDATA type */ /* Get the RDATA type */
uint32_t this_type; uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
/* If it is type A or AAAA, print the value */ /* If it is type A or AAAA, print the value */
if (this_type == GETDNS_RRTYPE_A) if (this_type == GETDNS_RRTYPE_A) {
{ struct getdns_bindata *this_a_record =
struct getdns_bindata * this_a_record = NULL; NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv4_address", &this_a_record); this_ret =
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME) getdns_dict_get_bindata(this_rdata,
{ "ipv4_address", &this_a_record);
fprintf(stderr, "Weird: the A record at %d in record at %d had no address. Exiting.", if (this_ret ==
(int) rr_count, (int) rec_count); GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the A record at %d in record at %d had no address. Exiting.",
(int) rr_count,
(int) rec_count);
return; return;
} }
printf("The IPv4 address is %s\n", getdns_display_ip_address(this_a_record)); printf("The IPv4 address is %s\n",
} getdns_display_ip_address
else if (this_type == GETDNS_RRTYPE_AAAA) (this_a_record));
{ } else if (this_type == GETDNS_RRTYPE_AAAA) {
struct getdns_bindata * this_aaaa_record = NULL; struct getdns_bindata *this_aaaa_record
this_ret = getdns_dict_get_bindata(this_rdata, "ipv6_address", &this_aaaa_record); = NULL;
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME) this_ret =
{ getdns_dict_get_bindata(this_rdata,
fprintf(stderr, "Weird: the AAAA record at %d in record at %d had no address. Exiting.", "ipv6_address", &this_aaaa_record);
(int) rr_count, (int) rec_count); if (this_ret ==
GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the AAAA record at %d in record at %d had no address. Exiting.",
(int) rr_count,
(int) rec_count);
return; return;
} }
printf("The IPv6 address is %s\n", getdns_display_ip_address(this_aaaa_record)); printf("The IPv6 address is %s\n",
getdns_display_ip_address
(this_aaaa_record));
} }
} }
} }
} } else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
else if (this_callback_type == GETDNS_CALLBACK_CANCEL) fprintf(stderr,
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id); "The callback with ID %" PRIu64 " was cancelled. Exiting.",
this_transaction_id);
else else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type); fprintf(stderr,
"The callback got a callback_type of %d. Exiting.",
this_callback_type);
} }
int main() int
main()
{ {
/* Create the DNS context for this call */ /* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL; struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true); getdns_return_t context_create_return =
if (context_create_return != GETDNS_RETURN_GOOD) 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); fprintf(stderr, "Trying to create the context failed: %d",
return(GETDNS_RETURN_GENERIC_ERROR); context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
/* Create an event base and put it in the context using the unknown function name */ /* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base; struct event_base *this_event_base;
this_event_base = event_base_new(); this_event_base = event_base_new();
if (this_event_base == NULL) if (this_event_base == NULL) {
{
fprintf(stderr, "Trying to create the event base failed."); fprintf(stderr, "Trying to create the event base failed.");
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} }
(void)getdns_extension_set_libevent_base(this_context, this_event_base); (void) getdns_extension_set_libevent_base(this_context,
this_event_base);
/* Set up the getdns call */ /* Set up the getdns call */
const char * this_name = "www.example.com"; const char *this_name = "www.example.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
getdns_transaction_t this_transaction_id = 0; getdns_transaction_t this_transaction_id = 0;
/* Make the call */ /* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name, getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn); NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
{ fprintf(stderr, "A bad domain name was used: %s. Exiting.",
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name); this_name);
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} } else {
else
{
/* Call the event loop */ /* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base); int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return); UNUSED_PARAM(dispatch_return);

View File

@ -48,29 +48,34 @@
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
/* declarations */ /* declarations */
static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus); static void ub_resolve_callback(void *arg, int err, ldns_buffer * result,
int sec, char *bogus);
static void ub_resolve_timeout(evutil_socket_t fd, short what, void *arg); static void ub_resolve_timeout(evutil_socket_t fd, short what, void *arg);
static void ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg); static void ub_local_resolve_timeout(evutil_socket_t fd, short what,
void *arg);
static void handle_network_request_error(getdns_network_req* netreq, int err); static void handle_network_request_error(getdns_network_req * netreq, int err);
static void handle_dns_request_complete(getdns_dns_req* dns_req); static void handle_dns_request_complete(getdns_dns_req * dns_req);
static int submit_network_request(getdns_network_req* netreq); static int submit_network_request(getdns_network_req * netreq);
typedef struct netreq_cb_data { typedef struct netreq_cb_data
{
getdns_network_req *netreq; getdns_network_req *netreq;
int err; int err;
ldns_buffer* result; ldns_buffer *result;
int sec; int sec;
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 ub_resolve_timeout(evutil_socket_t fd, short what, void *arg) { static void
getdns_dns_req *dns_req = (getdns_dns_req*) arg; ub_resolve_timeout(evutil_socket_t fd, short what, void *arg)
{
getdns_dns_req *dns_req = (getdns_dns_req *) arg;
getdns_context_t context = dns_req->context; getdns_context_t 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);
@ -78,25 +83,24 @@ static void ub_resolve_timeout(evutil_socket_t fd, short what, void *arg) {
/* cleanup */ /* cleanup */
dns_req_free(dns_req); dns_req_free(dns_req);
cb(context, cb(context, GETDNS_CALLBACK_TIMEOUT, NULL, user_arg, trans_id);
GETDNS_CALLBACK_TIMEOUT,
NULL,
user_arg,
trans_id);
} }
static void ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg) { static void
netreq_cb_data* cb_data = (netreq_cb_data*) arg; ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg)
{
netreq_cb_data *cb_data = (netreq_cb_data *) arg;
/* cleanup the local timer here since the memory may be /* cleanup the local timer here since the memory may be
* invalid after calling ub_resolve_callback * invalid after calling ub_resolve_callback
*/ */
getdns_dns_req* dnsreq = cb_data->netreq->owner; getdns_dns_req *dnsreq = cb_data->netreq->owner;
event_free(dnsreq->local_cb_timer); event_free(dnsreq->local_cb_timer);
dnsreq->local_cb_timer = NULL; dnsreq->local_cb_timer = NULL;
/* just call ub_resolve_callback */ /* just call ub_resolve_callback */
ub_resolve_callback(cb_data->netreq, cb_data->err, cb_data->result, cb_data->sec, cb_data->bogus); ub_resolve_callback(cb_data->netreq, cb_data->err, cb_data->result,
cb_data->sec, cb_data->bogus);
/* cleanup the state */ /* cleanup the state */
ldns_buffer_free(cb_data->result); ldns_buffer_free(cb_data->result);
@ -107,53 +111,48 @@ static void ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg)
} }
/* cleanup and send an error to the user callback */ /* cleanup and send an error to the user callback */
static void handle_network_request_error(getdns_network_req* netreq, int err) { static void
handle_network_request_error(getdns_network_req * netreq, int err)
{
getdns_dns_req *dns_req = netreq->owner; getdns_dns_req *dns_req = netreq->owner;
getdns_context_t context = dns_req->context; getdns_context_t 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;
/* clean up */ /* clean up */
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, cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
GETDNS_CALLBACK_ERROR,
NULL,
user_arg,
trans_id);
} }
/* cleanup and send the response to the user callback */ /* cleanup and send the response to the user callback */
static void handle_dns_request_complete(getdns_dns_req* dns_req) { static void
getdns_dict* response = create_getdns_response(dns_req); handle_dns_request_complete(getdns_dns_req * dns_req)
{
getdns_dict *response = create_getdns_response(dns_req);
getdns_context_t context = dns_req->context; getdns_context_t 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;
/* clean up the request */ /* clean up the request */
getdns_context_clear_outbound_request(dns_req); getdns_context_clear_outbound_request(dns_req);
dns_req_free(dns_req); dns_req_free(dns_req);
if (response) { if (response) {
cb(context, cb(context,
GETDNS_CALLBACK_COMPLETE, GETDNS_CALLBACK_COMPLETE, response, user_arg, trans_id);
response,
user_arg,
trans_id);
} else { } else {
cb(context, cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
GETDNS_CALLBACK_ERROR,
NULL,
user_arg,
trans_id);
} }
} }
static int submit_network_request(getdns_network_req* netreq) { static int
submit_network_request(getdns_network_req * netreq)
{
getdns_dns_req *dns_req = netreq->owner; getdns_dns_req *dns_req = netreq->owner;
int r = ub_resolve_event(dns_req->unbound, int r = ub_resolve_event(dns_req->unbound,
dns_req->name, dns_req->name,
@ -166,10 +165,11 @@ static int submit_network_request(getdns_network_req* netreq) {
return r; return r;
} }
static void
ub_resolve_callback(void *arg, int err, ldns_buffer * result, int sec,
static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus) { char *bogus)
getdns_network_req* netreq = (getdns_network_req*) arg; {
getdns_network_req *netreq = (getdns_network_req *) arg;
/* if netreq->state == NET_REQ_NOT_SENT here, that implies /* if netreq->state == NET_REQ_NOT_SENT here, that implies
* that ub called us back immediately - probably from a local file. * that ub called us back immediately - probably from a local file.
* This most likely means that getdns_general has not returned * This most likely means that getdns_general has not returned
@ -180,8 +180,9 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
* netreqs need to be issued and some resolve immediately vs. not. * netreqs need to be issued and some resolve immediately vs. not.
*/ */
struct timeval tv; struct timeval tv;
getdns_dns_req* dnsreq = netreq->owner; getdns_dns_req *dnsreq = netreq->owner;
netreq_cb_data* cb_data = (netreq_cb_data*) malloc(sizeof(netreq_cb_data)); netreq_cb_data *cb_data =
(netreq_cb_data *) malloc(sizeof(netreq_cb_data));
cb_data->netreq = netreq; cb_data->netreq = netreq;
cb_data->err = err; cb_data->err = err;
@ -189,7 +190,8 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
cb_data->result = NULL; cb_data->result = NULL;
cb_data->bogus = NULL; /* unused but here in case we need it */ cb_data->bogus = NULL; /* unused but here in case we need it */
if (result) { if (result) {
cb_data->result = ldns_buffer_new(ldns_buffer_limit(result)); cb_data->result =
ldns_buffer_new(ldns_buffer_limit(result));
if (!cb_data->result) { if (!cb_data->result) {
cb_data->err = GETDNS_RETURN_GENERIC_ERROR; cb_data->err = GETDNS_RETURN_GENERIC_ERROR;
} else { } else {
@ -198,7 +200,9 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
} }
} }
/* schedule the timeout */ /* schedule the timeout */
dnsreq->local_cb_timer = evtimer_new(dnsreq->ev_base, ub_local_resolve_timeout, cb_data); dnsreq->local_cb_timer =
evtimer_new(dnsreq->ev_base, ub_local_resolve_timeout,
cb_data);
tv.tv_sec = 0; tv.tv_sec = 0;
/* half ms */ /* half ms */
tv.tv_usec = 500; tv.tv_usec = 500;
@ -210,7 +214,8 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
handle_network_request_error(netreq, err); handle_network_request_error(netreq, err);
} else { } else {
/* parse */ /* parse */
ldns_status r = ldns_buffer2pkt_wire(&(netreq->result), result); ldns_status r =
ldns_buffer2pkt_wire(&(netreq->result), result);
if (r != LDNS_STATUS_OK) { if (r != LDNS_STATUS_OK) {
handle_network_request_error(netreq, r); handle_network_request_error(netreq, r);
} else { } else {
@ -220,7 +225,7 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
handle_dns_request_complete(netreq->owner); handle_dns_request_complete(netreq->owner);
} else { } else {
/* not finished - update to next request and ship it */ /* not finished - update to next request and ship it */
getdns_dns_req* dns_req = netreq->owner; getdns_dns_req *dns_req = netreq->owner;
dns_req->current_req = netreq->next; dns_req->current_req = netreq->next;
submit_network_request(netreq->next); submit_network_request(netreq->next);
} }
@ -229,15 +234,14 @@ static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec
} }
getdns_return_t getdns_return_t
getdns_general_ub(struct ub_ctx* unbound, getdns_general_ub(struct ub_ctx *unbound,
struct event_base* ev_base, struct event_base *ev_base,
getdns_context_t context, getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn)
getdns_callback_t callbackfn)
{ {
/* timeout */ /* timeout */
struct timeval tv; struct timeval tv;
@ -254,7 +258,7 @@ getdns_general_ub(struct ub_ctx* unbound,
} }
/* request state */ /* request state */
getdns_dns_req* req = dns_req_new(context, getdns_dns_req *req = dns_req_new(context,
unbound, unbound,
name, name,
request_type, request_type,
@ -295,19 +299,17 @@ getdns_general_ub(struct ub_ctx* unbound,
/** /**
* getdns_general * getdns_general
*/ */
getdns_return_t getdns_return_t
getdns_general(getdns_context_t context, getdns_general(getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict * extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callback)
getdns_callback_t callback)
{ {
int extcheck = GETDNS_RETURN_GOOD; int extcheck = GETDNS_RETURN_GOOD;
if (!context || !context->event_base_async || if (!context || !context->event_base_async || callback == NULL) {
callback == NULL) {
/* Can't do async without an event loop /* Can't do async without an event loop
* or callback * or callback
*/ */
@ -315,18 +317,13 @@ getdns_general_ub(struct ub_ctx* unbound,
} }
extcheck = validate_extensions(extensions); extcheck = validate_extensions(extensions);
if(extcheck != GETDNS_RETURN_GOOD) if (extcheck != GETDNS_RETURN_GOOD)
return extcheck; return extcheck;
return getdns_general_ub(context->unbound_async, return getdns_general_ub(context->unbound_async,
context->event_base_async, context->event_base_async,
context, context,
name, name, request_type, extensions, userarg, transaction_id, callback);
request_type,
extensions,
userarg,
transaction_id,
callback);
} /* getdns_general */ } /* getdns_general */
@ -334,24 +331,22 @@ getdns_general_ub(struct ub_ctx* unbound,
* getdns_address * getdns_address
* *
*/ */
getdns_return_t getdns_return_t
getdns_address(getdns_context_t context, getdns_address(getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict * extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callback)
getdns_callback_t callback) { {
int cleanup_extensions = 0; int cleanup_extensions = 0;
if (!extensions) { if (!extensions) {
extensions = getdns_dict_create(); extensions = getdns_dict_create();
cleanup_extensions = 1; cleanup_extensions = 1;
} }
getdns_dict_set_int(extensions, getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_EXTENSION_TRUE);
GETDNS_EXTENSION_TRUE);
getdns_return_t result = getdns_return_t result = getdns_general(context, name, GETDNS_RRTYPE_A,
getdns_general(context, name, GETDNS_RRTYPE_A,
extensions, userarg, transaction_id, extensions, userarg, transaction_id,
callback); callback);
if (cleanup_extensions) { if (cleanup_extensions) {

View File

@ -44,16 +44,13 @@ struct ub_ctx;
struct event_base; struct event_base;
getdns_return_t getdns_return_t
getdns_general_ub( getdns_general_ub(struct ub_ctx *unbound,
struct ub_ctx* unbound, struct event_base *ev_base,
struct event_base* ev_base,
getdns_context_t context, getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_callback_t callbackfn
);
#endif #endif

View File

@ -74,7 +74,6 @@ struct event_base;
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED 309 #define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED 309
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT A query was made with a context that is using stub resolution and a DNSSEC extension specified. #define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT A query was made with a context that is using stub resolution and a DNSSEC extension specified.
/** @} /** @}
*/ */
@ -375,10 +374,12 @@ typedef uint64_t getdns_transaction_t;
/** /**
* used to check data types within complex types (dict, list) * used to check data types within complex types (dict, list)
*/ */
typedef enum getdns_data_type { typedef enum getdns_data_type
{
t_dict, t_list, t_int, t_bindata, t_invalid t_dict, t_list, t_int, t_bindata, t_invalid
} getdns_data_type; } getdns_data_type;
typedef struct getdns_bindata { typedef struct getdns_bindata
{
size_t size; size_t size;
uint8_t *data; uint8_t *data;
} getdns_bindata; } getdns_bindata;
@ -399,7 +400,6 @@ typedef struct getdns_dict getdns_dict;
*/ */
getdns_return_t getdns_strerror(getdns_return_t err, char *buf, size_t buflen); getdns_return_t getdns_strerror(getdns_return_t err, char *buf, size_t buflen);
/** /**
* getdns list data type * getdns list data type
* Use helper functions getdns_list_* to manipulate and iterate lists * Use helper functions getdns_list_* to manipulate and iterate lists
@ -414,7 +414,8 @@ typedef struct getdns_list getdns_list;
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if list is not valid or params are NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if list is not valid or params are NULL
*/ */
getdns_return_t getdns_list_get_length(struct getdns_list *list, size_t *answer); getdns_return_t getdns_list_get_length(struct getdns_list *list,
size_t * answer);
/** /**
* private function (API users should not be calling this), this uses library * private function (API users should not be calling this), this uses library
* routines to make a copy of the list - would be faster to make the copy directly * routines to make a copy of the list - would be faster to make the copy directly
@ -426,7 +427,8 @@ getdns_return_t getdns_list_get_length(struct getdns_list *list, size_t *answer)
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if list is invalid * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if list is invalid
* @return GETDNS_RETURN_GENERIC_ERROR if out of memory * @return GETDNS_RETURN_GENERIC_ERROR if out of memory
*/ */
getdns_return_t getdns_list_copy(struct getdns_list *srclist, struct getdns_list **dstlist); getdns_return_t getdns_list_copy(struct getdns_list *srclist,
struct getdns_list **dstlist);
/** /**
* get the enumerated data type of the indexed list item * get the enumerated data type of the indexed list item
* @param list the list from which to fetch the data type * @param list the list from which to fetch the data type
@ -435,7 +437,8 @@ getdns_return_t getdns_list_copy(struct getdns_list *srclist, struct getdns_list
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL
*/ */
getdns_return_t getdns_list_get_data_type(struct getdns_list *list, size_t index, getdns_data_type *answer); getdns_return_t getdns_list_get_data_type(struct getdns_list *list,
size_t index, getdns_data_type * answer);
/** /**
* retrieve the dictionary value of the specified list item, the caller must not free * retrieve the dictionary value of the specified list item, the caller must not free
* storage associated with the return value. When the list is destroyed this * storage associated with the return value. When the list is destroyed this
@ -447,7 +450,8 @@ getdns_return_t getdns_list_get_data_type(struct getdns_list *list, size_t index
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL
* @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item * @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item
*/ */
getdns_return_t getdns_list_get_dict(struct getdns_list *list, size_t index, struct getdns_dict **answer); getdns_return_t getdns_list_get_dict(struct getdns_list *list, size_t index,
struct getdns_dict **answer);
/** /**
* retrieve the list value of the specified list item, the caller must not free * retrieve the list value of the specified list item, the caller must not free
@ -460,7 +464,8 @@ getdns_return_t getdns_list_get_dict(struct getdns_list *list, size_t index, str
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL
* @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item * @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item
*/ */
getdns_return_t getdns_list_get_list(struct getdns_list *list, size_t index, struct getdns_list **answer); getdns_return_t getdns_list_get_list(struct getdns_list *list, size_t index,
struct getdns_list **answer);
/** /**
* retrieve the binary data value of the specified list item, the caller must not * retrieve the binary data value of the specified list item, the caller must not
* free storage associated with the return value. When the list is destroyed any * free storage associated with the return value. When the list is destroyed any
@ -472,7 +477,8 @@ getdns_return_t getdns_list_get_list(struct getdns_list *list, size_t index, str
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL
* @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item * @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item
*/ */
getdns_return_t getdns_list_get_bindata(struct getdns_list *list, size_t index, struct getdns_bindata **answer); getdns_return_t getdns_list_get_bindata(struct getdns_list *list, size_t index,
struct getdns_bindata **answer);
/** /**
* retrieve the integer value of the specified list item * retrieve the integer value of the specified list item
* @param list the list from which to fetch the item * @param list the list from which to fetch the item
@ -482,7 +488,8 @@ getdns_return_t getdns_list_get_bindata(struct getdns_list *list, size_t index,
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if the index is out of range or the list is NULL
* @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item * @return GETDNS_RETURN_WRONG_TYPE_REQUESTED if the data type does not match the contents of the indexed item
*/ */
getdns_return_t getdns_list_get_int(struct getdns_list *list, size_t index, uint32_t *answer); getdns_return_t getdns_list_get_int(struct getdns_list *list, size_t index,
uint32_t * answer);
/** /**
* fetch a list of names from the dictionary, this list must be freed by the caller * fetch a list of names from the dictionary, this list must be freed by the caller
@ -492,7 +499,8 @@ getdns_return_t getdns_list_get_int(struct getdns_list *list, size_t index, uint
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or empty * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or empty
*/ */
getdns_return_t getdns_dict_get_names(struct getdns_dict *dict, struct getdns_list **answer); getdns_return_t getdns_dict_get_names(struct getdns_dict *dict,
struct getdns_list **answer);
/** /**
* fetch the data type for the data associated with the specified name * fetch the data type for the data associated with the specified name
* @param this_dict dictionary from which to fetch the data type * @param this_dict dictionary from which to fetch the data type
@ -501,7 +509,8 @@ getdns_return_t getdns_dict_get_names(struct getdns_dict *dict, struct getdns_li
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist
*/ */
getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict, char *name, getdns_data_type *answer); getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict,
char *name, getdns_data_type * answer);
/** /**
* fetch the dictionary associated with the specified name, the dictionary should * fetch the dictionary associated with the specified name, the dictionary should
* not be free()'d by the caller, it will be freed when the parent dictionary is * not be free()'d by the caller, it will be freed when the parent dictionary is
@ -512,7 +521,8 @@ getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict, char *n
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist
*/ */
getdns_return_t getdns_dict_get_dict(struct getdns_dict *this_dict, char *name, struct getdns_dict **answer); getdns_return_t getdns_dict_get_dict(struct getdns_dict *this_dict, char *name,
struct getdns_dict **answer);
/** /**
* fetch the list associated with the specified name * fetch the list associated with the specified name
* the list should not be free()'d by the caller, when the dictionary is destroyed * the list should not be free()'d by the caller, when the dictionary is destroyed
@ -523,7 +533,8 @@ getdns_return_t getdns_dict_get_dict(struct getdns_dict *this_dict, char *name,
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist
*/ */
getdns_return_t getdns_dict_get_list(struct getdns_dict *this_dict, char *name, struct getdns_list **answer); getdns_return_t getdns_dict_get_list(struct getdns_dict *this_dict, char *name,
struct getdns_list **answer);
/** /**
* fetch the bindata associated with the specified name, the bindata should not be * fetch the bindata associated with the specified name, the bindata should not be
* free()'d by the caller * free()'d by the caller
@ -533,7 +544,8 @@ getdns_return_t getdns_dict_get_list(struct getdns_dict *this_dict, char *name,
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist
*/ */
getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict, char *name, struct getdns_bindata **answer); getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict,
char *name, struct getdns_bindata **answer);
/** /**
* fetch the integer value associated with the specified name * fetch the integer value associated with the specified name
* @param this_dict dictionary from which to fetch the integer * @param this_dict dictionary from which to fetch the integer
@ -542,13 +554,14 @@ getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict, char *nam
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist * @return GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist
*/ */
getdns_return_t getdns_dict_get_int(struct getdns_dict *this_dict, char *name, uint32_t *answer); getdns_return_t getdns_dict_get_int(struct getdns_dict *this_dict, char *name,
uint32_t * answer);
/** /**
* create a new list with no items * create a new list with no items
* @return pointer to an allocated list, NULL if insufficient memory * @return pointer to an allocated list, NULL if insufficient memory
*/ */
struct getdns_list * getdns_list_create(); struct getdns_list *getdns_list_create();
/** /**
* free memory allocated to the list (also frees all children of the list) * free memory allocated to the list (also frees all children of the list)
* note that lists and bindata retrieved from the list via the getdns_list_get_* * note that lists and bindata retrieved from the list via the getdns_list_get_*
@ -566,8 +579,9 @@ void getdns_list_destroy(struct getdns_list *list);
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_GENERAL_ERROR if out of memory * @return GETDNS_RETURN_GENERAL_ERROR if out of memory
*/ */
getdns_return_t getdns_list_add_item(struct getdns_list *list, size_t *index); getdns_return_t getdns_list_add_item(struct getdns_list *list, size_t * index);
getdns_return_t getdns_list_set_dict(struct getdns_list *list, size_t index, struct getdns_dict *child_dict); getdns_return_t getdns_list_set_dict(struct getdns_list *list, size_t index,
struct getdns_dict *child_dict);
/** /**
* assign the child_list to an item in a parent list, the parent list copies * assign the child_list to an item in a parent list, the parent list copies
* the child list and will free the copy when the list is destroyed * the child list and will free the copy when the list is destroyed
@ -577,7 +591,8 @@ getdns_return_t getdns_list_set_dict(struct getdns_list *list, size_t index, str
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL
*/ */
getdns_return_t getdns_list_set_list(struct getdns_list *list, size_t index, struct getdns_list *child_list); getdns_return_t getdns_list_set_list(struct getdns_list *list, size_t index,
struct getdns_list *child_list);
/** /**
* assign the child_bindata to an item in a parent list, the parent list copies * assign the child_bindata to an item in a parent list, the parent list copies
* the child data and will free the copy when the list is destroyed * the child data and will free the copy when the list is destroyed
@ -587,13 +602,15 @@ getdns_return_t getdns_list_set_list(struct getdns_list *list, size_t index, str
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL
*/ */
getdns_return_t getdns_list_set_bindata(struct getdns_list *list, size_t index, struct getdns_bindata *child_bindata); getdns_return_t getdns_list_set_bindata(struct getdns_list *list, size_t index,
struct getdns_bindata *child_bindata);
/** /**
* set the integer value of the indexed item (zero based index) * set the integer value of the indexed item (zero based index)
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
* @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL * @return GETDNS_RETURN_NO_SUCH_LIST_ITEM if index is out of range, or list is NULL
*/ */
getdns_return_t getdns_list_set_int(struct getdns_list *list, size_t index, uint32_t child_uint32); getdns_return_t getdns_list_set_int(struct getdns_list *list, size_t index,
uint32_t child_uint32);
/** /**
* create a new dictionary with no items * create a new dictionary with no items
@ -619,7 +636,8 @@ getdns_dict_copy(struct getdns_dict *srcdict, struct getdns_dict **dstdict);
*/ */
void getdns_dict_destroy(struct getdns_dict *dict); void getdns_dict_destroy(struct getdns_dict *dict);
getdns_return_t getdns_dict_set_dict(struct getdns_dict *dict, char *name, struct getdns_dict *child_dict); getdns_return_t getdns_dict_set_dict(struct getdns_dict *dict, char *name,
struct getdns_dict *child_dict);
/** /**
* create a new entry in the dictionary, or replace the value of an existing entry * create a new entry in the dictionary, or replace the value of an existing entry
* this routine makes a copy of the child_list * this routine makes a copy of the child_list
@ -628,7 +646,8 @@ getdns_return_t getdns_dict_set_dict(struct getdns_dict *dict, char *name, struc
* @param child_list value to assign to the node identified by name * @param child_list value to assign to the node identified by name
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_dict_set_list(struct getdns_dict *dict, char *name, struct getdns_list *child_list); getdns_return_t getdns_dict_set_list(struct getdns_dict *dict, char *name,
struct getdns_list *child_list);
/** /**
* create a new entry in the dictionary, or replace the value of an existing entry * create a new entry in the dictionary, or replace the value of an existing entry
* this routine makes a copy of the child_bindata * this routine makes a copy of the child_bindata
@ -637,7 +656,8 @@ getdns_return_t getdns_dict_set_list(struct getdns_dict *dict, char *name, struc
* @param child_bindata value to assign to the node identified by name * @param child_bindata value to assign to the node identified by name
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_dict_set_bindata(struct getdns_dict *dict, char *name, struct getdns_bindata *child_bindata); getdns_return_t getdns_dict_set_bindata(struct getdns_dict *dict, char *name,
struct getdns_bindata *child_bindata);
/** /**
* create a new entry in the dictionary, or replace the value of an existing entry * create a new entry in the dictionary, or replace the value of an existing entry
* @param dict dictionary in which to add or change the value * @param dict dictionary in which to add or change the value
@ -645,71 +665,51 @@ getdns_return_t getdns_dict_set_bindata(struct getdns_dict *dict, char *name, st
* @param child_uint32 value to assign to the node identified by name * @param child_uint32 value to assign to the node identified by name
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_dict_set_int(struct getdns_dict *dict, char *name, uint32_t child_uint32); getdns_return_t getdns_dict_set_int(struct getdns_dict *dict, char *name,
uint32_t child_uint32);
/* Callback arguments */ /* Callback arguments */
typedef void (*getdns_callback_t)( typedef void (*getdns_callback_t) (getdns_context_t context,
getdns_context_t context,
uint16_t callback_type, uint16_t callback_type,
struct getdns_dict *response, struct getdns_dict * response,
void *userarg, void *userarg, getdns_transaction_t transaction_id);
getdns_transaction_t transaction_id);
/* Function definitions */ /* Function definitions */
getdns_return_t getdns_return_t
getdns_general( getdns_general(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_callback_t callbackfn
);
getdns_return_t getdns_return_t
getdns_address( getdns_address(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_callback_t callbackfn
);
getdns_return_t getdns_return_t
getdns_hostname( getdns_hostname(getdns_context_t context,
getdns_context_t context,
struct getdns_dict *address, struct getdns_dict *address,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_callback_t callbackfn
);
getdns_return_t getdns_return_t
getdns_service( getdns_service(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_callback_t callbackfn
);
getdns_return_t getdns_context_create( getdns_return_t getdns_context_create(getdns_context_t * context,
getdns_context_t *context, int set_from_os);
int set_from_os
);
void void getdns_context_destroy(getdns_context_t context);
getdns_context_destroy(
getdns_context_t context
);
getdns_return_t getdns_return_t
getdns_cancel_callback( getdns_cancel_callback(getdns_context_t context,
getdns_context_t context, getdns_transaction_t transaction_id);
getdns_transaction_t transaction_id
);
/** /**
* \defgroup syncfuns Synchronous API functions that do not use callbacks * \defgroup syncfuns Synchronous API functions that do not use callbacks
@ -731,14 +731,11 @@ getdns_cancel_callback(
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_return_t
getdns_general_sync( getdns_general_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict *extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict **response);
struct getdns_dict **response
);
/** /**
* retrieve address assigned to a DNS name * retrieve address assigned to a DNS name
@ -751,13 +748,10 @@ getdns_general_sync(
*/ */
getdns_return_t getdns_return_t
getdns_address_sync( getdns_address_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict *extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict **response);
struct getdns_dict **response
);
/** /**
* retrieve hostname assigned to an IP address * retrieve hostname assigned to an IP address
@ -769,13 +763,10 @@ getdns_address_sync(
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_return_t
getdns_hostname_sync( getdns_hostname_sync(getdns_context_t context,
getdns_context_t context,
struct getdns_dict *address, struct getdns_dict *address,
struct getdns_dict *extensions, struct getdns_dict *extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict **response);
struct getdns_dict **response
);
/** /**
* retrieve a service assigned to a DNS name * retrieve a service assigned to a DNS name
@ -787,48 +778,28 @@ getdns_hostname_sync(
* @return GETDNS_RETURN_GOOD on success * @return GETDNS_RETURN_GOOD on success
*/ */
getdns_return_t getdns_return_t
getdns_service_sync( getdns_service_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict *extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict **response);
struct getdns_dict **response
);
void void getdns_free_sync_request_memory(struct getdns_dict *response);
getdns_free_sync_request_memory(
struct getdns_dict *response
);
/** @} /** @}
*/ */
char * char *getdns_convert_dns_name_to_fqdn(char *name_from_dns_response);
getdns_convert_dns_name_to_fqdn(
char *name_from_dns_response
);
char * char *getdns_convert_fqdn_to_dns_name(char *fqdn_as_string);
getdns_convert_fqdn_to_dns_name(
char *fqdn_as_string
);
char * char *getdns_convert_ulabel_to_alabel(char *ulabel);
getdns_convert_ulabel_to_alabel(
char *ulabel
);
char * char *getdns_convert_alabel_to_ulabel(char *alabel);
getdns_convert_alabel_to_ulabel(
char *alabel
);
getdns_return_t getdns_return_t
getdns_validate_dnssec( getdns_validate_dnssec(struct getdns_bindata *record_to_validate,
struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records, struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas struct getdns_list *trust_anchor_rdatas);
);
/** /**
* creates a string that describes the dictionary in a human readable form * creates a string that describes the dictionary in a human readable form
@ -837,141 +808,91 @@ getdns_validate_dnssec(
* @param dict dictionary to pretty print * @param dict dictionary to pretty print
* @return character array (caller must free this) containing pretty string * @return character array (caller must free this) containing pretty string
*/ */
char * char *getdns_pretty_print_dict(struct getdns_dict *dict);
getdns_pretty_print_dict(struct getdns_dict *dict);
char * char *getdns_display_ip_address(struct getdns_bindata
getdns_display_ip_address( *bindata_of_ipv4_or_ipv6_address);
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address
);
getdns_return_t getdns_return_t
getdns_context_set_context_update_callback( getdns_context_set_context_update_callback(getdns_context_t context,
getdns_context_t context, void (*value) (getdns_context_t context, uint16_t changed_item)
void (*value)(getdns_context_t context, uint16_t changed_item) );
);
getdns_return_t getdns_return_t
getdns_context_set_resolution_type( getdns_context_set_resolution_type(getdns_context_t context, uint16_t value);
getdns_context_t context,
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_namespaces( getdns_context_set_namespaces(getdns_context_t context,
getdns_context_t context, size_t namespace_count, uint16_t * namespaces);
size_t namespace_count,
uint16_t *namespaces
);
getdns_return_t getdns_return_t
getdns_context_set_dns_transport( getdns_context_set_dns_transport(getdns_context_t context, uint16_t value);
getdns_context_t context,
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_limit_outstanding_queries( getdns_context_set_limit_outstanding_queries(getdns_context_t context,
getdns_context_t context, uint16_t limit);
uint16_t limit
);
getdns_return_t getdns_return_t
getdns_context_set_timeout( getdns_context_set_timeout(getdns_context_t context, uint16_t timeout);
getdns_context_t context,
uint16_t timeout
);
getdns_return_t getdns_return_t
getdns_context_set_follow_redirects( getdns_context_set_follow_redirects(getdns_context_t context, uint16_t value);
getdns_context_t context,
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_dns_root_servers( getdns_context_set_dns_root_servers(getdns_context_t context,
getdns_context_t context, struct getdns_list *addresses);
struct getdns_list *addresses
);
getdns_return_t getdns_return_t
getdns_context_set_append_name( getdns_context_set_append_name(getdns_context_t context, uint16_t value);
getdns_context_t context,
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_suffix( getdns_context_set_suffix(getdns_context_t context, struct getdns_list *value);
getdns_context_t context,
struct getdns_list *value
);
getdns_return_t getdns_return_t
getdns_context_set_dnssec_trust_anchors( getdns_context_set_dnssec_trust_anchors(getdns_context_t context,
getdns_context_t context, struct getdns_list *value);
struct getdns_list *value
);
getdns_return_t getdns_return_t
getdns_context_set_dnssec_allowed_skew( getdns_context_set_dnssec_allowed_skew(getdns_context_t context,
getdns_context_t context, uint16_t value);
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_stub_resolution( getdns_context_set_stub_resolution(getdns_context_t context,
getdns_context_t context, struct getdns_list *upstream_list);
struct getdns_list *upstream_list
);
getdns_return_t getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size( getdns_context_set_edns_maximum_udp_payload_size(getdns_context_t context,
getdns_context_t context, uint16_t value);
uint16_t value
);
getdns_return_t getdns_return_t
getdns_context_set_edns_extended_rcode( getdns_context_set_edns_extended_rcode(getdns_context_t context,
getdns_context_t context, uint8_t value);
uint8_t value
);
getdns_return_t getdns_return_t
getdns_context_set_edns_version( getdns_context_set_edns_version(getdns_context_t context, uint8_t value);
getdns_context_t context,
uint8_t value
);
getdns_return_t getdns_return_t
getdns_context_set_edns_do_bit( getdns_context_set_edns_do_bit(getdns_context_t context, uint8_t value);
getdns_context_t context,
uint8_t value
);
getdns_return_t getdns_return_t
getdns_context_set_memory_allocator( getdns_context_set_memory_allocator(getdns_context_t context,
getdns_context_t context, void (*value) (size_t somesize)
void (*value)(size_t somesize) );
);
getdns_return_t getdns_return_t
getdns_context_set_memory_deallocator( getdns_context_set_memory_deallocator(getdns_context_t context,
getdns_context_t context, void (*value) (void *)
void (*value)(void*) );
);
getdns_return_t getdns_return_t
getdns_context_set_memory_reallocator( getdns_context_set_memory_reallocator(getdns_context_t context,
getdns_context_t context, void (*value) (void *)
void (*value)(void*) );
);
/* Extension - refactor to abstract async evt loop */ /* Extension - refactor to abstract async evt loop */
/* For libevent, which we are using for these examples */ /* For libevent, which we are using for these examples */
getdns_return_t getdns_return_t
getdns_extension_set_libevent_base( getdns_extension_set_libevent_base(getdns_context_t context,
getdns_context_t context, struct event_base *this_event_base);
struct event_base *this_event_base
);
#endif /* GETDNS_H */ #endif /* GETDNS_H */

View File

@ -32,9 +32,8 @@
#include <getdns/getdns.h> #include <getdns/getdns.h>
struct getdns_struct_lookup_table
{ /* may or may not want to move this into */
struct getdns_struct_lookup_table { /* may or may not want to move this into */
int id; /* getdns.h if it's more generally useful */ int id; /* getdns.h if it's more generally useful */
const char *name; const char *name;
}; };

View File

@ -26,27 +26,44 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <getdns/getdns.h> #include <getdns/getdns.h>
#include <getdns/getdns_error.h> #include <getdns/getdns_error.h>
getdns_lookup_table getdns_error_str[] = { getdns_lookup_table getdns_error_str[] = {
{ GETDNS_RETURN_GOOD, "Good" }, {GETDNS_RETURN_GOOD, "Good"}
{ GETDNS_RETURN_GENERIC_ERROR, "Generic error" }, ,
{ GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name" }, {GETDNS_RETURN_GENERIC_ERROR, "Generic error"}
{ GETDNS_RETURN_BAD_CONTEXT, "Bad value for a context type" }, ,
{ GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Did not update the context" }, {GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name"}
{ GETDNS_RETURN_UNKNOWN_TRANSACTION, "An attempt was made to cancel a callback with a transaction_id that is not recognized" }, ,
{ GETDNS_RETURN_NO_SUCH_LIST_ITEM, "A helper function for lists had an index argument that was too high" }, {GETDNS_RETURN_BAD_CONTEXT, "Bad value for a context type"}
{ GETDNS_RETURN_NO_SUCH_DICT_NAME, "A helper function for dicts had a name argument that for a name that is not in the dict" }, ,
{ GETDNS_RETURN_WRONG_TYPE_REQUESTED, "A helper function was supposed to return a certain type for an item, but the wrong type was given" }, {GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Did not update the context"}
{ GETDNS_RETURN_NO_SUCH_EXTENSION, "A name in the extensions dict is not a valid extension" }, ,
{ GETDNS_RETURN_EXTENSION_MISFORMAT, "One or more of the extensions is has a bad format" }, {GETDNS_RETURN_UNKNOWN_TRANSACTION,
{ GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED, "A query was made with a context that is using stub resolution and a DNSSEC extension specified" }, "An attempt was made to cancel a callback with a transaction_id that is not recognized"}
{ 0, "" } ,
{GETDNS_RETURN_NO_SUCH_LIST_ITEM,
"A helper function for lists had an index argument that was too high"}
,
{GETDNS_RETURN_NO_SUCH_DICT_NAME,
"A helper function for dicts had a name argument that for a name that is not in the dict"}
,
{GETDNS_RETURN_WRONG_TYPE_REQUESTED,
"A helper function was supposed to return a certain type for an item, but the wrong type was given"}
,
{GETDNS_RETURN_NO_SUCH_EXTENSION,
"A name in the extensions dict is not a valid extension"}
,
{GETDNS_RETURN_EXTENSION_MISFORMAT,
"One or more of the extensions is has a bad format"}
,
{GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED,
"A query was made with a context that is using stub resolution and a DNSSEC extension specified"}
,
{0, ""}
}; };
/*---------------------------------------- getdns_get_errorstr_by_id() */ /*---------------------------------------- getdns_get_errorstr_by_id() */
/** /**
* return error string from getdns return * return error string from getdns return
@ -55,7 +72,6 @@ getdns_lookup_table getdns_error_str[] = {
* @return string containing error message * @return string containing error message
*/ */
const char * const char *
getdns_get_errorstr_by_id(uint16_t err) getdns_get_errorstr_by_id(uint16_t err)
{ {

View File

@ -34,7 +34,6 @@
#include "util-internal.h" #include "util-internal.h"
#include <string.h> #include <string.h>
/* stuff to make it compile pedantically */ /* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
@ -43,14 +42,11 @@
* *
*/ */
getdns_return_t getdns_return_t
getdns_hostname( getdns_hostname(getdns_context_t context,
getdns_context_t context, struct getdns_dict * address,
struct getdns_dict *address, struct getdns_dict * extensions,
struct getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callback)
getdns_callback_t callback
)
{ {
struct getdns_bindata *address_data; struct getdns_bindata *address_data;
struct getdns_bindata *address_type; struct getdns_bindata *address_type;
@ -58,17 +54,22 @@ getdns_hostname(
char *name; char *name;
getdns_return_t retval; getdns_return_t retval;
if ((retval =
if ((retval = getdns_dict_get_bindata(address, "address_data", &address_data)) != GETDNS_RETURN_GOOD) getdns_dict_get_bindata(address, "address_data",
&address_data)) != GETDNS_RETURN_GOOD)
return retval; return retval;
if ((retval = getdns_dict_get_bindata(address, "address_type", &address_type)) != GETDNS_RETURN_GOOD) if ((retval =
getdns_dict_get_bindata(address, "address_type",
&address_type)) != GETDNS_RETURN_GOOD)
return retval; return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *)address_type->data, strlen(GETDNS_STR_IPV4)) == 0) || if ((strncmp(GETDNS_STR_IPV4, (char *) address_type->data,
(strncmp(GETDNS_STR_IPV6, (char *)address_type->data, strlen(GETDNS_STR_IPV6)) == 0)) strlen(GETDNS_STR_IPV4)) == 0)
|| (strncmp(GETDNS_STR_IPV6, (char *) address_type->data,
strlen(GETDNS_STR_IPV6)) == 0))
req_type = GETDNS_RRTYPE_PTR; req_type = GETDNS_RRTYPE_PTR;
else else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED; return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *)address_data->data)) == 0) if ((name = reverse_address((char *) address_data->data)) == 0)
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general(context, name, req_type, extensions, return getdns_general(context, name, req_type, extensions,
userarg, transaction_id, callback); userarg, transaction_id, callback);

View File

@ -39,12 +39,11 @@
/*---------------------------------------- getdns_list_get_length */ /*---------------------------------------- getdns_list_get_length */
getdns_return_t getdns_return_t
getdns_list_get_length(struct getdns_list *list, size_t *answer) getdns_list_get_length(struct getdns_list * list, size_t * answer)
{ {
int retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; int retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && answer != NULL) if (list != NULL && answer != NULL) {
{
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
*answer = list->numinuse; *answer = list->numinuse;
} }
@ -54,12 +53,12 @@ getdns_list_get_length(struct getdns_list *list, size_t *answer)
/*---------------------------------------- getdns_list_get_data_type */ /*---------------------------------------- getdns_list_get_data_type */
getdns_return_t getdns_return_t
getdns_list_get_data_type(struct getdns_list *list, size_t index, getdns_data_type *answer) getdns_list_get_data_type(struct getdns_list * list, size_t index,
getdns_data_type * answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index < list->numinuse) if (list != NULL && index < list->numinuse) {
{
*answer = list->items[index].dtype; *answer = list->items[index].dtype;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -68,16 +67,15 @@ getdns_list_get_data_type(struct getdns_list *list, size_t index, getdns_data_ty
/*---------------------------------------- getdns_list_get_dict */ /*---------------------------------------- getdns_list_get_dict */
getdns_return_t getdns_return_t
getdns_list_get_dict(struct getdns_list *list, size_t index, struct getdns_dict **answer) getdns_list_get_dict(struct getdns_list * list, size_t index,
struct getdns_dict ** answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index < list->numinuse) if (list != NULL && index < list->numinuse) {
{ if (list->items[index].dtype != t_dict)
if(list->items[index].dtype != t_dict)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = list->items[index].data.dict; *answer = list->items[index].data.dict;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -88,16 +86,15 @@ getdns_list_get_dict(struct getdns_list *list, size_t index, struct getdns_dict
/*---------------------------------------- getdns_list_get_list */ /*---------------------------------------- getdns_list_get_list */
getdns_return_t getdns_return_t
getdns_list_get_list(struct getdns_list *list, size_t index, struct getdns_list **answer) getdns_list_get_list(struct getdns_list * list, size_t index,
struct getdns_list ** answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index < list->numinuse) if (list != NULL && index < list->numinuse) {
{ if (list->items[index].dtype != t_list)
if(list->items[index].dtype != t_list)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = list->items[index].data.list; *answer = list->items[index].data.list;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -107,16 +104,16 @@ getdns_list_get_list(struct getdns_list *list, size_t index, struct getdns_list
} /* getdns_list_get_list */ } /* getdns_list_get_list */
/*---------------------------------------- getdns_list_get_bindata */ /*---------------------------------------- getdns_list_get_bindata */
getdns_return_t getdns_list_get_bindata(struct getdns_list *list, size_t index, struct getdns_bindata **answer) getdns_return_t
getdns_list_get_bindata(struct getdns_list * list, size_t index,
struct getdns_bindata ** answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index < list->numinuse) if (list != NULL && index < list->numinuse) {
{ if (list->items[index].dtype != t_bindata)
if(list->items[index].dtype != t_bindata)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = list->items[index].data.bindata; *answer = list->items[index].data.bindata;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -127,16 +124,14 @@ getdns_return_t getdns_list_get_bindata(struct getdns_list *list, size_t index,
/*---------------------------------------- getdns_list_get_int */ /*---------------------------------------- getdns_list_get_int */
getdns_return_t getdns_return_t
getdns_list_get_int(struct getdns_list *list, size_t index, uint32_t *answer) getdns_list_get_int(struct getdns_list * list, size_t index, uint32_t * answer)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index < list->numinuse) if (list != NULL && index < list->numinuse) {
{ if (list->items[index].dtype != t_int)
if(list->items[index].dtype != t_int)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED; retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else else {
{
*answer = list->items[index].data.n; *answer = list->items[index].data.n;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} }
@ -154,21 +149,22 @@ getdns_list_get_int(struct getdns_list *list, size_t index, uint32_t *answer)
* @return GETDNS_RETURN_GOOD on success, GETDNS_RETURN_GENERIC_ERROR if out of memory * @return GETDNS_RETURN_GOOD on success, GETDNS_RETURN_GENERIC_ERROR if out of memory
*/ */
getdns_return_t getdns_return_t
getdns_list_realloc(struct getdns_list *list) getdns_list_realloc(struct getdns_list * list)
{ {
getdns_return_t retval = GETDNS_RETURN_GENERIC_ERROR; getdns_return_t retval = GETDNS_RETURN_GENERIC_ERROR;
int i; int i;
struct getdns_list_item *newlist; struct getdns_list_item *newlist;
if(list != NULL) if (list != NULL) {
{ newlist =
newlist = (struct getdns_list_item *) realloc(list->items (struct getdns_list_item *) realloc(list->items,
, (list->numalloc + GETDNS_LIST_BLOCKSZ) * sizeof(struct getdns_list_item)); (list->numalloc +
if(newlist != NULL) GETDNS_LIST_BLOCKSZ) *
{ sizeof(struct getdns_list_item));
if (newlist != NULL) {
list->items = newlist; list->items = newlist;
for(i=list->numalloc; i<list->numalloc + GETDNS_LIST_BLOCKSZ; i++) for (i = list->numalloc;
{ i < list->numalloc + GETDNS_LIST_BLOCKSZ; i++) {
list->items[i].inuse = false; list->items[i].inuse = false;
list->items[i].dtype = t_invalid; list->items[i].dtype = t_invalid;
} }
@ -182,61 +178,80 @@ getdns_list_realloc(struct getdns_list *list)
/*---------------------------------------- getdns_list_copy */ /*---------------------------------------- getdns_list_copy */
getdns_return_t getdns_return_t
getdns_list_copy(struct getdns_list *srclist, struct getdns_list **dstlist) getdns_list_copy(struct getdns_list * srclist, struct getdns_list ** dstlist)
{ {
int i; int i;
size_t index; size_t index;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(srclist != NULL && dstlist != NULL) if (srclist != NULL && dstlist != NULL) {
{
*dstlist = getdns_list_create(); *dstlist = getdns_list_create();
if(*dstlist != NULL) if (*dstlist != NULL) {
{
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
for(i=0; i<srclist->numinuse; i++) for (i = 0; i < srclist->numinuse; i++) {
{ if (getdns_list_add_item(*dstlist,
if(getdns_list_add_item(*dstlist, &index) == GETDNS_RETURN_GOOD) &index) == GETDNS_RETURN_GOOD) {
{
(*dstlist)->items[index].inuse = true; (*dstlist)->items[index].inuse = true;
(*dstlist)->items[index].dtype = srclist->items[i].dtype; (*dstlist)->items[index].dtype =
srclist->items[i].dtype;
if(srclist->items[i].dtype == t_int) if (srclist->items[i].dtype == t_int)
(*dstlist)->items[index].data.n = srclist->items[i].data.n; (*dstlist)->items[index].data.
else if(srclist->items[i].dtype == t_list) n =
retval = getdns_list_copy(srclist->items[index].data.list srclist->items[i].data.n;
, &((*dstlist)->items[i].data.list)); else if (srclist->items[i].dtype ==
else if(srclist->items[i].dtype == t_bindata) t_list)
{ retval =
(*dstlist)->items[i].data.bindata = (struct getdns_bindata *) getdns_list_copy(srclist->
malloc(sizeof(getdns_bindata)); items[index].data.list,
(*dstlist)->items[i].data.bindata->size = srclist->items[i].data.bindata->size; &((*dstlist)->items[i].
(*dstlist)->items[i].data.bindata->data = (uint8_t *) data.list));
malloc(srclist->items[i].data.bindata->size); else if (srclist->items[i].dtype ==
if((*dstlist)->items[i].data.bindata->data != NULL) t_bindata) {
memcpy((*dstlist)->items[i].data.bindata->data, (*dstlist)->items[i].data.
srclist->items[i].data.bindata->data bindata =
, srclist->items[i].data.bindata->size); (struct getdns_bindata *)
malloc(sizeof
(getdns_bindata));
(*dstlist)->items[i].data.
bindata->size =
srclist->items[i].data.
bindata->size;
(*dstlist)->items[i].data.
bindata->data = (uint8_t *)
malloc(srclist->items[i].
data.bindata->size);
if ((*dstlist)->items[i].data.
bindata->data != NULL)
memcpy((*dstlist)->
items[i].data.
bindata->data,
srclist->items[i].
data.bindata->data,
srclist->items[i].
data.bindata->
size);
else else
retval = GETDNS_RETURN_GENERIC_ERROR; retval =
GETDNS_RETURN_GENERIC_ERROR;
} else if (srclist->items[i].dtype ==
t_dict) {
retval =
getdns_dict_copy(srclist->
items[index].data.dict,
&((*dstlist)->items[i].
data.dict));
} }
else if (srclist->items[i].dtype == t_dict) } else {
{
retval = getdns_dict_copy(srclist->items[index].data.dict,
&((*dstlist)->items[i].data.dict));
}
}
else {
retval = GETDNS_RETURN_GENERIC_ERROR; retval = GETDNS_RETURN_GENERIC_ERROR;
getdns_list_destroy(*dstlist); getdns_list_destroy(*dstlist);
*dstlist = NULL; *dstlist = NULL;
} }
if(retval != GETDNS_RETURN_GOOD) if (retval != GETDNS_RETURN_GOOD)
break; break;
} }
} } else
else
retval = GETDNS_RETURN_GENERIC_ERROR; retval = GETDNS_RETURN_GENERIC_ERROR;
} }
@ -250,8 +265,7 @@ getdns_list_create()
struct getdns_list *list = NULL; struct getdns_list *list = NULL;
list = (struct getdns_list *) malloc(sizeof(struct getdns_list)); list = (struct getdns_list *) malloc(sizeof(struct getdns_list));
if(list != NULL) if (list != NULL) {
{
list->numalloc = 0; list->numalloc = 0;
list->numinuse = 0; list->numinuse = 0;
list->items = NULL; list->items = NULL;
@ -268,26 +282,22 @@ getdns_list_destroy(struct getdns_list *list)
{ {
int i; int i;
if(list != NULL) if (list != NULL) {
{ if (list->items != NULL) {
if(list->items != NULL) for (i = 0; i < list->numinuse; i++) {
{ if (list->items[i].dtype == t_list) {
for(i=0; i<list->numinuse; i++) if (list->items[i].dtype == t_list)
{ getdns_list_destroy(list->
if(list->items[i].dtype == t_list) items[i].data.list);
{ } else if (list->items[i].dtype == t_bindata) {
if(list->items[i].dtype == t_list) if (list->items[i].data.bindata->size >
getdns_list_destroy(list->items[i].data.list); 0)
} free(list->items[i].data.
else if(list->items[i].dtype == t_bindata) bindata->data);
{
if(list->items[i].data.bindata->size > 0)
free(list->items[i].data.bindata->data);
free(list->items[i].data.bindata); free(list->items[i].data.bindata);
} } else if (list->items[i].dtype == t_dict) {
else if(list->items[i].dtype == t_dict) getdns_dict_destroy(list->items[i].
{ data.dict);
getdns_dict_destroy(list->items[i].data.dict);
} }
} }
free(list->items); free(list->items);
@ -298,18 +308,16 @@ getdns_list_destroy(struct getdns_list *list)
/*---------------------------------------- getdns_list_add_item */ /*---------------------------------------- getdns_list_add_item */
getdns_return_t getdns_return_t
getdns_list_add_item(struct getdns_list *list, size_t *index) getdns_list_add_item(struct getdns_list *list, size_t * index)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && index != NULL) if (list != NULL && index != NULL) {
{ if (list->numalloc == list->numinuse)
if(list->numalloc == list->numinuse)
retval = getdns_list_realloc(list); retval = getdns_list_realloc(list);
else else
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
if(retval == GETDNS_RETURN_GOOD) if (retval == GETDNS_RETURN_GOOD) {
{
*index = list->numinuse; *index = list->numinuse;
list->items[*index].inuse = true; list->items[*index].inuse = true;
list->numinuse++; list->numinuse++;
@ -320,16 +328,17 @@ getdns_list_add_item(struct getdns_list *list, size_t *index)
/*---------------------------------------- getdns_list_set_dict */ /*---------------------------------------- getdns_list_set_dict */
getdns_return_t getdns_return_t
getdns_list_set_dict(struct getdns_list *list, size_t index, struct getdns_dict *child_dict) getdns_list_set_dict(struct getdns_list * list, size_t index,
struct getdns_dict * child_dict)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && child_dict != NULL) if (list != NULL && child_dict != NULL) {
{ if (list->numinuse > index) {
if(list->numinuse > index)
{
list->items[index].dtype = t_dict; list->items[index].dtype = t_dict;
retval = getdns_dict_copy(child_dict, &(list->items[index].data.dict)); retval =
getdns_dict_copy(child_dict,
&(list->items[index].data.dict));
} }
} }
@ -338,16 +347,17 @@ getdns_list_set_dict(struct getdns_list *list, size_t index, struct getdns_dict
/*---------------------------------------- getdns_set_list */ /*---------------------------------------- getdns_set_list */
getdns_return_t getdns_return_t
getdns_list_set_list(struct getdns_list *list, size_t index, struct getdns_list *child_list) getdns_list_set_list(struct getdns_list * list, size_t index,
struct getdns_list * child_list)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && child_list != NULL) if (list != NULL && child_list != NULL) {
{ if (list->numinuse > index) {
if(list->numinuse > index)
{
list->items[index].dtype = t_list; list->items[index].dtype = t_list;
retval = getdns_list_copy(child_list, &(list->items[index].data.list)); retval =
getdns_list_copy(child_list,
&(list->items[index].data.list));
} }
} }
@ -356,26 +366,27 @@ getdns_list_set_list(struct getdns_list *list, size_t index, struct getdns_list
/*---------------------------------------- getdns_list_set_bindata */ /*---------------------------------------- getdns_list_set_bindata */
getdns_return_t getdns_return_t
getdns_list_set_bindata(struct getdns_list *list, size_t index, struct getdns_bindata *child_bindata) getdns_list_set_bindata(struct getdns_list * list, size_t index,
struct getdns_bindata * child_bindata)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL && child_bindata != NULL) if (list != NULL && child_bindata != NULL) {
{ if (list->numinuse > index) {
if(list->numinuse > index)
{
list->items[index].dtype = t_bindata; list->items[index].dtype = t_bindata;
list->items[index].data.bindata = (struct getdns_bindata *) list->items[index].data.bindata =
(struct getdns_bindata *)
malloc(sizeof(struct getdns_bindata)); malloc(sizeof(struct getdns_bindata));
if(list->items[index].data.bindata != NULL) if (list->items[index].data.bindata != NULL) {
{ list->items[index].data.bindata->size =
list->items[index].data.bindata->size = child_bindata->size; child_bindata->size;
list->items[index].data.bindata->data = (uint8_t *) malloc(child_bindata->size list->items[index].data.bindata->data =
* sizeof(uint8_t)); (uint8_t *) malloc(child_bindata->size *
memcpy(list->items[index].data.bindata->data, child_bindata->data, child_bindata->size); sizeof(uint8_t));
memcpy(list->items[index].data.bindata->data,
child_bindata->data, child_bindata->size);
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;
} } else
else
retval = GETDNS_RETURN_GENERIC_ERROR; retval = GETDNS_RETURN_GENERIC_ERROR;
} }
} }
@ -385,14 +396,13 @@ getdns_list_set_bindata(struct getdns_list *list, size_t index, struct getdns_bi
/*---------------------------------------- getdns_list_set_int */ /*---------------------------------------- getdns_list_set_int */
getdns_return_t getdns_return_t
getdns_list_set_int(struct getdns_list *list, size_t index, uint32_t child_uint32) getdns_list_set_int(struct getdns_list * list, size_t index,
uint32_t child_uint32)
{ {
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM; getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(list != NULL) if (list != NULL) {
{ if (list->numinuse > index) {
if(list->numinuse > index)
{
list->items[index].dtype = t_int; list->items[index].dtype = t_int;
list->items[index].data.n = child_uint32; list->items[index].data.n = child_uint32;
retval = GETDNS_RETURN_GOOD; retval = GETDNS_RETURN_GOOD;

View File

@ -37,10 +37,12 @@
/** /**
* this structure represents a single item in a list * this structure represents a single item in a list
*/ */
struct getdns_list_item { struct getdns_list_item
{
int inuse; int inuse;
getdns_data_type dtype; getdns_data_type dtype;
union { union
{
getdns_list *list; getdns_list *list;
getdns_dict *dict; getdns_dict *dict;
int n; int n;
@ -57,11 +59,11 @@ struct getdns_list_item {
* The use cases do not justify working too hard at shrinking the structures. * The use cases do not justify working too hard at shrinking the structures.
* Indexes are 0 based. * Indexes are 0 based.
*/ */
struct getdns_list { struct getdns_list
{
int numalloc; int numalloc;
int numinuse; int numinuse;
struct getdns_list_item *items; struct getdns_list_item *items;
}; };
#endif #endif

View File

@ -42,7 +42,9 @@
#define gd_malloc(sz) context->memory_allocator(sz) #define gd_malloc(sz) context->memory_allocator(sz)
#define gd_free(ptr) context->memory_deallocator(ptr) #define gd_free(ptr) context->memory_deallocator(ptr)
void network_req_free(getdns_network_req* net_req) { void
network_req_free(getdns_network_req * net_req)
{
if (!net_req) { if (!net_req) {
return; return;
} }
@ -53,13 +55,14 @@ void network_req_free(getdns_network_req* net_req) {
gd_free(net_req); gd_free(net_req);
} }
getdns_network_req* network_req_new(getdns_dns_req* owner, getdns_network_req *
network_req_new(getdns_dns_req * owner,
uint16_t request_type, uint16_t request_type,
uint16_t request_class, uint16_t request_class, struct getdns_dict *extensions)
struct getdns_dict* extensions) { {
getdns_context_t context = owner->context; getdns_context_t context = owner->context;
getdns_network_req* net_req = gd_malloc(sizeof(getdns_network_req)); getdns_network_req *net_req = gd_malloc(sizeof(getdns_network_req));
if (!net_req) { if (!net_req) {
return NULL; return NULL;
} }
@ -77,7 +80,9 @@ getdns_network_req* network_req_new(getdns_dns_req* owner,
return net_req; return net_req;
} }
void dns_req_free(getdns_dns_req* req) { void
dns_req_free(getdns_dns_req * req)
{
if (!req) { if (!req) {
return; return;
} }
@ -113,12 +118,11 @@ void dns_req_free(getdns_dns_req* req) {
} }
/* create a new dns req to be submitted */ /* create a new dns req to be submitted */
getdns_dns_req* getdns_dns_req *
dns_req_new(getdns_context_t context, dns_req_new(getdns_context_t context,
struct ub_ctx* unbound, struct ub_ctx *unbound,
const char* name, const char *name, uint16_t request_type, struct getdns_dict *extensions)
uint16_t request_type, {
struct getdns_dict *extensions) {
getdns_dns_req *result = NULL; getdns_dns_req *result = NULL;
getdns_network_req *req = NULL; getdns_network_req *req = NULL;
@ -149,9 +153,7 @@ dns_req_new(getdns_context_t context,
/* create the requests */ /* create the requests */
req = network_req_new(result, req = network_req_new(result,
request_type, request_type, LDNS_RR_CLASS_IN, extensions);
LDNS_RR_CLASS_IN,
extensions);
if (!req) { if (!req) {
dns_req_free(result); dns_req_free(result);
return NULL; return NULL;
@ -162,15 +164,16 @@ dns_req_new(getdns_context_t context,
/* tack on A or AAAA if needed */ /* tack on A or AAAA if needed */
r = getdns_dict_get_int(extensions, r = getdns_dict_get_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, &both);
&both);
if (r == GETDNS_RETURN_GOOD && if (r == GETDNS_RETURN_GOOD &&
both == GETDNS_EXTENSION_TRUE && both == GETDNS_EXTENSION_TRUE &&
(request_type == GETDNS_RRTYPE_A || request_type == GETDNS_RRTYPE_AAAA)) { (request_type == GETDNS_RRTYPE_A
|| request_type == GETDNS_RRTYPE_AAAA)) {
uint16_t next_req_type = (request_type == GETDNS_RRTYPE_A) ? GETDNS_RRTYPE_AAAA : GETDNS_RRTYPE_A; uint16_t next_req_type =
getdns_network_req* next_req = (request_type ==
network_req_new(result, GETDNS_RRTYPE_A) ? GETDNS_RRTYPE_AAAA : GETDNS_RRTYPE_A;
getdns_network_req *next_req = network_req_new(result,
next_req_type, next_req_type,
LDNS_RR_CLASS_IN, LDNS_RR_CLASS_IN,
extensions); extensions);

View File

@ -38,18 +38,14 @@
* *
*/ */
getdns_return_t getdns_return_t
getdns_service( getdns_service(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict * extensions,
void *userarg, void *userarg,
getdns_transaction_t *transaction_id, getdns_transaction_t * transaction_id, getdns_callback_t callback)
getdns_callback_t callback
)
{ {
return getdns_general(context, name, GETDNS_RRTYPE_SRV, return getdns_general(context, name, GETDNS_RRTYPE_SRV,
extensions, userarg, transaction_id, extensions, userarg, transaction_id, callback);
callback);
} /* getdns_service */ } /* getdns_service */
/* getdns_core_only.c */ /* getdns_core_only.c */

View File

@ -44,24 +44,22 @@
/* stuff to make it compile pedantically */ /* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x)) #define UNUSED_PARAM(x) ((void)(x))
static void sync_callback_func(getdns_context_t context, static void
sync_callback_func(getdns_context_t context,
uint16_t callback_type, uint16_t callback_type,
struct getdns_dict *response, struct getdns_dict *response,
void *userarg, void *userarg, getdns_transaction_t transaction_id)
getdns_transaction_t transaction_id) { {
*((getdns_dict **)userarg) = response; *((getdns_dict **) userarg) = response;
} }
getdns_return_t getdns_return_t
getdns_general_sync( getdns_general_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
struct getdns_dict *extensions, struct getdns_dict *extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict **response)
struct getdns_dict **response
)
{ {
getdns_return_t response_status; getdns_return_t response_status;
@ -70,8 +68,7 @@ getdns_general_sync(
response_status = getdns_general_ub(context->unbound_sync, response_status = getdns_general_ub(context->unbound_sync,
context->event_base_sync, context->event_base_sync,
context, name, request_type, context, name, request_type,
extensions, (void *)response, extensions, (void *) response, NULL, sync_callback_func);
NULL, sync_callback_func);
event_base_dispatch(context->event_base_sync); event_base_dispatch(context->event_base_sync);
} }
@ -79,13 +76,10 @@ getdns_general_sync(
} }
getdns_return_t getdns_return_t
getdns_address_sync( getdns_address_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict * extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict ** response)
struct getdns_dict **response
)
{ {
int cleanup_extensions = 0; int cleanup_extensions = 0;
if (!extensions) { if (!extensions) {
@ -93,8 +87,7 @@ getdns_address_sync(
cleanup_extensions = 1; cleanup_extensions = 1;
} }
getdns_dict_set_int(extensions, getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_EXTENSION_TRUE);
GETDNS_EXTENSION_TRUE);
getdns_return_t result = getdns_return_t result =
getdns_general_sync(context, name, GETDNS_RRTYPE_A, getdns_general_sync(context, name, GETDNS_RRTYPE_A,
@ -106,13 +99,10 @@ getdns_address_sync(
} }
getdns_return_t getdns_return_t
getdns_hostname_sync( getdns_hostname_sync(getdns_context_t context,
getdns_context_t context, struct getdns_dict * address,
struct getdns_dict *address, struct getdns_dict * extensions,
struct getdns_dict *extensions, uint32_t * response_length, struct getdns_dict ** response)
uint32_t *response_length,
struct getdns_dict **response
)
{ {
struct getdns_bindata *address_data; struct getdns_bindata *address_data;
struct getdns_bindata *address_type; struct getdns_bindata *address_type;
@ -120,43 +110,43 @@ getdns_hostname_sync(
char *name; char *name;
getdns_return_t retval; getdns_return_t retval;
if ((retval =
if ((retval = getdns_dict_get_bindata(address, "address_data", &address_data)) != GETDNS_RETURN_GOOD) getdns_dict_get_bindata(address, "address_data",
&address_data)) != GETDNS_RETURN_GOOD)
return retval; return retval;
if ((retval = getdns_dict_get_bindata(address, "address_type", &address_type)) != GETDNS_RETURN_GOOD) if ((retval =
getdns_dict_get_bindata(address, "address_type",
&address_type)) != GETDNS_RETURN_GOOD)
return retval; return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *)address_type->data, strlen(GETDNS_STR_IPV4)) == 0) || if ((strncmp(GETDNS_STR_IPV4, (char *) address_type->data,
(strncmp(GETDNS_STR_IPV6, (char *)address_type->data, strlen(GETDNS_STR_IPV6)) == 0)) strlen(GETDNS_STR_IPV4)) == 0)
|| (strncmp(GETDNS_STR_IPV6, (char *) address_type->data,
strlen(GETDNS_STR_IPV6)) == 0))
req_type = GETDNS_RRTYPE_PTR; req_type = GETDNS_RRTYPE_PTR;
else else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED; return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *)address_data)) == 0) if ((name = reverse_address((char *) address_data)) == 0)
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general_sync(context, name, req_type, extensions, return getdns_general_sync(context, name, req_type, extensions,
response_length, response); response_length, response);
} }
getdns_return_t getdns_return_t
getdns_service_sync( getdns_service_sync(getdns_context_t context,
getdns_context_t context,
const char *name, const char *name,
struct getdns_dict *extensions, struct getdns_dict * extensions,
uint32_t *response_length, uint32_t * response_length, struct getdns_dict ** response)
struct getdns_dict **response
)
{ {
return getdns_general_sync(context, name, GETDNS_RRTYPE_SRV, extensions, return getdns_general_sync(context, name, GETDNS_RRTYPE_SRV,
response_length, response); extensions, response_length, response);
} }
void void
getdns_free_sync_request_memory( getdns_free_sync_request_memory(struct getdns_dict *response)
struct getdns_dict *response
)
{ {
getdns_dict_destroy(response); getdns_dict_destroy(response);
} }
/* getdns_core_sync.c */ /* getdns_core_sync.c */

View File

@ -37,8 +37,8 @@ static int ncases = 0;
void void
tstmsg_prog_begin(char *prognm) tstmsg_prog_begin(char *prognm)
{ {
if(testprog != NULL) if (testprog != NULL) {
{ tstmsg_prog_end(); tstmsg_prog_end();
free(testprog); free(testprog);
} }
testprog = strdup(prognm); testprog = strdup(prognm);
@ -57,21 +57,21 @@ tstmsg_case_begin(char *casenm)
{ {
ncases++; ncases++;
cases = (char **) realloc(cases, sizeof(char *) * ncases); cases = (char **) realloc(cases, sizeof(char *) * ncases);
cases[ncases-1] = strdup(casenm); cases[ncases - 1] = strdup(casenm);
printf("TESTCASE %s:%s BEGIN\n", testprog, cases[ncases-1]); printf("TESTCASE %s:%s BEGIN\n", testprog, cases[ncases - 1]);
} /* tstmsg_case_begin */ } /* tstmsg_case_begin */
void void
tstmsg_case_end(void) tstmsg_case_end(void)
{ {
if(ncases > 0) if (ncases > 0) {
{ printf("TESTCASE %s:%s END\n", testprog, cases[ncases - 1]);
printf("TESTCASE %s:%s END\n", testprog, cases[ncases-1]);
ncases--; ncases--;
free(cases[ncases]); free(cases[ncases]);
if (ncases) { if (ncases) {
cases = (char **) realloc(cases, sizeof(char *) * ncases); cases =
(char **) realloc(cases, sizeof(char *) * ncases);
} else { } else {
cases = NULL; cases = NULL;
} }
@ -81,7 +81,7 @@ tstmsg_case_end(void)
void void
tstmsg_case_msg(char *msg) tstmsg_case_msg(char *msg)
{ {
printf(" %s:%s: %s\n", testprog, cases[ncases-1], msg); printf(" %s:%s: %s\n", testprog, cases[ncases - 1], msg);
} /* tstmsg_case_msg */ } /* tstmsg_case_msg */
/* testmessages.c */ /* testmessages.c */

View File

@ -58,21 +58,27 @@ tst_bindatasetget(void)
tstmsg_case_msg("getdns_dict_get_bindata() empty dict"); tstmsg_case_msg("getdns_dict_get_bindata() empty dict");
retval = getdns_dict_get_bindata(NULL, key, &ans_bdata); retval = getdns_dict_get_bindata(NULL, key, &ans_bdata);
sprintf(msg, "line %d: getdns_dict_get_bindata(NULL, key, &ans_bdata),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_bindata(NULL, key, &ans_bdata),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_dict_get_bindata(dict, key, NULL); retval = getdns_dict_get_bindata(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_bindata(dict, key, NULL),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_bindata(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata(dict, NULL, &ans_bindata)"); tstmsg_case_msg("getdns_dict_get_bindata(dict, NULL, &ans_bindata)");
retval = getdns_dict_get_bindata(dict, NULL, &ans_bdata); retval = getdns_dict_get_bindata(dict, NULL, &ans_bdata);
sprintf(msg, "line %d: getdns_dict_get_bindata,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_dict_get_bindata,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata(dict, key, &ans_bdata)"); tstmsg_case_msg("getdns_dict_get_bindata(dict, key, &ans_bdata)");
retval = getdns_dict_get_bindata(dict, key, &ans_bdata); retval = getdns_dict_get_bindata(dict, key, &ans_bdata);
sprintf(msg, "line %d: getdns_list_get_bindata,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_list_get_bindata,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -84,18 +90,22 @@ tst_bindatasetget(void)
dict = getdns_dict_create(); dict = getdns_dict_create();
strcpy(key, "foo"); strcpy(key, "foo");
bindata = (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata)); bindata =
(struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
bindata->size = strlen("foobar") + 1; bindata->size = strlen("foobar") + 1;
bindata->data = (void *) strdup("foobar"); bindata->data = (void *) strdup("foobar");
tstmsg_case_msg("getdns_dict_set_bindata(dict, key, bindata)"); tstmsg_case_msg("getdns_dict_set_bindata(dict, key, bindata)");
retval = getdns_dict_set_bindata(dict, key, bindata); retval = getdns_dict_set_bindata(dict, key, bindata);
sprintf(msg, "line %d: getdns_dict_set_bindata,retval=%d,key=%s", __LINE__, retval, key); sprintf(msg, "line %d: getdns_dict_set_bindata,retval=%d,key=%s",
__LINE__, retval, key);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata(dict, key, &ans_bdata)"); tstmsg_case_msg("getdns_dict_get_bindata(dict, key, &ans_bdata)");
retval = getdns_dict_get_bindata(dict, key, &ans_bdata); retval = getdns_dict_get_bindata(dict, key, &ans_bdata);
sprintf(msg, "line %d: getdns_dict_get_bindata,retval=%d,key=%s,data=%s", __LINE__, retval, key, ans_bdata->data); sprintf(msg,
"line %d: getdns_dict_get_bindata,retval=%d,key=%s,data=%s",
__LINE__, retval, key, ans_bdata->data);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -133,21 +143,27 @@ tst_dictsetget(void)
tstmsg_case_msg("getdns_dict_get_dict() empty dict"); tstmsg_case_msg("getdns_dict_get_dict() empty dict");
retval = getdns_dict_get_dict(NULL, key, &ansdict); retval = getdns_dict_get_dict(NULL, key, &ansdict);
sprintf(msg, "line %d: getdns_dict_get_dict(NULL, key, &ansdict),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_dict(NULL, key, &ansdict),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_dict_get_dict(dict, key, NULL); retval = getdns_dict_get_dict(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_dict(dict, key, NULL),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_dict(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_dict(dict, NULL, &ansdict)"); tstmsg_case_msg("getdns_dict_get_dict(dict, NULL, &ansdict)");
retval = getdns_dict_get_dict(dict, NULL, &ansdict); retval = getdns_dict_get_dict(dict, NULL, &ansdict);
sprintf(msg, "line %d: getdns_dict_get_dict,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_dict_get_dict,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_dict(dict, key, &ansdict)"); tstmsg_case_msg("getdns_dict_get_dict(dict, key, &ansdict)");
retval = getdns_dict_get_dict(dict, key, &ansdict); retval = getdns_dict_get_dict(dict, key, &ansdict);
sprintf(msg, "line %d: getdns_list_get_dict,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_list_get_dict,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -165,7 +181,8 @@ tst_dictsetget(void)
tstmsg_case_msg("getdns_dict_set_dict(dict, key, newdict)"); tstmsg_case_msg("getdns_dict_set_dict(dict, key, newdict)");
retval = getdns_dict_set_dict(dict, key, newdict); retval = getdns_dict_set_dict(dict, key, newdict);
sprintf(msg, "line %d: getdns_dict_set_dict,retval=%d,key=%s", __LINE__, retval, key); sprintf(msg, "line %d: getdns_dict_set_dict,retval=%d,key=%s",
__LINE__, retval, key);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(newdict); getdns_dict_destroy(newdict);
@ -173,8 +190,9 @@ tst_dictsetget(void)
retval = getdns_dict_get_dict(dict, key, &ansdict); retval = getdns_dict_get_dict(dict, key, &ansdict);
getdns_dict_get_int(ansdict, "foo", &int1); getdns_dict_get_int(ansdict, "foo", &int1);
getdns_dict_get_int(ansdict, "bar", &int2); getdns_dict_get_int(ansdict, "bar", &int2);
sprintf(msg, "line %d: getdns_dict_get_dict,retval=%d,key=%s,int1=%d,int2=%d" sprintf(msg,
, __LINE__, retval, key, int1, int2); "line %d: getdns_dict_get_dict,retval=%d,key=%s,int1=%d,int2=%d",
__LINE__, retval, key, int1, int2);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -213,7 +231,8 @@ tst_getnames(void)
tstmsg_case_msg("getdns_dict_get_names(dict, NULL)"); tstmsg_case_msg("getdns_dict_get_names(dict, NULL)");
getdns_dict_get_names(dict, NULL); getdns_dict_get_names(dict, NULL);
tstmsg_case_msg("getdns_dict_get_names(dict, &list), empty dictionary"); tstmsg_case_msg
("getdns_dict_get_names(dict, &list), empty dictionary");
getdns_dict_get_names(dict, &list); getdns_dict_get_names(dict, &list);
getdns_list_destroy(list); getdns_list_destroy(list);
@ -229,18 +248,16 @@ tst_getnames(void)
getdns_dict_get_names(dict, &list); getdns_dict_get_names(dict, &list);
result = getdns_list_get_length(list, &llen); result = getdns_list_get_length(list, &llen);
if(llen != i) if (llen != i) {
{ tstmsg_case_msg
tstmsg_case_msg("getdns_list_get_length returned unreasonable length, exiting"); ("getdns_list_get_length returned unreasonable length, exiting");
return; return;
} }
for(index=0; index<llen; index++) for (index = 0; index < llen; index++) {
{
getdns_list_get_data_type(list, index, &dtype); getdns_list_get_data_type(list, index, &dtype);
printf(" list item %d: ", (int) index); printf(" list item %d: ", (int) index);
switch(dtype) switch (dtype) {
{
case t_bindata: case t_bindata:
printf("NOTIMPLEMENTED"); printf("NOTIMPLEMENTED");
break; break;
@ -297,21 +314,27 @@ tst_listsetget(void)
tstmsg_case_msg("getdns_dict_get_list() empty dict"); tstmsg_case_msg("getdns_dict_get_list() empty dict");
retval = getdns_dict_get_list(NULL, key, &anslist); retval = getdns_dict_get_list(NULL, key, &anslist);
sprintf(msg, "line %d: getdns_dict_get_list(NULL, key, &anslist),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_list(NULL, key, &anslist),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_dict_get_list(dict, key, NULL); retval = getdns_dict_get_list(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_list(dict, key, NULL),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_list(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_list(dict, NULL, &anslist)"); tstmsg_case_msg("getdns_dict_get_list(dict, NULL, &anslist)");
retval = getdns_dict_get_list(dict, NULL, &anslist); retval = getdns_dict_get_list(dict, NULL, &anslist);
sprintf(msg, "line %d: getdns_dict_get_list,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_dict_get_list,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_list(dict, key, &anslist)"); tstmsg_case_msg("getdns_dict_get_list(dict, key, &anslist)");
retval = getdns_dict_get_list(dict, key, &anslist); retval = getdns_dict_get_list(dict, key, &anslist);
sprintf(msg, "line %d: getdns_list_get_list,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_list_get_list,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -331,7 +354,8 @@ tst_listsetget(void)
tstmsg_case_msg("getdns_dict_set_list(dict, key, newlist)"); tstmsg_case_msg("getdns_dict_set_list(dict, key, newlist)");
retval = getdns_dict_set_list(dict, key, newlist); retval = getdns_dict_set_list(dict, key, newlist);
sprintf(msg, "line %d: getdns_dict_set_list,retval=%d,key=%s", __LINE__, retval, key); sprintf(msg, "line %d: getdns_dict_set_list,retval=%d,key=%s",
__LINE__, retval, key);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_list_destroy(newlist); getdns_list_destroy(newlist);
@ -339,8 +363,9 @@ tst_listsetget(void)
retval = getdns_dict_get_list(dict, key, &anslist); retval = getdns_dict_get_list(dict, key, &anslist);
getdns_list_get_int(anslist, 0, &int1); getdns_list_get_int(anslist, 0, &int1);
getdns_list_get_int(anslist, 1, &int2); getdns_list_get_int(anslist, 1, &int2);
sprintf(msg, "line %d: getdns_dict_get_list,retval=%d,key=%s,int1=%d,int2=%d" sprintf(msg,
, __LINE__, retval, key, int1, int2); "line %d: getdns_dict_get_list,retval=%d,key=%s,int1=%d,int2=%d",
__LINE__, retval, key, int1, int2);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -375,21 +400,27 @@ tst_intsetget(void)
tstmsg_case_msg("getdns_dict_get_int() empty dict"); tstmsg_case_msg("getdns_dict_get_int() empty dict");
retval = getdns_dict_get_int(NULL, key, &ans_int); retval = getdns_dict_get_int(NULL, key, &ans_int);
sprintf(msg, "line %d: getdns_dict_get_int(NULL, key, &ans_int),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_int(NULL, key, &ans_int),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_dict_get_int(dict, key, NULL); retval = getdns_dict_get_int(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_int(dict, key, NULL),retval = %d", __LINE__, retval); sprintf(msg,
"line %d: getdns_dict_get_int(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_int(dict, NULL, &ans_int)"); tstmsg_case_msg("getdns_dict_get_int(dict, NULL, &ans_int)");
retval = getdns_dict_get_int(dict, NULL, &ans_int); retval = getdns_dict_get_int(dict, NULL, &ans_int);
sprintf(msg, "line %d: getdns_dict_get_int,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_dict_get_int,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)"); tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)");
retval = getdns_dict_get_int(dict, key, &ans_int); retval = getdns_dict_get_int(dict, key, &ans_int);
sprintf(msg, "line %d: getdns_list_get_int,retval = %d", __LINE__, retval); sprintf(msg, "line %d: getdns_list_get_int,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -405,29 +436,35 @@ tst_intsetget(void)
tstmsg_case_msg("getdns_dict_set_int(dict, key, newint)"); tstmsg_case_msg("getdns_dict_set_int(dict, key, newint)");
retval = getdns_dict_set_int(dict, key, newint); retval = getdns_dict_set_int(dict, key, newint);
sprintf(msg, "line %d: getdns_dict_set_int,retval=%d,key=%s,int=%d", __LINE__, retval, key, newint); sprintf(msg, "line %d: getdns_dict_set_int,retval=%d,key=%s,int=%d",
__LINE__, retval, key, newint);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)"); tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)");
retval = getdns_dict_get_int(dict, key, &ans_int); retval = getdns_dict_get_int(dict, key, &ans_int);
sprintf(msg, "line %d: getdns_dict_get_int,retval=%d,key=%s,int=%d", __LINE__, retval, key, ans_int); sprintf(msg, "line %d: getdns_dict_get_int,retval=%d,key=%s,int=%d",
__LINE__, retval, key, ans_int);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
strcpy(key, "bar"); strcpy(key, "bar");
newint = 52; newint = 52;
tstmsg_case_msg("getdns_dict_set_int(dict, key, newint)"); tstmsg_case_msg("getdns_dict_set_int(dict, key, newint)");
retval = getdns_dict_set_int(dict, key, newint); retval = getdns_dict_set_int(dict, key, newint);
sprintf(msg, "line %d: getdns_dict_set_int,retval=%d,key=%s,int=%d", __LINE__, retval, key, newint); sprintf(msg, "line %d: getdns_dict_set_int,retval=%d,key=%s,int=%d",
__LINE__, retval, key, newint);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)"); tstmsg_case_msg("getdns_dict_get_int(dict, key, &ans_int)");
retval = getdns_dict_get_int(dict, key, &ans_int); retval = getdns_dict_get_int(dict, key, &ans_int);
sprintf(msg, "line %d: getdns_dict_get_int,retval=%d,key=%s,int=%d", __LINE__, retval, key, ans_int); sprintf(msg, "line %d: getdns_dict_get_int,retval=%d,key=%s,int=%d",
__LINE__, retval, key, ans_int);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_data_type(dict, key, &dtype)"); tstmsg_case_msg("getdns_dict_get_data_type(dict, key, &dtype)");
retval = getdns_dict_get_data_type(dict, key, &dtype); retval = getdns_dict_get_data_type(dict, key, &dtype);
sprintf(msg, "line %d: getdns_dict_get_data_type,retval=%d,key=%s,dtype=%d", __LINE__, retval, key, dtype); sprintf(msg,
"line %d: getdns_dict_get_data_type,retval=%d,key=%s,dtype=%d",
__LINE__, retval, key, dtype);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -500,8 +537,7 @@ tst_create(void)
tstmsg_case_msg("getdns_dict_create"); tstmsg_case_msg("getdns_dict_create");
dict = getdns_dict_create(); dict = getdns_dict_create();
if(dict != NULL) if (dict != NULL) {
{
tstmsg_case_msg("getdns_dict_destroy(dict)"); tstmsg_case_msg("getdns_dict_destroy(dict)");
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
} }

View File

@ -60,12 +60,14 @@ tst_bindatasetget(void)
tstmsg_case_msg("getdns_list_get_bindata() empty list"); tstmsg_case_msg("getdns_list_get_bindata() empty list");
retval = getdns_list_get_bindata(NULL, index, &ans_bindata); retval = getdns_list_get_bindata(NULL, index, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata(NULL, index, &ans_bindata),retval = %d" sprintf(msg,
, retval); "getdns_list_get_bindata(NULL, index, &ans_bindata),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_list_get_bindata(list, index, NULL); retval = getdns_list_get_bindata(list, index, NULL);
sprintf(msg, "getdns_list_get_bindata(list, index, NULL),retval = %d", retval); sprintf(msg, "getdns_list_get_bindata(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata(list, 0, &ans_bindata)"); tstmsg_case_msg("getdns_list_get_bindata(list, 0, &ans_bindata)");
@ -82,7 +84,9 @@ tst_bindatasetget(void)
tstmsg_case_msg("getdns_list_set_bindata() empty list"); tstmsg_case_msg("getdns_list_set_bindata() empty list");
retval = getdns_list_set_bindata(NULL, index, NULL); retval = getdns_list_set_bindata(NULL, index, NULL);
sprintf(msg, "getdns_list_set_bindata(NULL, index, ans_bindata),retval = %d", retval); sprintf(msg,
"getdns_list_set_bindata(NULL, index, ans_bindata),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata(list, 0, ans_bindata)"); tstmsg_case_msg("getdns_list_set_bindata(list, 0, ans_bindata)");
@ -97,7 +101,8 @@ tst_bindatasetget(void)
/* test set and get legitimate use case */ /* test set and get legitimate use case */
new_bindata = (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata)); new_bindata =
(struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
new_bindata->size = strlen("foobar") + 1; new_bindata->size = strlen("foobar") + 1;
new_bindata->data = (uint8_t *) strdup("foobar"); new_bindata->data = (uint8_t *) strdup("foobar");
new_bindata->data[strlen("foobar")] = '\0'; new_bindata->data[strlen("foobar")] = '\0';
@ -105,8 +110,9 @@ tst_bindatasetget(void)
getdns_list_add_item(list, &index); getdns_list_add_item(list, &index);
getdns_list_set_bindata(list, index, new_bindata); getdns_list_set_bindata(list, index, new_bindata);
retval = getdns_list_get_bindata(list, index, &ans_bindata); retval = getdns_list_get_bindata(list, index, &ans_bindata);
sprintf(msg, "getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s" sprintf(msg,
, retval, (int) ans_bindata->size, (char *) ans_bindata->data); "getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s",
retval, (int) ans_bindata->size, (char *) ans_bindata->data);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_list_destroy(list); getdns_list_destroy(list);
@ -140,11 +146,13 @@ tst_dictsetget(void)
tstmsg_case_msg("getdns_list_get_dict() empty list"); tstmsg_case_msg("getdns_list_get_dict() empty list");
retval = getdns_list_get_dict(NULL, index, &dict); retval = getdns_list_get_dict(NULL, index, &dict);
sprintf(msg, "getdns_list_get_dict(NULL, index, &dict),retval = %d", retval); sprintf(msg, "getdns_list_get_dict(NULL, index, &dict),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_list_get_dict(list, index, NULL); retval = getdns_list_get_dict(list, index, NULL);
sprintf(msg, "getdns_list_get_dict(list, index, NULL),retval = %d", retval); sprintf(msg, "getdns_list_get_dict(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict(list, 0, &dict)"); tstmsg_case_msg("getdns_list_get_dict(list, 0, &dict)");
@ -161,7 +169,8 @@ tst_dictsetget(void)
tstmsg_case_msg("getdns_list_set_dict() empty list"); tstmsg_case_msg("getdns_list_set_dict() empty list");
retval = getdns_list_set_dict(NULL, index, dict); retval = getdns_list_set_dict(NULL, index, dict);
sprintf(msg, "getdns_list_set_dict(NULL, index, dict),retval = %d", retval); sprintf(msg, "getdns_list_set_dict(NULL, index, dict),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict(list, 0, dict)"); tstmsg_case_msg("getdns_list_set_dict(list, 0, dict)");
@ -181,7 +190,8 @@ tst_dictsetget(void)
getdns_list_set_dict(list, index, dict); getdns_list_set_dict(list, index, dict);
retval = getdns_list_get_dict(list, index, &ansdict); retval = getdns_list_get_dict(list, index, &ansdict);
getdns_dict_get_int(ansdict, "foo", &ans_int); getdns_dict_get_int(ansdict, "foo", &ans_int);
sprintf(msg, "getdns_list_set/get_dict,retval=%d, ans=%d", retval, ans_int); sprintf(msg, "getdns_list_set/get_dict,retval=%d, ans=%d", retval,
ans_int);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_dict_destroy(dict); getdns_dict_destroy(dict);
@ -215,11 +225,14 @@ tst_listsetget(void)
tstmsg_case_msg("getdns_list_get_list() empty list"); tstmsg_case_msg("getdns_list_get_list() empty list");
retval = getdns_list_get_list(NULL, index, &ans_list); retval = getdns_list_get_list(NULL, index, &ans_list);
sprintf(msg, "getdns_list_get_list(NULL, index, &ans_list),retval = %d", retval); sprintf(msg,
"getdns_list_get_list(NULL, index, &ans_list),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_list_get_list(list, index, NULL); retval = getdns_list_get_list(list, index, NULL);
sprintf(msg, "getdns_list_get_list(list, index, NULL),retval = %d", retval); sprintf(msg, "getdns_list_get_list(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list(list, 0, &ans_list)"); tstmsg_case_msg("getdns_list_get_list(list, 0, &ans_list)");
@ -236,7 +249,8 @@ tst_listsetget(void)
tstmsg_case_msg("getdns_list_set_list() empty list"); tstmsg_case_msg("getdns_list_set_list() empty list");
retval = getdns_list_set_list(NULL, index, NULL); retval = getdns_list_set_list(NULL, index, NULL);
sprintf(msg, "getdns_list_set_list(NULL, index, ans_list),retval = %d", retval); sprintf(msg, "getdns_list_set_list(NULL, index, ans_list),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list(list, 0, ans_list)"); tstmsg_case_msg("getdns_list_set_list(list, 0, ans_list)");
@ -259,7 +273,8 @@ tst_listsetget(void)
getdns_list_set_list(list, index, new_list); getdns_list_set_list(list, index, new_list);
retval = getdns_list_get_list(list, index, &ans_list); retval = getdns_list_get_list(list, index, &ans_list);
getdns_list_get_int(ans_list, 0, &ans_int); getdns_list_get_int(ans_list, 0, &ans_int);
sprintf(msg, "getdns_list_set/get_list,retval = %d, ans[0] = %d", retval, ans_int); sprintf(msg, "getdns_list_set/get_list,retval = %d, ans[0] = %d",
retval, ans_int);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_list_destroy(list); getdns_list_destroy(list);
@ -290,11 +305,13 @@ tst_intsetget(void)
tstmsg_case_msg("getdns_list_get_int() empty list"); tstmsg_case_msg("getdns_list_get_int() empty list");
retval = getdns_list_get_int(NULL, index, &ans_int); retval = getdns_list_get_int(NULL, index, &ans_int);
sprintf(msg, "getdns_list_get_int(NULL, index, &ans_int),retval = %d", retval); sprintf(msg, "getdns_list_get_int(NULL, index, &ans_int),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
retval = getdns_list_get_int(list, index, NULL); retval = getdns_list_get_int(list, index, NULL);
sprintf(msg, "getdns_list_get_int(list, index, NULL),retval = %d", retval); sprintf(msg, "getdns_list_get_int(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int(list, 0, &ans_int)"); tstmsg_case_msg("getdns_list_get_int(list, 0, &ans_int)");
@ -311,7 +328,8 @@ tst_intsetget(void)
tstmsg_case_msg("getdns_list_set_int() empty list"); tstmsg_case_msg("getdns_list_set_int() empty list");
retval = getdns_list_set_int(NULL, index, ans_int); retval = getdns_list_set_int(NULL, index, ans_int);
sprintf(msg, "getdns_list_set_int(NULL, index, ans_int),retval = %d", retval); sprintf(msg, "getdns_list_set_int(NULL, index, ans_int),retval = %d",
retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int(list, 0, ans_int)"); tstmsg_case_msg("getdns_list_set_int(list, 0, ans_int)");
@ -329,7 +347,8 @@ tst_intsetget(void)
getdns_list_add_item(list, &index); getdns_list_add_item(list, &index);
getdns_list_set_int(list, index, 42); getdns_list_set_int(list, index, 42);
retval = getdns_list_get_int(list, index, &ans_int); retval = getdns_list_get_int(list, index, &ans_int);
sprintf(msg, "getdns_list_set/get_int,retval = %d, ans = %d", retval, ans_int); sprintf(msg, "getdns_list_set/get_int,retval = %d, ans = %d", retval,
ans_int);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
getdns_list_destroy(list); getdns_list_destroy(list);
@ -359,8 +378,7 @@ tst_create(void)
tstmsg_case_msg("getdns_list_create"); tstmsg_case_msg("getdns_list_create");
list = getdns_list_create(); list = getdns_list_create();
if(list != NULL) if (list != NULL) {
{
tstmsg_case_msg("getdns_list_destroy(list)"); tstmsg_case_msg("getdns_list_destroy(list)");
getdns_list_destroy(list); getdns_list_destroy(list);
} }
@ -372,20 +390,17 @@ tst_create(void)
tstmsg_case_msg("getdns_add_item(list) past block size"); tstmsg_case_msg("getdns_add_item(list) past block size");
list = getdns_list_create(); list = getdns_list_create();
for(i=0; i<GETDNS_LIST_BLOCKSZ+2; i++) for (i = 0; i < GETDNS_LIST_BLOCKSZ + 2; i++) {
{
retval = getdns_list_add_item(list, &index); retval = getdns_list_add_item(list, &index);
if(retval != GETDNS_RETURN_GOOD) if (retval != GETDNS_RETURN_GOOD) {
{ sprintf(msg, "getdns_list_add_item,i=%d,retval = %d",
sprintf(msg, "getdns_list_add_item,i=%d,retval = %d", i, retval); i, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
} } else {
else if (index != i) {
{ sprintf(msg,
if(index != i) "getdns_list_add_item,i=%d,index=%d,retval = %d",
{ i, (int) index, retval);
sprintf(msg, "getdns_list_add_item,i=%d,index=%d,retval = %d"
, i, (int) index, retval);
tstmsg_case_msg(msg); tstmsg_case_msg(msg);
} }
} }

View File

@ -34,23 +34,25 @@
#include <event2/event.h> #include <event2/event.h>
/* Set up the callback function, which will also do the processing of the results */ /* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context, void
this_callbackfn(struct getdns_context_t *this_context,
uint16_t this_callback_type, uint16_t this_callback_type,
struct getdns_dict *this_response, struct getdns_dict *this_response,
void *this_userarg, void *this_userarg, getdns_transaction_t this_transaction_id)
getdns_transaction_t this_transaction_id)
{ {
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */ if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
{ char *res = getdns_pretty_print_dict(this_response);
char* res = getdns_pretty_print_dict(this_response);
fprintf(stdout, "%s", res); fprintf(stdout, "%s", res);
getdns_dict_destroy(this_response); getdns_dict_destroy(this_response);
} } else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
else if (this_callback_type == GETDNS_CALLBACK_CANCEL) fprintf(stderr,
fprintf(stderr, "The callback with ID %lld was cancelled. Exiting.", this_transaction_id); "The callback with ID %lld was cancelled. Exiting.",
this_transaction_id);
else else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type); fprintf(stderr,
"The callback got a callback_type of %d. Exiting.",
this_callback_type);
} }
int int
@ -58,11 +60,12 @@ main()
{ {
/* Create the DNS context for this call */ /* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL; struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true); getdns_return_t context_create_return =
if (context_create_return != GETDNS_RETURN_GOOD) 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); fprintf(stderr, "Trying to create the context failed: %d",
return(GETDNS_RETURN_GENERIC_ERROR); context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB); getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
@ -70,24 +73,25 @@ main()
/* Create an event base and put it in the context using the unknown function name */ /* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base; struct event_base *this_event_base;
this_event_base = event_base_new(); this_event_base = event_base_new();
if (this_event_base == NULL) if (this_event_base == NULL) {
{
fprintf(stderr, "Trying to create the event base failed."); fprintf(stderr, "Trying to create the event base failed.");
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} }
(void)getdns_extension_set_libevent_base(this_context, this_event_base); (void) getdns_extension_set_libevent_base(this_context,
this_event_base);
/* Set up the getdns call */ /* Set up the getdns call */
const char * this_name = "www.google.com"; const char *this_name = "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
getdns_transaction_t this_transaction_id = 0; getdns_transaction_t this_transaction_id = 0;
/* Make the call */ /* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name, getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn); NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
{ fprintf(stderr, "A bad domain name was used: %s. Exiting.",
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name); this_name);
return(GETDNS_RETURN_GENERIC_ERROR); return (GETDNS_RETURN_GENERIC_ERROR);
} }
// dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id, // dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id,
// this_callbackfn); // this_callbackfn);
@ -96,8 +100,7 @@ main()
// fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name); // fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
// return(GETDNS_RETURN_GENERIC_ERROR); // return(GETDNS_RETURN_GENERIC_ERROR);
// } // }
else else {
{
/* Call the event loop */ /* Call the event loop */
event_base_dispatch(this_event_base); event_base_dispatch(this_event_base);
// TODO: check the return value above // TODO: check the return value above
@ -109,4 +112,3 @@ main()
} /* main */ } /* main */
/* example-simple-answers.c */ /* example-simple-answers.c */

View File

@ -32,7 +32,9 @@
#include "testmessages.h" #include "testmessages.h"
#include <getdns/getdns.h> #include <getdns/getdns.h>
static void print_response(getdns_dict* response) { static void
print_response(getdns_dict * response)
{
char *dict_str = getdns_pretty_print_dict(response); char *dict_str = getdns_pretty_print_dict(response);
if (dict_str) { if (dict_str) {
fprintf(stdout, "The packet %s\n", dict_str); fprintf(stdout, "The packet %s\n", dict_str);
@ -40,21 +42,25 @@ static void print_response(getdns_dict* response) {
} }
} }
int main() int
main()
{ {
/* Create the DNS context for this call */ /* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL; struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true); getdns_return_t context_create_return =
if (context_create_return != GETDNS_RETURN_GOOD) 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); fprintf(stderr, "Trying to create the context failed: %d",
return(GETDNS_RETURN_GENERIC_ERROR); context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
} }
getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB); getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
getdns_dict* response = NULL; getdns_dict *response = NULL;
uint32_t responseLen = 0; uint32_t responseLen = 0;
getdns_return_t ret = getdns_address_sync(this_context, "www.google.com", NULL, &responseLen, &response); getdns_return_t ret =
getdns_address_sync(this_context, "www.google.com", NULL,
&responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) { if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Address sync returned error.\n"); fprintf(stderr, "Address sync returned error.\n");
@ -63,7 +69,9 @@ int main()
print_response(response); print_response(response);
getdns_dict_destroy(response); getdns_dict_destroy(response);
ret = getdns_service_sync(this_context, "www.google.com", NULL, &responseLen, &response); ret =
getdns_service_sync(this_context, "www.google.com", NULL,
&responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) { if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Service sync returned error.\n"); fprintf(stderr, "Service sync returned error.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -78,4 +86,3 @@ int main()
} /* main */ } /* main */
/* example-simple-answers.c */ /* example-simple-answers.c */

View File

@ -46,7 +46,8 @@ struct ub_ctx;
struct event; struct event;
struct event_base; struct event_base;
typedef enum network_req_state_enum { typedef enum network_req_state_enum
{
NET_REQ_NOT_SENT, NET_REQ_NOT_SENT,
NET_REQ_IN_FLIGHT, NET_REQ_IN_FLIGHT,
NET_REQ_FINISHED, NET_REQ_FINISHED,
@ -56,7 +57,8 @@ typedef enum network_req_state_enum {
/** /**
* structure used by validate_extensions() to check extension formats * structure used by validate_extensions() to check extension formats
*/ */
typedef struct getdns_extension_format { typedef struct getdns_extension_format
{
char *extstring; char *extstring;
getdns_data_type exttype; getdns_data_type exttype;
} getdns_extension_format; } getdns_extension_format;
@ -64,13 +66,14 @@ typedef struct getdns_extension_format {
/** /**
* Request data for unbound * Request data for unbound
**/ **/
typedef struct getdns_network_req { typedef struct getdns_network_req
{
/* the async_id from unbound */ /* the async_id from unbound */
int unbound_id; int unbound_id;
/* state var */ /* state var */
network_req_state state; network_req_state state;
/* owner request (contains name) */ /* owner request (contains name) */
struct getdns_dns_req* owner; struct getdns_dns_req *owner;
/* request type */ /* request type */
uint16_t request_type; uint16_t request_type;
@ -79,17 +82,18 @@ typedef struct getdns_network_req {
uint16_t request_class; uint16_t request_class;
/* result */ /* result */
ldns_pkt* result; ldns_pkt *result;
/* next request to issue after this one */ /* next request to issue after this one */
struct getdns_network_req* next; struct getdns_network_req *next;
} getdns_network_req; } getdns_network_req;
/** /**
* dns request - manages a number of network requests and * dns request - manages a number of network requests and
* the initial data passed to getdns_general * the initial data passed to getdns_general
*/ */
typedef struct getdns_dns_req { typedef struct getdns_dns_req
{
/* name */ /* name */
char *name; char *name;
@ -104,19 +108,19 @@ typedef struct getdns_dns_req {
struct getdns_network_req *first_req; struct getdns_network_req *first_req;
/* request timeout event */ /* request timeout event */
struct event* timeout; struct event *timeout;
/* local callback timer */ /* local callback timer */
struct event* local_cb_timer; struct event *local_cb_timer;
/* event base this req is scheduled on */ /* event base this req is scheduled on */
struct event_base* ev_base; struct event_base *ev_base;
/* context that owns the request */ /* context that owns the request */
getdns_context_t context; getdns_context_t context;
/* ub_ctx issuing the request */ /* ub_ctx issuing the request */
struct ub_ctx* unbound; struct ub_ctx *unbound;
/* request extensions */ /* request extensions */
getdns_dict *extensions; getdns_dict *extensions;
@ -133,23 +137,18 @@ typedef struct getdns_dns_req {
/* utility methods */ /* utility methods */
/* network request utilities */ /* network request utilities */
void network_req_free(getdns_network_req* net_req); void network_req_free(getdns_network_req * net_req);
getdns_network_req* network_req_new(getdns_dns_req* owner, getdns_network_req *network_req_new(getdns_dns_req * owner,
uint16_t request_type, uint16_t request_type,
uint16_t request_class, uint16_t request_class, struct getdns_dict *extensions);
struct getdns_dict* extensions);
/* dns request utils */ /* dns request utils */
getdns_dns_req* dns_req_new(getdns_context_t context, getdns_dns_req *dns_req_new(getdns_context_t context,
struct ub_ctx* unbound, struct ub_ctx *unbound,
const char* name, const char *name, uint16_t request_type, struct getdns_dict *extensions);
uint16_t request_type,
struct getdns_dict *extensions);
void dns_req_free(getdns_dns_req * req);
void dns_req_free(getdns_dns_req* req);
#endif #endif

View File

@ -59,18 +59,20 @@ getdns_extension_format extformats[] = {
{"specify_class", t_int}, {"specify_class", t_int},
}; };
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name, getdns_return_t
const char* value) { getdns_dict_util_set_string(getdns_dict * dict, char *name, const char *value)
{
/* account for the null term */ /* account for the null term */
if (value == NULL) { if (value == NULL) {
return GETDNS_RETURN_WRONG_TYPE_REQUESTED; return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
} }
getdns_bindata type_bin = { strlen(value) + 1, (uint8_t*) value }; getdns_bindata type_bin = { strlen(value) + 1, (uint8_t *) value };
return getdns_dict_set_bindata(dict, name, &type_bin); return getdns_dict_set_bindata(dict, name, &type_bin);
} }
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name, getdns_return_t
char** result) { getdns_dict_util_get_string(getdns_dict * dict, char *name, char **result)
{
struct getdns_bindata *bindata = NULL; struct getdns_bindata *bindata = NULL;
if (!result) { if (!result) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
@ -80,62 +82,75 @@ getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
if (!bindata) { if (!bindata) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
*result = (char*) bindata->data; *result = (char *) bindata->data;
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
getdns_return_t dict_to_sockaddr(getdns_dict* ns, struct sockaddr_storage* output) { getdns_return_t
char* address_type = NULL; dict_to_sockaddr(getdns_dict * ns, struct sockaddr_storage * output)
{
char *address_type = NULL;
struct getdns_bindata *address_data = NULL; struct getdns_bindata *address_data = NULL;
uint32_t port = 53; uint32_t port = 53;
memset(output, 0, sizeof(struct sockaddr_storage)); memset(output, 0, sizeof(struct sockaddr_storage));
output->ss_family = AF_UNSPEC; output->ss_family = AF_UNSPEC;
uint32_t prt = 0; uint32_t prt = 0;
if (getdns_dict_get_int(ns, GETDNS_STR_PORT, &prt) == GETDNS_RETURN_GOOD) { if (getdns_dict_get_int(ns, GETDNS_STR_PORT,
&prt) == GETDNS_RETURN_GOOD) {
port = prt; port = prt;
} }
getdns_dict_util_get_string(ns, GETDNS_STR_ADDRESS_TYPE, &address_type); getdns_dict_util_get_string(ns, GETDNS_STR_ADDRESS_TYPE,
&address_type);
getdns_dict_get_bindata(ns, GETDNS_STR_ADDRESS_DATA, &address_data); getdns_dict_get_bindata(ns, GETDNS_STR_ADDRESS_DATA, &address_data);
if (!address_type || !address_data) { if (!address_type || !address_data) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
if (strncmp(GETDNS_STR_IPV4, address_type, strlen(GETDNS_STR_IPV4)) == 0) { if (strncmp(GETDNS_STR_IPV4, address_type,
strlen(GETDNS_STR_IPV4)) == 0) {
/* data is an in_addr_t */ /* data is an in_addr_t */
struct sockaddr_in* addr = (struct sockaddr_in*) output; struct sockaddr_in *addr = (struct sockaddr_in *) output;
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
addr->sin_port = htons((uint16_t)port); addr->sin_port = htons((uint16_t) port);
memcpy(&(addr->sin_addr), address_data->data, address_data->size); memcpy(&(addr->sin_addr), address_data->data,
address_data->size);
} else { } else {
/* data is a v6 addr in host order */ /* data is a v6 addr in host order */
struct sockaddr_in6* addr = (struct sockaddr_in6*) output; struct sockaddr_in6 *addr = (struct sockaddr_in6 *) output;
addr->sin6_family = AF_INET6; addr->sin6_family = AF_INET6;
addr->sin6_port = htons((uint16_t)port); addr->sin6_port = htons((uint16_t) port);
memcpy(&(addr->sin6_addr), address_data->data, address_data->size); memcpy(&(addr->sin6_addr), address_data->data,
address_data->size);
} }
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* address, getdns_dict** output) { getdns_return_t
sockaddr_to_dict(struct sockaddr_storage * address, getdns_dict ** output)
{
if (!output || !address) { if (!output || !address) {
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
getdns_bindata addr_data; getdns_bindata addr_data;
*output = NULL; *output = NULL;
getdns_dict* result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
if (address->ss_family == AF_INET) { if (address->ss_family == AF_INET) {
struct sockaddr_in* addr = (struct sockaddr_in*) address; struct sockaddr_in *addr = (struct sockaddr_in *) address;
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV4); getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE,
GETDNS_STR_IPV4);
addr_data.size = sizeof(addr->sin_addr); addr_data.size = sizeof(addr->sin_addr);
addr_data.data = (uint8_t*) &(addr->sin_addr); addr_data.data = (uint8_t *) & (addr->sin_addr);
getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA, &addr_data); getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA,
&addr_data);
} else if (address->ss_family == AF_INET6) { } else if (address->ss_family == AF_INET6) {
struct sockaddr_in6* addr = (struct sockaddr_in6*) address; struct sockaddr_in6 *addr = (struct sockaddr_in6 *) address;
getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE, GETDNS_STR_IPV6); getdns_dict_util_set_string(result, GETDNS_STR_ADDRESS_TYPE,
GETDNS_STR_IPV6);
addr_data.size = sizeof(addr->sin6_addr); addr_data.size = sizeof(addr->sin6_addr);
addr_data.data = (uint8_t*) &(addr->sin6_addr); addr_data.data = (uint8_t *) & (addr->sin6_addr);
getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA, &addr_data); getdns_dict_set_bindata(result, GETDNS_STR_ADDRESS_DATA,
&addr_data);
} else { } else {
// invalid // invalid
getdns_dict_destroy(result); getdns_dict_destroy(result);
@ -146,7 +161,9 @@ getdns_return_t sockaddr_to_dict(struct sockaddr_storage* address, getdns_dict**
} }
/* result must be freed */ /* result must be freed */
static char* convert_rdf_to_str(ldns_rdf* rdf) { static char *
convert_rdf_to_str(ldns_rdf * rdf)
{
if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_DNAME) { if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_DNAME) {
ldns_dname2canonical(rdf); ldns_dname2canonical(rdf);
} }
@ -154,17 +171,22 @@ static char* convert_rdf_to_str(ldns_rdf* rdf) {
} }
/* create the header dict */ /* create the header dict */
static getdns_dict *create_reply_header_dict(ldns_pkt* reply) { static getdns_dict *
create_reply_header_dict(ldns_pkt * reply)
{
/* { "id": 23456, "qr": 1, "opcode": 0, ... }, */ /* { "id": 23456, "qr": 1, "opcode": 0, ... }, */
int r = 0; int r = 0;
getdns_dict* result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
if (!result) { if (!result) {
return NULL; return NULL;
} }
/* cheat since we know GETDNS_RETURN_GOOD == 0 */ /* cheat since we know GETDNS_RETURN_GOOD == 0 */
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ID, ldns_pkt_id(reply)); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ID,
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QR, ldns_pkt_qr(reply)); ldns_pkt_id(reply));
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_OPC, (int) ldns_pkt_get_opcode(reply)); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QR,
ldns_pkt_qr(reply));
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_OPC,
(int) ldns_pkt_get_opcode(reply));
if (r != 0) { if (r != 0) {
getdns_dict_destroy(result); getdns_dict_destroy(result);
@ -173,21 +195,26 @@ static getdns_dict *create_reply_header_dict(ldns_pkt* reply) {
return result; return result;
} }
static getdns_dict *create_reply_question_dict(ldns_pkt* reply) { static getdns_dict *
create_reply_question_dict(ldns_pkt * reply)
{
/* { "qname": <bindata for "www.example.com">, "qtype": 1, "qclass": 1 } */ /* { "qname": <bindata for "www.example.com">, "qtype": 1, "qclass": 1 } */
int r = 0; int r = 0;
ldns_rr *question = NULL; ldns_rr *question = NULL;
char* qname; char *qname;
getdns_dict* result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
if (!result) { if (!result) {
return NULL; return NULL;
} }
question = ldns_rr_list_rr(ldns_pkt_question(reply), 0); question = ldns_rr_list_rr(ldns_pkt_question(reply), 0);
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QTYPE, (int) ldns_rr_get_type(question)); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QTYPE,
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QCLASS, (int) ldns_rr_get_class(question)); (int) ldns_rr_get_type(question));
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QCLASS,
(int) ldns_rr_get_class(question));
qname = convert_rdf_to_str(ldns_rr_owner(question)); qname = convert_rdf_to_str(ldns_rr_owner(question));
if (qname) { if (qname) {
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_QNAME, qname); r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_QNAME,
qname);
free(qname); free(qname);
} else { } else {
r = 1; r = 1;
@ -199,23 +226,27 @@ static getdns_dict *create_reply_question_dict(ldns_pkt* reply) {
return result; return result;
} }
static getdns_dict *create_dict_from_rdf(ldns_rdf* rdf) { static getdns_dict *
create_dict_from_rdf(ldns_rdf * rdf)
{
/* /*
create a dict w/ rdata_raw and special fields if needed * create a dict w/ rdata_raw and special fields if needed
i.e. * i.e.
{ * {
"ipv4_address": <bindata of 0x0a0b0c01> * "ipv4_address": <bindata of 0x0a0b0c01>
"rdata_raw": <bindata of 0x0a0b0c01> * "rdata_raw": <bindata of 0x0a0b0c01>
} * }
*/ */
int r = 0; int r = 0;
getdns_bindata rbin = { ldns_rdf_size(rdf), ldns_rdf_data(rdf) }; getdns_bindata rbin = { ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
getdns_dict* result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_RDATA_RAW, &rbin); r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_RDATA_RAW, &rbin);
if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) { if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) {
r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_V6_ADDR, &rbin); r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_V6_ADDR,
&rbin);
} else if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A) { } else if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A) {
r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_V4_ADDR, &rbin); r |= getdns_dict_set_bindata(result, GETDNS_STR_KEY_V4_ADDR,
&rbin);
} }
if (r != 0) { if (r != 0) {
getdns_dict_destroy(result); getdns_dict_destroy(result);
@ -224,32 +255,37 @@ static getdns_dict *create_dict_from_rdf(ldns_rdf* rdf) {
return result; return result;
} }
static getdns_dict *create_dict_from_rr(ldns_rr* rr) { static getdns_dict *
create_dict_from_rr(ldns_rr * rr)
{
/* /*
{ * {
"name": <bindata for "www.example.com">, * "name": <bindata for "www.example.com">,
"type": 1, * "type": 1,
"class": 1, * "class": 1,
"ttl": 33000, * "ttl": 33000,
"rdata": * "rdata":
{ * {
"ipv4_address": <bindata of 0x0a0b0c01> * "ipv4_address": <bindata of 0x0a0b0c01>
"rdata_raw": <bindata of 0x0a0b0c01> * "rdata_raw": <bindata of 0x0a0b0c01>
} * }
} * }
*/ */
int r = 0; int r = 0;
char * name = NULL; char *name = NULL;
getdns_dict *result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
size_t rd_count = ldns_rr_rd_count(rr); size_t rd_count = ldns_rr_rd_count(rr);
ldns_rdf* owner = ldns_rr_owner(rr); ldns_rdf *owner = ldns_rr_owner(rr);
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_TYPE, (int) ldns_rr_get_type(rr)); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_TYPE,
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_CLASS, (int) ldns_rr_get_class(rr)); (int) ldns_rr_get_type(rr));
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_CLASS,
(int) ldns_rr_get_class(rr));
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_TTL, ldns_rr_ttl(rr)); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_TTL, ldns_rr_ttl(rr));
if (owner) { if (owner) {
name = convert_rdf_to_str(owner); name = convert_rdf_to_str(owner);
if (name) { if (name) {
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_NAME, name); r |= getdns_dict_util_set_string(result,
GETDNS_STR_KEY_NAME, name);
free(name); free(name);
} else { } else {
r = 1; r = 1;
@ -257,7 +293,7 @@ static getdns_dict *create_dict_from_rr(ldns_rr* rr) {
} }
/* create rdatas */ /* create rdatas */
if (rd_count >= 1) { if (rd_count >= 1) {
getdns_dict* rdata = create_dict_from_rdf(ldns_rr_rdf(rr, 0)); getdns_dict *rdata = create_dict_from_rdf(ldns_rr_rdf(rr, 0));
r |= getdns_dict_set_dict(result, GETDNS_STR_KEY_RDATA, rdata); r |= getdns_dict_set_dict(result, GETDNS_STR_KEY_RDATA, rdata);
getdns_dict_destroy(rdata); getdns_dict_destroy(rdata);
} }
@ -273,14 +309,16 @@ static getdns_dict *create_dict_from_rr(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 getdns_list *create_list_from_rr_list(ldns_rr_list* rr_list) { static getdns_list *
create_list_from_rr_list(ldns_rr_list * rr_list)
{
size_t i = 0; size_t i = 0;
size_t idx = 0; size_t idx = 0;
int r = 0; int r = 0;
getdns_list *result = getdns_list_create(); getdns_list *result = getdns_list_create();
for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) { for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) {
ldns_rr *rr = ldns_rr_list_rr(rr_list, i); ldns_rr *rr = ldns_rr_list_rr(rr_list, i);
getdns_dict* rrdict = create_dict_from_rr(rr); getdns_dict *rrdict = create_dict_from_rr(rr);
r |= getdns_list_add_item(result, &idx); r |= getdns_list_add_item(result, &idx);
r |= getdns_list_set_dict(result, idx, rrdict); r |= getdns_list_set_dict(result, idx, rrdict);
getdns_dict_destroy(rrdict); getdns_dict_destroy(rrdict);
@ -293,7 +331,9 @@ static getdns_list *create_list_from_rr_list(ldns_rr_list* rr_list) {
} }
/* helper to add the ipv4 or ipv6 bin data to the list of addrs */ /* helper to add the ipv4 or ipv6 bin data to the list of addrs */
static getdns_return_t add_only_addresses(getdns_list* addrs, ldns_rr_list* rr_list) { static getdns_return_t
add_only_addresses(getdns_list * addrs, ldns_rr_list * rr_list)
{
int r = 0; int r = 0;
size_t i = 0; size_t i = 0;
for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) { for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) {
@ -302,66 +342,69 @@ static getdns_return_t add_only_addresses(getdns_list* addrs, ldns_rr_list* rr_l
size_t rd_count = ldns_rr_rd_count(rr); size_t rd_count = ldns_rr_rd_count(rr);
for (j = 0; j < rd_count; ++j) { for (j = 0; j < rd_count; ++j) {
size_t item_idx = 0; size_t item_idx = 0;
ldns_rdf* rdf = ldns_rr_rdf(rr, j); ldns_rdf *rdf = ldns_rr_rdf(rr, j);
if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A || if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A ||
ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) { ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) {
getdns_bindata rbin = { ldns_rdf_size(rdf), ldns_rdf_data(rdf) }; getdns_bindata rbin =
{ ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
r |= getdns_list_add_item(addrs, &item_idx); r |= getdns_list_add_item(addrs, &item_idx);
r |= getdns_list_set_bindata(addrs, item_idx, &rbin); r |= getdns_list_set_bindata(addrs, item_idx,
&rbin);
} }
} }
} }
return r; return r;
} }
static getdns_dict *create_reply_dict(getdns_network_req* req, static getdns_dict *
getdns_list *just_addrs) { create_reply_dict(getdns_network_req * req, getdns_list * just_addrs)
{
/* turn a packet into this glorious structure /* turn a packet into this glorious structure
*
{ # This is the first reply * { # This is the first reply
"header": { "id": 23456, "qr": 1, "opcode": 0, ... }, * "header": { "id": 23456, "qr": 1, "opcode": 0, ... },
"question": { "qname": <bindata for "www.example.com">, "qtype": 1, "qclass": 1 }, * "question": { "qname": <bindata for "www.example.com">, "qtype": 1, "qclass": 1 },
"answer": * "answer":
[ * [
{ * {
"name": <bindata for "www.example.com">, * "name": <bindata for "www.example.com">,
"type": 1, * "type": 1,
"class": 1, * "class": 1,
"ttl": 33000, * "ttl": 33000,
"rdata": * "rdata":
{ * {
"ipv4_address": <bindata of 0x0a0b0c01> * "ipv4_address": <bindata of 0x0a0b0c01>
"rdata_raw": <bindata of 0x0a0b0c01> * "rdata_raw": <bindata of 0x0a0b0c01>
} * }
} * }
], * ],
"authority": * "authority":
[ * [
{ * {
"name": <bindata for "ns1.example.com">, * "name": <bindata for "ns1.example.com">,
"type": 1, * "type": 1,
"class": 1, * "class": 1,
"ttl": 600, * "ttl": 600,
"rdata": * "rdata":
{ * {
"ipv4_address": <bindata of 0x65439876> * "ipv4_address": <bindata of 0x65439876>
"rdata_raw": <bindata of 0x65439876> * "rdata_raw": <bindata of 0x65439876>
} * }
} * }
] * ]
"additional": [], * "additional": [],
"canonical_name": <bindata for "www.example.com">, * "canonical_name": <bindata for "www.example.com">,
"answer_type": GETDNS_NAMETYPE_DNS * "answer_type": GETDNS_NAMETYPE_DNS
} * }
*
*/ */
int r = 0; int r = 0;
ldns_pkt *reply = req->result; ldns_pkt *reply = req->result;
ldns_rr_list *rr_list = NULL; ldns_rr_list *rr_list = NULL;
ldns_rr* question = NULL; ldns_rr *question = NULL;
getdns_dict *subdict = NULL; getdns_dict *subdict = NULL;
getdns_list *sublist = NULL; getdns_list *sublist = NULL;
char* name = NULL; char *name = NULL;
getdns_dict *result = getdns_dict_create(); getdns_dict *result = getdns_dict_create();
if (!result) { if (!result) {
@ -402,11 +445,13 @@ static getdns_dict *create_reply_dict(getdns_network_req* req,
getdns_list_destroy(sublist); getdns_list_destroy(sublist);
/* other stuff */ /* other stuff */
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, GETDNS_NAMETYPE_DNS); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE,
GETDNS_NAMETYPE_DNS);
question = ldns_rr_list_rr(ldns_pkt_question(reply), 0); question = ldns_rr_list_rr(ldns_pkt_question(reply), 0);
name = convert_rdf_to_str(ldns_rr_owner(question)); name = convert_rdf_to_str(ldns_rr_owner(question));
if (name) { if (name) {
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_CANONICAL_NM, name); r |= getdns_dict_util_set_string(result,
GETDNS_STR_KEY_CANONICAL_NM, name);
free(name); free(name);
} else { } else {
r |= 1; r |= 1;
@ -418,43 +463,52 @@ static getdns_dict *create_reply_dict(getdns_network_req* req,
return result; return result;
} }
static char* get_canonical_name(const char* name) { static char *
ldns_rdf* rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, name); get_canonical_name(const char *name)
{
ldns_rdf *rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, name);
if (!rdf) { if (!rdf) {
return NULL; return NULL;
} }
char* result = convert_rdf_to_str(rdf); char *result = convert_rdf_to_str(rdf);
ldns_rdf_deep_free(rdf); ldns_rdf_deep_free(rdf);
return result; return result;
} }
getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) { getdns_dict *
getdns_dict* result = getdns_dict_create(); create_getdns_response(struct getdns_dns_req * completed_request)
getdns_list* replies_full = getdns_list_create(); {
getdns_list* just_addrs = NULL; getdns_dict *result = getdns_dict_create();
getdns_list* replies_tree = getdns_list_create(); getdns_list *replies_full = getdns_list_create();
getdns_list *just_addrs = NULL;
getdns_list *replies_tree = getdns_list_create();
getdns_network_req *netreq = completed_request->first_req; getdns_network_req *netreq = completed_request->first_req;
char* canonical_name = NULL; char *canonical_name = NULL;
int r = 0; int r = 0;
if (completed_request->first_req->request_class == GETDNS_RRTYPE_A || if (completed_request->first_req->request_class == GETDNS_RRTYPE_A ||
completed_request->first_req->request_class == GETDNS_RRTYPE_AAAA) { completed_request->first_req->request_class ==
GETDNS_RRTYPE_AAAA) {
just_addrs = getdns_list_create(); just_addrs = getdns_list_create();
} }
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS, GETDNS_RESPSTATUS_GOOD); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS,
GETDNS_RESPSTATUS_GOOD);
canonical_name = get_canonical_name(completed_request->name); canonical_name = get_canonical_name(completed_request->name);
r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_CANONICAL_NM, canonical_name); r |= getdns_dict_util_set_string(result, GETDNS_STR_KEY_CANONICAL_NM,
canonical_name);
free(canonical_name); free(canonical_name);
r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, GETDNS_NAMETYPE_DNS); r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE,
GETDNS_NAMETYPE_DNS);
while (netreq) { while (netreq) {
getdns_bindata full_data; getdns_bindata full_data;
full_data.data = NULL; full_data.data = NULL;
full_data.size = 0; full_data.size = 0;
ldns_pkt *pkt = netreq->result; ldns_pkt *pkt = netreq->result;
ldns_status s = ldns_pkt2wire(&(full_data.data), pkt, &(full_data.size)); ldns_status s =
ldns_pkt2wire(&(full_data.data), pkt, &(full_data.size));
size_t idx = 0; size_t idx = 0;
/* reply tree */ /* reply tree */
getdns_dict *reply = create_reply_dict(netreq, just_addrs); getdns_dict *reply = create_reply_dict(netreq, just_addrs);
@ -464,7 +518,8 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
/* buffer */ /* buffer */
if (s == LDNS_STATUS_OK) { if (s == LDNS_STATUS_OK) {
r |= getdns_list_add_item(replies_full, &idx); r |= getdns_list_add_item(replies_full, &idx);
r |= getdns_list_set_bindata(replies_full, idx, &full_data); r |= getdns_list_set_bindata(replies_full, idx,
&full_data);
free(full_data.data); free(full_data.data);
} else { } else {
r = 1; r = 1;
@ -473,10 +528,13 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
netreq = netreq->next; netreq = netreq->next;
} }
r |= getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_TREE, replies_tree); r |= getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_TREE,
r |= getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_FULL, replies_full); replies_tree);
r |= getdns_dict_set_list(result, GETDNS_STR_KEY_REPLIES_FULL,
replies_full);
if (just_addrs) { if (just_addrs) {
r |= getdns_dict_set_list(result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs); r |= getdns_dict_set_list(result, GETDNS_STR_KEY_JUST_ADDRS,
just_addrs);
} }
/* cleanup */ /* cleanup */
@ -506,15 +564,15 @@ reverse_address(char *addr_str)
char *rev_str; char *rev_str;
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, addr_str); addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, addr_str);
if (! addr_rdf) { if (!addr_rdf) {
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, addr_str); addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, addr_str);
if (! addr_rdf) if (!addr_rdf)
return NULL; return NULL;
} }
rev_rdf = ldns_rdf_address_reverse(addr_rdf); rev_rdf = ldns_rdf_address_reverse(addr_rdf);
ldns_rdf_deep_free(addr_rdf); ldns_rdf_deep_free(addr_rdf);
if (! rev_rdf) if (!rev_rdf)
return NULL; return NULL;
rev_str = ldns_rdf2str(rev_rdf); rev_str = ldns_rdf2str(rev_rdf);
@ -522,28 +580,31 @@ reverse_address(char *addr_str)
return rev_str; return rev_str;
} }
static int extformatcmp(const void *a, const void *b) static int
extformatcmp(const void *a, const void *b)
{ {
return strcmp(((getdns_extension_format *)a)->extstring, return strcmp(((getdns_extension_format *) a)->extstring,
((getdns_extension_format *)b)->extstring); ((getdns_extension_format *) b)->extstring);
} }
/*---------------------------------------- validate_extensions */ /*---------------------------------------- validate_extensions */
getdns_return_t getdns_return_t
validate_extensions(getdns_dict *extensions) validate_extensions(getdns_dict * extensions)
{ {
struct getdns_dict_item *item; struct getdns_dict_item *item;
getdns_extension_format *extformat; getdns_extension_format *extformat;
if(extensions) if (extensions)
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(extensions->root)) { LDNS_RBTREE_FOR(item, struct getdns_dict_item *,
&(extensions->root))
{
getdns_extension_format key; getdns_extension_format key;
key.extstring = (char *)item->node.key; key.extstring = (char *) item->node.key;
extformat = bsearch(&key, extformats, extformat = bsearch(&key, extformats,
sizeof(extformats) / sizeof(extformats) /
sizeof(getdns_extension_format), sizeof(getdns_extension_format),
sizeof(getdns_extension_format), extformatcmp); sizeof(getdns_extension_format), extformatcmp);
if (! extformat) if (!extformat)
return GETDNS_RETURN_NO_SUCH_EXTENSION; return GETDNS_RETURN_NO_SUCH_EXTENSION;
if (item->dtype != extformat->exttype) if (item->dtype != extformat->exttype)

View File

@ -44,19 +44,21 @@
struct getdns_dns_req; struct getdns_dns_req;
/* convert an ip address dict to a sock storage */ /* 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 dict_to_sockaddr(getdns_dict * ns,
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* sockaddr, getdns_dict** output); struct sockaddr_storage *output);
getdns_return_t sockaddr_to_dict(struct sockaddr_storage *sockaddr,
getdns_dict ** output);
getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request); getdns_dict *create_getdns_response(struct getdns_dns_req *completed_request);
/* dict util */ /* dict util */
/* set a string as bindata */ /* set a string as bindata */
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name, getdns_return_t getdns_dict_util_set_string(getdns_dict * dict, char *name,
const char* value); const char *value);
/* get a string from a dict. result is valid as long as dict is valid */ /* 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, getdns_return_t getdns_dict_util_get_string(getdns_dict * dict, char *name,
char** result); char **result);
char *reverse_address(char *addr_str); char *reverse_address(char *addr_str);
/** /**
@ -67,6 +69,6 @@ char *reverse_address(char *addr_str);
* @return GETDNS_RETURN_NO_SUCH_EXTENSION A name in the extensions dict is not a valid extension. * @return GETDNS_RETURN_NO_SUCH_EXTENSION A name in the extensions dict is not a valid extension.
* @return GETDNS_RETURN_EXTENSION_MISFORMAT One or more of the extensions has a bad format. * @return GETDNS_RETURN_EXTENSION_MISFORMAT One or more of the extensions has a bad format.
*/ */
getdns_return_t validate_extensions(getdns_dict *extensions); getdns_return_t validate_extensions(getdns_dict * extensions);
/* util-internal.h */ /* util-internal.h */

View File

@ -38,11 +38,9 @@
* *
*/ */
getdns_return_t getdns_return_t
getdns_validate_dnssec( getdns_validate_dnssec(struct getdns_bindata * record_to_validate,
struct getdns_bindata *record_to_validate, struct getdns_list * bundle_of_support_records,
struct getdns_list *bundle_of_support_records, struct getdns_list * trust_anchor_rdatas)
struct getdns_list *trust_anchor_rdatas
)
{ {
UNUSED_PARAM(record_to_validate); UNUSED_PARAM(record_to_validate);
UNUSED_PARAM(bundle_of_support_records); UNUSED_PARAM(bundle_of_support_records);