Issue #410: Document ownership with getdns_context_get_api_information()

+ const for extensions and namespaces
TODO: Look at other cases that are not const for no good reason.

Thanks Stefan Bühler
This commit is contained in:
Willem Toorop 2018-11-27 16:59:47 +01:00
parent 2d76a5fd52
commit e3b007a43a
10 changed files with 47 additions and 43 deletions

View File

@ -1,4 +1,5 @@
* 2018-0?-??: Version 1.4.3 * 2018-0?-??: Version 1.4.3
* Issue #410: Unspecified ownership of get_api_information()
* Fix for DNSSEC bug in finding most specific key when * Fix for DNSSEC bug in finding most specific key when
trust anchor proves non-existance of one of the labels trust anchor proves non-existance of one of the labels
along the authentication chain other than the non- along the authentication chain other than the non-

View File

@ -2132,7 +2132,7 @@ getdns_context_set_resolution_type(struct getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_context_set_namespaces(getdns_context *context, 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; size_t i;
getdns_return_t r = GETDNS_RETURN_GOOD; getdns_return_t r = GETDNS_RETURN_GOOD;

View File

@ -492,7 +492,7 @@ extformatcmp(const void *a, const void *b)
/*---------------------------------------- validate_extensions */ /*---------------------------------------- validate_extensions */
static getdns_return_t 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 * 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 static getdns_return_t
getdns_general_ns(getdns_context *context, getdns_eventloop *loop, 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, void *userarg, getdns_network_req **return_netreq_p,
getdns_callback_t callbackfn, internal_cb_t internal_cb, int usenamespaces) 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_return_t
_getdns_general_loop(getdns_context *context, getdns_eventloop *loop, _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, void *userarg, getdns_network_req **netreq_p,
getdns_callback_t callback, internal_cb_t internal_cb) 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_return_t
_getdns_address_loop(getdns_context *context, getdns_eventloop *loop, _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_transaction_t *transaction_id, getdns_callback_t callback)
{ {
getdns_dict *my_extensions = extensions; getdns_dict *my_extensions = NULL;
getdns_return_t r; getdns_return_t r;
uint32_t value; uint32_t value;
getdns_network_req *netreq = NULL; getdns_network_req *netreq = NULL;
if (!my_extensions) { if (!extensions) {
if (!(my_extensions=getdns_dict_create_with_context(context))) if (!(my_extensions=getdns_dict_create_with_context(context)))
return GETDNS_RETURN_MEMORY_ERROR; return GETDNS_RETURN_MEMORY_ERROR;
} else if ( } 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))) && (r = _getdns_dict_copy(extensions, &my_extensions)))
return r; 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))) my_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE)))
return r; return r;
r = getdns_general_ns(context, loop, 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); userarg, &netreq, callback, NULL, 1);
if (netreq && transaction_id) if (netreq && transaction_id)
*transaction_id = netreq->owner->trans_id; *transaction_id = netreq->owner->trans_id;
if (my_extensions != extensions) if (my_extensions)
getdns_dict_destroy(my_extensions); getdns_dict_destroy(my_extensions);
return r; return r;
@ -752,7 +752,7 @@ _getdns_address_loop(getdns_context *context, getdns_eventloop *loop,
getdns_return_t getdns_return_t
_getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, _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) getdns_transaction_t *transaction_id, getdns_callback_t callback)
{ {
struct getdns_bindata *address_data; struct getdns_bindata *address_data;
@ -842,7 +842,7 @@ _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop,
getdns_return_t getdns_return_t
_getdns_service_loop(getdns_context *context, getdns_eventloop *loop, _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_transaction_t * transaction_id, getdns_callback_t callback)
{ {
getdns_return_t r; getdns_return_t r;
@ -859,7 +859,7 @@ _getdns_service_loop(getdns_context *context, getdns_eventloop *loop,
*/ */
getdns_return_t getdns_return_t
getdns_general(getdns_context *context, 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, void *userarg, getdns_transaction_t * transaction_id,
getdns_callback_t callbackfn) getdns_callback_t callbackfn)
{ {
@ -881,7 +881,7 @@ getdns_general(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_address(getdns_context *context, 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) getdns_transaction_t *transaction_id, getdns_callback_t callbackfn)
{ {
if (!context) return GETDNS_RETURN_INVALID_PARAMETER; if (!context) return GETDNS_RETURN_INVALID_PARAMETER;
@ -896,7 +896,7 @@ getdns_address(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_hostname(getdns_context *context, 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) getdns_transaction_t *transaction_id, getdns_callback_t callbackfn)
{ {
if (!context) return GETDNS_RETURN_INVALID_PARAMETER; if (!context) return GETDNS_RETURN_INVALID_PARAMETER;
@ -910,7 +910,7 @@ getdns_hostname(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_service(getdns_context *context, 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) getdns_transaction_t *transaction_id, getdns_callback_t callbackfn)
{ {
if (!context) return GETDNS_RETURN_INVALID_PARAMETER; if (!context) return GETDNS_RETURN_INVALID_PARAMETER;

View File

@ -63,25 +63,25 @@ int _getdns_submit_netreq(getdns_network_req *netreq, uint64_t *now_ms);
getdns_return_t getdns_return_t
_getdns_general_loop(getdns_context *context, getdns_eventloop *loop, _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, void *userarg, getdns_network_req **netreq_p,
getdns_callback_t callbackfn, internal_cb_t internal_cb); getdns_callback_t callbackfn, internal_cb_t internal_cb);
getdns_return_t getdns_return_t
_getdns_address_loop(getdns_context *context, getdns_eventloop *loop, _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, void *userarg, getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn); getdns_callback_t callbackfn);
getdns_return_t getdns_return_t
_getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, _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, void *userarg, getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn); getdns_callback_t callbackfn);
getdns_return_t getdns_return_t
_getdns_service_loop(getdns_context *context, getdns_eventloop *loop, _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, void *userarg, getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn); getdns_callback_t callbackfn);

View File

@ -1030,7 +1030,7 @@ getdns_return_t
getdns_general(getdns_context *context, getdns_general(getdns_context *context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
getdns_dict *extensions, const getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
@ -1048,7 +1048,7 @@ getdns_general(getdns_context *context,
getdns_return_t getdns_return_t
getdns_address(getdns_context *context, getdns_address(getdns_context *context,
const char *name, const char *name,
getdns_dict *extensions, const getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
@ -1065,8 +1065,8 @@ getdns_address(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_hostname(getdns_context *context, getdns_hostname(getdns_context *context,
getdns_dict *address, const getdns_dict *address,
getdns_dict *extensions, const getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
@ -1084,7 +1084,7 @@ getdns_hostname(getdns_context *context,
getdns_return_t getdns_return_t
getdns_service(getdns_context *context, getdns_service(getdns_context *context,
const char *name, const char *name,
getdns_dict *extensions, const getdns_dict *extensions,
void *userarg, void *userarg,
getdns_transaction_t * transaction_id, getdns_callback_t callbackfn); getdns_transaction_t * transaction_id, getdns_callback_t callbackfn);
/** @} /** @}
@ -1201,7 +1201,7 @@ getdns_return_t
getdns_general_sync(getdns_context *context, getdns_general_sync(getdns_context *context,
const char *name, const char *name,
uint16_t request_type, uint16_t request_type,
getdns_dict *extensions, const getdns_dict *extensions,
getdns_dict **response); getdns_dict **response);
/** /**
@ -1216,7 +1216,7 @@ getdns_general_sync(getdns_context *context,
getdns_return_t getdns_return_t
getdns_address_sync(getdns_context *context, getdns_address_sync(getdns_context *context,
const char *name, const char *name,
getdns_dict *extensions, const getdns_dict *extensions,
getdns_dict **response); getdns_dict **response);
/** /**
@ -1230,8 +1230,8 @@ getdns_address_sync(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_hostname_sync(getdns_context *context, getdns_hostname_sync(getdns_context *context,
getdns_dict *address, const getdns_dict *address,
getdns_dict *extensions, const getdns_dict *extensions,
getdns_dict **response); getdns_dict **response);
/** /**
@ -1246,7 +1246,7 @@ getdns_hostname_sync(getdns_context *context,
getdns_return_t getdns_return_t
getdns_service_sync(getdns_context *context, getdns_service_sync(getdns_context *context,
const char *name, const char *name,
getdns_dict *extensions, const getdns_dict *extensions,
getdns_dict **response); getdns_dict **response);
/** @} /** @}
@ -1444,7 +1444,7 @@ getdns_context_set_resolution_type(getdns_context *context,
*/ */
getdns_return_t getdns_return_t
getdns_context_set_namespaces(getdns_context *context, 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 * 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. * GETDNS_RESOLUTION_STUB.
* - all_context (a dict) with names for all the other settings in * - all_context (a dict) with names for all the other settings in
* context. * context.
* The application is responsible for cleaning up the returned dictionary
* object with getdns_dict_destroy.
*/ */
getdns_dict* getdns_dict*
getdns_context_get_api_information(getdns_context* context); getdns_context_get_api_information(getdns_context* context);

View File

@ -92,7 +92,7 @@ getdns_dict *no_dnssec_checking_disabled_opportunistic
= &no_dnssec_checking_disabled_opportunistic_spc; = &no_dnssec_checking_disabled_opportunistic_spc;
static int 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; getdns_return_t r;
uint32_t value; 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, int with_opt, int edns_maximum_udp_payload_size,
uint8_t edns_extended_rcode, uint8_t edns_version, int edns_do_bit, uint8_t edns_extended_rcode, uint8_t edns_version, int edns_do_bit,
uint16_t opt_options_size, size_t noptions, getdns_list *options, 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; uint8_t *buf;
getdns_dict *option; getdns_dict *option;
@ -699,7 +699,7 @@ static const uint8_t no_suffixes[] = { 1, 0 };
/* create a new dns req to be submitted */ /* create a new dns req to be submitted */
getdns_dns_req * getdns_dns_req *
_getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop, _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) uint64_t *now_ms)
{ {
int dnssec_return_status = is_extension_set( int dnssec_return_status = is_extension_set(

View File

@ -164,7 +164,7 @@ getdns_sync_cb(getdns_context *context, getdns_callback_type_t callback_type,
getdns_return_t getdns_return_t
getdns_general_sync(getdns_context *context, const char *name, 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_sync_data data;
getdns_return_t r; getdns_return_t r;
@ -190,7 +190,7 @@ getdns_general_sync(getdns_context *context, const char *name,
getdns_return_t getdns_return_t
getdns_address_sync(getdns_context *context, const char *name, 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_sync_data data;
getdns_return_t r; getdns_return_t r;
@ -215,8 +215,8 @@ getdns_address_sync(getdns_context *context, const char *name,
} }
getdns_return_t getdns_return_t
getdns_hostname_sync(getdns_context *context, getdns_dict *address, getdns_hostname_sync(getdns_context *context, const getdns_dict *address,
getdns_dict *extensions, getdns_dict **response) const getdns_dict *extensions, getdns_dict **response)
{ {
getdns_sync_data data; getdns_sync_data data;
getdns_return_t r; getdns_return_t r;
@ -242,7 +242,7 @@ getdns_hostname_sync(getdns_context *context, getdns_dict *address,
getdns_return_t getdns_return_t
getdns_service_sync(getdns_context *context, const char *name, 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_sync_data data;
getdns_return_t r; getdns_return_t r;

View File

@ -431,7 +431,8 @@ extern getdns_dict *no_dnssec_checking_disabled_opportunistic;
/* dns request utils */ /* dns request utils */
getdns_dns_req *_getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop, 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); void _getdns_dns_req_free(getdns_dns_req * req);

View File

@ -143,7 +143,7 @@ int rbtree_find_less_equal(rbtree_type *rbtree, const void *key,
* @param rbtree: tree * @param rbtree: tree
* @return: smallest element or NULL if tree empty. * @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 * Returns last (largest) node in the tree

View File

@ -546,7 +546,7 @@ rbtree_find_less_equal(rbtree_type *rbtree, const void *key,
* *
*/ */
rbnode_type * rbnode_type *
rbtree_first (rbtree_type *rbtree) rbtree_first (const rbtree_type *rbtree)
{ {
rbnode_type *node; rbnode_type *node;