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-2024 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, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef STATUS_H
25 #define STATUS_H
26 
27 #include "interval.h"
28 
29 /*
30  * virtual function interface for status output
31  */
33  void *arg;
34  unsigned int flags_default;
35  void (*func) (void *arg, const unsigned int flags, const char *str);
36 };
37 
38 static inline void
39 virtual_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;
56  int msglevel;
57  const struct virtual_output *vout;
58 
59  struct buffer read_buf;
60 
61  struct event_timeout et;
62 
63  bool errors;
64 };
65 
66 struct status_output *status_open(const char *filename,
67  const int refresh_freq,
68  const int msglevel,
69  const struct virtual_output *vout,
70  const unsigned int flags);
71 
72 bool status_trigger(struct status_output *so);
73 
74 void status_reset(struct status_output *so);
75 
76 void status_flush(struct status_output *so);
77 
78 bool status_close(struct status_output *so);
79 
80 void status_printf(struct status_output *so, const char *format, ...)
81 #ifdef __GNUC__
82 #if __USE_MINGW_ANSI_STDIO
83 __attribute__ ((format(gnu_printf, 2, 3)))
84 #else
85 __attribute__ ((format(__printf__, 2, 3)))
86 #endif
87 #endif
88 ;
89 
90 bool status_read(struct status_output *so, struct buffer *buf);
91 
92 static inline unsigned int
93 status_rw_flags(const struct status_output *so)
94 {
95  if (so)
96  {
97  return so->flags;
98  }
99  else
100  {
101  return 0;
102  }
103 }
104 
105 #endif /* ifndef STATUS_H */
status_output::filename
char * filename
Definition: status.h:54
status_rw_flags
static unsigned int status_rw_flags(const struct status_output *so)
Definition: status.h:93
status_output::et
struct event_timeout et
Definition: status.h:61
status_output::msglevel
int msglevel
Definition: status.h:56
status_trigger
bool status_trigger(struct status_output *so)
Definition: status.c:133
status_output::errors
bool errors
Definition: status.h:63
status_output::flags
unsigned int flags
Definition: status.h:52
interval.h
status_output::read_buf
struct buffer read_buf
Definition: status.h:59
status_read
bool status_read(struct status_output *so, struct buffer *buf)
Definition: status.c:268
virtual_output_print
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
Definition: status.h:39
virtual_output::func
void(* func)(void *arg, const unsigned int flags, const char *str)
Definition: status.h:35
status_close
bool status_close(struct status_output *so)
Definition: status.c:188
status_output
Definition: status.h:48
buffer
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
virtual_output
Definition: status.h:32
status_open
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:61
status_printf
void status_printf(struct status_output *so, const char *format,...)
Definition: status.c:222
status_flush
void status_flush(struct status_output *so)
Definition: status.c:157
virtual_output::arg
void * arg
Definition: status.h:33
__attribute__
__attribute__((unused))
Definition: test.c:42
status_output::fd
int fd
Definition: status.h:55
event_timeout
Definition: interval.h:136
status_output::vout
const struct virtual_output * vout
Definition: status.h:57
virtual_output::flags_default
unsigned int flags_default
Definition: status.h:34
status_reset
void status_reset(struct status_output *so)
Definition: status.c:148