libwebsockets
Lightweight C library for HTML5 websockets
lws-protocols-plugins.h
Go to the documentation of this file.
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 
41 
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 
89 #define LWS_PROTOCOL_LIST_TERM { NULL, NULL, 0, 0, 0, NULL, 0 }
90 
100 lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
101 
111 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
112 lws_get_protocol(struct lws *wsi);
113 
115 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
117 
128 LWS_VISIBLE LWS_EXTERN void *
129 lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost,
130  const struct lws_protocols *prot, int size);
131 
141 LWS_VISIBLE LWS_EXTERN void *
142 lws_protocol_vh_priv_get(struct lws_vhost *vhost,
143  const struct lws_protocols *prot);
144 
175 LWS_VISIBLE LWS_EXTERN void *
176 lws_vhd_find_by_pvo(struct lws_context *cx, const char *protname,
177  const char *pvo_name, const char *pvo_value);
178 
179 
194 LWS_VISIBLE LWS_EXTERN void *
195 lws_adjust_protocol_psds(struct lws *wsi, size_t new_size);
196 
206 lws_finalize_startup(struct lws_context *context);
207 
217 lws_pvo_search(const struct lws_protocol_vhost_options *pvo, const char *name);
218 
229 lws_pvo_get_str(void *in, const char *name, const char **result);
230 
232 lws_protocol_init(struct lws_context *context);
233 
234 #define LWS_PLUGIN_API_MAGIC 191
235 
236 /*
237  * Abstract plugin header for any kind of plugin class, always at top of
238  * actual class plugin export type.
239  *
240  * The export type object must be exported with the same name as the plugin
241  * file, eg, libmyplugin.so must export a const one of these as the symbol
242  * "myplugin".
243  *
244  * That is the only expected export from the plugin.
245  */
246 
247 typedef struct lws_plugin_header {
248  const char *name;
249  const char *_class;
250  const char *lws_build_hash; /* set to LWS_BUILD_HASH */
251 
252  unsigned int api_magic;
253  /* set to LWS_PLUGIN_API_MAGIC at plugin build time */
254 
255  /* plugin-class specific superclass data follows */
257 
258 /*
259  * "lws_protocol_plugin" class export, for lws_protocol implementations done
260  * as plugins
261  */
262 typedef struct lws_plugin_protocol {
264 
265  const struct lws_protocols *protocols;
266  const struct lws_extension *extensions;
270 
271 
272 /*
273  * This is the dynamic, runtime created part of the plugin instantiation.
274  * These are kept in a linked-list and destroyed with the context.
275  */
276 
277 struct lws_plugin {
278  struct lws_plugin *list;
281 
282  union {
283 #if defined(LWS_WITH_LIBUV) && defined(UV_ERRNO_MAP)
284 #if (UV_VERSION_MAJOR > 0)
285  uv_lib_t lib;
286 #endif
287 #endif
288  void *l;
289  } u;
290 };
291 
292 /*
293  * Event lib library plugin type (when LWS_WITH_EVLIB_PLUGINS)
294  * Public so new event libs can equally be supported outside lws itself
295  */
296 
297 typedef struct lws_plugin_evlib {
299  const struct lws_event_loop_ops *ops;
301 
302 typedef int (*each_plugin_cb_t)(struct lws_plugin *p, void *user);
303 
326 lws_plugins_init(struct lws_plugin **pplugin, const char * const *d,
327  const char *_class, const char *filter,
328  each_plugin_cb_t each, void *each_user);
329 
345  void *each_user);
346 
347 #if defined(LWS_WITH_PLUGINS_BUILTIN)
348 
349 /* provide exports for builtin plugin protocols */
350 
351 extern const struct lws_protocols post_demo_protocols[1];
352 extern const struct lws_protocols lws_raw_proxy_protocols[1];
353 extern const struct lws_protocols lws_status_protocols[1];
354 extern const struct lws_protocols lws_mirror_protocols[1];
355 extern const struct lws_protocols lws_ssh_base_protocols[2];
356 extern const struct lws_protocols post_demo_protocols[1];
357 extern const struct lws_protocols dumb_increment_protocols[1];
358 extern const struct lws_protocols deaddrop_protocols[1];
359 extern const struct lws_protocols lws_raw_test_protocols[1];
360 extern const struct lws_protocols lws_sshd_demo_protocols[1];
361 extern const struct lws_protocols lws_acme_client_protocols[1];
362 extern const struct lws_protocols client_loopback_test_protocols[1];
363 extern const struct lws_protocols fulltext_demo_protocols[1];
364 extern const struct lws_protocols lws_openmetrics_export_protocols[
365 #if defined(LWS_WITH_SERVER) && defined(LWS_WITH_CLIENT) && defined(LWS_ROLE_WS)
366  4
367 #else
368 #if defined(LWS_WITH_SERVER)
369  3
370 #else
371  1
372 #endif
373 #endif
374  ];
375 
376 #define LWSOMPROIDX_DIRECT_HTTP_SERVER 0
377 #define LWSOMPROIDX_PROX_HTTP_SERVER 1
378 #define LWSOMPROIDX_PROX_WS_SERVER 2
379 #define LWSOMPROIDX_PROX_WS_CLIENT 3
380 
381 #endif
382 
const lws_plugin_header_t * hdr
lws_plugin_header_t hdr
struct lws_plugin * list
const struct lws_event_loop_ops * ops
lws_plugin_header_t hdr
lws_callback_function * callback
const struct lws_protocols * protocols
union lws_plugin::@35 u
const struct lws_extension * extensions
LWS_VISIBLE LWS_EXTERN int lws_finalize_startup(struct lws_context *context)
LWS_VISIBLE LWS_EXTERN int lws_pvo_get_str(void *in, const char *name, const char **result)
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name)
LWS_VISIBLE LWS_EXTERN void * lws_adjust_protocol_psds(struct lws *wsi, size_t new_size)
struct lws_plugin_header lws_plugin_header_t
LWS_VISIBLE LWS_EXTERN int lws_protocol_init(struct lws_context *context)
struct lws_plugin_evlib lws_plugin_evlib_t
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_get_protocol(struct lws *wsi)
struct lws_plugin_protocol lws_plugin_protocol_t
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED
int(* each_plugin_cb_t)(struct lws_plugin *p, void *user)
LWS_VISIBLE LWS_EXTERN void * lws_vhd_find_by_pvo(struct lws_context *cx, const char *protname, const char *pvo_name, const char *pvo_value)
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_VISIBLE LWS_EXTERN void * lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot, int size)
LWS_VISIBLE LWS_EXTERN void * lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot)
LWS_VISIBLE LWS_EXTERN const struct lws_protocol_vhost_options * lws_pvo_search(const struct lws_protocol_vhost_options *pvo, const char *name)
LWS_VISIBLE LWS_EXTERN int lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, void *each_user)
int lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
#define LWS_WARN_DEPRECATED
#define LWS_EXTERN
#define LWS_VISIBLE