Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: check for additional lints #200

Merged
merged 14 commits into from
Oct 2, 2023
19 changes: 0 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semicolon-outside-block-ignore-multiline = true
9 changes: 5 additions & 4 deletions crates/ironrdp-acceptor/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl Sequence for Acceptor {
.optional_data
.early_capability_flags;

#[allow(clippy::arithmetic_side_effects)] // IO channel ID is not big enough for overflowing
let channels = settings_initial
.conference_create_request
.gcc_blocks
Expand All @@ -236,10 +237,10 @@ impl Sequence for Acceptor {
.channels
.into_iter()
.enumerate()
.map(|(i, c)| (i as u16 + self.io_channel_id + 1, c))
.map(|(i, c)| (u16::try_from(i).unwrap() + self.io_channel_id + 1, c))
.collect()
})
.unwrap_or(Vec::new());
.unwrap_or_default();

(
Written::Nothing,
Expand Down Expand Up @@ -400,8 +401,8 @@ impl Sequence for Acceptor {
monitors: vec![gcc::Monitor {
left: 0,
top: 0,
right: self.desktop_size.width as i32,
bottom: self.desktop_size.height as i32,
right: i32::from(self.desktop_size.width),
bottom: i32::from(self.desktop_size.height),
flags: gcc::MonitorFlags::PRIMARY,
}],
});
Expand Down
7 changes: 5 additions & 2 deletions crates/ironrdp-acceptor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ extern crate tracing;

use ironrdp_async::{Framed, FramedRead, FramedWrite, StreamWrapper};
use ironrdp_connector::{custom_err, ConnectorResult, Sequence, Written};
use ironrdp_pdu::write_buf::WriteBuf;

mod channel_connection;
mod connection;
mod finalization;
mod util;

pub use connection::{Acceptor, AcceptorResult};
pub use ironrdp_connector::DesktopSize;
use ironrdp_pdu::write_buf::WriteBuf;

pub use self::channel_connection::{ChannelConnectionSequence, ChannelConnectionState};
pub use self::connection::{Acceptor, AcceptorResult, AcceptorState};
pub use self::finalization::{FinalizationSequence, FinalizationState};

pub enum BeginResult<S>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/ironrdp-acceptor/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ironrdp_connector::{ConnectorError, ConnectorErrorExt, ConnectorResult};
use ironrdp_pdu::write_buf::WriteBuf;
use ironrdp_pdu::{rdp, PduParsing};

