/src/suricata7/rust/src/sip/log.rs
Line | Count | Source |
1 | | /* Copyright (C) 2019 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 | | // written by Giuseppe Longo <giuseppe@glongo.it> |
19 | | |
20 | | use crate::jsonbuilder::{JsonBuilder, JsonError}; |
21 | | use crate::sip::sip::SIPTransaction; |
22 | | |
23 | 5.03k | fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> { |
24 | 5.03k | js.open_object("sip")?; |
25 | | |
26 | 5.03k | if let Some(req) = &tx.request { |
27 | 3.44k | js.set_string("method", &req.method)? |
28 | 3.44k | .set_string("uri", &req.path)? |
29 | 3.44k | .set_string("version", &req.version)?; |
30 | 1.58k | } |
31 | | |
32 | 5.03k | if let Some(req_line) = &tx.request_line { |
33 | 3.44k | js.set_string("request_line", req_line)?; |
34 | 1.58k | } |
35 | | |
36 | 5.03k | if let Some(resp) = &tx.response { |
37 | 1.58k | js.set_string("version", &resp.version)? |
38 | 1.58k | .set_string("code", &resp.code)? |
39 | 1.58k | .set_string("reason", &resp.reason)?; |
40 | 3.44k | } |
41 | | |
42 | 5.03k | if let Some(resp_line) = &tx.response_line { |
43 | 1.58k | js.set_string("response_line", resp_line)?; |
44 | 3.44k | } |
45 | | |
46 | 5.03k | js.close()?; |
47 | | |
48 | 5.03k | Ok(()) |
49 | 5.03k | } |
50 | | |
51 | | #[no_mangle] |
52 | 5.03k | pub extern "C" fn rs_sip_log_json(tx: &mut SIPTransaction, js: &mut JsonBuilder) -> bool { |
53 | 5.03k | log(tx, js).is_ok() |
54 | 5.03k | } |