• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22618661228

02 Mar 2026 09:33PM UTC coverage: 42.258% (-34.4%) from 76.611%
22618661228

push

github

victorjulien
github-actions: bump actions/download-artifact from 7.0.0 to 8.0.0

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7.0.0 to 8.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/37930b1c2...70fc10c6e)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

91511 of 216553 relevant lines covered (42.26%)

3416852.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.64
/rust/htp/src/c_api/connection_parser.rs
1
#![deny(missing_docs)]
2
use crate::{
3
    config::Config,
4
    connection::Connection,
5
    connection_parser::{ConnectionParser, HtpStreamState, ParserData},
6
    transaction::Transaction,
7
};
8
use std::{
9
    convert::{TryFrom, TryInto},
10
    ffi::CStr,
11
};
12
use time::{Duration, OffsetDateTime};
13

14
/// Take seconds and microseconds and return a OffsetDateTime
15
fn datetime_from_sec_usec(sec: i64, usec: i64) -> Option<OffsetDateTime> {
14,131✔
16
    match OffsetDateTime::from_unix_timestamp(sec) {
14,131✔
17
        Ok(date) => Some(date + Duration::microseconds(usec)),
14,131✔
18
        Err(_) => None,
×
19
    }
20
}
14,131✔
21

22
/// Closes the connection associated with the supplied parser.
23
///
24
/// timestamp is optional
25
/// # Safety
26
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
27
#[no_mangle]
28
#[allow(clippy::useless_conversion)]
29
pub unsafe extern "C" fn htp_connp_close(
1,338✔
30
    connp: *mut ConnectionParser, timestamp: *const libc::timeval,
1,338✔
31
) {
1,338✔
32
    if let Some(connp) = connp.as_mut() {
1,338✔
33
        connp.close(
1,338✔
34
            timestamp
1,338✔
35
                .as_ref()
1,338✔
36
                .map(|val| datetime_from_sec_usec(val.tv_sec.into(), val.tv_usec.into()))
1,338✔
37
                .unwrap_or(None),
1,338✔
38
        )
1,338✔
39
    }
×
40
}
1,338✔
41

42
/// Creates a new connection parser using the provided configuration or a default configuration if NULL provided.
43
/// Note the provided config will be copied into the created connection parser. Therefore, subsequent modification
44
/// to the original config will have no effect.
45
///
46
/// Returns a new connection parser instance, or NULL on error.
47
/// # Safety
48
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
49
#[no_mangle]
50
pub unsafe extern "C" fn htp_connp_create(cfg: *const Config) -> *mut ConnectionParser {
1,591✔
51
    Box::into_raw(Box::new(ConnectionParser::new(cfg.as_ref().unwrap())))
1,591✔
52
}
1,591✔
53

54
/// Destroys the connection parser, its data structures, as well
55
/// as the connection and its transactions.
56
/// # Safety
57
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
58
#[no_mangle]
59
pub unsafe extern "C" fn htp_connp_destroy_all(connp: *mut ConnectionParser) {
1,591✔
60
    drop(Box::from_raw(connp));
1,591✔
61
}
1,591✔
62

63
/// Returns the connection associated with the connection parser.
64
///
65
/// Returns Connection instance, or NULL if one is not available.
66
/// # Safety
67
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
68
#[no_mangle]
69
pub unsafe extern "C" fn htp_connp_connection(connp: *const ConnectionParser) -> *const Connection {
1,591✔
70
    connp
1,591✔
71
        .as_ref()
1,591✔
72
        .map(|val| &val.conn as *const Connection)
1,591✔
73
        .unwrap_or(std::ptr::null())
1,591✔
74
}
1,591✔
75

76
/// Retrieve the user data associated with this connection parser.
77
/// Returns user data, or NULL if there isn't any.
78
/// # Safety
79
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
80
#[no_mangle]
81
pub unsafe extern "C" fn htp_connp_user_data(connp: *const ConnectionParser) -> *mut libc::c_void {
23,976✔
82
    connp
23,976✔
83
        .as_ref()
23,976✔
84
        .and_then(|val| val.user_data::<*mut libc::c_void>())
23,976✔
85
        .copied()
23,976✔
86
        .unwrap_or(std::ptr::null_mut())
23,976✔
87
}
23,976✔
88

89
/// Associate user data with the supplied parser.
90
/// # Safety
91
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
92
#[no_mangle]
93
pub unsafe extern "C" fn htp_connp_set_user_data(
1,591✔
94
    connp: *mut ConnectionParser, user_data: *mut libc::c_void,
1,591✔
95
) {
1,591✔
96
    if let Some(connp) = connp.as_mut() {
1,591✔
97
        connp.set_user_data(Box::new(user_data))
1,591✔
98
    }
×
99
}
1,591✔
100

