Skip to content

Commit

Permalink
Merge branch 'main' into anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi authored Dec 8, 2024
2 parents 5324b2a + 9b28136 commit f816ba9
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DirectoryStructure {
}

func update(_ outlineView: NSOutlineView) {
guard let rootNodes: [FileNode] = DataRepository.shared.nodes(join(server, path)) else {
guard let rootNodes: [FileNode] = DataRepository.shared.nodes(join(server, treeAccessor.share, path)) else {
return
}

Expand All @@ -102,7 +102,7 @@ class DirectoryStructure {
return $0.isDirectory && outlineView.isItemExpanded($0)
}
.reduce(into: [FileNode]()) {
guard let nodes: [FileNode] = DataRepository.shared.nodes(join(server, $1.path)) else {
guard let nodes: [FileNode] = DataRepository.shared.nodes(join(server, treeAccessor.share, $1.path)) else {
return
}
let parent = $1.id
Expand Down Expand Up @@ -211,7 +211,7 @@ class DirectoryStructure {
let nodes = files
.map { FileNode(path: join(path, $0.name), file: $0, parent: parent?.id) }

DataRepository.shared.set(join(server, path), nodes: nodes)
DataRepository.shared.set(join(server, treeAccessor.share, path), nodes: nodes)

return nodes
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Close.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Close {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Close.Response

public let header: Header
public let structureSize: UInt16
public let flags: UInt16
Expand Down Expand Up @@ -44,7 +46,7 @@ public enum Close {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let flags: UInt16
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Create.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Create {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Create.Response

public private(set) var header: Header
public let structureSize: UInt16
public let securityFlags: UInt8
Expand Down Expand Up @@ -93,7 +95,7 @@ public enum Create {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let oplockLevel: UInt8
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Echo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Echo {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Echo.Response

public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down Expand Up @@ -37,7 +39,7 @@ public enum Echo {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/IOCtl.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum IOCtl {
public struct Request {
public struct Request: Message.Request {
public typealias Response = IOCtl.Response

public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down Expand Up @@ -75,7 +77,7 @@ public enum IOCtl {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Logoff.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Logoff {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Logoff.Response

public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down Expand Up @@ -36,7 +38,7 @@ public enum Logoff {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down
13 changes: 13 additions & 0 deletions Sources/SMBClient/Messages/Message.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public enum Message {
public protocol Request {
associatedtype Response: Message.Response
func encoded() -> Data
}

public protocol Response {
var header: Header { get }
init(data: Data)
}
}
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Negotiate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Negotiate {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Negotiate.Response

public let header: Header
public let structureSize: UInt16
public let dialectCount: UInt16
Expand Down Expand Up @@ -65,7 +67,7 @@ public enum Negotiate {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let securityMode: SecurityMode
Expand Down
8 changes: 5 additions & 3 deletions Sources/SMBClient/Messages/QueryDirectory.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum QueryDirectory {
public struct Request {
public struct Request: Message.Request {
public typealias Response = QueryDirectory.Response

public let header: Header
public let structureSize: UInt16
public let fileInformationClass: FileInformationClass
Expand Down Expand Up @@ -67,7 +69,7 @@ public enum QueryDirectory {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let outputBufferOffset: UInt16
Expand All @@ -82,7 +84,7 @@ public enum QueryDirectory {
structureSize = reader.read()
outputBufferOffset = reader.read()
outputBufferLength = reader.read()
buffer = data[UInt32(outputBufferOffset)..<UInt32(outputBufferOffset) + outputBufferLength]
buffer = reader.read(from: Int(outputBufferOffset), count: Int(outputBufferLength))
}

public func files() -> [FileDirectoryInformation] {
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/QueryInfo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum QueryInfo {
public struct Request {
public struct Request: Message.Request {
public typealias Response = QueryInfo.Response

public let header: Header
public let structureSize: UInt16
public let infoType: InfoType
Expand Down Expand Up @@ -69,7 +71,7 @@ public enum QueryInfo {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let outputBufferOffset: UInt16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Read.Response: CustomDebugStringConvertible {
Blob Length: \(dataLength)
Data Rmaining: \(dataRemaining)
Reserved2: \(String(format: "%08x", reserved2))
Data: \(buffer.hex)
Data: \(buffer)
"""
}
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Read.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Read {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Read.Response

public let header: Header
public let structureSize: UInt16
public let padding: UInt8
Expand Down Expand Up @@ -72,7 +74,7 @@ public enum Read {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let dataOffset: UInt8
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/SessionSetup.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum SessionSetup {
public struct Request {
public struct Request: Message.Request {
public typealias Response = SessionSetup.Response

public let header: Header
public let structureSize: UInt16
public let flags: Flags
Expand Down Expand Up @@ -60,7 +62,7 @@ public enum SessionSetup {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header

public let structureSize: UInt16
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/SetInfo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

enum SetInfo {
public struct Request {
public struct Request: Message.Request {
public typealias Response = SetInfo.Response

public let header: Header
public let structureSize: UInt16
public let infoType: InfoType
Expand Down Expand Up @@ -69,7 +71,7 @@ enum SetInfo {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16

Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/TreeConnect.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum TreeConnect {
public struct Request {
public struct Request: Message.Request {
public typealias Response = TreeConnect.Response

public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down Expand Up @@ -48,7 +50,7 @@ public enum TreeConnect {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let shareType: UInt8
Expand Down
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/TreeDisconnect.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum TreeDisconnect {
public struct Request {
public struct Request: Message.Request {
public typealias Response = TreeDisconnect.Response

public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down Expand Up @@ -37,7 +39,7 @@ public enum TreeDisconnect {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Foundation

extension Write.Request: CustomDebugStringConvertible {
public var debugDescription: String {
"""
\(header)
Write Request (\(String(format: "0x%02x", header.command)))
StructureSize: \(structureSize)
Data Offset: \(dataOffset)
Write Length: \(length)
File Offset: \(offset)
GUID handle: \(fileId.to(type: UUID.self))
Channel: 0x\(String(format: "%08x", channel))
Remaining Bytes: \(remainingBytes)
Write Flags: \(flags)
Blob Offset: \(writeChannelInfoOffset)
Blob Length: \(writeChannelInfoLength)
Channel Info Blob: \(buffer.hex)
"""
}
}

extension Write.Response: CustomDebugStringConvertible {
public var debugDescription: String {
"""
\(header)
Read Response (\(String(format: "0x%02x", header.command)))
StructureSize: \(structureSize)
Reserved: \(String(format: "%04x", reserved))
Write Count: \(count)
Write Remaining: \(remaining)
Channel Info Offset: \(writeChannelInfoOffset)
Channel Info Length: \(writeChannelInfoLength)
"""
}
}

extension Write.Flags: CustomDebugStringConvertible {
public var debugDescription: String {
var values = [String]()

if contains(.writeThrough) {
values.append("Write Through")
}
if contains(.writeUnbuffered) {
values.append("Unbuffered")
}

if values.isEmpty {
return "0x\(String(format: "%08x", rawValue))"
} else {
return "0x\(String(format: "%08x", rawValue)) (\(values.joined(separator: ", ")))"
}
}
}
6 changes: 4 additions & 2 deletions Sources/SMBClient/Messages/Write.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

public enum Write {
public struct Request {
public struct Request: Message.Request {
public typealias Response = Write.Response

public let header: Header
public let structureSize: UInt16
public let dataOffset: UInt16
Expand Down Expand Up @@ -69,7 +71,7 @@ public enum Write {
}
}

public struct Response {
public struct Response: Message.Response {
public let header: Header
public let structureSize: UInt16
public let reserved: UInt16
Expand Down
Loading

0 comments on commit f816ba9

Please sign in to comment.