template: rustfmt

and use generic logger callback prototype with later cast

and do some other small modifications so that the plugin
has less diff
pull/12862/head
Philippe Antoine 5 months ago committed by Victor Julien
parent a4b8c5319c
commit 2fa3a9fe62

@ -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;

@ -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()
}

@ -20,6 +20,6 @@
mod parser;
pub mod template;
/* TEMPLATE_START_REMOVE */
pub mod logger;
pub mod detect;
pub mod logger;
/* TEMPLATE_END_REMOVE */

@ -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::<TemplateState, TemplateTransaction>,
),
get_tx_iterator: Some(state_get_tx_iterator::<TemplateState, TemplateTransaction>),
get_tx_data: template_get_tx_data,
get_state_data: template_get_state_data,
apply_tx_config: None,

@ -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])

@ -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");

Loading…
Cancel
Save