Commit 6c684140 authored by Marek Vavruša's avatar Marek Vavruša

lib/utils: added convenience API for calling module props

parent 5515e446
......@@ -30,6 +30,7 @@
#include "lib/utils.h"
#include "lib/generic/array.h"
#include "lib/nsrep.h"
#include "lib/module.h"
/* Logging & debugging */
bool _env_debug = false;
......@@ -306,3 +307,31 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *p
/* Merge rdataset */
return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool);
}
static char *callprop(struct kr_module *module, const char *prop, const char *input, void *env)
{
if (!module || !prop) {
return NULL;
}
for (struct kr_prop *p = module->props; p && p->name; ++p) {
if (p->cb != NULL && strcmp(p->name, prop) == 0) {
return p->cb(env, module, input);
}
}
return NULL;
}
char *kr_module_call(struct kr_context *ctx, const char *module, const char *prop, const char *input)
{
if (!ctx || !ctx->modules || !module || !prop) {
return NULL;
}
module_array_t *mod_list = ctx->modules;
for (size_t i = 0; i < mod_list->len; ++i) {
struct kr_module *mod = mod_list->at[i];
if (strcmp(mod->name, module) == 0) {
return callprop(mod, prop, input, ctx);
}
}
return NULL;
}
\ No newline at end of file
......@@ -21,6 +21,7 @@
#include <netinet/in.h>
#include <libknot/packet/pkt.h>
#include "lib/generic/map.h"
#include "lib/resolve.h"
/*
* General-purpose attributes.
......@@ -121,4 +122,9 @@ int kr_bitcmp(const char *a, const char *b, int bits);
* @note RRSIG RRSets are merged according the type covered fields.
* @return 0 or an error
*/
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool);
\ No newline at end of file
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool);
/**
* Call module property.
*/
char *kr_module_call(struct kr_context *ctx, const char *module, const char *prop, const char *input);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment