summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/lib-sieve/sieve-runtime-trace.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/src/lib-sieve/sieve-runtime-trace.h
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--pigeonhole/src/lib-sieve/sieve-runtime-trace.h182
1 files changed, 182 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/sieve-runtime-trace.h b/pigeonhole/src/lib-sieve/sieve-runtime-trace.h
new file mode 100644
index 0000000..b165586
--- /dev/null
+++ b/pigeonhole/src/lib-sieve/sieve-runtime-trace.h
@@ -0,0 +1,182 @@
+#ifndef SIEVE_RUNTIME_TRACE_H
+#define SIEVE_RUNTIME_TRACE_H
+
+#include "sieve-common.h"
+#include "sieve-runtime.h"
+
+/*
+ * Runtime trace
+ */
+
+struct sieve_runtime_trace {
+ struct sieve_trace_config config;
+ struct sieve_trace_log *log;
+ unsigned int indent;
+};
+
+/* Trace configuration */
+
+static inline bool sieve_runtime_trace_active
+(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level)
+{
+ return ( renv->trace != NULL && trace_level <= renv->trace->config.level );
+}
+
+static inline bool sieve_runtime_trace_hasflag
+(const struct sieve_runtime_env *renv, unsigned int flag)
+{
+ return ( renv->trace != NULL && (renv->trace->config.flags & flag) != 0 );
+}
+
+/* Trace indent */
+
+static inline void sieve_runtime_trace_descend
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL ) renv->trace->indent++;
+}
+
+static inline void sieve_runtime_trace_ascend
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL ) renv->trace->indent--;
+}
+
+static inline void sieve_runtime_trace_toplevel
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL ) renv->trace->indent = 0;
+}
+
+/* Trace errors */
+
+void _sieve_runtime_trace_error
+ (const struct sieve_runtime_env *renv, const char *fmt, va_list args)
+ ATTR_FORMAT(2, 0);
+
+void _sieve_runtime_trace_operand_error
+ (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd,
+ const char *fmt, va_list args) ATTR_FORMAT(3, 0);
+
+static inline void sieve_runtime_trace_error
+ (const struct sieve_runtime_env *renv, const char *fmt, ...)
+ ATTR_FORMAT(2, 3);
+
+static inline void sieve_runtime_trace_operand_error
+ (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd,
+ const char *fmt, ...) ATTR_FORMAT(3, 4);
+
+static inline void ATTR_FORMAT(2, 3) sieve_runtime_trace_error
+ (const struct sieve_runtime_env *renv, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if ( renv->trace != NULL )
+ _sieve_runtime_trace_error(renv, fmt, args);
+ va_end(args);
+}
+
+static inline void ATTR_FORMAT(3, 4) sieve_runtime_trace_operand_error
+ (const struct sieve_runtime_env *renv, const struct sieve_operand *oprnd,
+ const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if ( renv->trace != NULL )
+ _sieve_runtime_trace_operand_error(renv, oprnd, fmt, args);
+ va_end(args);
+}
+
+/* Trace info */
+
+void _sieve_runtime_trace
+ (const struct sieve_runtime_env *renv, const char *fmt, va_list args)
+ ATTR_FORMAT(2, 0);
+
+static inline void sieve_runtime_trace
+ (const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level,
+ const char *fmt, ...) ATTR_FORMAT(3, 4);
+
+static inline void ATTR_FORMAT(3, 4) sieve_runtime_trace
+(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level,
+ const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+
+ if ( renv->trace != NULL && trace_level <= renv->trace->config.level ) {
+ _sieve_runtime_trace(renv, fmt, args);
+ }
+
+ va_end(args);
+}
+
+void _sieve_runtime_trace_address
+ (const struct sieve_runtime_env *renv, sieve_size_t address,
+ const char *fmt, va_list args) ATTR_FORMAT(3, 0);
+
+static inline void sieve_runtime_trace_address
+ (const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level,
+ sieve_size_t address, const char *fmt, ...) ATTR_FORMAT(4, 5);
+
+static inline void ATTR_FORMAT(4, 5) sieve_runtime_trace_address
+(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level,
+ sieve_size_t address, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+
+ if ( renv->trace != NULL && trace_level <= renv->trace->config.level ) {
+ _sieve_runtime_trace_address(renv, address, fmt, args);
+ }
+
+ va_end(args);
+}
+
+static inline void ATTR_FORMAT(3, 4) sieve_runtime_trace_here
+(const struct sieve_runtime_env *renv, sieve_trace_level_t trace_level,
+ const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+
+ if ( renv->trace != NULL && trace_level <= renv->trace->config.level ) {
+ _sieve_runtime_trace_address(renv, renv->pc, fmt, args);
+ }
+
+ va_end(args);
+}
+
+/* Trace boundaries */
+
+void _sieve_runtime_trace_begin(const struct sieve_runtime_env *renv);
+void _sieve_runtime_trace_end(const struct sieve_runtime_env *renv);
+void _sieve_runtime_trace_sep(const struct sieve_runtime_env *renv);
+
+static inline void sieve_runtime_trace_begin
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL )
+ _sieve_runtime_trace_begin(renv);
+}
+
+static inline void sieve_runtime_trace_end
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL )
+ _sieve_runtime_trace_end(renv);
+}
+
+static inline void sieve_runtime_trace_sep
+(const struct sieve_runtime_env *renv)
+{
+ if ( renv->trace != NULL )
+ _sieve_runtime_trace_sep(renv);
+}
+
+#endif