rust: bindgen more http range functions used in http2

Ticket: 7667
pull/14070/head
Philippe Antoine 4 weeks ago committed by Victor Julien
parent 842352c190
commit dc7874b2ac

@ -29,9 +29,8 @@ use nom7::character::complete::{char, digit1};
use nom7::combinator::{map_res, value};
use nom7::error::{make_error, ErrorKind};
use nom7::{Err, IResult};
use std::os::raw::c_uchar;
use std::str::FromStr;
use suricata_sys::sys::HttpRangeContainerBlock;
use suricata_sys::sys::{HttpRangeContainerBlock, SCHttpRangeContainerOpenFile, SCHttpRangeAppendData};
// Defined in app-layer-htp-file.h
#[allow(unused_doc_comments)]
@ -167,11 +166,11 @@ pub fn http2_range_open(
if let Ok((key, index)) = http2_range_key_get(tx) {
let name = &key[index..];
tx.file_range = unsafe {
HttpRangeContainerOpenFile(
SCHttpRangeContainerOpenFile(
key.as_ptr(),
key.len() as u32,
flow,
v,
v as *const _ as *const suricata_sys::sys::HTTPContentRange,
cfg.files_sbcfg,
name.as_ptr(),
name.len() as u16,
@ -187,7 +186,7 @@ pub fn http2_range_append(
cfg: &'static SuricataFileContext, fr: *mut HttpRangeContainerBlock, data: &[u8],
) {
unsafe {
HttpRangeAppendData(cfg.files_sbcfg, fr, data.as_ptr(), data.len() as u32);
SCHttpRangeAppendData(cfg.files_sbcfg, fr, data.as_ptr(), data.len() as u32);
}
}
@ -219,19 +218,6 @@ pub fn http2_range_close(tx: &mut HTTP2Transaction, dir: Direction, data: &[u8])
}
}
// Defined in app-layer-htp-range.h
extern "C" {
pub fn HttpRangeContainerOpenFile(
key: *const c_uchar, keylen: u32, f: *const Flow, cr: &HTTPContentRange,
sbcfg: *const StreamingBufferConfig, name: *const c_uchar, name_len: u16, flags: u16,
data: *const c_uchar, data_len: u32,
) -> *mut HttpRangeContainerBlock;
pub fn HttpRangeAppendData(
cfg: *const StreamingBufferConfig, c: *mut HttpRangeContainerBlock, data: *const c_uchar,
data_len: u32,
) -> std::os::raw::c_int;
}
#[cfg(test)]
mod tests {

@ -883,6 +883,11 @@ pub struct HttpRangeContainerBuffer {
pub struct HttpRangeContainerFile {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct HTTPContentRange {
_unused: [u8; 0],
}
#[doc = " A structure representing a single range request :\n either skipping, buffering, or appending\n As this belongs to a flow, appending data to it is ensured to be thread-safe\n Only one block per file has the pointer to the container"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@ -899,6 +904,20 @@ pub struct HttpRangeContainerBlock {
extern "C" {
pub fn SCHttpRangeFreeBlock(b: *mut HttpRangeContainerBlock);
}
extern "C" {
pub fn SCHttpRangeContainerOpenFile(
key: *const ::std::os::raw::c_uchar, keylen: u32, f: *const Flow,
cr: *const HTTPContentRange, sbcfg: *const StreamingBufferConfig,
name: *const ::std::os::raw::c_uchar, name_len: u16, flags: u16,
data: *const ::std::os::raw::c_uchar, data_len: u32,
) -> *mut HttpRangeContainerBlock;
}
extern "C" {
pub fn SCHttpRangeAppendData(
sbcfg: *const StreamingBufferConfig, c: *mut HttpRangeContainerBlock, data: *const u8,
len: u32,
) -> ::std::os::raw::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MpmPattern_ {

@ -198,7 +198,7 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena
SCReturnInt(0);
}
DEBUG_VALIDATE_BUG_ON(htud->file_range);
htud->file_range = HttpRangeContainerOpenFile(keyurl, keylen, s->f, &crparsed, &htp_sbcfg,
htud->file_range = SCHttpRangeContainerOpenFile(keyurl, keylen, s->f, &crparsed, &htp_sbcfg,
filename, filename_len, flags, data, data_len);
SCFree(keyurl);
if (htud->file_range == NULL) {
@ -242,7 +242,7 @@ int HTPFileStoreChunk(HtpTxUserData *tx, const uint8_t *data, uint32_t data_len,
}
if (tx->file_range != NULL) {
if (HttpRangeAppendData(&htp_sbcfg, tx->file_range, data, data_len) < 0) {
if (SCHttpRangeAppendData(&htp_sbcfg, tx->file_range, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
}
@ -268,7 +268,7 @@ bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer
const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len)
{
bool added = false;
if (HttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
if (c->container) {

@ -332,14 +332,14 @@ static HttpRangeContainerBlock *HttpRangeOpenFile(HttpRangeContainerFile *c, uin
HttpRangeContainerBlock *r =
HttpRangeOpenFileAux(c, start, end, total, sbcfg, name, name_len, flags);
if (r) {
if (HttpRangeAppendData(sbcfg, r, data, len) < 0) {
if (SCHttpRangeAppendData(sbcfg, r, data, len) < 0) {
SCLogDebug("Failed to append data while opening");
}
}
return r;
}
HttpRangeContainerBlock *HttpRangeContainerOpenFile(const uint8_t *key, uint32_t keylen,
HttpRangeContainerBlock *SCHttpRangeContainerOpenFile(const uint8_t *key, uint32_t keylen,
const Flow *f, const HTTPContentRange *crparsed, const StreamingBufferConfig *sbcfg,
const uint8_t *name, uint16_t name_len, uint16_t flags, const uint8_t *data,
uint32_t data_len)
@ -375,7 +375,7 @@ HttpRangeContainerBlock *HttpRangeContainerOpenFile(const uint8_t *key, uint32_t
return r;
}
int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
const uint8_t *data, uint32_t len)
{
if (len == 0) {

@ -23,6 +23,7 @@
// forward declarations
typedef struct HttpRangeContainerBuffer HttpRangeContainerBuffer;
typedef struct HttpRangeContainerFile HttpRangeContainerFile;
typedef struct HTTPContentRange HTTPContentRange;
/** A structure representing a single range request :
* either skipping, buffering, or appending
@ -42,6 +43,15 @@ typedef struct HttpRangeContainerBlock {
void SCHttpRangeFreeBlock(HttpRangeContainerBlock *b);
// HttpRangeContainerBlock but trouble with headers inclusion order
HttpRangeContainerBlock *SCHttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen,
const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg,
const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data,
uint32_t data_len);
int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
const uint8_t *data, uint32_t len);
#ifndef SURICATA_BINDGEN_H
#include "util-streaming-buffer.h"
@ -106,17 +116,9 @@ typedef struct HttpRangeContainerFile {
bool error;
} HttpRangeContainerFile;
int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c,
const uint8_t *data, uint32_t len);
File *HttpRangeClose(
const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags);
// HttpRangeContainerBlock but trouble with headers inclusion order
HttpRangeContainerBlock *HttpRangeContainerOpenFile(const unsigned char *key, uint32_t keylen,
const Flow *f, const HTTPContentRange *cr, const StreamingBufferConfig *sbcfg,
const unsigned char *name, uint16_t name_len, uint16_t flags, const unsigned char *data,
uint32_t data_len);
uint64_t HTPByteRangeMemcapGlobalCounter(void);
uint64_t HTPByteRangeMemuseGlobalCounter(void);
int HTPByteRangeSetMemcap(uint64_t);

Loading…
Cancel
Save