Lines Matching refs:ctx
69 lejp_construct(struct lejp_ctx *ctx, in lejp_construct() argument
70 signed char (*callback)(struct lejp_ctx *ctx, char reason), void *user, in lejp_construct() argument
73 ctx->st[0].s = 0; in lejp_construct()
74 ctx->st[0].p = 0; in lejp_construct()
75 ctx->st[0].i = 0; in lejp_construct()
76 ctx->st[0].b = 0; in lejp_construct()
77 ctx->sp = 0; in lejp_construct()
78 ctx->ipos = 0; in lejp_construct()
79 ctx->outer_array = 0; in lejp_construct()
80 ctx->path_match = 0; in lejp_construct()
81 ctx->path_stride = 0; in lejp_construct()
82 ctx->path[0] = '\0'; in lejp_construct()
83 ctx->user = user; in lejp_construct()
84 ctx->line = 1; in lejp_construct()
86 ctx->pst_sp = 0; in lejp_construct()
87 ctx->pst[0].callback = callback; in lejp_construct()
88 ctx->pst[0].paths = paths; in lejp_construct()
89 ctx->pst[0].count_paths = count_paths; in lejp_construct()
90 ctx->pst[0].user = NULL; in lejp_construct()
91 ctx->pst[0].ppos = 0; in lejp_construct()
93 ctx->pst[0].callback(ctx, LEJPCB_CONSTRUCTED); in lejp_construct()
107 lejp_destruct(struct lejp_ctx *ctx) in lejp_destruct() argument
110 if (ctx && ctx->pst[0].callback) in lejp_destruct()
111 ctx->pst[0].callback(ctx, LEJPCB_DESTRUCTED); in lejp_destruct()
137 lejp_change_callback(struct lejp_ctx *ctx, in lejp_change_callback() argument
138 signed char (*callback)(struct lejp_ctx *ctx, char reason)) in lejp_change_callback() argument
140 ctx->pst[0].callback(ctx, LEJPCB_DESTRUCTED); in lejp_change_callback()
141 ctx->pst[0].callback = callback; in lejp_change_callback()
142 ctx->pst[0].callback(ctx, LEJPCB_CONSTRUCTED); in lejp_change_callback()
143 ctx->pst[0].callback(ctx, LEJPCB_START); in lejp_change_callback()
147 lejp_check_path_match(struct lejp_ctx *ctx) in lejp_check_path_match() argument
153 if (ctx->path_stride) in lejp_check_path_match()
154 s = ctx->path_stride; in lejp_check_path_match()
157 for (n = 0; !ctx->path_match && in lejp_check_path_match()
158 n < ctx->pst[ctx->pst_sp].count_paths; n++) { in lejp_check_path_match()
159 ctx->wildcount = 0; in lejp_check_path_match()
160 p = ctx->path; in lejp_check_path_match()
162 q = *((char **)(((char *)ctx->pst[ctx->pst_sp].paths) + ((unsigned int)n * s))); in lejp_check_path_match()
172 ctx->wild[ctx->wildcount++] = (uint16_t)lws_ptr_diff_size_t(p, ctx->path); in lejp_check_path_match()
188 ctx->path_match = (uint8_t)(n + 1); in lejp_check_path_match()
189 ctx->path_match_len = ctx->pst[ctx->pst_sp].ppos; in lejp_check_path_match()
193 if (!ctx->path_match) in lejp_check_path_match()
194 ctx->wildcount = 0; in lejp_check_path_match()
198 lejp_get_wildcard(struct lejp_ctx *ctx, int wildcard, char *dest, int len) in lejp_get_wildcard() argument
202 if (wildcard >= ctx->wildcount || !len) in lejp_get_wildcard()
205 n = ctx->wild[wildcard]; in lejp_get_wildcard()
207 while (--len && n < ctx->pst[ctx->pst_sp].ppos && in lejp_get_wildcard()
208 (n == ctx->wild[wildcard] || ctx->path[n] != '.')) in lejp_get_wildcard()
209 *dest++ = ctx->path[n++]; in lejp_get_wildcard()
214 return n - ctx->wild[wildcard]; in lejp_get_wildcard()
238 lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) in lejp_parse() argument
243 if (!ctx->sp && !ctx->pst[ctx->pst_sp].ppos) in lejp_parse()
244 ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_START); in lejp_parse()
248 s = (unsigned char)ctx->st[ctx->sp].s; in lejp_parse()
253 ctx->line++; in lejp_parse()
254 ctx->st[ctx->sp].s &= (char)~LEJP_FLAG_WS_COMMENTLINE; in lejp_parse()
258 ctx->st[ctx->sp].s |= in lejp_parse()
264 if (ctx->st[ctx->sp].s & LEJP_FLAG_WS_COMMENTLINE) in lejp_parse()
269 if (!ctx->sp && c == '[') { in lejp_parse()
271 ctx->outer_array = 1; in lejp_parse()
272 ctx->st[ctx->sp].s = LEJP_MP_ARRAY_END; in lejp_parse()
274 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '['; in lejp_parse()
275 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = ']'; in lejp_parse()
276 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
277 if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_START)) in lejp_parse()
279 ctx->i[ctx->ipos++] = 0; in lejp_parse()
280 if (ctx->ipos > LWS_ARRAY_SIZE(ctx->i)) { in lejp_parse()
290 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
293 ctx->st[ctx->sp].s = LEJP_MEMBERS; in lejp_parse()
297 if (ctx->sp >= 1) in lejp_parse()
300 ctx->st[ctx->sp].s = LEJP_IDLE; in lejp_parse()
304 ctx->st[ctx->sp].s = LEJP_M_P; in lejp_parse()
312 ctx->st[ctx->sp].s = LEJP_MP_DELIM; in lejp_parse()
318 if (!ctx->sp) { /* JSON can't end on quote */ in lejp_parse()
322 if (ctx->st[ctx->sp - 1].s != LEJP_MP_DELIM) { in lejp_parse()
323 ctx->buf[ctx->npos] = '\0'; in lejp_parse()
324 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
329 ctx->sp--; in lejp_parse()
333 ctx->st[ctx->sp].s = LEJP_MP_STRING_ESC; in lejp_parse()
344 ctx->st[ctx->sp].s = LEJP_MP_STRING_ESC_U1; in lejp_parse()
345 ctx->uni = 0; in lejp_parse()
353 ctx->st[ctx->sp].s = LEJP_MP_STRING; in lejp_parse()
364 ctx->uni = (uint16_t)(ctx->uni << 4); in lejp_parse()
366 ctx->uni |= (uint16_t)(c - '0'); in lejp_parse()
369 ctx->uni |= (uint16_t)(c - 'a' + 10); in lejp_parse()
372 ctx->uni |= (uint16_t)(c - 'A' + 10); in lejp_parse()
377 ctx->st[ctx->sp].s++; in lejp_parse()
380 if (ctx->uni < 0x08) in lejp_parse()
386 c = (unsigned char)(0xe0 | ((ctx->uni >> 4) & 0xf)); in lejp_parse()
390 if (ctx->uni >= 0x080) { in lejp_parse()
396 c = (unsigned char)(0x80 | ((ctx->uni >> 2) & 0x3f)); in lejp_parse()
399 if (ctx->uni < 0x008) in lejp_parse()
405 c = (unsigned char)(0xc0 | (ctx->uni >> 2)); in lejp_parse()
409 if (ctx->uni >= 0x0080) in lejp_parse()
411 c = (unsigned char)(0x80 | (ctx->uni & 0x3f)); in lejp_parse()
414 c = (unsigned char)ctx->uni; in lejp_parse()
416 ctx->st[ctx->sp].s = LEJP_MP_STRING; in lejp_parse()
428 ctx->st[ctx->sp].s = LEJP_MP_VALUE; in lejp_parse()
429 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
431 lejp_check_path_match(ctx); in lejp_parse()
432 if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_PAIR_NAME)) in lejp_parse()
438 ctx->npos = 0; in lejp_parse()
439 ctx->dcount = 0; in lejp_parse()
440 ctx->f = 0; in lejp_parse()
441 ctx->st[ctx->sp].s = LEJP_MP_VALUE_NUM_INT; in lejp_parse()
447 ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; in lejp_parse()
449 ctx->npos = 0; in lejp_parse()
450 ctx->buf[0] = '\0'; in lejp_parse()
451 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
458 ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; in lejp_parse()
460 lejp_check_path_match(ctx); in lejp_parse()
461 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
464 ctx->path_match = 0; in lejp_parse()
469 ctx->st[ctx->sp].s = LEJP_MP_ARRAY_END; in lejp_parse()
471 if (ctx->pst[ctx->pst_sp].ppos + 3u >= in lejp_parse()
472 sizeof(ctx->path)) in lejp_parse()
474 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '['; in lejp_parse()
475 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = ']'; in lejp_parse()
476 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
477 if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_START)) in lejp_parse()
479 ctx->i[ctx->ipos++] = 0; in lejp_parse()
480 if (ctx->ipos > LWS_ARRAY_SIZE(ctx->i)) { in lejp_parse()
488 if (!ctx->sp) { /* JSON can't end on ] */ in lejp_parse()
492 ctx->sp--; in lejp_parse()
493 if (ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END) { in lejp_parse()
498 if (ctx->sp) { in lejp_parse()
499 ctx->pst[ctx->pst_sp].ppos = (unsigned char) in lejp_parse()
500 ctx->st[ctx->sp - 1].p; in lejp_parse()
501 ctx->ipos = (unsigned char)ctx->st[ctx->sp - 1].i; in lejp_parse()
503 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
504 if (ctx->path_match && in lejp_parse()
505 ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) in lejp_parse()
510 ctx->path_match = 0; in lejp_parse()
511 if (ctx->outer_array && !ctx->sp) { /* ended on ] */ in lejp_parse()
518 ctx->uni = 0; in lejp_parse()
519 ctx->st[ctx->sp].s = LEJP_MP_VALUE_TOK; in lejp_parse()
523 ctx->uni = 4; in lejp_parse()
524 ctx->st[ctx->sp].s = LEJP_MP_VALUE_TOK; in lejp_parse()
528 ctx->uni = 4 + 5; in lejp_parse()
529 ctx->st[ctx->sp].s = LEJP_MP_VALUE_TOK; in lejp_parse()
538 if (!ctx->npos && c == '-') { in lejp_parse()
539 ctx->f |= LEJP_SEEN_MINUS; in lejp_parse()
543 if (ctx->dcount < 20 && c >= '0' && c <= '9') { in lejp_parse()
544 if (ctx->f & LEJP_SEEN_POINT) in lejp_parse()
545 ctx->f |= LEJP_SEEN_POST_POINT; in lejp_parse()
546 ctx->dcount++; in lejp_parse()
550 if (!ctx->dcount || (ctx->f & LEJP_SEEN_POINT)) { in lejp_parse()
554 ctx->f |= LEJP_SEEN_POINT; in lejp_parse()
561 if ((ctx->f & in lejp_parse()
568 if (ctx->f & LEJP_SEEN_EXP) { in lejp_parse()
572 ctx->f |= LEJP_SEEN_EXP; in lejp_parse()
573 ctx->st[ctx->sp].s = LEJP_MP_VALUE_NUM_EXP; in lejp_parse()
577 if (!ctx->dcount) { in lejp_parse()
582 ctx->buf[ctx->npos] = '\0'; in lejp_parse()
583 if (ctx->f & LEJP_SEEN_POINT) { in lejp_parse()
584 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
588 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
594 ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; in lejp_parse()
598 ctx->st[ctx->sp].s = LEJP_MP_VALUE_NUM_INT; in lejp_parse()
607 if (c != tokens[ctx->uni]) { in lejp_parse()
611 ctx->uni++; in lejp_parse()
612 if (tokens[ctx->uni] != ' ') in lejp_parse()
614 switch (ctx->uni) { in lejp_parse()
616 ctx->buf[0] = '1'; in lejp_parse()
617 ctx->buf[1] = '\0'; in lejp_parse()
618 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
623 ctx->buf[0] = '0'; in lejp_parse()
624 ctx->buf[1] = '\0'; in lejp_parse()
625 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
630 ctx->buf[0] = '\0'; in lejp_parse()
631 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
636 ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; in lejp_parse()
640 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
643 ctx->st[ctx->sp].s = LEJP_M_P; in lejp_parse()
644 if (!ctx->sp) { in lejp_parse()
645 ctx->pst[ctx->pst_sp].ppos = 0; in lejp_parse()
650 ctx->path_match = 0; in lejp_parse()
653 ctx->pst[ctx->pst_sp].ppos = (unsigned char)ctx->st[ctx->sp - 1].p; in lejp_parse()
654 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
655 if (ctx->path_match && in lejp_parse()
656 ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) in lejp_parse()
661 ctx->path_match = 0; in lejp_parse()
663 if (ctx->st[ctx->sp - 1].s != LEJP_MP_ARRAY_END) in lejp_parse()
666 if (ctx->ipos) in lejp_parse()
667 ctx->i[ctx->ipos - 1]++; in lejp_parse()
668 ctx->st[ctx->sp].s = LEJP_MP_VALUE; in lejp_parse()
672 if (!ctx->sp) { in lejp_parse()
677 ctx->sp--; in lejp_parse()
678 if (ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END) { in lejp_parse()
684 if (ctx->sp) { in lejp_parse()
685 ctx->pst[ctx->pst_sp].ppos = (unsigned char) in lejp_parse()
686 ctx->st[ctx->sp - 1].p; in lejp_parse()
687 ctx->ipos = (unsigned char)ctx->st[ctx->sp - 1].i; in lejp_parse()
689 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
690 if (ctx->path_match && in lejp_parse()
691 ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) in lejp_parse()
696 ctx->path_match = 0; in lejp_parse()
698 if (ctx->outer_array && !ctx->sp) { /* ended on ] */ in lejp_parse()
710 if (!ctx->sp) { in lejp_parse()
713 lejp_check_path_match(ctx); in lejp_parse()
714 if (ctx->pst[ctx->pst_sp].callback(ctx, (char)n) || in lejp_parse()
715 ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
725 ctx->sp--; in lejp_parse()
726 if (ctx->sp) { in lejp_parse()
727 ctx->pst[ctx->pst_sp].ppos = (unsigned char)ctx->st[ctx->sp].p; in lejp_parse()
728 ctx->ipos = (unsigned char)ctx->st[ctx->sp].i; in lejp_parse()
730 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
731 if (ctx->path_match && in lejp_parse()
732 ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) in lejp_parse()
737 ctx->path_match = 0; in lejp_parse()
739 lejp_check_path_match(ctx); in lejp_parse()
740 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
747 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
750 if (ctx->ipos) in lejp_parse()
751 ctx->i[ctx->ipos - 1]++; in lejp_parse()
752 ctx->st[ctx->sp].s = LEJP_MP_VALUE; in lejp_parse()
753 if (ctx->sp) in lejp_parse()
754 ctx->pst[ctx->pst_sp].ppos = (unsigned char) in lejp_parse()
755 ctx->st[ctx->sp - 1].p; in lejp_parse()
756 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
764 ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; in lejp_parse()
765 ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_END); in lejp_parse()
772 if (!ctx->sp || ctx->st[ctx->sp - 1].s != LEJP_MP_DELIM) { in lejp_parse()
774 ctx->buf[ctx->npos++] = (char)c; in lejp_parse()
775 if (ctx->npos == sizeof(ctx->buf) - 1) { in lejp_parse()
776 if (ctx->pst[ctx->pst_sp].callback(ctx, in lejp_parse()
779 ctx->npos = 0; in lejp_parse()
784 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = (char)c; in lejp_parse()
789 if (ctx->pst[ctx->pst_sp].ppos && in lejp_parse()
790 ctx->st[ctx->sp].s != LEJP_MP_COMMA_OR_END && in lejp_parse()
791 ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END) in lejp_parse()
792 ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '.'; in lejp_parse()
794 ctx->st[ctx->sp].p = (char)ctx->pst[ctx->pst_sp].ppos; in lejp_parse()
795 ctx->st[ctx->sp].i = (char)ctx->ipos; in lejp_parse()
796 if (++ctx->sp == LWS_ARRAY_SIZE(ctx->st)) { in lejp_parse()
800 ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; in lejp_parse()
801 ctx->st[ctx->sp].s = (char)c; in lejp_parse()
802 ctx->st[ctx->sp].b = 0; in lejp_parse()
806 if (ctx->npos >= sizeof(ctx->buf)) { in lejp_parse()
810 ctx->buf[ctx->npos++] = (char)c; in lejp_parse()
825 ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_FAILED); in lejp_parse()
830 lejp_parser_push(struct lejp_ctx *ctx, void *user, const char * const *paths,
835 if (ctx->pst_sp + 1 == LEJP_MAX_PARSING_STACK_DEPTH)
838 lejp_check_path_match(ctx);
840 ctx->pst[ctx->pst_sp].path_match = ctx->path_match;
841 ctx->pst_sp++;
843 p = &ctx->pst[ctx->pst_sp];
850 ctx->path_match = 0;
851 lejp_check_path_match(ctx);
854 ctx->pst_sp, ctx->path);
860 lejp_parser_pop(struct lejp_ctx *ctx)
862 if (!ctx->pst_sp)
865 ctx->pst_sp--;
866 lwsl_debug("%s: popped parser stack to %d\n", __func__, ctx->pst_sp);
868 ctx->path_match = 0; /* force it to check */
869 lejp_check_path_match(ctx);