Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1614904794, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"f26c7decbfe2aef4020df28a6ec5c1a2", "oid":{ "oid": "f64b0d1c52cad0120d1c5aea6ebf1216b5cbcc41", "alias": [ "refs/heads/master"]},"blobname": "include/libwebsockets/lws-misc.h", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n#if defined(LWS_WITH_SPAWN)\n\n#if defined(WIN32) || defined(_WIN32)\n#else\n#include \u003csys/wait.h\u003e\n#include \u003csys/times.h\u003e\n#endif\n#endif\n\n#if defined(__OpenBSD__)\n#include \u003csys/siginfo.h\u003e\n#endif\n\n/** \u005cdefgroup misc Miscellaneous APIs\n* ##Miscellaneous APIs\n*\n* Various APIs outside of other categories\n*/\n///@{\n\nstruct lws_buflist;\n\n/**\n * lws_buflist_append_segment(): add buffer to buflist at head\n *\n * \u005cparam head: list head\n * \u005cparam buf: buffer to stash\n * \u005cparam len: length of buffer to stash\n *\n * Returns -1 on OOM, 1 if this was the first segment on the list, and 0 if\n * it was a subsequent segment.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_buflist_append_segment(struct lws_buflist **head, const uint8_t *buf,\n\t\t\t size_t len);\n/**\n * lws_buflist_next_segment_len(): number of bytes left in current segment\n *\n * \u005cparam head: list head\n * \u005cparam buf: if non-NULL, *buf is written with the address of the start of\n *\t\tthe remaining data in the segment\n *\n * Returns the number of bytes left in the current segment. 0 indicates\n * that the buflist is empty (there are no segments on the buflist).\n */\nLWS_VISIBLE LWS_EXTERN size_t\nlws_buflist_next_segment_len(struct lws_buflist **head, uint8_t **buf);\n\n/**\n * lws_buflist_use_segment(): remove len bytes from the current segment\n *\n * \u005cparam head: list head\n * \u005cparam len: number of bytes to mark as used\n *\n * If len is less than the remaining length of the current segment, the position\n * in the current segment is simply advanced and it returns.\n *\n * If len uses up the remaining length of the current segment, then the segment\n * is deleted and the list head moves to the next segment if any.\n *\n * Returns the number of bytes left in the current segment. 0 indicates\n * that the buflist is empty (there are no segments on the buflist).\n */\nLWS_VISIBLE LWS_EXTERN size_t\nlws_buflist_use_segment(struct lws_buflist **head, size_t len);\n\n/**\n * lws_buflist_total_len(): Get the total size of the buflist\n *\n * \u005cparam head: list head\n *\n * Returns the total number of bytes held on all segments of the buflist\n */\nLWS_VISIBLE LWS_EXTERN size_t\nlws_buflist_total_len(struct lws_buflist **head);\n\n/**\n * lws_buflist_linear_copy(): copy everything out as one without consuming\n *\n * \u005cparam head: list head\n * \u005cparam ofs: start offset into buflist in bytes\n * \u005cparam buf: buffer to copy linearly into\n * \u005cparam len: length of buffer available\n *\n * Returns -1 if len is too small, or bytes copied. Happy to do partial\n * copies, returns 0 when there are no more bytes to copy.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_buflist_linear_copy(struct lws_buflist **head, size_t ofs, uint8_t *buf,\n\t\t\tsize_t len);\n\n/**\n * lws_buflist_linear_use(): copy and consume from buflist head\n *\n * \u005cparam head: list head\n * \u005cparam buf: buffer to copy linearly into\n * \u005cparam len: length of buffer available\n *\n * Copies a possibly fragmented buflist from the head into the linear output\n * buffer \u005cp buf for up to length \u005cp len, and consumes the buflist content that\n * was copied out.\n *\n * Since it was consumed, calling again will resume copying out and consuming\n * from as far as it got the first time.\n *\n * Returns the number of bytes written into \u005cp buf.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_buflist_linear_use(struct lws_buflist **head, uint8_t *buf, size_t len);\n\n/**\n * lws_buflist_fragment_use(): copy and consume \u003c\u003d 1 frag from buflist head\n *\n * \u005cparam head: list head\n * \u005cparam buf: buffer to copy linearly into\n * \u005cparam len: length of buffer available\n * \u005cparam frag_first: pointer to char written on exit to if this is start of frag\n * \u005cparam frag_fin: pointer to char written on exit to if this is end of frag\n *\n * Copies all or part of the fragment at the start of a buflist from the head\n * into the output buffer \u005cp buf for up to length \u005cp len, and consumes the\n * buflist content that was copied out.\n *\n * Since it was consumed, calling again will resume copying out and consuming\n * from as far as it got the first time.\n *\n * Returns the number of bytes written into \u005cp buf.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_buflist_fragment_use(struct lws_buflist **head, uint8_t *buf,\n\t\t\t size_t len, char *frag_first, char *frag_fin);\n\n/**\n * lws_buflist_destroy_all_segments(): free all segments on the list\n *\n * \u005cparam head: list head\n *\n * This frees everything on the list unconditionally. *head is always\n * NULL after this.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_buflist_destroy_all_segments(struct lws_buflist **head);\n\n/**\n * lws_buflist_describe(): debug helper logging buflist status\n *\n * \u005cparam head: list head\n * \u005cparam id: pointer shown in debug list\n * \u005cparam reason: reason string show in debug list\n *\n * Iterates through the buflist segments showing position and size.\n * This only exists when lws was built in debug mode\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_buflist_describe(struct lws_buflist **head, void *id, const char *reason);\n\n/**\n * lws_ptr_diff(): helper to report distance between pointers as an int\n *\n * \u005cparam head: the pointer with the larger address\n * \u005cparam tail: the pointer with the smaller address\n *\n * This helper gives you an int representing the number of bytes further\n * forward the first pointer is compared to the second pointer.\n */\n#define lws_ptr_diff(head, tail) \u005c\n\t\t\t((int)((char *)(head) - (char *)(tail)))\n\n#define lws_ptr_diff_size_t(head, tail) \u005c\n\t\t\t((size_t)(ssize_t)((char *)(head) - (char *)(tail)))\n\n/**\n * lws_snprintf(): snprintf that truncates the returned length too\n *\n * \u005cparam str: destination buffer\n * \u005cparam size: bytes left in destination buffer\n * \u005cparam format: format string\n * \u005cparam ...: args for format\n *\n * This lets you correctly truncate buffers by concatenating lengths, if you\n * reach the limit the reported length doesn't exceed the limit.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_snprintf(char *str, size_t size, const char *format, ...) LWS_FORMAT(3);\n\n/**\n * lws_strncpy(): strncpy that guarantees NUL on truncated copy\n *\n * \u005cparam dest: destination buffer\n * \u005cparam src: source buffer\n * \u005cparam size: bytes left in destination buffer\n *\n * This lets you correctly truncate buffers by concatenating lengths, if you\n * reach the limit the reported length doesn't exceed the limit.\n */\nLWS_VISIBLE LWS_EXTERN char *\nlws_strncpy(char *dest, const char *src, size_t size);\n\n/*\n * Variation where we want to use the smaller of two lengths, useful when the\n * source string is not NUL terminated\n */\n#define lws_strnncpy(dest, src, size1, destsize) \u005c\n\tlws_strncpy(dest, src, (size_t)(size1 + 1) \u003c (size_t)(destsize) ? \u005c\n\t\t\t\t(size_t)(size1 + 1) : (size_t)(destsize))\n\n/**\n * lws_nstrstr(): like strstr for length-based strings without terminating NUL\n *\n * \u005cparam buf: the string to search\n * \u005cparam len: the length of the string to search\n * \u005cparam name: the substring to search for\n * \u005cparam nl: the length of name\n *\n * Returns NULL if \u005cp name is not present in \u005cp buf. Otherwise returns the\n * address of the first instance of \u005cp name in \u005cp buf.\n *\n * Neither buf nor name need to be NUL-terminated.\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_nstrstr(const char *buf, size_t len, const char *name, size_t nl);\n\n/**\n * lws_json_simple_find(): dumb JSON string parser\n *\n * \u005cparam buf: the JSON to search\n * \u005cparam len: the length of the JSON to search\n * \u005cparam name: the name field to search the JSON for, eg, \u0022\u005c\u0022myname\u005c\u0022:\u0022\n * \u005cparam alen: set to the length of the argument part if non-NULL return\n *\n * Either returns NULL if \u005cp name is not present in buf, or returns a pointer\n * to the argument body of the first instance of \u005cp name, and sets *alen to the\n * length of the argument body.\n *\n * This can cheaply handle fishing out, eg, myarg from {\u0022myname\u0022: \u0022myarg\u0022} by\n * searching for \u0022\u005c\u0022myname\u005c\u0022:\u0022. It will return a pointer to myarg and set *alen\n * to 5. It equally handles args like \u0022myname\u0022: true, or \u0022myname\u0022:false, and\n * null or numbers are all returned as delimited strings.\n *\n * Anything more complicated like the value is a subobject or array, you should\n * parse it using a full parser like lejp. This is suitable is the JSON is\n * and will remain short and simple, and contains well-known names amongst other\n * extensible JSON members.\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen);\n\n/**\n * lws_json_simple_strcmp(): dumb JSON string comparison\n *\n * \u005cparam buf: the JSON to search\n * \u005cparam len: the length of the JSON to search\n * \u005cparam name: the name field to search the JSON for, eg, \u0022\u005c\u0022myname\u005c\u0022:\u0022\n * \u005cparam comp: return a strcmp of this and the discovered argument\n *\n * Helper that combines lws_json_simple_find() with strcmp() if it was found.\n * If the \u005cp name was not found, returns -1. Otherwise returns a strcmp()\n * between what was found and \u005cp comp, ie, return 0 if they match or something\n * else if they don't.\n *\n * If the JSON is relatively simple and you want to target constrained\n * devices, this can be a good choice. If the JSON may be complex, you\n * should use a full JSON parser.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_json_simple_strcmp(const char *buf, size_t len, const char *name, const char *comp);\n\n\n/**\n * lws_hex_to_byte_array(): convert hex string like 0123456789ab into byte data\n *\n * \u005cparam h: incoming NUL-terminated hex string\n * \u005cparam dest: array to fill with binary decodes of hex pairs from h\n * \u005cparam max: maximum number of bytes dest can hold, must be at least half\n *\t\tthe size of strlen(h)\n *\n * This converts hex strings into an array of 8-bit representations, ie the\n * input \u0022abcd\u0022 produces two bytes of value 0xab and 0xcd.\n *\n * Returns number of bytes produced into \u005cp dest, or -1 on error.\n *\n * Errors include non-hex chars and an odd count of hex chars in the input\n * string.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hex_to_byte_array(const char *h, uint8_t *dest, int max);\n\n\n/**\n * lws_hex_random(): generate len - 1 or - 2 characters of random ascii hex\n *\n * \u005cparam context: the lws_context used to get the random\n * \u005cparam dest: destination for hex ascii chars\n * \u005cparam len: the number of bytes the buffer dest points to can hold\n *\n * This creates random ascii-hex strings up to a given length, with a\n * terminating NUL.\n *\n * There will not be any characters produced that are not 0-9, a-f, so it's\n * safe to go straight into, eg, JSON.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hex_random(struct lws_context *context, char *dest, size_t len);\n\n/*\n * lws_timingsafe_bcmp(): constant time memcmp\n *\n * \u005cparam a: first buffer\n * \u005cparam b: second buffer\n * \u005cparam len: count of bytes to compare\n *\n * Return 0 if the two buffers are the same, else nonzero.\n *\n * Always compares all of the buffer before returning, so it can't be used as\n * a timing oracle.\n */\n\nLWS_VISIBLE LWS_EXTERN int\nlws_timingsafe_bcmp(const void *a, const void *b, uint32_t len);\n\n/**\n * lws_get_random(): fill a buffer with platform random data\n *\n * \u005cparam context: the lws context\n * \u005cparam buf: buffer to fill\n * \u005cparam len: how much to fill\n *\n * Fills buf with len bytes of random. Returns the number of bytes set, if\n * not equal to len, then getting the random failed.\n */\nLWS_VISIBLE LWS_EXTERN size_t\nlws_get_random(struct lws_context *context, void *buf, size_t len);\n/**\n * lws_daemonize(): make current process run in the background\n *\n * \u005cparam _lock_path: the filepath to write the lock file\n *\n * Spawn lws as a background process, taking care of various things\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_daemonize(const char *_lock_path);\n/**\n * lws_get_library_version(): return string describing the version of lws\n *\n * On unix, also includes the git describe\n */\nLWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT\nlws_get_library_version(void);\n\n/**\n * lws_wsi_user() - get the user data associated with the connection\n * \u005cparam wsi: lws connection\n *\n * Not normally needed since it's passed into the callback\n */\nLWS_VISIBLE LWS_EXTERN void *\nlws_wsi_user(struct lws *wsi);\n\n/**\n * lws_wsi_tsi() - get the service thread index the wsi is bound to\n * \u005cparam wsi: lws connection\n *\n * Only useful is LWS_MAX_SMP \u003e 1\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_wsi_tsi(struct lws *wsi);\n\n/**\n * lws_set_wsi_user() - set the user data associated with the client connection\n * \u005cparam wsi: lws connection\n * \u005cparam user: user data\n *\n * By default lws allocates this and it's not legal to externally set it\n * yourself. However client connections may have it set externally when the\n * connection is created... if so, this api can be used to modify it at\n * runtime additionally.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_set_wsi_user(struct lws *wsi, void *user);\n\n/**\n * lws_parse_uri:\tcut up prot:/ads:port/path into pieces\n *\t\t\tNotice it does so by dropping '\u005c0' into input string\n *\t\t\tand the leading / on the path is consequently lost\n *\n * \u005cparam p:\t\t\tincoming uri string.. will get written to\n * \u005cparam prot:\t\tresult pointer for protocol part (https://)\n * \u005cparam ads:\t\tresult pointer for address part\n * \u005cparam port:\t\tresult pointer for port part\n * \u005cparam path:\t\tresult pointer for path part\n *\n * You may also refer to unix socket addresses, using a '+' at the start of\n * the address. In this case, the address should end with ':', which is\n * treated as the separator between the address and path (the normal separator\n * '/' is a valid part of the socket path). Eg,\n *\n * http://+/var/run/mysocket:/my/path\n *\n * If the first character after the + is '@', it's interpreted by lws client\n * processing as meaning to use linux abstract namespace sockets, the @ is\n * replaced with a '\u005c0' before use.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_parse_uri(char *p, const char **prot, const char **ads, int *port,\n\t const char **path);\n/**\n * lws_cmdline_option():\tsimple commandline parser\n *\n * \u005cparam argc:\t\tcount of argument strings\n * \u005cparam argv:\t\targument strings\n * \u005cparam val:\t\tstring to find\n *\n * Returns NULL if the string \u005cp val is not found in the arguments.\n *\n * If it is found, then it returns a pointer to the next character after \u005cp val.\n * So if \u005cp val is \u0022-d\u0022, then for the commandlines \u0022myapp -d15\u0022 and\n * \u0022myapp -d 15\u0022, in both cases the return will point to the \u002215\u0022.\n *\n * In the case there is no argument, like \u0022myapp -d\u0022, the return will\n * either point to the '\u005c\u005c0' at the end of -d, or to the start of the\n * next argument, ie, will be non-NULL.\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_cmdline_option(int argc, const char **argv, const char *val);\n\n/**\n * lws_cmdline_option_handle_builtin(): apply standard cmdline options\n *\n * \u005cparam argc:\t\tcount of argument strings\n * \u005cparam argv:\t\targument strings\n * \u005cparam info:\t\tcontext creation info\n *\n * Applies standard options to the context creation info to save them having\n * to be (unevenly) copied into the minimal examples.\n *\n * Applies default log levels that can be overriden by -d\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_cmdline_option_handle_builtin(int argc, const char **argv,\n\t\t\t\t struct lws_context_creation_info *info);\n\n/**\n * lws_now_secs(): return seconds since 1970-1-1\n */\nLWS_VISIBLE LWS_EXTERN unsigned long\nlws_now_secs(void);\n\n/**\n * lws_now_usecs(): return useconds since 1970-1-1\n */\nLWS_VISIBLE LWS_EXTERN lws_usec_t\nlws_now_usecs(void);\n\n/**\n * lws_get_context - Allow getting lws_context from a Websocket connection\n * instance\n *\n * With this function, users can access context in the callback function.\n * Otherwise users may have to declare context as a global variable.\n *\n * \u005cparam wsi:\tWebsocket connection instance\n */\nLWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT\nlws_get_context(const struct lws *wsi);\n\n/**\n * lws_get_vhost_listen_port - Find out the port number a vhost is listening on\n *\n * In the case you passed 0 for the port number at context creation time, you\n * can discover the port number that was actually chosen for the vhost using\n * this api.\n *\n * \u005cparam vhost:\tVhost to get listen port from\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_get_vhost_listen_port(struct lws_vhost *vhost);\n\n/**\n * lws_get_count_threads(): how many service threads the context uses\n *\n * \u005cparam context: the lws context\n *\n * By default this is always 1, if you asked for more than lws can handle it\n * will clip the number of threads. So you can use this to find out how many\n * threads are actually in use.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_get_count_threads(struct lws_context *context);\n\n/**\n * lws_get_parent() - get parent wsi or NULL\n * \u005cparam wsi: lws connection\n *\n * Specialized wsi like cgi stdin/out/err are associated to a parent wsi,\n * this allows you to get their parent.\n */\nLWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT\nlws_get_parent(const struct lws *wsi);\n\n/**\n * lws_get_child() - get child wsi or NULL\n * \u005cparam wsi: lws connection\n *\n * Allows you to find a related wsi from the parent wsi.\n */\nLWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT\nlws_get_child(const struct lws *wsi);\n\n/**\n * lws_get_effective_uid_gid() - find out eventual uid and gid while still root\n *\n * \u005cparam context: lws context\n * \u005cparam uid: pointer to uid result\n * \u005cparam gid: pointer to gid result\n *\n * This helper allows you to find out what the uid and gid for the process will\n * be set to after the privileges are dropped, beforehand. So while still root,\n * eg in LWS_CALLBACK_PROTOCOL_INIT, you can arrange things like cache dir\n * and subdir creation / permissions down /var/cache dynamically.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_get_effective_uid_gid(struct lws_context *context, uid_t *uid, gid_t *gid);\n\n/**\n * lws_get_udp() - get wsi's udp struct\n *\n * \u005cparam wsi: lws connection\n *\n * Returns NULL or pointer to the wsi's UDP-specific information\n */\nLWS_VISIBLE LWS_EXTERN const struct lws_udp * LWS_WARN_UNUSED_RESULT\nlws_get_udp(const struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN void *\nlws_get_opaque_parent_data(const struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_set_opaque_parent_data(struct lws *wsi, void *data);\n\nLWS_VISIBLE LWS_EXTERN void *\nlws_get_opaque_user_data(const struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_set_opaque_user_data(struct lws *wsi, void *data);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_get_child_pending_on_writable(const struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_clear_child_pending_on_writable(struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_get_close_length(struct lws *wsi);\n\nLWS_VISIBLE LWS_EXTERN unsigned char *\nlws_get_close_payload(struct lws *wsi);\n\n/**\n * lws_get_network_wsi() - Returns wsi that has the tcp connection for this wsi\n *\n * \u005cparam wsi: wsi you have\n *\n * Returns wsi that has the tcp connection (which may be the incoming wsi)\n *\n * HTTP/1 connections will always return the incoming wsi\n * HTTP/2 connections may return a different wsi that has the tcp connection\n */\nLWS_VISIBLE LWS_EXTERN\nstruct lws *lws_get_network_wsi(struct lws *wsi);\n\n/**\n * lws_set_allocator() - custom allocator support\n *\n * \u005cparam realloc\n *\n * Allows you to replace the allocator (and deallocator) used by lws\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_set_allocator(void *(*realloc)(void *ptr, size_t size, const char *reason));\n\nenum {\n\t/*\n\t * Flags for enable and disable rxflow with reason bitmap and with\n\t * backwards-compatible single bool\n\t */\n\tLWS_RXFLOW_REASON_USER_BOOL\t\t\u003d (1 \u003c\u003c 0),\n\tLWS_RXFLOW_REASON_HTTP_RXBUFFER\t\t\u003d (1 \u003c\u003c 6),\n\tLWS_RXFLOW_REASON_H2_PPS_PENDING\t\u003d (1 \u003c\u003c 7),\n\n\tLWS_RXFLOW_REASON_APPLIES\t\t\u003d (1 \u003c\u003c 14),\n\tLWS_RXFLOW_REASON_APPLIES_ENABLE_BIT\t\u003d (1 \u003c\u003c 13),\n\tLWS_RXFLOW_REASON_APPLIES_ENABLE\t\u003d LWS_RXFLOW_REASON_APPLIES |\n\t\t\t\t\t\t LWS_RXFLOW_REASON_APPLIES_ENABLE_BIT,\n\tLWS_RXFLOW_REASON_APPLIES_DISABLE\t\u003d LWS_RXFLOW_REASON_APPLIES,\n\tLWS_RXFLOW_REASON_FLAG_PROCESS_NOW\t\u003d (1 \u003c\u003c 12),\n\n};\n\n/**\n * lws_rx_flow_control() - Enable and disable socket servicing for\n *\t\t\t\treceived packets.\n *\n * If the output side of a server process becomes choked, this allows flow\n * control for the input side.\n *\n * \u005cparam wsi:\tWebsocket connection instance to get callback for\n * \u005cparam enable:\t0 \u003d disable read servicing for this connection, 1 \u003d enable\n *\n * If you need more than one additive reason for rxflow control, you can give\n * iLWS_RXFLOW_REASON_APPLIES_ENABLE or _DISABLE together with one or more of\n * b5..b0 set to idicate which bits to enable or disable. If any bits are\n * enabled, rx on the connection is suppressed.\n *\n * LWS_RXFLOW_REASON_FLAG_PROCESS_NOW flag may also be given to force any change\n * in rxflowbstatus to benapplied immediately, this should be used when you are\n * changing a wsi flow control state from outside a callback on that wsi.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_rx_flow_control(struct lws *wsi, int enable);\n\n/**\n * lws_rx_flow_allow_all_protocol() - Allow all connections with this protocol to receive\n *\n * When the user server code realizes it can accept more input, it can\n * call this to have the RX flow restriction removed from all connections using\n * the given protocol.\n * \u005cparam context:\tlws_context\n * \u005cparam protocol:\tall connections using this protocol will be allowed to receive\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_rx_flow_allow_all_protocol(const struct lws_context *context,\n\t\t\t const struct lws_protocols *protocol);\n\n/**\n * lws_remaining_packet_payload() - Bytes to come before \u0022overall\u0022\n *\t\t\t\t\t rx fragment is complete\n * \u005cparam wsi:\t\tWebsocket instance (available from user callback)\n *\n * This tracks how many bytes are left in the current ws fragment, according\n * to the ws length given in the fragment header.\n *\n * If the message was in a single fragment, and there is no compression, this\n * is the same as \u0022how much data is left to read for this message\u0022.\n *\n * However, if the message is being sent in multiple fragments, this will\n * reflect the unread amount of the current **fragment**, not the message. With\n * ws, it is legal to not know the length of the message before it completes.\n *\n * Additionally if the message is sent via the negotiated permessage-deflate\n * extension, this number only tells the amount of **compressed** data left to\n * be read, since that is the only information available at the ws layer.\n */\nLWS_VISIBLE LWS_EXTERN size_t\nlws_remaining_packet_payload(struct lws *wsi);\n\n#if defined(LWS_WITH_DIR)\n\ntypedef enum {\n\tLDOT_UNKNOWN,\n\tLDOT_FILE,\n\tLDOT_DIR,\n\tLDOT_LINK,\n\tLDOT_FIFO,\n\tLDOTT_SOCKET,\n\tLDOT_CHAR,\n\tLDOT_BLOCK\n} lws_dir_obj_type_t;\n\nstruct lws_dir_entry {\n\tconst char *name;\n\tlws_dir_obj_type_t type;\n};\n\ntypedef int\nlws_dir_callback_function(const char *dirpath, void *user,\n\t\t\t struct lws_dir_entry *lde);\n\n/**\n * lws_dir() - get a callback for everything in a directory\n *\n * \u005cparam dirpath: the directory to scan\n * \u005cparam user: pointer to give to callback\n * \u005cparam cb: callback to receive information on each file or dir\n *\n * Calls \u005cp cb (with \u005cp user) for every object in dirpath.\n *\n * This wraps whether it's using POSIX apis, or libuv (as needed for windows,\n * since it refuses to support POSIX apis for this).\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_dir(const char *dirpath, void *user, lws_dir_callback_function cb);\n\n/**\n * lws_dir_rm_rf_cb() - callback for lws_dir that performs recursive rm -rf\n *\n * \u005cparam dirpath: directory we are at in lws_dir\n * \u005cparam user: ignored\n * \u005cparam lde: lws_dir info on the file or directory we are at\n *\n * This is a readymade rm -rf callback for use with lws_dir. It recursively\n * removes everything below the starting dir and then the starting dir itself.\n * Works on linux, OSX and Windows at least.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_dir_rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde);\n\n/*\n * We pass every file in the base dir through a filter, and call back on the\n * ones that match. Directories are ignored.\n *\n * The original path filter string may look like, eg, \u0022sai-*.deb\u0022 or \u0022*.txt\u0022\n */\n\ntypedef int (*lws_dir_glob_cb_t)(void *data, const char *path);\n\ntypedef struct lws_dir_glob {\n\tconst char\t\t*filter;\n\tlws_dir_glob_cb_t\tcb;\n\tvoid\t\t\t*user;\n} lws_dir_glob_t;\n\n/**\n * lws_dir_glob_cb() - callback for lws_dir that performs filename globbing\n *\n * \u005cparam dirpath: directory we are at in lws_dir\n * \u005cparam user: pointer to your prepared lws_dir_glob_cb_t\n * \u005cparam lde: lws_dir info on the file or directory we are at\n *\n * \u005cp user is prepared with an `lws_dir_glob_t` containing a callback for paths\n * that pass the filtering, a user pointer to pass to that callback, and a\n * glob string like \u0022*.txt\u0022. It may not contain directories, the lws_dir musr\n * be started at the correct dir.\n *\n * Only the base path passed to lws_dir is scanned, it does not look in subdirs.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_dir_glob_cb(const char *dirpath, void *user, struct lws_dir_entry *lde);\n\n#endif\n\n/**\n * lws_get_allocated_heap() - if the platform supports it, returns amount of\n *\t\t\t\theap allocated by lws itself\n *\n * On glibc currently, this reports the total amount of current logical heap\n * allocation, found by tracking the amount allocated by lws_malloc() and\n * friends and accounting for freed allocations via lws_free().\n *\n * This is useful for confirming where processwide heap allocations actually\n * come from... this number represents all lws internal allocations, for\n * fd tables, wsi allocations, ah, etc combined. It doesn't include allocations\n * from user code, since lws_malloc() etc are not exported from the library.\n *\n * On other platforms, it always returns 0.\n */\nsize_t lws_get_allocated_heap(void);\n\n/**\n * lws_get_tsi() - Get thread service index wsi belong to\n * \u005cparam wsi: websocket connection to check\n *\n * Returns more than zero (or zero if only one service thread as is the default).\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_get_tsi(struct lws *wsi);\n\n/**\n * lws_is_ssl() - Find out if connection is using SSL\n * \u005cparam wsi:\twebsocket connection to check\n *\n * Returns nonzero if the wsi is inside a tls tunnel, else zero.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_is_ssl(struct lws *wsi);\n/**\n * lws_is_cgi() - find out if this wsi is running a cgi process\n *\n * \u005cparam wsi: lws connection\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_is_cgi(struct lws *wsi);\n\n/**\n * lws_open() - platform-specific wrapper for open that prepares the fd\n *\n * \u005cparam __file: the filepath to open\n * \u005cparam __oflag: option flags\n *\n * This is a wrapper around platform open() that sets options on the fd\n * according to lws policy. Currently that is FD_CLOEXEC to stop the opened\n * fd being available to any child process forked by user code.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_open(const char *__file, int __oflag, ...);\n\nstruct lws_wifi_scan { /* generic wlan scan item */\n\tstruct lws_wifi_scan *next;\n\tchar ssid[32];\n\tint32_t rssi; /* divide by .count to get db */\n\tuint8_t bssid[6];\n\tuint8_t count;\n\tuint8_t channel;\n\tuint8_t authmode;\n};\n\n#if defined(LWS_WITH_TLS) \u0026\u0026 !defined(LWS_WITH_MBEDTLS)\n/**\n * lws_get_ssl() - Return wsi's SSL context structure\n * \u005cparam wsi:\twebsocket connection\n *\n * Returns pointer to the SSL library's context structure\n */\nLWS_VISIBLE LWS_EXTERN SSL*\nlws_get_ssl(struct lws *wsi);\n#endif\n\nLWS_VISIBLE LWS_EXTERN void\nlws_explicit_bzero(void *p, size_t len);\n\ntypedef struct lws_humanize_unit {\n\tconst char *name; /* array ends with NULL name */\n\tuint64_t factor;\n} lws_humanize_unit_t;\n\nLWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_si[7];\nLWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_si_bytes[7];\nLWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_us[8];\n\n/**\n * lws_humanize() - Convert possibly large number to human-readable uints\n *\n * \u005cparam buf: result string buffer\n * \u005cparam len: remaining length in \u005cp buf\n * \u005cparam value: the uint64_t value to represent\n * \u005cparam schema: and array of scaling factors and units\n *\n * This produces a concise string representation of \u005cp value, referencing the\n * schema \u005cp schema of scaling factors and units to find the smallest way to\n * render it.\n *\n * Three schema are exported from lws for general use, humanize_schema_si, which\n * represents as, eg, \u0022 22.130Gi\u0022 or \u0022 128 \u0022; humanize_schema_si_bytes\n * which is the same but shows, eg, \u0022 22.130GiB\u0022, and humanize_schema_us,\n * which represents a count of us as a human-readable time like \u0022 14.350min\u0022,\n * or \u0022 1.500d\u0022.\n *\n * You can produce your own schema.\n */\n\nLWS_VISIBLE LWS_EXTERN int\nlws_humanize(char *buf, size_t len, uint64_t value,\n\t const lws_humanize_unit_t *schema);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_ser_wu16be(uint8_t *b, uint16_t u);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_ser_wu32be(uint8_t *b, uint32_t u32);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_ser_wu64be(uint8_t *b, uint64_t u64);\n\nLWS_VISIBLE LWS_EXTERN uint16_t\nlws_ser_ru16be(const uint8_t *b);\n\nLWS_VISIBLE LWS_EXTERN uint32_t\nlws_ser_ru32be(const uint8_t *b);\n\nLWS_VISIBLE LWS_EXTERN uint64_t\nlws_ser_ru64be(const uint8_t *b);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_vbi_encode(uint64_t value, void *buf);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_vbi_decode(const void *buf, uint64_t *value, size_t len);\n\n///@}\n\n#if defined(LWS_WITH_SPAWN)\n\n/* opaque internal struct */\nstruct lws_spawn_piped;\n\n#if defined(WIN32)\nstruct _lws_siginfo_t {\n\tint retcode;\n};\ntypedef struct _lws_siginfo_t siginfo_t;\n#endif\n\ntypedef void (*lsp_cb_t)(void *opaque, lws_usec_t *accounting, siginfo_t *si,\n\t\t\t int we_killed_him);\n\n\n/**\n * lws_spawn_piped_info - details given to create a spawned pipe\n *\n * \u005cp owner: lws_dll2_owner_t that lists all active spawns, or NULL\n * \u005cp vh: vhost to bind stdwsi to... from opt_parent if given\n * \u005cp opt_parent: optional parent wsi for stdwsi\n * \u005cp exec_array: argv for process to spawn\n * \u005cp env_array: environment for spawned process, NULL ends env list\n * \u005cp protocol_name: NULL, or vhost protocol name to bind stdwsi to\n * \u005cp chroot_path: NULL, or chroot patch for child process\n * \u005cp wd: working directory to cd to after fork, NULL defaults to /tmp\n * \u005cp plsp: NULL, or pointer to the outer lsp pointer so it can be set NULL when destroyed\n * \u005cp opaque: pointer passed to the reap callback, if any\n * \u005cp timeout: optional us-resolution timeout, or zero\n * \u005cp reap_cb: callback when child process has been reaped and the lsp destroyed\n * \u005cp tsi: tsi to bind stdwsi to... from opt_parent if given\n */\nstruct lws_spawn_piped_info {\n\tstruct lws_dll2_owner\t\t*owner;\n\tstruct lws_vhost\t\t*vh;\n\tstruct lws\t\t\t*opt_parent;\n\n\tconst char * const\t\t*exec_array;\n\tconst char\t\t\t**env_array;\n\tconst char\t\t\t*protocol_name;\n\tconst char\t\t\t*chroot_path;\n\tconst char\t\t\t*wd;\n\n\tstruct lws_spawn_piped\t\t**plsp;\n\n\tvoid\t\t\t\t*opaque;\n\n\tlsp_cb_t\t\t\treap_cb;\n\n\tlws_usec_t\t\t\ttimeout_us;\n\tint\t\t\t\tmax_log_lines;\n\tint\t\t\t\ttsi;\n\n\tconst struct lws_role_ops\t*ops; /* NULL is raw file */\n\n\tuint8_t\t\t\t\tdisable_ctrlc;\n};\n\n/**\n * lws_spawn_piped() - spawn a child process with stdxxx redirected\n *\n * \u005cp lspi: info struct describing details of spawn to create\n *\n * This spawns a child process managed in the lsp object and with attributes\n * set in the arguments. The stdin/out/err streams are redirected to pipes\n * which are instantiated into wsi that become child wsi of \u005cp parent if non-\n * NULL. .opaque_user_data on the stdwsi created is set to point to the\n * lsp object, so this can be recovered easily in the protocol handler.\n *\n * If \u005cp owner is non-NULL, successful spawns join the given dll2 owner in the\n * original process.\n *\n * If \u005cp timeout is non-zero, successful spawns register a sul with the us-\n * resolution timeout to callback \u005cp timeout_cb, in the original process.\n *\n * Returns 0 if the spawn went OK or nonzero if it failed and was cleaned up.\n * The spawned process continues asynchronously and this will return after\n * starting it if all went well.\n */\nLWS_VISIBLE LWS_EXTERN struct lws_spawn_piped *\nlws_spawn_piped(const struct lws_spawn_piped_info *lspi);\n\n/*\n * lws_spawn_piped_kill_child_process() - attempt to kill child process\n *\n * \u005cp lsp: child object to kill\n *\n * Attempts to signal the child process in \u005cp lsp to terminate.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_spawn_piped_kill_child_process(struct lws_spawn_piped *lsp);\n\n/**\n * lws_spawn_stdwsi_closed() - inform the spawn one of its stdxxx pipes closed\n *\n * \u005cp lsp: the spawn object\n * \u005cp wsi: the wsi that is closing\n *\n * When you notice one of the spawn stdxxx pipes closed, inform the spawn\n * instance using this api. When it sees all three have closed, it will\n * automatically try to reap the child process.\n *\n * This is the mechanism whereby the spawn object can understand its child\n * has closed.\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_spawn_stdwsi_closed(struct lws_spawn_piped *lsp, struct lws *wsi);\n\n/**\n * lws_spawn_get_stdfd() - return std channel index for stdwsi\n *\n * \u005cp wsi: the wsi\n *\n * If you know wsi is a stdwsi from a spawn, you can determine its original\n * channel index / fd before the pipes replaced the default fds. It will return\n * one of 0 (STDIN), 1 (STDOUT) or 2 (STDERR). You can handle all three in the\n * same protocol handler and then disambiguate them using this api.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_spawn_get_stdfd(struct lws *wsi);\n\n#endif\n\nstruct lws_fsmount {\n\tconst char\t*layers_path;\t/* where layers live */\n\tconst char\t*overlay_path;\t/* where overlay instantiations live */\n\n\tchar\t\tmp[256];\t/* mountpoint path */\n\tchar\t\tovname[64];\t/* unique name for mount instance */\n\tchar\t\tdistro[64];\t/* unique name for layer source */\n\n#if defined(__linux__)\n\tconst char\t*layers[4];\t/* distro layers, like \u0022base\u0022, \u0022env\u0022 */\n#endif\n};\n\n/**\n * lws_fsmount_mount() - Mounts an overlayfs stack of layers\n *\n * \u005cp fsm: struct lws_fsmount specifying the mount layout\n *\n * This api is able to assemble up to 4 layer directories on to a mountpoint\n * using overlayfs mount (Linux only).\n *\n * Set fsm.layers_path to the base dir where the layers themselves live, the\n * entries in fsm.layers[] specifies the relative path to the layer, comprising\n * fsm.layers_path/fsm.distro/fsm.layers[], with [0] being the deepest, earliest\n * layer and the rest being progressively on top of [0]; NULL indicates the\n * layer is unused.\n *\n * fsm.overlay_path is the base path of the overlayfs instantiations... empty\n * dirs must exist at\n *\n * fsm.overlay_path/overlays/fsm.ovname/work\n * fsm.overlay_path/overlays/fsm.ovname/session\n *\n * Set fsm.mp to the path of an already-existing empty dir that will be the\n * mountpoint, this can be whereever you like.\n *\n * Overlayfs merges the union of all the contributing layers at the mountpoint,\n * the mount is writeable but the layer themselves are immutable, all additions\n * and changes are stored in\n *\n * fsm.overlay_path/overlays/fsm.ovname/session\n *\n * Returns 0 if mounted OK, nonzero if errors.\n *\n * Retain fsm for use with unmounting.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_fsmount_mount(struct lws_fsmount *fsm);\n\n/**\n * lws_fsmount_unmount() - Unmounts an overlayfs dir\n *\n * \u005cp fsm: struct lws_fsmount specifying the mount layout\n *\n * Unmounts the mountpoint in fsm.mp.\n *\n * Delete fsm.overlay_path/overlays/fsm.ovname/session to permanently eradicate\n * all changes from the time the mountpoint was in use.\n *\n * Returns 0 if unmounted OK.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_fsmount_unmount(struct lws_fsmount *fsm);\n","s":{"c":1614904794,"u": 1331}} ],"g": 24019,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}