Check response contains a specific key (in nested JSON) */
| 1066 | |
| 1067 | /* Check response contains a specific key (in nested JSON) */ |
| 1068 | static int resp_has_key(const char *resp, const char *key) { |
| 1069 | if (!resp) |
| 1070 | return 0; |
| 1071 | char pattern[64]; |
| 1072 | snprintf(pattern, sizeof(pattern), "\"%s\"", key); |
| 1073 | if (strstr(resp, pattern) != NULL) |
| 1074 | return 1; |
| 1075 | snprintf(pattern, sizeof(pattern), "\\\"%s\\\"", key); |
| 1076 | if (strstr(resp, pattern) != NULL) |
| 1077 | return 1; |
| 1078 | /* TOON scalar form (`key: value`), the search_graph default output. */ |
| 1079 | snprintf(pattern, sizeof(pattern), "%s: ", key); |
| 1080 | if (strstr(resp, pattern) != NULL) |
| 1081 | return 1; |
| 1082 | /* TOON table-header form (`key[N]{...}:`), used by trace_path. */ |
| 1083 | snprintf(pattern, sizeof(pattern), "%s[", key); |
| 1084 | return strstr(resp, pattern) != NULL; |
| 1085 | } |
| 1086 | |
| 1087 | /* Check response does NOT contain a specific key */ |
| 1088 | static int resp_lacks_key(const char *resp, const char *key) { |
no outgoing calls
no test coverage detected