/src/suricata8/rust/src/applayertemplate/logger.rs
Line | Count | Source |
1 | | /* Copyright (C) 2018 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use super::template::TemplateTransaction; |
19 | | use crate::jsonbuilder::{JsonBuilder, JsonError}; |
20 | | use std; |
21 | | |
22 | 0 | fn log_template(tx: &TemplateTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> { |
23 | 0 | js.open_object("template")?; |
24 | 0 | if let Some(ref request) = tx.request { |
25 | 0 | js.set_string("request", request)?; |
26 | 0 | } |
27 | 0 | if let Some(ref response) = tx.response { |
28 | 0 | js.set_string("response", response)?; |
29 | 0 | } |
30 | 0 | js.close()?; |
31 | 0 | Ok(()) |
32 | 0 | } |
33 | | |
34 | | #[no_mangle] |
35 | 0 | pub unsafe extern "C" fn SCTemplateLoggerLog( |
36 | 0 | tx: *const std::os::raw::c_void, js: *mut std::os::raw::c_void, |
37 | 0 | ) -> bool { |
38 | 0 | let tx = cast_pointer!(tx, TemplateTransaction); |
39 | 0 | let js = cast_pointer!(js, JsonBuilder); |
40 | 0 | log_template(tx, js).is_ok() |
41 | 0 | } |