Parse an index-status body and compare each entry's "path" with the root * expected for its slot. Results go to out-params so the caller can tear * down before asserting. */
| 3902 | * expected for its slot. Results go to out-params so the caller can tear |
| 3903 | * down before asserting. */ |
| 3904 | static void th_index_status_check(const char *body, int expected_count, char expected[][4096], |
| 3905 | bool *parsed, int *count, bool *paths_whole) { |
| 3906 | *parsed = false; |
| 3907 | *count = 0; |
| 3908 | *paths_whole = false; |
| 3909 | yyjson_doc *doc = yyjson_read(body, strlen(body), 0); |
| 3910 | if (!doc) { |
| 3911 | return; |
| 3912 | } |
| 3913 | yyjson_val *arr = yyjson_doc_get_root(doc); |
| 3914 | if (yyjson_is_arr(arr)) { |
| 3915 | *parsed = true; |
| 3916 | *count = (int)yyjson_arr_size(arr); |
| 3917 | bool whole = *count == expected_count; |
| 3918 | size_t idx; |
| 3919 | size_t max_entries; |
| 3920 | yyjson_val *entry; |
| 3921 | yyjson_arr_foreach(arr, idx, max_entries, entry) { |
| 3922 | yyjson_val *slot = yyjson_obj_get(entry, "slot"); |
| 3923 | yyjson_val *path = yyjson_obj_get(entry, "path"); |
| 3924 | int s = yyjson_is_int(slot) ? yyjson_get_int(slot) : -1; |
| 3925 | whole = whole && s >= 0 && s < expected_count && yyjson_is_str(path) && |
| 3926 | strcmp(yyjson_get_str(path), expected[s]) == 0; |
| 3927 | } |
| 3928 | *paths_whole = whole; |
| 3929 | } |
| 3930 | yyjson_doc_free(doc); |
| 3931 | } |
| 3932 | |
| 3933 | /* The listing is sized for what the job table holds. Every slot takes a root |
| 3934 | * as long as the platform resolves; the body has to parse as JSON and carry |