libwebsockets
Lightweight C library for HTML5 websockets
|
Go to the source code of this file.
Data Structures | |
struct | lws_tokenize |
struct | lws_strexp |
Macros | |
#define | LWS_TOKENIZE_F_MINUS_NONTERM (1 << 0) |
#define | LWS_TOKENIZE_F_AGG_COLON (1 << 1) |
#define | LWS_TOKENIZE_F_COMMA_SEP_LIST (1 << 2) |
#define | LWS_TOKENIZE_F_RFC7230_DELIMS (1 << 3) |
#define | LWS_TOKENIZE_F_DOT_NONTERM (1 << 4) |
#define | LWS_TOKENIZE_F_NO_FLOATS (1 << 5) |
#define | LWS_TOKENIZE_F_NO_INTEGERS (1 << 6) |
#define | LWS_TOKENIZE_F_HASH_COMMENT (1 << 7) |
#define | LWS_TOKENIZE_F_SLASH_NONTERM (1 << 8) |
#define | LWS_TOKENIZE_F_ASTERISK_NONTERM (1 << 9) |
#define | LWS_TOKENIZE_F_EQUALS_NONTERM (1 << 10) |
#define | LWS_TOKENIZE_F_COLON_NONTERM (1 << 11) |
#define | LWS_TOKENIZE_F_EXPECT_MORE (1 << 12) |
Typedefs | |
typedef struct lws_tokenize | lws_tokenize_t |
typedef int(* | lws_strexp_expand_cb) (void *priv, const char *name, char *out, size_t *pos, size_t olen, size_t *exp_ofs) |
typedef struct lws_strexp | lws_strexp_t |
Enumerations | |
enum | lws_tokenize_elem { LWS_TOKZE_ERRS = 7 , LWS_TOKZE_TOO_LONG = -7 , LWS_TOKZE_WANT_READ = -6 , LWS_TOKZE_ERR_BROKEN_UTF8 = -5 , LWS_TOKZE_ERR_UNTERM_STRING = -4 , LWS_TOKZE_ERR_MALFORMED_FLOAT = -3 , LWS_TOKZE_ERR_NUM_ON_LHS = -2 , LWS_TOKZE_ERR_COMMA_LIST = -1 , LWS_TOKZE_ENDED = 0 , LWS_TOKZE_DELIMITER , LWS_TOKZE_TOKEN , LWS_TOKZE_INTEGER , LWS_TOKZE_FLOAT , LWS_TOKZE_TOKEN_NAME_EQUALS , LWS_TOKZE_TOKEN_NAME_COLON , LWS_TOKZE_QUOTED_STRING } |
enum | lws_tokenize_delimiter_tracking { LWSTZ_DT_NEED_FIRST_CONTENT , LWSTZ_DT_NEED_DELIM , LWSTZ_DT_NEED_NEXT_CONTENT } |
enum | lws_tokenize_state { LWS_TOKZS_LEADING_WHITESPACE , LWS_TOKZS_QUOTED_STRING , LWS_TOKZS_TOKEN , LWS_TOKZS_TOKEN_POST_TERMINAL } |
enum | { LSTRX_DONE , LSTRX_FILLED_OUT , LSTRX_FATAL_NAME_TOO_LONG = -1 , LSTRX_FATAL_NAME_UNKNOWN = -2 } |
Functions | |
LWS_VISIBLE LWS_EXTERN void | lws_tokenize_init (struct lws_tokenize *ts, const char *start, int flags) |
LWS_VISIBLE LWS_EXTERN lws_tokenize_elem | lws_tokenize (struct lws_tokenize *ts) |
LWS_VISIBLE LWS_EXTERN int | lws_tokenize_cstr (struct lws_tokenize *ts, char *str, size_t max) |
LWS_VISIBLE LWS_EXTERN void | lws_strexp_init (lws_strexp_t *exp, void *priv, lws_strexp_expand_cb cb, char *out, size_t olen) |
LWS_VISIBLE LWS_EXTERN void | lws_strexp_reset_out (lws_strexp_t *exp, char *out, size_t olen) |
LWS_VISIBLE LWS_EXTERN int | lws_strexp_expand (lws_strexp_t *exp, const char *in, size_t len, size_t *pused_in, size_t *pused_out) |
LWS_VISIBLE LWS_EXTERN int | lws_strcmp_wildcard (const char *wildcard, size_t wlen, const char *check, size_t clen) |
struct lws_tokenize |
Definition at line 101 of file lws-tokenize.h.
Data Fields | ||
---|---|---|
char | collect[256] | |
const char * | start |
set to the start of the string to tokenize |
const char * | token |
the start of an identified token or delimiter |
size_t | len |
set to the length of the string to tokenize |
size_t | token_len |
the length of the identied token or delimiter |
lws_tokenize_state | state | |
int | line | |
int | effline | |
uint16_t | flags |
optional LWS_TOKENIZE_F_ flags, or 0 |
uint8_t | delim | |
int8_t | e |
convenient for storing lws_tokenize return |
uint8_t | reset_token:1 | |
uint8_t | crlf:1 | |
uint8_t | dry:1 |
struct lws_strexp |
Definition at line 194 of file lws-tokenize.h.
Data Fields | ||
---|---|---|
char | name[32] | |
lws_strexp_expand_cb | cb | |
void * | priv | |
char * | out | |
size_t | olen | |
size_t | pos | |
size_t | exp_ofs | |
uint8_t | name_pos | |
char | state |
#define LWS_TOKENIZE_F_MINUS_NONTERM (1 << 0) |
Definition at line 26 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_AGG_COLON (1 << 1) |
Definition at line 28 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_COMMA_SEP_LIST (1 << 2) |
Definition at line 30 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_RFC7230_DELIMS (1 << 3) |
Definition at line 33 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_DOT_NONTERM (1 << 4) |
Definition at line 35 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_NO_FLOATS (1 << 5) |
Definition at line 39 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_NO_INTEGERS (1 << 6) |
Definition at line 41 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_HASH_COMMENT (1 << 7) |
Definition at line 43 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_SLASH_NONTERM (1 << 8) |
Definition at line 45 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_ASTERISK_NONTERM (1 << 9) |
Definition at line 47 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_EQUALS_NONTERM (1 << 10) |
Definition at line 49 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_COLON_NONTERM (1 << 11) |
Definition at line 51 of file lws-tokenize.h.
#define LWS_TOKENIZE_F_EXPECT_MORE (1 << 12) |
Definition at line 54 of file lws-tokenize.h.
typedef struct lws_tokenize lws_tokenize_t |
typedef int(* lws_strexp_expand_cb) (void *priv, const char *name, char *out, size_t *pos, size_t olen, size_t *exp_ofs) |
Definition at line 191 of file lws-tokenize.h.
typedef struct lws_strexp lws_strexp_t |
enum lws_tokenize_elem |
Definition at line 56 of file lws-tokenize.h.
Enumerator | |
---|---|
LWSTZ_DT_NEED_FIRST_CONTENT | |
LWSTZ_DT_NEED_DELIM | |
LWSTZ_DT_NEED_NEXT_CONTENT |
Definition at line 88 of file lws-tokenize.h.
enum lws_tokenize_state |
Enumerator | |
---|---|
LWS_TOKZS_LEADING_WHITESPACE | |
LWS_TOKZS_QUOTED_STRING | |
LWS_TOKZS_TOKEN | |
LWS_TOKZS_TOKEN_POST_TERMINAL |
Definition at line 94 of file lws-tokenize.h.
anonymous enum |
Enumerator | |
---|---|
LSTRX_DONE | |
LSTRX_FILLED_OUT | |
LSTRX_FATAL_NAME_TOO_LONG | |
LSTRX_FATAL_NAME_UNKNOWN |
Definition at line 208 of file lws-tokenize.h.
LWS_VISIBLE LWS_EXTERN void lws_tokenize_init | ( | struct lws_tokenize * | ts, |
const char * | start, | ||
int | flags | ||
) |
lws_tokenize() - breaks down a string into tokens and delimiters in-place
ts | the lws_tokenize struct to init |
start | the string to tokenize |
flags | LWS_TOKENIZE_F_ option flags |
This initializes the tokenize struct to point to the given string, and sets the length to 2GiB - 1 (so there must be a terminating NUL)... you can override this requirement by setting ts.len yourself before using it.
.delim is also initialized to LWSTZ_DT_NEED_FIRST_CONTENT.
LWS_VISIBLE LWS_EXTERN lws_tokenize_elem lws_tokenize | ( | struct lws_tokenize * | ts | ) |
lws_tokenize() - breaks down a string into tokens and delimiters in-place
ts | the lws_tokenize struct with information and state on what to do |
The ts
struct should have its start, len and flags members initialized to reflect the string to be tokenized and any options.
Then lws_tokenize()
may be called repeatedly on the struct, returning one of lws_tokenize_elem
each time, and with the struct's token
and token_len
members set to describe the content of the delimiter or token payload each time.
There are no allocations during the process.
returns lws_tokenize_elem that was identified (LWS_TOKZE_ENDED means reached the end of the string).
LWS_VISIBLE LWS_EXTERN int lws_tokenize_cstr | ( | struct lws_tokenize * | ts, |
char * | str, | ||
size_t | max | ||
) |
lws_tokenize_cstr() - copy token string to NUL-terminated buffer
ts | pointer to lws_tokenize struct to operate on |
str | destination buffer \pparam max: bytes in destination buffer |
returns 0 if OK or nonzero if the string + NUL won't fit.
LWS_VISIBLE LWS_EXTERN void lws_strexp_init | ( | lws_strexp_t * | exp, |
void * | priv, | ||
lws_strexp_expand_cb | cb, | ||
char * | out, | ||
size_t | olen | ||
) |
lws_strexp_init() - initialize an lws_strexp_t for use
exp:
the exp object to init priv:
the user's object pointer to pass to callback cb:
the callback to expand named objects out:
the start of the output buffer, or NULL just to get the length olen:
the length of the output buffer in bytes
Prepares an lws_strexp_t for use and sets the initial output buffer
If out
is NULL, substitution proceeds normally, but no output is produced, only the length is returned. olen should be set to the largest feasible overall length. To use this mode, the substitution callback must also check for NULL out
and avoid producing the output.
LWS_VISIBLE LWS_EXTERN void lws_strexp_reset_out | ( | lws_strexp_t * | exp, |
char * | out, | ||
size_t | olen | ||
) |
lws_strexp_reset_out() - reset the output buffer on an existing strexp
exp:
the exp object to init out:
the start of the output buffer, or NULL to just get length olen:
the length of the output buffer in bytes
Provides a new output buffer for lws_strexp_expand() to continue to write into. It can be the same as the old one if it has been copied out or used. The position of the next write will be reset to the start of the given buf.
If out
is NULL, substitution proceeds normally, but no output is produced, only the length is returned. olen
should be set to the largest feasible overall length. To use this mode, the substitution callback must also check for NULL out
and avoid producing the output.
LWS_VISIBLE LWS_EXTERN int lws_strexp_expand | ( | lws_strexp_t * | exp, |
const char * | in, | ||
size_t | len, | ||
size_t * | pused_in, | ||
size_t * | pused_out | ||
) |
lws_strexp_expand() - copy / expand a string into the output buffer
exp:
the exp object for the copy / expansion in:
the start of the next input data len:
the length of the input data pused_in:
pointer to write the amount of input used pused_out:
pointer to write the amount of output used
Copies in to the output buffer set in exp, expanding any ${name} tokens using the callback. *pused_in
is set to the number of input chars used and *pused_out
the number of output characters used
May return LSTRX_FILLED_OUT early with *pused < len if the output buffer is filled. Handle the output buffer and reset it with lws_strexp_reset_out() before calling again with adjusted in / len to continue.
In the case of large expansions, the expansion itself may fill the output buffer, in which case the expansion callback returns the LSTRX_FILLED_OUT and will be called again to continue with its *exp_ofs parameter set appropriately.
LWS_VISIBLE LWS_EXTERN int lws_strcmp_wildcard | ( | const char * | wildcard, |
size_t | wlen, | ||
const char * | check, | ||
size_t | clen | ||
) |
lws_strcmp_wildcard() - strcmp but the first arg can have wildcards
wildcard:
a string that may contain zero to three *, and may lack a NUL wlen:
length of the wildcard string check:
string to test to see if it matches wildcard clen:
length of check string
Like strcmp, but supports patterns like "a*", "a*b", "a*b*" etc where a and b are arbitrary substrings. Both the wc and check strings need not be NUL terminated, but are specified by lengths.