+ const char *field = query_field_for_id(query, cond->field);
+ debug("running condition: \"%s\" %s %s\"%s\"",
+ field, condition_names[cond->condition],
+ cond->case_sensitive ? "" : "(alternative) ",
+ cond->value ? cond->value : "(none)");
+ switch (cond->condition) {
+ case MATCH_EQUAL:
+ case MATCH_DIFFER:
+ if (field == NULL) {
+ return cond->condition != MATCH_DIFFER;
+ }
+ if (cond->case_sensitive) {
+ return !!((strcmp(field, cond->value) == 0)
+ ^ (cond->condition == MATCH_DIFFER));
+ } else {
+ return !!((ascii_strcasecmp(field, cond->value) == 0)
+ ^ (cond->condition == MATCH_DIFFER));
+ }
+ break;
+
+ case MATCH_CONTAINS:
+ if (field == NULL) {
+ return false;
+ }
+ if (cond->case_sensitive) {
+ return strstr(field, cond->value);
+ } else {
+ return m_stristrn(field, cond->value, cond->value_len);
+ }
+ break;
+
+ case MATCH_CONTAINED:
+ if (field == NULL) {
+ return false;
+ }
+ if (cond->case_sensitive) {
+ return strstr(cond->value, field);
+ } else {
+ return m_stristr(cond->value, field);
+ }
+ break;
+
+ case MATCH_EMPTY:
+ return !!((field == NULL || *field == '\0') ^ (!cond->case_sensitive));
+
+ default:
+ assert(false && "invalid condition type");
+ }