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

File diff suppressed because it is too large Load Diff

View File

@ -38,69 +38,72 @@ struct ldns_rbtree_t;
struct getdns_dns_req;
/** function pointer typedefs */
typedef void (*getdns_update_callback)(getdns_context_t context, uint16_t changed_item);
typedef void* (*getdns_memory_allocator)(size_t size);
typedef void (*getdns_memory_deallocator)(void*);
typedef void* (*getdns_memory_reallocator)(void* ptr, size_t size);
typedef void (*getdns_update_callback) (getdns_context_t context,
uint16_t changed_item);
typedef void *(*getdns_memory_allocator) (size_t size);
typedef void (*getdns_memory_deallocator) (void *);
typedef void *(*getdns_memory_reallocator) (void *ptr, size_t size);
struct getdns_context_t {
struct getdns_context_t
{
/* Context values */
uint16_t resolution_type;
uint16_t *namespaces;
uint16_t timeout;
uint16_t follow_redirects;
struct getdns_list *dns_root_servers;
uint16_t append_name;
struct getdns_list *suffix;
struct getdns_list *dnssec_trust_anchors;
struct getdns_list *upstream_list;
/* Context values */
uint16_t resolution_type;
uint16_t *namespaces;
uint16_t timeout;
uint16_t follow_redirects;
struct getdns_list *dns_root_servers;
uint16_t append_name;
struct getdns_list *suffix;
struct getdns_list *dnssec_trust_anchors;
struct getdns_list *upstream_list;
uint8_t edns_extended_rcode;
uint8_t edns_version;
uint8_t edns_do_bit;
uint8_t edns_extended_rcode;
uint8_t edns_version;
uint8_t edns_do_bit;
getdns_update_callback update_callback;
getdns_memory_allocator memory_allocator;
getdns_memory_deallocator memory_deallocator;
getdns_memory_reallocator memory_reallocator;
getdns_update_callback update_callback;
getdns_memory_allocator memory_allocator;
getdns_memory_deallocator memory_deallocator;
getdns_memory_reallocator memory_reallocator;
/* Event loop for sync requests */
struct event_base* event_base_sync;
/* Event loop for async requests */
struct event_base* event_base_async;
/* Event loop for sync requests */
struct event_base *event_base_sync;
/* Event loop for async requests */
struct event_base *event_base_async;
/* The underlying unbound contexts that do
the real work */
struct ub_ctx *unbound_sync;
struct ub_ctx *unbound_async;
/* The underlying unbound contexts that do
* the real work */
struct ub_ctx *unbound_sync;
struct ub_ctx *unbound_async;
/* which resolution type the contexts are configured for
* 0 means nothing set
*/
uint8_t resolution_type_set;
/* which resolution type the contexts are configured for
* 0 means nothing set
*/
uint8_t resolution_type_set;
/*
* outbound requests -> transaction to getdns_dns_req
*/
struct ldns_rbtree_t* outbound_requests;
} ;
/*
* outbound requests -> transaction to getdns_dns_req
*/
struct ldns_rbtree_t *outbound_requests;
};
/** internal functions **/
/**
* Sets up the unbound contexts with stub or recursive behavior
* 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 */
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 */
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 */
getdns_return_t getdns_context_cancel_request(getdns_context_t context,
getdns_transaction_t transaction_id,
int fire_callback);
getdns_transaction_t transaction_id, int fire_callback);
#endif

View File

@ -38,73 +38,76 @@
#define UNUSED_PARAM(x) ((void)(x))
char *
getdns_convert_dns_name_to_fqdn(
char *name_from_dns_response
)
{ UNUSED_PARAM(name_from_dns_response); return NULL; }
char *
getdns_convert_fqdn_to_dns_name(
char *fqdn_as_string
)
{ UNUSED_PARAM(fqdn_as_string); return NULL; }
char *
getdns_convert_ulabel_to_alabel(
char *ulabel
)
{ UNUSED_PARAM(ulabel); return NULL; }
char *
getdns_convert_alabel_to_ulabel(
char *alabel
)
{ UNUSED_PARAM(alabel); return NULL; }
char *
getdns_display_ip_address(
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address
)
getdns_convert_dns_name_to_fqdn(char *name_from_dns_response)
{
char buff[256];
if (!bindata_of_ipv4_or_ipv6_address ||
bindata_of_ipv4_or_ipv6_address->size == 0 ||
!bindata_of_ipv4_or_ipv6_address->data) {
return NULL;
}
if (bindata_of_ipv4_or_ipv6_address->size == 4) {
const char* ipStr = inet_ntop(AF_INET,
bindata_of_ipv4_or_ipv6_address->data,
buff,
256);
if (ipStr) {
return strdup(ipStr);
}
} else if (bindata_of_ipv4_or_ipv6_address->size == 16) {
const char* ipStr = inet_ntop(AF_INET6,
bindata_of_ipv4_or_ipv6_address->data,
buff,
256);
if (ipStr) {
return strdup(ipStr);
}
}
return NULL;
UNUSED_PARAM(name_from_dns_response);
return NULL;
}
char *
getdns_convert_fqdn_to_dns_name(char *fqdn_as_string)
{
UNUSED_PARAM(fqdn_as_string);
return NULL;
}
char *
getdns_convert_ulabel_to_alabel(char *ulabel)
{
UNUSED_PARAM(ulabel);
return NULL;
}
char *
getdns_convert_alabel_to_ulabel(char *alabel)
{
UNUSED_PARAM(alabel);
return NULL;
}
char *
getdns_display_ip_address(struct getdns_bindata
*bindata_of_ipv4_or_ipv6_address)
{
char buff[256];
if (!bindata_of_ipv4_or_ipv6_address ||
bindata_of_ipv4_or_ipv6_address->size == 0 ||
!bindata_of_ipv4_or_ipv6_address->data) {
return NULL;
}
if (bindata_of_ipv4_or_ipv6_address->size == 4) {
const char *ipStr = inet_ntop(AF_INET,
bindata_of_ipv4_or_ipv6_address->data,
buff,
256);
if (ipStr) {
return strdup(ipStr);
}
} else if (bindata_of_ipv4_or_ipv6_address->size == 16) {
const char *ipStr = inet_ntop(AF_INET6,
bindata_of_ipv4_or_ipv6_address->data,
buff,
256);
if (ipStr) {
return strdup(ipStr);
}
}
return NULL;
}
getdns_return_t
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);
if (!err_str) {
return GETDNS_RETURN_GENERIC_ERROR;
}
const char *err_str = getdns_get_errorstr_by_id(err);
if (!err_str) {
return GETDNS_RETURN_GENERIC_ERROR;
}
snprintf(buf, buflen, "%s", err_str);
snprintf(buf, buflen, "%s", err_str);
return retval;
} /* getdns_strerror */
return retval;
} /* getdns_strerror */
/* getdns_core_only.c */

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -37,56 +37,64 @@
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
void
this_callbackfn(struct getdns_context_t *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg, getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg 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 */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg 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 */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
/* Be sure the search returned something */
uint32_t this_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"
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"
{
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);
return;
}
struct getdns_list * 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"
struct getdns_list *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"
{
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);
return;
}
size_t num_addresses = 0;
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 */
if (num_addresses == 0) {
fprintf(stderr, "There are no addresses.\n");
getdns_dict_destroy(this_response);
return;
}
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_bindata * this_address_data;
char* ipAddr = NULL;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
for (size_t rec_count = 0; rec_count < num_addresses;
++rec_count) {
struct getdns_bindata *this_address_data;
char *ipAddr = NULL;
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);
printf("The address is %s\n", ipAddr);
free(ipAddr);
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id);
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr,
"The callback with ID %" PRIu64
" was cancelled. Exiting.\n", this_transaction_id);
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 */
getdns_dict_destroy(this_response);
@ -97,41 +105,41 @@ main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
getdns_return_t context_create_return =
getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
if (this_event_base == NULL) {
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 */
const char * this_name = "www.example.com";
char* this_userarg = "somestring"; // Could add things here to help identify this call
const char *this_name = "www.example.com";
char *this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
// getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
/* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
return(GETDNS_RETURN_GENERIC_ERROR);
getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n",
this_name);
return (GETDNS_RETURN_GENERIC_ERROR);
} else if (dns_request_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "The context is not setup properly.\n");
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
return (GETDNS_RETURN_GENERIC_ERROR);
} else {
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
@ -142,6 +150,6 @@ main()
event_base_free(this_event_base);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */
} /* main */
/* example-simple-answers.c */

View File

@ -35,73 +35,79 @@
int
main()
{
getdns_return_t context_create_return;
struct getdns_list *just_the_addresses_ptr;
size_t num_addresses = 0;
size_t rec_count;
struct getdns_bindata *this_address_data;
struct getdns_context_t *this_context = NULL;
uint32_t this_error = 0;
struct getdns_dict *this_extensions = NULL;
const char *this_name = "www.example.com";
uint8_t this_request_type = GETDNS_RRTYPE_A;
struct getdns_dict *this_response = NULL;
uint32_t this_response_length;
getdns_return_t this_ret;
getdns_return_t context_create_return;
struct getdns_list *just_the_addresses_ptr;
size_t num_addresses = 0;
size_t rec_count;
struct getdns_bindata *this_address_data;
struct getdns_context_t *this_context = NULL;
uint32_t this_error = 0;
struct getdns_dict *this_extensions = NULL;
const char *this_name = "www.example.com";
uint8_t this_request_type = GETDNS_RRTYPE_A;
struct getdns_dict *this_response = NULL;
uint32_t this_response_length;
getdns_return_t this_ret;
/* Create the DNS context for this call */
context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Set up the getdns_sync_request call */
/* Get the A and AAAA records */
this_extensions = getdns_dict_create();
this_ret = getdns_dict_set_int(this_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d", this_ret);
return(GETDNS_RETURN_GENERIC_ERROR);
this_ret =
getdns_dict_set_int(this_extensions, "return_both_v4_and_v6",
GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD) {
fprintf(stderr,
"Trying to set an extension do both IPv4 and IPv6 failed: %d",
this_ret);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Make the call */
getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response_length, &this_response);
getdns_return_t dns_request_return =
getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response_length, &this_response);
/* free the extensions */
getdns_dict_destroy(this_extensions);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
this_name);
return (GETDNS_RETURN_GENERIC_ERROR);
} else {
/* Be sure the search returned something */
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"
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"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", this_error);
return(GETDNS_RETURN_GENERIC_ERROR);
fprintf(stderr,
"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_list_get_length(just_the_addresses_ptr, &num_addresses); // 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
/* Go through each record */
if (num_addresses > 0) {
for (rec_count = 0; rec_count < num_addresses; ++rec_count )
{
char * display;
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);
/* Just print the address */
printf("The address is %s\n", display);
if (display) {
free(display);
}
}
}
if (num_addresses > 0) {
for (rec_count = 0; rec_count < num_addresses;
++rec_count) {
char *display;
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);
/* Just print the address */
printf("The address is %s\n", display);
if (display) {
free(display);
}
}
}
}
/* Clean up */
@ -109,6 +115,6 @@ main()
getdns_free_sync_request_memory(this_response);
exit(EXIT_SUCCESS);
} /* main */
} /* main */
/* example-synchronous.c */

View File

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

View File

