getdns_dict(3)

๐Ÿ“ฆ
version 1.7.3 ยท 2 versions
, in alpine 3.24, arch rolling, epel 10, epel 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu resolute, ubuntu stonking

โœจ NAME โœจ

okay so bestie, welcome to getdns_dict(3) โ€” section 3 of the getdns manual, and yes this is the dict create-and-destroy corner of the library ๐Ÿ’–

The whole crew here is:

  • getdns_dict
  • getdns_dict_create
  • getdns_dict_create_with_extended_memory_functions
  • getdns_dict_create_with_memory_functions
  • getdns_dict_destroy

โ€ฆand together they're the getdns dict create and destroy routines. That's the whole vibe. ๐ŸŽ€


๐Ÿ“š LIBRARY ๐Ÿ“š

DNS Resolver library (libgetdns, -lgetdns) โ€” she lives in libgetdns and you link her with -lgetdns, periodt. ๐Ÿฆ‹


๐Ÿซถ SYNOPSIS ๐Ÿซถ

#include <getdns.h>

getdns_dict *
getdns_dict_create ()

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

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

void
getdns_dict_destroy (getdns_dict *this_dict)

not me listing five whole functions like it's nothing ๐Ÿ˜ญ but fr fr, that's the whole API right there. Copy it exactly, bestie, character for character. ๐Ÿ’…


๐Ÿ’… DESCRIPTION ๐Ÿ’…

So the getdns_dict type is how you manage name/value pairs where the names are strings and the values areโ€ฆ honestly a little chaotic in the best way ๐ŸŒ€ โ€” the data types of the values are heterogeneous, and they include:

  • getdns_bindata
  • getdns_dict
  • getdns_list
  • uint32_t

it's giving "we contain multitudes" โœจ a dict can hold bindata, other dicts, lists, and plain uint32_t numbers, all at once. iconic behaviour honestly.

Now the important one: the destroy function performs a "deep" destroy, freeing storage for all of the members of the dictionary before destroying the dictionary itself. ๐ŸŒŠ so it's not just yeeting the top-level struct โ€” it goes all the way down and cleans up everything inside first. she's thorough. she's responsible. we love her. ๐Ÿซถ

careful though, because "deep destroy" means it's taking everything with it. don't go freeing members yourself and then calling this โ€” that's how you get double frees and a very bad time. ๐Ÿ’€

There are also a number of helper functions that provide access to the dictionary object โ€” go read their respective man pages for that whole situation, iykyk. ๐Ÿ‘‘

And here's what those two parameters actually mean:

  • userarg โ€” pass this argument to the user specified memory management functions for operations on lists created using extended memory functions. so you hand it over, and it gets passed along to your custom malloc/realloc/free crew. ๐Ÿค
  • this_dict โ€” the dictionary to destroy. that's it. that's the whole job. ๐Ÿ’…

๐ŸŒŸ RETURN VALUES ๐ŸŒŸ

Upon successful completion, the getdns_dict_create function returns a valid (empty) dictionary structure โœจ โ€” and heads up, that thing should be freed via a call to getdns_dict_destroy. don't just leave her lying around, that's not the move. ๐Ÿšฎ

And if a parameter is invalid, or in the event of some error, getdns_dict_create returns NULL. so likeโ€ฆ always check. no cap. ๐Ÿ™ˆ


๐ŸŽ€ EXAMPLES ๐ŸŽ€

TBD โ€” the examples section is literally just "TBD" in the original and I am not about to make stuff up for you, bestie. the examples are, at this moment, unwritten. we wait. we manifest. ๐Ÿ•ฏ๏ธโœจ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

go read these next, they're all part of the same friend group:


and that's the page!! ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

this one came out of getdns version 1.7.3, dated December 2015 โ€” so yeah, a lil vintage, but she's still serving. mwah. ๐Ÿ’œ๐Ÿ“