mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-08-03 06:42:16 +00:00
feat(tokio): add reqwest feature (#734)
Move the client ReqwestNetworkClient to ironrdp-tokio, so other clients can optionally use the implementation. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
817abb9805
commit
032c38be92
8 changed files with 41 additions and 18 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -2432,16 +2432,13 @@ dependencies = [
|
|||
"ironrdp-tokio",
|
||||
"proc-exit",
|
||||
"raw-window-handle",
|
||||
"reqwest",
|
||||
"semver",
|
||||
"smallvec",
|
||||
"softbuffer",
|
||||
"sspi",
|
||||
"tap",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
"uuid",
|
||||
"whoami",
|
||||
"windows 0.58.0",
|
||||
|
@ -2783,7 +2780,10 @@ version = "0.3.0"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"ironrdp-async",
|
||||
"reqwest",
|
||||
"sspi",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -13,6 +13,7 @@ mod session;
|
|||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
|
||||
pub use ironrdp_connector;
|
||||
use ironrdp_connector::sspi::generator::NetworkRequest;
|
||||
use ironrdp_connector::ConnectorResult;
|
||||
|
||||
|
|
|
@ -40,14 +40,17 @@ ironrdp = { path = "../ironrdp", version = "0.9", features = [
|
|||
"rdpsnd",
|
||||
"cliprdr",
|
||||
"displaycontrol",
|
||||
"connector"
|
||||
"connector",
|
||||
] }
|
||||
ironrdp-core = { path = "../ironrdp-core", version = "0.1", features = [
|
||||
"alloc",
|
||||
] }
|
||||
ironrdp-core = { path = "../ironrdp-core", version = "0.1", features = ["alloc"] }
|
||||
ironrdp-cliprdr-native = { path = "../ironrdp-cliprdr-native", version = "0.2" }
|
||||
ironrdp-rdpsnd-native = { path = "../ironrdp-rdpsnd-native", version = "0.2" }
|
||||
ironrdp-tls = { path = "../ironrdp-tls", version = "0.1" }
|
||||
ironrdp-tokio = { path = "../ironrdp-tokio", version = "0.3" }
|
||||
sspi = { version = "0.15", features = ["network_client", "dns_resolver"] } # TODO: enable additional features
|
||||
ironrdp-tokio = { path = "../ironrdp-tokio", version = "0.3", features = [
|
||||
"reqwest",
|
||||
] }
|
||||
|
||||
# Windowing and rendering
|
||||
winit = { version = "0.30", features = ["rwh_06"] }
|
||||
|
@ -71,8 +74,6 @@ anyhow = "1"
|
|||
smallvec = "1.13"
|
||||
tap = "1"
|
||||
semver = "1"
|
||||
reqwest = "0.12"
|
||||
url = "2.5"
|
||||
raw-window-handle = "0.6"
|
||||
uuid = { version = "1.16" }
|
||||
|
||||
|
|
|
@ -15,5 +15,4 @@ extern crate tracing;
|
|||
pub mod app;
|
||||
pub mod clipboard;
|
||||
pub mod config;
|
||||
pub mod network_client;
|
||||
pub mod rdp;
|
||||
|
|
|
@ -10,6 +10,7 @@ use ironrdp::session::{fast_path, ActiveStage, ActiveStageOutput, GracefulDiscon
|
|||
use ironrdp::{cliprdr, connector, rdpdr, rdpsnd, session};
|
||||
use ironrdp_core::WriteBuf;
|
||||
use ironrdp_rdpsnd_native::cpal;
|
||||
use ironrdp_tokio::reqwest::ReqwestNetworkClient;
|
||||
use ironrdp_tokio::{single_sequence_step_read, split_tokio_framed, FramedWrite};
|
||||
use rdpdr::NoopRdpdrBackend;
|
||||
use smallvec::SmallVec;
|
||||
|
@ -146,7 +147,7 @@ async fn connect(
|
|||
|
||||
let mut upgraded_framed = ironrdp_tokio::TokioFramed::new(upgraded_stream);
|
||||
|
||||
let mut network_client = crate::network_client::ReqwestNetworkClient::new();
|
||||
let mut network_client = ReqwestNetworkClient::new();
|
||||
let connection_result = ironrdp_tokio::connect_finalize(
|
||||
upgraded,
|
||||
&mut upgraded_framed,
|
||||
|
|
|
@ -15,11 +15,20 @@ categories.workspace = true
|
|||
doctest = false
|
||||
test = false
|
||||
|
||||
[features]
|
||||
default = ["reqwest"]
|
||||
reqwest = ["dep:reqwest", "dep:sspi", "dep:url"]
|
||||
|
||||
[dependencies]
|
||||
bytes = "1"
|
||||
ironrdp-async = { path = "../ironrdp-async", version = "0.4" } # public
|
||||
tokio = { version = "1", features = ["io-util"] }
|
||||
reqwest = { version = "0.12", optional = true }
|
||||
sspi = { version = "0.15", features = [
|
||||
"network_client",
|
||||
"dns_resolver",
|
||||
], optional = true } # TODO: enable additional features
|
||||
url = { version = "2.5", optional = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#[rustfmt::skip] // do not re-order this pub use
|
||||
pub use ironrdp_async::*;
|
||||
|
||||
#[cfg(feature = "reqwest")]
|
||||
pub mod reqwest;
|
||||
|
||||
use core::pin::Pin;
|
||||
use std::io;
|
||||
|
||||
|
|
|
@ -2,15 +2,16 @@ use core::future::Future;
|
|||
use core::pin::Pin;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
|
||||
use ironrdp::connector::{custom_err, ConnectorResult};
|
||||
use ironrdp_tokio::AsyncNetworkClient;
|
||||
use ironrdp_async::ironrdp_connector::{custom_err, ConnectorResult};
|
||||
use reqwest::Client;
|
||||
use sspi::{Error, ErrorKind};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::{TcpStream, UdpSocket};
|
||||
use url::Url;
|
||||
|
||||
pub(crate) struct ReqwestNetworkClient {
|
||||
use crate::AsyncNetworkClient;
|
||||
|
||||
pub struct ReqwestNetworkClient {
|
||||
client: Option<Client>,
|
||||
}
|
||||
|
||||
|
@ -32,11 +33,17 @@ impl AsyncNetworkClient for ReqwestNetworkClient {
|
|||
}
|
||||
|
||||
impl ReqwestNetworkClient {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self { client: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ReqwestNetworkClient {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ReqwestNetworkClient {
|
||||
async fn send_tcp(&self, url: &Url, data: &[u8]) -> ConnectorResult<Vec<u8>> {
|
||||
let addr = format!("{}:{}", url.host_str().unwrap_or_default(), url.port().unwrap_or(88));
|
||||
|
@ -89,10 +96,12 @@ impl ReqwestNetworkClient {
|
|||
.recv(&mut buf)
|
||||
.await
|
||||
.map_err(|e| custom_err!("failed to receive UDP request", e))?;
|
||||
let buf = &buf[0..n];
|
||||
|
||||
let mut reply_buf = Vec::with_capacity(n + 4);
|
||||
reply_buf.extend_from_slice(&(n as u32).to_be_bytes());
|
||||
reply_buf.extend_from_slice(&buf[0..n]);
|
||||
let n = u32::try_from(n).map_err(|e| custom_err!("invalid length", e))?;
|
||||
reply_buf.extend_from_slice(&n.to_be_bytes());
|
||||
reply_buf.extend_from_slice(buf);
|
||||
|
||||
Ok(reply_buf)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue