mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
Add "dynlib" prefix to example output, log queries
This adds the "dynlib: " prefix to all messages created by the `helloworld.c` dynamic library example. It also adds logging of queries that pass through `operate`.
This commit is contained in:
parent
d104d3be22
commit
5eabc429bc
1 changed files with 16 additions and 9 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "../../config.h"
|
#include "../../config.h"
|
||||||
#include "../../util/module.h"
|
#include "../../util/module.h"
|
||||||
|
#include "../../sldns/parseutil.h"
|
||||||
#include "../dynlibmod.h"
|
#include "../dynlibmod.h"
|
||||||
|
|
||||||
/* Declare the EXPORT macro that expands to exporting the symbol for DLLs when
|
/* Declare the EXPORT macro that expands to exporting the symbol for DLLs when
|
||||||
|
|
@ -33,7 +34,7 @@ int reply_callback(struct query_info* qinfo,
|
||||||
/* Init is called when the module is first loaded. It should be used to set up
|
/* Init is called when the module is first loaded. It should be used to set up
|
||||||
* the environment for this module and do any other initialisation required. */
|
* the environment for this module and do any other initialisation required. */
|
||||||
EXPORT void init(struct module_env* env, int id) {
|
EXPORT void init(struct module_env* env, int id) {
|
||||||
log_info("Hello world from init");
|
log_info("dynlib: hello world from init");
|
||||||
struct dynlibmod_env* de = (struct dynlibmod_env*) env->modinfo[id];
|
struct dynlibmod_env* de = (struct dynlibmod_env*) env->modinfo[id];
|
||||||
de->inplace_cb_register_wrapped(&reply_callback,
|
de->inplace_cb_register_wrapped(&reply_callback,
|
||||||
inplace_cb_reply,
|
inplace_cb_reply,
|
||||||
|
|
@ -45,7 +46,7 @@ EXPORT void init(struct module_env* env, int id) {
|
||||||
/* Deinit is run as the program is shutting down. It should be used to clean up
|
/* Deinit is run as the program is shutting down. It should be used to clean up
|
||||||
* the environment and any left over data. */
|
* the environment and any left over data. */
|
||||||
EXPORT void deinit(struct module_env* env, int id) {
|
EXPORT void deinit(struct module_env* env, int id) {
|
||||||
log_info("Hello world from deinit");
|
log_info("dynlib: hello world from deinit");
|
||||||
struct dynlibmod_env* de = (struct dynlibmod_env*) env->modinfo[id];
|
struct dynlibmod_env* de = (struct dynlibmod_env*) env->modinfo[id];
|
||||||
de->inplace_cb_delete_wrapped(env, inplace_cb_reply, id);
|
de->inplace_cb_delete_wrapped(env, inplace_cb_reply, id);
|
||||||
if (de->dyn_env != NULL) free(de->dyn_env);
|
if (de->dyn_env != NULL) free(de->dyn_env);
|
||||||
|
|
@ -55,7 +56,13 @@ EXPORT void deinit(struct module_env* env, int id) {
|
||||||
* used to determine which direction in the module chain it came from. */
|
* used to determine which direction in the module chain it came from. */
|
||||||
EXPORT void operate(struct module_qstate* qstate, enum module_ev event,
|
EXPORT void operate(struct module_qstate* qstate, enum module_ev event,
|
||||||
int id, struct outbound_entry* entry) {
|
int id, struct outbound_entry* entry) {
|
||||||
log_info("Hello world from operate");
|
log_info("dynlib: hello world from operate");
|
||||||
|
log_info("dynlib: incoming query: %s %s(%d) %s(%d)",
|
||||||
|
qstate->qinfo.qname,
|
||||||
|
sldns_lookup_by_id(sldns_rr_classes, qstate->qinfo.qclass)->name,
|
||||||
|
qstate->qinfo.qclass,
|
||||||
|
sldns_rr_descript(qstate->qinfo.qtype)->_name,
|
||||||
|
qstate->qinfo.qtype);
|
||||||
if (event == module_event_new || event == module_event_pass) {
|
if (event == module_event_new || event == module_event_pass) {
|
||||||
qstate->ext_state[id] = module_wait_module;
|
qstate->ext_state[id] = module_wait_module;
|
||||||
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
||||||
|
|
@ -65,7 +72,7 @@ EXPORT void operate(struct module_qstate* qstate, enum module_ev event,
|
||||||
((int *)env->dyn_env)[1] = 102;
|
((int *)env->dyn_env)[1] = 102;
|
||||||
((int *)env->dyn_env)[2] = 192;
|
((int *)env->dyn_env)[2] = 192;
|
||||||
} else {
|
} else {
|
||||||
log_err("Already has data!");
|
log_err("dynlib: already has data!");
|
||||||
qstate->ext_state[id] = module_error;
|
qstate->ext_state[id] = module_error;
|
||||||
}
|
}
|
||||||
} else if (event == module_event_moddone) {
|
} else if (event == module_event_moddone) {
|
||||||
|
|
@ -80,13 +87,13 @@ EXPORT void operate(struct module_qstate* qstate, enum module_ev event,
|
||||||
* mesh_attach_sub in services/mesh.h to see how this is done. */
|
* mesh_attach_sub in services/mesh.h to see how this is done. */
|
||||||
EXPORT void inform_super(struct module_qstate* qstate, int id,
|
EXPORT void inform_super(struct module_qstate* qstate, int id,
|
||||||
struct module_qstate* super) {
|
struct module_qstate* super) {
|
||||||
log_info("Hello world from inform_super");
|
log_info("dynlib: hello world from inform_super");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear is called once a query is complete and the response has been sent
|
/* Clear is called once a query is complete and the response has been sent
|
||||||
* back. It is used to clear up any per-query allocations. */
|
* back. It is used to clear up any per-query allocations. */
|
||||||
EXPORT void clear(struct module_qstate* qstate, int id) {
|
EXPORT void clear(struct module_qstate* qstate, int id) {
|
||||||
log_info("Hello world from clear");
|
log_info("dynlib: hello world from clear");
|
||||||
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
||||||
if (env->dyn_env != NULL) {
|
if (env->dyn_env != NULL) {
|
||||||
free(env->dyn_env);
|
free(env->dyn_env);
|
||||||
|
|
@ -97,7 +104,7 @@ EXPORT void clear(struct module_qstate* qstate, int id) {
|
||||||
/* Get mem is called when Unbound is printing performance information. This
|
/* Get mem is called when Unbound is printing performance information. This
|
||||||
* only happens explicitly and is only used to show memory usage to the user. */
|
* only happens explicitly and is only used to show memory usage to the user. */
|
||||||
EXPORT size_t get_mem(struct module_env* env, int id) {
|
EXPORT size_t get_mem(struct module_env* env, int id) {
|
||||||
log_info("Hello world from get_mem");
|
log_info("dynlib: hello world from get_mem");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,10 +115,10 @@ int reply_callback(struct query_info* qinfo,
|
||||||
struct edns_data* edns, struct edns_option** opt_list_out,
|
struct edns_data* edns, struct edns_option** opt_list_out,
|
||||||
struct comm_reply* repinfo, struct regional* region, int id,
|
struct comm_reply* repinfo, struct regional* region, int id,
|
||||||
void* callback) {
|
void* callback) {
|
||||||
log_info("Hello world from callback");
|
log_info("dynlib: hello world from callback");
|
||||||
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
struct dynlibmod_env* env = qstate->env->modinfo[id];
|
||||||
if (env->dyn_env != NULL) {
|
if (env->dyn_env != NULL) {
|
||||||
log_info("Numbers gotten from query: %d, %d, and %d",
|
log_info("dynlib: numbers gotten from query: %d, %d, and %d",
|
||||||
((int *)env->dyn_env)[0],
|
((int *)env->dyn_env)[0],
|
||||||
((int *)env->dyn_env)[1],
|
((int *)env->dyn_env)[1],
|
||||||
((int *)env->dyn_env)[2]);
|
((int *)env->dyn_env)[2]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue