| 979 | } |
| 980 | |
| 981 | static int agent_json_find_entry(const char *document, size_t length, const char *section, |
| 982 | size_t *entry_start, size_t *entry_end) { |
| 983 | size_t bom = length >= 3U && (unsigned char)document[0] == 0xefU && |
| 984 | (unsigned char)document[1] == 0xbbU && (unsigned char)document[2] == 0xbfU |
| 985 | ? 3U |
| 986 | : 0U; |
| 987 | agent_json_scanner_t scanner = {.data = document, .length = length, .position = bom}; |
| 988 | if (agent_json_skip_space(&scanner) != 0) { |
| 989 | return -1; |
| 990 | } |
| 991 | size_t root_start = scanner.position; |
| 992 | if (agent_json_scan_value(&scanner, 0U) != 0 || agent_json_skip_space(&scanner) != 0 || |
| 993 | scanner.position != length || document[root_start] != '{') { |
| 994 | return -1; |
| 995 | } |
| 996 | size_t object_start = root_start; |
| 997 | size_t object_end = scanner.position; |
| 998 | if (section) { |
| 999 | size_t section_start = 0U; |
| 1000 | size_t section_end = 0U; |
| 1001 | int section_result = agent_json_find_member(document, root_start, object_end, section, |
| 1002 | §ion_start, §ion_end); |
| 1003 | if (section_result != 0) { |
| 1004 | return section_result; |
| 1005 | } |
| 1006 | if (document[section_start] != '{') { |
| 1007 | return -1; |
| 1008 | } |
| 1009 | object_start = section_start; |
| 1010 | object_end = section_end; |
| 1011 | } |
| 1012 | return agent_json_find_member(document, object_start, object_end, AGENT_ENTRY_KEY, entry_start, |
| 1013 | entry_end); |
| 1014 | } |
| 1015 | |
| 1016 | static char *agent_json_escape(const char *value) { |
| 1017 | size_t length = strlen(value); |
no test coverage detected