mqtt: run rustfmt

pull/11454/head
Sascha Steinbiss 2 years ago committed by Victor Julien
parent ad02040860
commit e047ad25e2

@ -562,7 +562,9 @@ impl JsonBuilder {
}
/// Set a key and a string value (from bytes) on an object, with a limited size
pub fn set_string_from_bytes_limited(&mut self, key: &str, val: &[u8], limit: usize) -> Result<&mut Self, JsonError> {
pub fn set_string_from_bytes_limited(
&mut self, key: &str, val: &[u8], limit: usize,
) -> Result<&mut Self, JsonError> {
let mut valtrunc = Vec::new();
let val = if val.len() > limit {
let additional_bytes = val.len() - limit;
@ -723,12 +725,12 @@ impl JsonBuilder {
}
fn push_float(&mut self, val: f64) -> Result<(), JsonError> {
if val.is_nan() || val.is_infinite() {
self.push_str("null")?;
} else {
self.push_str(&val.to_string())?;
}
Ok(())
if val.is_nan() || val.is_infinite() {
self.push_str("null")?;
} else {
self.push_str(&val.to_string())?;
}
Ok(())
}
/// Encode a string into the buffer, escaping as needed.

@ -410,28 +410,31 @@ pub extern "C" fn rs_mqtt_tx_unsuback_has_reason_code(tx: &MQTTTransaction, code
#[cfg(test)]
mod test {
use super::*;
use crate::core::Direction;
use crate::mqtt::mqtt::MQTTTransaction;
use crate::mqtt::mqtt_message::*;
use crate::mqtt::parser::FixedHeader;
use crate::core::Direction;
use std;
#[test]
fn test_multi_unsubscribe() {
let mut t = MQTTTransaction::new(MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::UNSUBSCRIBE,
dup_flag: false,
qos_level: 0,
retain: false,
remaining_length: 0,
let mut t = MQTTTransaction::new(
MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::UNSUBSCRIBE,
dup_flag: false,
qos_level: 0,
retain: false,
remaining_length: 0,
},
op: MQTTOperation::UNSUBSCRIBE(MQTTUnsubscribeData {
message_id: 1,
topics: vec!["foo".to_string(), "baar".to_string()],
properties: None,
}),
},
op: MQTTOperation::UNSUBSCRIBE(MQTTUnsubscribeData {
message_id: 1,
topics: vec!["foo".to_string(), "baar".to_string()],
properties: None,
}),
}, Direction::ToServer);
Direction::ToServer,
);
t.msg.push(MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::UNSUBSCRIBE,
@ -470,29 +473,32 @@ mod test {
#[test]
fn test_multi_subscribe() {
let mut t = MQTTTransaction::new(MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::SUBSCRIBE,
dup_flag: false,
qos_level: 0,
retain: false,
remaining_length: 0,
let mut t = MQTTTransaction::new(
MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::SUBSCRIBE,
dup_flag: false,
qos_level: 0,
retain: false,
remaining_length: 0,
},
op: MQTTOperation::SUBSCRIBE(MQTTSubscribeData {
message_id: 1,
topics: vec![
MQTTSubscribeTopicData {
topic_name: "foo".to_string(),
qos: 0,
},
MQTTSubscribeTopicData {
topic_name: "baar".to_string(),
qos: 1,
},
],
properties: None,
}),
},
op: MQTTOperation::SUBSCRIBE(MQTTSubscribeData {
message_id: 1,
topics: vec![
MQTTSubscribeTopicData {
topic_name: "foo".to_string(),
qos: 0,
},
MQTTSubscribeTopicData {
topic_name: "baar".to_string(),
qos: 1,
},
],
properties: None,
}),
}, Direction::ToServer);
Direction::ToServer,
);
t.msg.push(MQTTMessage {
header: FixedHeader {
message_type: MQTTTypeCode::SUBSCRIBE,

@ -26,7 +26,9 @@ use std;
pub const MQTT_LOG_PASSWORDS: u32 = BIT_U32!(0);
#[inline]
fn log_mqtt_topic(js: &mut JsonBuilder, t: &MQTTSubscribeTopicData, max_log_len: usize ) -> Result<(), JsonError> {
fn log_mqtt_topic(
js: &mut JsonBuilder, t: &MQTTSubscribeTopicData, max_log_len: usize,
) -> Result<(), JsonError> {
js.start_object()?;
js.set_string_limited("topic", &t.topic_name, max_log_len)?;
js.set_uint("qos", t.qos as u64)?;

@ -142,7 +142,7 @@ impl MQTTState {
connected: false,
skip_request: 0,
skip_response: 0,
max_msg_len: unsafe { MAX_MSG_LEN},
max_msg_len: unsafe { MAX_MSG_LEN },
tx_index_completed: 0,
}
}
@ -597,7 +597,14 @@ impl MQTTState {
) {
let hdr = stream_slice.as_slice();
//MQTT payload has a fixed header of 2 bytes
let _mqtt_hdr = Frame::new(flow, stream_slice, hdr, 2, MQTTFrameType::Header as u8, None);
let _mqtt_hdr = Frame::new(
flow,
stream_slice,
hdr,
2,
MQTTFrameType::Header as u8,
None,
);
SCLogDebug!("mqtt_hdr Frame {:?}", _mqtt_hdr);
let rem_length = input.header.remaining_length as usize;
let data = &hdr[2..rem_length + 2];

@ -242,8 +242,7 @@ fn parse_connack(protocol_version: u8) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTC
#[inline]
fn parse_publish(
protocol_version: u8,
has_id: bool,
protocol_version: u8, has_id: bool,
) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTPublishData> {
move |i: &[u8]| {
let (i, topic) = parse_mqtt_string(i)?;
@ -414,8 +413,7 @@ fn parse_unsuback(protocol_version: u8) -> impl Fn(&[u8]) -> IResult<&[u8], MQTT
#[inline]
fn parse_disconnect(
remaining_len: usize,
protocol_version: u8,
remaining_len: usize, protocol_version: u8,
) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTDisconnectData> {
move |input: &[u8]| {
if protocol_version < 5 {
@ -486,11 +484,7 @@ fn parse_auth(i: &[u8]) -> IResult<&[u8], MQTTAuthData> {
#[inline]
fn parse_remaining_message<'a>(
full: &'a [u8],
len: usize,
skiplen: usize,
header: FixedHeader,
message_type: MQTTTypeCode,
full: &'a [u8], len: usize, skiplen: usize, header: FixedHeader, message_type: MQTTTypeCode,
protocol_version: u8,
) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], MQTTMessage> {
move |input: &'a [u8]| {
@ -632,9 +626,7 @@ fn parse_remaining_message<'a>(
}
pub fn parse_message(
input: &[u8],
protocol_version: u8,
max_msg_size: u32,
input: &[u8], protocol_version: u8, max_msg_size: u32,
) -> IResult<&[u8], MQTTMessage> {
// Parse the fixed header first. This is identical across versions and can
// be between 2 and 5 bytes long.
@ -939,7 +931,7 @@ mod tests {
#[test]
fn test_parse_msgidonly_v5() {
let buf = [
0x00, 0x01, /* Message Identifier: 1 */
0x00, 0x01, /* Message Identifier: 1 */
0x00, /* Reason Code: 0 */
0x00, /* Properties */
0x00, 0x61, 0x75, 0x74, 0x6f, 0x2d, 0x42, 0x34, 0x33, 0x45, 0x38, 0x30,

Loading…
Cancel
Save