telnet: apply rustfmt to parse_request

When we want to share our code in our documentation pages, the current
rust formatting isn't so nice to read. Formatted just the portion of
the code that will be shown, for now.
pull/7013/head
Juliana Fajardini 4 years ago committed by Victor Julien
parent 8adf172ab8
commit 71cbd2bf0e

@ -141,7 +141,9 @@ impl TelnetState {
None
}
fn parse_request(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8]) -> AppLayerResult {
fn parse_request(
&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8],
) -> AppLayerResult {
// We're not interested in empty requests.
if input.len() == 0 {
return AppLayerResult::ok();
@ -163,14 +165,32 @@ impl TelnetState {
let mut start = input;
while start.len() > 0 {
if self.request_frame.is_none() {
self.request_frame = Frame::new_ts(flow, stream_slice, start, -1 as i64, TelnetFrameType::Pdu as u8);
self.request_frame = Frame::new_ts(
flow,
stream_slice,
start,
-1 as i64,
TelnetFrameType::Pdu as u8,
);
}
if self.request_specific_frame.is_none() {
if let Ok((_, is_ctl)) = parser::peek_message_is_ctl(start) {
let f = if is_ctl {
Frame::new_ts(flow, stream_slice, start, -1 as i64, TelnetFrameType::Ctl as u8)
Frame::new_ts(
flow,
stream_slice,
start,
-1 as i64,
TelnetFrameType::Ctl as u8,
)
} else {
Frame::new_ts(flow, stream_slice, start, -1 as i64, TelnetFrameType::Data as u8)
Frame::new_ts(
flow,
stream_slice,
start,
-1 as i64,
TelnetFrameType::Data as u8,
)
};
self.request_specific_frame = f;
}
@ -178,7 +198,9 @@ impl TelnetState {
match parser::parse_message(start) {
Ok((rem, request)) => {
let consumed = start.len() - rem.len();
if rem.len() == start.len() { panic!("lockup"); }
if rem.len() == start.len() {
panic!("lockup");
}
start = rem;
if let Some(frame) = &self.request_frame {
@ -194,22 +216,22 @@ impl TelnetState {
match self.state {
TelnetProtocolState::LoginSent => {
self.state = TelnetProtocolState::LoginRecv;
},
}
TelnetProtocolState::PasswdSent => {
self.state = TelnetProtocolState::PasswdRecv;
},
}
TelnetProtocolState::AuthOk => {
let _message = std::str::from_utf8(&d);
if let Ok(_message) = _message {
SCLogDebug!("=> {}", _message);
}
},
_ => {},
}
_ => {}
}
} else if let parser::TelnetMessageType::Control(_c) = request {
SCLogDebug!("request {:?}", _c);
}
},
}
Err(nom7::Err::Incomplete(_)) => {
// Not enough data. This parser doesn't give us a good indication
// of how much data is missing so just ask for one more byte so the
@ -217,10 +239,10 @@ impl TelnetState {
let consumed = input.len() - start.len();
let needed = start.len() + 1;
return AppLayerResult::incomplete(consumed as u32, needed as u32);
},
}
Err(_) => {
return AppLayerResult::err();
},
}
}
}

Loading…
Cancel
Save