Match getdns.h with current spec

Introducing consts at several places
This commit is contained in:
Willem Toorop 2014-01-14 17:25:23 +01:00
parent 781a6a271f
commit f81db41872
7 changed files with 76 additions and 62 deletions

2
.gitignore vendored
View File

@ -16,10 +16,12 @@ autom4te.cache
missing
libtool
example-all-functions
example-reverse
example-simple-answers
example-synchronous
example-tree
example_all_functions
example_reverse
example_simple_answers
example_synchronous
example_tree

View File

@ -1122,7 +1122,7 @@ getdns_context_clear_outbound_request(getdns_dns_req * req)
}
char *
getdns_strdup(struct mem_funcs *mfs, const char *s)
getdns_strdup(const struct mem_funcs *mfs, const char *s)
{
size_t sz = strlen(s) + 1;
char *r = GETDNS_XMALLOC(*mfs, char, sz);

View File

@ -101,7 +101,7 @@ getdns_return_t getdns_context_clear_outbound_request(struct getdns_dns_req
getdns_return_t getdns_context_cancel_request(struct getdns_context *context,
getdns_transaction_t transaction_id, int fire_callback);
char *getdns_strdup(struct mem_funcs *mfs, const char *str);
char *getdns_strdup(const struct mem_funcs *mfs, const char *str);
struct getdns_bindata *getdns_bindata_copy(
struct mem_funcs *mfs,

View File

@ -55,7 +55,7 @@ static size_t sizeof_dname(uint8_t *dname)
}
char *
getdns_convert_dns_name_to_fqdn(char *name_from_dns_response)
getdns_convert_dns_name_to_fqdn(const char *name_from_dns_response)
{
char *str;
ldns_rdf *rdf = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_DNAME,
@ -68,7 +68,7 @@ getdns_convert_dns_name_to_fqdn(char *name_from_dns_response)
}
char *
getdns_convert_fqdn_to_dns_name(char *fqdn_as_string)
getdns_convert_fqdn_to_dns_name(const char *fqdn_as_string)
{
ldns_rdf *rdf;
char *data;
@ -91,7 +91,7 @@ getdns_convert_fqdn_to_dns_name(char *fqdn_as_string)
*/
char *
getdns_convert_ulabel_to_alabel(char *ulabel)
getdns_convert_ulabel_to_alabel(const char *ulabel)
{
int ret;
char *buf;
@ -122,7 +122,7 @@ getdns_convert_ulabel_to_alabel(char *ulabel)
*/
char *
getdns_convert_alabel_to_ulabel(char *alabel)
getdns_convert_alabel_to_ulabel(const char *alabel)
{
int ret; /* just in case we might want to use it someday */
char *buf;
@ -137,7 +137,7 @@ getdns_convert_alabel_to_ulabel(char *alabel)
char *
getdns_display_ip_address(struct getdns_bindata
getdns_display_ip_address(const struct getdns_bindata
*bindata_of_ipv4_or_ipv6_address)
{
char buff[256];

View File

@ -51,17 +51,21 @@
* @return NULL if additnotfnd == FALSE and key is not in dictionary
*/
struct getdns_dict_item *
getdns_dict_find(struct getdns_dict *dict, char *key, int addifnotfnd)
getdns_dict_find(const struct getdns_dict *dict, const char *key)
{
return (struct getdns_dict_item *)
ldns_rbtree_search((ldns_rbtree_t *)&(dict->root), key);
} /* getdns_dict_find */
struct getdns_dict_item *
getdns_dict_find_and_add(struct getdns_dict *dict, const char *key)
{
struct getdns_dict_item *item;
if (!dict || !key)
return NULL;
item = (struct getdns_dict_item *)
ldns_rbtree_search(&(dict->root), key);
if (!item && addifnotfnd) {
if (!item) {
/* tsearch will add a node automatically for us */
item = GETDNS_MALLOC(dict->mf, struct getdns_dict_item);
item->node.key = getdns_strdup(&dict->mf, key);
@ -69,12 +73,14 @@ getdns_dict_find(struct getdns_dict *dict, char *key, int addifnotfnd)
ldns_rbtree_insert(&(dict->root), (ldns_rbnode_t *) item);
}
return item;
} /* getdns_dict_find */
} /* getdns_dict_find_and_add */
/*---------------------------------------- getdns_dict_get_names
*/
getdns_return_t
getdns_dict_get_names(struct getdns_dict * dict, struct getdns_list ** answer)
getdns_dict_get_names(const struct getdns_dict * dict,
struct getdns_list ** answer)
{
struct getdns_dict_item *item;
size_t index;
@ -89,7 +95,8 @@ getdns_dict_get_names(struct getdns_dict * dict, struct getdns_list ** answer)
if (!*answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root)) {
LDNS_RBTREE_FOR(item, struct getdns_dict_item *,
(ldns_rbtree_t *)&(dict->root)) {
if (getdns_list_add_item(*answer, &index) != GETDNS_RETURN_GOOD)
continue;
bindata.size = strlen(item->node.key) + 1;
@ -101,7 +108,7 @@ getdns_dict_get_names(struct getdns_dict * dict, struct getdns_list ** answer)
/*---------------------------------------- getdns_dict_get_data_type */
getdns_return_t
getdns_dict_get_data_type(struct getdns_dict * dict, char *name,
getdns_dict_get_data_type(const struct getdns_dict * dict, const char *name,
getdns_data_type * answer)
{
struct getdns_dict_item *item;
@ -109,7 +116,7 @@ getdns_dict_get_data_type(struct getdns_dict * dict, char *name,
if (!dict || !name || !answer)
return GETDNS_RETURN_INVALID_PARAMETER;
item = getdns_dict_find(dict, name, 0);
item = getdns_dict_find(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -119,7 +126,7 @@ getdns_dict_get_data_type(struct getdns_dict * dict, char *name,
/*---------------------------------------- getdns_dict_get_dict */
getdns_return_t
getdns_dict_get_dict(struct getdns_dict * dict, char *name,
getdns_dict_get_dict(const struct getdns_dict * dict, const char *name,
struct getdns_dict ** answer)
{
struct getdns_dict_item *item;
@ -127,7 +134,7 @@ getdns_dict_get_dict(struct getdns_dict * dict, char *name,
if (!dict || !name || !answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
item = getdns_dict_find(dict, name, 0);
item = getdns_dict_find(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -140,7 +147,7 @@ getdns_dict_get_dict(struct getdns_dict * dict, char *name,
/*---------------------------------------- getdns_dict_get_list */
getdns_return_t
getdns_dict_get_list(struct getdns_dict * dict, char *name,
getdns_dict_get_list(const struct getdns_dict * dict, const char *name,
struct getdns_list ** answer)
{
struct getdns_dict_item *item;
@ -148,7 +155,7 @@ getdns_dict_get_list(struct getdns_dict * dict, char *name,
if (!dict || !name || !answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
item = getdns_dict_find(dict, name, 0);
item = getdns_dict_find(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -161,7 +168,7 @@ getdns_dict_get_list(struct getdns_dict * dict, char *name,
/*---------------------------------------- getdns_dict_get_bindata */
getdns_return_t
getdns_dict_get_bindata(struct getdns_dict * dict, char *name,
getdns_dict_get_bindata(const struct getdns_dict * dict, const char *name,
struct getdns_bindata ** answer)
{
struct getdns_dict_item *item;
@ -169,7 +176,7 @@ getdns_dict_get_bindata(struct getdns_dict * dict, char *name,
if (!dict || !name || !answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
item = getdns_dict_find(dict, name, 0);
item = getdns_dict_find(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -182,14 +189,15 @@ getdns_dict_get_bindata(struct getdns_dict * dict, char *name,
/*---------------------------------------- getdns_dict_get_int */
getdns_return_t
getdns_dict_get_int(struct getdns_dict * dict, char *name, uint32_t * answer)
getdns_dict_get_int(const struct getdns_dict * dict, const char *name,
uint32_t * answer)
{
struct getdns_dict_item *item;
if (!dict || !name || !answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
item = getdns_dict_find(dict, name, 0);
item = getdns_dict_find(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -389,7 +397,7 @@ getdns_dict_set_dict(struct getdns_dict * dict, char *name,
if (retval != GETDNS_RETURN_GOOD)
return retval;
item = getdns_dict_find(dict, name, 1);
item = getdns_dict_find_and_add(dict, name);
if (!item) {
getdns_dict_destroy(newdict);
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -415,7 +423,7 @@ getdns_dict_set_list(struct getdns_dict * dict, char *name,
if (retval != GETDNS_RETURN_GOOD)
return retval;
item = getdns_dict_find(dict, name, 1);
item = getdns_dict_find_and_add(dict, name);
if (!item) {
getdns_list_destroy(newlist);
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -440,7 +448,7 @@ getdns_dict_set_bindata(struct getdns_dict * dict, char *name,
if (!newbindata)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
item = getdns_dict_find(dict, name, 1);
item = getdns_dict_find_and_add(dict, name);
if (!item) {
getdns_bindata_destroy(&dict->mf, newbindata);
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -460,7 +468,7 @@ getdns_dict_set_int(struct getdns_dict * dict, char *name,
if (!dict || !name)
return GETDNS_RETURN_INVALID_PARAMETER;
item = getdns_dict_find(dict, name, 1);
item = getdns_dict_find_and_add(dict, name);
if (!item)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
@ -531,7 +539,8 @@ getdns_pp_bindata(ldns_buffer * buf, size_t indent,
} /* getdns_pp_bindata */
static int
getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict);
getdns_pp_dict(ldns_buffer * buf, size_t indent,
const struct getdns_dict *dict);
/*---------------------------------------- getdns_pp_list */
/**
@ -627,7 +636,8 @@ getdns_pp_list(ldns_buffer * buf, size_t indent, struct getdns_list *list)
* if an output error is encountered, a negative value
*/
static int
getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict)
getdns_pp_dict(ldns_buffer * buf, size_t indent,
const struct getdns_dict *dict)
{
size_t i, length, p = ldns_buffer_position(buf);
struct getdns_dict_item *item;
@ -640,7 +650,8 @@ getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict)
i = 0;
indent += 2;
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(dict->root)) {
LDNS_RBTREE_FOR(item, struct getdns_dict_item *,
(ldns_rbtree_t *)&(dict->root)) {
if (ldns_buffer_printf(buf, "%s\n%s\"%s\":", (i ? "," : "")
, getdns_indent(indent)
, item->node.key) < 0)
@ -706,7 +717,7 @@ getdns_pp_dict(ldns_buffer * buf, size_t indent, struct getdns_dict *dict)
* or NULL on error
*/
char *
getdns_pretty_print_dict(struct getdns_dict *dict)
getdns_pretty_print_dict(const struct getdns_dict *dict)
{
ldns_buffer *buf;
char *ret;

View File

@ -371,7 +371,7 @@ getdns_return_t getdns_strerror(getdns_return_t err, char *buf, size_t buflen);
* @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 *this_list,
getdns_return_t getdns_list_get_length(const struct getdns_list *this_list,
size_t * answer);
/**
* get the enumerated data type of the indexed list item
@ -381,7 +381,7 @@ getdns_return_t getdns_list_get_length(struct getdns_list *this_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 *this_list,
getdns_return_t getdns_list_get_data_type(const struct getdns_list *this_list,
size_t index, getdns_data_type * answer);
/**
* retrieve the dictionary value of the specified list item, the caller must not free
@ -394,7 +394,7 @@ getdns_return_t getdns_list_get_data_type(struct getdns_list *this_list,
* @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 *this_list, size_t index,
getdns_return_t getdns_list_get_dict(const struct getdns_list *this_list, size_t index,
struct getdns_dict **answer);
/**
@ -408,7 +408,7 @@ getdns_return_t getdns_list_get_dict(struct getdns_list *this_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_list(struct getdns_list *this_list, size_t index,
getdns_return_t getdns_list_get_list(const struct getdns_list *this_list, size_t index,
struct getdns_list **answer);
/**
* retrieve the binary data value of the specified list item, the caller must not
@ -421,7 +421,7 @@ getdns_return_t getdns_list_get_list(struct getdns_list *this_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_bindata(struct getdns_list *this_list, size_t index,
getdns_return_t getdns_list_get_bindata(const struct getdns_list *this_list, size_t index,
struct getdns_bindata **answer);
/**
* retrieve the integer value of the specified list item
@ -432,7 +432,7 @@ getdns_return_t getdns_list_get_bindata(struct getdns_list *this_list, size_t in
* @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 *this_list, size_t index,
getdns_return_t getdns_list_get_int(const struct getdns_list *this_list, size_t index,
uint32_t * answer);
/**
@ -443,7 +443,7 @@ getdns_return_t getdns_list_get_int(struct getdns_list *this_list, size_t index,
* @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 *this_dict,
getdns_return_t getdns_dict_get_names(const struct getdns_dict *this_dict,
struct getdns_list **answer);
/**
* fetch the data type for the data associated with the specified name
@ -453,8 +453,8 @@ getdns_return_t getdns_dict_get_names(struct getdns_dict *this_dict,
* @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(const struct getdns_dict *this_dict,
const 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
@ -465,8 +465,8 @@ getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict,
* @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(const struct getdns_dict *this_dict,
const 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
@ -477,8 +477,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(const struct getdns_dict *this_dict,
const char *name, struct getdns_list **answer);
/**
* fetch the bindata associated with the specified name, the bindata should not be
* free()'d by the caller
@ -488,8 +488,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(const struct getdns_dict *this_dict,
const 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
@ -498,8 +498,8 @@ getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict,
* @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(const struct getdns_dict *this_dict,
const char *name, uint32_t * answer);
/**
* create a new list with no items
@ -769,13 +769,13 @@ getdns_service_sync(struct getdns_context *context,
/** @}
*/
char *getdns_convert_dns_name_to_fqdn(char *name_from_dns_response);
char *getdns_convert_dns_name_to_fqdn(const char *name_from_dns_response);
char *getdns_convert_fqdn_to_dns_name(char *fqdn_as_string);
char *getdns_convert_fqdn_to_dns_name(const char *fqdn_as_string);
char *getdns_convert_ulabel_to_alabel(char *ulabel);
char *getdns_convert_ulabel_to_alabel(const char *ulabel);
char *getdns_convert_alabel_to_ulabel(char *alabel);
char *getdns_convert_alabel_to_ulabel(const char *alabel);
getdns_return_t
getdns_validate_dnssec(struct getdns_bindata *record_to_validate,
@ -789,9 +789,9 @@ getdns_validate_dnssec(struct getdns_bindata *record_to_validate,
* @param this_dict dictionary to pretty print
* @return character array (caller must free this) containing pretty string
*/
char *getdns_pretty_print_dict(struct getdns_dict *some_dict);
char *getdns_pretty_print_dict(const struct getdns_dict *some_dict);
char *getdns_display_ip_address(struct getdns_bindata
char *getdns_display_ip_address(const struct getdns_bindata
*bindata_of_ipv4_or_ipv6_address);
/*

View File

@ -41,7 +41,7 @@
/*---------------------------------------- getdns_list_get_length */
getdns_return_t
getdns_list_get_length(struct getdns_list * list, size_t * answer)
getdns_list_get_length(const struct getdns_list * list, size_t * answer)
{
if (!list || !answer)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
@ -52,7 +52,7 @@ getdns_list_get_length(struct getdns_list * list, size_t * answer)
/*---------------------------------------- getdns_list_get_data_type */
getdns_return_t
getdns_list_get_data_type(struct getdns_list * list, size_t index,
getdns_list_get_data_type(const struct getdns_list * list, size_t index,
getdns_data_type * answer)
{
if (!list || index >= list->numinuse)
@ -67,7 +67,7 @@ getdns_list_get_data_type(struct getdns_list * list, size_t index,
/*---------------------------------------- getdns_list_get_dict */
getdns_return_t
getdns_list_get_dict(struct getdns_list * list, size_t index,
getdns_list_get_dict(const struct getdns_list * list, size_t index,
struct getdns_dict ** answer)
{
if (!list || index >= list->numinuse)
@ -85,7 +85,7 @@ getdns_list_get_dict(struct getdns_list * list, size_t index,
/*---------------------------------------- getdns_list_get_list */
getdns_return_t
getdns_list_get_list(struct getdns_list * list, size_t index,
getdns_list_get_list(const struct getdns_list * list, size_t index,
struct getdns_list ** answer)
{
@ -104,7 +104,7 @@ getdns_list_get_list(struct getdns_list * list, size_t index,
/*---------------------------------------- getdns_list_get_bindata */
getdns_return_t
getdns_list_get_bindata(struct getdns_list * list, size_t index,
getdns_list_get_bindata(const struct getdns_list * list, size_t index,
struct getdns_bindata ** answer)
{
if (!list || index >= list->numinuse)
@ -122,7 +122,8 @@ getdns_list_get_bindata(struct getdns_list * list, size_t index,
/*---------------------------------------- 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(const struct getdns_list * list, size_t index,
uint32_t * answer)
{
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;