rust: bindgen SCHTPFileCloseHandleRange

Ticket: 7762
pull/14387/head
Philippe Antoine 10 months ago committed by Victor Julien
parent cddbd0b906
commit 15b1bf4865

@ -16,9 +16,8 @@
*/
use super::detect;
use crate::core::{StreamingBufferConfig, SuricataFileContext};
use crate::core::SuricataFileContext;
use crate::direction::Direction;
use crate::filecontainer::FileContainer;
use crate::flow::Flow;
use crate::http2::http2::HTTP2Transaction;
use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG;
@ -30,18 +29,9 @@ use nom7::combinator::{map_res, value};
use nom7::error::{make_error, ErrorKind};
use nom7::{Err, IResult};
use std::str::FromStr;
use suricata_sys::sys::{HttpRangeContainerBlock, SCHttpRangeContainerOpenFile, SCHttpRangeAppendData};
// Defined in app-layer-htp-file.h
#[allow(unused_doc_comments)]
/// cbindgen:ignore
extern "C" {
#[cfg(not(test))]
pub fn SCHTPFileCloseHandleRange(
sbcfg: &StreamingBufferConfig, fc: *mut FileContainer, flags: u16,
c: *mut HttpRangeContainerBlock, data: *const u8, data_len: u32,
) -> bool;
}
use suricata_sys::sys::{
HttpRangeContainerBlock, SCHttpRangeAppendData, SCHttpRangeContainerOpenFile,
};
#[cfg(test)]
#[allow(non_snake_case)]
@ -49,6 +39,12 @@ pub(super) unsafe fn SCHttpRangeFreeBlock(_range: *mut HttpRangeContainerBlock)
#[cfg(not(test))]
pub(super) use suricata_sys::sys::SCHttpRangeFreeBlock;
#[cfg(test)]
use crate::core::StreamingBufferConfig;
#[cfg(test)]
use crate::filecontainer::FileContainer;
#[cfg(not(test))]
pub(super) use suricata_sys::sys::SCHTPFileCloseHandleRange;
#[cfg(test)]
#[allow(non_snake_case)]
pub(super) unsafe fn SCHTPFileCloseHandleRange(

@ -1131,6 +1131,12 @@ extern "C" {
len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn SCHTPFileCloseHandleRange(
sbcfg: *const StreamingBufferConfig, arg1: *mut FileContainer, arg2: u16,
arg3: *mut HttpRangeContainerBlock, arg4: *const u8, arg5: u32,
) -> bool;
}
pub type FrameId = i64;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]

@ -260,36 +260,6 @@ end:
SCReturnInt(retval);
}
/** \brief close range, add reassembled file if possible
* \retval true if reassembled file was added
* \retval false if no reassembled file was added
*/
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files,
const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len)
{
bool added = false;
if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
if (c->container) {
// we only call HttpRangeClose if we may some new data
// ie we do not call it if we skipped all this range request
THashDataLock(c->container->hdata);
if (c->container->error) {
SCLogDebug("range in ERROR state");
}
File *ranged = HttpRangeClose(sbcfg, c, flags);
if (ranged && files) {
/* HtpState owns the constructed file now */
FileContainerAdd(files, ranged);
added = true;
}
DEBUG_VALIDATE_BUG_ON(ranged && !files);
THashDataUnlock(c->container->hdata);
}
return added;
}
/**
* \brief Close the file in the flow
*

@ -31,8 +31,6 @@ int HTPFileOpen(
HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint8_t);
int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *,
uint32_t, const htp_tx_t *, const bstr *rawvalue, HtpTxUserData *htud);
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t,
HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int HTPFileStoreChunk(HtpTxUserData *, const uint8_t *, uint32_t, uint8_t);
int HTPParseContentRange(const bstr *rawvalue, HTTPContentRange *range);

@ -627,3 +627,33 @@ void SCHttpRangeFreeBlock(HttpRangeContainerBlock *b)
SCFree(b);
}
}
/** \brief close range, add reassembled file if possible
* \retval true if reassembled file was added
* \retval false if no reassembled file was added
*/
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files,
const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len)
{
bool added = false;
if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
if (c->container) {
// we only call HttpRangeClose if we may some new data
// ie we do not call it if we skipped all this range request
THashDataLock(c->container->hdata);
if (c->container->error) {
SCLogDebug("range in ERROR state");
}
File *ranged = HttpRangeClose(sbcfg, c, flags);
if (ranged && files) {
/* HtpState owns the constructed file now */
FileContainerAdd(files, ranged);
added = true;
}
DEBUG_VALIDATE_BUG_ON(ranged && !files);
THashDataUnlock(c->container->hdata);
}
return added;
}

@ -52,6 +52,9 @@ HttpRangeContainerBlock *SCHttpRangeContainerOpenFile(const unsigned char *key,
int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
const uint8_t *data, uint32_t len);
bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t,
HttpRangeContainerBlock *, const uint8_t *, uint32_t);
#ifndef SURICATA_BINDGEN_H
#include "util-streaming-buffer.h"

Loading…
Cancel
Save