]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Simplify dealing with indentations
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 2 Apr 2024 15:51:21 +0000 (10:51 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 2 Apr 2024 15:51:21 +0000 (10:51 -0500)
13 files changed:
src/lib/io/worker.c
src/lib/server/log.c
src/lib/server/log.h
src/lib/server/request.c
src/lib/server/request.h
src/lib/unlang/edit.c
src/lib/unlang/foreach.c
src/lib/unlang/interpret.c
src/lib/unlang/interpret_synchronous.c
src/lib/unlang/io.c
src/lib/unlang/module.c
src/lib/unlang/timeout.c
src/lib/unlang/xlat.c

index 2af781c8444d0eb6e9d60b45d29847af9a6ec449..3b3d974aad70419f1679ce2598ae633ae7162179 100644 (file)
@@ -1108,8 +1108,8 @@ static void _worker_request_done_external(request_t *request, UNUSED rlm_rcode_t
         *      @todo - check that the stack is at frame 0, otherwise
         *      more things have gone wrong.
         */
-       fr_assert_msg(request_is_internal(request) || request_is_detached(request) || (request->log.unlang_indent == 0),
-                     "Request %s bad log indentation - expected 0 got %u", request->name, request->log.unlang_indent);
+       fr_assert_msg(request_is_internal(request) || request_is_detached(request) || (request->log.indent.unlang == 0),
+                     "Request %s bad log indentation - expected 0 got %u", request->name, request->log.indent.unlang);
        fr_assert_msg(!unlang_interpret_is_resumable(request),
                      "Request %s is marked as yielded at end of processing", request->name);
        fr_assert_msg(unlang_interpret_stack_depth(request) == 0,
index b5ecdc530fcde3ff55f1040cebc27d4df3f96c5c..d10ce5239b6298a2442e4a23b3ddf7d8ab0141af 100644 (file)
@@ -432,13 +432,13 @@ print_fmt:
        /*
         *      Make sure the indent isn't set to something crazy
         */
-       unlang_indent = request->log.unlang_indent > sizeof(spaces) - 1 ?
+       unlang_indent = request->log.indent.unlang > sizeof(spaces) - 1 ?
                        sizeof(spaces) - 1 :
-                       request->log.unlang_indent;
+                       request->log.indent.unlang;
 
-       module_indent = request->log.module_indent > sizeof(spaces) - 1 ?
+       module_indent = request->log.indent.module > sizeof(spaces) - 1 ?
                        sizeof(spaces) - 1 :
-                       request->log.module_indent;
+                       request->log.indent.module;
 
        /*
         *      Module name and indentation i.e.
@@ -880,8 +880,7 @@ void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request
                        ssize_t marker_idx, char const *marker_fmt, ...)
 {
        char const              *ellipses = "";
-       uint8_t                 unlang_indent;
-       uint8_t                 module_indent;
+       rindent_t               indent;
        va_list                 ap;
        char                    *error;
        static char const       marker_spaces[] = "                                                            "; /* 60 */
@@ -902,10 +901,9 @@ void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request
        /*
         *  Don't want format markers being indented
         */
-       unlang_indent = request->log.unlang_indent;
-       module_indent = request->log.module_indent;
-       request->log.unlang_indent = 0;
-       request->log.module_indent = 0;
+       indent = request->log.indent;
+       request->log.indent.module = 0;
+       request->log.indent.unlang = 0;
 
        va_start(ap, marker_fmt);
        error = fr_vasprintf(request, marker_fmt, ap);
@@ -915,8 +913,7 @@ void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request
        log_request(type, lvl, request, file, line, "%s%.*s^ %s", ellipses, (int) marker_idx, marker_spaces, error);
        talloc_free(error);
 
-       request->log.unlang_indent = unlang_indent;
-       request->log.module_indent = module_indent;
+       request->log.indent = indent;
 }
 
 void log_request_hex(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request,
index 50a87d3bdfddc1627a03443f2d27f501c0ff2d52..f39be8007fba9f919edfb6e060c60cbd8acd0773 100644 (file)
@@ -37,6 +37,11 @@ extern "C" {
  *
  */
 typedef struct log_dst log_dst_t;
+typedef struct rindent_s {
+       uint8_t                 unlang;         //!< By how much to indent log messages. uin8_t so it's obvious
+                                               //!< when a request has been exdented too much.
+       uint8_t                 module;         //!< Indentation after the module prefix name.
+} rindent_t;
 
 #include <freeradius-devel/server/request.h>
 #include <freeradius-devel/util/log.h>
@@ -374,12 +379,6 @@ void       log_global_free(void);
 #define RPEDEBUG4(fmt, ...)    log_request_perror(L_DBG_ERR, L_DBG_LVL_MAX, request, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
 /** @} */
 
-typedef struct {
-       uint8_t                 unlang_indent;  //!< By how much to indent log messages. uin8_t so it's obvious
-                                               //!< when a request has been exdented too much.
-       uint8_t                 module_indent;  //!< Indentation after the module prefix name.
-} rindent_t;
-
 /** Save indentation for later restoral.
  *
  *  This call avoids the need to manually REXDENT on error paths.  We
@@ -387,13 +386,11 @@ typedef struct {
  *
  */
 #define RINDENT_SAVE(_x, _request) do { \
-               (_x)->unlang_indent = request->log.unlang_indent; \
-               (_x)->module_indent = request->log.module_indent; \
+               (_x)->indent = request->log.indent; \
        } while (0)
 
 #define RINDENT_RESTORE(_request, _x) do { \
-               request->log.unlang_indent = (_x)->unlang_indent; \
-               request->log.module_indent = (_x)->module_indent; \
+               request->log.indent = (_x)->indent; \
        } while (0)
 
 #ifdef DEBUG_INDENT
@@ -432,9 +429,9 @@ typedef struct {
  */
 #  define RINDENT() do {\
        if (request->module) {\
-               request->log.module_indent += 2;\
+               request->log.indent.unlang += 2;\
        } else {\
-               request->log.unlang_indent += 2;\
+               request->log.indent.unlang += 2;\
        }\
 } while(0)
 
@@ -445,9 +442,9 @@ typedef struct {
  */
 #  define REXDENT() do {\
        if (request->module) {\
-               request->log.module_indent -= 2;\
+               request->log.indent.unlang -= 2;\
        } else {\
-               request->log.unlang_indent -= 2;\
+               request->log.indent.unlang -= 2;\
        }\
 } while(0)
 #endif
index 000d8995437388b82961a2ce7bcb237fe6c1d786..cb23d9e010ee6536af3bde69ed561be15eb8b22a 100644 (file)
@@ -158,8 +158,8 @@ static inline void CC_HINT(always_inline) request_log_init_child(request_t *chil
         *      Copy debug information.
         */
        memcpy(&(child->log), &(parent->log), sizeof(child->log));
-       child->log.unlang_indent = 0;   /* Apart from the indent which we reset */
-       child->log.module_indent = 0;   /* Apart from the indent which we reset */
+       child->log.indent.unlang = 0;   /* Apart from the indent which we reset */
+       child->log.indent.module = 0;   /* Apart from the indent which we reset */
        child->log.lvl = parent->log.lvl;
 }
 
index d2bd500880ac7195f4a77a06ad384a9e929ffa10..b11f56481400256d941ed1f0b9c70c5b260357d3 100644 (file)
@@ -215,9 +215,7 @@ struct request_s {
 
                fr_log_lvl_t            lvl;            //!< Log messages with lvl >= to this should be logged.
 
-               uint8_t                 unlang_indent;  //!< By how much to indent log messages. uin8_t so it's obvious
-                                                       //!< when a request has been exdented too much.
-               uint8_t                 module_indent;  //!< Indentation after the module prefix name.
+               rindent_t               indent;         //!< Indentation for log messages.
        } log;
 
        char const              *component;     //!< Section the request is in.
index 92631beb1ae8091f530546b2773d62d87885b306..d82ad41f0c69b280642e586db5436105185b427f 100644 (file)
@@ -1530,7 +1530,7 @@ static unlang_action_t process_edit(rlm_rcode_t *p_result, request_t *request, u
 
                        rcode = state->current->func(request, state, state->current);
                        if (rcode < 0) {
-                               RINDENT_RESTORE(request, &state->indent);
+                               RINDENT_RESTORE(request, state);
 
                                /*
                                 *      Expansions, etc. failures are SOFT failures, which undo the edit
@@ -1605,7 +1605,7 @@ static void edit_state_init_internal(request_t *request, unlang_frame_state_edit
        /*
         *      Save current indentation for the error path.
         */
-       RINDENT_SAVE(&state->indent, request);
+       RINDENT_SAVE(state, request);
 }
 
 /** Execute an update block
index 59ae416e8a3717cd38bd2c94844e8e60ea138eed..07657d98ee7ae7d73f7337513ee5819d7d71c4b6 100644 (file)
@@ -101,7 +101,7 @@ static unlang_action_t unlang_foreach_next(rlm_rcode_t *p_result, request_t *req
        if (!vp) {
                *p_result = frame->result;
 #ifndef NDEBUG
-               fr_assert(state->indent == request->log.unlang_indent);
+               fr_assert(state->indent == request->log.indent.unlang);
 #endif
                return UNLANG_ACTION_CALCULATE_RESULT;
        }
@@ -199,7 +199,7 @@ static unlang_action_t unlang_foreach(rlm_rcode_t *p_result, request_t *request,
        state->request = request;
        state->depth = depth;
 #ifndef NDEBUG
-       state->indent = request->log.unlang_indent;
+       state->indent = request->log.indent.unlang;
 #endif
 
        /*
index 4a74fbc8d21dd6366c943d4df0aee0f20c0beaab..3873376d28a586241b1b9a6b0824f3e7e97f264c 100644 (file)
@@ -1093,7 +1093,7 @@ void unlang_interpret_request_stop(request_t *request)
 
        intp = stack->intp;
        intp->funcs.stop(request, intp->uctx);
-       request->log.unlang_indent = 0;                 /* nothing unwinds the indentation stack */
+       request->log.indent.unlang = 0;                 /* nothing unwinds the indentation stack */
        request->master_state = REQUEST_STOP_PROCESSING;
 }
 
index 1e05dc8445cd519d4060ff546bcd0fe8d0b0691d..d12359e471a84ab2e309616282dc79df6b212db2 100644 (file)
@@ -62,8 +62,8 @@ static void _request_done_external(request_t *request, UNUSED rlm_rcode_t rcode,
                 *      @todo - check that the stack is at frame 0, otherwise
                 *      more things have gone wrong.
                 */
-               fr_assert_msg(request->parent || (request->log.unlang_indent == 0),
-                             "Request %s bad log indentation - expected 0 got %u", request->name, request->log.unlang_indent);
+               fr_assert_msg(request->parent || (request->log.indent.unlang == 0),
+                             "Request %s bad log indentation - expected 0 got %u", request->name, request->log.indent.unlang);
                fr_assert_msg(!unlang_interpret_is_resumable(request),
                              "Request %s is marked as yielded at end of processing", request->name);
        }
index 7af6079cb67fc6e5e5ec7c0e7c0d08ccdbefb05f..ca1fdd5f672ff4d68a7b2483e53367211a79d1ea 100644 (file)
@@ -56,7 +56,7 @@ request_t *unlang_io_subrequest_alloc(request_t *parent, fr_dict_t const *namesp
        /*
         *      Push the child, and set it's top frame to be true.
         */
-       child->log.unlang_indent = parent->log.unlang_indent;
+       child->log.indent.unlang = parent->log.indent.unlang;
 
        /*
         *      Initialize some basic information for the child.
index 6038a24dcdb8b5cbee7291e2e683553118f7710b..929ecbc1efe3216dcb2d65570e0c360b5e752739 100644 (file)
@@ -661,7 +661,7 @@ static unlang_action_t unlang_module_done(rlm_rcode_t *p_result, request_t *requ
        rlm_rcode_t                     rcode = state-> set_rcode ? state->rcode : *p_result;
 
 #ifndef NDEBUG
-       fr_assert(state->unlang_indent == request->log.unlang_indent);
+       fr_assert(state->unlang_indent == request->log.indent.unlang);
 #endif
 
        fr_assert(rcode >= RLM_MODULE_REJECT);
@@ -885,7 +885,7 @@ static unlang_action_t unlang_module(rlm_rcode_t *p_result, request_t *request,
        state->previous_module = request->module;
 
 #ifndef NDEBUG
-       state->unlang_indent = request->log.unlang_indent;
+       state->unlang_indent = request->log.indent.unlang;
 #endif
        /*
         *      Process a stand-alone child, and fall through
index c5bd1325eeb21f76a4453dbf64e7449798524151..3f41f34ba084959638b41356a8ef12006615e8f5 100644 (file)
@@ -62,7 +62,7 @@ static unlang_action_t unlang_timeout_resume_done(UNUSED rlm_rcode_t *p_result,
        unlang_frame_state_timeout_t    *state = talloc_get_type_abort(frame->state, unlang_frame_state_timeout_t);
 
        if (!state->success) {
-               RINDENT_RESTORE(request, &state->indent);
+               RINDENT_RESTORE(request, state);
 
                RWDEBUG("Timeout exceeded");
                return UNLANG_ACTION_FAIL;
@@ -79,7 +79,7 @@ static unlang_action_t unlang_timeout_set(rlm_rcode_t *p_result, request_t *requ
        /*
         *      Save current indentation for the error path.
         */
-       RINDENT_SAVE(&state->indent, request);
+       RINDENT_SAVE(state, request);
 
        timeout = fr_time_add(fr_time(), state->timeout);
 
index 53fa3d7d4464605ed6f0bc6cada91d01129ba033..365a0d31051755865ca841d1ff373bbc3818bc3f 100644 (file)
@@ -385,7 +385,7 @@ static unlang_action_t unlang_xlat(rlm_rcode_t *p_result, request_t *request, un
        xlat_action_t                   xa;
        xlat_exp_head_t const           *child = NULL;
 
-       RINDENT_SAVE(&state->indent, request);
+       RINDENT_SAVE(state, request);
        RINDENT();
 
        xa = xlat_frame_eval(state->ctx, &state->values, &child, request, state->head, &state->exp);
@@ -403,7 +403,7 @@ static unlang_action_t unlang_xlat(rlm_rcode_t *p_result, request_t *request, un
                fr_value_box_list_talloc_free(&state->out);
                if (unlang_xlat_push(state->ctx, state->success, &state->out, request, child, false) < 0) {
                        *p_result = RLM_MODULE_FAIL;
-                       RINDENT_RESTORE(request, &state->indent);
+                       RINDENT_RESTORE(request, state);
                        return UNLANG_ACTION_STOP_PROCESSING;
                }
                return UNLANG_ACTION_PUSHED_CHILD;
@@ -423,14 +423,14 @@ static unlang_action_t unlang_xlat(rlm_rcode_t *p_result, request_t *request, un
        case XLAT_ACTION_DONE:
                if (state->success) *state->success = true;
                *p_result = RLM_MODULE_OK;
-               RINDENT_RESTORE(request, &state->indent);
+               RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        case XLAT_ACTION_FAIL:
        fail:
                if (state->success) *state->success = false;
                *p_result = RLM_MODULE_FAIL;
-               RINDENT_RESTORE(request, &state->indent);
+               RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        default:
@@ -501,7 +501,7 @@ static unlang_action_t unlang_xlat_resume(rlm_rcode_t *p_result, request_t *requ
        case XLAT_ACTION_DONE:
                if (state->success) *state->success = true;
                *p_result = RLM_MODULE_OK;
-               RINDENT_RESTORE(request, &state->indent);
+               RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        case XLAT_ACTION_PUSH_UNLANG:
@@ -521,7 +521,7 @@ static unlang_action_t unlang_xlat_resume(rlm_rcode_t *p_result, request_t *requ
                fr_value_box_list_talloc_free(&state->out);
                if (unlang_xlat_push(state->ctx, state->success, &state->out, request, child, false) < 0) {
                        *p_result = RLM_MODULE_FAIL;
-                       RINDENT_RESTORE(request, &state->indent);
+                       RINDENT_RESTORE(request, state);
                        return UNLANG_ACTION_STOP_PROCESSING;
                }
                return UNLANG_ACTION_PUSHED_CHILD;
@@ -529,7 +529,7 @@ static unlang_action_t unlang_xlat_resume(rlm_rcode_t *p_result, request_t *requ
        case XLAT_ACTION_FAIL:
                if (state->success) *state->success = false;
                *p_result = RLM_MODULE_FAIL;
-               RINDENT_RESTORE(request, &state->indent);
+               RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
        /* DON'T SET DEFAULT */
        }
@@ -537,7 +537,7 @@ static unlang_action_t unlang_xlat_resume(rlm_rcode_t *p_result, request_t *requ
        fr_assert(0);           /* Garbage xlat action */
 
        *p_result = RLM_MODULE_FAIL;
-       RINDENT_RESTORE(request, &state->indent);
+       RINDENT_RESTORE(request, state);
        return UNLANG_ACTION_CALCULATE_RESULT;
 }