@ -48,316 +48,311 @@
#define UNUSED_PARAM(x) ((void)(x))
/* 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_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_dns_request_complete(getdns_dns_req* dns_req);
static int submit_network_request(getdns_network_req* netreq);
static void handle_network_request_error(getdns_network_req * netreq, int err);
static void handle_dns_request_complete(getdns_dns_req * dns_req);
static int submit_network_request(getdns_network_req * netreq);
typedef struct netreq_cb_data {
getdns_network_req *netreq;
int err;
ldns_buffer* result;
int sec;
char* bogus;
typedef struct netreq_cb_data
{
getdns_network_req *netreq;
int err;
ldns_buffer *result;
int sec;
char *bogus;
} netreq_cb_data;
/* cancel, cleanup and send timeout to callback */
static void 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_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void* user_arg = dns_req->user_pointer;
static void
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_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void *user_arg = dns_req->user_pointer;
/* cancel the req - also clears it from outbound */
getdns_context_cancel_request(context, trans_id, 0);
/* cancel the req - also clears it from outbound */
getdns_context_cancel_request(context, trans_id, 0);
/* cleanup */
dns_req_free(dns_req);
/* cleanup */
dns_req_free(dns_req);
cb(context,
GETDNS_CALLBACK_TIMEOUT,
NULL,
user_arg,
trans_id);
cb(context, GETDNS_CALLBACK_TIMEOUT, NULL, user_arg, trans_id);
}
static void 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
* invalid after calling ub_resolve_callback
*/
getdns_dns_req* dnsreq = cb_data->netreq->owner;
event_free(dnsreq->local_cb_timer);
dnsreq->local_cb_timer = NULL;
static void
ub_local_resolve_timeout(evutil_socket_t fd, short what, void *arg)
{
netreq_cb_data *cb_data = (netreq_cb_data *) arg;
/* just call ub_resolve_callback */
ub_resolve_callback(cb_data->netreq, cb_data->err, cb_data->result, cb_data->sec, cb_data->bogus);
/* cleanup the local timer here since the memory may be
* invalid after calling ub_resolve_callback
*/
getdns_dns_req *dnsreq = cb_data->netreq->owner;
event_free(dnsreq->local_cb_timer);
dnsreq->local_cb_timer = NULL;
/* cleanup the state */
ldns_buffer_free(cb_data->result);
if (cb_data->bogus) {
free(cb_data->bogus);
}
free(cb_data);
/* just call ub_resolve_callback */
ub_resolve_callback(cb_data->netreq, cb_data->err, cb_data->result,
cb_data->sec, cb_data->bogus);
/* cleanup the state */
ldns_buffer_free(cb_data->result);
if (cb_data->bogus) {
free(cb_data->bogus);
}
free(cb_data);
}
/* cleanup and send an error to the user callback */
static void handle_network_request_error(getdns_network_req* netreq, int err) {
getdns_dns_req *dns_req = netreq->owner;
getdns_context_t context = dns_req->context;
getdns_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void* user_arg = dns_req->user_pointer;
static void
handle_network_request_error(getdns_network_req * netreq, int err)
{
getdns_dns_req *dns_req = netreq->owner;
getdns_context_t context = dns_req->context;
getdns_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void *user_arg = dns_req->user_pointer;
/* clean up */
getdns_context_clear_outbound_request(dns_req);
dns_req_free(dns_req);
/* clean up */
getdns_context_clear_outbound_request(dns_req);
dns_req_free(dns_req);
cb(context,
GETDNS_CALLBACK_ERROR,
NULL,
user_arg,
trans_id);
cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
}
/* cleanup and send the response to the user callback */
static void handle_dns_request_complete(getdns_dns_req* dns_req) {
getdns_dict* response = create_getdns_response(dns_req);
static void
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_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void* user_arg = dns_req->user_pointer;
getdns_context_t context = dns_req->context;
getdns_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void *user_arg = dns_req->user_pointer;
/* clean up the request */
getdns_context_clear_outbound_request(dns_req);
dns_req_free(dns_req);
if (response) {
cb(context,
GETDNS_CALLBACK_COMPLETE,
response,
user_arg,
trans_id);
} else {
cb(context,
GETDNS_CALLBACK_ERROR,
NULL,
user_arg,
trans_id);
}
/* clean up the request */
getdns_context_clear_outbound_request(dns_req);
dns_req_free(dns_req);
if (response) {
cb(context,
GETDNS_CALLBACK_COMPLETE, response, user_arg, trans_id);
} else {
cb(context, GETDNS_CALLBACK_ERROR, NULL, user_arg, trans_id);
}
}
static int submit_network_request(getdns_network_req* netreq) {
getdns_dns_req *dns_req = netreq->owner;
int r = ub_resolve_event(dns_req->unbound,
dns_req->name,
netreq->request_type,
netreq->request_class,
netreq,
ub_resolve_callback,
&(netreq->unbound_id));
netreq->state = NET_REQ_IN_FLIGHT;
return r;
static int
submit_network_request(getdns_network_req * netreq)
{
getdns_dns_req *dns_req = netreq->owner;
int r = ub_resolve_event(dns_req->unbound,
dns_req->name,
netreq->request_type,
netreq->request_class,
netreq,
ub_resolve_callback,
&(netreq->unbound_id));
netreq->state = NET_REQ_IN_FLIGHT;
return r;
}
static void
ub_resolve_callback(void *arg, int err, ldns_buffer * result, int sec,
char *bogus)
{
getdns_network_req *netreq = (getdns_network_req *) arg;
/* if netreq->state == NET_REQ_NOT_SENT here, that implies
* that ub called us back immediately - probably from a local file.
* This most likely means that getdns_general has not returned
*/
if (netreq->state == NET_REQ_NOT_SENT) {
/* just do a very short timer since this was called immediately.
* we can make this less hacky, but it gets interesting when multiple
* netreqs need to be issued and some resolve immediately vs. not.
*/
struct timeval tv;
getdns_dns_req *dnsreq = netreq->owner;
netreq_cb_data *cb_data =
(netreq_cb_data *) malloc(sizeof(netreq_cb_data));
static void ub_resolve_callback(void* arg, int err, ldns_buffer* result, int sec, char* bogus) {
getdns_network_req* netreq = (getdns_network_req*) arg;
/* if netreq->state == NET_REQ_NOT_SENT here, that implies
* that ub called us back immediately - probably from a local file.
* This most likely means that getdns_general has not returned
*/
if (netreq->state == NET_REQ_NOT_SENT) {
/* just do a very short timer since this was called immediately.
* we can make this less hacky, but it gets interesting when multiple
* netreqs need to be issued and some resolve immediately vs. not.
*/
struct timeval tv;
getdns_dns_req* dnsreq = netreq->owner;
netreq_cb_data* cb_data = (netreq_cb_data*) malloc(sizeof(netreq_cb_data));
cb_data->netreq = netreq;
cb_data->err = err;
cb_data->sec = sec;
cb_data->result = NULL;
cb_data->bogus = NULL; /* unused but here in case we need it */
if (result) {
cb_data->result = ldns_buffer_new(ldns_buffer_limit(result));
if (!cb_data->result) {
cb_data->err = GETDNS_RETURN_GENERIC_ERROR;
} else {
/* copy */
ldns_buffer_copy(cb_data->result, result);
}
}
/* schedule the timeout */
dnsreq->local_cb_timer = evtimer_new(dnsreq->ev_base, ub_local_resolve_timeout, cb_data);
tv.tv_sec = 0;
/* half ms */
tv.tv_usec = 500;
evtimer_add(dnsreq->local_cb_timer, &tv);
return;
}
netreq->state = NET_REQ_FINISHED;
if (err) {
handle_network_request_error(netreq, err);
} else {
/* parse */
ldns_status r = ldns_buffer2pkt_wire(&(netreq->result), result);
if (r != LDNS_STATUS_OK) {
handle_network_request_error(netreq, r);
} else {
/* is this the last request */
if (!netreq->next) {
/* finished */
handle_dns_request_complete(netreq->owner);
} else {
/* not finished - update to next request and ship it */
getdns_dns_req* dns_req = netreq->owner;
dns_req->current_req = netreq->next;
submit_network_request(netreq->next);
}
}
}
cb_data->netreq = netreq;
cb_data->err = err;
cb_data->sec = sec;
cb_data->result = NULL;
cb_data->bogus = NULL; /* unused but here in case we need it */
if (result) {
cb_data->result =
ldns_buffer_new(ldns_buffer_limit(result));
if (!cb_data->result) {
cb_data->err = GETDNS_RETURN_GENERIC_ERROR;
} else {
/* copy */
ldns_buffer_copy(cb_data->result, result);
}
}
/* schedule the timeout */
dnsreq->local_cb_timer =
evtimer_new(dnsreq->ev_base, ub_local_resolve_timeout,
cb_data);
tv.tv_sec = 0;
/* half ms */
tv.tv_usec = 500;
evtimer_add(dnsreq->local_cb_timer, &tv);
return;
}
netreq->state = NET_REQ_FINISHED;
if (err) {
handle_network_request_error(netreq, err);
} else {
/* parse */
ldns_status r =
ldns_buffer2pkt_wire(&(netreq->result), result);
if (r != LDNS_STATUS_OK) {
handle_network_request_error(netreq, r);
} else {
/* is this the last request */
if (!netreq->next) {
/* finished */
handle_dns_request_complete(netreq->owner);
} else {
/* not finished - update to next request and ship it */
getdns_dns_req *dns_req = netreq->owner;
dns_req->current_req = netreq->next;
submit_network_request(netreq->next);
}
}
}
}
getdns_return_t
getdns_general_ub(struct ub_ctx* unbound,
struct event_base* ev_base,
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn)
getdns_general_ub(struct ub_ctx *unbound,
struct event_base *ev_base,
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn)
{
/* timeout */
struct timeval tv;
getdns_return_t gr;
int r;
/* timeout */
struct timeval tv;
getdns_return_t gr;
int r;
if (!name) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (!name) {
return GETDNS_RETURN_GENERIC_ERROR;
}
gr = getdns_context_prepare_for_resolution(context);
if (gr != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_BAD_CONTEXT;
}
gr = getdns_context_prepare_for_resolution(context);
if (gr != GETDNS_RETURN_GOOD) {
return GETDNS_RETURN_BAD_CONTEXT;
}
/* request state */
getdns_dns_req* req = dns_req_new(context,
unbound,
name,
request_type,
extensions);
if (!req) {
return GETDNS_RETURN_GENERIC_ERROR;
}
/* request state */
getdns_dns_req *req = dns_req_new(context,
unbound,
name,
request_type,
extensions);
if (!req) {
return GETDNS_RETURN_GENERIC_ERROR;
}
req->user_pointer = userarg;
req->user_callback = callbackfn;
req->user_pointer = userarg;
req->user_callback = callbackfn;
if (transaction_id) {
*transaction_id = req->trans_id;
}
if (transaction_id) {
*transaction_id = req->trans_id;
}
getdns_context_track_outbound_request(req);
getdns_context_track_outbound_request(req);
/* assign a timeout */
req->ev_base = ev_base;
req->timeout = evtimer_new(ev_base, ub_resolve_timeout, req);
tv.tv_sec = context->timeout / 1000;
tv.tv_usec = (context->timeout % 1000) * 1000;
evtimer_add(req->timeout, &tv);
/* assign a timeout */
req->ev_base = ev_base;
req->timeout = evtimer_new(ev_base, ub_resolve_timeout, req);
tv.tv_sec = context->timeout / 1000;
tv.tv_usec = (context->timeout % 1000) * 1000;
evtimer_add(req->timeout, &tv);
/* issue the first network req */
/* issue the first network req */
r = submit_network_request(req->first_req);
r = submit_network_request(req->first_req);
if (r != 0) {
/* clean up the request */
getdns_context_clear_outbound_request(req);
dns_req_free(req);
return GETDNS_RETURN_GENERIC_ERROR;
}
return GETDNS_RETURN_GOOD;
} /* getdns_general_ub */
if (r != 0) {
/* clean up the request */
getdns_context_clear_outbound_request(req);
dns_req_free(req);
return GETDNS_RETURN_GENERIC_ERROR;
}
return GETDNS_RETURN_GOOD;
} /* getdns_general_ub */
/**
* getdns_general
*/
getdns_return_t
getdns_general(getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback)
getdns_return_t
getdns_general(getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict * extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callback)
{
int extcheck = GETDNS_RETURN_GOOD;
int extcheck = GETDNS_RETURN_GOOD;
if (!context || !context->event_base_async ||
callback == NULL) {
/* Can't do async without an event loop
* or callback
*/
return GETDNS_RETURN_BAD_CONTEXT;
}
if (!context || !context->event_base_async || callback == NULL) {
/* Can't do async without an event loop
* or callback
*/
return GETDNS_RETURN_BAD_CONTEXT;
}
extcheck = validate_extensions(extensions);
if(extcheck != GETDNS_RETURN_GOOD)
return extcheck;
extcheck = validate_extensions(extensions);
if (extcheck != GETDNS_RETURN_GOOD)
return extcheck;
return getdns_general_ub(context->unbound_async,
context->event_base_async,
context,
name,
request_type,
extensions,
userarg,
transaction_id,
callback);
return getdns_general_ub(context->unbound_async,
context->event_base_async,
context,
name, request_type, extensions, userarg, transaction_id, callback);
} /* getdns_general */
} /* getdns_general */
/*
* getdns_address
*
*/
getdns_return_t
getdns_address(getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback) {
int cleanup_extensions = 0;
if (!extensions) {
extensions = getdns_dict_create();
cleanup_extensions = 1;
}
getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6,
GETDNS_EXTENSION_TRUE);
getdns_return_t
getdns_address(getdns_context_t context,
const char *name,
struct getdns_dict * extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callback)
{
int cleanup_extensions = 0;
if (!extensions) {
extensions = getdns_dict_create();
cleanup_extensions = 1;
}
getdns_dict_set_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, GETDNS_EXTENSION_TRUE);
getdns_return_t result =
getdns_general(context, name, GETDNS_RRTYPE_A,
extensions, userarg, transaction_id,
callback);
if (cleanup_extensions) {
getdns_dict_destroy(extensions);
}
return result;
getdns_return_t result = getdns_general(context, name, GETDNS_RRTYPE_A,
extensions, userarg, transaction_id,
callback);
if (cleanup_extensions) {
getdns_dict_destroy(extensions);
}
return result;
}
/* getdns_general.c */

