PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
atna_syslog_transport.h
Go to the documentation of this file.
1
17#ifndef PACS_SECURITY_ATNA_SYSLOG_TRANSPORT_HPP
18#define PACS_SECURITY_ATNA_SYSLOG_TRANSPORT_HPP
19
21
22#include <atomic>
23#include <cstdint>
24#include <string>
25
26namespace kcenon::pacs::security {
27
28// =============================================================================
29// Syslog Facility Codes (RFC 5424 Section 6.2.1)
30// =============================================================================
31
38enum class syslog_facility : uint8_t {
39 kern = 0,
40 user = 1,
41 mail = 2,
42 daemon = 3,
43 auth = 4,
44 syslog = 5,
45 lpr = 6,
46 news = 7,
47 uucp = 8,
48 cron = 9,
49 authpriv = 10,
50 ftp = 11,
51 ntp = 12,
52 log_audit = 13,
53 log_alert = 14,
54 clock = 15,
55 local0 = 16,
56 local1 = 17,
57 local2 = 18,
58 local3 = 19,
59 local4 = 20,
60 local5 = 21,
61 local6 = 22,
62 local7 = 23
63};
64
65// =============================================================================
66// Syslog Severity (RFC 5424 Section 6.2.1)
67// =============================================================================
68
72enum class syslog_severity : uint8_t {
73 emergency = 0,
74 alert = 1,
75 critical = 2,
76 error = 3,
77 warning = 4,
78 notice = 5,
79 informational = 6,
80 debug = 7
81};
82
83// =============================================================================
84// Transport Protocol
85// =============================================================================
86
90enum class syslog_transport_protocol : uint8_t {
91 udp,
92 tls
93};
94
95// =============================================================================
96// Configuration
97// =============================================================================
98
105
107 std::string host{"localhost"};
108
110 uint16_t port{514};
111
113 std::string app_name{"pacs_system"};
114
116 std::string hostname;
117
120
123
124 // -- TLS-specific options (RFC 5425) --
125
127 std::string ca_cert_path;
128
130 std::string client_cert_path;
131
133 std::string client_key_path;
134
136 bool verify_server{true};
137};
138
139// =============================================================================
140// ATNA Syslog Transport
141// =============================================================================
142
165public:
166 // =========================================================================
167 // Construction
168 // =========================================================================
169
175
177
178 // Non-copyable
181
182 // Movable
185
186 // =========================================================================
187 // Send Operations
188 // =========================================================================
189
199 [[nodiscard]] kcenon::pacs::VoidResult send(const std::string& xml_message);
200
201 // =========================================================================
202 // RFC 5424 Message Formatting
203 // =========================================================================
204
214 [[nodiscard]] std::string format_syslog_message(
215 const std::string& xml_message) const;
216
217 // =========================================================================
218 // Connection Management
219 // =========================================================================
220
226 [[nodiscard]] bool is_connected() const noexcept;
227
233 void close();
234
235 // =========================================================================
236 // Statistics
237 // =========================================================================
238
239 [[nodiscard]] size_t messages_sent() const noexcept;
240 [[nodiscard]] size_t send_errors() const noexcept;
241 void reset_statistics() noexcept;
242
243 // =========================================================================
244 // Configuration Access
245 // =========================================================================
246
247 [[nodiscard]] const syslog_transport_config& config() const noexcept;
248
249private:
250 // =========================================================================
251 // Private Implementation
252 // =========================================================================
253
254 [[nodiscard]] kcenon::pacs::VoidResult send_udp(const std::string& syslog_message);
255 [[nodiscard]] kcenon::pacs::VoidResult send_tls(const std::string& syslog_message);
256 [[nodiscard]] kcenon::pacs::VoidResult ensure_tls_connected();
257
258 [[nodiscard]] static std::string get_local_hostname();
259 [[nodiscard]] static std::string get_timestamp();
260 [[nodiscard]] static uint8_t compute_priority(
261 syslog_facility facility, syslog_severity severity);
262
263 // =========================================================================
264 // Private Members
265 // =========================================================================
266
268
269 // Socket handle (-1 = not connected)
270#ifdef _WIN32
271 using socket_type = unsigned long long; // SOCKET
272 static constexpr socket_type invalid_socket = ~static_cast<socket_type>(0);
273#else
274 using socket_type = int;
275 static constexpr socket_type invalid_socket = -1;
276#endif
278
279 // Opaque TLS context (avoids OpenSSL includes in header)
280 struct tls_context;
281 tls_context* tls_{nullptr};
282
283 std::atomic<size_t> messages_sent_{0};
284 std::atomic<size_t> send_errors_{0};
285};
286
287} // namespace kcenon::pacs::security
288
289#endif // PACS_SECURITY_ATNA_SYSLOG_TRANSPORT_HPP
Sends ATNA audit messages via Syslog protocol.
atna_syslog_transport(const syslog_transport_config &config)
Construct transport with configuration.
bool is_connected() const noexcept
Check if the transport is connected (TLS only)
std::string format_syslog_message(const std::string &xml_message) const
Format an XML audit message as an RFC 5424 Syslog message.
const syslog_transport_config & config() const noexcept
kcenon::pacs::VoidResult send_tls(const std::string &syslog_message)
static uint8_t compute_priority(syslog_facility facility, syslog_severity severity)
atna_syslog_transport(const atna_syslog_transport &)=delete
void close()
Close the transport connection.
kcenon::pacs::VoidResult send_udp(const std::string &syslog_message)
kcenon::pacs::VoidResult send(const std::string &xml_message)
Send an RFC 3881 XML audit message via Syslog.
atna_syslog_transport & operator=(const atna_syslog_transport &)=delete
syslog_transport_protocol
Syslog transport protocol.
@ udp
UDP (RFC 5426) — Fire-and-forget.
@ tls
TLS over TCP (RFC 5425) — Secure.
syslog_severity
Syslog severity levels.
@ informational
Default for audit events.
syslog_facility
Syslog facility values.
@ authpriv
Security/authorization (recommended for ATNA)
Result<T> type aliases and helpers for PACS system.
Configuration for the Syslog transport.
std::string client_key_path
Path to client private key file (mutual TLS)
std::string ca_cert_path
Path to CA certificate file for server verification.
syslog_transport_protocol protocol
Transport protocol (UDP or TLS)
uint16_t port
Port number (514 for UDP, 6514 for TLS per IANA)
std::string host
Audit Record Repository hostname or IP.
std::string app_name
Application name in Syslog header.
std::string client_cert_path
Path to client certificate file (mutual TLS)
std::string hostname
Hostname to report in Syslog header (auto-detected if empty)
syslog_severity severity
Syslog severity for audit events.
bool verify_server
Whether to verify server certificate (disable only for testing)