Coverage Report

Created: 2026-09-06 07:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata8/rust/src/sdp/logger.rs
Line
Count
Source
1
/* Copyright (C) 2024 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
22
use super::parser::{MediaDescription, SdpMessage, TimeDescription};
23
24
0
pub fn sdp_log(msg: &SdpMessage, js: &mut JsonBuilder) -> Result<(), JsonError> {
25
0
    js.open_object("sdp")?;
26
27
0
    js.set_string("origin", &msg.origin)?;
28
0
    js.set_string("session_name", &msg.session_name)?;
29
30
0
    if let Some(session_info) = &msg.session_info {
31
0
        js.set_string("session_info", session_info)?;
32
0
    }
33
0
    if let Some(uri) = &msg.uri {
34
0
        js.set_string("uri", uri)?;
35
0
    }
36
0
    if let Some(email) = &msg.email {
37
0
        js.set_string("email", email)?;
38
0
    }
39
0
    if let Some(phone_number) = &msg.phone_number {
40
0
        js.set_string("phone_number", phone_number)?;
41
0
    }
42
0
    if let Some(conn_data) = &msg.connection_data {
43
0
        js.set_string("connection_data", conn_data)?;
44
0
    }
45
0
    if let Some(bws) = &msg.bandwidths {
46
0
        log_bandwidth(bws, js)?;
47
0
    }
48
0
    log_time_description(&msg.time_description, js)?;
49
0
    if let Some(tz) = &msg.time_zone {
50
0
        js.set_string("timezone", tz)?;
51
0
    }
52
0
    if let Some(enc_key) = &msg.encryption_key {
53
0
        js.set_string("encryption_key", enc_key)?;
54
0
    }
55
0
    if let Some(attrs) = &msg.attributes {
56
0
        log_attributes(attrs, js)?;
57
0
    }
58
0
    if let Some(media) = &msg.media_description {
59
0
        log_media_description(media, js)?;
60
0
    }
61
0
    js.close()?;
62
0
    Ok(())
63
0
}
64
65
0
fn log_time_description(
66
0
    time: &Vec<TimeDescription>, js: &mut JsonBuilder,
67
0
) -> Result<(), JsonError> {
68
0
    js.open_array("time_descriptions")?;
69
0
    for t in time {
70
0
        js.start_object()?;
71
0
        js.set_string("time", &t.time)?;
72
0
        if let Some(repeat_time) = &t.repeat_time {
73
0
            js.set_string("repeat_time", repeat_time)?;
74
0
        }
75
0
        js.close()?;
76
    }
77
0
    js.close()?;
78
0
    Ok(())
79
0
}
80
81
0
fn log_media_description(
82
0
    media: &Vec<MediaDescription>, js: &mut JsonBuilder,
83
0
) -> Result<(), JsonError> {
84
0
    if !media.is_empty() {
85
0
        js.open_array("media_descriptions")?;
86
0
        for m in media {
87
0
            js.start_object()?;
88
0
            js.set_string("media", &m.media)?;
89
0
            if let Some(session_info) = &m.session_info {
90
0
                js.set_string("media_info", session_info)?;
91
0
            };
92
0
            if let Some(bws) = &m.bandwidths {
93
0
                log_bandwidth(bws, js)?;
94
0
            }
95
0
            if let Some(conn_data) = &m.connection_data {
96
0
                js.set_string("connection_data", conn_data)?;
97
0
            }
98
0
            if let Some(enc_key) = &m.encryption_key {
99
0
                js.set_string("encryption_key", enc_key)?;
100
0
            }
101
0
            if let Some(attrs) = &m.attributes {
102
0
                log_attributes(attrs, js)?;
103
0
            }
104
0
            js.close()?;
105
        }
106
0
        js.close()?;
107
0
    }
108
109
0
    Ok(())
110
0
}
111
112
0
fn log_bandwidth(bws: &Vec<String>, js: &mut JsonBuilder) -> Result<(), JsonError> {
113
0
    if !bws.is_empty() {
114
0
        js.open_array("bandwidths")?;
115
0
        for bw in bws {
116
0
            js.append_string(bw)?;
117
        }
118
0
        js.close()?;
119
0
    }
120
0
    Ok(())
121
0
}
122
123
0
fn log_attributes(attrs: &Vec<String>, js: &mut JsonBuilder) -> Result<(), JsonError> {
124
0
    if !attrs.is_empty() {
125
0
        js.open_array("attributes")?;
126
0
        for attr in attrs {
127
0
            js.append_string(attr)?;
128
        }
129
0
        js.close()?;
130
0
    }
131
0
    Ok(())
132
0
}