libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-purify.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LWS_JSON_PURIFY_FLAG_HTML_SAFE   1

Functions

LWS_VISIBLE LWS_EXTERN const char * lws_sql_purify (char *escaped, const char *string, size_t len)
int lws_sql_purify_len (const char *p)
LWS_VISIBLE LWS_EXTERN const char * lws_json_purify (char *escaped, const char *string, int len, int *in_used)
LWS_VISIBLE LWS_EXTERN const char * lws_json_purify_flags (char *escaped, const char *string, int len, int *in_used, int flags)
LWS_VISIBLE LWS_EXTERN int lws_json_purify_len (const char *string)
LWS_VISIBLE LWS_EXTERN void lws_filename_purify_inplace (char *filename)
LWS_VISIBLE LWS_EXTERN int lws_plat_write_cert (struct lws_vhost *vhost, int is_key, int fd, void *buf, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_plat_write_file (const char *filename, void *buf, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_plat_read_file (const char *filename, void *buf, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_plat_recommended_rsa_bits (void)

Macro Definition Documentation

◆ LWS_JSON_PURIFY_FLAG_HTML_SAFE

#define LWS_JSON_PURIFY_FLAG_HTML_SAFE   1

Definition at line 104 of file lws-purify.h.

Function Documentation

◆ lws_sql_purify()

LWS_VISIBLE LWS_EXTERN const char * lws_sql_purify ( char * escaped,
const char * string,
size_t len )

lws_sql_purify() - like strncpy but with escaping for sql quotes

Parameters
escapedoutput buffer
stringinput buffer ('/0' terminated)
lenoutput buffer max length

Because escaping expands the output string, it's not possible to do it in-place, ie, with escaped == string

◆ lws_sql_purify_len()

int lws_sql_purify_len ( const char * p)

lws_sql_purify_len() - return length of purified version of input string

Parameters
pinput buffer ('/0' terminated)

Calculates any character escaping without writing it anywhere and returns the calculated length of the purified string.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_json_purify()

LWS_VISIBLE LWS_EXTERN const char * lws_json_purify ( char * escaped,
const char * string,
int len,
int * in_used )

lws_json_purify() - like strncpy but with escaping for json chars

Parameters
escapedoutput buffer
stringinput buffer ('/0' terminated)
lenoutput buffer max length
in_usedNULL, or pointer to input cap on entry and the number of bytes of string we could escape in len on output

Because escaping expands the output string, it's not possible to do it in-place, ie, with escaped == string

If in_used is non-NULL, then on entry a positive value is taken as a cap on the number of bytes of string that may be processed; this allows processing non-NUL-terminated data like blobs in bounded chunks. A zero or negative value on entry means no cap. On return, it's set to the number of input bytes that were actually processed.

Escaped output is always truncated on an escape boundary, so the output is always syntactically valid however small len is.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_json_purify_flags()

LWS_VISIBLE LWS_EXTERN const char * lws_json_purify_flags ( char * escaped,
const char * string,
int len,
int * in_used,
int flags )

lws_json_purify_flags() - lws_json_purify() with additional options

Parameters
escapedoutput buffer
stringinput buffer ('/0' terminated)
lenoutput buffer max length
in_usedNULL, or pointer to input cap on entry and the number of bytes of string we could escape in len on output
flagsOR of LWS_JSON_PURIFY_FLAG_*

Performs the same job as lws_json_purify() with extra behaviours selected using flags.

◆ lws_json_purify_len()

LWS_VISIBLE LWS_EXTERN int lws_json_purify_len ( const char * string)

lws_json_purify_len() - find out the escaped length of a string

Parameters
stringinput buffer ('/0' terminated)

JSON may have to expand escapes by up to 6x the original depending on what it is. This doesn't actually do the escaping but goes through the motions and computes the length of the escaped string.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_filename_purify_inplace()

LWS_VISIBLE LWS_EXTERN void lws_filename_purify_inplace ( char * filename)

lws_filename_purify_inplace() - replace scary filename chars with underscore

Parameters
filenamefilename to be purified

Replace scary characters in the filename (it should not be a path) with underscore, so it's safe to use.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_plat_write_cert()

LWS_VISIBLE LWS_EXTERN int lws_plat_write_cert ( struct lws_vhost * vhost,
int is_key,
int fd,
void * buf,
size_t len )

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_plat_write_file()

LWS_VISIBLE LWS_EXTERN int lws_plat_write_file ( const char * filename,
void * buf,
size_t len )

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_plat_read_file()

LWS_VISIBLE LWS_EXTERN int lws_plat_read_file ( const char * filename,
void * buf,
size_t len )

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_plat_recommended_rsa_bits()

LWS_VISIBLE LWS_EXTERN int lws_plat_recommended_rsa_bits ( void )