From e3b007a43a24a3b0783c6c8deac24c5ec13b7eef Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Tue, 27 Nov 2018 16:59:47 +0100 Subject: [PATCH] Issue #410: Document ownership with getdns_context_get_api_information() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + const for extensions and namespaces TODO: Look at other cases that are not const for no good reason. Thanks Stefan Bühler --- ChangeLog | 1 + src/context.c | 2 +- src/general.c | 32 ++++++++++++++++---------------- src/general.h | 8 ++++---- src/getdns/getdns.h.in | 24 +++++++++++++----------- src/request-internal.c | 6 +++--- src/sync.c | 10 +++++----- src/types-internal.h | 3 ++- src/util/orig-headers/rbtree.h | 2 +- src/util/rbtree.c | 2 +- 10 files changed, 47 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a87df27..2ba1508e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ * 2018-0?-??: Version 1.4.3 + * Issue #410: Unspecified ownership of get_api_information() * Fix for DNSSEC bug in finding most specific key when trust anchor proves non-existance of one of the labels along the authentication chain other than the non- diff --git a/src/context.c b/src/context.c index 7b879f60..6dcbe489 100644 --- a/src/context.c +++ b/src/context.c @@ -2132,7 +2132,7 @@ getdns_context_set_resolution_type(struct getdns_context *context, */ getdns_return_t getdns_context_set_namespaces(getdns_context *context, - size_t namespace_count, getdns_namespace_t *namespaces) + size_t namespace_count, const getdns_namespace_t *namespaces) { size_t i; getdns_return_t r = GETDNS_RETURN_GOOD; diff --git a/src/general.c b/src/general.c index 3e50124d..9de1d510 100644 --- a/src/general.c +++ b/src/general.c @@ -492,7 +492,7 @@ extformatcmp(const void *a, const void *b) /*---------------------------------------- validate_extensions */ static getdns_return_t -validate_extensions(struct getdns_dict * extensions) +validate_extensions(const getdns_dict * extensions) { /** * this is a comprehensive list of extensions and their data types @@ -555,7 +555,7 @@ validate_extensions(struct getdns_dict * extensions) static getdns_return_t getdns_general_ns(getdns_context *context, getdns_eventloop *loop, - const char *name, uint16_t request_type, getdns_dict *extensions, + const char *name, uint16_t request_type, const getdns_dict *extensions, void *userarg, getdns_network_req **return_netreq_p, getdns_callback_t callbackfn, internal_cb_t internal_cb, int usenamespaces) { @@ -706,7 +706,7 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop, getdns_return_t _getdns_general_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, uint16_t request_type, getdns_dict *extensions, + const char *name, uint16_t request_type, const getdns_dict *extensions, void *userarg, getdns_network_req **netreq_p, getdns_callback_t callback, internal_cb_t internal_cb) { @@ -718,33 +718,33 @@ _getdns_general_loop(getdns_context *context, getdns_eventloop *loop, getdns_return_t _getdns_address_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, getdns_dict *extensions, void *userarg, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callback) { - getdns_dict *my_extensions = extensions; + getdns_dict *my_extensions = NULL; getdns_return_t r; uint32_t value; getdns_network_req *netreq = NULL; - if (!my_extensions) { + if (!extensions) { if (!(my_extensions=getdns_dict_create_with_context(context))) return GETDNS_RETURN_MEMORY_ERROR; } else if ( - getdns_dict_get_int(my_extensions, "return_both_v4_and_v6", &value) + getdns_dict_get_int(extensions, "return_both_v4_and_v6", &value) && (r = _getdns_dict_copy(extensions, &my_extensions))) return r; - if (my_extensions != extensions && (r = getdns_dict_set_int( + if (my_extensions && (r = getdns_dict_set_int( my_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE))) return r; r = getdns_general_ns(context, loop, - name, GETDNS_RRTYPE_AAAA, my_extensions, + name, GETDNS_RRTYPE_AAAA, my_extensions ? my_extensions : extensions, userarg, &netreq, callback, NULL, 1); if (netreq && transaction_id) *transaction_id = netreq->owner->trans_id; - if (my_extensions != extensions) + if (my_extensions) getdns_dict_destroy(my_extensions); return r; @@ -752,7 +752,7 @@ _getdns_address_loop(getdns_context *context, getdns_eventloop *loop, getdns_return_t _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, - getdns_dict *address, getdns_dict *extensions, void *userarg, + const getdns_dict *address, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callback) { struct getdns_bindata *address_data; @@ -842,7 +842,7 @@ _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, getdns_return_t _getdns_service_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, getdns_dict *extensions, void *userarg, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callback) { getdns_return_t r; @@ -859,7 +859,7 @@ _getdns_service_loop(getdns_context *context, getdns_eventloop *loop, */ getdns_return_t getdns_general(getdns_context *context, - const char *name, uint16_t request_type, getdns_dict *extensions, + const char *name, uint16_t request_type, const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn) { @@ -881,7 +881,7 @@ getdns_general(getdns_context *context, */ getdns_return_t getdns_address(getdns_context *context, - const char *name, getdns_dict *extensions, void *userarg, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn) { if (!context) return GETDNS_RETURN_INVALID_PARAMETER; @@ -896,7 +896,7 @@ getdns_address(getdns_context *context, */ getdns_return_t getdns_hostname(getdns_context *context, - getdns_dict *address, getdns_dict *extensions, void *userarg, + const getdns_dict *address, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn) { if (!context) return GETDNS_RETURN_INVALID_PARAMETER; @@ -910,7 +910,7 @@ getdns_hostname(getdns_context *context, */ getdns_return_t getdns_service(getdns_context *context, - const char *name, getdns_dict *extensions, void *userarg, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn) { if (!context) return GETDNS_RETURN_INVALID_PARAMETER; diff --git a/src/general.h b/src/general.h index e0860c78..f99c1b46 100644 --- a/src/general.h +++ b/src/general.h @@ -63,25 +63,25 @@ int _getdns_submit_netreq(getdns_network_req *netreq, uint64_t *now_ms); getdns_return_t _getdns_general_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, uint16_t request_type, getdns_dict *extensions, + const char *name, uint16_t request_type, const getdns_dict *extensions, void *userarg, getdns_network_req **netreq_p, getdns_callback_t callbackfn, internal_cb_t internal_cb); getdns_return_t _getdns_address_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, getdns_dict *extensions, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn); getdns_return_t _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, - getdns_dict *address, getdns_dict *extensions, + const getdns_dict *address, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn); getdns_return_t _getdns_service_loop(getdns_context *context, getdns_eventloop *loop, - const char *name, getdns_dict *extensions, + const char *name, const getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn); diff --git a/src/getdns/getdns.h.in b/src/getdns/getdns.h.in index 23e59cf4..aa7ae128 100644 --- a/src/getdns/getdns.h.in +++ b/src/getdns/getdns.h.in @@ -1030,7 +1030,7 @@ getdns_return_t getdns_general(getdns_context *context, const char *name, uint16_t request_type, - getdns_dict *extensions, + const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); @@ -1048,7 +1048,7 @@ getdns_general(getdns_context *context, getdns_return_t getdns_address(getdns_context *context, const char *name, - getdns_dict *extensions, + const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); @@ -1065,8 +1065,8 @@ getdns_address(getdns_context *context, */ getdns_return_t getdns_hostname(getdns_context *context, - getdns_dict *address, - getdns_dict *extensions, + const getdns_dict *address, + const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); @@ -1084,7 +1084,7 @@ getdns_hostname(getdns_context *context, getdns_return_t getdns_service(getdns_context *context, const char *name, - getdns_dict *extensions, + const getdns_dict *extensions, void *userarg, getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); /** @} @@ -1201,7 +1201,7 @@ getdns_return_t getdns_general_sync(getdns_context *context, const char *name, uint16_t request_type, - getdns_dict *extensions, + const getdns_dict *extensions, getdns_dict **response); /** @@ -1216,7 +1216,7 @@ getdns_general_sync(getdns_context *context, getdns_return_t getdns_address_sync(getdns_context *context, const char *name, - getdns_dict *extensions, + const getdns_dict *extensions, getdns_dict **response); /** @@ -1230,8 +1230,8 @@ getdns_address_sync(getdns_context *context, */ getdns_return_t getdns_hostname_sync(getdns_context *context, - getdns_dict *address, - getdns_dict *extensions, + const getdns_dict *address, + const getdns_dict *extensions, getdns_dict **response); /** @@ -1246,7 +1246,7 @@ getdns_hostname_sync(getdns_context *context, getdns_return_t getdns_service_sync(getdns_context *context, const char *name, - getdns_dict *extensions, + const getdns_dict *extensions, getdns_dict **response); /** @} @@ -1444,7 +1444,7 @@ getdns_context_set_resolution_type(getdns_context *context, */ getdns_return_t getdns_context_set_namespaces(getdns_context *context, - size_t namespace_count, getdns_namespace_t *namespaces); + size_t namespace_count, const getdns_namespace_t *namespaces); /** * Specifies what transport are used for DNS lookups. The default is @@ -1812,6 +1812,8 @@ getdns_context_set_extended_memory_functions(getdns_context *context, * GETDNS_RESOLUTION_STUB. * - all_context (a dict) with names for all the other settings in * context. + * The application is responsible for cleaning up the returned dictionary + * object with getdns_dict_destroy. */ getdns_dict* getdns_context_get_api_information(getdns_context* context); diff --git a/src/request-internal.c b/src/request-internal.c index 89476717..46c77e05 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -92,7 +92,7 @@ getdns_dict *no_dnssec_checking_disabled_opportunistic = &no_dnssec_checking_disabled_opportunistic_spc; static int -is_extension_set(getdns_dict *extensions, const char *name, int default_value) +is_extension_set(const getdns_dict *extensions, const char *name, int default_value) { getdns_return_t r; uint32_t value; @@ -167,7 +167,7 @@ network_req_init(getdns_network_req *net_req, getdns_dns_req *owner, int with_opt, int edns_maximum_udp_payload_size, uint8_t edns_extended_rcode, uint8_t edns_version, int edns_do_bit, uint16_t opt_options_size, size_t noptions, getdns_list *options, - size_t wire_data_sz, size_t max_query_sz, getdns_dict *extensions) + size_t wire_data_sz, size_t max_query_sz, const getdns_dict *extensions) { uint8_t *buf; getdns_dict *option; @@ -699,7 +699,7 @@ static const uint8_t no_suffixes[] = { 1, 0 }; /* create a new dns req to be submitted */ getdns_dns_req * _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop, - const char *name, uint16_t request_type, getdns_dict *extensions, + const char *name, uint16_t request_type, const getdns_dict *extensions, uint64_t *now_ms) { int dnssec_return_status = is_extension_set( diff --git a/src/sync.c b/src/sync.c index e592e7d1..bcf66e6f 100644 --- a/src/sync.c +++ b/src/sync.c @@ -164,7 +164,7 @@ getdns_sync_cb(getdns_context *context, getdns_callback_type_t callback_type, getdns_return_t getdns_general_sync(getdns_context *context, const char *name, - uint16_t request_type, getdns_dict *extensions, getdns_dict **response) + uint16_t request_type, const getdns_dict *extensions, getdns_dict **response) { getdns_sync_data data; getdns_return_t r; @@ -190,7 +190,7 @@ getdns_general_sync(getdns_context *context, const char *name, getdns_return_t getdns_address_sync(getdns_context *context, const char *name, - getdns_dict *extensions, getdns_dict **response) + const getdns_dict *extensions, getdns_dict **response) { getdns_sync_data data; getdns_return_t r; @@ -215,8 +215,8 @@ getdns_address_sync(getdns_context *context, const char *name, } getdns_return_t -getdns_hostname_sync(getdns_context *context, getdns_dict *address, - getdns_dict *extensions, getdns_dict **response) +getdns_hostname_sync(getdns_context *context, const getdns_dict *address, + const getdns_dict *extensions, getdns_dict **response) { getdns_sync_data data; getdns_return_t r; @@ -242,7 +242,7 @@ getdns_hostname_sync(getdns_context *context, getdns_dict *address, getdns_return_t getdns_service_sync(getdns_context *context, const char *name, - getdns_dict *extensions, getdns_dict **response) + const getdns_dict *extensions, getdns_dict **response) { getdns_sync_data data; getdns_return_t r; diff --git a/src/types-internal.h b/src/types-internal.h index a97b1719..e36b1f60 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -431,7 +431,8 @@ extern getdns_dict *no_dnssec_checking_disabled_opportunistic; /* dns request utils */ getdns_dns_req *_getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop, - const char *name, uint16_t request_type, getdns_dict *extensions, uint64_t *now_ms); + const char *name, uint16_t request_type, const getdns_dict *extensions, + uint64_t *now_ms); void _getdns_dns_req_free(getdns_dns_req * req); diff --git a/src/util/orig-headers/rbtree.h b/src/util/orig-headers/rbtree.h index dfcf09ac..2768c2c5 100644 --- a/src/util/orig-headers/rbtree.h +++ b/src/util/orig-headers/rbtree.h @@ -143,7 +143,7 @@ int rbtree_find_less_equal(rbtree_type *rbtree, const void *key, * @param rbtree: tree * @return: smallest element or NULL if tree empty. */ -rbnode_type *rbtree_first(rbtree_type *rbtree); +rbnode_type *rbtree_first(const rbtree_type *rbtree); /** * Returns last (largest) node in the tree diff --git a/src/util/rbtree.c b/src/util/rbtree.c index f031c9a1..ff4e3e46 100644 --- a/src/util/rbtree.c +++ b/src/util/rbtree.c @@ -546,7 +546,7 @@ rbtree_find_less_equal(rbtree_type *rbtree, const void *key, * */ rbnode_type * -rbtree_first (rbtree_type *rbtree) +rbtree_first (const rbtree_type *rbtree) { rbnode_type *node;