cosmetics
[tomato.git] / release / src / router / openvpn / plugin.h
blob02da0001a8277b3805f3bf9fdcb75798ceb3a44d
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.
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
26 * plug-in support, using dynamically loaded libraries
29 #ifndef OPENVPN_PLUGIN_H
30 #define OPENVPN_PLUGIN_H
32 #include "openvpn-plugin.h"
34 #ifdef ENABLE_PLUGIN
36 #include "misc.h"
38 #define MAX_PLUGINS 16
40 struct plugin_option {
41 const char *so_pathname;
42 const char **argv;
45 struct plugin_option_list {
46 int n;
47 struct plugin_option plugins[MAX_PLUGINS];
50 struct plugin {
51 bool initialized;
52 const char *so_pathname;
53 unsigned int plugin_type_mask;
54 int requested_initialization_point;
56 #if defined(USE_LIBDL)
57 void *handle;
58 #elif defined(USE_LOAD_LIBRARY)
59 HMODULE module;
60 #endif
62 openvpn_plugin_open_v1 open1;
63 openvpn_plugin_open_v2 open2;
64 openvpn_plugin_func_v1 func1;
65 openvpn_plugin_func_v2 func2;
66 openvpn_plugin_close_v1 close;
67 openvpn_plugin_abort_v1 abort;
68 openvpn_plugin_client_constructor_v1 client_constructor;
69 openvpn_plugin_client_destructor_v1 client_destructor;
70 openvpn_plugin_min_version_required_v1 min_version_required;
71 openvpn_plugin_select_initialization_point_v1 initialization_point;
73 openvpn_plugin_handle_t plugin_handle;
76 struct plugin_per_client
78 void *per_client_context[MAX_PLUGINS];
81 struct plugin_common
83 int n;
84 struct plugin plugins[MAX_PLUGINS];
87 struct plugin_list
89 struct plugin_per_client per_client;
90 struct plugin_common *common;
91 bool common_owned;
94 struct plugin_return
96 int n;
97 struct openvpn_plugin_string_list *list[MAX_PLUGINS];
100 struct plugin_option_list *plugin_option_list_new (struct gc_arena *gc);
101 bool plugin_option_list_add (struct plugin_option_list *list, char **p, struct gc_arena *gc);
103 #ifdef ENABLE_DEBUG
104 void plugin_option_list_print (const struct plugin_option_list *list, int msglevel);
105 #endif
107 struct plugin_list *plugin_list_init (const struct plugin_option_list *list);
109 void plugin_list_open (struct plugin_list *pl,
110 const struct plugin_option_list *list,
111 struct plugin_return *pr,
112 const struct env_set *es,
113 const int init_point);
115 struct plugin_list *plugin_list_inherit (const struct plugin_list *src);
117 int plugin_call (const struct plugin_list *pl,
118 const int type,
119 const struct argv *av,
120 struct plugin_return *pr,
121 struct env_set *es);
123 void plugin_list_close (struct plugin_list *pl);
124 bool plugin_defined (const struct plugin_list *pl, const int type);
126 void plugin_return_get_column (const struct plugin_return *src,
127 struct plugin_return *dest,
128 const char *colname);
130 void plugin_return_free (struct plugin_return *pr);
132 #ifdef ENABLE_DEBUG
133 void plugin_return_print (const int msglevel, const char *prefix, const struct plugin_return *pr);
134 #endif
136 static inline int
137 plugin_n (const struct plugin_list *pl)
139 if (pl && pl->common)
140 return pl->common->n;
141 else
142 return 0;
145 static inline bool
146 plugin_return_defined (const struct plugin_return *pr)
148 return pr->n >= 0;
151 static inline void
152 plugin_return_init (struct plugin_return *pr)
154 pr->n = 0;
157 #else
159 struct plugin_list { int dummy; };
160 struct plugin_return { int dummy; };
162 static inline bool
163 plugin_defined (const struct plugin_list *pl, const int type)
165 return false;
168 static inline int
169 plugin_call (const struct plugin_list *pl,
170 const int type,
171 const struct argv *av,
172 struct plugin_return *pr,
173 struct env_set *es)
175 return 0;
178 #endif /* ENABLE_PLUGIN */
180 #endif /* OPENVPN_PLUGIN_H */