flep_protocol/command/
mod.rs1pub use self::port::PORT;
2pub use self::mode::{MODE, Mode};
3pub use self::basic::{ABOR, CDUP, EPSV, FEAT, NOOP, PASV, PWD,
4 QUIT, REIN, STOU, SYST};
5pub use self::misc::{ACCT, APPE, CWD, DELE, HELP, LIST, MDTM, MKD, NLST,
6 RETR, RMD, RNFR, RNTO, SITE, SIZE, STAT, STOR, TYPE,
7 USER, PASS};
8pub use self::security::{ADAT, AUTH, CCC, CONF, ENC, MIC, PBSZ, PROT};
9pub use self::unimplemented::*;
10
11#[macro_use]
12pub mod macros;
13pub mod port;
14pub mod mode;
15pub mod basic;
17pub mod misc;
18pub mod security;
19pub mod unimplemented;
20
21use Error;
22use std::io::prelude::*;
23use std::{io, fmt};
24
25pub trait Command : Clone + fmt::Debug + PartialEq + Eq
27{
28 fn write(&self, write: &mut Write) -> Result<(), Error> {
30 let mut payload_buffer = io::Cursor::new(Vec::new());
32 self.write_payload(&mut payload_buffer)?;
33 let payload = payload_buffer.into_inner();
34
35 if payload.is_empty() {
37 write!(write, "{}", self.command_name())?;
38 } else {
39 write!(write, "{} ", self.command_name())?;
40 write.write(&payload)?;
41 }
42
43 Ok(())
44 }
45
46 fn write_payload(&self, write: &mut Write) -> Result<(), Error>;
48
49 fn read_payload(read: &mut BufRead) -> Result<Self, Error>;
51
52 fn command_name(&self) -> &'static str;
54
55 fn bytes(&self) -> Vec<u8> {
56 let mut buffer = io::Cursor::new(Vec::new());
57 self.write(&mut buffer).expect("IO failure while writing to memory buffer");
58 buffer.into_inner()
59 }
60
61 fn to_string(&self) -> String {
63 String::from_utf8(self.bytes()).unwrap()
64 }
65}