View File

@ -44,16 +44,13 @@ struct ub_ctx;
struct event_base;
getdns_return_t
getdns_general_ub(
struct ub_ctx* unbound,
struct event_base* ev_base,
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_general_ub(struct ub_ctx *unbound,
struct event_base *ev_base,
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
#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_TEXT A query was made with a context that is using stub resolution and a DNSSEC extension specified.
/** @}
*/
@ -370,17 +369,19 @@ struct event_base;
*/
typedef struct getdns_context_t *getdns_context_t;
typedef uint16_t getdns_return_t;
typedef uint64_t getdns_transaction_t;
typedef uint16_t getdns_return_t;
typedef uint64_t getdns_transaction_t;
/**
* used to check data types within complex types (dict, list)
*/
typedef enum getdns_data_type {
t_dict, t_list, t_int, t_bindata, t_invalid
typedef enum getdns_data_type
{
t_dict, t_list, t_int, t_bindata, t_invalid
} getdns_data_type;
typedef struct getdns_bindata {
size_t size;
uint8_t *data;
typedef struct getdns_bindata
{
size_t size;
uint8_t *data;
} 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 list data type
* 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_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
* 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_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
* @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_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
* 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_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
@ -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_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
* 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_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
* @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_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
@ -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_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
* @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_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
* 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_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
* 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_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
* 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_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
* @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_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
* @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)
* 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_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_set_dict(struct getdns_list *list, size_t index, struct getdns_dict *child_dict);
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);
/**
* 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
@ -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_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
* 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_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)
* @return GETDNS_RETURN_GOOD on success
* @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
@ -619,7 +636,8 @@ getdns_dict_copy(struct getdns_dict *srcdict, struct getdns_dict **dstdict);
*/
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
* 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
* @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
* 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
* @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
* @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
* @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 */
typedef void (*getdns_callback_t)(
getdns_context_t context,
uint16_t callback_type,
struct getdns_dict *response,
void *userarg,
getdns_transaction_t transaction_id);
typedef void (*getdns_callback_t) (getdns_context_t context,
uint16_t callback_type,
struct getdns_dict * response,
void *userarg, getdns_transaction_t transaction_id);
/* Function definitions */
getdns_return_t
getdns_general(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_general(getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_return_t
getdns_address(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_address(getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_return_t
getdns_hostname(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_hostname(getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_return_t
getdns_service(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_service(getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
getdns_return_t getdns_context_create(
getdns_context_t *context,
int set_from_os
);
getdns_return_t getdns_context_create(getdns_context_t * context,
int set_from_os);
void
getdns_context_destroy(
getdns_context_t context
);
void getdns_context_destroy(getdns_context_t context);
getdns_return_t
getdns_cancel_callback(
getdns_context_t context,
getdns_transaction_t transaction_id
);
getdns_cancel_callback(getdns_context_t context,
getdns_transaction_t transaction_id);
/**
* \defgroup syncfuns Synchronous API functions that do not use callbacks
@ -731,14 +731,11 @@ getdns_cancel_callback(
* @return GETDNS_RETURN_GOOD on success
*/
getdns_return_t
getdns_general_sync(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
);
getdns_general_sync(getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t * response_length, struct getdns_dict **response);
/**
* retrieve address assigned to a DNS name
@ -751,13 +748,10 @@ getdns_general_sync(
*/
getdns_return_t
getdns_address_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
);
getdns_address_sync(getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t * response_length, struct getdns_dict **response);
/**
* retrieve hostname assigned to an IP address
@ -769,13 +763,10 @@ getdns_address_sync(
* @return GETDNS_RETURN_GOOD on success
*/
getdns_return_t
getdns_hostname_sync(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
);
getdns_hostname_sync(getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t * response_length, struct getdns_dict **response);
/**
* retrieve a service assigned to a DNS name
@ -787,48 +778,28 @@ getdns_hostname_sync(
* @return GETDNS_RETURN_GOOD on success
*/
getdns_return_t
getdns_service_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict **response
);
getdns_service_sync(getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t * response_length, struct getdns_dict **response);
void
getdns_free_sync_request_memory(
struct getdns_dict *response
);
void getdns_free_sync_request_memory(struct getdns_dict *response);
/** @}
*/
char *
getdns_convert_dns_name_to_fqdn(
char *name_from_dns_response
);
char *getdns_convert_dns_name_to_fqdn(char *name_from_dns_response);
char *
getdns_convert_fqdn_to_dns_name(
char *fqdn_as_string
);
char *getdns_convert_fqdn_to_dns_name(char *fqdn_as_string);
char *
getdns_convert_ulabel_to_alabel(
char *ulabel
);
char *getdns_convert_ulabel_to_alabel(char *ulabel);
char *
getdns_convert_alabel_to_ulabel(
char *alabel
);
char *getdns_convert_alabel_to_ulabel(char *alabel);
getdns_return_t
getdns_validate_dnssec(
struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas
);
getdns_validate_dnssec(struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas);
/**
* 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
* @return character array (caller must free this) containing pretty string
*/
char *
getdns_pretty_print_dict(struct getdns_dict *dict);
char *getdns_pretty_print_dict(struct getdns_dict *dict);
char *
getdns_display_ip_address(
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address
);
char *getdns_display_ip_address(struct getdns_bindata
*bindata_of_ipv4_or_ipv6_address);
getdns_return_t
getdns_context_set_context_update_callback(
getdns_context_t context,
void (*value)(getdns_context_t context, uint16_t changed_item)
);
getdns_context_set_context_update_callback(getdns_context_t context,
void (*value) (getdns_context_t context, uint16_t changed_item)
);
getdns_return_t
getdns_context_set_resolution_type(
getdns_context_t context,
uint16_t value
);
getdns_context_set_resolution_type(getdns_context_t context, uint16_t value);
getdns_return_t
getdns_context_set_namespaces(
getdns_context_t context,
size_t namespace_count,
uint16_t *namespaces
);
getdns_context_set_namespaces(getdns_context_t context,
size_t namespace_count, uint16_t * namespaces);
getdns_return_t
getdns_context_set_dns_transport(
getdns_context_t context,
uint16_t value
);
getdns_context_set_dns_transport(getdns_context_t context, uint16_t value);
getdns_return_t
getdns_context_set_limit_outstanding_queries(
getdns_context_t context,
uint16_t limit
);
getdns_context_set_limit_outstanding_queries(getdns_context_t context,
uint16_t limit);
getdns_return_t
getdns_context_set_timeout(
getdns_context_t context,
uint16_t timeout
);
getdns_context_set_timeout(getdns_context_t context, uint16_t timeout);
getdns_return_t
getdns_context_set_follow_redirects(
getdns_context_t context,
uint16_t value
);
getdns_context_set_follow_redirects(getdns_context_t context, uint16_t value);
getdns_return_t
getdns_context_set_dns_root_servers(
getdns_context_t context,
struct getdns_list *addresses
);
getdns_context_set_dns_root_servers(getdns_context_t context,
struct getdns_list *addresses);
getdns_return_t
getdns_context_set_append_name(
getdns_context_t context,
uint16_t value
);
getdns_context_set_append_name(getdns_context_t context, uint16_t value);
getdns_return_t
getdns_context_set_suffix(
getdns_context_t context,
struct getdns_list *value
);
getdns_context_set_suffix(getdns_context_t context, struct getdns_list *value);
getdns_return_t
getdns_context_set_dnssec_trust_anchors(
getdns_context_t context,
struct getdns_list *value
);
getdns_context_set_dnssec_trust_anchors(getdns_context_t context,
struct getdns_list *value);
getdns_return_t
getdns_context_set_dnssec_allowed_skew(
getdns_context_t context,
uint16_t value
);
getdns_context_set_dnssec_allowed_skew(getdns_context_t context,
uint16_t value);
getdns_return_t
getdns_context_set_stub_resolution(
getdns_context_t context,
struct getdns_list *upstream_list
);
getdns_context_set_stub_resolution(getdns_context_t context,
struct getdns_list *upstream_list);
getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size(
getdns_context_t context,
uint16_t value
);
getdns_context_set_edns_maximum_udp_payload_size(getdns_context_t context,
uint16_t value);
getdns_return_t
getdns_context_set_edns_extended_rcode(
getdns_context_t context,
uint8_t value
);
getdns_context_set_edns_extended_rcode(getdns_context_t context,
uint8_t value);
getdns_return_t
getdns_context_set_edns_version(
getdns_context_t context,
uint8_t value
);
getdns_context_set_edns_version(getdns_context_t context, uint8_t value);
getdns_return_t
getdns_context_set_edns_do_bit(
getdns_context_t context,
uint8_t value
);
getdns_context_set_edns_do_bit(getdns_context_t context, uint8_t value);
getdns_return_t
getdns_context_set_memory_allocator(
getdns_context_t context,
void (*value)(size_t somesize)
);
getdns_context_set_memory_allocator(getdns_context_t context,
void (*value) (size_t somesize)
);
getdns_return_t
getdns_context_set_memory_deallocator(
getdns_context_t context,
void (*value)(void*)
);
getdns_context_set_memory_deallocator(getdns_context_t context,
void (*value) (void *)
);
getdns_return_t
getdns_context_set_memory_reallocator(
getdns_context_t context,
void (*value)(void*)
);
getdns_context_set_memory_reallocator(getdns_context_t context,
void (*value) (void *)
);
/* Extension - refactor to abstract async evt loop */
/* For libevent, which we are using for these examples */
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
);
getdns_extension_set_libevent_base(getdns_context_t context,
struct event_base *this_event_base);
#endif /* GETDNS_H */

View File

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

View File

@ -26,27 +26,44 @@
* THE SOFTWARE.
*/
#include <getdns/getdns.h>
#include <getdns/getdns_error.h>
getdns_lookup_table getdns_error_str[] = {
{ GETDNS_RETURN_GOOD, "Good" },
{ GETDNS_RETURN_GENERIC_ERROR, "Generic error" },
{ GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name" },
{ GETDNS_RETURN_BAD_CONTEXT, "Bad value for a context type" },
{ GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Did not update the context" },
{ 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_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_RETURN_GOOD, "Good"}
,
{GETDNS_RETURN_GENERIC_ERROR, "Generic error"}
,
{GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name"}
,
{GETDNS_RETURN_BAD_CONTEXT, "Bad value for a context type"}
,
{GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Did not update the context"}
,
{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_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() */
/**
* return error string from getdns return
@ -55,17 +72,16 @@ getdns_lookup_table getdns_error_str[] = {
* @return string containing error message
*/
const char *
getdns_get_errorstr_by_id(uint16_t err)
{
getdns_lookup_table *lt;
getdns_lookup_table *lt;
lt = getdns_error_str;
while (lt->name != 0) {
if (lt->id == err)
return lt->name;
lt++;
}
return 0;
lt = getdns_error_str;
while (lt->name != 0) {
if (lt->id == err)
return lt->name;
lt++;
}
return 0;
}

View File

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

View File

@ -39,111 +39,106 @@
/*---------------------------------------- getdns_list_get_length */
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)
{
retval = GETDNS_RETURN_GOOD;
*answer = list->numinuse;
}
if (list != NULL && answer != NULL) {
retval = GETDNS_RETURN_GOOD;
*answer = list->numinuse;
}
return retval;
} /* getdns_list_get_length */
return retval;
} /* getdns_list_get_length */
/*---------------------------------------- getdns_list_get_data_type */
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)
{
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)
{
*answer = list->items[index].dtype;
retval = GETDNS_RETURN_GOOD;
}
return retval;
} /* getdns_list_get_data_type */
if (list != NULL && index < list->numinuse) {
*answer = list->items[index].dtype;
retval = GETDNS_RETURN_GOOD;
}
return retval;
} /* getdns_list_get_data_type */
/*---------------------------------------- getdns_list_get_dict */
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->items[index].dtype != t_dict)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else
{
*answer = list->items[index].data.dict;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL && index < list->numinuse) {
if (list->items[index].dtype != t_dict)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else {
*answer = list->items[index].data.dict;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_get_dict */
return retval;
} /* getdns_list_get_dict */
/*---------------------------------------- getdns_list_get_list */
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->items[index].dtype != t_list)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else
{
*answer = list->items[index].data.list;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL && index < list->numinuse) {
if (list->items[index].dtype != t_list)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else {
*answer = list->items[index].data.list;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_get_list */
return retval;
} /* getdns_list_get_list */
/*---------------------------------------- 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->items[index].dtype != t_bindata)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else
{
*answer = list->items[index].data.bindata;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL && index < list->numinuse) {
if (list->items[index].dtype != t_bindata)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else {
*answer = list->items[index].data.bindata;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_get_bindata */
return retval;
} /* getdns_list_get_bindata */
/*---------------------------------------- getdns_list_get_int */
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->items[index].dtype != t_int)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else
{
*answer = list->items[index].data.n;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL && index < list->numinuse) {
if (list->items[index].dtype != t_int)
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
else {
*answer = list->items[index].data.n;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_get_int */
return retval;
} /* getdns_list_get_int */
/*---------------------------------------- getdns_list_realloc */
/**
@ -154,252 +149,267 @@ 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
*/
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;
int i;
struct getdns_list_item *newlist;
getdns_return_t retval = GETDNS_RETURN_GENERIC_ERROR;
int i;
struct getdns_list_item *newlist;
if(list != NULL)
{
newlist = (struct getdns_list_item *) realloc(list->items
, (list->numalloc + GETDNS_LIST_BLOCKSZ) * sizeof(struct getdns_list_item));
if(newlist != NULL)
{
list->items = newlist;
for(i=list->numalloc; i<list->numalloc + GETDNS_LIST_BLOCKSZ; i++)
{
list->items[i].inuse = false;
list->items[i].dtype = t_invalid;
}
list->numalloc += GETDNS_LIST_BLOCKSZ;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL) {
newlist =
(struct getdns_list_item *) realloc(list->items,
(list->numalloc +
GETDNS_LIST_BLOCKSZ) *
sizeof(struct getdns_list_item));
if (newlist != NULL) {
list->items = newlist;
for (i = list->numalloc;
i < list->numalloc + GETDNS_LIST_BLOCKSZ; i++) {
list->items[i].inuse = false;
list->items[i].dtype = t_invalid;
}
list->numalloc += GETDNS_LIST_BLOCKSZ;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_realloc */
return retval;
} /* getdns_list_realloc */
/*---------------------------------------- getdns_list_copy */
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;
size_t index;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
int i;
size_t index;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if(srclist != NULL && dstlist != NULL)
{
*dstlist = getdns_list_create();
if(*dstlist != NULL)
{
retval = GETDNS_RETURN_GOOD;
for(i=0; i<srclist->numinuse; i++)
{
if(getdns_list_add_item(*dstlist, &index) == GETDNS_RETURN_GOOD)
{
(*dstlist)->items[index].inuse = true;
(*dstlist)->items[index].dtype = srclist->items[i].dtype;
if (srclist != NULL && dstlist != NULL) {
*dstlist = getdns_list_create();
if (*dstlist != NULL) {
retval = GETDNS_RETURN_GOOD;
for (i = 0; i < srclist->numinuse; i++) {
if (getdns_list_add_item(*dstlist,
&index) == GETDNS_RETURN_GOOD) {
(*dstlist)->items[index].inuse = true;
(*dstlist)->items[index].dtype =
srclist->items[i].dtype;
if(srclist->items[i].dtype == t_int)
(*dstlist)->items[index].data.n = srclist->items[i].data.n;
else if(srclist->items[i].dtype == t_list)
retval = getdns_list_copy(srclist->items[index].data.list
, &((*dstlist)->items[i].data.list));
else if(srclist->items[i].dtype == t_bindata)
{
(*dstlist)->items[i].data.bindata = (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
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 {
retval = GETDNS_RETURN_GENERIC_ERROR;
getdns_list_destroy(*dstlist);
*dstlist = NULL;
}
if (srclist->items[i].dtype == t_int)
(*dstlist)->items[index].data.
n =
srclist->items[i].data.n;
else if (srclist->items[i].dtype ==
t_list)
retval =
getdns_list_copy(srclist->
items[index].data.list,
&((*dstlist)->items[i].
data.list));
else if (srclist->items[i].dtype ==
t_bindata) {
(*dstlist)->items[i].data.
bindata =
(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
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 {
retval = GETDNS_RETURN_GENERIC_ERROR;
getdns_list_destroy(*dstlist);
*dstlist = NULL;
}
if(retval != GETDNS_RETURN_GOOD)
break;
}
}
else
retval = GETDNS_RETURN_GENERIC_ERROR;
}
if (retval != GETDNS_RETURN_GOOD)
break;
}
} else
retval = GETDNS_RETURN_GENERIC_ERROR;
}
return retval;
} /* getdns_list_copy */
return retval;
} /* getdns_list_copy */
/*---------------------------------------- getdns_list_create */
struct getdns_list *
getdns_list_create()
{
struct getdns_list *list = NULL;
struct getdns_list *list = NULL;
list = (struct getdns_list *) malloc(sizeof(struct getdns_list));
if(list != NULL)
{
list->numalloc = 0;
list->numinuse = 0;
list->items = NULL;
list = (struct getdns_list *) malloc(sizeof(struct getdns_list));
if (list != NULL) {
list->numalloc = 0;
list->numinuse = 0;
list->items = NULL;
getdns_list_realloc(list);
}
getdns_list_realloc(list);
}
return list;
} /* getdns_list_create */
return list;
} /* getdns_list_create */
/*---------------------------------------- getdns_list_destroy */
void
getdns_list_destroy(struct getdns_list *list)
{
int i;
int i;
if(list != NULL)
{
if(list->items != NULL)
{
for(i=0; i<list->numinuse; i++)
{
if(list->items[i].dtype == t_list)
{
if(list->items[i].dtype == t_list)
getdns_list_destroy(list->items[i].data.list);
}
else if(list->items[i].dtype == t_bindata)
{
if(list->items[i].data.bindata->size > 0)
free(list->items[i].data.bindata->data);
free(list->items[i].data.bindata);
}
else if(list->items[i].dtype == t_dict)
{
getdns_dict_destroy(list->items[i].data.dict);
}
}
free(list->items);
}
free(list);
}
} /* getdns_list_destroy */
if (list != NULL) {
if (list->items != NULL) {
for (i = 0; i < list->numinuse; i++) {
if (list->items[i].dtype == t_list) {
if (list->items[i].dtype == t_list)
getdns_list_destroy(list->
items[i].data.list);
} else if (list->items[i].dtype == t_bindata) {
if (list->items[i].data.bindata->size >
0)
free(list->items[i].data.
bindata->data);
free(list->items[i].data.bindata);
} else if (list->items[i].dtype == t_dict) {
getdns_dict_destroy(list->items[i].
data.dict);
}
}
free(list->items);
}
free(list);
}
} /* getdns_list_destroy */
/*---------------------------------------- getdns_list_add_item */
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;
if(list != NULL && index != NULL)
{
if(list->numalloc == list->numinuse)
retval = getdns_list_realloc(list);
else
retval = GETDNS_RETURN_GOOD;
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (list != NULL && index != NULL) {
if (list->numalloc == list->numinuse)
retval = getdns_list_realloc(list);
else
retval = GETDNS_RETURN_GOOD;
if(retval == GETDNS_RETURN_GOOD)
{
*index = list->numinuse;
list->items[*index].inuse = true;
list->numinuse++;
}
}
return retval;
} /* getdns_list_add_item */
if (retval == GETDNS_RETURN_GOOD) {
*index = list->numinuse;
list->items[*index].inuse = true;
list->numinuse++;
}
}
return retval;
} /* getdns_list_add_item */
/*---------------------------------------- getdns_list_set_dict */
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->numinuse > index)
{
list->items[index].dtype = t_dict;
retval = getdns_dict_copy(child_dict, &(list->items[index].data.dict));
}
}
if (list != NULL && child_dict != NULL) {
if (list->numinuse > index) {
list->items[index].dtype = t_dict;
retval =
getdns_dict_copy(child_dict,
&(list->items[index].data.dict));
}
}
return retval;
} /* getdns_list_set_dict */
return retval;
} /* getdns_list_set_dict */
/*---------------------------------------- getdns_set_list */
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->numinuse > index)
{
list->items[index].dtype = t_list;
retval = getdns_list_copy(child_list, &(list->items[index].data.list));
}
}
if (list != NULL && child_list != NULL) {
if (list->numinuse > index) {
list->items[index].dtype = t_list;
retval =
getdns_list_copy(child_list,
&(list->items[index].data.list));
}
}
return retval;
} /* getdns_set_list */
return retval;
} /* getdns_set_list */
/*---------------------------------------- getdns_list_set_bindata */
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->numinuse > index)
{
list->items[index].dtype = t_bindata;
list->items[index].data.bindata = (struct getdns_bindata *)
malloc(sizeof(struct getdns_bindata));
if(list->items[index].data.bindata != NULL)
{
list->items[index].data.bindata->size = child_bindata->size;
list->items[index].data.bindata->data = (uint8_t *) malloc(child_bindata->size
* sizeof(uint8_t));
memcpy(list->items[index].data.bindata->data, child_bindata->data, child_bindata->size);
retval = GETDNS_RETURN_GOOD;
}
else
retval = GETDNS_RETURN_GENERIC_ERROR;
}
}
if (list != NULL && child_bindata != NULL) {
if (list->numinuse > index) {
list->items[index].dtype = t_bindata;
list->items[index].data.bindata =
(struct getdns_bindata *)
malloc(sizeof(struct getdns_bindata));
if (list->items[index].data.bindata != NULL) {
list->items[index].data.bindata->size =
child_bindata->size;
list->items[index].data.bindata->data =
(uint8_t *) malloc(child_bindata->size *
sizeof(uint8_t));
memcpy(list->items[index].data.bindata->data,
child_bindata->data, child_bindata->size);
retval = GETDNS_RETURN_GOOD;
} else
retval = GETDNS_RETURN_GENERIC_ERROR;
}
}
return retval;
} /* getdns_list_set_bindata */
return retval;
} /* getdns_list_set_bindata */
/*---------------------------------------- getdns_list_set_int */
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->numinuse > index)
{
list->items[index].dtype = t_int;
list->items[index].data.n = child_uint32;
retval = GETDNS_RETURN_GOOD;
}
}
if (list != NULL) {
if (list->numinuse > index) {
list->items[index].dtype = t_int;
list->items[index].data.n = child_uint32;
retval = GETDNS_RETURN_GOOD;
}
}
return retval;
} /* getdns_list_set_int */
return retval;
} /* getdns_list_set_int */
/* getdns_list.c */

