/src/suricata/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::sdp::logger::sdp_log; |
22 | | use crate::sip::sip::SIPTransaction; |
23 | | |
24 | 26.5k | fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> { |
25 | 26.5k | js.open_object("sip")?; |
26 | | |
27 | 26.5k | if let Some(req) = &tx.request { |
28 | 19.0k | js.set_string("method", &req.method)? |
29 | 19.0k | .set_string("uri", &req.path)? |
30 | 19.0k | .set_string("version", &req.version)?; |
31 | | |
32 | 19.0k | if let Some(sdp_body) = &req.body { |
33 | 3.55k | sdp_log(sdp_body, js)?; |
34 | 15.4k | } |
35 | 7.49k | } |
36 | | |
37 | 26.5k | if let Some(req_line) = &tx.request_line { |
38 | 19.0k | js.set_string("request_line", req_line)?; |
39 | 7.49k | } |
40 | | |
41 | 26.5k | if let Some(resp) = &tx.response { |
42 | 7.49k | js.set_string("version", &resp.version)? |
43 | 7.49k | .set_string("code", &resp.code)? |
44 | 7.49k | .set_string("reason", &resp.reason)?; |
45 | 7.49k | if let Some(sdp_body) = &resp.body { |
46 | 383 | sdp_log(sdp_body, js)?; |
47 | 7.11k | } |
48 | 19.0k | } |
49 | | |
50 | 26.5k | if let Some(resp_line) = &tx.response_line { |
51 | 7.49k | js.set_string("response_line", resp_line)?; |
52 | 19.0k | } |
53 | | |
54 | 26.5k | js.close()?; |
55 | | |
56 | 26.5k | Ok(()) |
57 | 26.5k | } |
58 | | |
59 | | #[no_mangle] |
60 | 26.5k | pub extern "C" fn SCSipLogJson(tx: &SIPTransaction, js: &mut JsonBuilder) -> bool { |
61 | 26.5k | log(tx, js).is_ok() |
62 | 26.5k | } |