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":1618125060, "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":"4c6b63e223fbeac518db26ef0215e8e5", "oid":{ "oid": "24abd699f6a01315c4f5e0e216249ce21d54aabe", "alias": [ "refs/heads/main","refs/heads/master"]},"blobname": "include/libwebsockets/lws-lejp.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/** \u005cdefgroup lejp JSON parser\n * ##JSON parsing related functions\n * \u005cingroup lwsapi\n *\n * LEJP is an extremely lightweight JSON stream parser included in lws.\n */\n//@{\nstruct lejp_ctx;\n\n#if !defined(LWS_ARRAY_SIZE)\n#define LWS_ARRAY_SIZE(_x) (sizeof(_x) / sizeof(_x[0]))\n#endif\n#define LEJP_FLAG_WS_KEEP 64\n#define LEJP_FLAG_WS_COMMENTLINE 32\n\nenum lejp_states {\n\tLEJP_IDLE \u003d 0,\n\tLEJP_MEMBERS \u003d 1,\n\tLEJP_M_P \u003d 2,\n\tLEJP_MP_STRING \u003d LEJP_FLAG_WS_KEEP | 3,\n\tLEJP_MP_STRING_ESC \u003d LEJP_FLAG_WS_KEEP | 4,\n\tLEJP_MP_STRING_ESC_U1 \u003d LEJP_FLAG_WS_KEEP | 5,\n\tLEJP_MP_STRING_ESC_U2 \u003d LEJP_FLAG_WS_KEEP | 6,\n\tLEJP_MP_STRING_ESC_U3 \u003d LEJP_FLAG_WS_KEEP | 7,\n\tLEJP_MP_STRING_ESC_U4 \u003d LEJP_FLAG_WS_KEEP | 8,\n\tLEJP_MP_DELIM \u003d 9,\n\tLEJP_MP_VALUE \u003d 10,\n\tLEJP_MP_VALUE_NUM_INT \u003d LEJP_FLAG_WS_KEEP | 11,\n\tLEJP_MP_VALUE_NUM_EXP \u003d LEJP_FLAG_WS_KEEP | 12,\n\tLEJP_MP_VALUE_TOK \u003d LEJP_FLAG_WS_KEEP | 13,\n\tLEJP_MP_COMMA_OR_END \u003d 14,\n\tLEJP_MP_ARRAY_END \u003d 15,\n};\n\nenum lejp_reasons {\n\tLEJP_CONTINUE \u003d -1,\n\tLEJP_REJECT_IDLE_NO_BRACE \u003d -2,\n\tLEJP_REJECT_MEMBERS_NO_CLOSE \u003d -3,\n\tLEJP_REJECT_MP_NO_OPEN_QUOTE \u003d -4,\n\tLEJP_REJECT_MP_STRING_UNDERRUN \u003d -5,\n\tLEJP_REJECT_MP_ILLEGAL_CTRL \u003d -6,\n\tLEJP_REJECT_MP_STRING_ESC_ILLEGAL_ESC \u003d -7,\n\tLEJP_REJECT_ILLEGAL_HEX \u003d -8,\n\tLEJP_REJECT_MP_DELIM_MISSING_COLON \u003d -9,\n\tLEJP_REJECT_MP_DELIM_BAD_VALUE_START \u003d -10,\n\tLEJP_REJECT_MP_VAL_NUM_INT_NO_FRAC \u003d -11,\n\tLEJP_REJECT_MP_VAL_NUM_FORMAT \u003d -12,\n\tLEJP_REJECT_MP_VAL_NUM_EXP_BAD_EXP \u003d -13,\n\tLEJP_REJECT_MP_VAL_TOK_UNKNOWN \u003d -14,\n\tLEJP_REJECT_MP_C_OR_E_UNDERF \u003d -15,\n\tLEJP_REJECT_MP_C_OR_E_NOTARRAY \u003d -16,\n\tLEJP_REJECT_MP_ARRAY_END_MISSING \u003d -17,\n\tLEJP_REJECT_STACK_OVERFLOW \u003d -18,\n\tLEJP_REJECT_MP_DELIM_ISTACK \u003d -19,\n\tLEJP_REJECT_NUM_TOO_LONG \u003d -20,\n\tLEJP_REJECT_MP_C_OR_E_NEITHER \u003d -21,\n\tLEJP_REJECT_UNKNOWN \u003d -22,\n\tLEJP_REJECT_CALLBACK \u003d -23\n};\n\n#define LEJP_FLAG_CB_IS_VALUE 64\n\nenum lejp_callbacks {\n\tLEJPCB_CONSTRUCTED\t\u003d 0,\n\tLEJPCB_DESTRUCTED\t\u003d 1,\n\n\tLEJPCB_START\t\t\u003d 2,\n\tLEJPCB_COMPLETE\t\t\u003d 3,\n\tLEJPCB_FAILED\t\t\u003d 4,\n\n\tLEJPCB_PAIR_NAME\t\u003d 5,\n\n\tLEJPCB_VAL_TRUE\t\t\u003d LEJP_FLAG_CB_IS_VALUE | 6,\n\tLEJPCB_VAL_FALSE\t\u003d LEJP_FLAG_CB_IS_VALUE | 7,\n\tLEJPCB_VAL_NULL\t\t\u003d LEJP_FLAG_CB_IS_VALUE | 8,\n\tLEJPCB_VAL_NUM_INT\t\u003d LEJP_FLAG_CB_IS_VALUE | 9,\n\tLEJPCB_VAL_NUM_FLOAT\t\u003d LEJP_FLAG_CB_IS_VALUE | 10,\n\tLEJPCB_VAL_STR_START\t\u003d 11, /* notice handle separately */\n\tLEJPCB_VAL_STR_CHUNK\t\u003d LEJP_FLAG_CB_IS_VALUE | 12,\n\tLEJPCB_VAL_STR_END\t\u003d LEJP_FLAG_CB_IS_VALUE | 13,\n\n\tLEJPCB_ARRAY_START\t\u003d 14,\n\tLEJPCB_ARRAY_END\t\u003d 15,\n\n\tLEJPCB_OBJECT_START\t\u003d 16,\n\tLEJPCB_OBJECT_END\t\u003d 17,\n};\n\n/**\n * _lejp_callback() - User parser actions\n * \u005cparam ctx:\tLEJP context\n * \u005cparam reason:\tCallback reason\n *\n *\tYour user callback is associated with the context at construction time,\n *\tand receives calls as the parsing progresses.\n *\n *\tAll of the callbacks may be ignored and just return 0.\n *\n *\tThe reasons it might get called, found in @reason, are:\n *\n * LEJPCB_CONSTRUCTED: The context was just constructed... you might want to\n *\t\tperform one-time allocation for the life of the context.\n *\n * LEJPCB_DESTRUCTED:\tThe context is being destructed... if you made any\n *\t\tallocations at construction-time, you can free them now\n *\n * LEJPCB_START:\tParsing is beginning at the first byte of input\n *\n * LEJPCB_COMPLETE:\tParsing has completed successfully. You'll get a 0 or\n *\t\t\tpositive return code from lejp_parse indicating the\n *\t\t\tamount of unused bytes left in the input buffer\n *\n * LEJPCB_FAILED:\tParsing failed. You'll get a negative error code\n * \t\t\treturned from lejp_parse\n *\n * LEJPCB_PAIR_NAME:\tWhen a \u0022name\u0022:\u0022value\u0022 pair has had the name parsed,\n *\t\t\tthis callback occurs. You can find the new name at\n *\t\t\tthe end of ctx-\u003epath[]\n *\n * LEJPCB_VAL_TRUE:\tThe \u0022true\u0022 value appeared\n *\n * LEJPCB_VAL_FALSE:\tThe \u0022false\u0022 value appeared\n *\n * LEJPCB_VAL_NULL:\tThe \u0022null\u0022 value appeared\n *\n * LEJPCB_VAL_NUM_INT:\tA string representing an integer is in ctx-\u003ebuf\n *\n * LEJPCB_VAL_NUM_FLOAT: A string representing a float is in ctx-\u003ebuf\n *\n * LEJPCB_VAL_STR_START: We are starting to parse a string, no data yet\n *\n * LEJPCB_VAL_STR_CHUNK: We filled the string buffer in the ctx, but it's not\n *\t\t\t the end of the string. We produce this to spill the\n *\t\t\t intermediate buffer to the user code, so we can handle\n *\t\t\t huge JSON strings using only the small buffer in the\n *\t\t\t ctx. If the whole JSON string fits in the ctx buffer,\n *\t\t\t you won't get these callbacks.\n *\n * LEJPCB_VAL_STR_END:\tString parsing has completed, the last chunk of the\n *\t\t\tstring is in ctx-\u003ebuf.\n *\n * LEJPCB_ARRAY_START:\tAn array started\n *\n * LEJPCB_ARRAY_END:\tAn array ended\n *\n * LEJPCB_OBJECT_START: An object started\n *\n * LEJPCB_OBJECT_END:\tAn object ended\n */\nLWS_EXTERN signed char _lejp_callback(struct lejp_ctx *ctx, char reason);\n\ntypedef signed char (*lejp_callback)(struct lejp_ctx *ctx, char reason);\n\n#ifndef LEJP_MAX_PARSING_STACK_DEPTH\n#define LEJP_MAX_PARSING_STACK_DEPTH 5\n#endif\n#ifndef LEJP_MAX_DEPTH\n#define LEJP_MAX_DEPTH 12\n#endif\n#ifndef LEJP_MAX_INDEX_DEPTH\n#define LEJP_MAX_INDEX_DEPTH 8\n#endif\n#ifndef LEJP_MAX_PATH\n#define LEJP_MAX_PATH 128\n#endif\n#ifndef LEJP_STRING_CHUNK\n/* must be \u003e\u003d 30 to assemble floats */\n#define LEJP_STRING_CHUNK 254\n#endif\n\nenum num_flags {\n\tLEJP_SEEN_MINUS \u003d (1 \u003c\u003c 0),\n\tLEJP_SEEN_POINT \u003d (1 \u003c\u003c 1),\n\tLEJP_SEEN_POST_POINT \u003d (1 \u003c\u003c 2),\n\tLEJP_SEEN_EXP \u003d (1 \u003c\u003c 3)\n};\n\nstruct _lejp_stack {\n\tchar s; /* lejp_state stack*/\n\tchar p;\t/* path length */\n\tchar i; /* index array length */\n\tchar b; /* user bitfield */\n};\n\nstruct _lejp_parsing_stack {\n\tvoid *user;\t/* private to the stack level */\n\tsigned char (*callback)(struct lejp_ctx *ctx, char reason);\n\tconst char * const *paths;\n\tuint8_t count_paths;\n\tuint8_t ppos;\n\tuint8_t path_match;\n};\n\nstruct lejp_ctx {\n\n\t/* sorted by type for most compact alignment\n\t *\n\t * pointers\n\t */\n\tvoid *user;\n\n\t/* arrays */\n\n\tstruct _lejp_parsing_stack pst[LEJP_MAX_PARSING_STACK_DEPTH];\n\tstruct _lejp_stack st[LEJP_MAX_DEPTH];\n\tuint16_t i[LEJP_MAX_INDEX_DEPTH]; /* index array */\n\tuint16_t wild[LEJP_MAX_INDEX_DEPTH]; /* index array */\n\tchar path[LEJP_MAX_PATH];\n\tchar buf[LEJP_STRING_CHUNK + 1];\n\n\t/* size_t */\n\n\tsize_t path_stride; /* 0 means default ptr size, else stride */\n\n\t/* int */\n\n\tuint32_t line;\n\n\t/* short */\n\n\tuint16_t uni;\n\n\t/* char */\n\n\tuint8_t npos;\n\tuint8_t dcount;\n\tuint8_t f;\n\tuint8_t sp; /* stack head */\n\tuint8_t ipos; /* index stack depth */\n\tuint8_t count_paths;\n\tuint8_t path_match;\n\tuint8_t path_match_len;\n\tuint8_t wildcount;\n\tuint8_t pst_sp; /* parsing stack head */\n\tuint8_t outer_array;\n};\n\nLWS_VISIBLE LWS_EXTERN void\nlejp_construct(struct lejp_ctx *ctx,\n\t signed char (*callback)(struct lejp_ctx *ctx, char reason),\n\t void *user, const char * const *paths, unsigned char paths_count);\n\nLWS_VISIBLE LWS_EXTERN void\nlejp_destruct(struct lejp_ctx *ctx);\n\nLWS_VISIBLE LWS_EXTERN int\nlejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len);\n\nLWS_VISIBLE LWS_EXTERN void\nlejp_change_callback(struct lejp_ctx *ctx,\n\t\t signed char (*callback)(struct lejp_ctx *ctx, char reason));\n\n/*\n * push the current paths / paths_count and lejp_cb to a stack in the ctx, and\n * start using the new ones\n */\nLWS_VISIBLE LWS_EXTERN int\nlejp_parser_push(struct lejp_ctx *ctx, void *user, const char * const *paths,\n\t\t unsigned char paths_count, lejp_callback lejp_cb);\n\n/*\n * pop the previously used paths / paths_count and lejp_cb, and continue\n * parsing using those as before\n */\nLWS_VISIBLE LWS_EXTERN int\nlejp_parser_pop(struct lejp_ctx *ctx);\n\n/* exported for use when reevaluating a path for use with a subcontext */\nLWS_VISIBLE LWS_EXTERN void\nlejp_check_path_match(struct lejp_ctx *ctx);\n\nLWS_VISIBLE LWS_EXTERN int\nlejp_get_wildcard(struct lejp_ctx *ctx, int wildcard, char *dest, int len);\n\nLWS_VISIBLE LWS_EXTERN const char *\nlejp_error_to_string(int e);\n//@}\n","s":{"c":1618125060,"u": 474}} ],"g": 3879,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}