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":1606518670, "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":"1993c18cda9cc728becb0665c7f18070", "oid":{ "oid": "41240965cf0359128c7c51cd35d6bd6d0bc95bb0", "alias": [ "refs/heads/main","refs/heads/master"]},"blobname": "include/libwebsockets/lws-http.h", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2020 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/* minimal space for typical headers and CSP stuff */\n\n#define LWS_RECOMMENDED_MIN_HEADER_SPACE 2048\n\n/*! \u005cdefgroup http HTTP\n\n Modules related to handling HTTP\n*/\n//@{\n\n/*! \u005cdefgroup httpft HTTP File transfer\n * \u005cingroup http\n\n APIs for sending local files in response to HTTP requests\n*/\n//@{\n\n/**\n * lws_get_mimetype() - Determine mimetype to use from filename\n *\n * \u005cparam file:\t\tfilename\n * \u005cparam m:\t\tNULL, or mount context\n *\n * This uses a canned list of known filetypes first, if no match and m is\n * non-NULL, then tries a list of per-mount file suffix to mimtype mappings.\n *\n * Returns either NULL or a pointer to the mimetype matching the file.\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_get_mimetype(const char *file, const struct lws_http_mount *m);\n\n/**\n * lws_serve_http_file() - Send a file back to the client using http\n * \u005cparam wsi:\t\tWebsocket instance (available from user callback)\n * \u005cparam file:\t\tThe file to issue over http\n * \u005cparam content_type:\tThe http content type, eg, text/html\n * \u005cparam other_headers:\tNULL or pointer to header string\n * \u005cparam other_headers_len:\tlength of the other headers if non-NULL\n *\n *\tThis function is intended to be called from the callback in response\n *\tto http requests from the client. It allows the callback to issue\n *\tlocal files down the http link in a single step.\n *\n *\tReturning \u003c0 indicates error and the wsi should be closed. Returning\n *\t\u003e0 indicates the file was completely sent and\n *\tlws_http_transaction_completed() called on the wsi (and close if !\u003d 0)\n *\t\u003d\u003d0 indicates the file transfer is started and needs more service later,\n *\tthe wsi should be left alone.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,\n\t\t const char *other_headers, int other_headers_len);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_serve_http_file_fragment(struct lws *wsi);\n//@}\n\n\nenum http_status {\n\tHTTP_STATUS_CONTINUE\t\t\t\t\t\u003d 100,\n\n\tHTTP_STATUS_OK\t\t\t\t\t\t\u003d 200,\n\tHTTP_STATUS_NO_CONTENT\t\t\t\t\t\u003d 204,\n\tHTTP_STATUS_PARTIAL_CONTENT\t\t\t\t\u003d 206,\n\n\tHTTP_STATUS_MOVED_PERMANENTLY\t\t\t\t\u003d 301,\n\tHTTP_STATUS_FOUND\t\t\t\t\t\u003d 302,\n\tHTTP_STATUS_SEE_OTHER\t\t\t\t\t\u003d 303,\n\tHTTP_STATUS_NOT_MODIFIED\t\t\t\t\u003d 304,\n\n\tHTTP_STATUS_BAD_REQUEST\t\t\t\t\t\u003d 400,\n\tHTTP_STATUS_UNAUTHORIZED,\n\tHTTP_STATUS_PAYMENT_REQUIRED,\n\tHTTP_STATUS_FORBIDDEN,\n\tHTTP_STATUS_NOT_FOUND,\n\tHTTP_STATUS_METHOD_NOT_ALLOWED,\n\tHTTP_STATUS_NOT_ACCEPTABLE,\n\tHTTP_STATUS_PROXY_AUTH_REQUIRED,\n\tHTTP_STATUS_REQUEST_TIMEOUT,\n\tHTTP_STATUS_CONFLICT,\n\tHTTP_STATUS_GONE,\n\tHTTP_STATUS_LENGTH_REQUIRED,\n\tHTTP_STATUS_PRECONDITION_FAILED,\n\tHTTP_STATUS_REQ_ENTITY_TOO_LARGE,\n\tHTTP_STATUS_REQ_URI_TOO_LONG,\n\tHTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,\n\tHTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,\n\tHTTP_STATUS_EXPECTATION_FAILED,\n\n\tHTTP_STATUS_INTERNAL_SERVER_ERROR\t\t\t\u003d 500,\n\tHTTP_STATUS_NOT_IMPLEMENTED,\n\tHTTP_STATUS_BAD_GATEWAY,\n\tHTTP_STATUS_SERVICE_UNAVAILABLE,\n\tHTTP_STATUS_GATEWAY_TIMEOUT,\n\tHTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,\n};\n/*! \u005cdefgroup html-chunked-substitution HTML Chunked Substitution\n * \u005cingroup http\n *\n * ##HTML chunked Substitution\n *\n * APIs for receiving chunks of text, replacing a set of variable names via\n * a callback, and then prepending and appending HTML chunked encoding\n * headers.\n */\n//@{\n\nstruct lws_process_html_args {\n\tchar *p; /**\u003c pointer to the buffer containing the data */\n\tint len; /**\u003c length of the original data at p */\n\tint max_len; /**\u003c maximum length we can grow the data to */\n\tint final; /**\u003c set if this is the last chunk of the file */\n\tint chunked; /**\u003c 0 \u003d\u003d unchunked, 1 \u003d\u003d produce chunk headers\n\t\t\t(incompatible with HTTP/2) */\n};\n\ntypedef const char *(*lws_process_html_state_cb)(void *data, int index);\n\nstruct lws_process_html_state {\n\tchar *start; /**\u003c pointer to start of match */\n\tchar swallow[16]; /**\u003c matched character buffer */\n\tint pos; /**\u003c position in match */\n\tvoid *data; /**\u003c opaque pointer */\n\tconst char * const *vars; /**\u003c list of variable names */\n\tint count_vars; /**\u003c count of variable names */\n\n\tlws_process_html_state_cb replace;\n\t\t/**\u003c called on match to perform substitution */\n};\n\n/*! lws_chunked_html_process() - generic chunked substitution\n * \u005cparam args: buffer to process using chunked encoding\n * \u005cparam s: current processing state\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_chunked_html_process(struct lws_process_html_args *args,\n\t\t\t struct lws_process_html_state *s);\n//@}\n\n/** \u005cdefgroup HTTP-headers-read HTTP headers: read\n * \u005cingroup http\n *\n * ##HTTP header releated functions\n *\n * In lws the client http headers are temporarily stored in a pool, only for the\n * duration of the http part of the handshake. It's because in most cases,\n * the header content is ignored for the whole rest of the connection lifetime\n * and would then just be taking up space needlessly.\n *\n * During LWS_CALLBACK_HTTP when the URI path is delivered is the last time\n * the http headers are still allocated, you can use these apis then to\n * look at and copy out interesting header content (cookies, etc)\n *\n * Notice that the header total length reported does not include a terminating\n * '\u005c0', however you must allocate for it when using the _copy apis. So the\n * length reported for a header containing \u0022123\u0022 is 3, but you must provide\n * a buffer of length 4 so that \u0022123\u005c0\u0022 may be copied into it, or the copy\n * will fail with a nonzero return code.\n *\n * In the special case of URL arguments, like ?x\u003d1\u0026y\u003d2, the arguments are\n * stored in a token named for the method, eg, WSI_TOKEN_GET_URI if it\n * was a GET or WSI_TOKEN_POST_URI if POST. You can check the total\n * length to confirm the method.\n *\n * For URL arguments, each argument is stored urldecoded in a \u0022fragment\u0022, so\n * you can use the fragment-aware api lws_hdr_copy_fragment() to access each\n * argument in turn: the fragments contain urldecoded strings like x\u003d1 or y\u003d2.\n *\n * As a convenience, lws has an api that will find the fragment with a\n * given name\u003d part, lws_get_urlarg_by_name().\n */\n///@{\n\n/** struct lws_tokens\n * you need these to look at headers that have been parsed if using the\n * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum\n * list below is absent, .token \u003d NULL and len \u003d 0. Otherwise .token\n * points to .len chars containing that header content.\n */\nstruct lws_tokens {\n\tunsigned char *token; /**\u003c pointer to start of the token */\n\tint len; /**\u003c length of the token's value */\n};\n\n/* enum lws_token_indexes\n * these have to be kept in sync with lextable.h / minilex.c\n *\n * NOTE: These public enums are part of the abi. If you want to add one,\n * add it at where specified so existing users are unaffected.\n */\nenum lws_token_indexes {\n\tWSI_TOKEN_GET_URI, /* 0 */\n\tWSI_TOKEN_POST_URI,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_OPTIONS_URI,\n#endif\n\tWSI_TOKEN_HOST,\n\tWSI_TOKEN_CONNECTION,\n\tWSI_TOKEN_UPGRADE, /* 5 */\n\tWSI_TOKEN_ORIGIN,\n#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_DRAFT,\n#endif\n\tWSI_TOKEN_CHALLENGE,\n#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_EXTENSIONS,\n\tWSI_TOKEN_KEY1, /* 10 */\n\tWSI_TOKEN_KEY2,\n\tWSI_TOKEN_PROTOCOL,\n\tWSI_TOKEN_ACCEPT,\n\tWSI_TOKEN_NONCE,\n#endif\n\tWSI_TOKEN_HTTP,\n#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP2_SETTINGS, /* 16 */\n#endif\n\tWSI_TOKEN_HTTP_ACCEPT,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_AC_REQUEST_HEADERS,\n#endif\n\tWSI_TOKEN_HTTP_IF_MODIFIED_SINCE,\n\tWSI_TOKEN_HTTP_IF_NONE_MATCH, /* 20 */\n\tWSI_TOKEN_HTTP_ACCEPT_ENCODING,\n\tWSI_TOKEN_HTTP_ACCEPT_LANGUAGE,\n\tWSI_TOKEN_HTTP_PRAGMA,\n\tWSI_TOKEN_HTTP_CACHE_CONTROL,\n\tWSI_TOKEN_HTTP_AUTHORIZATION,\n\tWSI_TOKEN_HTTP_COOKIE,\n\tWSI_TOKEN_HTTP_CONTENT_LENGTH, /* 27 */\n\tWSI_TOKEN_HTTP_CONTENT_TYPE,\n\tWSI_TOKEN_HTTP_DATE,\n\tWSI_TOKEN_HTTP_RANGE,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_REFERER,\n#endif\n#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_KEY,\n\tWSI_TOKEN_VERSION,\n\tWSI_TOKEN_SWORIGIN,\n#endif\n#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_COLON_AUTHORITY,\n\tWSI_TOKEN_HTTP_COLON_METHOD,\n\tWSI_TOKEN_HTTP_COLON_PATH,\n\tWSI_TOKEN_HTTP_COLON_SCHEME,\n\tWSI_TOKEN_HTTP_COLON_STATUS,\n#endif\n\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_ACCEPT_CHARSET,\n#endif\n\tWSI_TOKEN_HTTP_ACCEPT_RANGES,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN,\n#endif\n\tWSI_TOKEN_HTTP_AGE,\n\tWSI_TOKEN_HTTP_ALLOW,\n\tWSI_TOKEN_HTTP_CONTENT_DISPOSITION,\n\tWSI_TOKEN_HTTP_CONTENT_ENCODING,\n\tWSI_TOKEN_HTTP_CONTENT_LANGUAGE,\n\tWSI_TOKEN_HTTP_CONTENT_LOCATION,\n\tWSI_TOKEN_HTTP_CONTENT_RANGE,\n\tWSI_TOKEN_HTTP_ETAG,\n\tWSI_TOKEN_HTTP_EXPECT,\n\tWSI_TOKEN_HTTP_EXPIRES,\n\tWSI_TOKEN_HTTP_FROM,\n\tWSI_TOKEN_HTTP_IF_MATCH,\n\tWSI_TOKEN_HTTP_IF_RANGE,\n\tWSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE,\n\tWSI_TOKEN_HTTP_LAST_MODIFIED,\n\tWSI_TOKEN_HTTP_LINK,\n\tWSI_TOKEN_HTTP_LOCATION,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_MAX_FORWARDS,\n\tWSI_TOKEN_HTTP_PROXY_AUTHENTICATE,\n\tWSI_TOKEN_HTTP_PROXY_AUTHORIZATION,\n#endif\n\tWSI_TOKEN_HTTP_REFRESH,\n\tWSI_TOKEN_HTTP_RETRY_AFTER,\n\tWSI_TOKEN_HTTP_SERVER,\n\tWSI_TOKEN_HTTP_SET_COOKIE,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY,\n#endif\n\tWSI_TOKEN_HTTP_TRANSFER_ENCODING,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_HTTP_USER_AGENT,\n\tWSI_TOKEN_HTTP_VARY,\n\tWSI_TOKEN_HTTP_VIA,\n\tWSI_TOKEN_HTTP_WWW_AUTHENTICATE,\n#endif\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_PATCH_URI,\n\tWSI_TOKEN_PUT_URI,\n\tWSI_TOKEN_DELETE_URI,\n#endif\n\n\tWSI_TOKEN_HTTP_URI_ARGS,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_PROXY,\n\tWSI_TOKEN_HTTP_X_REAL_IP,\n#endif\n\tWSI_TOKEN_HTTP1_0,\n\tWSI_TOKEN_X_FORWARDED_FOR,\n\tWSI_TOKEN_CONNECT,\n\tWSI_TOKEN_HEAD_URI,\n#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_TE,\n\tWSI_TOKEN_REPLAY_NONCE, /* ACME */\n#endif\n#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_COLON_PROTOCOL,\n#endif\n\tWSI_TOKEN_X_AUTH_TOKEN,\n\n\t/****** add new things just above ---^ ******/\n\n\t/* use token storage to stash these internally, not for\n\t * user use */\n\n\t_WSI_TOKEN_CLIENT_SENT_PROTOCOLS,\n\t_WSI_TOKEN_CLIENT_PEER_ADDRESS,\n\t_WSI_TOKEN_CLIENT_URI,\n\t_WSI_TOKEN_CLIENT_HOST,\n\t_WSI_TOKEN_CLIENT_ORIGIN,\n\t_WSI_TOKEN_CLIENT_METHOD,\n\t_WSI_TOKEN_CLIENT_IFACE,\n\t_WSI_TOKEN_CLIENT_ALPN,\n\n\t/* always last real token index*/\n\tWSI_TOKEN_COUNT,\n\n\t/* parser state additions, no storage associated */\n\tWSI_TOKEN_NAME_PART,\n#if defined(LWS_WITH_CUSTOM_HEADERS) || defined(LWS_HTTP_HEADERS_ALL)\n\tWSI_TOKEN_UNKNOWN_VALUE_PART,\n#endif\n\tWSI_TOKEN_SKIPPING,\n\tWSI_TOKEN_SKIPPING_SAW_CR,\n\tWSI_PARSING_COMPLETE,\n\tWSI_INIT_TOKEN_MUXURL,\n};\n\nstruct lws_token_limits {\n\tunsigned short token_limit[WSI_TOKEN_COUNT]; /**\u003c max chars for this token */\n};\n\nenum lws_h2_settings {\n\tH2SET_HEADER_TABLE_SIZE \u003d 1,\n\tH2SET_ENABLE_PUSH,\n\tH2SET_MAX_CONCURRENT_STREAMS,\n\tH2SET_INITIAL_WINDOW_SIZE,\n\tH2SET_MAX_FRAME_SIZE,\n\tH2SET_MAX_HEADER_LIST_SIZE,\n\tH2SET_RESERVED7,\n\tH2SET_ENABLE_CONNECT_PROTOCOL, /* defined in mcmanus-httpbis-h2-ws-02 */\n\n\tH2SET_COUNT /* always last */\n};\n\n/**\n * lws_token_to_string() - returns a textual representation of a hdr token index\n *\n * \u005cparam token: token index\n */\nLWS_VISIBLE LWS_EXTERN const unsigned char *\nlws_token_to_string(enum lws_token_indexes token);\n\n/**\n * lws_hdr_total_length: report length of all fragments of a header totalled up\n *\t\tThe returned length does not include the space for a\n *\t\tterminating '\u005c0'\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam h: which header index we are interested in\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);\n\n/**\n * lws_hdr_fragment_length: report length of a single fragment of a header\n *\t\tThe returned length does not include the space for a\n *\t\tterminating '\u005c0'\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam h: which header index we are interested in\n * \u005cparam frag_idx: which fragment of h we want to get the length of\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h,\n\t\t\tint frag_idx);\n\n/**\n * lws_hdr_copy() - copy all fragments of the given header to a buffer\n *\t\tThe buffer length len must include space for an additional\n *\t\tterminating '\u005c0', or it will fail returning -1.\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam dest: destination buffer\n * \u005cparam len: length of destination buffer\n * \u005cparam h: which header index we are interested in\n *\n * copies the whole, aggregated header, even if it was delivered in\n * several actual headers piece by piece. Returns -1 or length of the whole\n * header.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);\n\n/**\n * lws_hdr_copy_fragment() - copy a single fragment of the given header to a buffer\n *\t\tThe buffer length len must include space for an additional\n *\t\tterminating '\u005c0', or it will fail returning -1.\n *\t\tIf the requested fragment index is not present, it fails\n *\t\treturning -1.\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam dest: destination buffer\n * \u005cparam len: length of destination buffer\n * \u005cparam h: which header index we are interested in\n * \u005cparam frag_idx: which fragment of h we want to copy\n *\n * Normally this is only useful\n * to parse URI arguments like ?x\u003d1\u0026y\u003d2, token index WSI_TOKEN_HTTP_URI_ARGS\n * fragment 0 will contain \u0022x\u003d1\u0022 and fragment 1 \u0022y\u003d2\u0022\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,\n\t\t enum lws_token_indexes h, int frag_idx);\n\n/**\n * lws_hdr_custom_length() - return length of a custom header\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam name: header string (including terminating :)\n * \u005cparam nlen: length of name\n *\n * Lws knows about 100 common http headers, and parses them into indexes when\n * it recognizes them. When it meets a header that it doesn't know, it stores\n * the name and value directly, and you can look them up using\n * lws_hdr_custom_length() and lws_hdr_custom_copy().\n *\n * This api returns -1, or the length of the value part of the header if it\n * exists. Lws must be built with LWS_WITH_CUSTOM_HEADERS (on by default) to\n * use this api.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hdr_custom_length(struct lws *wsi, const char *name, int nlen);\n\n/**\n * lws_hdr_custom_copy() - copy value part of a custom header\n *\n * \u005cparam wsi: websocket connection\n * \u005cparam dst: pointer to buffer to receive the copy\n * \u005cparam len: number of bytes available at dst\n * \u005cparam name: header string (including terminating :)\n * \u005cparam nlen: length of name\n *\n * Lws knows about 100 common http headers, and parses them into indexes when\n * it recognizes them. When it meets a header that it doesn't know, it stores\n * the name and value directly, and you can look them up using\n * lws_hdr_custom_length() and lws_hdr_custom_copy().\n *\n * This api returns -1, or the length of the string it copied into dst if it\n * was big enough to contain both the string and an extra terminating NUL. Lws\n * must be built with LWS_WITH_CUSTOM_HEADERS (on by default) to use this api.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name,\n\t\t int nlen);\n\n/**\n * lws_get_urlarg_by_name() - return pointer to arg value if present\n * \u005cparam wsi: the connection to check\n * \u005cparam name: the arg name, like \u0022token\u003d\u0022\n * \u005cparam buf: the buffer to receive the urlarg (including the name\u003d part)\n * \u005cparam len: the length of the buffer to receive the urlarg\n *\n * Returns NULL if not found or a pointer inside buf to just after the\n * name\u003d part.\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);\n///@}\n\n/*! \u005cdefgroup HTTP-headers-create HTTP headers: create\n *\n * ## HTTP headers: Create\n *\n * These apis allow you to create HTTP response headers in a way compatible with\n * both HTTP/1.x and HTTP/2.\n *\n * They each append to a buffer taking care about the buffer end, which is\n * passed in as a pointer. When data is written to the buffer, the current\n * position p is updated accordingly.\n *\n * All of these apis are LWS_WARN_UNUSED_RESULT as they can run out of space\n * and fail with nonzero return.\n */\n///@{\n\n#define LWSAHH_CODE_MASK\t\t\t((1 \u003c\u003c 16) - 1)\n#define LWSAHH_FLAG_NO_SERVER_NAME\t\t(1 \u003c\u003c 30)\n\n/**\n * lws_add_http_header_status() - add the HTTP response status code\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam code: an HTTP code like 200, 404 etc (see enum http_status)\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Adds the initial response code, so should be called first.\n *\n * Code may additionally take OR'd flags:\n *\n * LWSAHH_FLAG_NO_SERVER_NAME: don't apply server name header this time\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_add_http_header_status(struct lws *wsi,\n\t\t\t unsigned int code, unsigned char **p,\n\t\t\t unsigned char *end);\n/**\n * lws_add_http_header_by_name() - append named header and value\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam name: the hdr name, like \u0022my-header:\u0022\n * \u005cparam value: the value after the \u003d for this header\n * \u005cparam length: the length of the value\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Appends name: value to the headers\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,\n\t\t\t const unsigned char *value, int length,\n\t\t\t unsigned char **p, unsigned char *end);\n/**\n * lws_add_http_header_by_token() - append given header and value\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam token: the token index for the hdr\n * \u005cparam value: the value after the \u003d for this header\n * \u005cparam length: the length of the value\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Appends name\u003dvalue to the headers, but is able to take advantage of better\n * HTTP/2 coding mechanisms where possible.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,\n\t\t\t const unsigned char *value, int length,\n\t\t\t unsigned char **p, unsigned char *end);\n/**\n * lws_add_http_header_content_length() - append content-length helper\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam content_length: the content length to use\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Appends content-length: content_length to the headers\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_add_http_header_content_length(struct lws *wsi,\n\t\t\t\t lws_filepos_t content_length,\n\t\t\t\t unsigned char **p, unsigned char *end);\n/**\n * lws_finalize_http_header() - terminate header block\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Indicates no more headers will be added\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_finalize_http_header(struct lws *wsi, unsigned char **p,\n\t\t\t unsigned char *end);\n\n/**\n * lws_finalize_write_http_header() - Helper finializing and writing http headers\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam start: pointer to the start of headers in the buffer, eg \u0026buf[LWS_PRE]\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Terminates the headers correctly accoring to the protocol in use (h1 / h2)\n * and writes the headers. Returns nonzero for error.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_finalize_write_http_header(struct lws *wsi, unsigned char *start,\n\t\t\t unsigned char **p, unsigned char *end);\n\n#define LWS_ILLEGAL_HTTP_CONTENT_LEN ((lws_filepos_t)-1ll)\n\n/**\n * lws_add_http_common_headers() - Helper preparing common http headers\n *\n * \u005cparam wsi: the connection to check\n * \u005cparam code: an HTTP code like 200, 404 etc (see enum http_status)\n * \u005cparam content_type: the content type, like \u0022text/html\u0022\n * \u005cparam content_len: the content length, in bytes\n * \u005cparam p: pointer to current position in buffer pointer\n * \u005cparam end: pointer to end of buffer\n *\n * Adds the initial response code, so should be called first.\n *\n * Code may additionally take OR'd flags:\n *\n * LWSAHH_FLAG_NO_SERVER_NAME: don't apply server name header this time\n *\n * This helper just calls public apis to simplify adding headers that are\n * commonly needed. If it doesn't fit your case, or you want to add additional\n * headers just call the public apis directly yourself for what you want.\n *\n * You can miss out the content length header by providing the constant\n * LWS_ILLEGAL_HTTP_CONTENT_LEN for the content_len.\n *\n * It does not call lws_finalize_http_header(), to allow you to add further\n * headers after calling this. You will need to call that yourself at the end.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_add_http_common_headers(struct lws *wsi, unsigned int code,\n\t\t\t const char *content_type, lws_filepos_t content_len,\n\t\t\t unsigned char **p, unsigned char *end);\n\nenum {\n\tLWSHUMETH_GET,\n\tLWSHUMETH_POST,\n\tLWSHUMETH_OPTIONS,\n\tLWSHUMETH_PUT,\n\tLWSHUMETH_PATCH,\n\tLWSHUMETH_DELETE,\n\tLWSHUMETH_CONNECT,\n\tLWSHUMETH_HEAD,\n\tLWSHUMETH_COLON_PATH,\n};\n\n/**\n * lws_http_get_uri_and_method() - Get information on method and url\n *\n * \u005cparam wsi: the connection to get information on\n * \u005cparam puri_ptr: points to pointer to set to url\n * \u005cparam puri_len: points to int to set to uri length\n *\n * Returns -1 or method index as one of the LWSHUMETH_ constants\n *\n * If returns method, *puri_ptr is set to the method's URI string and *puri_len\n * to its length\n */\n\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len);\n\n///@}\n\n/*! \u005cdefgroup urlendec Urlencode and Urldecode\n * \u005cingroup http\n *\n * ##HTML chunked Substitution\n *\n * APIs for receiving chunks of text, replacing a set of variable names via\n * a callback, and then prepending and appending HTML chunked encoding\n * headers.\n */\n//@{\n\n/**\n * lws_urlencode() - like strncpy but with urlencoding\n *\n * \u005cparam escaped: output buffer\n * \u005cparam string: input buffer ('/0' terminated)\n * \u005cparam len: output buffer max length\n *\n * Because urlencoding expands the output string, it's not\n * possible to do it in-place, ie, with escaped \u003d\u003d string\n */\nLWS_VISIBLE LWS_EXTERN const char *\nlws_urlencode(char *escaped, const char *string, int len);\n\n/*\n * URLDECODE 1 / 2\n *\n * This simple urldecode only operates until the first '\u005c0' and requires the\n * data to exist all at once\n */\n/**\n * lws_urldecode() - like strncpy but with urldecoding\n *\n * \u005cparam string: output buffer\n * \u005cparam escaped: input buffer ('\u005c0' terminated)\n * \u005cparam len: output buffer max length\n *\n * This is only useful for '\u005c0' terminated strings\n *\n * Since urldecoding only shrinks the output string, it is possible to\n * do it in-place, ie, string \u003d\u003d escaped\n *\n * Returns 0 if completed OK or nonzero for urldecode violation (non-hex chars\n * where hex required, etc)\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_urldecode(char *string, const char *escaped, int len);\n///@}\n\n/**\n * lws_http_date_render_from_unix() - render unixtime as RFC7231 date string\n *\n * \u005cparam buf:\t\tDestination string buffer\n * \u005cparam len:\t\tavilable length of dest string buffer in bytes\n * \u005cparam t:\t\tpointer to the time_t to render\n *\n * Returns 0 if time_t is rendered into the string buffer successfully, else\n * nonzero.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_date_render_from_unix(char *buf, size_t len, const time_t *t);\n\n/**\n * lws_http_date_parse_unix() - parse a RFC7231 date string into unixtime\n *\n * \u005cparam b:\t\tSource string buffer\n * \u005cparam len:\t\tavilable length of source string buffer in bytes\n * \u005cparam t:\t\tpointer to the destination time_t to set\n *\n * Returns 0 if string buffer parsed as RFC7231 time successfully, and\n * *t set to the parsed unixtime, else return nonzero.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_date_parse_unix(const char *b, size_t len, time_t *t);\n\n/**\n * lws_http_check_retry_after() - increase a timeout if retry-after present\n *\n * \u005cparam wsi:\t\thttp stream this relates to\n * \u005cparam us_interval_in_out: default us retry interval on entry may be updated\n *\n * This function may extend the incoming retry interval if the server has\n * requested that using retry-after: header. It won't reduce the incoming\n * retry interval, only leave it alone or increase it.\n *\n * *us_interval_in_out should be set to a default retry interval on entry, if\n * the wsi has a retry-after time or interval that resolves to an interval\n * longer than the entry *us_interval_in_out, that will be updated to the longer\n * interval and return 0.\n *\n * If no usable retry-after or the time is now or in the past,\n * *us_interval_in_out is left alone and the function returns nonzero.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_check_retry_after(struct lws *wsi, lws_usec_t *us_interval_in_out);\n\n/**\n * lws_return_http_status() - Return simple http status\n * \u005cparam wsi:\t\tWebsocket instance (available from user callback)\n * \u005cparam code:\t\tStatus index, eg, 404\n * \u005cparam html_body:\t\tUser-readable HTML description \u003c 1KB, or NULL\n *\n *\tHelper to report HTTP errors back to the client cleanly and\n *\tconsistently\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_return_http_status(struct lws *wsi, unsigned int code,\n\t\t const char *html_body);\n\n/**\n * lws_http_redirect() - write http redirect out on wsi\n *\n * \u005cparam wsi:\twebsocket connection\n * \u005cparam code:\tHTTP response code (eg, 301)\n * \u005cparam loc:\twhere to redirect to\n * \u005cparam len:\tlength of loc\n * \u005cparam p:\tpointer current position in buffer (updated as we write)\n * \u005cparam end:\tpointer to end of buffer\n *\n * Returns amount written, or \u003c 0 indicating fatal write failure.\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len,\n\t\t unsigned char **p, unsigned char *end);\n\n/**\n * lws_http_transaction_completed() - wait for new http transaction or close\n * \u005cparam wsi:\twebsocket connection\n *\n *\tReturns 1 if the HTTP connection must close now\n *\tReturns 0 and resets connection to wait for new HTTP header /\n *\t transaction if possible\n */\nLWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT\nlws_http_transaction_completed(struct lws *wsi);\n\n/**\n * lws_http_headers_detach() - drop the associated headers storage and allow\n *\t\t\t\tit to be reused by another connection\n * \u005cparam wsi:\thttp connection\n *\n * If the wsi has an ah headers struct attached, detach it.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_headers_detach(struct lws *wsi);\n\n/**\n * lws_http_mark_sse() - called to indicate this http stream is now doing SSE\n *\n * \u005cparam wsi:\thttp connection\n *\n * Cancel any timeout on the wsi, and for h2, mark the network connection as\n * containing an immortal stream for the duration the SSE stream is open.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_mark_sse(struct lws *wsi);\n\n/**\n * lws_h2_client_stream_long_poll_rxonly() - h2 stream to immortal read-only\n *\n * \u005cparam wsi: h2 stream client wsi\n *\n * Send END_STREAM-flagged zero-length DATA frame to set client stream wsi into\n * half-closed (local) and remote into half-closed (remote). Set the client\n * stream wsi to be immortal (not subject to timeouts).\n *\n * Used if the remote server supports immortal long poll to put the stream into\n * a read-only state where it can wait as long as needed for rx.\n *\n * Returns 0 if the process (which happens asynchronously) started or non-zero\n * if it wasn't an h2 stream.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_h2_client_stream_long_poll_rxonly(struct lws *wsi);\n\n/**\n * lws_http_compression_apply() - apply an http compression transform\n *\n * \u005cparam wsi: the wsi to apply the compression transform to\n * \u005cparam name: NULL, or the name of the compression transform, eg, \u0022deflate\u0022\n * \u005cparam p: pointer to pointer to headers buffer\n * \u005cparam end: pointer to end of headers buffer\n * \u005cparam decomp: 0 \u003d add compressor to wsi, 1 \u003d add decompressor\n *\n * This allows transparent compression of dynamically generated HTTP. The\n * requested compression (eg, \u0022deflate\u0022) is only applied if the client headers\n * indicated it was supported (and it has support in lws), otherwise it's a NOP.\n *\n * If the requested compression method is NULL, then the supported compression\n * formats are tried, and for non-decompression (server) mode the first that's\n * found on the client's accept-encoding header is chosen.\n *\n * NOTE: the compression transform, same as h2 support, relies on the user\n * code using LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part\n * written. The internal lws fileserving code already does this.\n *\n * If the library was built without the cmake option\n * LWS_WITH_HTTP_STREAM_COMPRESSION set, then a NOP is provided for this api,\n * allowing user code to build either way and use compression if available.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_compression_apply(struct lws *wsi, const char *name,\n\t\t\t unsigned char **p, unsigned char *end, char decomp);\n\n/**\n * lws_http_is_redirected_to_get() - true if redirected to GET\n *\n * \u005cparam wsi: the wsi to check\n *\n * Check if the wsi is currently in GET mode, after, eg, doing a POST and\n * receiving a 303.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_is_redirected_to_get(struct lws *wsi);\n\n/**\n * lws_http_cookie_get() - return copy of named cookie if present\n *\n * \u005cparam wsi: the wsi to check\n * \u005cparam name: name of the cookie\n * \u005cparam buf: buffer to store the cookie contents into\n * \u005cparam max_len: on entry, maximum length of buf... on exit, used len of buf\n *\n * If no cookie header, or no cookie of the requested name, or the value is\n * larger than can fit in buf, returns nonzero.\n *\n * If the cookie is found, copies its value into buf with a terminating NUL,\n * sets *max_len to the used length, and returns 0.\n *\n * This handles the parsing of the possibly multi-cookie header string and\n * terminating the requested cookie at the next ; if present.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_http_cookie_get(struct lws *wsi, const char *name, char *buf, size_t *max);\n\n/**\n * lws_http_client_http_error() - determine if the response code indicates an error\n *\n * \u005cparam code: the response code to test\n *\n * Returns nonzero if the code indicates an error, else zero if reflects a\n * non-error condition\n */\n#define lws_http_client_http_resp_is_error(code) (!(code \u003c 400))\n\n/**\n * lws_h2_update_peer_txcredit() - manually update stream peer tx credit\n *\n * \u005cparam wsi: the h2 child stream whose peer credit to change\n * \u005cparam sid: the stream ID, or LWS_H2_STREAM_SID for the wsi stream ID\n * \u005cparam bump: signed change to confer upon peer tx credit for sid\n *\n * In conjunction with LCCSCF_H2_MANUAL_RXFLOW flag, allows the user code to\n * selectively starve the remote peer of the ability to send us data on a client\n * connection.\n *\n * Normally lws sends an initial window size for the peer to send to it of 0,\n * but during the header phase it sends a WINDOW_UPDATE to increase the amount\n * available. LCCSCF_H2_MANUAL_RXFLOW restricts this initial increase in tx\n * credit for the stream, before it has been asked to send us anything, to the\n * amount specified in the client info .manual_initial_tx_credit member, and\n * this api can be called to send the other side permission to send us up to\n * \u005cp bump additional bytes.\n *\n * The nwsi tx credit is updated automatically for exactly what was sent to us\n * on a stream with LCCSCF_H2_MANUAL_RXFLOW flag, but the stream's own tx credit\n * must be handled manually by user code via this api.\n *\n * Returns 0 for success or nonzero for failure.\n */\n#define LWS_H2_STREAM_SID -1\nLWS_VISIBLE LWS_EXTERN int\nlws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump);\n\n\n/**\n * lws_h2_get_peer_txcredit_estimate() - return peer tx credit estimate\n *\n * \u005cparam wsi: the h2 child stream whose peer credit estimate to return\n *\n * Returns the estimated amount of tx credit at the peer, in other words the\n * number of bytes the peer is authorized to send to us.\n *\n * It's an 'estimate' because we don't know how much is already in flight\n * towards us and actually already used.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_h2_get_peer_txcredit_estimate(struct lws *wsi);\n\n///@}\n\n","s":{"c":1606518670,"u": 570}} ],"g": 5551,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}