Commit 6977e02b authored by Jan Včelák's avatar Jan Včelák 🚀

process answer: remove callbacks from api

ref #209
parent 8d008539
......@@ -25,16 +25,6 @@ static int noop(knot_pkt_t *pkt, knot_process_t *ctx)
return NS_PROC_NOOP;
}
/*! \brief Module implementation. */
const knot_process_module_t _process_answer = {
&process_answer_begin,
&process_answer_reset,
&process_answer_finish,
&process_answer,
&noop, /* No output */
&noop /* No error processing. */
};
/*! \brief Accessor to query-specific data. */
#define ANSWER_DATA(ctx) ((struct answer_data *)(ctx)->data)
......@@ -56,7 +46,7 @@ static bool is_answer_to_query(const knot_pkt_t *query, knot_pkt_t *answer)
knot_dname_is_equal(knot_pkt_qname(query), knot_pkt_qname(answer));
}
int process_answer_begin(knot_process_t *ctx, void *module_param)
static int process_answer_begin(knot_process_t *ctx, void *module_param)
{
/* Initialize context. */
assert(ctx);
......@@ -70,7 +60,7 @@ int process_answer_begin(knot_process_t *ctx, void *module_param)
return NS_PROC_MORE;
}
int process_answer_reset(knot_process_t *ctx)
static int process_answer_reset(knot_process_t *ctx)
{
assert(ctx);
......@@ -81,7 +71,7 @@ int process_answer_reset(knot_process_t *ctx)
return NS_PROC_MORE;
}
int process_answer_finish(knot_process_t *ctx)
static int process_answer_finish(knot_process_t *ctx)
{
process_answer_reset(ctx);
mm_free(&ctx->mm, ctx->data);
......@@ -97,7 +87,7 @@ int process_answer_finish(knot_process_t *ctx)
return ret; \
}
int process_answer(knot_pkt_t *pkt, knot_process_t *ctx)
static int process_answer(knot_pkt_t *pkt, knot_process_t *ctx)
{
assert(pkt && ctx);
struct answer_data *data = ANSWER_DATA(ctx);
......@@ -139,4 +129,19 @@ int process_answer(knot_pkt_t *pkt, knot_process_t *ctx)
return next_state;
}
#undef ANSWER_REQUIRES
\ No newline at end of file
#undef ANSWER_REQUIRES
/*! \brief Module implementation. */
static const knot_process_module_t PROCESS_ANSWER_MODULE = {
&process_answer_begin,
&process_answer_reset,
&process_answer_finish,
&process_answer,
&noop, /* No output. */
&noop /* No error processing. */
};
const knot_process_module_t *process_answer_get_module(void)
{
return &PROCESS_ANSWER_MODULE;
}
......@@ -19,8 +19,8 @@
#include "knot/nameserver/process_query.h"
/* Query processing module implementation. */
extern const knot_process_module_t _process_answer;
#define NS_PROC_ANSWER (&_process_answer)
const knot_process_module_t *process_answer_get_module(void);
#define NS_PROC_ANSWER process_answer_get_module()
#define NS_PROC_ANSWER_ID 2
/*! \brief Answer processsing logging base. */
......@@ -30,7 +30,6 @@ extern const knot_process_module_t _process_answer;
what " of '%s' from '%s': ", msg); \
} while(0)
/* Module load parameters. */
struct process_answer_param {
zone_t *zone;
......@@ -49,40 +48,3 @@ struct answer_data
struct process_answer_param *param; /*!< Module parameters. */
mm_ctx_t *mm; /*!< Memory context. */
};
/*!
* \brief Initialize answer processing context.
*
* \param ctx
* \param module_param
* \return MORE (awaits answer)
*/
int process_answer_begin(knot_process_t *ctx, void *module_param);
/*!
* \brief Reset answer processing context.
*
* \param ctx
* \return MORE (awaits next answer)
*/
int process_answer_reset(knot_process_t *ctx);
/*!
* \brief Finish and close current answer processing.
*
* \param ctx
* \return NOOP (context will be inoperable further on)
*/
int process_answer_finish(knot_process_t *ctx);
/*!
* \brief Process single answer packet.
*
* \param pkt
* \param ctx
* \retval NOOP (unsupported answer)
* \return MORE (awaits next answer)
* \retval DONE (processing finished)
* \retval FAIL (processing failed)
*/
int process_answer(knot_pkt_t *pkt, knot_process_t *ctx);
......@@ -211,7 +211,7 @@ static int exec_request(struct request *last, struct timeval *timeout)
}
/* Receive and process expected answers. */
while(last->state == NS_PROC_MORE) {
while (last->state == NS_PROC_MORE) {
int rcvd = request_recv(last, timeout);
if (rcvd <= 0) {
return rcvd;
......
......@@ -86,7 +86,6 @@ static int zone_query_execute(zone_t *zone, uint16_t pkt_type, const conf_iface_
case KNOT_QUERY_AXFR: query_type = KNOT_RRTYPE_AXFR; break;
case KNOT_QUERY_IXFR: query_type = KNOT_RRTYPE_IXFR; break;
case KNOT_QUERY_NOTIFY: opcode = KNOT_OPCODE_NOTIFY; break;
case KNOT_QUERY_UPDATE: opcode = KNOT_OPCODE_UPDATE; break;
}
/* Create a memory pool for this task. */
......@@ -94,7 +93,7 @@ static int zone_query_execute(zone_t *zone, uint16_t pkt_type, const conf_iface_
mm_ctx_t mm;
mm_ctx_mempool(&mm, 4096);
/* Create a zone transfer request. */
/* Create a query message. */
knot_pkt_t *query = zone_query(zone, query_type, &mm);
if (query == NULL) {
return KNOT_ENOMEM;
......@@ -115,6 +114,10 @@ static int zone_query_execute(zone_t *zone, uint16_t pkt_type, const conf_iface_
/* Create a request. */
struct request *req = requestor_make(&re, &remote->via, &remote->addr, query);
if (req == NULL) {
return KNOT_ENOMEM;
}
struct process_answer_param param;
param.zone = zone;
param.query = query;
......
......@@ -93,7 +93,7 @@ int knot_process_out(uint8_t *wire, uint16_t *wire_len, knot_process_t *ctx)
{
knot_pkt_t *pkt = knot_pkt_new(wire, *wire_len, &ctx->mm);
switch(ctx->state) {
switch (ctx->state) {
case NS_PROC_FULL: ctx->state = ctx->module->out(pkt, ctx); break;
case NS_PROC_FAIL: ctx->state = ctx->module->err(pkt, ctx); break;
default:
......
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