diff options
author | Caoimhe <caoimhebyrne06@gmail.com> | 2023-05-19 23:32:04 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-21 18:45:53 +0200 |
commit | d87f823a68a538f4898b0d5f467d9e32b64ca032 (patch) | |
tree | 648c6db1ca240b6a00986a9e1eb7827945c729bc /Userland/Services/SpiceAgent | |
parent | af91c750803de47824863c88f42be692d4e9a4c2 (diff) | |
download | serenity-d87f823a68a538f4898b0d5f467d9e32b64ca032.zip |
SpiceAgent: Implement `FileTransferData` messages
Diffstat (limited to 'Userland/Services/SpiceAgent')
-rw-r--r-- | Userland/Services/SpiceAgent/Message.cpp | 21 | ||||
-rw-r--r-- | Userland/Services/SpiceAgent/Message.h | 22 |
2 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Services/SpiceAgent/Message.cpp b/Userland/Services/SpiceAgent/Message.cpp index 6bbb430e6e..6c7da27948 100644 --- a/Userland/Services/SpiceAgent/Message.cpp +++ b/Userland/Services/SpiceAgent/Message.cpp @@ -267,4 +267,25 @@ ErrorOr<String> FileTransferStatusMessage::debug_description() return builder.to_string(); } +ErrorOr<FileTransferDataMessage> FileTransferDataMessage::read_from_stream(AK::Stream& stream) +{ + auto id = TRY(stream.read_value<u32>()); + auto size = TRY(stream.read_value<u64>()); + + auto contents = TRY(ByteBuffer::create_uninitialized(size)); + TRY(stream.read_until_filled(contents)); + + return FileTransferDataMessage(id, contents); +} + +ErrorOr<String> FileTransferDataMessage::debug_description() +{ + StringBuilder builder; + TRY(builder.try_append("FileTransferData { "sv)); + TRY(builder.try_appendff("id = {}, ", id())); + TRY(builder.try_appendff("contents.size() = {}", contents().size())); + TRY(builder.try_append(" }"sv)); + return builder.to_string(); +} + } diff --git a/Userland/Services/SpiceAgent/Message.h b/Userland/Services/SpiceAgent/Message.h index 3875b89195..4d2345f3e7 100644 --- a/Userland/Services/SpiceAgent/Message.h +++ b/Userland/Services/SpiceAgent/Message.h @@ -242,6 +242,28 @@ private: FileTransferStatus m_status; }; +// Contains the file data sent from a file transfer request after it has been approved. +class FileTransferDataMessage : public Message { +public: + static ErrorOr<FileTransferDataMessage> read_from_stream(AK::Stream& stream); + + ErrorOr<String> debug_description() override; + + u32 id() const { return m_id; } + ByteBuffer const& contents() { return m_contents; } + +private: + FileTransferDataMessage(u32 id, ByteBuffer const& contents) + : Message(Type::FileTransferData) + , m_id(id) + , m_contents(contents) + { + } + + u32 m_id { 0 }; + ByteBuffer m_contents; +}; + } namespace AK { |