From: Philippe Antoine Date: Tue, 21 Jan 2025 13:56:08 +0000 (+0100) Subject: template: rustfmt X-Git-Tag: suricata-8.0.0-beta1~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fa3a9fe62544e8644a1f47ce45023e3722c639d;p=thirdparty%2Fsuricata.git template: rustfmt and use generic logger callback prototype with later cast and do some other small modifications so that the plugin has less diff --- diff --git a/rust/src/applayertemplate/detect.rs b/rust/src/applayertemplate/detect.rs index 47f7f040fb..e7fffb9460 100644 --- a/rust/src/applayertemplate/detect.rs +++ b/rust/src/applayertemplate/detect.rs @@ -19,12 +19,12 @@ use super::template::{TemplateTransaction, ALPROTO_TEMPLATE}; /* TEMPLATE_START_REMOVE */ use crate::conf::conf_get_node; /* TEMPLATE_END_REMOVE */ -use crate::direction::Direction; use crate::detect::{ DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData, DetectHelperKeywordRegister, DetectSignatureSetAppProto, SCSigTableElmt, SIGMATCH_INFO_STICKY_BUFFER, SIGMATCH_NOOPT, }; +use crate::direction::Direction; use std::os::raw::{c_int, c_void}; static mut G_TEMPLATE_BUFFER_BUFFER_ID: c_int = 0; diff --git a/rust/src/applayertemplate/logger.rs b/rust/src/applayertemplate/logger.rs index 766a07acdb..a970e83277 100644 --- a/rust/src/applayertemplate/logger.rs +++ b/rust/src/applayertemplate/logger.rs @@ -33,8 +33,9 @@ fn log_template(tx: &TemplateTransaction, js: &mut JsonBuilder) -> Result<(), Js #[no_mangle] pub unsafe extern "C" fn rs_template_logger_log( - tx: *mut std::os::raw::c_void, js: &mut JsonBuilder, + tx: *const std::os::raw::c_void, js: *mut std::os::raw::c_void, ) -> bool { let tx = cast_pointer!(tx, TemplateTransaction); + let js = cast_pointer!(js, JsonBuilder); log_template(tx, js).is_ok() } diff --git a/rust/src/applayertemplate/mod.rs b/rust/src/applayertemplate/mod.rs index ae7005a09d..70e6d99f03 100644 --- a/rust/src/applayertemplate/mod.rs +++ b/rust/src/applayertemplate/mod.rs @@ -20,6 +20,6 @@ mod parser; pub mod template; /* TEMPLATE_START_REMOVE */ -pub mod logger; pub mod detect; +pub mod logger; /* TEMPLATE_END_REMOVE */ diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index 88f66af34b..d6ee9c6999 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -16,16 +16,16 @@ */ use super::parser; -use crate::applayer::{self, *}; +use crate::applayer::*; use crate::conf::conf_get; use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP}; use crate::flow::Flow; use nom7 as nom; -use suricata_sys::sys::AppProto; use std; use std::collections::VecDeque; use std::ffi::CString; use std::os::raw::{c_char, c_int, c_void}; +use suricata_sys::sys::AppProto; static mut TEMPLATE_MAX_TX: usize = 256; @@ -121,7 +121,9 @@ impl TemplateState { } fn find_request(&mut self) -> Option<&mut TemplateTransaction> { - self.transactions.iter_mut().find(|tx| tx.response.is_none()) + self.transactions + .iter_mut() + .find(|tx| tx.response.is_none()) } fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { @@ -152,11 +154,12 @@ impl TemplateState { SCLogNotice!("Request: {}", request); let mut tx = self.new_tx(); tx.request = Some(request); - if self.transactions.len() >= unsafe {TEMPLATE_MAX_TX} { - tx.tx_data.set_event(TemplateEvent::TooManyTransactions as u8); + if self.transactions.len() >= unsafe { TEMPLATE_MAX_TX } { + tx.tx_data + .set_event(TemplateEvent::TooManyTransactions as u8); } self.transactions.push_back(tx); - if self.transactions.len() >= unsafe {TEMPLATE_MAX_TX} { + if self.transactions.len() >= unsafe { TEMPLATE_MAX_TX } { return AppLayerResult::err(); } } @@ -201,7 +204,7 @@ impl TemplateState { Ok((rem, response)) => { start = rem; - if let Some(tx) = self.find_request() { + if let Some(tx) = self.find_request() { tx.tx_data.updated_tc = true; tx.response = Some(response); SCLogNotice!("Found response for request:"); @@ -388,9 +391,7 @@ pub unsafe extern "C" fn rs_template_register_parser() { localstorage_new: None, localstorage_free: None, get_tx_files: None, - get_tx_iterator: Some( - applayer::state_get_tx_iterator::, - ), + get_tx_iterator: Some(state_get_tx_iterator::), get_tx_data: template_get_tx_data, get_state_data: template_get_state_data, apply_tx_config: None, diff --git a/scripts/setup-app-layer.py b/scripts/setup-app-layer.py index ca2ecc5b16..a19cad30b8 100755 --- a/scripts/setup-app-layer.py +++ b/scripts/setup-app-layer.py @@ -210,6 +210,8 @@ def logger_patch_output_c(proto): if line.find("rs_template_logger_log") > -1: output.write(inlines[i].replace("TEMPLATE", proto.upper()).replace( "template", proto.lower())) + # RegisterSimpleJsonApplayerLogger( on itw own line for clang-format + output.write(inlines[i-1]) if line.find("OutputTemplateLogInitSub(") > -1: output.write(inlines[i].replace("Template", proto)) output.write(inlines[i+1]) diff --git a/src/output.c b/src/output.c index 7a9c86a267..527ddda59a 100644 --- a/src/output.c +++ b/src/output.c @@ -912,7 +912,8 @@ void OutputRegisterRootLoggers(void) RegisterSimpleJsonApplayerLogger(ALPROTO_WEBSOCKET, rs_websocket_logger_log, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_LDAP, rs_ldap_logger_log, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_DOH2, AlertJsonDoh2, NULL); - RegisterSimpleJsonApplayerLogger(ALPROTO_TEMPLATE, rs_template_logger_log, NULL); + RegisterSimpleJsonApplayerLogger( + ALPROTO_TEMPLATE, (EveJsonSimpleTxLogFunc)rs_template_logger_log, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_RDP, (EveJsonSimpleTxLogFunc)rs_rdp_to_json, NULL); // special case : http2 is logged in http object RegisterSimpleJsonApplayerLogger(ALPROTO_HTTP2, rs_http2_log_json, "http");