*/
RCSID("$Id$")
-#include <freeradius-devel/unlang/timeout.h>
#include <freeradius-devel/unlang/interpret.h>
#include <freeradius-devel/server/rcode.h>
#include "group_priv.h"
fr_timer_t *ev;
fr_value_box_list_t result;
-
- unlang_t *instruction; //!< to run on timeout
} unlang_frame_state_timeout_t;
/** Immediately cancel the timeout if the frame is cancelled
state->fired = true;
RINDENT_RESTORE(request, state);
-
- if (!state->instruction) return;
-
- /*
- * Push something else onto the stack to execute.
- */
- if (unlikely(unlang_interpret_push_instruction(NULL, request, state->instruction,
- FRAME_CONF(RLM_MODULE_TIMEOUT, true)) < 0)) {
- unlang_interpret_signal(request, FR_SIGNAL_CANCEL); /* also stops the request and does cleanups */
- }
}
static unlang_action_t unlang_timeout_resume_done(unlang_result_t *p_result, UNUSED request_t *request, unlang_stack_frame_t *frame)
return UNLANG_ACTION_PUSHED_CHILD;
}
-/** When a timeout fires, run the given section.
- *
- * @param[in] request to push timeout onto
- * @param[in] timeout when to run the timeout
- * @param[in] cs section to run when the timeout fires.
- * @param[in] top_frame Set to UNLANG_TOP_FRAME if the interpreter should return.
- * Set to UNLANG_SUB_FRAME if the interprer should continue.
- *
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-int unlang_timeout_section_push(request_t *request, CONF_SECTION *cs, fr_time_delta_t timeout, bool top_frame)
-{
- /** Static instruction for performing xlat evaluations
- *
- */
- static unlang_t timeout_instruction = {
- .type = UNLANG_TYPE_TIMEOUT,
- .name = "timeout",
- .debug_name = "timeout",
- .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN,
- };
-
- unlang_frame_state_timeout_t *state;
- unlang_stack_t *stack = request->stack;
- unlang_stack_frame_t *frame;
- unlang_t *instruction;
-
- /*
- * Get the instruction we are supposed to run on timeout.
- */
- instruction = (unlang_t *)cf_data_value(cf_data_find(cs, unlang_group_t, NULL));
- if (!instruction) {
- REDEBUG("Failed to find pre-compiled unlang for section %s { ... }",
- cf_section_name1(cs));
- return -1;
- }
-
- /*
- * Push a new timeout frame onto the stack
- */
- if (unlang_interpret_push(NULL, request, &timeout_instruction,
- FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) return -1;
- frame = &stack->frame[stack->depth];
-
- /*
- * Allocate its state, and set the timeout.
- */
- MEM(frame->state = state = talloc_zero(stack, unlang_frame_state_timeout_t));
-
- RINDENT_SAVE(state, request);
- state->depth = stack->depth;
- state->request = request;
- state->timeout = timeout;
- state->instruction = instruction;
-
- if (fr_timer_in(state, unlang_interpret_event_list(request)->tl, &state->ev, timeout,
- false, unlang_timeout_handler, state) < 0) {
- RPEDEBUG("Failed setting timeout for section %s", cf_section_name1(cs));
- return -1;
- }
-
- frame_repeat(frame, unlang_timeout_resume_done);
-
- return 0;
-
-}
-
static unlang_t *unlang_compile_timeout(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
{
CONF_SECTION *cs = cf_item_to_section(ci);
+++ /dev/null
-#pragma once
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/**
- * $Id$
- *
- * @file unlang/timeout.h
- * @brief Declarations for unlang timeouts
- *
- * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
- */
-#include <freeradius-devel/server/request.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int unlang_timeout_section_push(request_t *request, CONF_SECTION *cs, fr_time_delta_t timeout, bool top_frame) CC_HINT(nonnull);
-
-#ifdef __cplusplus
-}
-#endif