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.
This commit is contained in:
Christian Kreibich 2022-06-18 01:03:31 -07:00
parent a2525e44ba
commit 8bc142f73c

View file

@ -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;