Creating, destroying, reading from and manipulating getdns_dicts

Functions

getdns_return_t getdns_dict_get_names (const getdns_dict *dict, getdns_list **answer)
 
getdns_return_t getdns_dict_get_data_type (const getdns_dict *dict, const char *name, getdns_data_type *answer)
 
getdns_return_t getdns_dict_get_dict (const getdns_dict *dict, const char *name, getdns_dict **answer)
 
getdns_return_t getdns_dict_get_list (const getdns_dict *dict, const char *name, getdns_list **answer)
 
getdns_return_t getdns_dict_get_bindata (const getdns_dict *dict, const char *name, getdns_bindata **answer)
 
getdns_return_t getdns_dict_get_int (const getdns_dict *dict, const char *name, uint32_t *answer)
 
getdns_dictgetdns_dict_create ()
 
getdns_dictgetdns_dict_create_with_context (const getdns_context *context)
 
getdns_dictgetdns_dict_create_with_memory_functions (void *(*malloc)(size_t), void *(*realloc)(void *, size_t), void(*free)(void *))
 
getdns_dictgetdns_dict_create_with_extended_memory_functions (void *userarg, void *(*malloc)(void *userarg, size_t), void *(*realloc)(void *userarg, void *, size_t), void(*free)(void *userarg, void *))
 
void getdns_dict_destroy (getdns_dict *dict)
 
getdns_return_t getdns_dict_set_dict (getdns_dict *dict, const char *name, const getdns_dict *child_dict)
 
getdns_return_t getdns_dict_set_list (getdns_dict *dict, const char *name, const getdns_list *child_list)
 
getdns_return_t getdns_dict_set_bindata (getdns_dict *dict, const char *name, const getdns_bindata *child_bindata)
 
getdns_return_t getdns_dict_set_int (getdns_dict *dict, const char *name, uint32_t child_uint32)
 
char * getdns_pretty_print_dict (const getdns_dict *some_dict)
 
getdns_return_t getdns_dict_util_set_string (getdns_dict *dict, const char *name, const char *value)
 
getdns_return_t getdns_dict_util_get_string (const getdns_dict *dict, const char *name, char **result)
 
int getdns_pretty_snprint_dict (char *str, size_t size, const getdns_dict *dict)
 
char * getdns_print_json_dict (const getdns_dict *some_dict, int pretty)
 
int getdns_snprint_json_dict (char *str, size_t size, const getdns_dict *dict, int pretty)
 

Detailed Description

Function Documentation

◆ getdns_dict_get_names()

getdns_return_t getdns_dict_get_names ( const getdns_dict dict,
getdns_list **  answer 
)

fetch a list of names from the dictionary, this list must be freed by the caller via a call to getdns_list_destroy

Parameters
dictdictionary from which to produce the list of names
**answera pointer to the new list will be assigned to *answer
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or empty

◆ getdns_dict_get_data_type()

getdns_return_t getdns_dict_get_data_type ( const getdns_dict dict,
const char *  name,
getdns_data_type answer 
)

fetch the data type for the data associated with the specified name

Parameters
dictdictionary from which to fetch the data type
namea name/key value to look up in the dictionary
*answerdata type will be stored at this address
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_dict_get_dict()

