From: Arran Cudbard-Bell Date: Sat, 11 Nov 2017 15:54:26 +0000 (+0000) Subject: Add an UNLANG_ACTION_YIELD action X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55f3e445e210a0df9b3b8e07e712ea44453785c1;p=thirdparty%2Ffreeradius-server.git Add an UNLANG_ACTION_YIELD action It's more explicit than just using the rcode --- diff --git a/src/include/interpreter.h b/src/include/interpreter.h index e2081f9967c..fb3e75c5642 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -87,6 +87,7 @@ typedef enum { UNLANG_ACTION_PUSHED_CHILD, //!< #unlang_t pushed a new child onto the stack, //!< execute it instead of continuing. UNLANG_ACTION_BREAK, //!< Break out of the current group. + UNLANG_ACTION_YIELD, //!< Temporarily pause execution until an event occurs. UNLANG_ACTION_STOP_PROCESSING //!< Break out of processing the current request (unwind). } unlang_action_t; diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index fa545833ae2..4fcf56b3104 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -35,6 +35,7 @@ static FR_NAME_NUMBER unlang_action_table[] = { { "continue", UNLANG_ACTION_CONTINUE }, { "pushed-child", UNLANG_ACTION_PUSHED_CHILD }, { "break", UNLANG_ACTION_BREAK }, + { "yield", UNLANG_ACTION_YIELD }, { "stop", UNLANG_ACTION_STOP_PROCESSING }, { NULL, -1 } }; @@ -803,7 +804,7 @@ static unlang_action_t unlang_detach(REQUEST *request, rad_assert(request->backlog != NULL); *presult = RLM_MODULE_YIELD; - return UNLANG_ACTION_CALCULATE_RESULT; + return UNLANG_ACTION_YIELD; } static unlang_action_t unlang_call(REQUEST *request, @@ -985,7 +986,7 @@ static unlang_action_t unlang_subrequest(REQUEST *request, } *presult = RLM_MODULE_YIELD; - return UNLANG_ACTION_CALCULATE_RESULT; + return UNLANG_ACTION_YIELD; } /** Parallel children have states @@ -1349,7 +1350,7 @@ static unlang_action_t unlang_parallel(REQUEST *request, } *presult = RLM_MODULE_YIELD; - return UNLANG_ACTION_CALCULATE_RESULT; + return UNLANG_ACTION_YIELD; } static unlang_action_t unlang_case(REQUEST *request, @@ -1724,7 +1725,7 @@ static unlang_action_t unlang_map(REQUEST *request, *presult = map_proc(request, g->proc_inst); - return UNLANG_ACTION_CALCULATE_RESULT; + return *presult == RLM_MODULE_YIELD ? UNLANG_ACTION_YIELD : UNLANG_ACTION_CALCULATE_RESULT; } @@ -1806,7 +1807,7 @@ done: RDEBUG2("%s (%s)", instruction->name ? instruction->name : "", fr_int2str(mod_rcode_table, *presult, "")); - return UNLANG_ACTION_CALCULATE_RESULT; + return *presult == RLM_MODULE_YIELD ? UNLANG_ACTION_YIELD : UNLANG_ACTION_CALCULATE_RESULT; } @@ -1932,7 +1933,7 @@ static unlang_action_t unlang_resume(REQUEST *request, *priority = instruction->actions[*presult]; } - return UNLANG_ACTION_CALCULATE_RESULT; + return *presult == RLM_MODULE_YIELD ? UNLANG_ACTION_YIELD : UNLANG_ACTION_CALCULATE_RESULT; } /* @@ -2239,31 +2240,44 @@ static inline unlang_frame_action_t unlang_frame_eval(REQUEST *request, unlang_s frame->next = NULL; return UNLANG_FRAME_ACTION_POP; - case UNLANG_ACTION_CALCULATE_RESULT: - if (*result == RLM_MODULE_YIELD) { - /* - * Detach is magic. The parent - * "create" function takes care - * of bumping the instruction - * pointer... - */ - if (frame->instruction->type == UNLANG_TYPE_DETACH) { - RDEBUG4("** [%i] %s - detaching child with current (%s %d)", - stack->depth, __FUNCTION__, - fr_int2str(mod_rcode_table, frame->result, ""), - frame->priority); - DUMP_STACK; - *result = RLM_MODULE_YIELD; - } + case UNLANG_ACTION_YIELD: + yield: + *result = RLM_MODULE_YIELD; /* Fixup rcode */ + + /* + * Detach is magic. The parent "create" function + * takes care of bumping the instruction + * pointer... + */ + switch (frame->instruction->type) { + case UNLANG_TYPE_DETACH: + RDEBUG4("** [%i] %s - detaching child with current (%s %d)", + stack->depth, __FUNCTION__, + fr_int2str(mod_rcode_table, frame->result, ""), + frame->priority); + DUMP_STACK; + + return UNLANG_FRAME_ACTION_YIELD; - rad_assert(frame->instruction->type == UNLANG_TYPE_RESUME); + case UNLANG_TYPE_RESUME: frame->repeat = true; RDEBUG4("** [%i] %s - yielding with current (%s %d)", stack->depth, __FUNCTION__, fr_int2str(mod_rcode_table, frame->result, ""), frame->priority); DUMP_STACK; - *result = RLM_MODULE_YIELD; return UNLANG_FRAME_ACTION_YIELD; + + default: + rad_assert(0); + return UNLANG_FRAME_ACTION_YIELD; + } + break; /* Static analysis tools are stupid */ + + case UNLANG_ACTION_CALCULATE_RESULT: + /* Temporary fixup - ops should return the correct code */ + if (frame->result == RLM_MODULE_YIELD) { + action = UNLANG_ACTION_YIELD; + goto yield; } frame->repeat = false;