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
//! The RFC 2389 Options (`OPTS`) command
//
// The OPTS (options) command allows a user-PI to specify the desired
// behavior of a server-FTP process when another FTP command (the target
// command) is later issued. The exact behavior, and syntax, will vary
// with the target command indicated, and will be specified with the
// definition of that command. Where no OPTS behavior is defined for a
// particular command there are no options available for that command.
use crate::server::commands::Cmd;
use crate::server::error::FTPError;
use crate::server::reply::{Reply, ReplyCode};
use crate::server::CommandArgs;
use crate::storage;
/// The parameters that can be given to the `OPTS` command, specifying the option the client wants
/// to set.
#[derive(Debug, PartialEq, Clone)]
pub enum Opt {
/// The client wants us to enable UTF-8 encoding for file paths and such.
UTF8 { on: bool },
}
pub struct Opts {
option: Opt,
}
impl Opts {
pub fn new(option: Opt) -> Self {
Opts { option }
}
}
impl<S, U> Cmd<S, U> for Opts
where
U: Send + Sync + 'static,
S: 'static + storage::StorageBackend<U> + Sync + Send,
S::File: tokio_io::AsyncRead + Send,
S::Metadata: storage::Metadata,
{
fn execute(&self, _args: &CommandArgs<S, U>) -> Result<Reply, FTPError> {
match &self.option {
Opt::UTF8 { on: true } => Ok(Reply::new(ReplyCode::FileActionOkay, "Always in UTF-8 mode.")),
Opt::UTF8 { on: false } => Ok(Reply::new(ReplyCode::CommandNotImplementedForParameter, "Non UTF-8 mode not supported")),
}
}
}