getdns_return_t getdns_dict_get_dict ( const getdns_dict dict,
const char *  name,
getdns_dict **  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 free()'d

Parameters
dictdictionary from which to fetch the dictionary
namea name/key value to look up in the dictionary
**answera copy of the dictionary will be stored at this address
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_dict_get_list()

getdns_return_t getdns_dict_get_list ( const getdns_dict dict,
const char *  name,
getdns_list **  answer 
)

fetch the list associated with the specified name the list should not be free()'d by the caller, when the dictionary is destroyed the list will also be destroyed

Parameters
dictdictionary from which to fetch the list
namea name/key value to look up in the dictionary
**answera copy of the list will be stored at this address
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_dict_get_bindata()

getdns_return_t getdns_dict_get_bindata ( const getdns_dict dict,
const char *  name,
getdns_bindata **  answer 
)

fetch the bindata associated with the specified name, the bindata should not be free()'d by the caller

Parameters
dictdictionary from which to fetch the bindata
namea name/key value to look up in the dictionary
**answera copy of the bindata will be stored at this address
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_dict_get_int()

getdns_return_t getdns_dict_get_int ( const getdns_dict dict,
const char *  name,
uint32_t *  answer 
)

fetch the integer value associated with the specified name

Parameters
dictdictionary from which to fetch the integer
namea name/key value to look up in the dictionary
*answerthe integer will be stored at this address
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_dict_create()

getdns_dict* getdns_dict_create ( )

create a new dictionary with no items

Returns
pointer to an allocated dictionary, NULL if insufficient memory

◆ getdns_dict_create_with_context()

getdns_dict* getdns_dict_create_with_context ( const getdns_context context)

create a new dict with no items, creating and initializing it with the custom memory function from context. These memory functions will be used for creating, and inherited by the list members when populating the dict. The custom deallocator will be used for destroying the dict.

Parameters
contextThe context from which the custom memory functions will be used to create and initialize the dict.
Returns
pointer to an allocated dict, NULL if insufficient memory

◆ getdns_dict_create_with_memory_functions()

getdns_dict* getdns_dict_create_with_memory_functions ( void *(*)(size_t)  malloc,
void *(*)(void *, size_t)  realloc,
void(*)(void *)  free 
)

create a new dict with no items, creating and initializing it with the provided custom memory function. These memory functions will be used for creating, and inherited by the dict members when populating the dict. The custom deallocator will be used for destroying the dict.

Parameters
mallocCustom allocator
reallocCustom reallocator
freeCustom deallocator
Returns
pointer to an allocated dict, NULL if insufficient memory

◆ getdns_dict_create_with_extended_memory_functions()

getdns_dict* getdns_dict_create_with_extended_memory_functions ( void *  userarg,
void *(*)(void *userarg, size_t)  malloc,
void *(*)(void *userarg, void *, size_t)  realloc,
void(*)(void *userarg, void *)  free 
)

create a new dict with no items, creating and initializing it with the provided extended custom memory function. These memory functions will be used for creating, and inherited by the dict members when populating the dict. The custom deallocator will be used for destroying the dict.

Parameters
userargWill be passed as the first argument to the extended custom malloc, realloc, and free.
mallocCustom allocator
reallocCustom reallocator
freeCustom deallocator
Returns
pointer to an allocated dict, NULL if insufficient memory

◆ getdns_dict_destroy()

void getdns_dict_destroy ( getdns_dict dict)

destroy a dictionary and all items within that dictionary be aware that if you have fetched any data from the dictionary it will no longer be available (you are likely to experience bad things if you try)

◆ getdns_dict_set_dict()

getdns_return_t getdns_dict_set_dict ( getdns_dict dict,
const char *  name,
const 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_dict_

Parameters
dictdictionary in which to add or change the value
namekey that identifies which item in the dictionary to add/change
child_dictvalue to assign to the node identified by name
Returns
GETDNS_RETURN_GOOD on success

◆ getdns_dict_set_list()

getdns_return_t getdns_dict_set_list ( getdns_dict dict,
const char *  name,
const 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_list

Parameters
dictdictionary in which to add or change the value
namekey that identifies which item in the dictionary to add/change
child_listvalue to assign to the node identified by name
Returns
GETDNS_RETURN_GOOD on success

◆ getdns_dict_set_bindata()

getdns_return_t getdns_dict_set_bindata ( getdns_dict dict,
const char *  name,
const getdns_bindata child_bindata 
)

create a new entry in the dictionary, or replace the value of an existing entry this routine makes a copy of the child_bindata

Parameters
dictdictionary in which to add or change the value
namekey that identifies which item in the dictionary to add/change
child_bindatavalue to assign to the node identified by name
Returns
GETDNS_RETURN_GOOD on success

◆ getdns_dict_set_int()

getdns_return_t getdns_dict_set_int ( getdns_dict dict,
const char *  name,
uint32_t  child_uint32 
)

create a new entry in the dictionary, or replace the value of an existing entry

Parameters
dictdictionary in which to add or change the value
namekey that identifies which item in the dictionary to add/change
child_uint32value to assign to the node identified by name
Returns
GETDNS_RETURN_GOOD on success

◆ getdns_pretty_print_dict()

char* getdns_pretty_print_dict ( const getdns_dict some_dict)

creates a string that describes the dictionary in a human readable form one line per item in the dictionary

Parameters
some_dictdictionary to pretty print
Returns
character array (caller must free this) containing pretty string

◆ getdns_dict_util_set_string()

getdns_return_t getdns_dict_util_set_string ( getdns_dict dict,
const char *  name,
const char *  value 
)

Create a new entry in the dictionary, or replace the value of an existing entry, with a getdns_bindata representing a string. The string will be copied. The size of the bindata will be strlen(value), though there will be a '\0' byte directly after the size'd position even, though the size argument suggests that this would not be part of the bindata's date space.

See also
getdns_dict_set_bindata
Parameters
dictdictionary in which to add or change the value
namekey that identifies which item in the dictionary to add/change
valuestring to be copied and stored in the bindata at key
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_INVALID_PARAMETER when one of the arguments was NULL
GETDNS_RETURN_MEMORY_ERROR when the copy could not be allocated

◆ getdns_dict_util_get_string()

getdns_return_t getdns_dict_util_get_string ( const getdns_dict dict,
const char *  name,
char **  result 
)

Get the string associated with the speicifed name. The string should not be free()'d by the caller.

See also
getdns_dict_get_bindata
Parameters
dictdictionary from which to fetch the bindata
namea name/key value to look up in the dictionary
resultThe bindata's data value
Returns
GETDNS_RETURN_GOOD on success
GETDNS_RETURN_NO_SUCH_DICT_NAME if dict is invalid or name does not exist

◆ getdns_pretty_snprint_dict()

int getdns_pretty_snprint_dict ( char *  str,
size_t  size,
const getdns_dict dict 
)

Pretty print the getdns_dict in a given buffer snprintf style.

Parameters
strpointer to the buffer to print to
sizesize of the given buffer. No more than size bytes (including the terminating null byte) will be written to str.
dictgetdns_dict to print
Returns
The number of characters written excluding the terminating null byte or the number of characters which would have been written if enough space had been available.

◆ getdns_print_json_dict()

char* getdns_print_json_dict ( const getdns_dict some_dict,
int  pretty 
)

creates a string containing a json representation of some_dict. bindatas are converted to strings when possible, including bindatas for addresses, dnames and other printable data. All other bindatas are converted to lists of byte values.

Parameters
some_dictdict to represent as json data
prettywhen non-zero returns formatted json
Returns
character array (caller must free this) containing pretty string

◆ getdns_snprint_json_dict()

int getdns_snprint_json_dict ( char *  str,
size_t  size,
const getdns_dict dict,
int  pretty 
)

Prints a json representation of dict in a given buffer snprintf style. bindatas are converted to strings when possible, including bindatas for addresses, dnames and other printable data. All other bindatas are converted to lists of byte values.

Parameters
strpointer to the buffer to print to
sizesize of the given buffer. No more than size bytes (including the terminating null byte) will be written to str.
dictdict to represent as json data
prettywhen non-zero returns formatted json
Returns
The number of characters written excluding the terminating null byte or the number of characters which would have been written if enough space had been available.