syslog_rs/
socket.rs

1/*-
2 * syslog-rs - a syslog client translated from libc to rust
3 * 
4 * Copyright 2025 Aleksandr Morozov
5 * 
6 * The syslog-rs crate can be redistributed and/or modified
7 * under the terms of either of the following licenses:
8 *
9 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
10 *
11 *   2. The MIT License (MIT)
12 *                     
13 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
14 */
15
16
17use std::fmt;
18
19
20/// An enum of types of the current syslog tap instance.
21#[derive(Copy, Clone, Debug, PartialEq, Eq)]
22pub enum TapType
23{
24    /// Not defined
25    None, 
26
27    /// Unprivileged socket used
28    UnPriv,
29
30    /// Privileged socket used
31    Priv,
32
33    /// A compatibility socket used
34    OldLog,
35
36    /// Custom unix datagram
37    CustomLog,
38
39    /// Windows only event log
40    WindowsEventLog,
41
42    /// Writing to file directly
43    LocalFile,
44
45    /// Network UDP
46    NetUdp,
47
48    /// Network TCP
49    NetTcp,
50
51    /// Network TLS over TCP
52    NetTls,
53}
54
55impl fmt::Display for TapType
56{
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
58    {
59        match self
60        {
61            Self::None => 
62                write!(f, "NO TYPE"),
63            Self::UnPriv => 
64                write!(f, "UNPRIV"),
65            Self::Priv => 
66                write!(f, "PRIV"),
67            Self::OldLog =>
68                write!(f, "OLD LOG"),
69            Self::CustomLog => 
70                write!(f, "CUSTOM LOG"),
71            Self::WindowsEventLog =>
72                write!(f, "WINDOWS EVENT LOG"),
73            Self::LocalFile =>
74                write!(f, "LOCAL FILE"),
75            Self::NetUdp => 
76                write!(f, "NET UDP"),
77            Self::NetTcp => 
78                write!(f, "NET TCP"),
79            Self::NetTls => 
80                write!(f, "NET TLS TCP")
81        }
82    }
83}
84
85impl TapType
86{
87    pub(crate) 
88    fn is_priv(&self) -> bool
89    {
90        return *self == Self::Priv;
91    }
92
93    pub(crate) 
94    fn is_network(&self) -> bool
95    {
96        return *self == Self::NetTcp || *self == Self::NetUdp;
97    }
98
99    pub(crate)
100    fn is_file(&self) -> bool
101    {
102        return *self == Self::LocalFile;
103    }
104
105}