minidlna support now Samsung TV C550/C650 (thx amir909)
[tomato.git] / release / src / router / openvpn / win32.h
bloba972a88eba7a6ed28159102d99804a371269027c
1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
8 * Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
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.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifdef WIN32
26 #ifndef OPENVPN_WIN32_H
27 #define OPENVPN_WIN32_H
29 #include "mtu.h"
31 /* location of executables */
32 #define SYS_PATH_ENV_VAR_NAME "SystemRoot" /* environmental variable name that normally contains the system path */
33 #define DEFAULT_WIN_SYS_PATH "C:\\WINDOWS" /* --win-sys default value */
34 #define NETSH_PATH_SUFFIX "\\system32\\netsh.exe"
35 #define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.exe"
38 * Win32-specific OpenVPN code, targetted at the mingw
39 * development environment.
42 void init_win32 (void);
43 void uninit_win32 (void);
45 void set_pause_exit_win32 (void);
48 * Use keyboard input or events
49 * to simulate incoming signals
52 #define SIGUSR1 1
53 #define SIGUSR2 2
54 #define SIGHUP 3
55 #define SIGTERM 4
56 #define SIGINT 5
58 struct security_attributes
60 SECURITY_ATTRIBUTES sa;
61 SECURITY_DESCRIPTOR sd;
64 #define HANDLE_DEFINED(h) ((h) != NULL && (h) != INVALID_HANDLE_VALUE)
67 * Save old window title.
69 struct window_title
71 bool saved;
72 char old_window_title [256];
75 struct rw_handle {
76 HANDLE read;
77 HANDLE write;
81 * Event-based notification of incoming TCP connections
84 #define NE32_PERSIST_EVENT (1<<0)
85 #define NE32_WRITE_EVENT (1<<1)
87 static inline bool
88 defined_net_event_win32 (const struct rw_handle *event)
90 return event->read != NULL;
93 void init_net_event_win32 (struct rw_handle *event, long network_events, socket_descriptor_t sd, unsigned int flags);
94 long reset_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd);
95 void close_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd, unsigned int flags);
98 * A stateful variant of the net_event_win32 functions above
101 struct net_event_win32
103 struct rw_handle handle;
104 socket_descriptor_t sd;
105 long event_mask;
108 void net_event_win32_init (struct net_event_win32 *ne);
109 void net_event_win32_start (struct net_event_win32 *ne, long network_events, socket_descriptor_t sd);
110 void net_event_win32_reset (struct net_event_win32 *ne);
111 void net_event_win32_reset_write (struct net_event_win32 *ne);
112 void net_event_win32_stop (struct net_event_win32 *ne);
113 void net_event_win32_close (struct net_event_win32 *ne);
115 static inline bool
116 net_event_win32_defined (const struct net_event_win32 *ne)
118 return defined_net_event_win32 (&ne->handle);
121 static inline struct rw_handle *
122 net_event_win32_get_event (struct net_event_win32 *ne)
124 return &ne->handle;
127 static inline long
128 net_event_win32_get_event_mask (const struct net_event_win32 *ne)
130 return ne->event_mask;
133 static inline void
134 net_event_win32_clear_selected_events (struct net_event_win32 *ne, long selected_events)
136 ne->event_mask &= ~selected_events;
140 * Signal handling
142 struct win32_signal {
143 # define WSO_MODE_UNDEF 0
144 # define WSO_MODE_SERVICE 1
145 # define WSO_MODE_CONSOLE 2
146 int mode;
147 struct rw_handle in;
148 DWORD console_mode_save;
149 bool console_mode_save_defined;
152 extern struct win32_signal win32_signal; /* static/global */
153 extern struct window_title window_title; /* static/global */
155 void win32_signal_clear (struct win32_signal *ws);
157 /* win32_signal_open startup type */
158 #define WSO_NOFORCE 0
159 #define WSO_FORCE_SERVICE 1
160 #define WSO_FORCE_CONSOLE 2
162 void win32_signal_open (struct win32_signal *ws,
163 int force, /* set to WSO force parm */
164 const char *exit_event_name,
165 bool exit_event_initial_state);
167 void win32_signal_close (struct win32_signal *ws);
169 int win32_signal_get (struct win32_signal *ws);
171 void win32_pause (struct win32_signal *ws);
174 * Set the text on the window title bar
177 void window_title_clear (struct window_title *wt);
178 void window_title_save (struct window_title *wt);
179 void window_title_restore (const struct window_title *wt);
180 void window_title_generate (const char *title);
183 * We try to do all Win32 I/O using overlapped
184 * (i.e. asynchronous) I/O for a performance win.
186 struct overlapped_io {
187 # define IOSTATE_INITIAL 0
188 # define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */
189 # define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returned immediately without queueing */
190 int iostate;
191 OVERLAPPED overlapped;
192 DWORD size;
193 DWORD flags;
194 int status;
195 bool addr_defined;
196 struct sockaddr_in addr;
197 int addrlen;
198 struct buffer buf_init;
199 struct buffer buf;
202 void overlapped_io_init (struct overlapped_io *o,
203 const struct frame *frame,
204 BOOL event_state,
205 bool tuntap_buffer);
207 void overlapped_io_close (struct overlapped_io *o);
209 static inline bool
210 overlapped_io_active (struct overlapped_io *o)
212 return o->iostate == IOSTATE_QUEUED || o->iostate == IOSTATE_IMMEDIATE_RETURN;
215 char *overlapped_io_state_ascii (const struct overlapped_io *o);
218 * Use to control access to resources that only one
219 * OpenVPN process on a given machine can access at
220 * a given time.
223 struct semaphore
225 const char *name;
226 bool locked;
227 HANDLE hand;
230 void semaphore_clear (struct semaphore *s);
231 void semaphore_open (struct semaphore *s, const char *name);
232 bool semaphore_lock (struct semaphore *s, int timeout_milliseconds);
233 void semaphore_release (struct semaphore *s);
234 void semaphore_close (struct semaphore *s);
237 * Special global semaphore used to protect network
238 * shell commands from simultaneous instantiation.
240 * It seems you can't run more than one instance
241 * of netsh on the same machine at the same time.
244 extern struct semaphore netcmd_semaphore;
245 void netcmd_semaphore_init (void);
246 void netcmd_semaphore_close (void);
247 void netcmd_semaphore_lock (void);
248 void netcmd_semaphore_release (void);
250 bool get_console_input_win32 (const char *prompt, const bool echo, char *input, const int capacity);
251 char *getpass (const char *prompt);
253 /* Set Win32 security attributes structure to allow all access */
254 bool init_security_attributes_allow_all (struct security_attributes *obj);
256 /* return true if filename is safe to be used on Windows */
257 bool win_safe_filename (const char *fn);
259 /* add constant environmental variables needed by Windows */
260 struct env_set;
261 void env_set_add_win32 (struct env_set *es);
263 /* get and set the current windows system path */
264 void set_win_sys_path (const char *newpath, struct env_set *es);
265 void set_win_sys_path_via_env (struct env_set *es);
266 char *get_win_sys_path (void);
268 /* call self in a subprocess */
269 void fork_to_self (const char *cmdline);
271 #endif
272 #endif