libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
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
43
45 const char *name;
66 unsigned int id;
73 void *user;
84
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
100lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name);
101
112lws_get_protocol(struct lws *wsi);
113
117
129lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost,
130 const struct lws_protocols *prot, int size);
131
142lws_protocol_vh_priv_get(struct lws_vhost *vhost,
143 const struct lws_protocols *prot);
144
176lws_vhd_find_by_pvo(struct lws_context *cx, const char *protname,
177 const char *pvo_name, const char *pvo_value);
178
179
195lws_adjust_protocol_psds(struct lws *wsi, size_t new_size);
196
206lws_finalize_startup(struct lws_context *context, const char *where);
207
217lws_pvo_search(const struct lws_protocol_vhost_options *pvo, const char *name);
218
229lws_pvo_get_str(void *in, const char *name, const char **result);
230
231struct lws_http_mount;
232
242lws_pmo_search(const struct lws_http_mount *mount, const char *name);
243
254lws_pmo_get_str(const struct lws_http_mount *mount, const char *name,
255 const char **result);
256
258lws_protocol_init(struct lws_context *context);
259
260/*
261 * 192: lws_plugin_header_t .priority
262 * 193: lws_plugin_protocol_t .init / .deinit
263 */
264#define LWS_PLUGIN_API_MAGIC 193
265
266/*
267 * Abstract plugin header for any kind of plugin class, always at top of
268 * actual class plugin export type.
269 *
270 * The export type object must be exported with the same name as the plugin
271 * file, eg, libmyplugin.so must export a const one of these as the symbol
272 * "myplugin".
273 *
274 * That is the only expected export from the plugin.
275 */
276
277typedef struct lws_plugin_header {
278 const char *name;
279 const char *_class;
280 const char *lws_build_hash; /* set to LWS_BUILD_HASH */
281
282 unsigned int api_magic;
283 /* set to LWS_PLUGIN_API_MAGIC at plugin build time */
284
285 unsigned int priority;
288
289 /* plugin-class specific superclass data follows */
291
292/*
293 * "lws_protocol_plugin" class export, for lws_protocol implementations done
294 * as plugins
295 */
296typedef struct lws_plugin_protocol {
298
299 const struct lws_protocols *protocols;
300 const struct lws_extension *extensions;
303
304 /* the members below are only read from plugins built with
305 * api_magic >= 193 */
306
307 int (*init)(struct lws_context *cx);
316 void (*deinit)(struct lws_context *cx);
321
322
323/*
324 * This is the dynamic, runtime created part of the plugin instantiation.
325 * These are kept in a linked-list and destroyed with the context.
326 */
327
329 struct lws_plugin *list;
330
332
333 char basename[64];
336
337 union {
338#if defined(LWS_WITH_LIBUV) && defined(UV_ERRNO_MAP)
339#if (UV_VERSION_MAJOR > 0)
340 uv_lib_t lib;
341#endif
342#endif
343 void *l;
344 } u;
345};
346
347/*
348 * Event lib library plugin type (when LWS_WITH_EVLIB_PLUGINS)
349 * Public so new event libs can equally be supported outside lws itself
350 */
351
356
357typedef int (*each_plugin_cb_t)(struct lws_plugin *p, void *user);
358
381lws_plugins_init(struct lws_plugin **pplugin, const char * const *d,
382 const char *_class, const char *filter,
383 each_plugin_cb_t each, void *each_user);
384
400 void *each_user);
401
402
403struct pss_webrtc;
404struct vhd_webrtc;
405struct lws_webrtc_peer_media;
406
407typedef void (*lws_webrtc_on_media_cb)(struct lws *wsi_ws, int tid, const uint8_t *buf, size_t len, int marker, uint32_t timestamp);
408
409typedef int (*lws_webrtc_session_iter_cb)(struct pss_webrtc *pss, void *user);
410
415
416#define LWS_WEBRTC_OPS_ABI_VERSION 9
417
420
421 int (*send_video)(struct lws_webrtc_peer_media *media, const uint8_t *buf, size_t len, int codec, uint32_t pts);
422 int (*send_audio)(struct lws_webrtc_peer_media *media, const uint8_t *buf, size_t len, uint32_t timestamp);
423 int (*send_text)(struct pss_webrtc *pss, const char *buf, size_t len);
424 int (*send_pli)(struct pss_webrtc *pss);
425 void (*media_ref)(struct lws_webrtc_peer_media *media);
426 void (*media_unref)(struct lws_webrtc_peer_media **pmedia);
427 int (*foreach_session)(struct vhd_webrtc *vhd, lws_webrtc_session_iter_cb cb, void *user);
428 struct lws_webrtc_peer_media *(*get_media)(struct pss_webrtc *pss);
429 int (*shared_callback)(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len, struct vhd_webrtc *vhd);
430
431 void *(*get_user_data)(struct pss_webrtc *pss);
432 void (*set_user_data)(struct pss_webrtc *pss, void *data);
433 struct lws_vhost *(*get_vhost)(struct vhd_webrtc *vhd);
434 struct lws_context *(*get_context)(struct vhd_webrtc *vhd);
435 void (*set_on_media)(struct vhd_webrtc *vhd, lws_webrtc_on_media_cb cb);
436
437 uint8_t (*get_video_pt)(struct pss_webrtc *pss);
438 uint8_t (*get_audio_pt)(struct pss_webrtc *pss);
439
440 uint8_t (*get_video_pt_h264)(struct pss_webrtc *pss);
441 uint8_t (*get_video_pt_av1)(struct pss_webrtc *pss);
442 uint16_t (*get_seq_video)(struct pss_webrtc *pss);
443 int (*create_offer)(struct pss_webrtc *pss);
444};
445
446#if defined(LWS_WITH_PLUGINS_BUILTIN)
447
448/* provide exports for builtin plugin protocols */
449
450extern const struct lws_protocols post_demo_protocols[1];
451extern const struct lws_protocols lws_raw_proxy_protocols[1];
452extern const struct lws_protocols lws_status_protocols[1];
453extern const struct lws_protocols lws_mirror_protocols[1];
454extern const struct lws_protocols lws_ssh_base_protocols[2];
455extern const struct lws_protocols post_demo_protocols[1];
456extern const struct lws_protocols dumb_increment_protocols[1];
457extern const struct lws_protocols deaddrop_protocols[1];
458extern const struct lws_protocols lws_raw_test_protocols[1];
459extern const struct lws_protocols lws_sshd_demo_protocols[1];
460extern const struct lws_protocols lws_acme_client_protocols[1];
461extern const struct lws_protocols client_loopback_test_protocols[1];
462extern const struct lws_protocols fulltext_demo_protocols[1];
463extern const struct lws_protocols lws_openmetrics_export_protocols[
464#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_CLIENT) && defined(LWS_ROLE_WS)
465 4
466#else
467#if defined(LWS_WITH_SERVER)
468 3
469#else
470 1
471#endif
472#endif
473 ];
474extern const struct lws_protocols lws_dht_object_store_protocols[];
475
476#define LWSOMPROIDX_DIRECT_HTTP_SERVER 0
477#define LWSOMPROIDX_PROX_HTTP_SERVER 1
478#define LWSOMPROIDX_PROX_WS_SERVER 2
479#define LWSOMPROIDX_PROX_WS_CLIENT 3
480
481#endif
482
483typedef void (*lws_dht_store_completion_cb_t)(void *closure, int result);
484
485
486
lws_plugin_header_t hdr
const struct lws_event_loop_ops * ops
lws_plugin_header_t hdr
void(* deinit)(struct lws_context *cx)
int(* init)(struct lws_context *cx)
lws_callback_function * callback
const struct lws_protocols * protocols
const struct lws_extension * extensions
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_protocol_get(struct lws *wsi) LWS_WARN_DEPRECATED
LWS_VISIBLE LWS_EXTERN int lws_pmo_get_str(const struct lws_http_mount *mount, const char *name, const char **result)
void(* lws_dht_store_completion_cb_t)(void *closure, int result)
LWS_VISIBLE LWS_EXTERN int lws_pvo_get_str(void *in, const char *name, const char **result)
int(* lws_webrtc_session_iter_cb)(struct pss_webrtc *pss, void *user)
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name)
struct lws_plugin_header lws_plugin_header_t
LWS_VISIBLE LWS_EXTERN void * lws_adjust_protocol_psds(struct lws *wsi, size_t new_size)
LWS_VISIBLE LWS_EXTERN int lws_protocol_init(struct lws_context *context)
void(* lws_webrtc_on_media_cb)(struct lws *wsi_ws, int tid, const uint8_t *buf, size_t len, int marker, uint32_t timestamp)
struct lws_plugin_evlib lws_plugin_evlib_t
LWS_VISIBLE LWS_EXTERN const struct lws_protocols * lws_get_protocol(struct lws *wsi)
LWS_VISIBLE LWS_EXTERN void * lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot)
struct lws_plugin_protocol lws_plugin_protocol_t
LWS_VISIBLE LWS_EXTERN const struct lws_protocol_vhost_options * lws_pmo_search(const struct lws_http_mount *mount, const char *name)
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 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_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 int lws_finalize_startup(struct lws_context *context, const char *where)
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 int lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, void *each_user)
@ LWS_WEBRTC_CODEC_H264
@ LWS_WEBRTC_CODEC_AV1
int lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
lws_callback_reasons
unsigned short uint16_t
unsigned int uint32_t
#define LWS_WARN_DEPRECATED
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
const lws_plugin_header_t * hdr
struct lws_plugin * list
union lws_plugin::@212075251220221362023025000075256263262302222360 u
uint8_t(* get_video_pt_av1)(struct pss_webrtc *pss)
int(* send_video)(struct lws_webrtc_peer_media *media, const uint8_t *buf, size_t len, int codec, uint32_t pts)
void(* set_user_data)(struct pss_webrtc *pss, void *data)
int(* send_audio)(struct lws_webrtc_peer_media *media, const uint8_t *buf, size_t len, uint32_t timestamp)
uint8_t(* get_audio_pt)(struct pss_webrtc *pss)
int(* foreach_session)(struct vhd_webrtc *vhd, lws_webrtc_session_iter_cb cb, void *user)
void(* media_unref)(struct lws_webrtc_peer_media **pmedia)
int(* shared_callback)(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len, struct vhd_webrtc *vhd)
uint16_t(* get_seq_video)(struct pss_webrtc *pss)
uint8_t(* get_video_pt)(struct pss_webrtc *pss)
int(* send_text)(struct pss_webrtc *pss, const char *buf, size_t len)
int(* send_pli)(struct pss_webrtc *pss)
void(* set_on_media)(struct vhd_webrtc *vhd, lws_webrtc_on_media_cb cb)
int(* create_offer)(struct pss_webrtc *pss)
uint8_t(* get_video_pt_h264)(struct pss_webrtc *pss)
void(* media_ref)(struct lws_webrtc_peer_media *media)