using Opc.Ua; using ZB.MOM.WW.OtOpcUa.Core.Authorization; using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security; namespace ZB.MOM.WW.OtOpcUa.OpcUaServer; /// SDK-owned, session-bound peer cursor; it does not expose or own the peer token to the client. internal sealed class ProjectedBrowseContinuation : IDisposable { private readonly object _sync = new(); private readonly NodeId _parent; private readonly NodeId _session; private readonly DataCallerIdentity _caller; private string? _cursor; private bool _disposed; public ProjectedBrowseContinuation(NodeId parent, NodeId session, RoleCarryingUserIdentity caller, string? cursor) { _parent = parent; _session = session; _caller = new(caller.Principal, caller.ApiKeyId, caller.CredentialVersion, caller.CredentialExpiresUtc); _cursor = cursor; } public bool TryGetCursor(NodeId parent, NodeId session, RoleCarryingUserIdentity caller, out string? cursor) { lock (_sync) { if (!_disposed && parent == _parent && session == _session && _caller == new DataCallerIdentity(caller.Principal, caller.ApiKeyId, caller.CredentialVersion, caller.CredentialExpiresUtc)) { cursor = _cursor; return true; } cursor = null; return false; } } public bool TryAdvance(string? expectedCursor, string? nextCursor, Func commit) { ArgumentNullException.ThrowIfNull(commit); lock (_sync) { if (_disposed || _cursor != expectedCursor || !commit()) return false; _cursor = nextCursor; return true; } } public void Dispose() { lock (_sync) { _disposed = true; _cursor = null; } } }