From 8bc142f73c4ce6b0218d5fa3897dc29b3edd0dc3 Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Sat, 18 Jun 2022 01:03:31 -0700 Subject: [PATCH] Management framework: add "finish" callback to requests These callbacks are handy for stringing together codepaths separated by event request/response transactions: when such a transaction completes, the callback allows locating a parent request for the finished one, to continue its processing. --- scripts/policy/frameworks/management/request.zeek | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/policy/frameworks/management/request.zeek b/scripts/policy/frameworks/management/request.zeek index 676c65f6bd..f7a798ace6 100644 --- a/scripts/policy/frameworks/management/request.zeek +++ b/scripts/policy/frameworks/management/request.zeek @@ -32,6 +32,14 @@ export { finished: bool &default=F; }; + # To allow a callback to refer to Requests, the Request type must + # exist. So redef to add it: + redef record Request += { + ## A callback to invoke when this request is finished via + ## :zeek:see:`Management::Request::finish`. + finish: function(req: Management::Request::Request) &optional; + }; + ## The timeout interval for request state. Such state (see the ## :zeek:see:`Management::Request` module) ties together request and ## response event pairs. A timeout causes cleanup of request state if @@ -131,6 +139,9 @@ function finish(reqid: string): bool local req = g_requests[reqid]; delete g_requests[reqid]; + if ( req?$finish ) + req$finish(req); + req$finished = T; return T;