]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-event: Add event_get_global_root()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Apr 2026 19:52:41 +0000 (19:52 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sat, 2 May 2026 05:31:35 +0000 (05:31 +0000)
Returns the bottom-most (oldest pushed) event on the global event
stack, or the current global event if the stack is empty. Lets
plugins annotate the outermost active caller's event from within a
nested global event context.

src/lib/lib-event.c
src/lib/lib-event.h

index 92be8a5107054526709ea11897abb7e0a31b6fbc..dd9399d9ccd91ba6723b4b4cb6b2d587cc84d3a1 100644 (file)
@@ -553,6 +553,17 @@ struct event *event_get_global(void)
        return current_global_event;
 }
 
+struct event *event_get_global_root(void)
+{
+       if (array_is_created(&global_event_stack) &&
+           array_count(&global_event_stack) > 0) {
+               struct event *const *events =
+                       array_front(&global_event_stack);
+               return events[0];
+       }
+       return current_global_event;
+}
+
 #undef event_reason_begin
 struct event_reason *
 event_reason_begin(const char *reason_code, const char *source_filename,
index d005d8ea02f9835f6f85c407812130e8915bc4e4..6fc9251ef590930726e0e3c4c3ec09159903cf84 100644 (file)
@@ -215,6 +215,11 @@ struct event *event_push_global(struct event *event);
 struct event *event_pop_global(struct event *event);
 /* Returns the current global event. */
 struct event *event_get_global(void);
+/* Returns the bottom-most (oldest pushed) global event, or NULL if the
+   global event stack is empty. Useful for plugins that need to annotate
+   the outermost active caller's event (e.g. an IMAP command's global
+   event) from within a nested global event context. */
+struct event *event_get_global_root(void);
 
 /* Shortcut to create and push a global event and set its reason_code field. */
 struct event_reason *