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":1571532994, "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":"145dcbf720fc98ba4dbe8b2d32e2a522", "oid":{ "oid": "b7a04a67d15efd0f17bf795b8d3648425b604581", "alias": [ "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 - 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/* 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\t\t\t\t\t\u003d 0,\n\tWSI_TOKEN_POST_URI\t\t\t\t\t\u003d 1,\n\tWSI_TOKEN_OPTIONS_URI\t\t\t\t\t\u003d 2,\n\tWSI_TOKEN_HOST\t\t\t\t\t\t\u003d 3,\n\tWSI_TOKEN_CONNECTION\t\t\t\t\t\u003d 4,\n\tWSI_TOKEN_UPGRADE\t\t\t\t\t\u003d 5,\n\tWSI_TOKEN_ORIGIN\t\t\t\t\t\u003d 6,\n\tWSI_TOKEN_DRAFT\t\t\t\t\t\t\u003d 7,\n\tWSI_TOKEN_CHALLENGE\t\t\t\t\t\u003d 8,\n\tWSI_TOKEN_EXTENSIONS\t\t\t\t\t\u003d 9,\n\tWSI_TOKEN_KEY1\t\t\t\t\t\t\u003d 10,\n\tWSI_TOKEN_KEY2\t\t\t\t\t\t\u003d 11,\n\tWSI_TOKEN_PROTOCOL\t\t\t\t\t\u003d 12,\n\tWSI_TOKEN_ACCEPT\t\t\t\t\t\u003d 13,\n\tWSI_TOKEN_NONCE\t\t\t\t\t\t\u003d 14,\n\tWSI_TOKEN_HTTP\t\t\t\t\t\t\u003d 15,\n\tWSI_TOKEN_HTTP2_SETTINGS\t\t\t\t\u003d 16,\n\tWSI_TOKEN_HTTP_ACCEPT\t\t\t\t\t\u003d 17,\n\tWSI_TOKEN_HTTP_AC_REQUEST_HEADERS\t\t\t\u003d 18,\n\tWSI_TOKEN_HTTP_IF_MODIFIED_SINCE\t\t\t\u003d 19,\n\tWSI_TOKEN_HTTP_IF_NONE_MATCH\t\t\t\t\u003d 20,\n\tWSI_TOKEN_HTTP_ACCEPT_ENCODING\t\t\t\t\u003d 21,\n\tWSI_TOKEN_HTTP_ACCEPT_LANGUAGE\t\t\t\t\u003d 22,\n\tWSI_TOKEN_HTTP_PRAGMA\t\t\t\t\t\u003d 23,\n\tWSI_TOKEN_HTTP_CACHE_CONTROL\t\t\t\t\u003d 24,\n\tWSI_TOKEN_HTTP_AUTHORIZATION\t\t\t\t\u003d 25,\n\tWSI_TOKEN_HTTP_COOKIE\t\t\t\t\t\u003d 26,\n\tWSI_TOKEN_HTTP_CONTENT_LENGTH\t\t\t\t\u003d 27,\n\tWSI_TOKEN_HTTP_CONTENT_TYPE\t\t\t\t\u003d 28,\n\tWSI_TOKEN_HTTP_DATE\t\t\t\t\t\u003d 29,\n\tWSI_TOKEN_HTTP_RANGE\t\t\t\t\t\u003d 30,\n\tWSI_TOKEN_HTTP_REFERER\t\t\t\t\t\u003d 31,\n\tWSI_TOKEN_KEY\t\t\t\t\t\t\u003d 32,\n\tWSI_TOKEN_VERSION\t\t\t\t\t\u003d 33,\n\tWSI_TOKEN_SWORIGIN\t\t\t\t\t\u003d 34,\n\n\tWSI_TOKEN_HTTP_COLON_AUTHORITY\t\t\t\t\u003d 35,\n\tWSI_TOKEN_HTTP_COLON_METHOD\t\t\t\t\u003d 36,\n\tWSI_TOKEN_HTTP_COLON_PATH\t\t\t\t\u003d 37,\n\tWSI_TOKEN_HTTP_COLON_SCHEME\t\t\t\t\u003d 38,\n\tWSI_TOKEN_HTTP_COLON_STATUS\t\t\t\t\u003d 39,\n\n\tWSI_TOKEN_HTTP_ACCEPT_CHARSET\t\t\t\t\u003d 40,\n\tWSI_TOKEN_HTTP_ACCEPT_RANGES\t\t\t\t\u003d 41,\n\tWSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN\t\t\u003d 42,\n\tWSI_TOKEN_HTTP_AGE\t\t\t\t\t\u003d 43,\n\tWSI_TOKEN_HTTP_ALLOW\t\t\t\t\t\u003d 44,\n\tWSI_TOKEN_HTTP_CONTENT_DISPOSITION\t\t\t\u003d 45,\n\tWSI_TOKEN_HTTP_CONTENT_ENCODING\t\t\t\t\u003d 46,\n\tWSI_TOKEN_HTTP_CONTENT_LANGUAGE\t\t\t\t\u003d 47,\n\tWSI_TOKEN_HTTP_CONTENT_LOCATION\t\t\t\t\u003d 48,\n\tWSI_TOKEN_HTTP_CONTENT_RANGE\t\t\t\t\u003d 49,\n\tWSI_TOKEN_HTTP_ETAG\t\t\t\t\t\u003d 50,\n\tWSI_TOKEN_HTTP_EXPECT\t\t\t\t\t\u003d 51,\n\tWSI_TOKEN_HTTP_EXPIRES\t\t\t\t\t\u003d 52,\n\tWSI_TOKEN_HTTP_FROM\t\t\t\t\t\u003d 53,\n\tWSI_TOKEN_HTTP_IF_MATCH\t\t\t\t\t\u003d 54,\n\tWSI_TOKEN_HTTP_IF_RANGE\t\t\t\t\t\u003d 55,\n\tWSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE\t\t\t\u003d 56,\n\tWSI_TOKEN_HTTP_LAST_MODIFIED\t\t\t\t\u003d 57,\n\tWSI_TOKEN_HTTP_LINK\t\t\t\t\t\u003d 58,\n\tWSI_TOKEN_HTTP_LOCATION\t\t\t\t\t\u003d 59,\n\tWSI_TOKEN_HTTP_MAX_FORWARDS\t\t\t\t\u003d 60,\n\tWSI_TOKEN_HTTP_PROXY_AUTHENTICATE\t\t\t\u003d 61,\n\tWSI_TOKEN_HTTP_PROXY_AUTHORIZATION\t\t\t\u003d 62,\n\tWSI_TOKEN_HTTP_REFRESH\t\t\t\t\t\u003d 63,\n\tWSI_TOKEN_HTTP_RETRY_AFTER\t\t\t\t\u003d 64,\n\tWSI_TOKEN_HTTP_SERVER\t\t\t\t\t\u003d 65,\n\tWSI_TOKEN_HTTP_SET_COOKIE\t\t\t\t\u003d 66,\n\tWSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY\t\t\u003d 67,\n\tWSI_TOKEN_HTTP_TRANSFER_ENCODING\t\t\t\u003d 68,\n\tWSI_TOKEN_HTTP_USER_AGENT\t\t\t\t\u003d 69,\n\tWSI_TOKEN_HTTP_VARY\t\t\t\t\t\u003d 70,\n\tWSI_TOKEN_HTTP_VIA\t\t\t\t\t\u003d 71,\n\tWSI_TOKEN_HTTP_WWW_AUTHENTICATE\t\t\t\t\u003d 72,\n\n\tWSI_TOKEN_PATCH_URI\t\t\t\t\t\u003d 73,\n\tWSI_TOKEN_PUT_URI\t\t\t\t\t\u003d 74,\n\tWSI_TOKEN_DELETE_URI\t\t\t\t\t\u003d 75,\n\n\tWSI_TOKEN_HTTP_URI_ARGS\t\t\t\t\t\u003d 76,\n\tWSI_TOKEN_PROXY\t\t\t\t\t\t\u003d 77,\n\tWSI_TOKEN_HTTP_X_REAL_IP\t\t\t\t\u003d 78,\n\tWSI_TOKEN_HTTP1_0\t\t\t\t\t\u003d 79,\n\tWSI_TOKEN_X_FORWARDED_FOR\t\t\t\t\u003d 80,\n\tWSI_TOKEN_CONNECT\t\t\t\t\t\u003d 81,\n\tWSI_TOKEN_HEAD_URI\t\t\t\t\t\u003d 82,\n\tWSI_TOKEN_TE\t\t\t\t\t\t\u003d 83,\n\tWSI_TOKEN_REPLAY_NONCE\t\t\t\t\t\u003d 84,\n\tWSI_TOKEN_COLON_PROTOCOL\t\t\t\t\u003d 85,\n\tWSI_TOKEN_X_AUTH_TOKEN\t\t\t\t\t\u003d 86,\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)\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\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\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\n *\n * GET 0\n * POST 1\n * OPTIONS 2\n * PUT 3\n * PATCH 4\n * DELETE 5\n * CONNECT 6\n * HEAD 7\n * :path 8\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_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 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","s":{"c":1571532994,"u": 815}} ],"g": 3031,"chitpc": 0,"ehitpc": 0, "indexed":0 }