/*********************************************************/
/* toksvc: a framework-native token broker service */
/* Copyright (C) 2020 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */
/*********************************************************/
#include <psxtypes/psxtypes.h>
#include <ntapi/ntapi.h>
#include <toksvc/toksvc.h>
#include "toksvc_daemon_impl.h"
#include "toksvc_driver_impl.h"
int32_t __stdcall toks_daemon_cancel(struct toks_daemon_ctx * dctx)
{
nt_tty_port_msg * msg;
nt_cid * cid;
struct toks_waiter * waiter;
int nwaiters;
int idx;
if ((nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx)) == 0)
return NT_STATUS_NOT_FOUND;
idx = 0;
msg = &dctx->reply;
cid = &msg->header.client_id;
waiter = dctx->waiter_first;
for (; idx<nwaiters; ) {
if (waiter->msg.header.client_id.process_id == cid->process_id) {
if (waiter->msg.header.client_id.thread_id == cid->thread_id) {
if (waiter->msg.header.msg_id) {
waiter->msg.header.msg_id = 0;
toks_set_driver_nwaiters(dctx->driver_ctx,--nwaiters);
return NT_STATUS_CANCELLED;
}
}
}
if (++waiter == dctx->waiter_cap)
waiter = dctx->waiter_base;
}
return NT_STATUS_NOT_FOUND;
}