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-2018 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_tv(struct status_output *so, struct timeval *tv);
73 
74 bool status_trigger(struct status_output *so);
75 
76 void status_reset(struct status_output *so);
77 
78 void status_flush(struct status_output *so);
79 
80 bool status_close(struct status_output *so);
81 
82 void status_printf(struct status_output *so, const char *format, ...)
83 #ifdef __GNUC__
84 #if __USE_MINGW_ANSI_STDIO
85 __attribute__ ((format(gnu_printf, 2, 3)))
86 #else
87 __attribute__ ((format(__printf__, 2, 3)))
88 #endif
89 #endif
90 ;
91 
92 bool status_read(struct status_output *so, struct buffer *buf);
93 
94 static inline unsigned int
95 status_rw_flags(const struct status_output *so)
96 {
97  if (so)
98  {
99  return so->flags;
100  }
101  else
102  {
103  return 0;
104  }
105 }
106 
107 #endif /* ifndef STATUS_H */
char * filename
Definition: status.h:54
bool errors
Definition: status.h:63
bool status_read(struct status_output *so, struct buffer *buf)
Definition: status.c:285
static void virtual_output_print(const struct virtual_output *vo, const unsigned int flags, const char *str)
Definition: status.h:39
unsigned int flags_default
Definition: status.h:34
unsigned int flags
Definition: status.h:52
bool status_close(struct status_output *so)
Definition: status.c:203
static unsigned int status_rw_flags(const struct status_output *so)
Definition: status.h:95
const struct virtual_output * vout
Definition: status.h:57
void status_flush(struct status_output *so)
Definition: status.c:172
list flags
void * arg
Definition: status.h:33
void status_printf(struct status_output *so, const char *format,...)
Definition: status.c:239
void status_reset(struct status_output *so)
Definition: status.c:163
void(* func)(void *arg, const unsigned int flags, const char *str)
Definition: status.h:35
bool status_trigger(struct status_output *so)
Definition: status.c:135
int msglevel
Definition: status.h:56
bool status_trigger_tv(struct status_output *so, struct timeval *tv)
Definition: status.c:150
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
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:63