]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: rustfmt
authorPhilippe Antoine <pantoine@oisf.net>
Tue, 12 Dec 2023 13:32:26 +0000 (14:32 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 20 Jul 2024 08:37:58 +0000 (10:37 +0200)
rust/src/http2/decompression.rs
rust/src/http2/detect.rs
rust/src/http2/http2.rs
rust/src/http2/logger.rs
rust/src/http2/parser.rs
rust/src/http2/range.rs

index 99f8af39032ca3710e73b61f6a3477293e5a162e..31e8547a8134b85bf50bdb6f62cc7b47367efba0 100644 (file)
@@ -178,10 +178,12 @@ impl HTTP2DecoderHalf {
         if self.encoding == HTTP2ContentEncoding::Unknown {
             if input == b"gzip" {
                 self.encoding = HTTP2ContentEncoding::Gzip;
-                self.decoder = HTTP2Decompresser::Gzip(Box::new(GzDecoder::new(HTTP2cursor::new())));
+                self.decoder =
+                    HTTP2Decompresser::Gzip(Box::new(GzDecoder::new(HTTP2cursor::new())));
             } else if input == b"deflate" {
                 self.encoding = HTTP2ContentEncoding::Deflate;
-                self.decoder = HTTP2Decompresser::Deflate(Box::new(DeflateDecoder::new(HTTP2cursor::new())));
+                self.decoder =
+                    HTTP2Decompresser::Deflate(Box::new(DeflateDecoder::new(HTTP2cursor::new())));
             } else if input == b"br" {
                 self.encoding = HTTP2ContentEncoding::Br;
                 self.decoder = HTTP2Decompresser::Brotli(Box::new(brotli::Decompressor::new(
index 1879ac69d5ac18e28dcc74ef1d0f1ae4344355cb..7354d270da2696f9c76231d1342ec0304a1bd733 100644 (file)
@@ -538,7 +538,7 @@ fn http2_tx_get_resp_line(tx: &mut HTTP2Transaction) {
         return;
     }
     let empty = Vec::new();
-    let mut resp_line : Vec<u8> = Vec::new();
+    let mut resp_line: Vec<u8> = Vec::new();
 
     let status =
         if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToClient, ":status") {
@@ -617,7 +617,7 @@ fn http2_lower(value: &[u8]) -> Option<Vec<u8>> {
 fn http2_normalize_host(value: &[u8]) -> &[u8] {
     match value.iter().position(|&x| x == b'@') {
         Some(i) => {
-            let value = &value[i+1..];
+            let value = &value[i + 1..];
             match value.iter().position(|&x| x == b':') {
                 Some(i) => {
                     return &value[..i];
@@ -627,16 +627,14 @@ fn http2_normalize_host(value: &[u8]) -> &[u8] {
                 }
             }
         }
-        None => {
-            match value.iter().position(|&x| x == b':') {
-                Some(i) => {
-                    return &value[..i];
-                }
-                None => {
-                    return value;
-                }
+        None => match value.iter().position(|&x| x == b':') {
+            Some(i) => {
+                return &value[..i];
             }
-        }
+            None => {
+                return value;
+            }
+        },
     }
 }
 
index 2e41c2967aa7c34e11cf567d32955899b2ccd11b..98c760453cc5661441ef7fabb49c8ccf04273d58 100644 (file)
@@ -186,13 +186,13 @@ impl HTTP2Transaction {
                 if let Some(sfcm) = unsafe { SURICATA_HTTP2_FILE_CONFIG } {
                     //TODO get a file container instead of NULL
                     (c.HTPFileCloseHandleRange)(
-                            sfcm.files_sbcfg,
-                            std::ptr::null_mut(),
-                            0,
-                            self.file_range,
-                            std::ptr::null_mut(),
-                            0,
-                            );
+                        sfcm.files_sbcfg,
+                        std::ptr::null_mut(),
+                        0,
+                        self.file_range,
+                        std::ptr::null_mut(),
+                        0,
+                    );
                     (c.HttpRangeFreeBlock)(self.file_range);
                     self.file_range = std::ptr::null_mut();
                 }
@@ -239,7 +239,8 @@ impl HTTP2Transaction {
     }
 
     fn decompress<'a>(
-        &'a mut self, input: &'a [u8], dir: Direction, sfcm: &'static SuricataFileContext, over: bool, flow: *const Flow,
+        &'a mut self, input: &'a [u8], dir: Direction, sfcm: &'static SuricataFileContext,
+        over: bool, flow: *const Flow,
     ) -> io::Result<()> {
         let mut output = Vec::with_capacity(decompression::HTTP2_DECOMPRESSION_CHUNK_SIZE);
         let decompressed = self.decoder.decompress(input, &mut output, dir)?;
@@ -258,7 +259,14 @@ impl HTTP2Transaction {
                 ) {
                     match range::http2_parse_check_content_range(&value) {
                         Ok((_, v)) => {
-                            range::http2_range_open(self, &v, flow, sfcm, Direction::ToClient, decompressed);
+                            range::http2_range_open(
+                                self,
+                                &v,
+                                flow,
+                                sfcm,
+                                Direction::ToClient,
+                                decompressed,
+                            );
                             if over && !self.file_range.is_null() {
                                 range::http2_range_close(self, Direction::ToClient, &[])
                             }
@@ -603,7 +611,7 @@ impl HTTP2State {
         tx.state = HTTP2TransactionState::HTTP2StateGlobal;
         tx.tx_data.update_file_flags(self.state_data.file_flags);
         // TODO can this tx hold files?
-        tx.tx_data.file_tx = STREAM_TOSERVER|STREAM_TOCLIENT; // might hold files in both directions
+        tx.tx_data.file_tx = STREAM_TOSERVER | STREAM_TOCLIENT; // might hold files in both directions
         tx.update_file_flags(tx.tx_data.file_flags);
         self.transactions.push_back(tx);
         return self.transactions.back_mut().unwrap();
@@ -677,7 +685,7 @@ impl HTTP2State {
             tx.state = HTTP2TransactionState::HTTP2StateOpen;
             tx.tx_data.update_file_flags(self.state_data.file_flags);
             tx.update_file_flags(tx.tx_data.file_flags);
-            tx.tx_data.file_tx = STREAM_TOSERVER|STREAM_TOCLIENT; // might hold files in both directions
+            tx.tx_data.file_tx = STREAM_TOSERVER | STREAM_TOCLIENT; // might hold files in both directions
             self.transactions.push_back(tx);
             return Some(self.transactions.back_mut().unwrap());
         }
@@ -688,9 +696,7 @@ impl HTTP2State {
         for block in blocks {
             if block.error >= parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeError {
                 self.set_event(HTTP2Event::InvalidHeader);
-            } else if block.error
-                == parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSizeUpdate
-            {
+            } else if block.error == parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSizeUpdate {
                 update = true;
                 if block.sizeupdate > sizeup {
                     sizeup = block.sizeupdate;
@@ -1087,15 +1093,10 @@ impl HTTP2State {
                                         tx_same.ft_ts.tx_id = tx_same.tx_id - 1;
                                     };
                                     let mut dinput = &rem[..hlsafe];
-                                    if padded && !rem.is_empty() && usize::from(rem[0]) < hlsafe{
+                                    if padded && !rem.is_empty() && usize::from(rem[0]) < hlsafe {
                                         dinput = &rem[1..hlsafe - usize::from(rem[0])];
                                     }
-                                    if tx_same.decompress(
-                                        dinput,
-                                        dir,
-                                        sfcm,
-                                        over,
-                                        flow).is_err() {
+                                    if tx_same.decompress(dinput, dir, sfcm, over, flow).is_err() {
                                         self.set_event(HTTP2Event::FailedDecompression);
                                     }
                                 }
@@ -1324,9 +1325,15 @@ pub unsafe extern "C" fn rs_http2_getfiles(
     let tx = cast_pointer!(tx, HTTP2Transaction);
     if let Some(sfcm) = { SURICATA_HTTP2_FILE_CONFIG } {
         if direction & STREAM_TOSERVER != 0 {
-            return AppLayerGetFileState { fc: &mut tx.ft_ts.file, cfg: sfcm.files_sbcfg }
+            return AppLayerGetFileState {
+                fc: &mut tx.ft_ts.file,
+                cfg: sfcm.files_sbcfg,
+            };
         } else {
-            return AppLayerGetFileState { fc: &mut tx.ft_tc.file, cfg: sfcm.files_sbcfg }
+            return AppLayerGetFileState {
+                fc: &mut tx.ft_tc.file,
+                cfg: sfcm.files_sbcfg,
+            };
         }
     }
     AppLayerGetFileState::err()
index ca8994e40849b13738d9d036c91a558043f7217e..bf5fc9b1ea458d62dc5cc81a2075622f461e61c1 100644 (file)
@@ -125,7 +125,10 @@ fn log_http2_frames(frames: &[HTTP2Frame], js: &mut JsonBuilder) -> Result<bool,
             }
             for e in set {
                 js.start_object()?;
-                js.set_string("settings_id", &format!("SETTINGS{}", &e.id.to_string().to_uppercase()))?;
+                js.set_string(
+                    "settings_id",
+                    &format!("SETTINGS{}", &e.id.to_string().to_uppercase()),
+                )?;
                 js.set_uint("settings_value", e.value as u64)?;
                 js.close()?;
             }
index b4681cba300814b5b12e1900424c0b2c9fea76e6..ff3e172b69fb1270373c22f908474c5d0b1d6efa 100644 (file)
@@ -463,8 +463,9 @@ fn http2_parse_headers_block_literal_incindex<'a>(
                 while dyn_headers.current_size > dyn_headers.max_size
                     && toremove < dyn_headers.table.len()
                 {
-                    dyn_headers.current_size -=
-                        32 + dyn_headers.table[toremove].name.len() + dyn_headers.table[toremove].value.len();
+                    dyn_headers.current_size -= 32
+                        + dyn_headers.table[toremove].name.len()
+                        + dyn_headers.table[toremove].value.len();
                     toremove += 1;
                 }
                 dyn_headers.table.drain(0..toremove);
index 9c96899443a17b9ecf76eac54418b9c67aab1711..71c22a7b5d01c2b09449bfd70c28987ba5982e45 100644 (file)
@@ -131,7 +131,11 @@ pub fn http2_range_open(
         // whole file in one range
         return;
     }
-    let flags = if dir == Direction::ToServer { tx.ft_ts.file_flags } else { tx.ft_tc.file_flags };
+    let flags = if dir == Direction::ToServer {
+        tx.ft_ts.file_flags
+    } else {
+        tx.ft_tc.file_flags
+    };
     if let Ok((key, index)) = http2_range_key_get(tx) {
         let name = &key[index..];
         tx.file_range = unsafe {
@@ -151,15 +155,15 @@ pub fn http2_range_open(
     }
 }
 
-pub fn http2_range_append(cfg: &'static SuricataFileContext, fr: *mut HttpRangeContainerBlock, data: &[u8]) {
+pub fn http2_range_append(
+    cfg: &'static SuricataFileContext, fr: *mut HttpRangeContainerBlock, data: &[u8],
+) {
     unsafe {
         HttpRangeAppendData(cfg.files_sbcfg, fr, data.as_ptr(), data.len() as u32);
     }
 }
 
-pub fn http2_range_close(
-    tx: &mut HTTP2Transaction, dir: Direction, data: &[u8],
-) {
+pub fn http2_range_close(tx: &mut HTTP2Transaction, dir: Direction, data: &[u8]) {
     let added = if let Some(c) = unsafe { SC } {
         if let Some(sfcm) = unsafe { SURICATA_HTTP2_FILE_CONFIG } {
             let (files, flags) = if dir == Direction::ToServer {
@@ -168,13 +172,13 @@ pub fn http2_range_close(
                 (&mut tx.ft_tc.file, tx.ft_tc.file_flags)
             };
             let added = (c.HTPFileCloseHandleRange)(
-                    sfcm.files_sbcfg,
-                    files,
-                    flags,
-                    tx.file_range,
-                    data.as_ptr(),
-                    data.len() as u32,
-                    );
+                sfcm.files_sbcfg,
+                files,
+                flags,
+                tx.file_range,
+                data.as_ptr(),
+                data.len() as u32,
+            );
             (c.HttpRangeFreeBlock)(tx.file_range);
             added
         } else {
@@ -197,7 +201,8 @@ extern "C" {
         data: *const c_uchar, data_len: u32,
     ) -> *mut HttpRangeContainerBlock;
     pub fn HttpRangeAppendData(
-        cfg: *const StreamingBufferConfig, c: *mut HttpRangeContainerBlock, data: *const c_uchar, data_len: u32,
+        cfg: *const StreamingBufferConfig, c: *mut HttpRangeContainerBlock, data: *const c_uchar,
+        data_len: u32,
     ) -> std::os::raw::c_int;
 }