OpenVPN
status.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2025 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef STATUS_H
24#define STATUS_H
25
26#include "interval.h"
27
28/*
29 * virtual function interface for status output
30 */
32{
33 void *arg;
34 unsigned int flags_default;
35 void (*func)(void *arg, const unsigned int flags, const char *str);
36};
37
38static inline void
39virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
40{
41 (*vo->func)(vo->arg, flags, str);
42}
43
44/*
45 * printf-style interface for inputting/outputting status info
46 */
47
49{
50#define STATUS_OUTPUT_READ (1 << 0)
51#define STATUS_OUTPUT_WRITE (1 << 1)
52 unsigned int flags;
53
54 char *filename;
55 int fd;
57 const struct virtual_output *vout;
58
60
62
63 bool errors;
64};
65
66struct status_output *status_open(const char *filename, const int refresh_freq, const int msglevel,
67 const struct virtual_output *vout, const unsigned int flags);
68
69bool status_trigger(struct status_output *so);
70
71void status_reset(struct status_output *so);
72
73void status_flush(struct status_output *so);
74
75bool status_close(struct status_output *so);
76
77void status_printf(struct status_output *so, const char *format, ...)
78#ifdef __GNUC__
79#if __USE_MINGW_ANSI_STDIO
80 __attribute__((format(gnu_printf, 2, 3)))
81#else
82 __attribute__((format(__printf__, 2, 3)))
83#endif
84#endif
85 ;
86
87bool status_read(struct status_output *so, struct buffer *buf);
88
89static inline unsigned int
91{
92 if (so)
93 {
94 return so->flags;
95 }
96 else
97 {
98 return 0;
99 }
100}
101
102#endif /* ifndef STATUS_H */
static unsigned int status_rw_flags(const struct status_output *so)
Definition status.h:90
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
Definition status.h:39
bool status_trigger(struct status_output *so)
Definition status.c:124
void status_printf(struct status_output *so, const char *format,...)
Definition status.c:213
bool status_read(struct status_output *so, struct buffer *buf)
Definition status.c:259
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
Definition status.c:60
void status_flush(struct status_output *so)
Definition status.c:148
void status_reset(struct status_output *so)
Definition status.c:139
bool status_close(struct status_output *so)
Definition status.c:179
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
struct buffer read_buf
Definition status.h:59
const struct virtual_output * vout
Definition status.h:57
bool errors
Definition status.h:63
struct event_timeout et
Definition status.h:61
int msglevel
Definition status.h:56
unsigned int flags
Definition status.h:52
char * filename
Definition status.h:54
unsigned int flags_default
Definition status.h:34
void * arg
Definition status.h:33
void(* func)(void *arg, const unsigned int flags, const char *str)
Definition status.h:35
__attribute__((unused))
Definition test.c:42