syslog_rs/
syslog_provider.rs1
2
3
4
5pub trait SyslogDestination: std::fmt::Debug + Send + 'static
6{
7 fn init(self) -> SyRes<TapTypeData>;
8}
9
10#[derive(Debug)]
11pub struct SyslogLocal
12{
13 custom_path: Option<PathBuf>,
14 use_alt_path: bool,
15}
16
17impl SyslogLocal
18{
19 pub
20 fn new() -> Self
21 {
22 return
23 Self
24 {
25 custom_path: None,
26 use_alt_path: false,
27 };
28 }
29
30 pub
31 fn new_custom_path<P: Into<PathBuf>>(custom_path: P, use_alt_path: bool) -> Self
32 {
33 return
34 Self
35 {
36 custom_path: Some(custom_path.into()),
37 use_alt_path: use_alt_path,
38 };
39 }
40}
41
42impl SyslogDestination for SyslogLocal
43{
44 fn init(self) -> SyRes<TapTypeData>
45 {
46 return
47 TapTypeData
48 ::new_unix(
49 self.custom_path.as_ref().map(|v| v.as_path()),
50 self.use_alt_path
51 );
52 }
53}
54
55#[cfg(feature = "build_with_net")]
56pub mod imp_syslog_net
57{
58 use crate::{error::SyRes, socket::{TapTypeData, TapTypeDataRemProto}};
59
60 use super::SyslogDestination;
61
62 #[derive(Debug)]
63 pub struct SyslogNet
64 {
65 proto: TapTypeDataRemProto,
66 dest_addr: String,
67 bind_addr: Option<String>,
68 }
69
70 impl SyslogNet
71 {
72 pub
73 fn new_tcp<D: AsRef<str>>(dest_addr: impl Into<String>) -> Self
74 {
75 return
76 Self
77 {
78 proto: TapTypeDataRemProto::Tcp,
79 dest_addr: dest_addr.into(),
80 bind_addr: None,
81 };
82 }
83
84 pub
85 fn new_udp(dest_addr: impl Into<String>, bind_addr: impl Into<String>) -> Self
86 {
87 return
88 Self
89 {
90 proto: TapTypeDataRemProto::Udp,
91 dest_addr: dest_addr.into(),
92 bind_addr: Some(bind_addr.into()),
93 };
94 }
95 }
96
97 impl SyslogDestination for SyslogNet
98 {
99 fn init(self) -> SyRes<TapTypeData>
100 {
101 return TapTypeData::new_net(self.proto, self.dest_addr, self.bind_addr);
102 }
103 }
104}
105
106use std::path::PathBuf;
107
108use crate::{error::SyRes, socket::TapTypeData};
109
110#[cfg(feature = "build_with_net")]
111pub use self::imp_syslog_net::SyslogNet;
112
113#[cfg(feature = "build_with_file")]
114pub mod imp_syslog_file
115{
116 use std::path::PathBuf;
117
118 use crate::{error::SyRes, socket::TapTypeData};
119
120 use super::SyslogDestination;
121
122 #[derive(Debug)]
123 pub struct SyslogFile
124 {
125 file_path: PathBuf
126 }
127
128 impl SyslogFile
129 {
130 pub
131 fn new<P: Into<PathBuf>>(dest_path: P) -> Self
132 {
133 return
134 Self
135 {
136 file_path: dest_path.into()
137 };
138 }
139 }
140
141 impl SyslogDestination for SyslogFile
142 {
143 fn init(self) -> SyRes<TapTypeData>
144 {
145 return TapTypeData::new_file(self.file_path);
146 }
147 }
148}
149
150#[cfg(feature = "build_with_file")]
151pub use self::imp_syslog_file::SyslogFile;
152
153#[cfg(feature = "build_with_tls")]
154pub mod imp_syslog_tls
155{
156 use crate::{error::SyRes, socket::TapTypeData};
157
158 use super::SyslogDestination;
159
160 #[derive(Debug)]
161 pub struct SyslogTls
162 {
163 dest_addr: String,
164 serv_name: String,
165 root_cert: Vec<u8>,
166 }
167
168 impl SyslogTls
169 {
170 pub
171 fn new(dest_addr: impl Into<String>, serv_name: impl Into<String>, root_cert: Vec<u8>) -> Self
172 {
173 return
174 Self
175 {
176 dest_addr: dest_addr.into(),
177 serv_name: serv_name.into(),
178 root_cert: root_cert
179 };
180 }
181 }
182
183 impl SyslogDestination for SyslogTls
184 {
185 fn init(self) -> SyRes<TapTypeData>
186 {
187 return TapTypeData::new_tls(self.dest_addr, &self.serv_name, &self.root_cert);
188 }
189 }
190}
191
192#[cfg(feature = "build_with_tls")]
193pub use self::imp_syslog_tls::SyslogTls;