From: Jason Ish Date: Wed, 10 Nov 2021 17:24:14 +0000 (-0600) Subject: rfb: use generic tx iterator X-Git-Tag: suricata-7.0.0-beta1~1206 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0188a01dafce1fa4b35da67762f0ee96ded77777;p=thirdparty%2Fsuricata.git rfb: use generic tx iterator --- diff --git a/rust/src/rfb/rfb.rs b/rust/src/rfb/rfb.rs index d9b6d543cf..b6414cbedf 100644 --- a/rust/src/rfb/rfb.rs +++ b/rust/src/rfb/rfb.rs @@ -49,6 +49,12 @@ pub struct RFBTransaction { tx_data: applayer::AppLayerTxData, } +impl Transaction for RFBTransaction { + fn id(&self) -> u64 { + self.tx_id + } +} + impl RFBTransaction { pub fn new() -> RFBTransaction { RFBTransaction { @@ -96,6 +102,12 @@ pub struct RFBState { state: parser::RFBGlobalState } +impl State for RFBState { + fn get_transactions(&self) -> &[RFBTransaction] { + &self.transactions + } +} + impl RFBState { pub fn new() -> Self { Self { @@ -482,27 +494,6 @@ impl RFBState { } } } - - fn tx_iterator( - &mut self, - min_tx_id: u64, - state: &mut u64, - ) -> Option<(&RFBTransaction, u64, bool)> { - let mut index = *state as usize; - let len = self.transactions.len(); - - while index < len { - let tx = &self.transactions[index]; - if tx.tx_id < min_tx_id + 1 { - index += 1; - continue; - } - *state = index as u64; - return Some((tx, tx.tx_id - 1, (len - index) > 1)); - } - - return None; - } } // C exports. @@ -612,32 +603,6 @@ pub unsafe extern "C" fn rs_rfb_state_get_events( return tx.events; } -#[no_mangle] -pub unsafe extern "C" fn rs_rfb_state_get_tx_iterator( - _ipproto: u8, - _alproto: AppProto, - state: *mut std::os::raw::c_void, - min_tx_id: u64, - _max_tx_id: u64, - istate: &mut u64, -) -> applayer::AppLayerGetTxIterTuple { - let state = cast_pointer!(state, RFBState); - match state.tx_iterator(min_tx_id, istate) { - Some((tx, out_tx_id, has_next)) => { - let c_tx = tx as *const _ as *mut _; - let ires = applayer::AppLayerGetTxIterTuple::with_values( - c_tx, - out_tx_id, - has_next, - ); - return ires; - } - None => { - return applayer::AppLayerGetTxIterTuple::not_found(); - } - } -} - // Parser name as a C style string. const PARSER_NAME: &'static [u8] = b"rfb\0"; @@ -671,7 +636,7 @@ pub unsafe extern "C" fn rs_rfb_register_parser() { localstorage_new: None, localstorage_free: None, get_files: None, - get_tx_iterator: Some(rs_rfb_state_get_tx_iterator), + get_tx_iterator: Some(applayer::state_get_tx_iterator::), get_tx_data: rs_rfb_get_tx_data, apply_tx_config: None, flags: 0,