Pass along a userarg with context update callbacks

This commit is contained in:
Willem Toorop 2015-04-02 14:42:26 +02:00
parent 18381e7753
commit 56bb9dbbdc
4 changed files with 30 additions and 3 deletions

View File

@ -24,6 +24,9 @@
* Better random number generation with OpenBSD's arc4random
* Let getdns_address schedule the AAAA query first. This results in AAAA
being the first in the just_address_answers sections of the response dict.
* New context update callback function to also return a user given argument
along with the context and which item was changed.
Thanks Scott Hollenbeck.
* 2015-01-16: Version 0.1.6
* Fix: linking against libev on FreeBSD

View File

@ -736,6 +736,8 @@ getdns_context_create_with_extended_memory_functions(
result->my_mf.mf.ext.free = free;
result->update_callback = NULL;
result->update_callback2 = NULL;
result->update_userarg = NULL;
result->mf.mf_arg = userarg;
result->mf.mf.ext.malloc = malloc;
@ -899,10 +901,19 @@ getdns_context_set_context_update_callback(struct getdns_context *context,
return GETDNS_RETURN_GOOD;
} /* getdns_context_set_context_update_callback */
getdns_return_t
getdns_context_set_update_callback(getdns_context *context, void *userarg,
void (*value) (getdns_context *, getdns_context_code_t, void *))
{
if (!context) return GETDNS_RETURN_INVALID_PARAMETER;
context->update_userarg = userarg;
context->update_callback2 = value;
return GETDNS_RETURN_GOOD;
}
/*
* Helpers to set options on the unbound ctx
*/
static void
set_ub_string_opt(struct getdns_context *ctx, char *opt, char *value)
{
@ -1003,6 +1014,10 @@ rebuild_ub_ctx(struct getdns_context* context) {
static void
dispatch_updated(struct getdns_context *context, uint16_t item)
{
if (context->update_callback2)
context->update_callback2(
context, item, context->update_userarg);
if (context->update_callback) {
context->update_callback(context, item);
}

View File

@ -60,6 +60,9 @@ enum filechgs { GETDNS_FCHG_ERRORS = -1
typedef void (*getdns_update_callback) (struct getdns_context *,
getdns_context_code_t);
typedef void (*getdns_update_callback2) (struct getdns_context *,
getdns_context_code_t, void *userarg);
/* internal use only for detecting changes to system files */
struct filechg {
char *fn;
@ -132,6 +135,8 @@ struct getdns_context {
int edns_maximum_udp_payload_size; /* -1 is unset */
getdns_update_callback update_callback;
getdns_update_callback2 update_callback2;
void *update_userarg;
int processing;
int destroying;

View File

@ -187,6 +187,7 @@ getdns_context_get_edns_version(getdns_context *context, uint8_t* value);
getdns_return_t
getdns_context_get_edns_do_bit(getdns_context *context, uint8_t* value);
int
getdns_pretty_snprint_dict(char *str, size_t size, const getdns_dict *dict);
@ -210,6 +211,9 @@ int
getdns_snprint_json_list(
char *str, size_t size, const getdns_list *list, int pretty);
getdns_return_t
getdns_context_set_update_callback(getdns_context *context, void *userarg,
void (*value) (getdns_context *, getdns_context_code_t, void *));
#ifdef __cplusplus
}