libwebsockets
Lightweight C library for HTML5 websockets
context and vhost related functions

Modules

 Vhost mounts and options
 

Data Structures

struct  lws_context_creation_info
 
struct  lws_protocol_vhost_options
 

Macros

#define LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT
 
#define LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME   (1ll << 2)
 
#define LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT
 
#define LWS_SERVER_OPTION_LIBEV   (1ll << 4)
 
#define LWS_SERVER_OPTION_DISABLE_IPV6   (1ll << 5)
 
#define LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS   (1ll << 6)
 
#define LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED   (1ll << 7)
 
#define LWS_SERVER_OPTION_VALIDATE_UTF8   (1ll << 8)
 
#define LWS_SERVER_OPTION_SSL_ECDH
 
#define LWS_SERVER_OPTION_LIBUV   (1ll << 10)
 
#define LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS
 
#define LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT   (1ll << 12)
 
#define LWS_SERVER_OPTION_EXPLICIT_VHOSTS   (1ll << 13)
 
#define LWS_SERVER_OPTION_UNIX_SOCK   (1ll << 14)
 
#define LWS_SERVER_OPTION_STS   (1ll << 15)
 
#define LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY   (1ll << 16)
 
#define LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE   (1ll << 17)
 
#define LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN   (1ll << 18)
 
#define LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN   (1ll << 19)
 
#define LWS_SERVER_OPTION_FALLBACK_TO_RAW   /* use below name */ (1ll << 20)
 
#define LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG   (1ll << 20)
 
#define LWS_SERVER_OPTION_LIBEVENT   (1ll << 21)
 
#define LWS_SERVER_OPTION_ONLY_RAW   /* Use below name instead */ (1ll << 22)
 
#define LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG   (1ll << 22)
 
#define LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE   (1ll << 23)
 
#define LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX   (1ll << 24)
 
#define LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT   (1ll << 25)
 
#define LWS_SERVER_OPTION_IGNORE_MISSING_CERT   (1ll << 26)
 
#define LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK   (1ll << 27)
 
#define LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE   (1ll << 28)
 
#define LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER   (1ll << 29)
 
#define LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND   (1ll << 30)
 
#define LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW   (1ll << 31)
 
#define LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL   (1ll << 32)
 
#define LWS_SERVER_OPTION_GLIB   (1ll << 33)
 
#define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE   (1ll << 34)
 
#define LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES   (1ll << 35)
 
#define lws_check_opt(c, f)   ((((uint64_t)c) & ((uint64_t)f)) == ((uint64_t)f))
 

Typedefs

typedef int(* lws_context_ready_cb_t) (struct lws_context *context)
 
typedef int(* lws_peer_limits_notify_t) (struct lws_context *ctx, lws_sockfd_type sockfd, lws_sockaddr46 *sa46)
 
typedef int(* lws_reload_func) (void)
 

Functions

LWS_VISIBLE LWS_EXTERN struct lws_context * lws_create_context (const struct lws_context_creation_info *info)
 
LWS_VISIBLE LWS_EXTERN void lws_context_destroy (struct lws_context *context)
 
LWS_VISIBLE LWS_EXTERN void lws_context_deprecate (struct lws_context *context, lws_reload_func cb)
 
LWS_VISIBLE LWS_EXTERN int lws_context_is_deprecated (struct lws_context *context)
 
LWS_VISIBLE LWS_EXTERN int lws_set_proxy (struct lws_vhost *vhost, const char *proxy)
 
LWS_VISIBLE LWS_EXTERN int lws_set_socks (struct lws_vhost *vhost, const char *socks)
 
LWS_VISIBLE LWS_EXTERN struct lws_vhost * lws_create_vhost (struct lws_context *context, const struct lws_context_creation_info *info)
 
LWS_VISIBLE LWS_EXTERN void lws_vhost_destroy (struct lws_vhost *vh)
 
LWS_VISIBLE LWS_EXTERN int lwsws_get_config_globals (struct lws_context_creation_info *info, const char *d, char **config_strings, int *len)
 
