mirror of https://github.com/getdnsapi/getdns.git
Pass along a userarg with context update callbacks
This commit is contained in:
parent
18381e7753
commit
56bb9dbbdc
|
@ -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
|
||||
|
|
|
@ -735,7 +735,9 @@ getdns_context_create_with_extended_memory_functions(
|
|||
result->my_mf.mf.ext.realloc = realloc;
|
||||
result->my_mf.mf.ext.free = free;
|
||||
|
||||
result->update_callback = NULL;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -131,7 +134,9 @@ struct getdns_context {
|
|||
uint8_t edns_do_bit;
|
||||
int edns_maximum_udp_payload_size; /* -1 is unset */
|
||||
|
||||
getdns_update_callback update_callback;
|
||||
getdns_update_callback update_callback;
|
||||
getdns_update_callback2 update_callback2;
|
||||
void *update_userarg;
|
||||
|
||||
int processing;
|
||||
int destroying;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue