mutating func readGlobalRequestMessage()

in Sources/NIOSSH/SSHMessages.swift [775:821]


    mutating func readGlobalRequestMessage() throws -> SSHMessage.GlobalRequestMessage? {
        self.rewindReaderOnNil { `self` in
            guard
                let name = self.readSSHStringAsString(),
                let wantReply = self.readSSHBoolean()
            else {
                return nil
            }

            let type: SSHMessage.GlobalRequestMessage.RequestType

            switch name {
            case "tcpip-forward":
                guard
                    let addressToBind = self.readSSHStringAsString(),
                    let port = self.readInteger(as: UInt32.self)
                else {
                    return nil
                }

                type = .tcpipForward(addressToBind, port)

            case "cancel-tcpip-forward":
                guard
                    let addressToBind = self.readSSHStringAsString(),
                    let port = self.readInteger(as: UInt32.self)
                else {
                    return nil
                }

                type = .cancelTcpipForward(addressToBind, port)

            default:
                // The list of global request types can be, and is, extended.
                // Throwing an error would abort the connection, therefore the request is wrapped to be `unknown`.
                //
                // The remainder of the payload is formatted according to the spec associated by the request type.
                // It cannot be parsed unless the request type is a known type.
                // So the remainder of the payload is attached as-is.
                let globalRequestPayload = self.readSlice(length: self.readableBytes)!

                type = .unknown(name, globalRequestPayload)
            }

            return SSHMessage.GlobalRequestMessage(wantReply: wantReply, type: type)
        }
    }