diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 6fca0f9ff0..c4e7c2e8aa 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -63,6 +63,26 @@ impl AppLayerResult { } } +impl From for AppLayerResult { + fn from(v: bool) -> Self { + if v == false { + Self::err() + } else { + Self::ok() + } + } +} + +impl From for AppLayerResult { + fn from(v: i32) -> Self { + if v < 0 { + Self::err() + } else { + Self::ok() + } + } +} + /// Rust parser declaration #[repr(C)] pub struct RustParser { diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index 7b80fbba5b..93df4b3400 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -316,10 +316,7 @@ pub extern "C" fn rs_template_parse_request( let state = cast_pointer!(state, TemplateState); let buf = build_slice!(input, input_len as usize); - if !state.parse_request(buf) { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse_request(buf).into() } #[no_mangle] @@ -341,10 +338,7 @@ pub extern "C" fn rs_template_parse_response( }; let state = cast_pointer!(state, TemplateState); let buf = build_slice!(input, input_len as usize); - if !state.parse_response(buf) { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse_response(buf).into() } #[no_mangle] diff --git a/rust/src/sip/sip.rs b/rust/src/sip/sip.rs index 0733306b3e..cda829a49f 100755 --- a/rust/src/sip/sip.rs +++ b/rust/src/sip/sip.rs @@ -360,10 +360,7 @@ pub extern "C" fn rs_sip_parse_request( ) -> AppLayerResult { let buf = build_slice!(input, input_len as usize); let state = cast_pointer!(state, SIPState); - if !state.parse_request(buf) { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse_request(buf).into() } #[no_mangle] @@ -378,10 +375,7 @@ pub extern "C" fn rs_sip_parse_response( ) -> AppLayerResult { let buf = build_slice!(input, input_len as usize); let state = cast_pointer!(state, SIPState); - if !state.parse_response(buf) { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse_response(buf).into() } const PARSER_NAME: &'static [u8] = b"sip\0"; diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index b555f15baf..fc59644e66 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -325,10 +325,7 @@ pub extern "C" fn rs_snmp_parse_request(_flow: *const core::Flow, _flags: u8) -> AppLayerResult { let buf = build_slice!(input,input_len as usize); let state = cast_pointer!(state,SNMPState); - if state.parse(buf, STREAM_TOSERVER) < 0 { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse(buf, STREAM_TOSERVER).into() } #[no_mangle] @@ -341,10 +338,7 @@ pub extern "C" fn rs_snmp_parse_response(_flow: *const core::Flow, _flags: u8) -> AppLayerResult { let buf = build_slice!(input,input_len as usize); let state = cast_pointer!(state,SNMPState); - if state.parse(buf, STREAM_TOCLIENT) < 0 { - return AppLayerResult::err(); - } - AppLayerResult::ok() + state.parse(buf, STREAM_TOCLIENT).into() } #[no_mangle]