HTTP2Event, HTTP2Frame, HTTP2FrameTypeData, HTTP2State, HTTP2Transaction, HTTP2TransactionState,
};
use super::parser;
-use crate::core::{STREAM_TOCLIENT, STREAM_TOSERVER};
+use crate::core::Direction;
use std::ffi::CStr;
use std::str::FromStr;
fn http2_tx_has_frametype(
- tx: &mut HTTP2Transaction, direction: u8, value: u8,
+ tx: &mut HTTP2Transaction, direction: Direction, value: u8,
) -> std::os::raw::c_int {
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
if tx.frames_ts[i].header.ftype as u8 == value {
return 1;
tx: *mut std::os::raw::c_void, direction: u8, value: u8,
) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_tx_has_frametype(tx, direction, value);
+ return http2_tx_has_frametype(tx, direction.into(), value);
}
#[no_mangle]
}
fn http2_tx_has_errorcode(
- tx: &mut HTTP2Transaction, direction: u8, code: u32,
+ tx: &mut HTTP2Transaction, direction: Direction, code: u32,
) -> std::os::raw::c_int {
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
match tx.frames_ts[i].data {
HTTP2FrameTypeData::GOAWAY(goaway) => {
tx: *mut std::os::raw::c_void, direction: u8, code: u32,
) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_tx_has_errorcode(tx, direction, code);
+ return http2_tx_has_errorcode(tx, direction.into(), code);
}
#[no_mangle]
}
fn http2_tx_get_next_priority(
- tx: &mut HTTP2Transaction, direction: u8, nb: u32,
+ tx: &mut HTTP2Transaction, direction: Direction, nb: u32,
) -> std::os::raw::c_int {
let mut pos = 0 as u32;
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
match &tx.frames_ts[i].data {
HTTP2FrameTypeData::PRIORITY(prio) => {
tx: *mut std::os::raw::c_void, direction: u8, nb: u32,
) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_tx_get_next_priority(tx, direction, nb);
+ return http2_tx_get_next_priority(tx, direction.into(), nb);
}
fn http2_tx_get_next_window(
- tx: &mut HTTP2Transaction, direction: u8, nb: u32,
+ tx: &mut HTTP2Transaction, direction: Direction, nb: u32,
) -> std::os::raw::c_int {
let mut pos = 0 as u32;
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
match tx.frames_ts[i].data {
HTTP2FrameTypeData::WINDOWUPDATE(wu) => {
tx: *mut std::os::raw::c_void, direction: u8, nb: u32,
) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_tx_get_next_window(tx, direction, nb);
+ return http2_tx_get_next_window(tx, direction.into(), nb);
}
#[no_mangle]
}
fn http2_detect_settingsctx_match(
- ctx: &mut parser::DetectHTTP2settingsSigCtx, tx: &mut HTTP2Transaction, direction: u8,
+ ctx: &mut parser::DetectHTTP2settingsSigCtx, tx: &mut HTTP2Transaction, direction: Direction,
) -> std::os::raw::c_int {
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
match &tx.frames_ts[i].data {
HTTP2FrameTypeData::SETTINGS(set) => {
) -> std::os::raw::c_int {
let ctx = cast_pointer!(ctx, parser::DetectHTTP2settingsSigCtx);
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_detect_settingsctx_match(ctx, tx, direction);
+ return http2_detect_settingsctx_match(ctx, tx, direction.into());
}
#[no_mangle]
}
fn http2_detect_sizeupdatectx_match(
- ctx: &mut parser::DetectU64Data, tx: &mut HTTP2Transaction, direction: u8,
+ ctx: &mut parser::DetectU64Data, tx: &mut HTTP2Transaction, direction: Direction,
) -> std::os::raw::c_int {
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
for i in 0..tx.frames_ts.len() {
if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
if http2_detect_sizeupdate_match(blocks, ctx) != 0 {
) -> std::os::raw::c_int {
let ctx = cast_pointer!(ctx, parser::DetectU64Data);
let tx = cast_pointer!(tx, HTTP2Transaction);
- return http2_detect_sizeupdatectx_match(ctx, tx, direction);
+ return http2_detect_sizeupdatectx_match(ctx, tx, direction.into());
}
//TODOask better syntax between rs_http2_tx_get_header_name in argument
tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
let mut pos = 0 as u32;
- if direction & STREAM_TOSERVER != 0 {
- for i in 0..tx.frames_ts.len() {
- if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
- if nb < pos + blocks.len() as u32 {
- let value = &blocks[(nb - pos) as usize].name;
- *buffer = value.as_ptr(); //unsafe
- *buffer_len = value.len() as u32;
- return 1;
- } else {
- pos = pos + blocks.len() as u32;
+ match direction.into() {
+ Direction::ToServer => {
+ for i in 0..tx.frames_ts.len() {
+ if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
+ if nb < pos + blocks.len() as u32 {
+ let value = &blocks[(nb - pos) as usize].name;
+ *buffer = value.as_ptr(); //unsafe
+ *buffer_len = value.len() as u32;
+ return 1;
+ } else {
+ pos = pos + blocks.len() as u32;
+ }
}
}
}
- } else {
- for i in 0..tx.frames_tc.len() {
- if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
- if nb < pos + blocks.len() as u32 {
- let value = &blocks[(nb - pos) as usize].name;
- *buffer = value.as_ptr(); //unsafe
- *buffer_len = value.len() as u32;
- return 1;
- } else {
- pos = pos + blocks.len() as u32;
+ Direction::ToClient => {
+ for i in 0..tx.frames_tc.len() {
+ if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
+ if nb < pos + blocks.len() as u32 {
+ let value = &blocks[(nb - pos) as usize].name;
+ *buffer = value.as_ptr(); //unsafe
+ *buffer_len = value.len() as u32;
+ return 1;
+ } else {
+ pos = pos + blocks.len() as u32;
+ }
}
}
}
}
fn http2_frames_get_header_firstvalue<'a>(
- tx: &'a mut HTTP2Transaction, direction: u8, name: &str,
+ tx: &'a mut HTTP2Transaction, direction: Direction, name: &str,
) -> Result<&'a [u8], ()> {
- let frames = if direction == STREAM_TOSERVER {
+ let frames = if direction == Direction::ToServer {
&tx.frames_ts
} else {
&tx.frames_tc
// same as http2_frames_get_header_value but returns a new Vec
// instead of using the transation to store the result slice
pub fn http2_frames_get_header_value_vec(
- tx: &HTTP2Transaction, direction: u8, name: &str,
+ tx: &HTTP2Transaction, direction: Direction, name: &str,
) -> Result<Vec<u8>, ()> {
let mut found = 0;
let mut vec = Vec::new();
- let frames = if direction == STREAM_TOSERVER {
+ let frames = if direction == Direction::ToServer {
&tx.frames_ts
} else {
&tx.frames_tc
}
fn http2_frames_get_header_value<'a>(
- tx: &'a mut HTTP2Transaction, direction: u8, name: &str,
+ tx: &'a mut HTTP2Transaction, direction: Direction, name: &str,
) -> Result<&'a [u8], ()> {
let mut found = 0;
let mut vec = Vec::new();
let mut single: Result<&[u8], ()> = Err(());
- let frames = if direction == STREAM_TOSERVER {
+ let frames = if direction == Direction::ToServer {
&tx.frames_ts
} else {
&tx.frames_tc
pub unsafe extern "C" fn rs_http2_tx_get_uri(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_firstvalue(tx, STREAM_TOSERVER, ":path") {
+ if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":path") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
pub unsafe extern "C" fn rs_http2_tx_get_method(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_firstvalue(tx, STREAM_TOSERVER, ":method") {
+ if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":method") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
pub unsafe extern "C" fn rs_http2_tx_get_host(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_value(tx, STREAM_TOSERVER, ":authority") {
+ if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, ":authority") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
pub unsafe extern "C" fn rs_http2_tx_get_host_norm(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_value(tx, STREAM_TOSERVER, ":authority") {
+ if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, ":authority") {
let r = http2_normalize_host(value);
// r is a tuple with the value and its size
// this is useful when we only take a substring (before the port)
pub unsafe extern "C" fn rs_http2_tx_get_useragent(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_value(tx, STREAM_TOSERVER, "user-agent") {
+ if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, "user-agent") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
pub unsafe extern "C" fn rs_http2_tx_get_status(
tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if let Ok(value) = http2_frames_get_header_firstvalue(tx, STREAM_TOCLIENT, ":status") {
+ if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToClient, ":status") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
pub unsafe extern "C" fn rs_http2_tx_get_cookie(
tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
- if direction == STREAM_TOSERVER {
- if let Ok(value) = http2_frames_get_header_value(tx, STREAM_TOSERVER, "cookie") {
+ if direction == Direction::ToServer.into() {
+ if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, "cookie") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
}
} else {
- if let Ok(value) = http2_frames_get_header_value(tx, STREAM_TOCLIENT, "set-cookie") {
+ if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToClient, "set-cookie") {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
) -> u8 {
let hname: &CStr = CStr::from_ptr(strname); //unsafe
if let Ok(s) = hname.to_str() {
- if let Ok(value) = http2_frames_get_header_value(tx, direction, &s.to_lowercase()) {
+ if let Ok(value) = http2_frames_get_header_value(tx, direction.into(), &s.to_lowercase()) {
*buffer = value.as_ptr(); //unsafe
*buffer_len = value.len() as u32;
return 1;
tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
let mut vec = vec![b'\r', b'\n'];
- let frames = if direction & STREAM_TOSERVER != 0 {
+ let frames = if direction & Direction::ToServer as u8 != 0 {
&tx.frames_ts
} else {
&tx.frames_tc
return 0;
}
-fn http2_header_iscookie(direction: u8, hname: &[u8]) -> bool {
+fn http2_header_iscookie(direction: Direction, hname: &[u8]) -> bool {
if let Ok(s) = std::str::from_utf8(hname) {
- if direction & STREAM_TOSERVER != 0 {
+ if direction == Direction::ToServer {
if s.to_lowercase() == "cookie" {
return true;
}
tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
let mut vec = Vec::new();
- let frames = if direction & STREAM_TOSERVER != 0 {
+ let frames = if direction & Direction::ToServer as u8 != 0 {
&tx.frames_ts
} else {
&tx.frames_tc
for i in 0..frames.len() {
if let Some(blocks) = http2_header_blocks(&frames[i]) {
for block in blocks.iter() {
- if !http2_header_iscookie(direction, &block.name) {
+ if !http2_header_iscookie(direction.into(), &block.name) {
// we do not escape linefeeds nor : in headers names
vec.extend_from_slice(&block.name);
vec.extend_from_slice(&[b':', b' ']);
tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
let mut vec = Vec::new();
- let frames = if direction & STREAM_TOSERVER != 0 {
+ let frames = if direction & Direction::ToServer as u8 != 0 {
&tx.frames_ts
} else {
&tx.frames_tc
tx: &mut HTTP2Transaction, direction: u8, nb: u32, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
let mut pos = 0 as u32;
- if direction & STREAM_TOSERVER != 0 {
- for i in 0..tx.frames_ts.len() {
- if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
- if nb < pos + blocks.len() as u32 {
- let ehdr = http2_escape_header(&blocks, nb - pos);
- tx.escaped.push(ehdr);
- let idx = tx.escaped.len() - 1;
- let value = &tx.escaped[idx];
- *buffer = value.as_ptr(); //unsafe
- *buffer_len = value.len() as u32;
- return 1;
- } else {
- pos = pos + blocks.len() as u32;
+ match direction.into() {
+ Direction::ToServer => {
+ for i in 0..tx.frames_ts.len() {
+ if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
+ if nb < pos + blocks.len() as u32 {
+ let ehdr = http2_escape_header(&blocks, nb - pos);
+ tx.escaped.push(ehdr);
+ let idx = tx.escaped.len() - 1;
+ let value = &tx.escaped[idx];
+ *buffer = value.as_ptr(); //unsafe
+ *buffer_len = value.len() as u32;
+ return 1;
+ } else {
+ pos = pos + blocks.len() as u32;
+ }
}
}
}
- } else {
- for i in 0..tx.frames_tc.len() {
- if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
- if nb < pos + blocks.len() as u32 {
- let ehdr = http2_escape_header(&blocks, nb - pos);
- tx.escaped.push(ehdr);
- let idx = tx.escaped.len() - 1;
- let value = &tx.escaped[idx];
- *buffer = value.as_ptr(); //unsafe
- *buffer_len = value.len() as u32;
- return 1;
- } else {
- pos = pos + blocks.len() as u32;
+ Direction::ToClient => {
+ for i in 0..tx.frames_tc.len() {
+ if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
+ if nb < pos + blocks.len() as u32 {
+ let ehdr = http2_escape_header(&blocks, nb - pos);
+ tx.escaped.push(ehdr);
+ let idx = tx.escaped.len() - 1;
+ let value = &tx.escaped[idx];
+ *buffer = value.as_ptr(); //unsafe
+ *buffer_len = value.len() as u32;
+ return 1;
+ } else {
+ pos = pos + blocks.len() as u32;
+ }
}
}
}
}
-
return 0;
}
blocks: blocks,
};
let txdata = HTTP2FrameTypeData::HEADERS(hs);
- let tx = state.find_or_create_tx(&head, &txdata, STREAM_TOSERVER);
+ let tx = state.find_or_create_tx(&head, &txdata, Direction::ToServer);
tx.frames_ts.push(HTTP2Frame {
header: head,
data: txdata,
match parser::http2_parse_frame_settings(&dec) {
Ok((_, set)) => {
let txdata = HTTP2FrameTypeData::SETTINGS(set);
- let tx = state.find_or_create_tx(&head, &txdata, STREAM_TOSERVER);
+ let tx = state.find_or_create_tx(&head, &txdata, Direction::ToServer);
tx.frames_ts.push(HTTP2Frame {
header: head,
data: txdata,
header: head,
data: txdata,
});
- match http2_frames_get_header_value(&mut tx, STREAM_TOSERVER, "Host") {
+ match http2_frames_get_header_value(&mut tx, Direction::ToServer, "Host") {
Ok(x) => {
assert_eq!(x, "abc.com, efg.net".as_bytes());
}
use super::range;
use crate::applayer::{self, *};
-use crate::core::{
- self, AppProto, Flow, HttpRangeContainerBlock, SuricataFileContext, ALPROTO_FAILED,
- ALPROTO_UNKNOWN, IPPROTO_TCP, SC, STREAM_TOCLIENT, STREAM_TOSERVER,
-};
+use crate::core::{self, *};
use crate::filecontainer::*;
use crate::filetracker::*;
use nom;
core::sc_app_layer_decoder_events_set_event_raw(&mut self.events, ev);
}
- fn handle_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: u8) {
+ fn handle_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: Direction) {
for i in 0..blocks.len() {
if blocks[i].name == "content-encoding".as_bytes().to_vec() {
self.decoder.http2_encoding_fromvec(&blocks[i].value, dir);
}
fn decompress<'a>(
- &'a mut self, input: &'a [u8], dir: u8, sfcm: &'static SuricataFileContext, over: bool,
- files: &mut FileContainer, flags: u16, flow: *const Flow,
+ &'a mut self, input: &'a [u8], dir: Direction, sfcm: &'static SuricataFileContext,
+ over: bool, files: &mut FileContainer, flags: u16, flow: *const Flow,
) -> io::Result<()> {
let mut output = Vec::with_capacity(decompression::HTTP2_DECOMPRESSION_CHUNK_SIZE);
let decompressed = self.decoder.decompress(input, &mut output, dir)?;
let xid: u32 = self.tx_id as u32;
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
self.ft_tc.tx_id = self.tx_id - 1;
if !self.ft_tc.file_open {
// we are now sure that new_chunk will open a file
self.tx_data.incr_files_opened();
if let Ok(value) = detect::http2_frames_get_header_value_vec(
self,
- STREAM_TOCLIENT,
+ Direction::ToClient,
"content-range",
) {
match range::http2_parse_check_content_range(&value) {
}
fn handle_frame(
- &mut self, header: &parser::HTTP2FrameHeader, data: &HTTP2FrameTypeData, dir: u8,
+ &mut self, header: &parser::HTTP2FrameHeader, data: &HTTP2FrameTypeData, dir: Direction,
) {
//handle child_stream_id changes
match data {
HTTP2FrameTypeData::PUSHPROMISE(hs) => {
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
//we could set an event if self.child_stream_id != 0
if header.flags & parser::HTTP2_FLAG_HEADER_END_HEADERS == 0 {
self.child_stream_id = hs.stream_id;
self.handle_headers(&hs.blocks, dir);
}
HTTP2FrameTypeData::CONTINUATION(hs) => {
- if dir == STREAM_TOCLIENT
+ if dir == Direction::ToClient
&& header.flags & parser::HTTP2_FLAG_HEADER_END_HEADERS != 0
{
self.child_stream_id = 0;
self.handle_headers(&hs.blocks, dir);
}
HTTP2FrameTypeData::HEADERS(hs) => {
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
self.child_stream_id = 0;
}
self.handle_headers(&hs.blocks, dir);
match self.state {
HTTP2TransactionState::HTTP2StateHalfClosedClient
| HTTP2TransactionState::HTTP2StateDataServer => {
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
self.state = HTTP2TransactionState::HTTP2StateClosed;
}
}
HTTP2TransactionState::HTTP2StateHalfClosedServer => {
- if dir == STREAM_TOSERVER {
+ if dir == Direction::ToServer {
self.state = HTTP2TransactionState::HTTP2StateClosed;
}
}
HTTP2TransactionState::HTTP2StateClosed => {}
HTTP2TransactionState::HTTP2StateGlobal => {}
_ => {
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
self.state = HTTP2TransactionState::HTTP2StateHalfClosedServer;
} else {
self.state = HTTP2TransactionState::HTTP2StateHalfClosedClient;
}
} else if header.ftype == parser::HTTP2FrameType::DATA as u8 {
//not end of stream
- if dir == STREAM_TOSERVER {
+ if dir == Direction::ToServer {
if self.state < HTTP2TransactionState::HTTP2StateDataClient {
self.state = HTTP2TransactionState::HTTP2StateDataClient;
}
}
pub fn find_or_create_tx(
- &mut self, header: &parser::HTTP2FrameHeader, data: &HTTP2FrameTypeData, dir: u8,
+ &mut self, header: &parser::HTTP2FrameHeader, data: &HTTP2FrameTypeData, dir: Direction,
) -> &mut HTTP2Transaction {
if header.stream_id == 0 {
return self.create_global_tx();
//yes, the right stream_id for Suricata is not the header one
HTTP2FrameTypeData::PUSHPROMISE(hs) => hs.stream_id,
HTTP2FrameTypeData::CONTINUATION(_) => {
- if dir == STREAM_TOCLIENT {
+ if dir == Direction::ToClient {
//continuation of a push promise
self.find_child_stream_id(header.stream_id)
} else {
}
}
- fn process_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: u8) {
+ fn process_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: Direction) {
let (mut update, mut sizeup) = (false, 0);
for i in 0..blocks.len() {
if blocks[i].error >= parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeError {
}
if update {
//borrow checker forbids to pass directly dyn_headers
- let dyn_headers = if dir == STREAM_TOCLIENT {
+ let dyn_headers = if dir == Direction::ToClient {
&mut self.dynamic_headers_tc
} else {
&mut self.dynamic_headers_ts
}
fn parse_frame_data(
- &mut self, ftype: u8, input: &[u8], complete: bool, hflags: u8, dir: u8,
+ &mut self, ftype: u8, input: &[u8], complete: bool, hflags: u8, dir: Direction,
) -> HTTP2FrameTypeData {
match num::FromPrimitive::from_u8(ftype) {
Some(parser::HTTP2FrameType::GOAWAY) => {
for i in 0..set.len() {
if set[i].id == parser::HTTP2SettingsId::SETTINGSHEADERTABLESIZE {
//reverse order as this is what we accept from the other endpoint
- let dyn_headers = if dir == STREAM_TOCLIENT {
+ let dyn_headers = if dir == Direction::ToClient {
&mut self.dynamic_headers_ts
} else {
&mut self.dynamic_headers_tc
}
}
Some(parser::HTTP2FrameType::PUSHPROMISE) => {
- let dyn_headers = if dir == STREAM_TOCLIENT {
+ let dyn_headers = if dir == Direction::ToClient {
&mut self.dynamic_headers_tc
} else {
&mut self.dynamic_headers_ts
return HTTP2FrameTypeData::DATA;
}
Some(parser::HTTP2FrameType::CONTINUATION) => {
- let dyn_headers = if dir == STREAM_TOCLIENT {
+ let dyn_headers = if dir == Direction::ToClient {
&mut self.dynamic_headers_tc
} else {
&mut self.dynamic_headers_ts
}
}
Some(parser::HTTP2FrameType::HEADERS) => {
- let dyn_headers = if dir == STREAM_TOCLIENT {
+ let dyn_headers = if dir == Direction::ToClient {
&mut self.dynamic_headers_tc
} else {
&mut self.dynamic_headers_ts
}
fn parse_frames(
- &mut self, mut input: &[u8], il: usize, dir: u8, flow: *const Flow,
+ &mut self, mut input: &[u8], il: usize, dir: Direction, flow: *const Flow,
) -> AppLayerResult {
while input.len() > 0 {
match parser::http2_parse_frame_header(input) {
let over = head.flags & parser::HTTP2_FLAG_HEADER_EOS != 0;
let ftype = head.ftype;
let sid = head.stream_id;
- if dir == STREAM_TOSERVER {
+ if dir == Direction::ToServer {
tx.frames_ts.push(HTTP2Frame {
header: head,
data: txdata,
let index = self.find_tx_index(sid);
if index > 0 {
let tx_same = &mut self.transactions[index - 1];
- let (files, flags) = self.files.get(dir.into());
+ let (files, flags) = self.files.get(dir);
match tx_same.decompress(
&rem[..hlsafe],
dir,
}
//then parse all we can
- let r = self.parse_frames(input, il, STREAM_TOSERVER, flow);
+ let r = self.parse_frames(input, il, Direction::ToServer, flow);
if r.status == 1 {
//adds bytes consumed by banner to incomplete result
return AppLayerResult::incomplete(r.consumed + magic_consumed as u32, r.needed);
}
}
//then parse all we can
- return self.parse_frames(input, il, STREAM_TOCLIENT, flow);
+ return self.parse_frames(input, il, Direction::ToClient, flow);
}
fn tx_iterator(
let state = cast_pointer!(state, HTTP2State);
let buf = build_slice!(input, input_len as usize);
- state.files.flags_ts = FileFlowToFlags(flow, STREAM_TOSERVER);
+ state.files.flags_ts = FileFlowToFlags(flow, Direction::ToServer.into());
state.files.flags_ts = state.files.flags_ts | FILE_USE_DETECT;
return state.parse_ts(buf, flow);
}
) -> AppLayerResult {
let state = cast_pointer!(state, HTTP2State);
let buf = build_slice!(input, input_len as usize);
- state.files.flags_tc = FileFlowToFlags(flow, STREAM_TOCLIENT);
+ state.files.flags_tc = FileFlowToFlags(flow, Direction::ToClient.into());
state.files.flags_tc = state.files.flags_tc | FILE_USE_DETECT;
return state.parse_tc(buf, flow);
}
state: *mut std::os::raw::c_void, direction: u8,
) -> *mut FileContainer {
let state = cast_pointer!(state, HTTP2State);
- if direction == STREAM_TOCLIENT {
+ if direction == Direction::ToClient.into() {
&mut state.files.files_tc as *mut FileContainer
} else {
&mut state.files.files_ts as *mut FileContainer