pub fn encode_send_data_indication<T>(
pub(crate) fn encode_send_data_indication<T>(
initiator_id: u16,
channel_id: u16,
user_msg: &T,
Expand All @@ -30,7 +30,7 @@ where
Ok(written)
}

pub fn wrap_share_data(pdu: rdp::headers::ShareDataPdu, io_channel_id: u16) -> rdp::headers::ShareControlHeader {
pub(crate) fn wrap_share_data(pdu: rdp::headers::ShareDataPdu, io_channel_id: u16) -> rdp::headers::ShareControlHeader {
rdp::headers::ShareControlHeader {
share_id: 0,
pdu_source: io_channel_id,
Expand Down
1 change: 0 additions & 1 deletion crates/ironrdp-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ bytes = "1"
ironrdp-connector.workspace = true
ironrdp-pdu.workspace = true
# ironrdp-session.workspace = true
tap = "1"
tracing.workspace = true
3 changes: 2 additions & 1 deletion crates/ironrdp-async/src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ where
if self.buf.len() >= length {
return Ok(self.buf.split_to(length));
} else {
self.buf.reserve(length - self.buf.len());
self.buf
.reserve(length.checked_sub(self.buf.len()).expect("length > self.buf.len()"));
}

let len = self.read().await?;
Expand Down
6 changes: 3 additions & 3 deletions crates/ironrdp-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod connector;
mod framed;
mod session;

pub use connector::*;
pub use framed::*;
pub use session::*;
pub use self::connector::*;
pub use self::framed::*;
// pub use self::session::*;
1 change: 0 additions & 1 deletion crates/ironrdp-blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ bytes = "1"
ironrdp-connector.workspace = true
ironrdp-pdu.workspace = true
# ironrdp-session.workspace = true
tap = "1"
tracing.workspace = true
3 changes: 2 additions & 1 deletion crates/ironrdp-blocking/src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ where
if self.buf.len() >= length {
return Ok(self.buf.split_to(length));
} else {
self.buf.reserve(length - self.buf.len());
self.buf
.reserve(length.checked_sub(self.buf.len()).expect("length > self.buf.len()"));
}

let len = self.read()?;
Expand Down
6 changes: 3 additions & 3 deletions crates/ironrdp-blocking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod connector;
mod framed;
mod session;

pub use connector::*;
pub use framed::*;
pub use session::*;
pub use self::connector::*;
pub use self::framed::*;
// pub use self::session::*;
3 changes: 0 additions & 3 deletions crates/ironrdp-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ ironrdp = { workspace = true, features = ["input", "graphics", "dvc", "rdpdr", "
ironrdp-cliprdr-native.workspace = true
ironrdp-tls.workspace = true
ironrdp-tokio.workspace = true
ironrdp-rdpsnd.workspace = true
ironrdp-rdpdr.workspace = true
sspi = { workspace = true, features = ["network_client", "dns_resolver"] } # enable additional features

# Windowing and rendering
Expand All @@ -53,7 +51,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1", features = ["full"]}

# Utils
chrono = "0.4"
whoami = "1.4"
anyhow = "1"
smallvec = "1.10"
Expand Down
20 changes: 16 additions & 4 deletions crates/ironrdp-client/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#![allow(clippy::print_stderr, clippy::print_stdout)] // allowed in this module only

use std::num::NonZeroU32;

use anyhow::Context as _;
use tokio::sync::mpsc;
use winit::dpi::LogicalPosition;
use winit::event::{self, Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy};
use winit::window::{Window, WindowBuilder};

use crate::rdp::{RdpInputEvent, RdpOutputEvent};

pub struct GuiContext {
pub window: Window,
pub event_loop: EventLoop<RdpOutputEvent>,
pub context: softbuffer::Context,
window: Window,
event_loop: EventLoop<RdpOutputEvent>,
context: softbuffer::Context,
}

impl GuiContext {
Expand All @@ -24,6 +26,7 @@ impl GuiContext {
.build(&event_loop)
.context("unable to create winit Window")?;

// SAFETY: both the context and the window are held by the GuiContext
let context = unsafe { softbuffer::Context::new(&window) }
.map_err(|e| anyhow::Error::msg(format!("unable to initialize softbuffer context: {e}")))?;

Expand All @@ -34,13 +37,22 @@ impl GuiContext {
})
}

pub fn window(&self) -> &Window {
&self.window
}

pub fn create_event_proxy(&self) -> EventLoopProxy<RdpOutputEvent> {
self.event_loop.create_proxy()
}

pub fn run(self, input_event_sender: mpsc::UnboundedSender<RdpInputEvent>) -> ! {
let Self {
window,
event_loop,
context,
} = self;

// SAFETY: both the context and the window are kept alive until the end of this function’s scope
let mut surface = unsafe { softbuffer::Surface::new(&context, &window) }.expect("surface");

let mut input_database = ironrdp::input::Database::new();
Expand Down
9 changes: 9 additions & 0 deletions crates/ironrdp-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#![allow(unused_crate_dependencies)] // false positives because there is both a library and a binary

// No need to be as strict as in production libraries
#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::cast_lossless)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_possible_wrap)]
#![allow(clippy::cast_sign_loss)]

#[macro_use]
extern crate tracing;

Expand Down
6 changes: 4 additions & 2 deletions crates/ironrdp-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_crate_dependencies)] // false positives because there is both a library and a binary

#[macro_use]
extern crate tracing;

Expand All @@ -16,11 +18,11 @@ fn main() -> anyhow::Result<()> {
let gui = GuiContext::init().context("unable to initialize GUI context")?;
debug!("GUI context initialized");

let window_size = gui.window.inner_size();
let window_size = gui.window().inner_size();
config.connector.desktop_size.width = u16::try_from(window_size.width).unwrap();
config.connector.desktop_size.height = u16::try_from(window_size.height).unwrap();

let event_loop_proxy = gui.event_loop.create_proxy();
let event_loop_proxy = gui.create_event_proxy();

let rt = runtime::Builder::new_multi_thread()
.enable_all()
Expand Down
9 changes: 4 additions & 5 deletions crates/ironrdp-client/src/rdp.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use ironrdp::cliprdr::backend::{ClipboardMessage, CliprdrBackendFactory};
use ironrdp::cliprdr::Cliprdr;
use ironrdp::connector::sspi::network_client::reqwest_network_client::RequestClientFactory;
use ironrdp::connector::{ConnectionResult, ConnectorResult};
use ironrdp::graphics::image_processing::PixelFormat;
use ironrdp::pdu::input::fast_path::FastPathInputEvent;
use ironrdp::session::image::DecodedImage;
use ironrdp::session::{ActiveStage, ActiveStageOutput, SessionResult};
use ironrdp::{connector, session};
use ironrdp::{cliprdr, connector, rdpdr, rdpsnd, session};
use smallvec::SmallVec;
use tokio::net::TcpStream;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -108,13 +107,13 @@ async fn connect(
.with_server_name(&config.destination)
.with_credssp_network_client(RequestClientFactory)
// .with_static_channel(ironrdp::dvc::Drdynvc::new()) // FIXME: drdynvc is not working
.with_static_channel(ironrdp::rdpsnd::Rdpsnd::new())
.with_static_channel(ironrdp_rdpdr::Rdpdr::new("IronRDP".to_string()).with_smartcard(0));
.with_static_channel(rdpsnd::Rdpsnd::new())
.with_static_channel(rdpdr::Rdpdr::new("IronRDP".to_owned()).with_smartcard(0));

if let Some(builder) = cliprdr_factory {
let backend = builder.build_cliprdr_backend();

let cliprdr = Cliprdr::new(backend);
let cliprdr = cliprdr::Cliprdr::new(backend);

connector.attach_static_channel(cliprdr);
}
Expand Down
5 changes: 1 addition & 4 deletions crates/ironrdp-cliprdr-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ categories.workspace = true
doctest = false
test = false

[dependencies]
[target.'cfg(windows)'.dependencies]
ironrdp-cliprdr.workspace = true
ironrdp-svc.workspace = true
thiserror.workspace = true
tracing.workspace = true

[target.'cfg(windows)'.dependencies]

windows = { version = "0.48.0", features = [
"Win32_Foundation",
"Win32_System_DataExchange",
Expand Down
3 changes: 1 addition & 2 deletions crates/ironrdp-cliprdr-native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#![warn(clippy::as_ptr_cast_mut)]
#![warn(clippy::cast_ptr_alignment)]
#![warn(clippy::fn_to_numeric_cast_any)]
// TODO(@pacmancoder): Enable after toolchain update
// #![warn(clippy::ptr_cast_constness)]
#![warn(clippy::ptr_cast_constness)]

#[cfg(windows)]
mod windows;
Expand Down
Loading
Loading