101
/// Opens connection.
102
///
103
/// timestamp is optional
104
/// # Safety
105
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
106
#[no_mangle]
107
#[allow(clippy::useless_conversion)]
108
pub unsafe extern "C" fn htp_connp_open(
1,591✔
109
    connp: *mut ConnectionParser, client_addr: *const libc::c_char, client_port: libc::c_int,
1,591✔
110
    server_addr: *const libc::c_char, server_port: libc::c_int, timestamp: *const libc::timeval,
1,591✔
111
) {
1,591✔
112
    if let Some(connp) = connp.as_mut() {
1,591✔
113
        connp.open(
1,591✔
114
            client_addr.as_ref().and_then(|client_addr| {
1,591✔
115
                CStr::from_ptr(client_addr)
×
116
                    .to_str()
×
117
                    .ok()
×
118
                    .and_then(|val| val.parse().ok())
×
119
            }),
1,591✔
120
            client_port.try_into().ok(),
1,591✔
121
            server_addr.as_ref().and_then(|server_addr| {
1,591✔
122
                CStr::from_ptr(server_addr)
×
123
                    .to_str()
×
124
                    .ok()
×
125
                    .and_then(|val| val.parse().ok())
×
126
            }),
1,591✔
127
            server_port.try_into().ok(),
1,591✔
128
            timestamp
1,591✔
129
                .as_ref()
1,591✔
130
                .map(|val| datetime_from_sec_usec(val.tv_sec.into(), val.tv_usec.into()))
1,591✔
131
                .unwrap_or(None),
1,591✔
132
        )
1,591✔
133
    }
×
134
}
1,591✔
135

136
/// Closes the connection associated with the supplied parser.
137
///
138
/// timestamp is optional
139
/// # Safety
140
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
141
#[no_mangle]
142
#[allow(clippy::useless_conversion)]
143
pub unsafe extern "C" fn htp_connp_request_close(
1,426✔
144
    connp: *mut ConnectionParser, timestamp: *const libc::timeval,
1,426✔
145
) {
1,426✔
146
    if let Some(connp) = connp.as_mut() {
1,426✔
147
        connp.request_close(
1,426✔
148
            timestamp
1,426✔
149
                .as_ref()
1,426✔
150
                .map(|val| datetime_from_sec_usec(val.tv_sec.into(), val.tv_usec.into()))
1,426✔
151
                .unwrap_or(None),
1,426✔
152
        )
1,426✔
153
    }
×
154
}
1,426✔
155

156
/// Process a chunk of inbound client request data
157
///
158
/// timestamp is optional
159
/// Returns HTP_STREAM_STATE_DATA, HTP_STREAM_STATE_ERROR or HTP_STREAM_STATE_DATA_OTHER (see QUICK_START).
160
///         HTP_STREAM_STATE_CLOSED and HTP_STREAM_STATE_TUNNEL are also possible.
161
/// # Safety
162
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
163
#[no_mangle]
164
#[allow(clippy::useless_conversion)]
165
pub unsafe extern "C" fn htp_connp_request_data(
2,430✔
166
    connp: *mut ConnectionParser, timestamp: *const libc::timeval, data: *const libc::c_void,
2,430✔
167
    len: libc::size_t,
2,430✔
168
) -> HtpStreamState {
2,430✔
169
    connp
2,430✔
170
        .as_mut()
2,430✔
171
        .map(|connp| {
2,430✔
172
            connp.request_data(
2,430✔
173
                ParserData::from((data as *const u8, len)),
2,430✔
174
                timestamp
2,430✔
175
                    .as_ref()
2,430✔
176
                    .map(|val| datetime_from_sec_usec(val.tv_sec.into(), val.tv_usec.into()))
2,430✔
177
                    .unwrap_or(None),
2,430✔
178
            )
2,430✔
179
        })
2,430✔
180
        .unwrap_or(HtpStreamState::ERROR)
2,430✔
181
}
2,430✔
182

183
/// Process a chunk of outbound (server or response) data.
184
///
185
/// timestamp is optional.
186
/// Returns HTP_STREAM_STATE_OK on state change, HTP_STREAM_STATE_ERROR on error, or HTP_STREAM_STATE_DATA when more data is needed
187
/// # Safety
188
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
189
#[no_mangle]
190
#[allow(clippy::useless_conversion)]
191
pub unsafe extern "C" fn htp_connp_response_data(
7,346✔
192
    connp: *mut ConnectionParser, timestamp: *const libc::timeval, data: *const libc::c_void,
7,346✔
193
    len: libc::size_t,
7,346✔
194
) -> HtpStreamState {
7,346✔
195
    connp
7,346✔
196
        .as_mut()
7,346✔
197
        .map(|connp| {
7,346✔
198
            connp.response_data(
7,346✔
199
                ParserData::from((data as *const u8, len)),
7,346✔
200
                timestamp
7,346✔
201
                    .as_ref()
7,346✔
202
                    .map(|val| datetime_from_sec_usec(val.tv_sec.into(), val.tv_usec.into()))
7,346✔
203
                    .unwrap_or(None),
7,346✔
204
            )
7,346✔
205
        })
7,346✔
206
        .unwrap_or(HtpStreamState::ERROR)
7,346✔
207
}
7,346✔
208

