From 098aced714e2648956d19bf91daaf1d0bea3775c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 23 May 2017 11:26:56 +0200 Subject: [PATCH] rust/nfs/files: no longer Option/Box --- rust/src/nfs/nfs3.rs | 48 +++++++++++++------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/rust/src/nfs/nfs3.rs b/rust/src/nfs/nfs3.rs index 253d43cbd6..228faa9024 100644 --- a/rust/src/nfs/nfs3.rs +++ b/rust/src/nfs/nfs3.rs @@ -107,7 +107,7 @@ pub struct NFS3TransactionFile { /// file tracker for a single file. Boxed so that we don't use /// as much space if we're not a file tx. - pub file_tracker: Option>, + pub file_tracker: FileTransferTracker, } impl NFS3TransactionFile { @@ -115,7 +115,7 @@ impl NFS3TransactionFile { return NFS3TransactionFile { file_additional_procs: Vec::new(), file_last_xid: 0, - file_tracker: None, + file_tracker: FileTransferTracker::new(), } } } @@ -152,6 +152,8 @@ pub struct NFS3Transaction { pub file_handle: Vec, /// Procedure type specific data + /// TODO see if this can be an Option>. Initial + /// attempt failed. pub type_data: Option, pub logged: LoggerFlags, @@ -245,20 +247,15 @@ impl NFS3Files { } /// little wrapper around the FileTransferTracker::new_chunk method -fn filetracker_newchunk(ftopt: &mut Option>, files: &mut FileContainer, +fn filetracker_newchunk(ft: &mut FileTransferTracker, files: &mut FileContainer, flags: u16, name: &Vec, data: &[u8], chunk_offset: u64, chunk_size: u32, fill_bytes: u8, is_last: bool, xid: &u32) { - match ftopt { - &mut Some(ref mut ft) => { - match unsafe {suricata_nfs3_file_config} { - Some(sfcm) => { - ft.new_chunk(sfcm, files, flags, &name, data, chunk_offset, - chunk_size, fill_bytes, is_last, xid); } - None => panic!("BUG"), - } - }, - &mut None => { panic!("BUG"); }, + match unsafe {suricata_nfs3_file_config} { + Some(sfcm) => { + ft.new_chunk(sfcm, files, flags, &name, data, chunk_offset, + chunk_size, fill_bytes, is_last, xid); } + None => panic!("BUG"), } } @@ -516,12 +513,7 @@ impl NFS3State { _ => panic!("BUG"), }; tdf.file_additional_procs.push(NFSPROC3_COMMIT); - match tdf.file_tracker { - Some(ref mut sft) => { - sft.close(files, flags); - }, - None => { }, - } + tdf.file_tracker.close(files, flags); tdf.file_last_xid = r.hdr.xid; tx.request_done = true; }, @@ -579,11 +571,7 @@ impl NFS3State { tx.type_data = Some(NFS3TransactionTypeData::FILE(NFS3TransactionFile::new())); match tx.type_data { Some(NFS3TransactionTypeData::FILE(ref mut d)) => { - d.file_tracker = Some(Box::new(FileTransferTracker::new())); - match d.file_tracker { - Some(ref mut ft) => { ft.tx_id = tx.id; }, - None => { }, - } + d.file_tracker.tx_id = tx.id; }, _ => { }, } @@ -879,16 +867,8 @@ impl NFS3State { Some(NFS3TransactionTypeData::FILE(ref mut x)) => x, _ => { panic!("BUG") }, }; - let cs1 = match tdf.file_tracker { - Some(ref mut ft) => { - let cs2 = ft.update(files, flags, data); - // return number of bytes we consumed - SCLogDebug!("consumed {}", cs2); - cs2 - }, - None => { 0 }, - }; - cs1 + let cs = tdf.file_tracker.update(files, flags, data); + cs }, None => { 0 }, };