diff --git a/ChangeLog b/ChangeLog index ec108fa9..f9d9fb7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,8 @@ Thanks Scott Hollenbeck. * Demotivate use of getdns_strerror and expose getdns_get_errorstr_by_id. Thanks Scott Hollenbeck. + * A getter for context update callback, to allow for chaining update + callbacks. * 2015-01-16: Version 0.1.6 * Fix: linking against libev on FreeBSD diff --git a/src/context.c b/src/context.c index e3954a29..b3c26c48 100644 --- a/src/context.c +++ b/src/context.c @@ -697,6 +697,11 @@ transaction_id_cmp(const void *id1, const void *id2) } } +static void +NULL_update_callback( + getdns_context *context, getdns_context_code_t code, void *userarg) +{ (void)context; (void)code; (void)userarg; } + /* * getdns_context_create * @@ -736,7 +741,7 @@ getdns_context_create_with_extended_memory_functions( result->my_mf.mf.ext.free = free; result->update_callback = NULL; - result->update_callback2 = NULL; + result->update_callback2 = NULL_update_callback; result->update_userarg = NULL; result->mf.mf_arg = userarg; @@ -903,11 +908,23 @@ getdns_context_set_context_update_callback(struct getdns_context *context, getdns_return_t getdns_context_set_update_callback(getdns_context *context, void *userarg, - void (*value) (getdns_context *, getdns_context_code_t, void *)) + void (*cb)(getdns_context *, getdns_context_code_t, void *)) { if (!context) return GETDNS_RETURN_INVALID_PARAMETER; context->update_userarg = userarg; - context->update_callback2 = value; + context->update_callback2 = cb ? cb : NULL_update_callback; + return GETDNS_RETURN_GOOD; +} + +getdns_return_t +getdns_context_get_update_callback(getdns_context *context, void **userarg, + void (**cb)(getdns_context *, getdns_context_code_t, void *)) +{ + if (!context || !userarg || !cb) + return GETDNS_RETURN_INVALID_PARAMETER; + + *userarg = context->update_userarg; + *cb = context->update_callback2; return GETDNS_RETURN_GOOD; } @@ -1014,7 +1031,7 @@ rebuild_ub_ctx(struct getdns_context* context) { static void dispatch_updated(struct getdns_context *context, uint16_t item) { - if (context->update_callback2) + if (context->update_callback2 != NULL_update_callback) context->update_callback2( context, item, context->update_userarg); diff --git a/src/getdns/getdns_extra.h b/src/getdns/getdns_extra.h index b7dec5aa..a3610bab 100644 --- a/src/getdns/getdns_extra.h +++ b/src/getdns/getdns_extra.h @@ -215,6 +215,11 @@ getdns_return_t getdns_context_set_update_callback(getdns_context *context, void *userarg, void (*value) (getdns_context *, getdns_context_code_t, void *)); +getdns_return_t +getdns_context_get_update_callback(getdns_context *context, void **userarg, + void (**value) (getdns_context *, getdns_context_code_t, void *)); + + const char *getdns_get_errorstr_by_id(uint16_t err); /* WARNING! Function getdns_strerror is not in the API specification and diff --git a/src/libgetdns.symbols b/src/libgetdns.symbols index e75fe44d..7bb6b1c4 100644 --- a/src/libgetdns.symbols +++ b/src/libgetdns.symbols @@ -120,6 +120,7 @@ getdns_snprint_json_dict getdns_print_json_list getdns_snprint_json_list getdns_context_set_update_callback +getdns_context_get_update_callback getdns_get_errorstr_by_id getdns_strerror plain_mem_funcs_user_arg