View File

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

View File

@ -42,144 +42,147 @@
#define gd_malloc(sz) context->memory_allocator(sz)
#define gd_free(ptr) context->memory_deallocator(ptr)
void network_req_free(getdns_network_req* net_req) {
if (!net_req) {
return;
}
getdns_context_t context = net_req->owner->context;
if (net_req->result) {
ldns_pkt_free(net_req->result);
}
gd_free(net_req);
void
network_req_free(getdns_network_req * net_req)
{
if (!net_req) {
return;
}
getdns_context_t context = net_req->owner->context;
if (net_req->result) {
ldns_pkt_free(net_req->result);
}
gd_free(net_req);
}
getdns_network_req* network_req_new(getdns_dns_req* owner,
uint16_t request_type,
uint16_t request_class,
struct getdns_dict* extensions) {
getdns_network_req *
network_req_new(getdns_dns_req * owner,
uint16_t request_type,
uint16_t request_class, struct getdns_dict *extensions)
{
getdns_context_t context = owner->context;
getdns_network_req* net_req = gd_malloc(sizeof(getdns_network_req));
if (!net_req) {
return NULL;
}
net_req->result = NULL;
net_req->next = NULL;
getdns_context_t context = owner->context;
getdns_network_req *net_req = gd_malloc(sizeof(getdns_network_req));
if (!net_req) {
return NULL;
}
net_req->result = NULL;
net_req->next = NULL;
net_req->request_type = request_type;
net_req->request_class = request_class;
net_req->unbound_id = -1;
net_req->state = NET_REQ_NOT_SENT;
net_req->owner = owner;
net_req->request_type = request_type;
net_req->request_class = request_class;
net_req->unbound_id = -1;
net_req->state = NET_REQ_NOT_SENT;
net_req->owner = owner;
/* TODO: records and other extensions */
/* TODO: records and other extensions */
return net_req;
return net_req;
}
void dns_req_free(getdns_dns_req* req) {
if (!req) {
return;
}
getdns_network_req *net_req = NULL;
getdns_context_t context = req->context;
void
dns_req_free(getdns_dns_req * req)
{
if (!req) {
return;
}
getdns_network_req *net_req = NULL;
getdns_context_t context = req->context;
/* free extensions */
getdns_dict_destroy(req->extensions);
/* free extensions */
getdns_dict_destroy(req->extensions);
/* free network requests */
net_req = req->first_req;
while (net_req) {
getdns_network_req *next = net_req->next;
network_req_free(net_req);
net_req = next;
}
/* free network requests */
net_req = req->first_req;
while (net_req) {
getdns_network_req *next = net_req->next;
network_req_free(net_req);
net_req = next;
}
/* cleanup timeout */
if (req->timeout) {
event_del(req->timeout);
event_free(req->timeout);
}
/* cleanup timeout */
if (req->timeout) {
event_del(req->timeout);
event_free(req->timeout);
}
if (req->local_cb_timer) {
event_del(req->local_cb_timer);
event_free(req->local_cb_timer);
}
if (req->local_cb_timer) {
event_del(req->local_cb_timer);
event_free(req->local_cb_timer);
}
/* free strduped name */
free(req->name);
/* free strduped name */
free(req->name);
gd_free(req);
gd_free(req);
}
/* create a new dns req to be submitted */
getdns_dns_req*
getdns_dns_req *
dns_req_new(getdns_context_t context,
struct ub_ctx* unbound,
const char* name,
uint16_t request_type,
struct getdns_dict *extensions) {
struct ub_ctx *unbound,
const char *name, uint16_t request_type, struct getdns_dict *extensions)
{
getdns_dns_req *result = NULL;
getdns_network_req *req = NULL;
getdns_return_t r;
uint32_t both = GETDNS_EXTENSION_FALSE;
getdns_dns_req *result = NULL;
getdns_network_req *req = NULL;
getdns_return_t r;
uint32_t both = GETDNS_EXTENSION_FALSE;
result = gd_malloc(sizeof(getdns_dns_req));
if (result == NULL) {
return NULL;
}
result = gd_malloc(sizeof(getdns_dns_req));
if (result == NULL) {
return NULL;
}
result->name = strdup(name);
result->context = context;
result->unbound = unbound;
result->canceled = 0;
result->current_req = NULL;
result->first_req = NULL;
result->trans_id = ldns_get_random();
result->timeout = NULL;
result->local_cb_timer = NULL;
result->ev_base = NULL;
result->name = strdup(name);
result->context = context;
result->unbound = unbound;
result->canceled = 0;
result->current_req = NULL;
result->first_req = NULL;
result->trans_id = ldns_get_random();
result->timeout = NULL;
result->local_cb_timer = NULL;
result->ev_base = NULL;
getdns_dict_copy(extensions, &result->extensions);
getdns_dict_copy(extensions, &result->extensions);
/* will be set by caller */
result->user_pointer = NULL;
result->user_callback = NULL;
/* will be set by caller */
result->user_pointer = NULL;
result->user_callback = NULL;
/* create the requests */
req = network_req_new(result,
request_type,
LDNS_RR_CLASS_IN,
extensions);
if (!req) {
dns_req_free(result);
return NULL;
}
/* create the requests */
req = network_req_new(result,
request_type, LDNS_RR_CLASS_IN, extensions);
if (!req) {
dns_req_free(result);
return NULL;
}
result->current_req = req;
result->first_req = req;
result->current_req = req;
result->first_req = req;
/* tack on A or AAAA if needed */
r = getdns_dict_get_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6,
&both);
if (r == GETDNS_RETURN_GOOD &&
both == GETDNS_EXTENSION_TRUE &&
(request_type == GETDNS_RRTYPE_A || request_type == GETDNS_RRTYPE_AAAA)) {
/* tack on A or AAAA if needed */
r = getdns_dict_get_int(extensions,
GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6, &both);
if (r == GETDNS_RETURN_GOOD &&
both == GETDNS_EXTENSION_TRUE &&
(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;
getdns_network_req* next_req =
network_req_new(result,
next_req_type,
LDNS_RR_CLASS_IN,
extensions);
if (!next_req) {
dns_req_free(result);
return NULL;
}
req->next = next_req;
}
uint16_t next_req_type =
(request_type ==
GETDNS_RRTYPE_A) ? GETDNS_RRTYPE_AAAA : GETDNS_RRTYPE_A;
getdns_network_req *next_req = network_req_new(result,
next_req_type,
LDNS_RR_CLASS_IN,
extensions);
if (!next_req) {
dns_req_free(result);
return NULL;
}
req->next = next_req;
}
return result;
return result;
}

View File

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

View File

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

View File

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

View File

@ -41,71 +41,81 @@
void
tst_bindatasetget(void)
{
char msg[TSTMSGBUF];
char key[20];
getdns_return_t retval;
struct getdns_dict *dict = NULL;
struct getdns_bindata *ans_bdata;
struct getdns_bindata *bindata;
char msg[TSTMSGBUF];
char key[20];
getdns_return_t retval;
struct getdns_dict *dict = NULL;
struct getdns_bindata *ans_bdata;
struct getdns_bindata *bindata;
tstmsg_case_begin("tst_bindatasetget");
tstmsg_case_begin("tst_bindatasetget");
dict = getdns_dict_create();
dict = getdns_dict_create();
/* test int get function against empty dict and with bogus params */
/* test int get function against empty dict and with bogus params */
strcpy(key, "foo");
strcpy(key, "foo");
tstmsg_case_msg("getdns_dict_get_bindata() empty dict");
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);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata() empty dict");
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);
tstmsg_case_msg(msg);
retval = getdns_dict_get_bindata(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_bindata(dict, key, NULL),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_bindata(dict, key, NULL);
sprintf(msg,
"line %d: getdns_dict_get_bindata(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata(dict, NULL, &ans_bindata)");
retval = getdns_dict_get_bindata(dict, NULL, &ans_bdata);
sprintf(msg, "line %d: getdns_dict_get_bindata,retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_bindata(dict, NULL, &ans_bindata)");
retval = getdns_dict_get_bindata(dict, NULL, &ans_bdata);
sprintf(msg, "line %d: getdns_dict_get_bindata,retval = %d", __LINE__,
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
/* TODO: test getdns_dict_set functions with bogus params */
/* TODO: test getdns_dict_set functions with bogus params */
/* test set and get legitimate use case */
/* test set and get legitimate use case */
dict = getdns_dict_create();
dict = getdns_dict_create();
strcpy(key, "foo");
bindata = (struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
bindata->size = strlen("foobar") + 1;
bindata->data = (void *) strdup("foobar");
strcpy(key, "foo");
bindata =
(struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
bindata->size = strlen("foobar") + 1;
bindata->data = (void *) strdup("foobar");
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
free(bindata->data);
free(bindata);
getdns_dict_destroy(dict);
free(bindata->data);
free(bindata);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_bindatasetget */
return;
} /* tst_bindatasetget */
/*---------------------------------------- tst_dictsetget */
/**
@ -114,75 +124,83 @@ tst_bindatasetget(void)
void
tst_dictsetget(void)
{
char msg[TSTMSGBUF];
char key[20];
uint32_t int1;
uint32_t int2;
getdns_return_t retval;
struct getdns_dict *newdict;
struct getdns_dict *ansdict;
struct getdns_dict *dict = NULL;
char msg[TSTMSGBUF];
char key[20];
uint32_t int1;
uint32_t int2;
getdns_return_t retval;
struct getdns_dict *newdict;
struct getdns_dict *ansdict;
struct getdns_dict *dict = NULL;
tstmsg_case_begin("tst_dictsetget");
tstmsg_case_begin("tst_dictsetget");
dict = getdns_dict_create();
dict = getdns_dict_create();
/* test get function against empty list and with bogus params */
/* test get function against empty list and with bogus params */
strcpy(key, "foo");
strcpy(key, "foo");
tstmsg_case_msg("getdns_dict_get_dict() empty dict");
retval = getdns_dict_get_dict(NULL, key, &ansdict);
sprintf(msg, "line %d: getdns_dict_get_dict(NULL, key, &ansdict),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_dict() empty dict");
retval = getdns_dict_get_dict(NULL, key, &ansdict);
sprintf(msg,
"line %d: getdns_dict_get_dict(NULL, key, &ansdict),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_dict(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_dict(dict, key, NULL),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_dict(dict, key, NULL);
sprintf(msg,
"line %d: getdns_dict_get_dict(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
/* TODO: test getdns_dict_set functions with bogus params */
/* TODO: test getdns_dict_set functions with bogus params */
/* test set and get legitimate use case */
/* test set and get legitimate use case */
dict = getdns_dict_create();
dict = getdns_dict_create();
strcpy(key, "foo");
newdict = getdns_dict_create();
getdns_dict_set_int(newdict, "foo", 42);
getdns_dict_set_int(newdict, "bar", 52);
strcpy(key, "foo");
newdict = getdns_dict_create();
getdns_dict_set_int(newdict, "foo", 42);
getdns_dict_set_int(newdict, "bar", 52);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(newdict);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(newdict);
tstmsg_case_msg("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, "bar", &int2);
sprintf(msg, "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("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, "bar", &int2);
sprintf(msg,
"line %d: getdns_dict_get_dict,retval=%d,key=%s,int1=%d,int2=%d",
__LINE__, retval, key, int1, int2);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_dictsetget */
return;
} /* tst_dictsetget */
/*---------------------------------------- tst_getnames */
/**
@ -191,84 +209,83 @@ tst_dictsetget(void)
void
tst_getnames(void)
{
size_t index;
size_t llen;
uint32_t ansint;
int i;
getdns_return_t result;
getdns_data_type dtype;
struct getdns_dict *dict = NULL;
struct getdns_list *list = NULL;
size_t index;
size_t llen;
uint32_t ansint;
int i;
getdns_return_t result;
getdns_data_type dtype;
struct getdns_dict *dict = NULL;
struct getdns_list *list = NULL;
tstmsg_case_begin("tst_getnames");
tstmsg_case_begin("tst_getnames");
dict = getdns_dict_create();
dict = getdns_dict_create();
/* degenerative use cases */
/* degenerative use cases */
tstmsg_case_msg("getdns_dict_get_names(NULL, &list)");
getdns_dict_get_names(NULL, &list);
getdns_list_destroy(list);
tstmsg_case_msg("getdns_dict_get_names(NULL, &list)");
getdns_dict_get_names(NULL, &list);
getdns_list_destroy(list);
tstmsg_case_msg("getdns_dict_get_names(dict, NULL)");
getdns_dict_get_names(dict, NULL);
tstmsg_case_msg("getdns_dict_get_names(dict, NULL)");
getdns_dict_get_names(dict, NULL);
tstmsg_case_msg("getdns_dict_get_names(dict, &list), empty dictionary");
getdns_dict_get_names(dict, &list);
getdns_list_destroy(list);
/* legit use case, add items out of order to exercise tree */
/* TODO: add elements of type dict, bindata, list to the dict */
tstmsg_case_msg
("getdns_dict_get_names(dict, &list), empty dictionary");
getdns_dict_get_names(dict, &list);
getdns_list_destroy(list);
i = 0;
getdns_dict_set_int(dict, "foo", i++);
getdns_dict_set_int(dict, "bar", i++);
getdns_dict_set_int(dict, "quz", i++);
getdns_dict_set_int(dict, "alpha", i++);
/* legit use case, add items out of order to exercise tree */
/* TODO: add elements of type dict, bindata, list to the dict */
getdns_dict_get_names(dict, &list);
i = 0;
getdns_dict_set_int(dict, "foo", i++);
getdns_dict_set_int(dict, "bar", i++);
getdns_dict_set_int(dict, "quz", i++);
getdns_dict_set_int(dict, "alpha", i++);
result = getdns_list_get_length(list, &llen);
if(llen != i)
{
tstmsg_case_msg("getdns_list_get_length returned unreasonable length, exiting");
return;
}
getdns_dict_get_names(dict, &list);
for(index=0; index<llen; index++)
{
getdns_list_get_data_type(list, index, &dtype);
printf(" list item %d: ", (int) index);
switch(dtype)
{
case t_bindata:
printf("NOTIMPLEMENTED");
break;
result = getdns_list_get_length(list, &llen);
if (llen != i) {
tstmsg_case_msg
("getdns_list_get_length returned unreasonable length, exiting");
return;
}
case t_dict:
printf("NOTIMPLEMENTED");
break;
for (index = 0; index < llen; index++) {
getdns_list_get_data_type(list, index, &dtype);
printf(" list item %d: ", (int) index);
switch (dtype) {
case t_bindata:
printf("NOTIMPLEMENTED");
break;
case t_int:
getdns_list_get_int(list, index, &ansint);
printf("t_int, value=%d\n", ansint);
break;
case t_dict:
printf("NOTIMPLEMENTED");
break;
case t_invalid:
printf("data type invalid");
break;
case t_int:
getdns_list_get_int(list, index, &ansint);
printf("t_int, value=%d\n", ansint);
break;
case t_list:
printf("NOTIMPLEMENTED");
break;
}
}
case t_invalid:
printf("data type invalid");
break;
getdns_dict_destroy(dict);
getdns_list_destroy(list);
case t_list:
printf("NOTIMPLEMENTED");
break;
}
}
tstmsg_case_end();
} /* tst_getnames */
getdns_dict_destroy(dict);
getdns_list_destroy(list);
tstmsg_case_end();
} /* tst_getnames */
/*---------------------------------------- tst_listsetget */
/**
@ -277,78 +294,86 @@ tst_getnames(void)
void
tst_listsetget(void)
{
char msg[TSTMSGBUF];
char key[20];
size_t index;
uint32_t int1;
uint32_t int2;
getdns_return_t retval;
struct getdns_list *newlist;
struct getdns_list *anslist;
struct getdns_dict *dict = NULL;
char msg[TSTMSGBUF];
char key[20];
size_t index;
uint32_t int1;
uint32_t int2;
getdns_return_t retval;
struct getdns_list *newlist;
struct getdns_list *anslist;
struct getdns_dict *dict = NULL;
tstmsg_case_begin("tst_listsetget");
tstmsg_case_begin("tst_listsetget");
dict = getdns_dict_create();
dict = getdns_dict_create();
/* test get function against empty list and with bogus params */
/* test get function against empty list and with bogus params */
strcpy(key, "foo");
strcpy(key, "foo");
tstmsg_case_msg("getdns_dict_get_list() empty dict");
retval = getdns_dict_get_list(NULL, key, &anslist);
sprintf(msg, "line %d: getdns_dict_get_list(NULL, key, &anslist),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_list() empty dict");
retval = getdns_dict_get_list(NULL, key, &anslist);
sprintf(msg,
"line %d: getdns_dict_get_list(NULL, key, &anslist),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_list(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_list(dict, key, NULL),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_list(dict, key, NULL);
sprintf(msg,
"line %d: getdns_dict_get_list(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
/* TODO: test getdns_dict_set functions with bogus params */
/* TODO: test getdns_dict_set functions with bogus params */
/* test set and get legitimate use case */
/* test set and get legitimate use case */
dict = getdns_dict_create();
dict = getdns_dict_create();
strcpy(key, "foo");
newlist = getdns_list_create();
getdns_list_add_item(newlist, &index);
getdns_list_set_int(newlist, index, 42);
getdns_list_add_item(newlist, &index);
getdns_list_set_int(newlist, index, 52);
strcpy(key, "foo");
newlist = getdns_list_create();
getdns_list_add_item(newlist, &index);
getdns_list_set_int(newlist, index, 42);
getdns_list_add_item(newlist, &index);
getdns_list_set_int(newlist, index, 52);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_list_destroy(newlist);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_list_destroy(newlist);
tstmsg_case_msg("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, 1, &int2);
sprintf(msg, "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("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, 1, &int2);
sprintf(msg,
"line %d: getdns_dict_get_list,retval=%d,key=%s,int1=%d,int2=%d",
__LINE__, retval, key, int1, int2);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_listsetget */
return;
} /* tst_listsetget */
/*---------------------------------------- tst_intsetget */
/**
@ -357,85 +382,97 @@ tst_listsetget(void)
void
tst_intsetget(void)
{
char msg[TSTMSGBUF];
char key[20];
uint32_t ans_int;
uint32_t newint;
getdns_return_t retval;
struct getdns_dict *dict = NULL;
getdns_data_type dtype;
char msg[TSTMSGBUF];
char key[20];
uint32_t ans_int;
uint32_t newint;
getdns_return_t retval;
struct getdns_dict *dict = NULL;
getdns_data_type dtype;
tstmsg_case_begin("tst_intsetget");
tstmsg_case_begin("tst_intsetget");
dict = getdns_dict_create();
dict = getdns_dict_create();
/* test int get function against empty list and with bogus params */
/* test int get function against empty list and with bogus params */
strcpy(key, "foo");
strcpy(key, "foo");
tstmsg_case_msg("getdns_dict_get_int() empty dict");
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);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_dict_get_int() empty dict");
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);
tstmsg_case_msg(msg);
retval = getdns_dict_get_int(dict, key, NULL);
sprintf(msg, "line %d: getdns_dict_get_int(dict, key, NULL),retval = %d", __LINE__, retval);
tstmsg_case_msg(msg);
retval = getdns_dict_get_int(dict, key, NULL);
sprintf(msg,
"line %d: getdns_dict_get_int(dict, key, NULL),retval = %d",
__LINE__, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
/* TODO: test getdns_dict_set functions with bogus params */
/* TODO: test getdns_dict_set functions with bogus params */
/* test set and get legitimate use case */
/* test set and get legitimate use case */
dict = getdns_dict_create();
dict = getdns_dict_create();
strcpy(key, "foo");
newint = 42;
strcpy(key, "foo");
newint = 42;
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
strcpy(key, "bar");
newint = 52;
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
strcpy(key, "bar");
newint = 52;
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
tstmsg_case_msg("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);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_dict_destroy(dict);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_intsetget */
return;
} /* tst_intsetget */
/*---------------------------------------- tst_copy */
/**
@ -444,45 +481,45 @@ tst_intsetget(void)
void
tst_copy(void)
{
char *dictstr = NULL;
struct getdns_dict *dict1 = NULL;
struct getdns_dict *dict2 = NULL;
char *dictstr = NULL;
struct getdns_dict *dict1 = NULL;
struct getdns_dict *dict2 = NULL;
tstmsg_case_begin("tst_copy");
tstmsg_case_begin("tst_copy");
tstmsg_case_msg("empty list cases");
tstmsg_case_msg("empty list cases");
getdns_dict_copy(NULL, NULL);
dict1 = getdns_dict_create();
getdns_dict_copy(dict1, &dict2);
getdns_dict_destroy(dict2);
getdns_dict_copy(NULL, &dict1);
getdns_dict_copy(NULL, NULL);
dict1 = getdns_dict_create();
getdns_dict_copy(dict1, &dict2);
getdns_dict_destroy(dict2);
getdns_dict_copy(NULL, &dict1);
tstmsg_case_msg("dict1 populate");
tstmsg_case_msg("dict1 populate");
getdns_dict_set_int(dict1, "foo", 42);
getdns_dict_set_int(dict1, "bar", 52);
getdns_dict_set_int(dict1, "quz", 62);
getdns_dict_set_int(dict1, "foo", 42);
getdns_dict_set_int(dict1, "bar", 52);
getdns_dict_set_int(dict1, "quz", 62);
dictstr = getdns_pretty_print_dict(dict1);
printf("%s", dictstr);
free(dictstr);
dictstr = getdns_pretty_print_dict(dict1);
printf("%s", dictstr);
free(dictstr);
tstmsg_case_msg("getdns_dict_copy(dict1, &dict2)");
tstmsg_case_msg("getdns_dict_copy(dict1, &dict2)");
getdns_dict_copy(dict1, &dict2);
getdns_dict_copy(dict1, &dict2);
dictstr = getdns_pretty_print_dict(dict2);
printf("%s", dictstr);
free(dictstr);
dictstr = getdns_pretty_print_dict(dict2);
printf("%s", dictstr);
free(dictstr);
getdns_dict_destroy(dict1);
getdns_dict_destroy(dict2);
getdns_dict_destroy(dict1);
getdns_dict_destroy(dict2);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_copy */
return;
} /* tst_copy */
/*---------------------------------------- tst_create */
/**
@ -491,28 +528,27 @@ tst_copy(void)
void
tst_create(void)
{
struct getdns_dict *dict = NULL;
struct getdns_dict *dict = NULL;
/* make sure we can do a simple create/destroy first */
/* make sure we can do a simple create/destroy first */
tstmsg_case_begin("tst_create");
tstmsg_case_begin("tst_create");
tstmsg_case_msg("getdns_dict_create");
dict = getdns_dict_create();
tstmsg_case_msg("getdns_dict_create");
dict = getdns_dict_create();
if(dict != NULL)
{
tstmsg_case_msg("getdns_dict_destroy(dict)");
getdns_dict_destroy(dict);
}
if (dict != NULL) {
tstmsg_case_msg("getdns_dict_destroy(dict)");
getdns_dict_destroy(dict);
}
tstmsg_case_msg("getdns_dict_destroy(NULL)");
getdns_dict_destroy(NULL);
tstmsg_case_msg("getdns_dict_destroy(NULL)");
getdns_dict_destroy(NULL);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_create */
return;
} /* tst_create */
/*---------------------------------------- main */
/**
@ -521,25 +557,25 @@ tst_create(void)
int
main(int argc, char *argv[])
{
tstmsg_prog_begin("tests_dict");
tstmsg_prog_begin("tests_dict");
tst_create();
tst_create();
tst_bindatasetget();
tst_bindatasetget();
tst_dictsetget();
tst_dictsetget();
tst_intsetget();
tst_intsetget();
tst_listsetget();
tst_listsetget();
tst_getnames();
tst_getnames();
tst_copy();
tst_copy();
tstmsg_prog_end();
tstmsg_prog_end();
return 0;
} /* main */
return 0;
} /* main */
/* end tests_dict.c */

View File

@ -45,76 +45,82 @@
void
tst_bindatasetget(void)
{
char msg[TSTMSGBUF];
size_t index = 0;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_bindata *new_bindata = NULL;
struct getdns_bindata *ans_bindata = NULL;
char msg[TSTMSGBUF];
size_t index = 0;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_bindata *new_bindata = NULL;
struct getdns_bindata *ans_bindata = NULL;
tstmsg_case_begin("tst_bindatasetget");
tstmsg_case_begin("tst_bindatasetget");
list = getdns_list_create();
list = getdns_list_create();
/* test get function against empty list and with bogus params */
/* test get function against empty list and with bogus params */
tstmsg_case_msg("getdns_list_get_bindata() empty list");
retval = getdns_list_get_bindata(NULL, index, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata(NULL, index, &ans_bindata),retval = %d"
, retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata() empty list");
retval = getdns_list_get_bindata(NULL, index, &ans_bindata);
sprintf(msg,
"getdns_list_get_bindata(NULL, index, &ans_bindata),retval = %d",
retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_bindata(list, index, NULL);
sprintf(msg, "getdns_list_get_bindata(list, index, NULL),retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_bindata(list, index, NULL);
sprintf(msg, "getdns_list_get_bindata(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata(list, 0, &ans_bindata)");
retval = getdns_list_get_bindata(list, 0, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata(list, 0, &ans_bindata)");
retval = getdns_list_get_bindata(list, 0, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata(list, 1, &ans_bindata)");
retval = getdns_list_get_bindata(list, 1, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_bindata(list, 1, &ans_bindata)");
retval = getdns_list_get_bindata(list, 1, &ans_bindata);
sprintf(msg, "getdns_list_get_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
/* test set function against empty list with bogus params */
/* test set function against empty list with bogus params */
tstmsg_case_msg("getdns_list_set_bindata() empty list");
retval = getdns_list_set_bindata(NULL, index, NULL);
sprintf(msg, "getdns_list_set_bindata(NULL, index, ans_bindata),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata() empty list");
retval = getdns_list_set_bindata(NULL, index, NULL);
sprintf(msg,
"getdns_list_set_bindata(NULL, index, ans_bindata),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata(list, 0, ans_bindata)");
retval = getdns_list_set_bindata(list, 0, NULL);
sprintf(msg, "getdns_list_set_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata(list, 0, ans_bindata)");
retval = getdns_list_set_bindata(list, 0, NULL);
sprintf(msg, "getdns_list_set_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata(list, 1, ans_bindata)");
retval = getdns_list_set_bindata(list, 1, NULL);
sprintf(msg, "getdns_list_set_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_bindata(list, 1, ans_bindata)");
retval = getdns_list_set_bindata(list, 1, NULL);
sprintf(msg, "getdns_list_set_bindata,retval = %d", retval);
tstmsg_case_msg(msg);
/* 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->size = strlen("foobar") + 1;
new_bindata->data = (uint8_t *) strdup("foobar");
new_bindata->data[strlen("foobar")] = '\0';
new_bindata =
(struct getdns_bindata *) malloc(sizeof(struct getdns_bindata));
new_bindata->size = strlen("foobar") + 1;
new_bindata->data = (uint8_t *) strdup("foobar");
new_bindata->data[strlen("foobar")] = '\0';
getdns_list_add_item(list, &index);
getdns_list_set_bindata(list, index, new_bindata);
retval = getdns_list_get_bindata(list, index, &ans_bindata);
sprintf(msg, "getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s"
, retval, (int) ans_bindata->size, (char *) ans_bindata->data);
tstmsg_case_msg(msg);
getdns_list_add_item(list, &index);
getdns_list_set_bindata(list, index, new_bindata);
retval = getdns_list_get_bindata(list, index, &ans_bindata);
sprintf(msg,
"getdns_list_set/get_bindata,retval = %d, bindata->data = %d,%s",
retval, (int) ans_bindata->size, (char *) ans_bindata->data);
tstmsg_case_msg(msg);
getdns_list_destroy(list);
getdns_list_destroy(list);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_bindatasetget */
return;
} /* tst_bindatasetget */
/*---------------------------------------- tst_dictsetget */
/**
@ -123,74 +129,78 @@ tst_bindatasetget(void)
void
tst_dictsetget(void)
{
char msg[TSTMSGBUF];
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_dict *dict = NULL;
struct getdns_dict *ansdict = NULL;
char msg[TSTMSGBUF];
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;
struct getdns_dict *dict = NULL;
struct getdns_dict *ansdict = NULL;
tstmsg_case_begin("tst_dictsetget");
tstmsg_case_begin("tst_dictsetget");
list = getdns_list_create();
dict = getdns_dict_create();
list = getdns_list_create();
dict = getdns_dict_create();
/* test dict get function against empty list and with bogus params */
/* test dict get function against empty list and with bogus params */
tstmsg_case_msg("getdns_list_get_dict() empty list");
retval = getdns_list_get_dict(NULL, index, &dict);
sprintf(msg, "getdns_list_get_dict(NULL, index, &dict),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict() empty list");
retval = getdns_list_get_dict(NULL, index, &dict);
sprintf(msg, "getdns_list_get_dict(NULL, index, &dict),retval = %d",
retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_dict(list, index, NULL);
sprintf(msg, "getdns_list_get_dict(list, index, NULL),retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_dict(list, index, NULL);
sprintf(msg, "getdns_list_get_dict(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict(list, 0, &dict)");
retval = getdns_list_get_dict(list, 0, &dict);
sprintf(msg, "getdns_list_get_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict(list, 0, &dict)");
retval = getdns_list_get_dict(list, 0, &dict);
sprintf(msg, "getdns_list_get_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict(list, 1, &dict)");
retval = getdns_list_get_dict(list, 1, &dict);
sprintf(msg, "getdns_list_get_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_dict(list, 1, &dict)");
retval = getdns_list_get_dict(list, 1, &dict);
sprintf(msg, "getdns_list_get_dict,retval = %d", retval);
tstmsg_case_msg(msg);
/* test int set function against empty list with bogus params */
/* test int set function against empty list with bogus params */
tstmsg_case_msg("getdns_list_set_dict() empty list");
retval = getdns_list_set_dict(NULL, index, dict);
sprintf(msg, "getdns_list_set_dict(NULL, index, dict),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict() empty list");
retval = getdns_list_set_dict(NULL, index, dict);
sprintf(msg, "getdns_list_set_dict(NULL, index, dict),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict(list, 0, dict)");
retval = getdns_list_set_dict(list, 0, dict);
sprintf(msg, "getdns_list_set_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict(list, 0, dict)");
retval = getdns_list_set_dict(list, 0, dict);
sprintf(msg, "getdns_list_set_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict(list, 1, dict)");
retval = getdns_list_set_dict(list, 1, dict);
sprintf(msg, "getdns_list_set_dict,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_dict(list, 1, dict)");
retval = getdns_list_set_dict(list, 1, dict);
sprintf(msg, "getdns_list_set_dict,retval = %d", retval);
tstmsg_case_msg(msg);
/* test set and get legitimate use case */
/* test set and get legitimate use case */
getdns_dict_set_int(dict, "foo", 42);
getdns_list_add_item(list, &index);
getdns_list_set_dict(list, index, dict);
retval = getdns_list_get_dict(list, index, &ansdict);
getdns_dict_get_int(ansdict, "foo", &ans_int);
sprintf(msg, "getdns_list_set/get_dict,retval=%d, ans=%d", retval, ans_int);
tstmsg_case_msg(msg);
getdns_dict_set_int(dict, "foo", 42);
getdns_list_add_item(list, &index);
getdns_list_set_dict(list, index, dict);
retval = getdns_list_get_dict(list, index, &ansdict);
getdns_dict_get_int(ansdict, "foo", &ans_int);
sprintf(msg, "getdns_list_set/get_dict,retval=%d, ans=%d", retval,
ans_int);
tstmsg_case_msg(msg);
getdns_dict_destroy(dict);
getdns_list_destroy(list);
getdns_dict_destroy(dict);
getdns_list_destroy(list);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_dictsetget */
return;
} /* tst_dictsetget */
/*---------------------------------------- tst_listsetget */
/**
@ -199,75 +209,80 @@ tst_dictsetget(void)
void
tst_listsetget(void)
{
char msg[TSTMSGBUF];
size_t index = 0;
getdns_return_t retval;
uint32_t ans_int;
struct getdns_list *list = NULL;
struct getdns_list *new_list = NULL;
struct getdns_list *ans_list = NULL;
char msg[TSTMSGBUF];
size_t index = 0;
getdns_return_t retval;
uint32_t ans_int;
struct getdns_list *list = NULL;
struct getdns_list *new_list = NULL;
struct getdns_list *ans_list = NULL;
tstmsg_case_begin("tst_listsetget");
tstmsg_case_begin("tst_listsetget");
list = getdns_list_create();
list = getdns_list_create();
/* test get function against empty list and with bogus params */
/* test get function against empty list and with bogus params */
tstmsg_case_msg("getdns_list_get_list() empty list");
retval = getdns_list_get_list(NULL, index, &ans_list);
sprintf(msg, "getdns_list_get_list(NULL, index, &ans_list),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list() empty list");
retval = getdns_list_get_list(NULL, index, &ans_list);
sprintf(msg,
"getdns_list_get_list(NULL, index, &ans_list),retval = %d",
retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_list(list, index, NULL);
sprintf(msg, "getdns_list_get_list(list, index, NULL),retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_list(list, index, NULL);
sprintf(msg, "getdns_list_get_list(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list(list, 0, &ans_list)");
retval = getdns_list_get_list(list, 0, &ans_list);
sprintf(msg, "getdns_list_get_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list(list, 0, &ans_list)");
retval = getdns_list_get_list(list, 0, &ans_list);
sprintf(msg, "getdns_list_get_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list(list, 1, &ans_list)");
retval = getdns_list_get_list(list, 1, &ans_list);
sprintf(msg, "getdns_list_get_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_list(list, 1, &ans_list)");
retval = getdns_list_get_list(list, 1, &ans_list);
sprintf(msg, "getdns_list_get_list,retval = %d", retval);
tstmsg_case_msg(msg);
/* test set function against empty list with bogus params */
/* test set function against empty list with bogus params */
tstmsg_case_msg("getdns_list_set_list() empty list");
retval = getdns_list_set_list(NULL, index, NULL);
sprintf(msg, "getdns_list_set_list(NULL, index, ans_list),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list() empty list");
retval = getdns_list_set_list(NULL, index, NULL);
sprintf(msg, "getdns_list_set_list(NULL, index, ans_list),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list(list, 0, ans_list)");
retval = getdns_list_set_list(list, 0, NULL);
sprintf(msg, "getdns_list_set_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list(list, 0, ans_list)");
retval = getdns_list_set_list(list, 0, NULL);
sprintf(msg, "getdns_list_set_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list(list, 1, ans_list)");
retval = getdns_list_set_list(list, 1, NULL);
sprintf(msg, "getdns_list_set_list,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_list(list, 1, ans_list)");
retval = getdns_list_set_list(list, 1, NULL);
sprintf(msg, "getdns_list_set_list,retval = %d", retval);
tstmsg_case_msg(msg);
/* test set and get legitimate use case */
/* test set and get legitimate use case */
new_list = getdns_list_create();
getdns_list_add_item(new_list, &index);
getdns_list_set_int(new_list, index, 42);
new_list = getdns_list_create();
getdns_list_add_item(new_list, &index);
getdns_list_set_int(new_list, index, 42);
getdns_list_add_item(list, &index);
getdns_list_set_list(list, index, new_list);
retval = getdns_list_get_list(list, index, &ans_list);
getdns_list_get_int(ans_list, 0, &ans_int);
sprintf(msg, "getdns_list_set/get_list,retval = %d, ans[0] = %d", retval, ans_int);
tstmsg_case_msg(msg);
getdns_list_add_item(list, &index);
getdns_list_set_list(list, index, new_list);
retval = getdns_list_get_list(list, index, &ans_list);
getdns_list_get_int(ans_list, 0, &ans_int);
sprintf(msg, "getdns_list_set/get_list,retval = %d, ans[0] = %d",
retval, ans_int);
tstmsg_case_msg(msg);
getdns_list_destroy(list);
getdns_list_destroy(list);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_listsetget */
return;
} /* tst_listsetget */
/*---------------------------------------- tst_intsetget */
/**
@ -276,68 +291,72 @@ tst_listsetget(void)
void
tst_intsetget(void)
{
char msg[TSTMSGBUF];
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;
char msg[TSTMSGBUF];
size_t index = 0;
uint32_t ans_int;
getdns_return_t retval;
struct getdns_list *list = NULL;
tstmsg_case_begin("tst_intsetget");
tstmsg_case_begin("tst_intsetget");
list = getdns_list_create();
list = getdns_list_create();
/* test int get function against empty list and with bogus params */
/* test int get function against empty list and with bogus params */
tstmsg_case_msg("getdns_list_get_int() empty list");
retval = getdns_list_get_int(NULL, index, &ans_int);
sprintf(msg, "getdns_list_get_int(NULL, index, &ans_int),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int() empty list");
retval = getdns_list_get_int(NULL, index, &ans_int);
sprintf(msg, "getdns_list_get_int(NULL, index, &ans_int),retval = %d",
retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_int(list, index, NULL);
sprintf(msg, "getdns_list_get_int(list, index, NULL),retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_int(list, index, NULL);
sprintf(msg, "getdns_list_get_int(list, index, NULL),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int(list, 0, &ans_int)");
retval = getdns_list_get_int(list, 0, &ans_int);
sprintf(msg, "getdns_list_get_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int(list, 0, &ans_int)");
retval = getdns_list_get_int(list, 0, &ans_int);
sprintf(msg, "getdns_list_get_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int(list, 1, &ans_int)");
retval = getdns_list_get_int(list, 1, &ans_int);
sprintf(msg, "getdns_list_get_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_int(list, 1, &ans_int)");
retval = getdns_list_get_int(list, 1, &ans_int);
sprintf(msg, "getdns_list_get_int,retval = %d", retval);
tstmsg_case_msg(msg);
/* test int set function against empty list with bogus params */
/* test int set function against empty list with bogus params */
tstmsg_case_msg("getdns_list_set_int() empty list");
retval = getdns_list_set_int(NULL, index, ans_int);
sprintf(msg, "getdns_list_set_int(NULL, index, ans_int),retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int() empty list");
retval = getdns_list_set_int(NULL, index, ans_int);
sprintf(msg, "getdns_list_set_int(NULL, index, ans_int),retval = %d",
retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int(list, 0, ans_int)");
retval = getdns_list_set_int(list, 0, ans_int);
sprintf(msg, "getdns_list_set_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int(list, 0, ans_int)");
retval = getdns_list_set_int(list, 0, ans_int);
sprintf(msg, "getdns_list_set_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int(list, 1, ans_int)");
retval = getdns_list_set_int(list, 1, ans_int);
sprintf(msg, "getdns_list_set_int,retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_set_int(list, 1, ans_int)");
retval = getdns_list_set_int(list, 1, ans_int);
sprintf(msg, "getdns_list_set_int,retval = %d", retval);
tstmsg_case_msg(msg);
/* test set and get legitimate use case */
/* test set and get legitimate use case */
getdns_list_add_item(list, &index);
getdns_list_set_int(list, index, 42);
retval = getdns_list_get_int(list, index, &ans_int);
sprintf(msg, "getdns_list_set/get_int,retval = %d, ans = %d", retval, ans_int);
tstmsg_case_msg(msg);
getdns_list_add_item(list, &index);
getdns_list_set_int(list, index, 42);
retval = getdns_list_get_int(list, index, &ans_int);
sprintf(msg, "getdns_list_set/get_int,retval = %d, ans = %d", retval,
ans_int);
tstmsg_case_msg(msg);
getdns_list_destroy(list);
getdns_list_destroy(list);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_intsetget */
return;
} /* tst_intsetget */
/*---------------------------------------- tst_create */
/**
@ -346,75 +365,71 @@ tst_intsetget(void)
void
tst_create(void)
{
char msg[TSTMSGBUF];
size_t index;
int i;
getdns_return_t retval;
struct getdns_list *list = NULL;
char msg[TSTMSGBUF];
size_t index;
int i;
getdns_return_t retval;
struct getdns_list *list = NULL;
/* make sure we can do a simple create/destroy first */
/* make sure we can do a simple create/destroy first */
tstmsg_case_begin("tst_create");
tstmsg_case_begin("tst_create");
tstmsg_case_msg("getdns_list_create");
list = getdns_list_create();
tstmsg_case_msg("getdns_list_create");
list = getdns_list_create();
if(list != NULL)
{
tstmsg_case_msg("getdns_list_destroy(list)");
getdns_list_destroy(list);
}
if (list != NULL) {
tstmsg_case_msg("getdns_list_destroy(list)");
getdns_list_destroy(list);
}
tstmsg_case_msg("getdns_list_destroy(NULL)");
getdns_list_destroy(NULL);
tstmsg_case_msg("getdns_list_destroy(NULL)");
getdns_list_destroy(NULL);
/* add items until we force it to allocate more storage */
/* add items until we force it to allocate more storage */
tstmsg_case_msg("getdns_add_item(list) past block size");
list = getdns_list_create();
for(i=0; i<GETDNS_LIST_BLOCKSZ+2; i++)
{
retval = getdns_list_add_item(list, &index);
if(retval != GETDNS_RETURN_GOOD)
{
sprintf(msg, "getdns_list_add_item,i=%d,retval = %d", i, retval);
tstmsg_case_msg(msg);
}
else
{
if(index != i)
{
sprintf(msg, "getdns_list_add_item,i=%d,index=%d,retval = %d"
, i, (int) index, retval);
tstmsg_case_msg(msg);
}
}
}
tstmsg_case_msg("getdns_add_item(list) past block size");
list = getdns_list_create();
for (i = 0; i < GETDNS_LIST_BLOCKSZ + 2; i++) {
retval = getdns_list_add_item(list, &index);
if (retval != GETDNS_RETURN_GOOD) {
sprintf(msg, "getdns_list_add_item,i=%d,retval = %d",
i, retval);
tstmsg_case_msg(msg);
} else {
if (index != i) {
sprintf(msg,
"getdns_list_add_item,i=%d,index=%d,retval = %d",
i, (int) index, retval);
tstmsg_case_msg(msg);
}
}
}
tstmsg_case_msg("getdns_list_get_length(list)");
retval = getdns_list_get_length(list, &index);
sprintf(msg, "list length = %d", (int) index);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_length(list)");
retval = getdns_list_get_length(list, &index);
sprintf(msg, "list length = %d", (int) index);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_length()");
retval = getdns_list_get_length(NULL, &index);
sprintf(msg, "NUll, &i, retval = %d", retval);
tstmsg_case_msg(msg);
tstmsg_case_msg("getdns_list_get_length()");
retval = getdns_list_get_length(NULL, &index);
sprintf(msg, "NUll, &i, retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_length(NULL, NULL);
sprintf(msg, "NUll, NULL, retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_length(NULL, NULL);
sprintf(msg, "NUll, NULL, retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_length(list, NULL);
sprintf(msg, "list, NULL, retval = %d", retval);
tstmsg_case_msg(msg);
retval = getdns_list_get_length(list, NULL);
sprintf(msg, "list, NULL, retval = %d", retval);
tstmsg_case_msg(msg);
getdns_list_destroy(list);
getdns_list_destroy(list);
tstmsg_case_end();
tstmsg_case_end();
return;
} /* tst_create */
return;
} /* tst_create */
/*---------------------------------------- main */
/**
@ -423,21 +438,21 @@ tst_create(void)
int
main(int argc, char *argv[])
{
tstmsg_prog_begin("tests_list");
tstmsg_prog_begin("tests_list");
tst_create();
tst_create();
tst_bindatasetget();
tst_bindatasetget();
tst_dictsetget();
tst_dictsetget();
tst_intsetget();
tst_intsetget();
tst_listsetget();
tst_listsetget();
tstmsg_prog_end();
tstmsg_prog_end();
return 0;
} /* main */
return 0;
} /* main */
/* end tests_list.c */

View File

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

View File

@ -32,50 +32,57 @@
#include "testmessages.h"
#include <getdns/getdns.h>
static void print_response(getdns_dict* response) {
char *dict_str = getdns_pretty_print_dict(response);
if (dict_str) {
fprintf(stdout, "The packet %s\n", dict_str);
free(dict_str);
}
static void
print_response(getdns_dict * response)
{
char *dict_str = getdns_pretty_print_dict(response);
if (dict_str) {
fprintf(stdout, "The packet %s\n", dict_str);
free(dict_str);
}
}
int main()
int
main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
getdns_return_t context_create_return =
getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
getdns_dict* response = NULL;
uint32_t responseLen = 0;
getdns_return_t ret = getdns_address_sync(this_context, "www.google.com", NULL, &responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Address sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
ret = getdns_service_sync(this_context, "www.google.com", NULL, &responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Service sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
/* Clean up */
getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
getdns_dict *response = NULL;
uint32_t responseLen = 0;
getdns_return_t ret =
getdns_address_sync(this_context, "www.google.com", NULL,
&responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Address sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
ret =
getdns_service_sync(this_context, "www.google.com", NULL,
&responseLen, &response);
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
fprintf(stderr, "Service sync returned error.\n");
exit(EXIT_FAILURE);
}
print_response(response);
getdns_dict_destroy(response);
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */
} /* main */
/* example-simple-answers.c */

View File

@ -46,110 +46,109 @@ struct ub_ctx;
struct event;
struct event_base;
typedef enum network_req_state_enum {
NET_REQ_NOT_SENT,
NET_REQ_IN_FLIGHT,
NET_REQ_FINISHED,
NET_REQ_CANCELED
typedef enum network_req_state_enum
{
NET_REQ_NOT_SENT,
NET_REQ_IN_FLIGHT,
NET_REQ_FINISHED,
NET_REQ_CANCELED
} network_req_state;
/**
* structure used by validate_extensions() to check extension formats
*/
typedef struct getdns_extension_format {
char *extstring;
getdns_data_type exttype;
typedef struct getdns_extension_format
{
char *extstring;
getdns_data_type exttype;
} getdns_extension_format;
/**
* Request data for unbound
**/
typedef struct getdns_network_req {
typedef struct getdns_network_req
{
/* the async_id from unbound */
int unbound_id;
/* state var */
network_req_state state;
/* owner request (contains name) */
struct getdns_dns_req* owner;
int unbound_id;
/* state var */
network_req_state state;
/* owner request (contains name) */
struct getdns_dns_req *owner;
/* request type */
uint16_t request_type;
/* request type */
uint16_t request_type;
/* request class */
uint16_t request_class;
/* request class */
uint16_t request_class;
/* result */
ldns_pkt* result;
/* result */
ldns_pkt *result;
/* next request to issue after this one */
struct getdns_network_req* next;
/* next request to issue after this one */
struct getdns_network_req *next;
} getdns_network_req;
/**
* dns request - manages a number of network requests and
* the initial data passed to getdns_general
*/
typedef struct getdns_dns_req {
typedef struct getdns_dns_req
{
/* name */
char *name;
/* name */
char *name;
/* canceled flag */
int canceled;
/* canceled flag */
int canceled;
/* current network request */
/* current network request */
struct getdns_network_req *current_req;
/* first request in list */
struct getdns_network_req *first_req;
/* first request in list */
struct getdns_network_req *first_req;
/* request timeout event */
struct event* timeout;
/* request timeout event */
struct event *timeout;
/* local callback timer */
struct event* local_cb_timer;
/* local callback timer */
struct event *local_cb_timer;
/* event base this req is scheduled on */
struct event_base* ev_base;
/* event base this req is scheduled on */
struct event_base *ev_base;
/* context that owns the request */
getdns_context_t context;
/* context that owns the request */
getdns_context_t context;
/* ub_ctx issuing the request */
struct ub_ctx* unbound;
/* ub_ctx issuing the request */
struct ub_ctx *unbound;
/* request extensions */
getdns_dict *extensions;
/* request extensions */
getdns_dict *extensions;
/* callback data */
getdns_callback_t user_callback;
void *user_pointer;
/* callback data */
getdns_callback_t user_callback;
void *user_pointer;
/* the transaction id */
getdns_transaction_t trans_id;
/* the transaction id */
getdns_transaction_t trans_id;
} getdns_dns_req;
/* utility methods */
/* network request utilities */
void network_req_free(getdns_network_req* net_req);
getdns_network_req* network_req_new(getdns_dns_req* owner,
uint16_t request_type,
uint16_t request_class,
struct getdns_dict* extensions);
void network_req_free(getdns_network_req * net_req);
getdns_network_req *network_req_new(getdns_dns_req * owner,
uint16_t request_type,
uint16_t request_class, struct getdns_dict *extensions);
/* dns request utils */
getdns_dns_req* dns_req_new(getdns_context_t context,
struct ub_ctx* unbound,
const char* name,
uint16_t request_type,
struct getdns_dict *extensions);
getdns_dns_req *dns_req_new(getdns_context_t context,
struct ub_ctx *unbound,
const char *name, 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

File diff suppressed because it is too large Load Diff

View File

@ -44,19 +44,21 @@
struct getdns_dns_req;
/* convert an ip address dict to a sock storage */
getdns_return_t dict_to_sockaddr(getdns_dict* ns, struct sockaddr_storage* output);
getdns_return_t sockaddr_to_dict(struct sockaddr_storage* sockaddr, getdns_dict** output);
getdns_return_t dict_to_sockaddr(getdns_dict * ns,
struct sockaddr_storage *output);
getdns_return_t sockaddr_to_dict(struct sockaddr_storage *sockaddr,
getdns_dict ** output);
getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request);
getdns_dict *create_getdns_response(struct getdns_dns_req *completed_request);
/* dict util */
/* set a string as bindata */
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
const char* value);
getdns_return_t getdns_dict_util_set_string(getdns_dict * dict, char *name,
const char *value);
/* get a string from a dict. result is valid as long as dict is valid */
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
char** result);
getdns_return_t getdns_dict_util_get_string(getdns_dict * dict, char *name,
char **result);
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_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 */

View File

@ -38,16 +38,14 @@
*
*/
getdns_return_t
getdns_validate_dnssec(
struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas
)
getdns_validate_dnssec(struct getdns_bindata * record_to_validate,
struct getdns_list * bundle_of_support_records,
struct getdns_list * trust_anchor_rdatas)
{
UNUSED_PARAM(record_to_validate);
UNUSED_PARAM(bundle_of_support_records);
UNUSED_PARAM(trust_anchor_rdatas);
return GETDNS_RETURN_GOOD;
} /* getdns_validate_dnssec */
UNUSED_PARAM(record_to_validate);
UNUSED_PARAM(bundle_of_support_records);
UNUSED_PARAM(trust_anchor_rdatas);
return GETDNS_RETURN_GOOD;
} /* getdns_validate_dnssec */
/* getdns_validate_dnssec.c */