LWS_VISIBLE LWS_EXTERN int lwsws_get_config_vhosts (struct lws_context *context, struct lws_context_creation_info *info, const char *d, char **config_strings, int *len)
 
LWS_VISIBLE LWS_EXTERN struct lws_vhost * lws_get_vhost (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN const char * lws_get_vhost_name (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN struct lws_vhost * lws_get_vhost_by_name (struct lws_context *context, const char *name)
 
LWS_VISIBLE LWS_EXTERN int lws_get_vhost_port (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN void * lws_get_vhost_user (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN const char * lws_get_vhost_iface (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN int lws_json_dump_vhost (const struct lws_vhost *vh, char *buf, int len)
 
LWS_VISIBLE LWS_EXTERN int lws_json_dump_context (const struct lws_context *context, char *buf, int len, int hide_vhosts)
 
LWS_VISIBLE LWS_EXTERN void * lws_vhost_user (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN void * lws_context_user (struct lws_context *context)
 

Detailed Description

Context and Vhost releated functions

LWS requires that there is one context, in which you may define multiple vhosts. Each vhost is a virtual host, with either its own listen port or sharing an existing one. Each vhost has its own SSL context that can be set up individually or left disabled.

If you don't care about multiple "site" support, you can ignore it and lws will create a single default vhost at context creation time.

Macro Definition Documentation

◆ LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG

#define LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG   (1ll << 22)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) All connections to this vhost / port are bound to the role and protocol given in .listen_accept_role / .listen_accept_protocol.

If those explicit user-controlled names are NULL, for backwards- compatibility the connection is bound to "raw-skt" role, and in order of priority: 1) the vh protocol with a pvo named "raw", 2) the vh protocol with a pvo named "default", or 3) protocols[0].

It's much preferred to specify the role + protocol using the .listen_accept_role and .listen_accept_protocol in the info struct.

◆ LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER

#define LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER   (1ll << 29)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) If you really want to allow HTTP connections on a tls listener, you can do it with this combined with LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT. But this is allowing accidental loss of the security assurances provided by tls depending on the client using http when he meant https... it's not recommended.

◆ LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE

#define LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE   (1ll << 23)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Set to allow multiple listen sockets on one interface + address + port. The default is to strictly allow only one listen socket at a time. This is automatically selected if you have multiple service threads. Linux only.

◆ LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT

#define LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT

#include <include/libwebsockets/lws-context-vhost.h>

Value:
((1ll << 3) | \
(1ll << 12))

(VH) Allow non-SSL (plaintext) connections on the same port as SSL is listening. If combined with LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS it will try to force http connections on an https listener (eg, http://x.com:443) to redirect to an explicit https connection (eg, https://x.com)

◆ LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX

#define LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX   (1ll << 24)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Force setting up the vhost SSL_CTX, even though the user code doesn't explicitly provide a cert in the info struct. It implies the user code is going to provide a cert at the LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS callback, which provides the vhost SSL_CTX * in the user parameter.

◆ LWS_SERVER_OPTION_DISABLE_IPV6

#define LWS_SERVER_OPTION_DISABLE_IPV6   (1ll << 5)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Disable IPV6 support

◆ LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS

#define LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS   (1ll << 6)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Don't load OS CA certs, you will need to load your own CA cert(s)

◆ LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT

#define LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT   (1ll << 12)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Initialize the SSL library at all

◆ LWS_SERVER_OPTION_EXPLICIT_VHOSTS

#define LWS_SERVER_OPTION_EXPLICIT_VHOSTS   (1ll << 13)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Only create the context when calling context create api, implies user code will create its own vhosts

◆ LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND

#define LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND   (1ll << 30)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) When instantiating a new vhost and the specified port is already in use, a null value shall be return to signal the error.

◆ LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG

#define LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG   (1ll << 20)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) if invalid http is coming in the first line, then abandon trying to treat the connection as http, and belatedly apply the .listen_accept_role / .listen_accept_protocol info struct members to the connection. If they are NULL, for backwards-compatibility the connection is bound to "raw-skt" role, and in order of priority: 1) the vh protocol with a pvo named "raw", 2) the vh protocol with a pvo named "default", or 3) protocols[0].

Must be combined with LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT to work with a socket listening with tls.

◆ LWS_SERVER_OPTION_GLIB

#define LWS_SERVER_OPTION_GLIB   (1ll << 33)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Use glib event loop

◆ LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW

#define LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW   (1ll << 31)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Indicates the connections using this vhost should ignore h2 WINDOW_UPDATE from broken peers and fix them up

◆ LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE

#define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE   (1ll << 34)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Tell the vhost to treat plain text http connections as H2 with prior knowledge (no upgrade request involved)

◆ LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE

#define LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE   (1ll << 28)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Send lws default HTTP headers recommended by Mozilla Observatory for security. This is a helper option that sends canned headers on each http response enabling a VERY strict Content Security Policy. The policy is so strict, for example it won't let the page run its own inline JS nor show images or take CSS from a different server. In many cases your JS only comes from your server as do the image sources and CSS, so that is what you want... attackers hoping to inject JS into your DOM are completely out of luck since even if they succeed, it will be rejected for execution by the browser according to the strict CSP. In other cases you have to deviate from the complete strictness, in which case don't use this flag: use the .headers member in the vhost init described in struct lws_context_creation_info instead to send the adapted headers yourself.

◆ LWS_SERVER_OPTION_IGNORE_MISSING_CERT

#define LWS_SERVER_OPTION_IGNORE_MISSING_CERT   (1ll << 26)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Don't fail if the vhost TLS cert or key are missing, just continue. The vhost won't be able to serve anything, but if for example the ACME plugin was configured to fetch a cert, this lets you bootstrap your vhost from having no cert to start with.

◆ LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY

#define LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY   (1ll << 16)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Enable LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE to take effect

◆ LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE

#define LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE   (1ll << 17)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) if set, only ipv6 allowed on the vhost

◆ LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN

#define LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN   (1ll << 19)

#include <include/libwebsockets/lws-context-vhost.h>

For backwards-compatibility reasons, by default lws prepends "http://" to the origin you give in the client connection info struct. If you give this flag when you create the context, only the string you give in the client connect info for .origin (if any) will be used directly.

◆ LWS_SERVER_OPTION_LIBEV

#define LWS_SERVER_OPTION_LIBEV   (1ll << 4)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Use libev event loop

◆ LWS_SERVER_OPTION_LIBEVENT

#define LWS_SERVER_OPTION_LIBEVENT   (1ll << 21)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Use libevent event loop

◆ LWS_SERVER_OPTION_LIBUV

#define LWS_SERVER_OPTION_LIBUV   (1ll << 10)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Use libuv event loop

◆ LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES

#define LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES   (1ll << 35)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Disable lws_system state, eg, because we are a secure streams proxy client that is not trying to track system state by itself.

◆ LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED

#define LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED   (1ll << 7)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Accept connections with no valid Cert (eg, selfsigned)

◆ LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS

#define LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS

#include <include/libwebsockets/lws-context-vhost.h>

Value:
((1ll << 11) |\
(1ll << 12))

(VH) Use an http redirect to force the client to ask for https. Notice if your http server issues the STS header and the client has ever seen that, the client will fail the http connection before it can actually do the redirect.

Combine with LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS to handle, eg, http://x.com:443 -> https://x.com

(deprecated: use mount redirection)

◆ LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT

#define LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT

#include <include/libwebsockets/lws-context-vhost.h>

Value:
((1ll << 1) | \
(1ll << 12))

(VH) Don't allow the connection unless the client has a client cert that we recognize; provides LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT

◆ LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT

#define LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT   (1ll << 25)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) You probably don't want this. It forces this vhost to not call LWS_CALLBACK_PROTOCOL_INIT on its protocols. It's used in the special case of a temporary vhost bound to a single protocol.

◆ LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME

#define LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME   (1ll << 2)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Don't try to get the server's hostname

◆ LWS_SERVER_OPTION_SSL_ECDH

#define LWS_SERVER_OPTION_SSL_ECDH

#include <include/libwebsockets/lws-context-vhost.h>

Value:
((1ll << 9) | \
(1ll << 12))

(VH) initialize ECDH ciphers

◆ LWS_SERVER_OPTION_STS

#define LWS_SERVER_OPTION_STS   (1ll << 15)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Send Strict Transport Security header, making clients subsequently go to https even if user asked for http

◆ LWS_SERVER_OPTION_UNIX_SOCK

#define LWS_SERVER_OPTION_UNIX_SOCK   (1ll << 14)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Use Unix socket

◆ LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN

#define LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN   (1ll << 18)

#include <include/libwebsockets/lws-context-vhost.h>

(CTX) Libuv only: Do not spin on SIGSEGV / SIGFPE. A segfault normally makes the lib spin so you can attach a debugger to it even if it happened without a debugger in place. You can disable that by giving this option.

◆ LWS_SERVER_OPTION_VALIDATE_UTF8

#define LWS_SERVER_OPTION_VALIDATE_UTF8   (1ll << 8)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Check UT-8 correctness

◆ LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL

#define LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL   (1ll << 32)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) Tell the vhost to treat half-closed remote clients as entered into an immortal (ie, not subject to normal timeouts) long poll mode.

◆ LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK

#define LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK   (1ll << 27)

#include <include/libwebsockets/lws-context-vhost.h>

(VH) On this vhost, if the connection is being upgraded, insist that there's a Host: header and that the contents match the vhost name + port (443 / 80 are assumed if no :port given based on if the connection is using TLS).

By default, without this flag, on upgrade lws just checks that the Host: header was given without checking the contents... this is to allow lax hostname mappings like localhost / 127.0.0.1, and CNAME mappings like www.mysite.com / mysite.com

Function Documentation

◆ lws_context_deprecate()

LWS_VISIBLE LWS_EXTERN void lws_context_deprecate ( struct lws_context *  context,
lws_reload_func  cb 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_context_deprecate() - Deprecate the websocket context

Parameters
contextWebsocket context
cbCallback notified when old context listen sockets are closed
 This function is used on an existing context before superceding it
 with a new context.

 It closes any listen sockets in the context, so new connections are
 not possible.

 And it marks the context to be deleted when the number of active
 connections into it falls to zero.

 This is aimed at allowing seamless configuration reloads.

 The callback cb will be called after the listen sockets are actually
 closed and may be reopened.  In the callback the new context should be
 configured and created.  (With libuv, socket close happens async after
 more loop events).

◆ lws_context_destroy()

LWS_VISIBLE LWS_EXTERN void lws_context_destroy ( struct lws_context *  context)

#include <include/libwebsockets/lws-context-vhost.h>

lws_context_destroy() - Destroy the websocket context

Parameters
contextWebsocket context
 This function closes any active connections and then frees the
 context.  After calling this, any further use of the context is
 undefined.

◆ lws_context_user()

LWS_VISIBLE LWS_EXTERN void* lws_context_user ( struct lws_context *  context)

#include <include/libwebsockets/lws-context-vhost.h>

lws_context_user() - get the user data associated with the context

Parameters
contextWebsocket context

This returns the optional user allocation that can be attached to the context the sockets live in at context_create time. It's a way to let all sockets serviced in the same context share data without using globals statics in the user code.

◆ lws_create_context()

LWS_VISIBLE LWS_EXTERN struct lws_context* lws_create_context ( const struct lws_context_creation_info info)

#include <include/libwebsockets/lws-context-vhost.h>

lws_create_context() - Create the websocket handler

Parameters
infopointer to struct with parameters
 This function creates the listening socket (if serving) and takes care
 of all initialization in one step.

 If option LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, no vhost is
 created; you're expected to create your own vhosts afterwards using
 lws_create_vhost().  Otherwise a vhost named "default" is also created
 using the information in the vhost-related members, for compatibility.

 After initialization, it returns a struct lws_context * that
 represents this server.  After calling, user code needs to take care
 of calling lws_service() with the context pointer to get the
 server's sockets serviced.  This must be done in the same process
 context as the initialization call.

 The protocol callback functions are called for a handful of events
 including http requests coming in, websocket connections becoming
 established, and data arriving; it's also called periodically to allow
 async transmission.

 HTTP requests are sent always to the FIRST protocol in protocol, since
 at that time websocket protocol has not been negotiated.  Other
 protocols after the first one never see any HTTP callback activity.

 The server created is a simple http server by default; part of the
 websocket standard is upgrading this http connection to a websocket one.

 This allows the same server to provide files like scripts and favicon /
 images or whatever over http and dynamic data over websockets all in
 one place; they're all handled in the user callback.

◆ lws_create_vhost()

LWS_VISIBLE LWS_EXTERN struct lws_vhost* lws_create_vhost ( struct lws_context *  context,
const struct lws_context_creation_info info 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_create_vhost() - Create a vhost (virtual server context)

Parameters
contextpointer to result of lws_create_context()
infopointer to struct with parameters

This function creates a virtual server (vhost) using the vhost-related members of the info struct. You can create many vhosts inside one context if you created the context with the option LWS_SERVER_OPTION_EXPLICIT_VHOSTS

◆ lws_get_vhost()

LWS_VISIBLE LWS_EXTERN struct lws_vhost* lws_get_vhost ( struct lws *  wsi)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost() - return the vhost a wsi belongs to

Parameters
wsiwhich connection

◆ lws_get_vhost_by_name()

LWS_VISIBLE LWS_EXTERN struct lws_vhost* lws_get_vhost_by_name ( struct lws_context *  context,
const char *  name 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost_by_name() - returns the vhost with the requested name, or NULL

Parameters
contextthe lws_context to look in
namevhost name we are looking for

Returns NULL, or the vhost with the name name

◆ lws_get_vhost_iface()

LWS_VISIBLE LWS_EXTERN const char* lws_get_vhost_iface ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost_iface() - returns the binding for the vhost listen socket

Parameters
vhostwhich vhost

◆ lws_get_vhost_name()

LWS_VISIBLE LWS_EXTERN const char* lws_get_vhost_name ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost_name() - returns the name of a vhost

Parameters
vhostwhich vhost

◆ lws_get_vhost_port()

LWS_VISIBLE LWS_EXTERN int lws_get_vhost_port ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost_port() - returns the port a vhost listens on, or -1

Parameters
vhostwhich vhost

◆ lws_get_vhost_user()

LWS_VISIBLE LWS_EXTERN void* lws_get_vhost_user ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-context-vhost.h>

lws_get_vhost_user() - returns the user pointer for the vhost

Parameters
vhostwhich vhost

◆ lws_json_dump_context()

LWS_VISIBLE LWS_EXTERN int lws_json_dump_context ( const struct lws_context *  context,
char *  buf,
int  len,
int  hide_vhosts 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_json_dump_context() - describe context state and stats in JSON

Parameters
contextthe context
bufbuffer to fill with JSON
lenmax length of buf
hide_vhostsnonzero to not provide per-vhost mount etc information

Generates a JSON description of vhost state into buf

◆ lws_json_dump_vhost()

LWS_VISIBLE LWS_EXTERN int lws_json_dump_vhost ( const struct lws_vhost *  vh,
char *  buf,
int  len 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_json_dump_vhost() - describe vhost state and stats in JSON

Parameters
vhthe vhost
bufbuffer to fill with JSON
lenmax length of buf

◆ lws_set_proxy()

LWS_VISIBLE LWS_EXTERN int lws_set_proxy ( struct lws_vhost *  vhost,
const char *  proxy 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_set_proxy() - Setups proxy to lws_context.

Parameters
vhostpointer to struct lws_vhost you want set proxy for
proxypointer to c string containing proxy in format address:port

Returns 0 if proxy string was parsed and proxy was setup. Returns -1 if proxy is NULL or has incorrect format.

This is only required if your OS does not provide the http_proxy environment variable (eg, OSX)

IMPORTANT! You should call this function right after creation of the lws_context and before call to connect. If you call this function after connect behavior is undefined. This function will override proxy settings made on lws_context creation with genenv() call.

◆ lws_set_socks()

LWS_VISIBLE LWS_EXTERN int lws_set_socks ( struct lws_vhost *  vhost,
const char *  socks 
)

#include <include/libwebsockets/lws-context-vhost.h>

lws_set_socks() - Setup socks to lws_context.

Parameters
vhostpointer to struct lws_vhost you want set socks for
sockspointer to c string containing socks in format address:port

Returns 0 if socks string was parsed and socks was setup. Returns -1 if socks is NULL or has incorrect format.

This is only required if your OS does not provide the socks_proxy environment variable (eg, OSX)

IMPORTANT! You should call this function right after creation of the lws_context and before call to connect. If you call this function after connect behavior is undefined. This function will override proxy settings made on lws_context creation with genenv() call.

◆ lws_vhost_destroy()

LWS_VISIBLE LWS_EXTERN void lws_vhost_destroy ( struct lws_vhost *  vh)

#include <include/libwebsockets/lws-context-vhost.h>

lws_vhost_destroy() - Destroy a vhost (virtual server context)

Parameters
vhpointer to result of lws_create_vhost()

This function destroys a vhost. Normally, if you just want to exit, then lws_destroy_context() will take care of everything. If you want to destroy an individual vhost and all connections and allocations, you can do it with this.

If the vhost has a listen sockets shared by other vhosts, it will be given to one of the vhosts sharing it rather than closed.

The vhost close is staged according to the needs of the event loop, and if there are multiple service threads. At the point the vhost itself if about to be freed, if you provided a finalize callback and optional arg at vhost creation time, it will be called just before the vhost is freed.

◆ lws_vhost_user()

LWS_VISIBLE LWS_EXTERN void* lws_vhost_user ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-context-vhost.h>

lws_vhost_user() - get the user data associated with the vhost

Parameters
vhostWebsocket vhost

This returns the optional user pointer that can be attached to a vhost when it was created. Lws never dereferences this pointer, it only sets it when the vhost is created, and returns it using this api.

◆ lwsws_get_config_globals()

LWS_VISIBLE LWS_EXTERN int lwsws_get_config_globals ( struct lws_context_creation_info info,
const char *  d,
char **  config_strings,
int *  len 
)

#include <include/libwebsockets/lws-context-vhost.h>

lwsws_get_config_globals() - Parse a JSON server config file

Parameters
infopointer to struct with parameters
dfilepath of the config file
config_stringsstorage for the config strings extracted from JSON, the pointer is incremented as strings are stored
lenpointer to the remaining length left in config_strings the value is decremented as strings are stored

This function prepares a n lws_context_creation_info struct with global settings from a file d.

Requires CMake option LWS_WITH_LEJP_CONF to have been enabled

◆ lwsws_get_config_vhosts()

LWS_VISIBLE LWS_EXTERN int lwsws_get_config_vhosts ( struct lws_context *  context,
struct lws_context_creation_info info,
const char *  d,
char **  config_strings,
int *  len 
)

#include <include/libwebsockets/lws-context-vhost.h>

lwsws_get_config_vhosts() - Create vhosts from a JSON server config file

Parameters
contextpointer to result of lws_create_context()
infopointer to struct with parameters
dfilepath of the config file
config_stringsstorage for the config strings extracted from JSON, the pointer is incremented as strings are stored
lenpointer to the remaining length left in config_strings the value is decremented as strings are stored

This function creates vhosts into a context according to the settings in JSON files found in directory d.

Requires CMake option LWS_WITH_LEJP_CONF to have been enabled