mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
refactor(core): move IntoOwned
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
committed by
Benoît Cortier
parent
7419467ad3
commit
76b0518afa
@@ -5,7 +5,7 @@ use ironrdp_cliprdr::pdu::{
|
||||
ClipboardFormat, ClipboardGeneralCapabilityFlags, FileContentsRequest, FileContentsResponse, FormatDataRequest,
|
||||
FormatDataResponse, LockDataId,
|
||||
};
|
||||
use ironrdp_core::impl_as_any;
|
||||
use ironrdp_core::{impl_as_any, IntoOwned};
|
||||
use windows::Win32::Foundation::{HWND, LPARAM, WPARAM};
|
||||
use windows::Win32::UI::WindowsAndMessaging::PostMessageW;
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use ironrdp_core::{IntoOwned, ReadCursor, WriteCursor};
|
||||
use ironrdp_pdu::utils::{read_string_from_cursor, write_string_to_cursor, CharacterSet};
|
||||
use ironrdp_pdu::{
|
||||
cast_int, ensure_size, impl_pdu_borrowing, invalid_message_err, IntoOwnedPdu, PduDecode, PduEncode, PduResult,
|
||||
};
|
||||
use ironrdp_pdu::{cast_int, ensure_size, impl_pdu_borrowing, invalid_message_err, PduDecode, PduEncode, PduResult};
|
||||
|
||||
use crate::pdu::PartialHeader;
|
||||
|
||||
@@ -16,10 +14,10 @@ pub struct ClientTemporaryDirectory<'a> {
|
||||
|
||||
impl_pdu_borrowing!(ClientTemporaryDirectory<'_>, OwnedClientTemporaryDirectory);
|
||||
|
||||
impl IntoOwnedPdu for ClientTemporaryDirectory<'_> {
|
||||
impl IntoOwned for ClientTemporaryDirectory<'_> {
|
||||
type Owned = OwnedClientTemporaryDirectory;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
OwnedClientTemporaryDirectory {
|
||||
path_buffer: Cow::Owned(self.path_buffer.into_owned()),
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use ironrdp_core::{IntoOwned, ReadCursor, WriteCursor};
|
||||
use ironrdp_pdu::utils::{combine_u64, split_u64};
|
||||
use ironrdp_pdu::{
|
||||
cast_int, ensure_size, impl_pdu_borrowing, invalid_message_err, IntoOwnedPdu, PduDecode, PduEncode, PduResult,
|
||||
};
|
||||
use ironrdp_pdu::{cast_int, ensure_size, impl_pdu_borrowing, invalid_message_err, PduDecode, PduEncode, PduResult};
|
||||
|
||||
use crate::pdu::{ClipboardPduFlags, PartialHeader};
|
||||
|
||||
@@ -36,10 +34,10 @@ pub struct FileContentsResponse<'a> {
|
||||
|
||||
impl_pdu_borrowing!(FileContentsResponse<'_>, OwnedFileContentsResponse);
|
||||
|
||||
impl IntoOwnedPdu for FileContentsResponse<'_> {
|
||||
impl IntoOwned for FileContentsResponse<'_> {
|
||||
type Owned = OwnedFileContentsResponse;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
OwnedFileContentsResponse {
|
||||
is_error: self.is_error,
|
||||
stream_id: self.stream_id,
|
||||
|
||||
@@ -9,11 +9,10 @@ pub use self::palette::*;
|
||||
#[rustfmt::skip]
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ironrdp_core::IntoOwned;
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use ironrdp_pdu::utils::{read_string_from_cursor, to_utf16_bytes, CharacterSet};
|
||||
use ironrdp_pdu::{
|
||||
cast_int, ensure_fixed_part_size, ensure_size, impl_pdu_borrowing, IntoOwnedPdu, PduDecode, PduEncode, PduResult,
|
||||
};
|
||||
use ironrdp_pdu::{cast_int, ensure_fixed_part_size, ensure_size, impl_pdu_borrowing, PduDecode, PduEncode, PduResult};
|
||||
|
||||
use super::ClipboardFormatId;
|
||||
use crate::pdu::{ClipboardPduFlags, PartialHeader};
|
||||
@@ -27,10 +26,10 @@ pub struct FormatDataResponse<'a> {
|
||||
|
||||
impl_pdu_borrowing!(FormatDataResponse<'_>, OwnedFormatDataResponse);
|
||||
|
||||
impl IntoOwnedPdu for FormatDataResponse<'_> {
|
||||
impl IntoOwned for FormatDataResponse<'_> {
|
||||
type Owned = OwnedFormatDataResponse;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
OwnedFormatDataResponse {
|
||||
is_error: self.is_error,
|
||||
data: Cow::Owned(self.data.into_owned()),
|
||||
@@ -163,10 +162,6 @@ impl<'a> FormatDataResponse<'a> {
|
||||
read_string_from_cursor(&mut cursor, CharacterSet::Unicode, true)
|
||||
}
|
||||
|
||||
pub fn into_owned(self) -> OwnedFormatDataResponse {
|
||||
self.into_owned_pdu()
|
||||
}
|
||||
|
||||
pub fn into_data(self) -> Cow<'a, [u8]> {
|
||||
self.data
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use ironrdp_core::{IntoOwned, ReadCursor, WriteCursor};
|
||||
use ironrdp_pdu::utils::{read_string_from_cursor, to_utf16_bytes, write_string_to_cursor, CharacterSet};
|
||||
use ironrdp_pdu::{
|
||||
cast_int, ensure_size, impl_pdu_borrowing, impl_pdu_pod, invalid_message_err, IntoOwnedPdu, PduDecode, PduEncode,
|
||||
PduResult,
|
||||
cast_int, ensure_size, impl_pdu_borrowing, impl_pdu_pod, invalid_message_err, PduDecode, PduEncode, PduResult,
|
||||
};
|
||||
|
||||
use crate::pdu::{ClipboardPduFlags, PartialHeader};
|
||||
@@ -219,10 +218,10 @@ pub struct FormatList<'a> {
|
||||
|
||||
impl_pdu_borrowing!(FormatList<'_>, OwnedFormatList);
|
||||
|
||||
impl IntoOwnedPdu for FormatList<'_> {
|
||||
impl IntoOwned for FormatList<'_> {
|
||||
type Owned = OwnedFormatList;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
OwnedFormatList {
|
||||
use_ascii: self.use_ascii,
|
||||
encoded_formats: Cow::Owned(self.encoded_formats.into_owned()),
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/// Used to produce an owned version of a given data.
|
||||
pub trait IntoOwned: Sized {
|
||||
/// The resulting type after obtaining ownership.
|
||||
type Owned: 'static;
|
||||
|
||||
/// Creates owned data from data.
|
||||
fn into_owned(self) -> Self::Owned;
|
||||
}
|
||||
@@ -12,11 +12,13 @@ mod macros;
|
||||
|
||||
mod as_any;
|
||||
mod cursor;
|
||||
mod into_owned;
|
||||
|
||||
// Flat API hierarchy of common traits and types
|
||||
|
||||
pub use self::as_any::*;
|
||||
pub use self::cursor::*;
|
||||
pub use self::into_owned::*;
|
||||
|
||||
// Trait that can only be implemented within the current module
|
||||
pub(crate) mod private {
|
||||
|
||||
@@ -247,13 +247,6 @@ pub fn decode_owned_cursor<T: PduDecodeOwned>(src: &mut ReadCursor<'_>) -> PduRe
|
||||
T::decode_owned(src)
|
||||
}
|
||||
|
||||
/// Trait used to produce an owned version of a given PDU.
|
||||
pub trait IntoOwnedPdu: Sized {
|
||||
type Owned: 'static;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned;
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum Action {
|
||||
|
||||
@@ -223,10 +223,10 @@ macro_rules! const_assert {
|
||||
#[macro_export]
|
||||
macro_rules! impl_pdu_pod {
|
||||
($pdu_ty:ty) => {
|
||||
impl $crate::IntoOwnedPdu for $pdu_ty {
|
||||
impl ::ironrdp_core::IntoOwned for $pdu_ty {
|
||||
type Owned = Self;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ macro_rules! impl_pdu_borrowing {
|
||||
impl $crate::PduDecodeOwned for $owned_ty {
|
||||
fn decode_owned(src: &mut ReadCursor<'_>) -> $crate::PduResult<Self> {
|
||||
let pdu = <$pdu_ty $(<$($lt),+>)? as $crate::PduDecode>::decode(src)?;
|
||||
Ok($crate::IntoOwnedPdu::into_owned_pdu(pdu))
|
||||
Ok(ironrdp_core::IntoOwned::into_owned(pdu))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::gcc::{ChannelDef, ClientGccBlocks, ConferenceCreateRequest, Conferenc
|
||||
use crate::tpdu::{TpduCode, TpduHeader};
|
||||
use crate::tpkt::TpktHeader;
|
||||
use crate::x224::{user_data_size, X224Pdu};
|
||||
use crate::{per, IntoOwnedPdu, PduError, PduErrorExt as _, PduResult};
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use crate::{per, PduError, PduErrorExt as _, PduResult};
|
||||
use ironrdp_core::{IntoOwned, ReadCursor, WriteCursor};
|
||||
|
||||
// T.125 MCS is defined in:
|
||||
//
|
||||
@@ -274,19 +274,19 @@ pub enum McsMessage<'a> {
|
||||
|
||||
impl_pdu_borrowing!(McsMessage<'_>, OwnedMcsMessage);
|
||||
|
||||
impl IntoOwnedPdu for McsMessage<'_> {
|
||||
impl IntoOwned for McsMessage<'_> {
|
||||
type Owned = OwnedMcsMessage;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
match self {
|
||||
Self::ErectDomainRequest(msg) => McsMessage::ErectDomainRequest(msg.into_owned_pdu()),
|
||||
Self::AttachUserRequest(msg) => McsMessage::AttachUserRequest(msg.into_owned_pdu()),
|
||||
Self::AttachUserConfirm(msg) => McsMessage::AttachUserConfirm(msg.into_owned_pdu()),
|
||||
Self::ChannelJoinRequest(msg) => McsMessage::ChannelJoinRequest(msg.into_owned_pdu()),
|
||||
Self::ChannelJoinConfirm(msg) => McsMessage::ChannelJoinConfirm(msg.into_owned_pdu()),
|
||||
Self::SendDataRequest(msg) => McsMessage::SendDataRequest(msg.into_owned_pdu()),
|
||||
Self::SendDataIndication(msg) => McsMessage::SendDataIndication(msg.into_owned_pdu()),
|
||||
Self::DisconnectProviderUltimatum(msg) => McsMessage::DisconnectProviderUltimatum(msg.into_owned_pdu()),
|
||||
Self::ErectDomainRequest(msg) => McsMessage::ErectDomainRequest(msg.into_owned()),
|
||||
Self::AttachUserRequest(msg) => McsMessage::AttachUserRequest(msg.into_owned()),
|
||||
Self::AttachUserConfirm(msg) => McsMessage::AttachUserConfirm(msg.into_owned()),
|
||||
Self::ChannelJoinRequest(msg) => McsMessage::ChannelJoinRequest(msg.into_owned()),
|
||||
Self::ChannelJoinConfirm(msg) => McsMessage::ChannelJoinConfirm(msg.into_owned()),
|
||||
Self::SendDataRequest(msg) => McsMessage::SendDataRequest(msg.into_owned()),
|
||||
Self::SendDataIndication(msg) => McsMessage::SendDataIndication(msg.into_owned()),
|
||||
Self::DisconnectProviderUltimatum(msg) => McsMessage::DisconnectProviderUltimatum(msg.into_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,10 +557,10 @@ pub struct SendDataRequest<'a> {
|
||||
|
||||
impl_pdu_borrowing!(SendDataRequest<'_>, OwnedSendDataRequest);
|
||||
|
||||
impl IntoOwnedPdu for SendDataRequest<'_> {
|
||||
impl IntoOwned for SendDataRequest<'_> {
|
||||
type Owned = OwnedSendDataRequest;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
SendDataRequest {
|
||||
user_data: Cow::Owned(self.user_data.into_owned()),
|
||||
..self
|
||||
@@ -638,10 +638,10 @@ pub struct SendDataIndication<'a> {
|
||||
|
||||
impl_pdu_borrowing!(SendDataIndication<'_>, OwnedSendDataIndication);
|
||||
|
||||
impl IntoOwnedPdu for SendDataIndication<'_> {
|
||||
impl IntoOwned for SendDataIndication<'_> {
|
||||
type Owned = OwnedSendDataIndication;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
SendDataIndication {
|
||||
user_data: Cow::Owned(self.user_data.into_owned()),
|
||||
..self
|
||||
|
||||
@@ -2,8 +2,8 @@ use std::borrow::Cow;
|
||||
|
||||
use crate::tpdu::{TpduCode, TpduHeader};
|
||||
use crate::tpkt::TpktHeader;
|
||||
use crate::{IntoOwnedPdu, Pdu, PduDecode, PduEncode, PduError, PduErrorExt as _, PduResult};
|
||||
use ironrdp_core::{ReadCursor, WriteCursor};
|
||||
use crate::{Pdu, PduDecode, PduEncode, PduError, PduErrorExt as _, PduResult};
|
||||
use ironrdp_core::{IntoOwned, ReadCursor, WriteCursor};
|
||||
|
||||
pub trait X224Pdu<'de>: Sized {
|
||||
const X224_NAME: &'static str;
|
||||
@@ -92,10 +92,10 @@ pub struct X224Data<'a> {
|
||||
|
||||
impl_pdu_borrowing!(X224Data<'_>, OwnedX224Data);
|
||||
|
||||
impl IntoOwnedPdu for X224Data<'_> {
|
||||
impl IntoOwned for X224Data<'_> {
|
||||
type Owned = OwnedX224Data;
|
||||
|
||||
fn into_owned_pdu(self) -> Self::Owned {
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
X224Data {
|
||||
data: Cow::Owned(self.data.into_owned()),
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use ironrdp::cliprdr::pdu::{
|
||||
};
|
||||
use ironrdp_cliprdr_format::bitmap::{dib_to_png, dibv5_to_png, png_to_cf_dibv5};
|
||||
use ironrdp_cliprdr_format::html::{cf_html_to_plain_html, plain_html_to_cf_html};
|
||||
use ironrdp_core::impl_as_any;
|
||||
use ironrdp_core::{impl_as_any, IntoOwned};
|
||||
use transaction::{ClipboardContent, ClipboardContentValue};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user