1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Theread context.
//!
//! Type Context holds data for thread-local features such as allocator and logger.
use super::variant::Variant;
use super::layer::{Confidence, Layer};
use super::symbol;
use super::token::Token;
use std::io::{Error, ErrorKind};
/// A Context object.
#[repr(C)]
pub struct Context {
close_stream: bool,
confidence_threshold: u32,
}
impl Context {
/// Returns a config value in the current profile.
pub fn get_config(&self, name: &str) -> &Variant {
unsafe {
&*symbol::Context_getConfig.unwrap()(self, name.as_ptr() as *const i8, name.len())
}
}
/// Closes the current stream session.
///
/// This method only works in the stream dissector.
pub fn close_stream(&mut self) {
self.close_stream = true
}
/// Checks the current confidence threshold level.
///
/// If the threshold level is lower than or equal to `confidence`, returns `Ok`.
/// Otherwise, returns `Err`.
pub fn assert_confidence(&self, confidence: Confidence) -> Result<(), Error> {
if confidence as u32 >= self.confidence_threshold {
Ok(())
} else {
Err(Error::new(ErrorKind::Other, "insufficient confidence"))
}
}
/// Marks the `layer` as a part of the stream.
pub fn add_layer_linkage(&mut self, token: Token, id: u64, layer: &mut Layer) {
unsafe {
symbol::Context_addLayerLinkage.unwrap()(self, token, id, layer);
}
}
}