Check if ALL results have a specific label (validates label filter works) */
| 884 | |
| 885 | /* Check if ALL results have a specific label (validates label filter works) */ |
| 886 | static int all_results_have_label(const char *resp, const char *label) { |
| 887 | if (!resp) |
| 888 | return 0; |
| 889 | /* Every "label":"X" in results must match. Check no other label appears. */ |
| 890 | char pattern[64]; |
| 891 | snprintf(pattern, sizeof(pattern), "\"label\":\"%s\"", label); |
| 892 | char escaped[64]; |
| 893 | snprintf(escaped, sizeof(escaped), "\\\"label\\\":\\\"%s\\\"", label); |
| 894 | /* If response contains "label" at all, every one must match */ |
| 895 | const char *p = resp; |
| 896 | while ((p = strstr(p, "label")) != NULL) { |
| 897 | /* Skip the key name — find the value */ |
| 898 | p += 5; /* past "label" */ |
| 899 | const char *val = strstr(p, ":\""); |
| 900 | if (!val || val > p + 10) { |
| 901 | p++; |
| 902 | continue; |
| 903 | } |
| 904 | val += 2; |
| 905 | /* Check this label value matches */ |
| 906 | if (strncmp(val, label, strlen(label)) != 0) { |
| 907 | /* Check for escaped version */ |
| 908 | const char *eval = strstr(p, ":\\\""); |
| 909 | if (eval && eval < p + 10) { |
| 910 | eval += 3; |
| 911 | if (strncmp(eval, label, strlen(label)) != 0) |
| 912 | return 0; |
| 913 | } else { |
| 914 | return 0; |
| 915 | } |
| 916 | } |
| 917 | p++; |
| 918 | } |
| 919 | return 1; |
| 920 | } |
| 921 | |
| 922 | /* Check response contains a specific key (in nested JSON) */ |
| 923 | static int resp_has_key(const char *resp, const char *key) { |