libwebsockets
Lightweight C library for HTML5 websockets
lws-misc.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_flow
 
struct  lws_wifi_scan
 
struct  lws_humanize_unit
 
struct  lws_fsmount
 

Macros

#define lws_ptr_diff(head, tail)    ((int)((char *)(head) - (char *)(tail)))
 
#define lws_ptr_diff_size_t(head, tail)    ((size_t)(ssize_t)((char *)(head) - (char *)(tail)))
 
#define lws_strnncpy(dest, src, size1, destsize)
 
#define lws_assert_fourcc(_a, _b)   do { } while (0);
 
#define LWS_MINILEX_FAIL   -1
 
#define LWS_MINILEX_CONTINUE   0
 
#define LWS_MINILEX_MATCH   1
 

Typedefs

typedef struct lws_flow lws_flow_t
 
typedef struct lws_humanize_unit lws_humanize_unit_t
 

Enumerations

enum  { LWSDLOFLOW_STATE_READ , LWSDLOFLOW_STATE_READ_COMPLETED , LWSDLOFLOW_STATE_READ_FAILED }
 
enum  {
  LWS_RXFLOW_REASON_USER_BOOL = (1 << 0) , LWS_RXFLOW_REASON_HTTP_RXBUFFER = (1 << 6) , LWS_RXFLOW_REASON_H2_PPS_PENDING = (1 << 7) , LWS_RXFLOW_REASON_APPLIES = (1 << 14) ,
  LWS_RXFLOW_REASON_APPLIES_ENABLE_BIT = (1 << 13) , LWS_RXFLOW_REASON_APPLIES_ENABLE , LWS_RXFLOW_REASON_APPLIES_DISABLE = LWS_RXFLOW_REASON_APPLIES , LWS_RXFLOW_REASON_FLAG_PROCESS_NOW = (1 << 12)
}
 