209
/// Get the number of transactions processed on this connection.
210
///
211
/// Returns the number of transactions or -1 on error.
212
/// # Safety
213
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
214
#[no_mangle]
215
pub unsafe extern "C" fn htp_connp_tx_size(connp: *const ConnectionParser) -> isize {
242,796✔
216
    connp
242,796✔
217
        .as_ref()
242,796✔
218
        .map(|connp| isize::try_from(connp.tx_size()).unwrap_or(-1))
242,796✔
219
        .unwrap_or(-1)
242,796✔
220
}
242,796✔
221

222
/// Get a transaction by its index for the iterator.
223
/// # Safety
224
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
225
#[no_mangle]
226
pub unsafe extern "C" fn htp_connp_tx_index(
154,766✔
227
    connp: *mut ConnectionParser, index: usize,
154,766✔
228
) -> *mut Transaction {
154,766✔
229
    if let Some(tx) = connp.as_mut().unwrap().tx_index(index) {
154,766✔
230
        if tx.is_started() {
154,299✔
231
            return tx as *mut Transaction;
133,095✔
232
        }
21,204✔
233
    }
467✔
234
    std::ptr::null_mut()
21,671✔
235
}
154,766✔
236

237
/// Get a transaction.
238
///
239
/// Returns the transaction or NULL on error.
240
/// # Safety
241
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
242
#[no_mangle]
243
pub unsafe extern "C" fn htp_connp_tx(
3,398✔
244
    connp: *mut ConnectionParser, tx_id: usize,
3,398✔
245
) -> *const Transaction {
3,398✔
246
    connp
3,398✔
247
        .as_ref()
3,398✔
248
        .map(|connp| {
3,398✔
249
            connp
3,398✔
250
                .tx(tx_id)
3,398✔
251
                .map(|tx| {
3,398✔
252
                    if tx.is_started() {
3,397✔
253
                        tx as *const Transaction
2,989✔
254
                    } else {
255
                        std::ptr::null()
408✔
256
                    }
257
                })
3,398✔
258
                .unwrap_or(std::ptr::null())
3,398✔
259
        })
3,398✔
260
        .unwrap_or(std::ptr::null())
3,398✔
261
}
3,398✔
262

263
/// Retrieves the pointer to the active response transaction. In connection
264
/// parsing mode there can be many open transactions, and up to 2 active
265
/// transactions at any one time. This is due to HTTP pipelining. Can be NULL.
266
/// # Safety
267
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
268
#[no_mangle]
269
pub unsafe extern "C" fn htp_connp_get_response_tx(
9✔
270
    connp: *mut ConnectionParser,
9✔
271
) -> *const Transaction {
9✔
272
    if let Some(connp) = connp.as_mut() {
9✔
273
        if let Some(req) = connp.response() {
9✔
274
            return req;
9✔
275
        }
×
276
    }
×
277
    std::ptr::null()
×
278
}
9✔
279

280
/// Retrieves the pointer to the active request transaction. In connection
281
/// parsing mode there can be many open transactions, and up to 2 active
282
/// transactions at any one time. This is due to HTTP pipelining. Call be NULL.
283
/// # Safety
284
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
285
#[no_mangle]
286
pub unsafe extern "C" fn htp_connp_get_request_tx(
×
287
    connp: *mut ConnectionParser,
×
288
) -> *const Transaction {
×
289
    if let Some(connp) = connp.as_mut() {
×
290
        if let Some(req) = connp.request() {
×
291
            return req;
×
292
        }
×
293
    }
×
294
    std::ptr::null()
×
295
}
×
296

297
/// Returns the number of bytes consumed from the current data chunks so far or -1 on error.
298
/// # Safety
299
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
300
#[no_mangle]
301
pub unsafe extern "C" fn htp_connp_request_data_consumed(connp: *const ConnectionParser) -> i64 {
4,416✔
302
    connp
4,416✔
303
        .as_ref()
4,416✔
304
        .map(|connp| connp.request_data_consumed().try_into().ok().unwrap_or(-1))
4,416✔
305
        .unwrap_or(-1)
4,416✔
306
}
4,416✔
307

308
/// Returns the number of bytes consumed from the most recent outbound data chunk. Normally, an invocation
309
/// of htp_connp_response_data() will consume all data from the supplied buffer, but there are circumstances
310
/// where only partial consumption is possible. In such cases HTP_STREAM_DATA_OTHER will be returned.
311
/// Consumed bytes are no longer necessary, but the remainder of the buffer will be need to be saved
312
/// for later.
313
/// Returns the number of bytes consumed from the last data chunk sent for outbound processing
314
/// or -1 on error.
315
/// # Safety
316
/// When calling this method, you have to ensure that connp is either properly initialized or NULL
317
#[no_mangle]
318
pub unsafe extern "C" fn htp_connp_response_data_consumed(connp: *const ConnectionParser) -> i64 {
4,435✔
319
    connp
4,435✔
320
        .as_ref()
4,435✔
321
        .map(|connp| connp.response_data_consumed().try_into().ok().unwrap_or(-1))
4,435✔
322
        .unwrap_or(-1)
4,435✔
323
}
4,435✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc