]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add unlang function signal set
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 24 Jun 2021 18:05:13 +0000 (13:05 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 24 Jun 2021 18:05:13 +0000 (13:05 -0500)
src/lib/unlang/function.c
src/lib/unlang/function.h

index b7527f4d871151ff91f3f5e1bc64c9dd1972de63..73c87f168a3c832773a5325e22fb5f36f4222f15 100644 (file)
@@ -173,7 +173,46 @@ int unlang_function_clear(request_t *request)
        return 0;
 }
 
+/** Set a new signal function for an existing function frame
+ *
+ * @private
+ *
+ * The function frame being modified must be at the top of the stack.
+ *
+ * @param[in] request          The current request.
+ * @param[in] signal           The signal function to set.
+ * @param[in] signal_name      Name of the signal function call (for debugging).
+ * @return
+ *     - 0 on success.
+ *      - -1 on failure.
+ */
+int _unlang_function_signal_set(request_t *request, unlang_function_signal_t signal, char const *signal_name)
+{
+       unlang_stack_t                  *stack = request->stack;
+       unlang_stack_frame_t            *frame = &stack->frame[stack->depth];
+       unlang_frame_state_func_t       *state;
+
+       if (frame->instruction->type != UNLANG_TYPE_FUNCTION) {
+               RERROR("Can't set repeat function on non-function frame");
+               return -1;
+       }
+
+       state = talloc_get_type_abort(frame->state, unlang_frame_state_func_t);
+
+       /*
+        *      If we're inside unlang_function_call,
+        *      it'll pickup state->repeat and do the right thing
+        *      once the current function returns.
+        */
+       state->signal = signal;
+       state->signal_name = signal_name;
+
+       return 0;
+}
+
 /** Set a new repeat function for an existing function frame
+ *
+ * @private
  *
  * The function frame being modified must be at the top of the stack.
  *
@@ -184,7 +223,7 @@ int unlang_function_clear(request_t *request)
  *     - 0 on success.
  *      - -1 on failure.
  */
-int _unlang_function_repeat(request_t *request, unlang_function_t repeat, char const *repeat_name)
+int _unlang_function_repeat_set(request_t *request, unlang_function_t repeat, char const *repeat_name)
 {
        unlang_stack_t                  *stack = request->stack;
        unlang_stack_frame_t            *frame = &stack->frame[stack->depth];
@@ -210,6 +249,8 @@ int _unlang_function_repeat(request_t *request, unlang_function_t repeat, char c
 }
 
 /** Push a generic function onto the unlang stack
+ *
+ * @private
  *
  * These can be pushed by any other type of unlang op to allow a submodule or function
  * deeper in the C call stack to establish a new resumption point.
index 8a9113385fa758e98ece1a25521a032449b35a66..e5ff555e6aef4ff2e283ea87e00637b000e7909d 100644 (file)
@@ -58,7 +58,21 @@ typedef void (*unlang_function_signal_t)(request_t *request, fr_state_signal_t a
 
 int            unlang_function_clear(request_t *request) CC_HINT(warn_unused_result);
 
-int            _unlang_function_repeat(request_t *request, unlang_function_t repeat, char const *name) CC_HINT(warn_unused_result);
+/** Set a new signal function for an existing function frame
+ *
+ * The function frame being modified must be at the top of the stack.
+ *
+ * @param[in] request          The current request.
+ * @param[in] signal           The signal function to set.
+ * @param[in] signal_name      Name of the signal function call (for debugging).
+ * @return
+ *     - 0 on success.
+ *      - -1 on failure.
+ */
+#define                unlang_function_signal_set(_request, _signal) \
+               _unlang_function_signal_set(_request, _signal, STRINGIFY(_signal))
+int            _unlang_function_signal_set(request_t *request, unlang_function_signal_t signal, char const *name)
+               CC_HINT(warn_unused_result);
 
 /** Set a new repeat function for an existing function frame
  *
@@ -70,15 +84,10 @@ int         _unlang_function_repeat(request_t *request, unlang_function_t repeat, char
  *     - 0 on success.
  *      - -1 on failure.
  */
-#define                unlang_function_repeat(_request, _repeat) \
-               _unlang_function_repeat(_request, _repeat, STRINGIFY(_repeat))
-
-unlang_action_t        _unlang_function_push(request_t *request,
-                                     unlang_function_t func, char const *func_name,
-                                     unlang_function_t repeat, char const *repeat_name,
-                                     unlang_function_signal_t signal, char const *signal_name,
-                                     bool top_frame, void *uctx)
-                                     CC_HINT(warn_unused_result);
+#define                unlang_function_repeat_set(_request, _repeat) \
+               _unlang_function_repeat_set(_request, _repeat, STRINGIFY(_repeat))
+int            _unlang_function_repeat_set(request_t *request, unlang_function_t repeat, char const *name)
+               CC_HINT(warn_unused_result);
 
 /** Push a generic function onto the unlang stack
  *
@@ -101,6 +110,12 @@ unlang_action_t    _unlang_function_push(request_t *request,
                                      _repeat, STRINGIFY(_repeat), \
                                      _signal, STRINGIFY(_signal), \
                                      _top_frame, _uctx)
+unlang_action_t        _unlang_function_push(request_t *request,
+                                     unlang_function_t func, char const *func_name,
+                                     unlang_function_t repeat, char const *repeat_name,
+                                     unlang_function_signal_t signal, char const *signal_name,
+                                     bool top_frame, void *uctx)
+                                     CC_HINT(warn_unused_result);
 
 #ifdef __cplusplus
 }