Functions

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_buflist_append_segment (struct lws_buflist **head, const uint8_t *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN size_t lws_buflist_next_segment_len (struct lws_buflist **head, uint8_t **buf)
 
LWS_VISIBLE LWS_EXTERN size_t lws_buflist_use_segment (struct lws_buflist **head, size_t len)
 
LWS_VISIBLE LWS_EXTERN size_t lws_buflist_total_len (struct lws_buflist **head)
 
LWS_VISIBLE LWS_EXTERN int lws_buflist_linear_copy (struct lws_buflist **head, size_t ofs, uint8_t *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_buflist_linear_use (struct lws_buflist **head, uint8_t *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_buflist_fragment_use (struct lws_buflist **head, uint8_t *buf, size_t len, char *frag_first, char *frag_fin)
 
LWS_VISIBLE LWS_EXTERN void lws_buflist_destroy_all_segments (struct lws_buflist **head)
 
LWS_VISIBLE LWS_EXTERN void lws_buflist_describe (struct lws_buflist **head, void *id, const char *reason)
 
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_flow_feed (lws_flow_t *flow)
 
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_flow_req (lws_flow_t *flow)
 
LWS_VISIBLE LWS_EXTERN int lws_snprintf (char *str, size_t size, const char *format,...) LWS_FORMAT(3)
 
LWS_VISIBLE LWS_EXTERN char * lws_strncpy (char *dest, const char *src, size_t size)
 
LWS_VISIBLE LWS_EXTERN const char * lws_nstrstr (const char *buf, size_t len, const char *name, size_t nl)
 
LWS_VISIBLE LWS_EXTERN const char * lws_json_simple_find (const char *buf, size_t len, const char *name, size_t *alen)
 
LWS_VISIBLE LWS_EXTERN int lws_json_simple_strcmp (const char *buf, size_t len, const char *name, const char *comp)
 
LWS_VISIBLE LWS_EXTERN int lws_hex_len_to_byte_array (const char *h, size_t hlen, uint8_t *dest, int max)
 
LWS_VISIBLE LWS_EXTERN int lws_hex_to_byte_array (const char *h, uint8_t *dest, int max)
 
LWS_VISIBLE LWS_EXTERN void lws_hex_from_byte_array (const uint8_t *src, size_t slen, char *dest, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_hex_random (struct lws_context *context, char *dest, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_timingsafe_bcmp (const void *a, const void *b, uint32_t len)
 
LWS_VISIBLE LWS_EXTERN size_t lws_get_random (struct lws_context *context, void *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_daemonize (const char *_lock_path)
 
LWS_VISIBLE LWS_EXTERN const char *LWS_WARN_UNUSED_RESULT lws_get_library_version (void)
 
LWS_VISIBLE LWS_EXTERN void * lws_wsi_user (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_wsi_tsi (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_set_wsi_user (struct lws *wsi, void *user)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_parse_uri (char *p, const char **prot, const char **ads, int *port, const char **path)
 
LWS_VISIBLE LWS_EXTERN const char * lws_cmdline_option (int argc, const char **argv, const char *val)
 
LWS_VISIBLE LWS_EXTERN void lws_cmdline_option_handle_builtin (int argc, const char **argv, struct lws_context_creation_info *info)
 
LWS_VISIBLE LWS_EXTERN unsigned long lws_now_secs (void)
 
LWS_VISIBLE LWS_EXTERN lws_usec_t lws_now_usecs (void)
 
LWS_VISIBLE LWS_EXTERN struct lws_context *LWS_WARN_UNUSED_RESULT lws_get_context (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_vhost_listen_port (struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_count_threads (struct lws_context *context)
 
LWS_VISIBLE LWS_EXTERN struct lws *LWS_WARN_UNUSED_RESULT lws_get_parent (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN struct lws *LWS_WARN_UNUSED_RESULT lws_get_child (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_get_effective_uid_gid (struct lws_context *context, uid_t *uid, gid_t *gid)
 
LWS_VISIBLE LWS_EXTERN const struct lws_udp *LWS_WARN_UNUSED_RESULT lws_get_udp (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void * lws_get_opaque_parent_data (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_set_opaque_parent_data (struct lws *wsi, void *data)
 
LWS_VISIBLE LWS_EXTERN void * lws_get_opaque_user_data (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_set_opaque_user_data (struct lws *wsi, void *data)
 
LWS_VISIBLE LWS_EXTERN int lws_get_child_pending_on_writable (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_clear_child_pending_on_writable (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_get_close_length (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN unsigned char * lws_get_close_payload (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN struct lws * lws_get_network_wsi (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_set_allocator (void *(*realloc)(void *ptr, size_t size, const char *reason))
 
LWS_VISIBLE LWS_EXTERN int lws_rx_flow_control (struct lws *wsi, int enable)
 
LWS_VISIBLE LWS_EXTERN void lws_rx_flow_allow_all_protocol (const struct lws_context *context, const struct lws_protocols *protocol)
 
LWS_VISIBLE LWS_EXTERN size_t lws_remaining_packet_payload (struct lws *wsi)
 
size_t lws_get_allocated_heap (void)
 
LWS_VISIBLE LWS_EXTERN int lws_get_tsi (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_is_ssl (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_is_cgi (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_tls_jit_trust_blob_queury_skid (const void *_blob, size_t blen, const uint8_t *skid, size_t skid_len, const uint8_t **prpder, size_t *prder_len)
 
LWS_VISIBLE LWS_EXTERN int lws_open (const char *__file, int __oflag,...)
 
LWS_VISIBLE LWS_EXTERN void lws_explicit_bzero (void *p, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_humanize (char *buf, size_t len, uint64_t value, const lws_humanize_unit_t *schema)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu16be (uint8_t *b, uint16_t u)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu32be (uint8_t *b, uint32_t u32)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu64be (uint8_t *b, uint64_t u64)
 
LWS_VISIBLE LWS_EXTERN uint16_t lws_ser_ru16be (const uint8_t *b)
 
LWS_VISIBLE LWS_EXTERN uint32_t lws_ser_ru32be (const uint8_t *b)
 
LWS_VISIBLE LWS_EXTERN uint64_t lws_ser_ru64be (const uint8_t *b)
 
LWS_VISIBLE LWS_EXTERN int lws_vbi_encode (uint64_t value, void *buf)
 
LWS_VISIBLE LWS_EXTERN int lws_vbi_decode (const void *buf, uint64_t *value, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_fsmount_mount (struct lws_fsmount *fsm)
 
LWS_VISIBLE LWS_EXTERN int lws_fsmount_unmount (struct lws_fsmount *fsm)
 
LWS_VISIBLE LWS_EXTERN int lws_minilex_parse (const uint8_t *lex, int16_t *ps, const uint8_t c, int *match)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_sigbits (uintptr_t u)
 
LWS_VISIBLE LWS_EXTERN int lws_wol (struct lws_context *ctx, const char *ip_or_NULL, uint8_t *mac_6_bytes)
 

Variables

LWS_VISIBLE const lws_humanize_unit_t humanize_schema_si [7]
 
LWS_VISIBLE const lws_humanize_unit_t humanize_schema_si_bytes [7]
 
LWS_VISIBLE const lws_humanize_unit_t humanize_schema_us [8]
 

Data Structure Documentation

◆ lws_fsmount

struct lws_fsmount

Definition at line 1148 of file lws-misc.h.

+ Collaboration diagram for lws_fsmount:
Data Fields
const char * layers_path
const char * overlay_path
char mp[256]
char ovname[64]
char distro[64]

Macro Definition Documentation

◆ LWS_MINILEX_FAIL

#define LWS_MINILEX_FAIL   -1

Definition at line 1212 of file lws-misc.h.

◆ LWS_MINILEX_CONTINUE

#define LWS_MINILEX_CONTINUE   0

Definition at line 1213 of file lws-misc.h.

◆ LWS_MINILEX_MATCH

#define LWS_MINILEX_MATCH   1

Definition at line 1214 of file lws-misc.h.

Function Documentation

◆ lws_fsmount_mount()

LWS_VISIBLE LWS_EXTERN int lws_fsmount_mount ( struct lws_fsmount fsm)

lws_fsmount_mount() - Mounts an overlayfs stack of layers

fsm: struct lws_fsmount specifying the mount layout

This api is able to assemble up to 4 layer directories on to a mountpoint using overlayfs mount (Linux only).

Set fsm.layers_path to the base dir where the layers themselves live, the entries in fsm.layers[] specifies the relative path to the layer, comprising fsm.layers_path/fsm.distro/fsm.layers[], with [0] being the deepest, earliest layer and the rest being progressively on top of [0]; NULL indicates the layer is unused.

fsm.overlay_path is the base path of the overlayfs instantiations... empty dirs must exist at

fsm.overlay_path/overlays/fsm.ovname/work fsm.overlay_path/overlays/fsm.ovname/session

Set fsm.mp to the path of an already-existing empty dir that will be the mountpoint, this can be whereever you like.

Overlayfs merges the union of all the contributing layers at the mountpoint, the mount is writeable but the layer themselves are immutable, all additions and changes are stored in

fsm.overlay_path/overlays/fsm.ovname/session

Returns 0 if mounted OK, nonzero if errors.

Retain fsm for use with unmounting.

◆ lws_fsmount_unmount()

LWS_VISIBLE LWS_EXTERN int lws_fsmount_unmount ( struct lws_fsmount fsm)

lws_fsmount_unmount() - Unmounts an overlayfs dir

fsm: struct lws_fsmount specifying the mount layout

Unmounts the mountpoint in fsm.mp.

Delete fsm.overlay_path/overlays/fsm.ovname/session to permanently eradicate all changes from the time the mountpoint was in use.

Returns 0 if unmounted OK.

◆ lws_minilex_parse()

LWS_VISIBLE LWS_EXTERN int lws_minilex_parse ( const uint8_t lex,
int16_t *  ps,
const uint8_t  c,
int *  match 
)

lws_minilex_parse() - stateful matching vs lws minilex tables

lex: the start of the precomputed minilex table ps: pointer to the int16_t that holds the parsing state (init to 0) c: the next incoming character to parse match: pointer to take the match

Returns either

  • LWS_MINILEX_FAIL if there is no way to match the characters seen, this is sticky for additional characters until the *ps is reset to 0.
  • LWS_MINILEX_CONTINUE if the character could be part of a match but more are required to see if it can match
  • LWS_MINILEX_MATCH and *match is set to the match index if there is a valid match.

In cases where the match is ambiguous, eg, we saw "right" and the possible matches are "right" or "right-on", LWS_MINILEX_CONTINUE is returned. To allow it to match on the complete-but-ambiguous token, if the caller sees a delimiter it can call lws_minilex_parse() again with c == 0. This will either return LWS_MINILEX_MATCH and set *match to the smaller ambiguous match, or return LWS_MINILEX_FAIL.

◆ lws_sigbits()

LWS_VISIBLE LWS_EXTERN unsigned int lws_sigbits ( uintptr_t  u)

◆ lws_wol()

LWS_VISIBLE LWS_EXTERN int lws_wol ( struct lws_context *  ctx,
const char *  ip_or_NULL,
uint8_t mac_6_bytes 
)

lws_wol() - broadcast a magic WOL packet to MAC, optionally binding to if IP

ctx: The lws context ip_or_NULL: The IP address to bind to at the client side, to send the magic packet on. If NULL, the system chooses, probably the interface with the default route. mac_6_bytes: Points to a 6-byte MAC address to direct the magic packet to