Skip to main content

huginn_net_http/output/
common.rs

1use std::fmt;
2use std::fmt::Formatter;
3
4#[derive(Debug, Clone, PartialEq)]
5#[cfg_attr(feature = "json", derive(serde::Serialize))]
6pub struct IpPort {
7    pub ip: std::net::IpAddr,
8    pub port: u16,
9}
10
11impl IpPort {
12    pub fn new(ip: std::net::IpAddr, port: u16) -> Self {
13        Self { ip, port }
14    }
15}
16
17/// Whether a matched browser/web server label was a *specified* (concrete)
18/// or *generic* (catch-all) entry in the underlying database.
19///
20/// Defined locally so `huginn-net-http` does not depend on `huginn-net-db`.
21#[derive(Clone, Debug, PartialEq, Eq)]
22#[cfg_attr(feature = "json", derive(serde::Serialize))]
23pub enum OsKind {
24    Specified,
25    Generic,
26}
27
28impl fmt::Display for OsKind {
29    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
30        f.write_str(match self {
31            OsKind::Specified => "Specified",
32            OsKind::Generic => "Generic",
33        })
34    }
35}
36
37/// Quality classification for an HTTP match.
38///
39/// - `Matched(score)` a signature was matched with the given quality score
40///   (higher is better, typically in `[0.0, 1.0]`).
41/// - `NotMatched` the matcher was active but no signature was a viable fit.
42/// - `Disabled` matching was disabled (no matcher plugged in).
43#[derive(Clone, Debug)]
44#[cfg_attr(feature = "json", derive(serde::Serialize))]
45pub enum MatchQuality {
46    Matched(f32),
47    NotMatched,
48    Disabled,
49}
50
51/// Represents a browser identified from an HTTP request signature.
52#[derive(Debug, Clone)]
53#[cfg_attr(feature = "json", derive(serde::Serialize))]
54pub struct Browser {
55    pub name: String,
56    pub family: Option<String>,
57    pub variant: Option<String>,
58    pub kind: OsKind,
59}
60
61/// Represents a web server identified from an HTTP response signature.
62#[derive(Debug, Clone)]
63#[cfg_attr(feature = "json", derive(serde::Serialize))]
64pub struct WebServer {
65    pub name: String,
66    pub family: Option<String>,
67    pub variant: Option<String>,
68    pub kind: OsKind,
69}