flep_protocol/command/
basic.rs

1/// Defines a packet which takes no arguments.
2macro_rules! define_basic_command {
3    ($name:ident, $module_name:ident) => {
4        pub use self::$module_name::$name;
5
6        pub mod $module_name {
7            use Command;
8            use std::io::prelude::*;
9
10            #[derive(Clone, Debug, PartialEq, Eq)]
11            pub struct $name;
12
13            impl Command for $name
14            {
15                fn write_payload(&self, _: &mut Write) -> Result<(), $crate::Error> { Ok(()) }
16                fn read_payload(_: &mut BufRead) -> Result<Self, $crate::Error> { Ok($name) }
17
18                fn command_name(&self) -> &'static str { stringify!($name) }
19            }
20
21            #[cfg(test)]
22            mod test
23            {
24                use super::*;
25                use {Command, CommandKind};
26                use std::io;
27
28                #[test]
29                fn correctly_writes_basic_packets() {
30                    let packet = $name;
31                    let raw_bytes = packet.bytes();
32                    let text = String::from_utf8(raw_bytes).unwrap();
33
34                    assert_eq!(text, stringify!($name));
35                }
36
37                #[test]
38                fn correctly_reads_basic_packets() {
39                    let raw_text = format!("{}\r\n", stringify!($name));
40                    let command = CommandKind::read(&mut io::Cursor::new(raw_text.as_bytes().to_vec())).unwrap();
41
42                    assert_eq!(command, CommandKind::$name($name));
43                }
44            }
45        }
46    }
47}
48
49// Abort the current file transfer.
50define_basic_command!(ABOR, abor);
51// Change directory up one level.
52define_basic_command!(CDUP, cdup);
53// Get the feature list implemented by the server.
54define_basic_command!(FEAT, feat);
55// Extended passive mode.
56define_basic_command!(EPSV, epsv);
57// A no-operation.
58define_basic_command!(NOOP, noop);
59// Enable passive mode.
60define_basic_command!(PASV, pasv);
61// Gets the name of the current working directory on the remote host.
62define_basic_command!(PWD, pwd);
63// Terminates the command connection.
64define_basic_command!(QUIT, quit);
65// Reinitializes the command connectio.
66define_basic_command!(REIN, rein);
67// Begins transmission of a file to the remote site.
68define_basic_command!(STOU, stou);
69// Returns a word identifying the system.
70define_basic_command!(SYST, syst);