| 774 | static int agent_json_scan_value(agent_json_scanner_t *scanner, unsigned depth); |
| 775 | |
| 776 | static int agent_json_scan_object(agent_json_scanner_t *scanner, unsigned depth) { |
| 777 | if (depth >= AGENT_JSON_MAX_DEPTH || scanner->position >= scanner->length || |
| 778 | scanner->data[scanner->position++] != '{') { |
| 779 | return -1; |
| 780 | } |
| 781 | if (agent_json_skip_space(scanner) != 0) { |
| 782 | return -1; |
| 783 | } |
| 784 | if (scanner->position < scanner->length && scanner->data[scanner->position] == '}') { |
| 785 | scanner->position++; |
| 786 | return 0; |
| 787 | } |
| 788 | for (;;) { |
| 789 | if (scanner->position >= scanner->length) { |
| 790 | return -1; |
| 791 | } |
| 792 | if (scanner->data[scanner->position] == '"' || scanner->data[scanner->position] == '\'') { |
| 793 | if (agent_json_scan_string(scanner, NULL, NULL) != 0) { |
| 794 | return -1; |
| 795 | } |
| 796 | } else { |
| 797 | size_t start = scanner->position; |
| 798 | while (scanner->position < scanner->length && |
| 799 | (isalnum((unsigned char)scanner->data[scanner->position]) || |
| 800 | strchr("_$-", scanner->data[scanner->position]))) { |
| 801 | scanner->position++; |
| 802 | } |
| 803 | if (scanner->position == start) { |
| 804 | return -1; |
| 805 | } |
| 806 | } |
| 807 | if (agent_json_skip_space(scanner) != 0 || scanner->position >= scanner->length || |
| 808 | scanner->data[scanner->position++] != ':' || |
| 809 | agent_json_scan_value(scanner, depth + 1U) != 0 || |
| 810 | agent_json_skip_space(scanner) != 0 || scanner->position >= scanner->length) { |
| 811 | return -1; |
| 812 | } |
| 813 | char separator = scanner->data[scanner->position++]; |
| 814 | if (separator == '}') { |
| 815 | return 0; |
| 816 | } |
| 817 | if (separator != ',') { |
| 818 | return -1; |
| 819 | } |
| 820 | if (agent_json_skip_space(scanner) != 0) { |
| 821 | return -1; |
| 822 | } |
| 823 | if (scanner->position < scanner->length && scanner->data[scanner->position] == '}') { |
| 824 | scanner->position++; |
| 825 | return 0; |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | static int agent_json_scan_array(agent_json_scanner_t *scanner, unsigned depth) { |
| 831 | if (depth >= AGENT_JSON_MAX_DEPTH) { |
no test coverage detected