Check response contains a specific key (in nested JSON) */
| 977 | |
| 978 | /* Check response contains a specific key (in nested JSON) */ |
| 979 | static int resp_has_key(const char *resp, const char *key) { |
| 980 | if (!resp) |
| 981 | return 0; |
| 982 | char pattern[64]; |
| 983 | snprintf(pattern, sizeof(pattern), "\"%s\"", key); |
| 984 | if (strstr(resp, pattern) != NULL) |
| 985 | return 1; |
| 986 | snprintf(pattern, sizeof(pattern), "\\\"%s\\\"", key); |
| 987 | if (strstr(resp, pattern) != NULL) |
| 988 | return 1; |
| 989 | /* TOON scalar form (`key: value`), the search_graph default output. */ |
| 990 | snprintf(pattern, sizeof(pattern), "%s: ", key); |
| 991 | if (strstr(resp, pattern) != NULL) |
| 992 | return 1; |
| 993 | /* TOON table-header form (`key[N]{...}:`), used by trace_path. */ |
| 994 | snprintf(pattern, sizeof(pattern), "%s[", key); |
| 995 | return strstr(resp, pattern) != NULL; |
| 996 | } |
| 997 | |
| 998 | /* Check response does NOT contain a specific key */ |
| 999 | static int resp_lacks_key(const char *resp, const char *key) { |
no outgoing calls
no test coverage detected