syslog_client.h
Go to the documentation of this file.
1 /**
2  * @file syslog_client.h
3  * @brief Syslog client
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _SYSLOG_CLIENT_H
32 #define _SYSLOG_CLIENT_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //Syslog client support
38 #ifndef SYSLOG_CLIENT_SUPPORT
39  #define SYSLOG_CLIENT_SUPPORT DISABLED
40 #elif (SYSLOG_CLIENT_SUPPORT != ENABLED && SYSLOG_CLIENT_SUPPORT != DISABLED)
41  #error SYSLOG_CLIENT_SUPPORT parameter is not valid
42 #endif
43 
44 //Size of internal buffer
45 #ifndef SYSLOG_CLIENT_BUFFER_SIZE
46  #define SYSLOG_CLIENT_BUFFER_SIZE 512
47 #elif (SYSLOG_CLIENT_BUFFER_SIZE < 128)
48  #error SYSLOG_CLIENT_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Application specific context
52 #ifndef SYSLOG_CLIENT_PRIVATE_CONTEXT
53  #define SYSLOG_CLIENT_PRIVATE_CONTEXT
54 #endif
55 
56 //C++ guard
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 
62 /**
63  * @brief Syslog facility values
64  **/
65 
66 typedef enum
67 {
68  SYSLOG_FACILITY_KERNEL = 0, ///<Kernel messages
69  SYSLOG_FACILITY_USER_LEVEL = 1, ///<User-level messages
70  SYSLOG_FACILITY_MAIL = 2, ///<Mail system
71  SYSLOG_FACILITY_SYSTEM = 3, ///<System daemons
72  SYSLOG_FACILITY_SEC_AUTH = 4, ///<Security/authorization messages
73  SYSLOG_FACILITY_INTENAL = 5, ///<Messages generated internally by syslogd
74  SYSLOG_FACILITY_LINE_PRINTER = 6, ///<Line printer subsystem
75  SYSLOG_FACILITY_NETWORK_NEWS = 7, ///<Network news subsystem
76  SYSLOG_FACILITY_UUCP = 8, ///<UUCP subsystem
77  SYSLOG_FACILITY_CLOCK = 9, ///<Clock daemon
78  SYSLOG_FACILITY_SEC_AUTH2 = 10, ///<Security/authorization messages
79  SYSLOG_FACILITY_FTP = 11, ///<FTP daemon
80  SYSLOG_FACILITY_NTP = 12, ///<NTP subsystem
81  SYSLOG_FACILITY_LOG_AUDIT = 13, ///<Log audit
82  SYSLOG_FACILITY_LOG_ALERT = 14, ///<Log alert
83  SYSLOG_FACILITY_Clock = 15, ///<Clock daemon
84  SYSLOG_FACILITY_LOCAL0 = 16, ///<Local use 0
85  SYSLOG_FACILITY_LOCAL1 = 17, ///<Local use 1
86  SYSLOG_FACILITY_LOCAL2 = 18, ///<Local use 2
87  SYSLOG_FACILITY_LOCAL3 = 19, ///<Local use 3
88  SYSLOG_FACILITY_LOCAL4 = 20, ///<Local use 4
89  SYSLOG_FACILITY_LOCAL5 = 21, ///<Local use 5
90  SYSLOG_FACILITY_LOCAL6 = 22, ///<Local use 6
91  SYSLOG_FACILITY_LOCAL7 = 23 ///<Local use 7
93 
94 
95 /**
96  * @brief Syslog severity values
97  **/
98 
99 typedef enum
100 {
101  SYSLOG_SEVERITY_EMERGENCY = 0, ///<System is unusable
102  SYSLOG_SEVERITY_ALERT = 1, ///<Action must be taken immediately
103  SYSLOG_SEVERITY_CRITICAL = 2, ///<Critical conditions
104  SYSLOG_SEVERITY_ERROR = 3, ///<Error conditions
105  SYSLOG_SEVERITY_WARNING = 4, ///<Warning conditions
106  SYSLOG_SEVERITY_NOTICE = 5, ///<Normal but significant condition
107  SYSLOG_SEVERITY_INFO = 6, ///<Informational messages
108  SYSLOG_SEVERITY_DEBUG = 7 ///<Debug-level messages
110 
111 
112 /**
113  * @brief Syslog client context
114  **/
115 
116 typedef struct
117 {
118  OsMutex mutex; ///<Mutex preventing simultaneous access to the context
119  NetInterface *interface; ///<Underlying network interface
120  Socket *socket; ///<Underlying UDP socket
121  char_t buffer[SYSLOG_CLIENT_BUFFER_SIZE]; ///<Internal buffer
122  SYSLOG_CLIENT_PRIVATE_CONTEXT ///<Application specific context
124 
125 
126 //Syslog client related functions
128 
130  NetInterface *interface);
131 
133  const IpAddr *serverIpAddr, uint16_t serverPort);
134 
136  uint_t severity, const char_t *message);
137 
139  uint_t severity, const char_t *format, ...);
140 
142 
144 
145 //C++ guard
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif
uint8_t message[]
Definition: chap.h:154
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
error_t
Error codes.
Definition: error.h:43
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define Socket
Definition: socket.h:36
IP network address.
Definition: ip.h:79
Mutex object.
Syslog client context.
Socket * socket
Underlying UDP socket.
NetInterface * interface
Underlying network interface.
OsMutex mutex
Mutex preventing simultaneous access to the context.
error_t syslogClientFormatMessage(SyslogClientContext *context, uint_t facility, uint_t severity, const char_t *format,...)
Format Syslog message.
SyslogFacility
Syslog facility values.
Definition: syslog_client.h:67
@ SYSLOG_FACILITY_LOCAL3
Local use 3.
Definition: syslog_client.h:87
@ SYSLOG_FACILITY_LOCAL0
Local use 0.
Definition: syslog_client.h:84
@ SYSLOG_FACILITY_LOG_AUDIT
Log audit.
Definition: syslog_client.h:81
@ SYSLOG_FACILITY_NETWORK_NEWS
Network news subsystem.
Definition: syslog_client.h:75
@ SYSLOG_FACILITY_NTP
NTP subsystem.
Definition: syslog_client.h:80
@ SYSLOG_FACILITY_KERNEL
Kernel messages.
Definition: syslog_client.h:68
@ SYSLOG_FACILITY_LOG_ALERT
Log alert.
Definition: syslog_client.h:82
@ SYSLOG_FACILITY_LOCAL4
Local use 4.
Definition: syslog_client.h:88
@ SYSLOG_FACILITY_Clock
Clock daemon.
Definition: syslog_client.h:83
@ SYSLOG_FACILITY_MAIL
Mail system.
Definition: syslog_client.h:70
@ SYSLOG_FACILITY_SEC_AUTH2
Security/authorization messages.
Definition: syslog_client.h:78
@ SYSLOG_FACILITY_LOCAL6
Local use 6.
Definition: syslog_client.h:90
@ SYSLOG_FACILITY_LOCAL7
Local use 7.
Definition: syslog_client.h:91
@ SYSLOG_FACILITY_LINE_PRINTER
Line printer subsystem.
Definition: syslog_client.h:74
@ SYSLOG_FACILITY_INTENAL
Messages generated internally by syslogd.
Definition: syslog_client.h:73
@ SYSLOG_FACILITY_FTP
FTP daemon.
Definition: syslog_client.h:79
@ SYSLOG_FACILITY_SYSTEM
System daemons.
Definition: syslog_client.h:71
@ SYSLOG_FACILITY_LOCAL5
Local use 5.
Definition: syslog_client.h:89
@ SYSLOG_FACILITY_LOCAL2
Local use 2.
Definition: syslog_client.h:86
@ SYSLOG_FACILITY_LOCAL1
Local use 1.
Definition: syslog_client.h:85
@ SYSLOG_FACILITY_SEC_AUTH
Security/authorization messages.
Definition: syslog_client.h:72
@ SYSLOG_FACILITY_UUCP
UUCP subsystem.
Definition: syslog_client.h:76
@ SYSLOG_FACILITY_USER_LEVEL
User-level messages.
Definition: syslog_client.h:69
@ SYSLOG_FACILITY_CLOCK
Clock daemon.
Definition: syslog_client.h:77
SyslogSeverity
Syslog severity values.
@ SYSLOG_SEVERITY_ALERT
Action must be taken immediately.
@ SYSLOG_SEVERITY_ERROR
Error conditions.
@ SYSLOG_SEVERITY_WARNING
Warning conditions.
@ SYSLOG_SEVERITY_NOTICE
Normal but significant condition.
@ SYSLOG_SEVERITY_DEBUG
Debug-level messages.
@ SYSLOG_SEVERITY_CRITICAL
Critical conditions.
@ SYSLOG_SEVERITY_EMERGENCY
System is unusable.
@ SYSLOG_SEVERITY_INFO
Informational messages.
void syslogClientDeinit(SyslogClientContext *context)
Release Syslog client context.
error_t syslogClientConnect(SyslogClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Specify the address of the Syslog server.
error_t syslogClientInit(SyslogClientContext *context)
Syslog client initialization.
Definition: syslog_client.c:56
error_t syslogClientClose(SyslogClientContext *context)
Close the connection with the Syslog server.
#define SYSLOG_CLIENT_PRIVATE_CONTEXT
Definition: syslog_client.h:53
error_t syslogClientBindToInterface(SyslogClientContext *context, NetInterface *interface)
Bind the Syslog client to a particular network interface.
Definition: syslog_client.c:86
error_t syslogClientSendMessage(SyslogClientContext *context, uint_t facility, uint_t severity, const char_t *message)
Send Syslog message.
#define SYSLOG_CLIENT_BUFFER_SIZE
Definition: syslog_client.h:46