From 6e8ace78ff06f4de3e69c97e897fd817711fd109 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Fri, 21 Feb 2014 12:55:34 +0100 Subject: [PATCH] Match examples with current spec [API 0.402] --- src/example/example-all-functions.c | 53 ++---- src/example/example-reverse.c | 62 ++----- src/example/example-simple-answers.c | 231 ++++++--------------------- src/example/example-synchronous.c | 38 +---- src/example/example-tree.c | 52 ++---- 5 files changed, 90 insertions(+), 346 deletions(-) diff --git a/src/example/example-all-functions.c b/src/example/example-all-functions.c index a89bc11d..632bd4de 100644 --- a/src/example/example-all-functions.c +++ b/src/example/example-all-functions.c @@ -1,29 +1,3 @@ -/* - * Copyright (c) 2013, NLNet Labs, Versign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ #include #include #include @@ -40,6 +14,7 @@ char * retcharstar; /* The args */ int boolarg; char * charstararg; +char ** charstarptrarg; getdns_callback_t callbackarg; uint16_t regulararg; uint16_t *regularptrarg; @@ -52,16 +27,16 @@ getdns_transport_t transportarg; getdns_append_name_t appendnamearg; 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_bindata ** bindataptrarg; +getdns_dict * dictarg; +getdns_bindata * bindataarg; +getdns_list * listarg; +getdns_dict ** dictptrarg; +getdns_list ** listptrarg; size_t sizetarg; size_t * sizetptrarg; -struct getdns_context *contextarg = NULL; +getdns_context *contextarg = NULL; uint8_t uint8arg; uint16_t uint16arg; uint32_t uint32arg; @@ -80,7 +55,7 @@ void * extendedreallocfunctionarg(void* userarg, void* foo, size_t bar) {UNUSED_PARAM(userarg); UNUSED_PARAM(foo); UNUSED_PARAM(bar); return NULL; } void extendeddeallocfunctionarg(void* userarg, void* foo) {UNUSED_PARAM(userarg); UNUSED_PARAM(foo);} -void setcallbackfunctionarg(struct getdns_context *foo1, getdns_context_code_t foo2) +void setcallbackfunctionarg(getdns_context *foo1, getdns_context_code_t foo2) {UNUSED_PARAM(foo1);UNUSED_PARAM(foo2);} int main() @@ -236,12 +211,14 @@ retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg); retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg); retregular = getdns_dict_remove_name(dictarg, charstararg); -retcharstar = getdns_convert_fqdn_to_dns_name( - charstararg +retregular = getdns_convert_fqdn_to_dns_name( + charstararg, + bindataptrarg ); -retcharstar = getdns_convert_dns_name_to_fqdn( - charstararg +retregular = getdns_convert_dns_name_to_fqdn( + bindataarg, + charstarptrarg ); retcharstar = getdns_convert_ulabel_to_alabel( diff --git a/src/example/example-reverse.c b/src/example/example-reverse.c index a0351b64..d72b503a 100644 --- a/src/example/example-reverse.c +++ b/src/example/example-reverse.c @@ -1,35 +1,3 @@ -/* - * Copyright (c) 2013, NLNet Labs, Versign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "config.h" -#ifdef HAVE_EVENT2_EVENT_H -# include -#else -# include -#endif #include #include #include @@ -40,9 +8,9 @@ #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 *this_context, +void this_callbackfn(getdns_context *this_context, getdns_callback_type_t this_callback_type, - struct getdns_dict *this_response, + getdns_dict *this_response, void *this_userarg, getdns_transaction_t this_transaction_id) { @@ -61,39 +29,37 @@ void this_callbackfn(struct getdns_context *this_context, getdns_dict_destroy(this_response); return; } - struct getdns_list *replies_tree; + getdns_list *replies_tree; this_ret = getdns_dict_get_list(this_response, "replies_tree", &replies_tree); // Ignore any error size_t num_replies; this_ret = getdns_list_get_length(replies_tree, &num_replies); // Ignore any error /* Go through each reply */ for ( size_t reply_count = 0; reply_count < num_replies; ++reply_count) { - struct getdns_dict * this_reply; + getdns_dict * this_reply; this_ret = getdns_list_get_dict(replies_tree, reply_count, &this_reply); // Ignore any error /* Just print the address */ - struct getdns_list* reply_answers; + getdns_list* reply_answers; this_ret = getdns_dict_get_list(this_reply, "answer", &reply_answers); // Ignore any error size_t num_answers; this_ret = getdns_list_get_length(reply_answers, &num_answers); // Ignore any error /* Go through each answer */ for ( size_t answer_count = 0; answer_count < num_answers; ++answer_count) { - struct getdns_dict * this_rr; + getdns_dict * this_rr; this_ret = getdns_list_get_dict(reply_answers, answer_count, &this_rr); /* Get the RDATA type */ uint32_t this_type; this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error if (this_type == GETDNS_RRTYPE_PTR) { - struct getdns_dict *this_rdata; + getdns_dict *this_rdata; this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error - struct getdns_bindata * this_dname; + getdns_bindata * this_dname; this_ret = getdns_dict_get_bindata(this_rdata, "rdata_raw", &this_dname); - char *this_dname_str = getdns_convert_dns_name_to_fqdn((char *)this_dname->data); - printf("The dname is %s\n", this_dname_str); - free(this_dname_str); - + char *this_dname_str; + this_ret = getdns_convert_dns_name_to_fqdn(this_dname, &this_dname_str); // Ignore any error } } @@ -109,7 +75,7 @@ void this_callbackfn(struct getdns_context *this_context, int main() { /* Create the DNS context for this call */ - struct getdns_context *this_context = NULL; + getdns_context *this_context = NULL; getdns_return_t context_create_return = getdns_context_create(&this_context, 1); if (context_create_return != GETDNS_RETURN_GOOD) { @@ -127,12 +93,12 @@ int main() } (void)getdns_extension_set_libevent_base(this_context, this_event_base); /* Set up the getdns call */ - struct getdns_dict * this_addr_to_look_up = getdns_dict_create(); + getdns_dict * this_addr_to_look_up = getdns_dict_create(); // TODO: check the return value above - struct getdns_bindata this_type = { 4, (void *)"IPv4" }; + getdns_bindata this_type = { 4, (void *)"IPv4" }; getdns_return_t this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_type", &this_type); UNUSED_PARAM(this_ret); - struct getdns_bindata this_ipv4_addr = { 4, (void *)"\x08\x08\x08\x08" }; + getdns_bindata this_ipv4_addr = { 4, (void *)"\x08\x08\x08\x08" }; this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_data", &this_ipv4_addr); char* this_userarg = "somestring"; // Could add things here to help identify this call getdns_transaction_t this_transaction_id = 0; diff --git a/src/example/example-simple-answers.c b/src/example/example-simple-answers.c index 3dad21dd..1866543c 100644 --- a/src/example/example-simple-answers.c +++ b/src/example/example-simple-answers.c @@ -1,212 +1,75 @@ -/** - * - * \file example-simple-answers.c - * @brief example using getdns to resolve a simple query - * - * Originally taken from the getdns API description pseudo implementation. - * Modified to more clearly demonstrate some of the API features. - * - */ - -/* - * Copyright (c) 2013, NLNet Labs, Versign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - #include #include #include #include -#include #include #include #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 *this_context, - uint16_t this_callback_type, - struct getdns_dict *this_response, - void *this_userarg, - getdns_transaction_t this_transaction_id) +void this_callbackfn(getdns_context *this_context, + getdns_callback_type_t this_callback_type, + getdns_dict *this_response, + void *this_userarg, + getdns_transaction_t this_transaction_id) { - getdns_return_t this_ret; - uint32_t this_error; - size_t num_addresses; - struct getdns_list *just_the_addresses_ptr; - struct getdns_dict *this_address; - struct getdns_bindata *this_address_data; - size_t rec_count; - char *this_address_str; - - UNUSED_PARAM(this_userarg); - UNUSED_PARAM(this_context); - + 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 */ - - this_ret = getdns_dict_get_int(this_response, "status", &this_error); - if (this_ret != GETDNS_RETURN_GOOD) - { - fprintf(stderr, "The dictionary does not contain \"status\" (this shouldn't have happened). Exiting\n"); - getdns_dict_destroy(this_response); - return; - } - - if (this_error != GETDNS_RESPSTATUS_GOOD) + 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" { fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error); getdns_dict_destroy(this_response); return; } - + 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) + if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic" { - fprintf(stderr, "The dict does not contain \"just_address_answers\" (this shouldn't have happened), and returned %d. Exiting.\n", this_ret); + fprintf(stderr, "Trying to get the answers failed: %d\n", this_ret); getdns_dict_destroy(this_response); return; } - - this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); - if (this_ret != GETDNS_RETURN_GOOD) - { - fprintf(stderr, "The address list is invalid (this shouldn't have happened). Exiting\n"); - getdns_dict_destroy(this_response); - return; - } - - if (num_addresses == 0) - fprintf(stderr, "The address list has 0 records. Exiting\n"); - + size_t num_addresses; + this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error /* Go through each record */ - for (rec_count = 0; rec_count < num_addresses; ++rec_count) + for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count ) { - this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); - if(this_ret != GETDNS_RETURN_GOOD) - { - fprintf(stderr, "Record %d is invalid (this shouldn't have happened). skipping.\n", (int) rec_count); - continue; - } - + getdns_dict * this_address; + this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error /* Just print the address */ - this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); - if(this_ret != GETDNS_RETURN_GOOD) - { - fprintf(stderr, "Record %d does not contain \"address_data\" (this shouldn't happen), skipping\n", (int) rec_count); - } - else - { - this_address_str = getdns_display_ip_address(this_address_data); - printf("The address is %s\n", this_address_str); - free(this_address_str); - } - } // for rec_count + getdns_bindata * this_address_data; + this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error + char *this_address_str = getdns_display_ip_address(this_address_data); + printf("The address is %s\n", this_address_str); + free(this_address_str); + } } 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); - getdns_dict_destroy(this_response); -} /* this_callbackfn */ +} -void -usage(void) +int main() { - printf( - "USAGE: example-simple-answers [-s] [hostname]\n" - "\n" - "-s act as stub resolver (default is to act as a recursive resolver)\n" - "\n" - "The example program demonstrates the simplest use of the getdns API to\n" - "resolve a hostname to an IP address\n" - "\n"); - - return; -} /* usage */ - -/*---------------------------------------- main */ -int -main(int argc, char *argv[]) -{ - char *this_name = "www.example.com"; - char *this_userarg = "somestring"; - char opt; - int stubonly = 0; - int dispatch_return; - int exitval = EXIT_SUCCESS; - struct getdns_context *this_context = NULL; - struct event_base *this_event_base; - getdns_return_t dns_request_return; - getdns_transaction_t this_transaction_id; - getdns_return_t context_create_return; - - while((opt = getopt(argc, argv, "?s")) != -1) - { - switch(opt) - { - case 's': - stubonly = 1; - break; - case '?': - default: - usage(); - exit(1); - } - } - argc -= optind; - argv += optind; - - if(argc > 0) - this_name = argv[0]; - - printf("resolving %s\n", this_name); - - /* Create the DNS context for this call, use OS configs such as resolv.conf */ - - context_create_return = getdns_context_create(&this_context, 1); + /* Create the DNS context for this call */ + getdns_context *this_context = NULL; + getdns_return_t context_create_return = getdns_context_create(&this_context, 1); if (context_create_return != GETDNS_RETURN_GOOD) { fprintf(stderr, "Trying to create the context failed: %d", context_create_return); return(GETDNS_RETURN_GENERIC_ERROR); } - - if(stubonly == 1) - { - if(getdns_context_set_resolution_type(this_context, GETDNS_RESOLUTION_STUB) - != GETDNS_RETURN_GOOD) - { - fprintf(stderr, "Failed to set stub resolver in context (this should never fail). Exiting.\n"); - 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) { @@ -214,36 +77,32 @@ main(int argc, char *argv[]) getdns_context_destroy(this_context); return(GETDNS_RETURN_GENERIC_ERROR); } - 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 */ - - this_transaction_id = 0; + 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 */ - - dns_request_return = getdns_address(this_context, this_name, + getdns_return_t dns_request_return = getdns_address(this_context, this_name, NULL, this_userarg, &this_transaction_id, this_callbackfn); if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) { fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name); - exitval = GETDNS_RETURN_GENERIC_ERROR; + event_base_free(this_event_base); + getdns_context_destroy(this_context); + return(GETDNS_RETURN_GENERIC_ERROR); } else { /* Call the event loop */ - - dispatch_return = event_base_dispatch(this_event_base); - if(dispatch_return < 0) - fprintf(stderr, "event_base_dispatch() failed, returned %d\n", dispatch_return); + int dispatch_return = event_base_dispatch(this_event_base); + UNUSED_PARAM(dispatch_return); + // TODO: check the return value above } - /* Clean up */ - event_base_free(this_event_base); getdns_context_destroy(this_context); - - return exitval; -} /* main */ - -/* example-simple-answers.c */ + /* Assuming we get here, leave gracefully */ + exit(EXIT_SUCCESS); +} diff --git a/src/example/example-synchronous.c b/src/example/example-synchronous.c index 43f1f1ff..4095388b 100644 --- a/src/example/example-synchronous.c +++ b/src/example/example-synchronous.c @@ -1,29 +1,3 @@ -/* - * Copyright (c) 2013, NLNet Labs, Versign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ #include #include #include @@ -35,7 +9,7 @@ int main() { getdns_return_t this_ret; /* Holder for all function returns */ /* Create the DNS context for this call */ - struct getdns_context *this_context = NULL; + getdns_context *this_context = NULL; getdns_return_t context_create_return = getdns_context_create(&this_context, 1); if (context_create_return != GETDNS_RETURN_GOOD) { @@ -46,7 +20,7 @@ int main() const char * this_name = "www.example.com"; uint8_t this_request_type = GETDNS_RRTYPE_A; /* Get the A and AAAA records */ - struct getdns_dict * this_extensions = getdns_dict_create(); + getdns_dict * 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) { @@ -55,7 +29,7 @@ int main() getdns_context_destroy(this_context); return(GETDNS_RETURN_GENERIC_ERROR); } - struct getdns_dict * this_response = NULL; + getdns_dict * this_response = NULL; /* Make the call */ getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type, @@ -81,17 +55,17 @@ int main() getdns_context_destroy(this_context); return(GETDNS_RETURN_GENERIC_ERROR); } - struct getdns_list * just_the_addresses_ptr; + getdns_list * just_the_addresses_ptr; this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error size_t num_addresses; this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error /* Go through each record */ for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count ) { - struct getdns_dict * this_address; + getdns_dict * this_address; this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error /* Just print the address */ - struct getdns_bindata * this_address_data; + getdns_bindata * this_address_data; this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error char *this_address_str = getdns_display_ip_address(this_address_data); printf("The address is %s\n", this_address_str); diff --git a/src/example/example-tree.c b/src/example/example-tree.c index 54d12b41..f815baee 100644 --- a/src/example/example-tree.c +++ b/src/example/example-tree.c @@ -1,35 +1,3 @@ -/* - * Copyright (c) 2013, NLNet Labs, Versign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "config.h" -#ifdef HAVE_EVENT2_EVENT_H -# include -#else -# include -#endif #include #include #include @@ -40,9 +8,9 @@ #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 *this_context, +void this_callbackfn(getdns_context *this_context, getdns_callback_type_t this_callback_type, - struct getdns_dict *this_response, + getdns_dict *this_response, void *this_userarg, getdns_transaction_t this_transaction_id) { @@ -61,7 +29,7 @@ void this_callbackfn(struct getdns_context *this_context, return; } /* Find all the answers returned */ - struct getdns_list * these_answers; + 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) { @@ -74,20 +42,20 @@ void this_callbackfn(struct getdns_context *this_context, /* Go through each answer */ for ( size_t rec_count = 0; rec_count < num_answers; ++rec_count ) { - struct getdns_dict * this_record; + 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; + 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; this_ret = getdns_list_get_length(this_answer, &num_rrs); for ( size_t rr_count = 0; rr_count < num_rrs; ++rr_count ) { - struct getdns_dict *this_rr = NULL; + 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; + 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; @@ -95,7 +63,7 @@ void this_callbackfn(struct getdns_context *this_context, /* If it is type A or AAAA, print the value */ if (this_type == GETDNS_RRTYPE_A) { - struct getdns_bindata * this_a_record = NULL; + 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) { @@ -110,7 +78,7 @@ void this_callbackfn(struct getdns_context *this_context, } else if (this_type == GETDNS_RRTYPE_AAAA) { - struct getdns_bindata * this_aaaa_record = NULL; + 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) { @@ -136,7 +104,7 @@ void this_callbackfn(struct getdns_context *this_context, int main() { /* Create the DNS context for this call */ - struct getdns_context *this_context = NULL; + getdns_context *this_context = NULL; getdns_return_t context_create_return = getdns_context_create(&this_context, 1); if (context_create_return != GETDNS_RETURN_GOOD) {