Files
MontaukOS/kernel/src/Api/DataTransfer.hpp
T

53 lines
2.0 KiB
C++

/*
* DataTransfer.hpp
* Multi-format payloads shared by the clipboard and drag and drop
* Copyright (c) 2026 Daniel Hammer
*/
#pragma once
#include <cstdint>
#include "Syscall.hpp"
// A transfer is a small set of formats, each one MIME type plus bytes, all
// owned by the kernel heap. Producers offer every representation they can
// (a file list and its paths as text, say) and each consumer reads the one it
// understands. The clipboard holds one transfer per user; the window server
// holds the active drag's.
namespace DataTransfer {
struct Format {
char mime[montauk::abi::TRANSFER_MIME_MAX];
uint8_t* data;
uint32_t len;
};
struct Transfer {
Format formats[montauk::abi::TRANSFER_MAX_FORMATS];
uint32_t count;
};
// Copy `count` formats in from user memory, validating every pointer the
// items carry (the item array itself must already be validated). On
// failure `out` is left empty. Returns a StatusCodes value.
int BuildFromUser(const montauk::abi::TransferItem* items, uint32_t count, Transfer& out);
// A transfer holding just `text` as TRANSFER_MIME_TEXT.
int BuildText(const char* text, uint32_t len, Transfer& out);
void Free(Transfer& transfer);
// Exact match first; a request without parameters ("text/plain") also
// matches a stored format that has them ("text/plain;charset=utf-8").
const Format* Find(const Transfer& transfer, const char* mime);
uint32_t ListFormats(const Transfer& transfer, montauk::abi::TransferFormatInfo* out, uint32_t max);
// Copy a format to a (validated) user buffer. *outLen always receives the
// full length; BufferTooSmall when it does not fit, nothing copied then.
int CopyOut(const Format& format, void* buffer, uint32_t bufferLen, uint32_t* outLen);
// MIME string checks shared by every entry point: "type/subtype" with
// optional parameters, printable ASCII, shorter than TRANSFER_MIME_MAX.
bool ValidMime(const char* mime);
}