libwebsockets
Lightweight C library for HTML5 websockets
lws-protocols-plugins.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
40 
44 struct lws_protocols {
45  const char *name;
66  unsigned int id;
73  void *user;
85  /* Add new things just above here ---^
86  * This is part of the ABI, don't needlessly break compatibility */
87 };
88 
97 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
98 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
99 
109 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
110 lws_get_protocol(struct lws *wsi);
111 
113 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
114 lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED;
115 
126 LWS_VISIBLE LWS_EXTERN void *
127 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost,
128  const struct lws_protocols *prot, int size);
129 
139 LWS_VISIBLE LWS_EXTERN void *
140 lws_protocol_vh_priv_get(struct lws_vhost *vhost,
141  const struct lws_protocols *prot);
142 
157 LWS_VISIBLE LWS_EXTERN void *
158 lws_adjust_protocol_psds(struct lws *wsi, size_t new_size);
159 
168 LWS_VISIBLE LWS_EXTERN int
169 lws_finalize_startup(struct lws_context *context);
170 
179 LWS_VISIBLE LWS_EXTERN const struct lws_protocol_vhost_options *
180 lws_pvo_search(const struct lws_protocol_vhost_options *pvo, const char *name);
181 
191 LWS_VISIBLE LWS_EXTERN int
192 lws_pvo_get_str(void *in, const char *name, const char **result);
193 
194 LWS_VISIBLE LWS_EXTERN int
195 lws_protocol_init(struct lws_context *context);
196 
197 #define LWS_PLUGIN_API_MAGIC 190
198 
199 /*
200  * Abstract plugin header for any kind of plugin class, always at top of
201  * actual class plugin export type.
202  *
203  * The export type object must be exported with the same name as the plugin
204  * file, eg, libmyplugin.so must export a const one of these as the symbol
205  * "myplugin".
206  *
207  * That is the only expected export from the plugin.
208  */
209 
210 typedef struct lws_plugin_header {
211  const char *name;
212  const char *_class;
213 
214  unsigned int api_magic;
215  /* set to LWS_PLUGIN_API_MAGIC at plugin build time */
216 
217  /* plugin-class specific superclass data follows */
219 
220 /*
221  * "lws_protocol_plugin" class export, for lws_protocol implementations done
222  * as plugins
223  */
224 typedef struct lws_plugin_protocol {
226 
227  const struct lws_protocols *protocols;
228  const struct lws_extension *extensions;
232 
233 
234 /*
235  * This is the dynamic, runtime created part of the plugin instantiation.
236  * These are kept in a linked-list and destroyed with the context.
237  */
238 
239 struct lws_plugin {
240  struct lws_plugin *list;
242  const lws_plugin_header_t *hdr;
243 
244  union {
245 #if defined(LWS_WITH_LIBUV) && defined(UV_ERRNO_MAP)
246 #if (UV_VERSION_MAJOR > 0)
247  uv_lib_t lib;
248 #endif
249 #endif
250  void *l;
251  } u;
252 };
253 
254 /*
255  * Event lib library plugin type (when LWS_WITH_EVLIB_PLUGINS)
256  * Public so new event libs can equally be supported outside lws itself
257  */
258 
259 typedef struct lws_plugin_evlib {
261  const struct lws_event_loop_ops *ops;
263 
264 typedef int (*each_plugin_cb_t)(struct lws_plugin *p, void *user);
265 
287 LWS_VISIBLE LWS_EXTERN int
288 lws_plugins_init(struct lws_plugin **pplugin, const char * const *d,
289  const char *_class, const char *filter,
290  each_plugin_cb_t each, void *each_user);
291 
305 LWS_VISIBLE LWS_EXTERN int
306 lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each,
307  void *each_user);
308 
lws_protocol_vhost_options
Definition: lws-context-vhost.h:1128
lws_plugin::list
struct lws_plugin * list
Definition: lws-protocols-plugins.h:240
lws_callback_function
int lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
Definition: lws-callbacks.h:901
lws_protocol_get
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED
lws_protocol_vhost_options::name
const char * name
Definition: lws-context-vhost.h:1131
lws_pvo_get_str
LWS_VISIBLE LWS_EXTERN int lws_pvo_get_str(void *in, const char *name, const char **result)
lws_protocols::user
void * user
Definition: lws-protocols-plugins.h:73
lws_protocol_vh_priv_get
LWS_VISIBLE LWS_EXTERN void * lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot)
lws_extension
Definition: lws-ws-ext.h:139
lws_get_protocol
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_get_protocol(struct lws *wsi)
lws_plugin_protocol::extensions
const struct lws_extension * extensions
Definition: lws-protocols-plugins.h:228
lws_plugin_protocol::count_protocols
int count_protocols
Definition: lws-protocols-plugins.h:229
lws_finalize_startup
LWS_VISIBLE LWS_EXTERN int lws_finalize_startup(struct lws_context *context)
lws_plugin_protocol::count_extensions
int count_extensions
Definition: lws-protocols-plugins.h:230
lws_protocols::rx_buffer_size
size_t rx_buffer_size
Definition: lws-protocols-plugins.h:57
lws_protocol_vh_priv_zalloc
LWS_VISIBLE LWS_EXTERN void * lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot, int size)
lws_adjust_protocol_psds
LWS_VISIBLE LWS_EXTERN void * lws_adjust_protocol_psds(struct lws *wsi, size_t new_size)
lws_protocols::tx_packet_size
size_t tx_packet_size
Definition: lws-protocols-plugins.h:75
lws_plugins_destroy
LWS_VISIBLE LWS_EXTERN int lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, void *each_user)
lws_protocols::id
unsigned int id
Definition: lws-protocols-plugins.h:66
lws_plugin_protocol::protocols
const struct lws_protocols * protocols
Definition: lws-protocols-plugins.h:227
lws_protocols
Definition: lws-protocols-plugins.h:44
lws_vhost_name_to_protocol
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name)
lws_plugin
Definition: lws-protocols-plugins.h:239
lws_plugin_protocol
Definition: lws-protocols-plugins.h:224
lws_protocols::callback
lws_callback_function * callback
Definition: lws-protocols-plugins.h:48
lws_plugin_evlib
Definition: lws-protocols-plugins.h:259
lws_protocols::name
const char * name
Definition: lws-protocols-plugins.h:45
lws_plugins_init
LWS_VISIBLE LWS_EXTERN int lws_plugins_init(struct lws_plugin **pplugin, const char *const *d, const char *_class, const char *filter, each_plugin_cb_t each, void *each_user)
lws_plugin_header
Definition: lws-protocols-plugins.h:210
lws_protocols::per_session_data_size
size_t per_session_data_size
Definition: lws-protocols-plugins.h:52
lws_pvo_search
LWS_VISIBLE LWS_EXTERN const struct lws_protocol_vhost_options * lws_pvo_search(const struct lws_protocol_vhost_options *pvo, const char *name)