now_proto_pdu/session/
mod.rs1mod lock;
2mod logoff;
3mod msg_box_req;
4mod msg_box_rsp;
5mod set_kbd_layout;
6mod window_rec_event;
7mod window_rec_start;
8mod window_rec_stop;
9
10use ironrdp_core::{DecodeResult, Encode, EncodeResult, IntoOwned, ReadCursor, WriteCursor};
11pub use lock::NowSessionLockMsg;
12pub use logoff::NowSessionLogoffMsg;
13pub use msg_box_req::{NowMessageBoxStyle, NowSessionMsgBoxReqMsg, OwnedNowSessionMsgBoxReqMsg};
14pub use msg_box_rsp::{NowMsgBoxResponse, NowSessionMsgBoxRspMsg, OwnedNowSessionMsgBoxRspMsg};
15pub use set_kbd_layout::{NowSessionSetKbdLayoutMsg, OwnedNowSessionSetKbdLayoutMsg, SetKbdLayoutOption};
16pub use window_rec_event::{
17 ActiveWindowEventData, NowSessionWindowRecEventMsg, OwnedActiveWindowEventData, OwnedNowSessionWindowRecEventMsg,
18 OwnedTitleChangedEventData, OwnedWindowRecEventKind, TitleChangedEventData, WindowRecEventKind,
19};
20pub use window_rec_start::{NowSessionWindowRecStartMsg, WindowRecStartFlags};
21pub use window_rec_stop::NowSessionWindowRecStopMsg;
22
23use crate::NowHeader;
24
25#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct NowSessionMessageKind(pub u8);
28
29impl NowSessionMessageKind {
30 pub const LOCK: Self = Self(0x01);
32 pub const LOGOFF: Self = Self(0x02);
34 pub const MSGBOX_REQ: Self = Self(0x03);
36 pub const MSGBOX_RSP: Self = Self(0x04);
38 pub const SET_KBD_LAYOUT: Self = Self(0x05);
40 pub const WINDOW_REC_START: Self = Self(0x06);
42 pub const WINDOW_REC_STOP: Self = Self(0x07);
44 pub const WINDOW_REC_EVENT: Self = Self(0x08);
46}
47
48#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum NowSessionMessage<'a> {
51 Lock(NowSessionLockMsg),
52 Logoff(NowSessionLogoffMsg),
53 MsgBoxReq(NowSessionMsgBoxReqMsg<'a>),
54 MsgBoxRsp(NowSessionMsgBoxRspMsg<'a>),
55 SetKbdLayout(NowSessionSetKbdLayoutMsg<'a>),
56 WindowRecStart(NowSessionWindowRecStartMsg),
57 WindowRecStop(NowSessionWindowRecStopMsg),
58 WindowRecEvent(NowSessionWindowRecEventMsg<'a>),
59}
60
61pub type OwnedNowSessionMessage = NowSessionMessage<'static>;
62
63impl IntoOwned for NowSessionMessage<'_> {
64 type Owned = OwnedNowSessionMessage;
65
66 fn into_owned(self) -> Self::Owned {
67 match self {
68 Self::Lock(msg) => OwnedNowSessionMessage::Lock(msg),
69 Self::Logoff(msg) => OwnedNowSessionMessage::Logoff(msg),
70 Self::MsgBoxReq(msg) => OwnedNowSessionMessage::MsgBoxReq(msg.into_owned()),
71 Self::MsgBoxRsp(msg) => OwnedNowSessionMessage::MsgBoxRsp(msg.into_owned()),
72 Self::SetKbdLayout(msg) => OwnedNowSessionMessage::SetKbdLayout(msg.into_owned()),
73 Self::WindowRecStart(msg) => OwnedNowSessionMessage::WindowRecStart(msg),
74 Self::WindowRecStop(msg) => OwnedNowSessionMessage::WindowRecStop(msg),
75 Self::WindowRecEvent(msg) => OwnedNowSessionMessage::WindowRecEvent(msg.into_owned()),
76 }
77 }
78}
79
80impl<'a> NowSessionMessage<'a> {
81 const NAME: &'static str = "NOW_SESSION_MSG";
82
83 pub fn decode_from_body(header: NowHeader, src: &mut ReadCursor<'a>) -> DecodeResult<Self> {
84 match NowSessionMessageKind(header.kind) {
85 NowSessionMessageKind::LOCK => Ok(Self::Lock(NowSessionLockMsg::default())),
86 NowSessionMessageKind::LOGOFF => Ok(Self::Logoff(NowSessionLogoffMsg::default())),
87 NowSessionMessageKind::MSGBOX_REQ => {
88 Ok(Self::MsgBoxReq(NowSessionMsgBoxReqMsg::decode_from_body(header, src)?))
89 }
90 NowSessionMessageKind::MSGBOX_RSP => {
91 Ok(Self::MsgBoxRsp(NowSessionMsgBoxRspMsg::decode_from_body(header, src)?))
92 }
93 NowSessionMessageKind::SET_KBD_LAYOUT => Ok(Self::SetKbdLayout(
94 NowSessionSetKbdLayoutMsg::decode_from_body(header, src)?,
95 )),
96 NowSessionMessageKind::WINDOW_REC_START => Ok(Self::WindowRecStart(
97 NowSessionWindowRecStartMsg::decode_from_body(header, src)?,
98 )),
99 NowSessionMessageKind::WINDOW_REC_STOP => Ok(Self::WindowRecStop(NowSessionWindowRecStopMsg::default())),
100 NowSessionMessageKind::WINDOW_REC_EVENT => Ok(Self::WindowRecEvent(
101 NowSessionWindowRecEventMsg::decode_from_body(header, src)?,
102 )),
103 _ => Err(unsupported_message_err!(class: header.class.0, kind: header.kind)),
104 }
105 }
106}
107
108impl Encode for NowSessionMessage<'_> {
109 fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
110 match self {
111 Self::Lock(msg) => msg.encode(dst),
112 Self::Logoff(msg) => msg.encode(dst),
113 Self::MsgBoxReq(msg) => msg.encode(dst),
114 Self::MsgBoxRsp(msg) => msg.encode(dst),
115 Self::SetKbdLayout(msg) => msg.encode(dst),
116 Self::WindowRecStart(msg) => msg.encode(dst),
117 Self::WindowRecStop(msg) => msg.encode(dst),
118 Self::WindowRecEvent(msg) => msg.encode(dst),
119 }
120 }
121
122 fn name(&self) -> &'static str {
123 Self::NAME
124 }
125
126 fn size(&self) -> usize {
127 match self {
128 Self::Lock(msg) => msg.size(),
129 Self::Logoff(msg) => msg.size(),
130 Self::MsgBoxReq(msg) => msg.size(),
131 Self::MsgBoxRsp(msg) => msg.size(),
132 Self::SetKbdLayout(msg) => msg.size(),
133 Self::WindowRecStart(msg) => msg.size(),
134 Self::WindowRecStop(msg) => msg.size(),
135 Self::WindowRecEvent(msg) => msg.size(),
136 }
137 }
138}