Skip to content

Commit 15b1bf4

Browse files
catenacybervictorjulien
authored andcommitted
rust: bindgen SCHTPFileCloseHandleRange
Ticket: 7762
1 parent cddbd0b commit 15b1bf4

6 files changed

Lines changed: 49 additions & 46 deletions

File tree

rust/src/http2/range.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
*/
1717

1818
use super::detect;
19-
use crate::core::{StreamingBufferConfig, SuricataFileContext};
19+
use crate::core::SuricataFileContext;
2020
use crate::direction::Direction;
21-
use crate::filecontainer::FileContainer;
2221
use crate::flow::Flow;
2322
use crate::http2::http2::HTTP2Transaction;
2423
use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG;
@@ -30,25 +29,22 @@ use nom7::combinator::{map_res, value};
3029
use nom7::error::{make_error, ErrorKind};
3130
use nom7::{Err, IResult};
3231
use std::str::FromStr;
33-
use suricata_sys::sys::{HttpRangeContainerBlock, SCHttpRangeContainerOpenFile, SCHttpRangeAppendData};
34-
35-
// Defined in app-layer-htp-file.h
36-
#[allow(unused_doc_comments)]
37-
/// cbindgen:ignore
38-
extern "C" {
39-
#[cfg(not(test))]
40-
pub fn SCHTPFileCloseHandleRange(
41-
sbcfg: &StreamingBufferConfig, fc: *mut FileContainer, flags: u16,
42-
c: *mut HttpRangeContainerBlock, data: *const u8, data_len: u32,
43-
) -> bool;
44-
}
32+
use suricata_sys::sys::{
33+
HttpRangeContainerBlock, SCHttpRangeAppendData, SCHttpRangeContainerOpenFile,
34+
};
4535

4636
#[cfg(test)]
4737
#[allow(non_snake_case)]
4838
pub(super) unsafe fn SCHttpRangeFreeBlock(_range: *mut HttpRangeContainerBlock) {}
4939
#[cfg(not(test))]
5040
pub(super) use suricata_sys::sys::SCHttpRangeFreeBlock;
5141

42+
#[cfg(test)]
43+
use crate::core::StreamingBufferConfig;
44+
#[cfg(test)]
45+
use crate::filecontainer::FileContainer;
46+
#[cfg(not(test))]
47+
pub(super) use suricata_sys::sys::SCHTPFileCloseHandleRange;
5248
#[cfg(test)]
5349
#[allow(non_snake_case)]
5450
pub(super) unsafe fn SCHTPFileCloseHandleRange(

rust/sys/src/sys.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,12 @@ extern "C" {
11311131
len: u32,
11321132
) -> ::std::os::raw::c_int;
11331133
}
1134+
extern "C" {
1135+
pub fn SCHTPFileCloseHandleRange(
1136+
sbcfg: *const StreamingBufferConfig, arg1: *mut FileContainer, arg2: u16,
1137+
arg3: *mut HttpRangeContainerBlock, arg4: *const u8, arg5: u32,
1138+
) -> bool;
1139+
}
11341140
pub type FrameId = i64;
11351141
#[repr(C)]
11361142
#[derive(Debug, Default, Copy, Clone)]

src/app-layer-htp-file.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -260,36 +260,6 @@ int HTPFileStoreChunk(HtpTxUserData *tx, const uint8_t *data, uint32_t data_len,
260260
SCReturnInt(retval);
261261
}
262262

263-
/** \brief close range, add reassembled file if possible
264-
* \retval true if reassembled file was added
265-
* \retval false if no reassembled file was added
266-
*/
267-
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files,
268-
const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len)
269-
{
270-
bool added = false;
271-
if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
272-
SCLogDebug("Failed to append data");
273-
}
274-
if (c->container) {
275-
// we only call HttpRangeClose if we may some new data
276-
// ie we do not call it if we skipped all this range request
277-
THashDataLock(c->container->hdata);
278-
if (c->container->error) {
279-
SCLogDebug("range in ERROR state");
280-
}
281-
File *ranged = HttpRangeClose(sbcfg, c, flags);
282-
if (ranged && files) {
283-
/* HtpState owns the constructed file now */
284-
FileContainerAdd(files, ranged);
285-
added = true;
286-
}
287-
DEBUG_VALIDATE_BUG_ON(ranged && !files);
288-
THashDataUnlock(c->container->hdata);
289-
}
290-
return added;
291-
}
292-
293263
/**
294264
* \brief Close the file in the flow
295265
*

src/app-layer-htp-file.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ int HTPFileOpen(
3131
HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint8_t);
3232
int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *,
3333
uint32_t, const htp_tx_t *, const bstr *rawvalue, HtpTxUserData *htud);
34-
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t,
35-
HttpRangeContainerBlock *, const uint8_t *, uint32_t);
3634
int HTPFileStoreChunk(HtpTxUserData *, const uint8_t *, uint32_t, uint8_t);
3735

3836
int HTPParseContentRange(const bstr *rawvalue, HTTPContentRange *range);

src/app-layer-htp-range.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,33 @@ void SCHttpRangeFreeBlock(HttpRangeContainerBlock *b)
627627
SCFree(b);
628628
}
629629
}
630+
631+
/** \brief close range, add reassembled file if possible
632+
* \retval true if reassembled file was added
633+
* \retval false if no reassembled file was added
634+
*/
635+
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files,
636+
const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len)
637+
{
638+
bool added = false;
639+
if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
640+
SCLogDebug("Failed to append data");
641+
}
642+
if (c->container) {
643+
// we only call HttpRangeClose if we may some new data
644+
// ie we do not call it if we skipped all this range request
645+
THashDataLock(c->container->hdata);
646+
if (c->container->error) {
647+
SCLogDebug("range in ERROR state");
648+
}
649+
File *ranged = HttpRangeClose(sbcfg, c, flags);
650+
if (ranged && files) {
651+
/* HtpState owns the constructed file now */
652+
FileContainerAdd(files, ranged);
653+
added = true;
654+
}
655+
DEBUG_VALIDATE_BUG_ON(ranged && !files);
656+
THashDataUnlock(c->container->hdata);
657+
}
658+
return added;
659+
}

src/app-layer-htp-range.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ HttpRangeContainerBlock *SCHttpRangeContainerOpenFile(const unsigned char *key,
5252
int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
5353
const uint8_t *data, uint32_t len);
5454

55+
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t,
56+
HttpRangeContainerBlock *, const uint8_t *, uint32_t);
57+
5558
#ifndef SURICATA_BINDGEN_H
5659

5760
#include "util-streaming-buffer.h"

0 commit comments

Comments
 (0)