forked from bolcom/libunftp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stor.rs
55 lines (52 loc) · 1.91 KB
/
stor.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! The RFC 959 Store (`STOR`) command
//
// This command causes the server-DTP to accept the data
// transferred via the data connection and to store the data as
// a file at the server site. If the file specified in the
// pathname exists at the server site, then its contents shall
// be replaced by the data being transferred. A new file is
// created at the server site if the file specified in the
// pathname does not already exist.
use crate::server::chancomms::DataChanCmd;
use crate::{
auth::UserDetail,
server::controlchan::{
command::Command,
error::ControlChanError,
handler::{CommandContext, CommandHandler},
Reply, ReplyCode,
},
storage::{Metadata, StorageBackend},
};
use async_trait::async_trait;
use futures::prelude::*;
#[derive(Debug)]
pub struct Stor;
#[async_trait]
impl<Storage, User> CommandHandler<Storage, User> for Stor
where
User: UserDetail + 'static,
Storage: StorageBackend<User> + 'static,
Storage::Metadata: Metadata,
{
#[tracing_attributes::instrument]
async fn handle(&self, args: CommandContext<Storage, User>) -> Result<Reply, ControlChanError> {
let mut session = args.session.lock().await;
let cmd: DataChanCmd = match args.parsed_command.clone() {
Command::Stor { path } => DataChanCmd::Stor { path },
_ => panic!("Programmer error, expected command to be STOR"),
};
let logger = args.logger;
match session.data_cmd_tx.take() {
Some(mut tx) => {
tokio::spawn(async move {
if let Err(err) = tx.send(cmd).await {
slog::warn!(logger, "{}", err);
}
});
Ok(Reply::new(ReplyCode::FileStatusOkay, "Ready to receive data"))
}
None => Ok(Reply::new(ReplyCode::CantOpenDataConnection, "No data connection established")),
}
}
}