use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use crate::proto::header::{Command, Smb2Header};
use crate::conn::pending::AsyncOp;
use crate::conn::state::Connection;
use crate::dispatch::HandlerResponse;
use crate::ntstatus;
use crate::server::ServerState;
mod aapl;
mod change_notify;
mod close;
mod copy;
pub(crate) mod create;
mod echo;
mod flush;
mod ioctl;
mod lock;
mod logoff;
pub(crate) mod negotiate;
mod oplock_break;
mod pipe;
mod query_directory;
mod query_info;
mod read;
mod reconnect;
mod session_setup;
mod set_info;
pub(crate) mod shared;
mod tree_connect;
mod tree_disconnect;
mod write;
pub(crate) use pipe::pipes;
pub(crate) enum Outcome {
Done(HandlerResponse),
Pending(Pending),
}
pub(crate) struct Pending {
pub op: Arc<AsyncOp>,
pub work: Pin<Box<dyn Future<Output = HandlerResponse> + Send>>,
}
pub(crate) async fn dispatch_command(
server: &Arc<ServerState>,
conn: &Arc<Connection>,
hdr: &Smb2Header,
body: &[u8],
encrypted: bool,
retained: usize,
) -> Outcome {
if let Some(outcome) = pipe::route(server, conn, hdr, body, retained).await {
return outcome;
}
let response = match hdr.command {
Command::Create => return create::handle(server, conn, hdr, body, retained).await,
Command::SetInfo => return set_info::handle(server, conn, hdr, body, retained).await,
Command::ChangeNotify => {
return change_notify::handle(server, conn, hdr, body, retained).await;
}
Command::Ioctl => return ioctl::handle(server, conn, hdr, body, retained).await,
Command::Negotiate => negotiate::handle(server, conn, hdr, body).await,
Command::SessionSetup => session_setup::handle(server, conn, hdr, body).await,
Command::Logoff => logoff::handle(server, conn, hdr, body).await,
Command::TreeConnect => tree_connect::handle(server, conn, hdr, body, encrypted).await,
Command::TreeDisconnect => tree_disconnect::handle(server, conn, hdr, body).await,
Command::Close => close::handle(server, conn, hdr, body).await,
Command::Flush => flush::handle(server, conn, hdr, body).await,
Command::Read => read::handle(server, conn, hdr, body).await,
Command::Write => write::handle(server, conn, hdr, body).await,
Command::Lock => lock::handle(server, conn, hdr, body).await,
Command::Echo => echo::handle(server, conn, hdr, body).await,
Command::QueryDirectory => query_directory::handle(server, conn, hdr, body).await,
Command::QueryInfo => query_info::handle(server, conn, hdr, body).await,
Command::OplockBreak => oplock_break::handle(server, conn, hdr, body).await,
Command::Cancel => HandlerResponse::err(ntstatus::STATUS_INVALID_PARAMETER),
};
Outcome::Done(response)
}