-// Needs to be extended with criteria
-// Cycles through databases, calling a handler function on each.
-int grep_databases(void *context, void (*fun)(void *context, struct database *db))
+// This will be generalized at some point
+static int match_criterion(struct database *db, struct database_criterion *c)
+{
+ if (!strcmp(c->name, "id"))
+ {
+ struct database_criterion_value *v;
+ for (v = c->values; v; v = v->next)
+ if (!strcmp(v->value, db->url))
+ return 1;
+ return 0;
+ }
+ else
+ return 0;
+}
+
+int database_match_criteria(struct database *db, struct database_criterion *cl)
+{
+ for (; cl; cl = cl->next)
+ if (!match_criterion(db, cl))
+ break;
+ if (cl) // one of the criteria failed to match -- skip this db
+ return 0;
+ else
+ return 1;
+}
+
+// Cycles through databases, calling a handler function on the ones for
+// which all criteria matched.
+int grep_databases(void *context, struct database_criterion *cl,
+ void (*fun)(void *context, struct database *db))