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 /// Writing to file directly
40 LocalFile,
41
42 /// Network UDP
43 NetUdp,
44
45 /// Network TCP
46 NetTcp,
47
48 /// Network TLS over TCP
49 NetTls,
50}
51
52impl fmt::Display for TapType
53{
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
55 {
56 match self
57 {
58 Self::None =>
59 write!(f, "NO TYPE"),
60 Self::UnPriv =>
61 write!(f, "UNPRIV"),
62 Self::Priv =>
63 write!(f, "PRIV"),
64 Self::OldLog =>
65 write!(f, "OLD LOG"),
66 Self::CustomLog =>
67 write!(f, "CUSTOM LOG"),
68 Self::LocalFile =>
69 write!(f, "LOCAL FILE"),
70 Self::NetUdp =>
71 write!(f, "NET UDP"),
72 Self::NetTcp =>
73 write!(f, "NET TCP"),
74 Self::NetTls =>
75 write!(f, "NET TLS TCP")
76 }
77 }
78}
79
80impl TapType
81{
82 pub(crate)
83 fn is_priv(&self) -> bool
84 {
85 return *self == Self::Priv;
86 }
87
88 pub(crate)
89 fn is_network(&self) -> bool
90 {
91 return *self == Self::NetTcp || *self == Self::NetUdp;
92 }
93
94 pub(crate)
95 fn is_file(&self) -> bool
96 {
97 return *self == Self::LocalFile;
98 }
99
100}