From: Arran Cudbard-Bell Date: Thu, 17 Dec 2020 23:55:16 +0000 (-0600) Subject: Make log_request_marker more similar to fr_log_marker X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa6046ffcf6590fc8c24cbc32c8b575445bc6d0c;p=thirdparty%2Ffreeradius-server.git Make log_request_marker more similar to fr_log_marker --- diff --git a/src/lib/server/log.c b/src/lib/server/log.c index 8d175b0028e..eb351eadbde 100644 --- a/src/lib/server/log.c +++ b/src/lib/server/log.c @@ -857,33 +857,41 @@ void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, /** Write the string being parsed, and a marker showing where the parse error occurred * - * @param[in] type the log category. - * @param[in] lvl of debugging this message should be logged at. - * @param[in] request The current request. - * @param[in] file src file the log message was generated in. - * @param[in] line number the log message was generated on. - * @param[in] str string we were parsing. - * @param[in] idx The position of the marker relative to the string. - * @param[in] fmt What the parse error was. - * @param[in] ... Arguments for fmt string. + * @param[in] type the log category. + * @param[in] lvl of debugging this message should be logged at. + * @param[in] request The current request. + * @param[in] file src file the log message was generated in. + * @param[in] line number the log message was generated on. + * @param[in] str Subject string we're printing a marker for. + * @param[in] str_len Subject string length. Use SIZE_MAX for the + * length of the string. + * @param[in] marker_idx The position of the marker relative to the string. + * @param[in] marker_fmt What the parse error was. + * @param[in] ... Arguments for fmt string. */ void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, - char const *str, size_t idx, - char const *fmt, ...) + char const *str, size_t str_len, size_t marker_idx, + char const *marker_fmt, ...) { - char const *prefix = ""; - uint8_t unlang_indent; - uint8_t module_indent; - va_list ap; - char *errstr; + char const *ellipses = ""; + uint8_t unlang_indent; + uint8_t module_indent; + va_list ap; + char *error; + static char const marker_spaces[] = " "; /* 60 */ - if (idx >= sizeof(spaces)) { - size_t offset = (idx - (sizeof(spaces) - 1)) + (sizeof(spaces) * 0.75); - idx -= offset; + if (str_len == SIZE_MAX) str_len = strlen(str); + + if (marker_idx < 0) marker_idx = marker_idx * -1; + + if (marker_idx >= sizeof(marker_spaces)) { + size_t offset = (marker_idx - (sizeof(marker_spaces) - 1)) + (sizeof(marker_spaces) * 0.75); + marker_idx -= offset; str += offset; + str_len -= offset; - prefix = "... "; + ellipses = "... "; } /* @@ -894,13 +902,13 @@ void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request request->log.unlang_indent = 0; request->log.module_indent = 0; - log_request(type, lvl, request, file, line, "%s%s", prefix, str); - - va_start(ap, fmt); - errstr = fr_vasprintf(request, fmt, ap); + va_start(ap, marker_fmt); + error = fr_vasprintf(request, marker_fmt, ap); va_end(ap); - log_request(type, lvl, request, file, line, "%s%.*s^ %s", prefix, (int) idx, spaces, errstr); - talloc_free(errstr); + + log_request(type, lvl, request, file, line, "%s%.*s", ellipses, (int)str_len, str); + 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; diff --git a/src/lib/server/log.h b/src/lib/server/log.h index f2c6cc60fa2..8538bbffb4b 100644 --- a/src/lib/server/log.h +++ b/src/lib/server/log.h @@ -113,8 +113,8 @@ void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, - char const *str, size_t idx, - char const *fmt, ...) CC_HINT(format (printf, 8, 9)) CC_HINT(nonnull); + char const *str, size_t str_len, + size_t marker_idx, char const *marker, ...) CC_HINT(format (printf, 9, 10)) CC_HINT(nonnull); void log_request_hex(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, @@ -144,7 +144,7 @@ void log_global_free(void); * @param[in] _str_len length of subject string. May be SIZE_MAX * to print the entire string. * @param[in] _marker_idx Where to place the marker. May be negative. - * @param[in] _marker text to print at marker_idx. + * @param[in] _marker text to print at marker_marker_idx. * @param[in] _line_prefix_fmt Prefix to add to all log lines. * @param[in] ... Arguments for _line_prefix_fmt. */ @@ -416,22 +416,22 @@ void log_global_free(void); * * @warning If a request_t * is **NOT** available, or is NULL, this macro must **NOT** be used. * - * @param[in] _type log category, a #fr_log_type_t value. - * @param[in] _lvl log priority, a #fr_log_lvl_t value. - * @param[in] _str to mark e.g. "my pet kitty". - * @param[in] _idx index e.g. 3 (starts from 0). - * @param[in] _fmt error message e.g. "kitties are not pets, are nature devouring hell beasts". - * @param[in] ... arguments for error string. + * @param[in] _type log category, a #fr_log_type_t value. + * @param[in] _lvl log priority, a #fr_log_lvl_t value. + * @param[in] _str to mark e.g. "my pet kitty". + * @param[in] _marker_idx index e.g. 3 (starts from 0). + * @param[in] _marker error message e.g. "kitties are not pets, are nature devouring hell beasts". + * @param[in] ... arguments for error string. */ #ifndef DEBUG_INDENT -#define RMARKER(_type, _lvl, _str, _idx, _fmt, ...) \ +#define RMARKER(_type, _lvl, _str, _marker_idx, _marker, ...) \ log_request_marker(_type, _lvl, request, \ __FILE__, __LINE__, \ - _str, _idx, _fmt, ## __VA_ARGS__) + _str, SIZE_MAX, _marker_idx, _marker, ## __VA_ARGS__) #else -#define RMARKER(_type, _lvl, _str, _idx, _fmt, ...) do { \ +#define RMARKER(_type, _lvl, _str, _marker_idx, _marker, ...) do { \ RDEBUG4("== (0) at %s[%u]", __FILE__, __LINE__); \ - log_request_marker(_type, _lvl, request, __FILE__, __LINE__, _str, _idx, _fmt, ## __VA_ARGS__); \ + log_request_marker(_type, _lvl, request, __FILE__, __LINE__, _str, _marker_idx, _marker, ## __VA_ARGS__); \ } while (0) #endif @@ -447,11 +447,11 @@ void log_global_free(void); * @warning If a request_t * is **NOT** available, or is NULL, this macro must **NOT** be used. * * @param[in] _str to mark e.g. "my pet kitty". - * @param[in] _idx index e.g. 3 (starts from 0). - * @param[in] _fmt error message e.g. "kitties are not pets, are nature devouring hell beasts". + * @param[in] _marker_idx index e.g. 3 (starts from 0). + * @param[in] _marker error message e.g. "kitties are not pets, are nature devouring hell beasts". * @param[in] ... arguments for error string. */ -#define REMARKER(_str, _idx, _fmt, ...) RMARKER(L_DBG_ERR, L_DBG_LVL_1, _str, _idx, _fmt, ## __VA_ARGS__) +#define REMARKER(_str, _marker_idx, _marker, ...) RMARKER(L_DBG_ERR, L_DBG_LVL_1, _str, _marker_idx, _marker, ## __VA_ARGS__) /** Output string with error marker, showing where format error occurred * @@ -465,11 +465,11 @@ void log_global_free(void); * @warning If a request_t * is **NOT** available, or is NULL, this macro must **NOT** be used. * * @param[in] _str to mark e.g. "my pet kitty". - * @param[in] _idx index e.g. 3 (starts from 0). - * @param[in] _fmt error message e.g. "kitties are not pets, are nature devouring hell beasts". + * @param[in] _marker_idx index e.g. 3 (starts from 0). + * @param[in] _marker error message e.g. "kitties are not pets, are nature devouring hell beasts". * @param[in] ... arguments for error string. */ -#define RDMARKER(_str, _idx, _fmt, ...) RMARKER(L_DBG, L_DBG_LVL_1, _str, _idx, _fmt, ## __VA_ARGS__) +#define RDMARKER(_str, _marker_idx, _marker, ...) RMARKER(L_DBG, L_DBG_LVL_1, _str, _marker_idx, _marker, ## __VA_ARGS__) /** Use different logging functions depending on whether request is NULL or not. * diff --git a/src/lib/util/log.c b/src/lib/util/log.c index 630f26d00cc..569bd9c64c6 100644 --- a/src/lib/util/log.c +++ b/src/lib/util/log.c @@ -688,21 +688,21 @@ void fr_log_marker(fr_log_t const *log, fr_log_type_t type, char const *file, in va_list ap; TALLOC_CTX *thread_log_pool = fr_log_pool_init(); char *line_prefix = NULL; - static char const spaces[] = " "; + static char const marker_spaces[] = " "; /* 60 */ if (str_len == SIZE_MAX) str_len = strlen(str); if (marker_idx < 0) marker_idx = marker_idx * -1; - if ((size_t)marker_idx >= sizeof(spaces)) { - size_t offset = (marker_idx - (sizeof(spaces) - 1)) + (sizeof(spaces) * 0.75); + if ((size_t)marker_idx >= sizeof(marker_spaces)) { + size_t offset = (marker_idx - (sizeof(marker_spaces) - 1)) + (sizeof(marker_spaces) * 0.75); marker_idx -= offset; if (offset > str_len) offset = str_len; str += offset; str_len -= offset; - ellipses = "... "; + ellipses = "... "; } if (line_prefix_fmt) { @@ -714,7 +714,7 @@ void fr_log_marker(fr_log_t const *log, fr_log_type_t type, char const *file, in fr_log(log, type, file, line, "%s%s%.*s", line_prefix ? line_prefix : "", ellipses, (int)str_len, str); fr_log(log, type, file, line, "%s%s%.*s^ %s", - line_prefix ? line_prefix : "", ellipses, (int)marker_idx, spaces, marker); + line_prefix ? line_prefix : "", ellipses, (int)marker_idx, marker_spaces, marker); if (line_prefix_fmt) talloc_free(line_prefix); }