]>
Commit | Line | Data |
---|---|---|
c54fc7f9 JI |
1 | /* Copyright (C) 2017 Open Information Security Foundation |
2 | * | |
3 | * You can copy, redistribute or modify this Program under the terms of | |
4 | * the GNU General Public License version 2 as published by the Free | |
5 | * Software Foundation. | |
6 | * | |
7 | * This program is distributed in the hope that it will be useful, | |
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | * GNU General Public License for more details. | |
11 | * | |
12 | * You should have received a copy of the GNU General Public License | |
13 | * version 2 along with this program; if not, write to the Free Software | |
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
15 | * 02110-1301, USA. | |
16 | */ | |
17 | ||
e96d9c11 VJ |
18 | extern crate libc; |
19 | use std; | |
20 | ||
21 | #[repr(C)] | |
22 | pub struct AppLayerGetTxIterTuple { | |
23 | tx_ptr: *mut libc::c_void, | |
24 | tx_id: u64, | |
25 | has_next: bool, | |
26 | } | |
27 | ||
28 | impl AppLayerGetTxIterTuple { | |
29 | pub fn with_values(tx_ptr: *mut libc::c_void, tx_id: u64, has_next: bool) -> AppLayerGetTxIterTuple { | |
30 | AppLayerGetTxIterTuple { | |
31 | tx_ptr: tx_ptr, tx_id: tx_id, has_next: has_next, | |
32 | } | |
33 | } | |
34 | pub fn not_found() -> AppLayerGetTxIterTuple { | |
35 | AppLayerGetTxIterTuple { | |
36 | tx_ptr: std::ptr::null_mut(), tx_id: 0, has_next: false, | |
37 | } | |
38 | } | |
39 | } | |
40 | ||
c54fc7f9 JI |
41 | /// LoggerFlags tracks which loggers have already been executed. |
42 | #[derive(Debug)] | |
43 | pub struct LoggerFlags { | |
44 | flags: u32, | |
45 | } | |
46 | ||
47 | impl LoggerFlags { | |
48 | ||
49 | pub fn new() -> LoggerFlags { | |
50 | return LoggerFlags{ | |
51 | flags: 0, | |
52 | } | |
53 | } | |
54 | ||
bca0cd71 VJ |
55 | pub fn get(&self) -> u32 { |
56 | self.flags | |
57 | } | |
58 | ||
59 | pub fn set(&mut self, bits: u32) { | |
60 | self.flags = bits; | |
61 | } | |
62 | ||
c54fc7f9 | 63 | } |
2ec33816 JI |
64 | |
65 | /// Export a function to get the DetectEngineState on a struct. | |
66 | #[macro_export] | |
67 | macro_rules!export_tx_get_detect_state { | |
68 | ($name:ident, $type:ty) => ( | |
69 | #[no_mangle] | |
70 | pub extern "C" fn $name(tx: *mut libc::c_void) | |
71 | -> *mut core::DetectEngineState | |
72 | { | |
73 | let tx = cast_pointer!(tx, $type); | |
74 | match tx.de_state { | |
75 | Some(ds) => { | |
76 | return ds; | |
77 | }, | |
78 | None => { | |
79 | return std::ptr::null_mut(); | |
80 | } | |
81 | } | |
82 | } | |
83 | ) | |
84 | } | |
85 | ||
86 | /// Export a function to set the DetectEngineState on a struct. | |
87 | #[macro_export] | |
88 | macro_rules!export_tx_set_detect_state { | |
89 | ($name:ident, $type:ty) => ( | |
90 | #[no_mangle] | |
91 | pub extern "C" fn $name(tx: *mut libc::c_void, | |
92 | de_state: &mut core::DetectEngineState) -> libc::c_int | |
93 | { | |
94 | let tx = cast_pointer!(tx, $type); | |
95 | tx.de_state = Some(de_state); | |
96 | 0 | |
97 | } | |
98 | ) | |
99 | } |