mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
lejp: make sure child object close is not mistaken for parent
This commit is contained in:
parent
80135635bb
commit
0405c0c878
3 changed files with 26 additions and 9 deletions
|
@ -106,7 +106,7 @@ enum lejp_callbacks {
|
||||||
LEJPCB_ARRAY_END = 15,
|
LEJPCB_ARRAY_END = 15,
|
||||||
|
|
||||||
LEJPCB_OBJECT_START = 16,
|
LEJPCB_OBJECT_START = 16,
|
||||||
LEJPCB_OBJECT_END = 17
|
LEJPCB_OBJECT_END = 17,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -688,22 +688,28 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len)
|
||||||
/* done, return unused amount */
|
/* done, return unused amount */
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pop */
|
/* pop */
|
||||||
|
|
||||||
ctx->sp--;
|
ctx->sp--;
|
||||||
if (ctx->sp) {
|
if (ctx->sp) {
|
||||||
ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p;
|
ctx->pst[ctx->pst_sp].ppos =
|
||||||
ctx->ipos = ctx->st[ctx->sp - 1].i;
|
ctx->st[ctx->sp].p;
|
||||||
|
ctx->ipos = ctx->st[ctx->sp].i;
|
||||||
}
|
}
|
||||||
ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0';
|
ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0';
|
||||||
if (ctx->path_match &&
|
if (ctx->path_match &&
|
||||||
ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len)
|
ctx->pst[ctx->pst_sp].ppos <=
|
||||||
|
ctx->path_match_len)
|
||||||
/*
|
/*
|
||||||
* we shrank the path to be
|
* we shrank the path to be
|
||||||
* smaller than the matching point
|
* smaller than the matching point
|
||||||
*/
|
*/
|
||||||
ctx->path_match = 0;
|
ctx->path_match = 0;
|
||||||
|
|
||||||
lejp_check_path_match(ctx);
|
lejp_check_path_match(ctx);
|
||||||
if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_OBJECT_END)) {
|
if (ctx->pst[ctx->pst_sp].callback(ctx,
|
||||||
|
LEJPCB_OBJECT_END)) {
|
||||||
ret = LEJP_REJECT_CALLBACK;
|
ret = LEJP_REJECT_CALLBACK;
|
||||||
goto reject;
|
goto reject;
|
||||||
}
|
}
|
||||||
|
@ -757,7 +763,8 @@ emit_string_char:
|
||||||
|
|
||||||
add_stack_level:
|
add_stack_level:
|
||||||
/* push on to the object stack */
|
/* push on to the object stack */
|
||||||
if (ctx->pst[ctx->pst_sp].ppos && ctx->st[ctx->sp].s != LEJP_MP_COMMA_OR_END &&
|
if (ctx->pst[ctx->pst_sp].ppos &&
|
||||||
|
ctx->st[ctx->sp].s != LEJP_MP_COMMA_OR_END &&
|
||||||
ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END)
|
ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END)
|
||||||
ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '.';
|
ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '.';
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ static const char * const reason_names[] = {
|
||||||
"LEJPCB_ARRAY_END",
|
"LEJPCB_ARRAY_END",
|
||||||
"LEJPCB_OBJECT_START",
|
"LEJPCB_OBJECT_START",
|
||||||
"LEJPCB_OBJECT_END",
|
"LEJPCB_OBJECT_END",
|
||||||
|
"LEJPCB_OBJECT_END_PRE",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const tok[] = {
|
static const char * const tok[] = {
|
||||||
|
@ -52,6 +53,11 @@ static signed char
|
||||||
cb(struct lejp_ctx *ctx, char reason)
|
cb(struct lejp_ctx *ctx, char reason)
|
||||||
{
|
{
|
||||||
char buf[1024], *p = buf, *end = &buf[sizeof(buf)];
|
char buf[1024], *p = buf, *end = &buf[sizeof(buf)];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
for (n = 0; n < ctx->sp; n++)
|
||||||
|
*p++ = ' ';
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
if (reason & LEJP_FLAG_CB_IS_VALUE) {
|
if (reason & LEJP_FLAG_CB_IS_VALUE) {
|
||||||
p += lws_snprintf(p, p - end, " value '%s' ", ctx->buf);
|
p += lws_snprintf(p, p - end, " value '%s' ", ctx->buf);
|
||||||
|
@ -73,13 +79,17 @@ cb(struct lejp_ctx *ctx, char reason)
|
||||||
|
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case LEJPCB_COMPLETE:
|
case LEJPCB_COMPLETE:
|
||||||
lwsl_notice("Parsing Completed (LEJPCB_COMPLETE)\n");
|
lwsl_notice("%sParsing Completed (LEJPCB_COMPLETE)\n", buf);
|
||||||
break;
|
break;
|
||||||
case LEJPCB_PAIR_NAME:
|
case LEJPCB_PAIR_NAME:
|
||||||
lwsl_notice("path: '%s' (LEJPCB_PAIR_NAME)\n", ctx->path);
|
lwsl_notice("%spath: '%s' (LEJPCB_PAIR_NAME)\n", buf, ctx->path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lwsl_notice("%s%s: path %s match %d statckp %d\r\n", buf, reason_names[(unsigned int)
|
||||||
|
(reason) & (LEJP_FLAG_CB_IS_VALUE - 1)], ctx->path,
|
||||||
|
ctx->path_match, ctx->pst[ctx->pst_sp].ppos);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue