diff --git a/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCClient.swift b/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCClient.swift index 22d5915..05da5d8 100644 --- a/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCClient.swift +++ b/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCClient.swift @@ -301,7 +301,7 @@ public final class ESXPCClient: ESClientProtocol { } try connectionLock.withLock { - try syncExecutor { callback in + try syncExecutor.sync { callback in let proxy = try connection.remoteObjectProxy { callback($0) } .get(name: "ESXPCConnection", description: "ES XPC client is not connected") try body(proxy, callback) @@ -314,7 +314,7 @@ public final class ESXPCClient: ESClientProtocol { body: @escaping (ESClientXPCProtocol, @escaping (Result) -> Void) throws -> Void ) throws -> T { try connectionLock.withLock { - try syncExecutor { (callback: @escaping (Result) -> Void) in + try syncExecutor.sync { (callback: @escaping (Result) -> Void) in let proxy = try connection.remoteObjectProxy { callback(.failure($0)) } .get(name: "ESXPCConnection", description: "ES XPC client is not connected") try body(proxy, callback) diff --git a/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCListener.swift b/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCListener.swift index 1c63538..edb44c6 100644 --- a/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCListener.swift +++ b/EndpointSecurity/Sources/SpellbookEndpointSecurityXPC/ESXPCListener.swift @@ -250,7 +250,7 @@ private final class ESXPCExportedObject: NSObject, ESClientXPCProtocol { do { let encoded = try xpcEncoder.encode(process) let executor = SynchronousExecutor("HandlePathInterest", timeout: 5.0) - guard let interest = try executor({ reply in + guard let interest = try executor.sync({ reply in DispatchQueue.global().async { self.delegate.handlePathInterest(encoded, reply: reply) } }) else { return .listen() diff --git a/Mac/Tests/SpellbookMacTests/Users & Groups/ACLTests.swift b/Mac/Tests/SpellbookMacTests/Users & Groups/ACLTests.swift index efeaccf..d4aa04b 100644 --- a/Mac/Tests/SpellbookMacTests/Users & Groups/ACLTests.swift +++ b/Mac/Tests/SpellbookMacTests/Users & Groups/ACLTests.swift @@ -1,12 +1,12 @@ import SpellbookMac -import SpellbookTestUtils +import SpellbookFoundation import XCTest private let fm = FileManager.default class ACLTests: XCTestCase { - let tmpRoot = TestTemporaryDirectory(prefix: "ACLTests") + let tmpRoot = TemporaryDirectory.bundle.directory(prefix: "ACLTests") override func setUpWithError() throws { try super.setUpWithError() @@ -19,7 +19,7 @@ class ACLTests: XCTestCase { } func test() throws { - let path = tmpRoot.url.path + let path = tmpRoot.location.path XCTAssertThrowsError(try FileManager.default.acl(atPath: path)) XCTAssertThrowsError(try fm.acl(atPath: "/foo/nonexistent")) diff --git a/Package.swift b/Package.swift index 2dab59c..d201850 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( .library(name: "SpellbookXPC", targets: ["SpellbookXPC"]), ], dependencies: [ - .package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "0.4.2"), + .package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "1.0.0"), ], targets: [ // MacShims. @@ -113,6 +113,7 @@ let package = Package( dependencies: [ "SpellbookMac", .product(name: "SpellbookFoundation", package: "SwiftSpellbook"), + .product(name: "SpellbookBinaryParsing", package: "SwiftSpellbook"), ], path: "XPC/Sources/SpellbookXPC" ), diff --git a/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportConnection.swift b/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportConnection.swift index 1297e8e..cce5b0b 100644 --- a/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportConnection.swift +++ b/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportConnection.swift @@ -24,6 +24,7 @@ import Foundation import SpellbookFoundation +import SpellbookBinaryParsing private let clientHello = Data(UUID(staticString: "fef88fd3-9f29-4632-8827-0b417472c8f2").uuidString.utf8) private let serverHello = Data(UUID(staticString: "071e1957-bf27-4669-961a-7e707b980740").uuidString.utf8) diff --git a/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportListener.swift b/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportListener.swift index e914dc8..da53d45 100644 --- a/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportListener.swift +++ b/XPC/Sources/SpellbookXPC/XPC Transport/XPCTransportListener.swift @@ -87,14 +87,14 @@ public class XPCTransportServer { self.connectionOpened?(transport.peerInfo) case .invalidated: self.connectionClosed?(transport.peerInfo) - self.connections.writeAsync { $0.removeValue(forKey: id) } + self.connections.write { _ = $0.removeValue(forKey: id) } case .connecting: break } } prepareNewConnectionReceive?(transport) - connections.writeAsync { $0[id] = transport } + connections.write { $0[id] = transport } transport.activate() } } diff --git a/XPC/Sources/SpellbookXPC/XPCConnection/XPCClient.swift b/XPC/Sources/SpellbookXPC/XPCConnection/XPCClient.swift index 0a9e977..70c644f 100644 --- a/XPC/Sources/SpellbookXPC/XPCConnection/XPCClient.swift +++ b/XPC/Sources/SpellbookXPC/XPCConnection/XPCClient.swift @@ -69,7 +69,7 @@ public class XPCClient { /// Observalbe state of the connection. The value is present when connection is alive. /// Can be used to monitor connection state (connected/not connected). - public let connectedState: Observable + public let connectedState: ValueObservable // Get a proxy for the remote object (that is, the object exported from the other side of this connection). public func remoteObjectProxy(synchronous: Bool = false, errorHandler: ((Error) -> Void)? = nil) -> RemoteInterface { @@ -113,7 +113,7 @@ public class XPCClient { self.queue = DispatchQueue(label: "\(Self.self).queue") self.connectedStateStore = infoStore - self.connectedState = infoStore.asObservable + self.connectedState = infoStore.observable self.connection = createConnection(.connection(.init(serviceName: "not activated connection"))) self.createConnection = createConnection } diff --git a/XPC/Sources/SpellbookXPC/XPCConnection/XPCConnection.swift b/XPC/Sources/SpellbookXPC/XPCConnection/XPCConnection.swift index eb3eee3..17b46dc 100644 --- a/XPC/Sources/SpellbookXPC/XPCConnection/XPCConnection.swift +++ b/XPC/Sources/SpellbookXPC/XPCConnection/XPCConnection.swift @@ -202,11 +202,11 @@ extension XPCConnection { } private func registerInStorage() { - _currentConnectionStorage.writeAsync { $0[ObjectIdentifier(self.native)] = Weak(self) } + _currentConnectionStorage.write { $0[ObjectIdentifier(self.native)] = Weak(self) } } private func unregisterFromStorage() { - _currentConnectionStorage.writeAsync { [id = ObjectIdentifier(native)] in $0.removeValue(forKey: id) } + _currentConnectionStorage.write { [id = ObjectIdentifier(native)] in _ = $0.removeValue(forKey: id) } } } diff --git a/XPC/Sources/SpellbookXPC/XPCConnection/XPCListener.swift b/XPC/Sources/SpellbookXPC/XPCConnection/XPCListener.swift index 0fe0ab1..5cc810a 100644 --- a/XPC/Sources/SpellbookXPC/XPCConnection/XPCListener.swift +++ b/XPC/Sources/SpellbookXPC/XPCConnection/XPCListener.swift @@ -140,49 +140,3 @@ extension XPCListenerInit { } } } - -// MARK: - AnyXPCListener - -public extension XPCListenerProtocol { - func eraseToAnyXPCListener() -> AnyXPCListener { - AnyXPCListener(self) - } -} - -public class AnyXPCListener: XPCListenerProtocol { - private let _newConnectionHandler: GetSet<((XPCConnection) -> Bool)?> - private let _verifyConnectionHandler: GetSet<((audit_token_t) -> Bool)?> - private let _resume: () -> Void - private let _suspend: () -> Void - private let _invalidate: () -> Void - - public init(_ listener: Listener) where Listener.ExportedInterface == ExportedInterface, Listener.RemoteInterface == RemoteInterface { - self._newConnectionHandler = GetSet(listener, \.newConnectionHandler) - self._verifyConnectionHandler = GetSet(listener, \.verifyConnectionHandler) - self._resume = listener.resume - self._suspend = listener.suspend - self._invalidate = listener.invalidate - } - - public var newConnectionHandler: ((XPCConnection) -> Bool)? { - get { _newConnectionHandler.get() } - set { _newConnectionHandler.set(newValue) } - } - - public var verifyConnectionHandler: ((audit_token_t) -> Bool)? { - get { _verifyConnectionHandler.get() } - set { _verifyConnectionHandler.set(newValue) } - } - - public func resume() { - _resume() - } - - public func suspend() { - _suspend() - } - - public func invalidate() { - _invalidate() - } -}