1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

lejp: integrate error strings and api to core lejp

lejp-conf isn't the only user that needs to generate human-readable
JSON parsing error stacks.

Build it in with lejp and introduce an error code -> string api
This commit is contained in:
Andy Green 2019-03-12 07:54:27 +08:00
parent 4ed522eb9c
commit 6a88483f02
3 changed files with 45 additions and 28 deletions

View file

@ -263,4 +263,7 @@ lejp_check_path_match(struct lejp_ctx *ctx);
LWS_VISIBLE LWS_EXTERN int
lejp_get_wildcard(struct lejp_ctx *ctx, int wildcard, char *dest, int len);
LWS_VISIBLE LWS_EXTERN const char *
lejp_error_to_string(int e);
//@}

View file

@ -24,6 +24,33 @@
#include <string.h>
#include <stdio.h>
static const char * const parser_errs[] = {
"",
"",
"No opening '{'",
"Expected closing '}'",
"Expected '\"'",
"String underrun",
"Illegal unescaped control char",
"Illegal escape format",
"Illegal hex number",
"Expected ':'",
"Illegal value start",
"Digit required after decimal point",
"Bad number format",
"Bad exponent format",
"Unknown token",
"Too many ']'",
"Mismatched ']'",
"Expected ']'",
"JSON nesting limit exceeded",
"Nesting tracking used up",
"Number too long",
"Comma or block end expected",
"Unknown",
"Parser callback errored (see earlier error)",
};
/**
* lejp_construct - prepare a struct lejp_ctx for use
*
@ -753,3 +780,17 @@ reject:
ctx->callback(ctx, LEJPCB_FAILED);
return ret;
}
const char *
lejp_error_to_string(int e)
{
if (e > 0)
e = 0;
else
e = -e;
if (e >= (int)LWS_ARRAY_SIZE(parser_errs))
return "Unknown error";
return parser_errs[e];
}

View file

@ -188,33 +188,6 @@ enum lejp_vhost_paths {
LEJPVP_FLAG_DISABLE_NO_PROTOCOL_WS_UPGRADES,
};
static const char * const parser_errs[] = {
"",
"",
"No opening '{'",
"Expected closing '}'",
"Expected '\"'",
"String underrun",
"Illegal unescaped control char",
"Illegal escape format",
"Illegal hex number",
"Expected ':'",
"Illegal value start",
"Digit required after decimal point",
"Bad number format",
"Bad exponent format",
"Unknown token",
"Too many ']'",
"Mismatched ']'",
"Expected ']'",
"JSON nesting limit exceeded",
"Nesting tracking used up",
"Number too long",
"Comma or block end expected",
"Unknown",
"Parser callback errored (see earlier error)",
};
#define MAX_PLUGIN_DIRS 10
struct jpargs {
@ -913,7 +886,7 @@ lwsws_get_config(void *user, const char *f, const char * const *paths,
if (m < 0) {
lwsl_err("%s(%u): parsing error %d: %s\n", f, n, m,
parser_errs[-m]);
lejp_error_to_string(m));
return 2;
}