[getdns-api] Feedback wanted for getdns_context_set_update_callback function (was Re: Questions and Suggestions After Implementing PHP Language Bindings)

Willem Toorop willem at nlnetlabs.nl
Tue Apr 7 16:33:40 CEST 2015


Dear All,

As Scott Hollenbeck has rightfully noticed (see quoted message below),
the API is inconsistent in its use of user registered functions.

A request callback function provided with an asynchronous requests, is
given alongside a (void *) user argument which will be passed when the
callback is called.  Similarly, user defined memory management functions
accommodate a user argument (perhaps to point to a structure to help
with memory book-keeping).  In contrast, the
getdns_context_set_context_update_callback does provide these means.

I propose to replace it with a new function that allows an user argument:

getdns_return_t
getdns_context_set_update_callback(
  getdns_context  *context,
  void            *userarg,
  void            (*value)(getdns_context       *context,
                           getdns_context_code_t changed_item,
                           void                 *userarg)
);

The new name is to keep the API backwards compatible.  An implementation
can provide the old symbol, though undocumented.
What do you think?

-- Willem

Op 11-03-15 om 12:44 schreef Hollenbeck, Scott:
> I've been experimenting with an effort to develop PHP language bindings for getdns. After exploring swig [1] and ultimately deciding to abandon it, I managed to get something working using the Zend engine. In the near future I hope to share the results. For the most part I found everything easy to understand and implement once I got more familiar with Zend. So far I've only found two things that tripped me up a little. So, I have a few questions and suggestions based on my implementation experience:
> 
> The callback function used with the async functions like getdns_address() includes a "void *userarg" parameter. The callback function used with getdns_context_set_context_update_callback() doesn't include a "void *userarg" parameter - why?
> 
> I found that parameter very useful. To make the PHP bindings work I need to pass the name of a callback function in PHP user space to the C code that wraps the async functions, and from there to the internal callback function that I use to call the callback function in PHP user space. It's easy to do when I can include the string that represents the PHP function name in a structure whose address gets passed with *userarg from wrapped function to internal callback. Without userarg in getdns_context_set_context_update_callback() I'm temporarily using a hard-coded PHP function name because there's no easy way get the string representing the name of a user-supplied function to the internal callback. Would it be possible to add a "void *userarg" to the list of arguments for the callback function?
> 
> The getdns_strerror() function requires the caller to allocate a buffer into which a character string will be written. The caller has no idea how long the longest returned string might be, though, so I had to pick some arbitrarily large value in the hope that it would be large enough. Would it be possible to either return a string with the expectation that the caller will be responsible for freeing it, or can a constant be defined to identify the largest buffer needed?
> 
> Scott
> 
> [1] http://getdnsapi.net/pipermail/users/2015-February/000010.html
> 
> _______________________________________________
> getdns-api mailing list
> getdns-api at vpnc.org
> 

_______________________________________________
getdns-api mailing list
getdns-api at vpnc.org



More information about the spec mailing list