Code

store: Added a generic JSON formatter.
[sysdb.git] / src / core / store_lookup.c
index 11d85fea0a5ead05b42f6fffd089b6b135b0bcb9..94459cb097b1e21526f9c54f65d1cf3cd433c1ca 100644 (file)
 
 #include <limits.h>
 
-/*
- * private data types
- */
-
-typedef struct {
-       sdb_store_matcher_t *m;
-       sdb_store_matcher_t *filter;
-       sdb_store_lookup_cb  cb;
-       void *user_data;
-} scan_iter_data_t;
-
-/*
- * private helper functions
- */
-
-static int
-scan_iter(sdb_store_obj_t *obj, void *user_data)
-{
-       scan_iter_data_t *d = user_data;
-
-       if (sdb_store_matcher_matches(d->m, obj, d->filter))
-               return d->cb(obj, d->user_data);
-       return 0;
-} /* scan_iter */
-
 /*
  * matcher implementations
  */
@@ -114,9 +89,9 @@ match_iter(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
 {
        sdb_avltree_iter_t *iter = NULL;
        int status;
-       int all = 0;
+       int all = (int)(m->type == MATCHER_ALL);
 
-       assert(m->type == MATCHER_ANY);
+       assert((m->type == MATCHER_ANY) || (m->type == MATCHER_ALL));
 
        /* TODO: support all object types */
        if (obj->type != SDB_HOST)
@@ -361,6 +336,7 @@ matchers[] = {
        match_logical,
        match_unary,
        match_iter,
+       match_iter,
        match_lt,
        match_le,
        match_eq,
@@ -529,7 +505,17 @@ sdb_store_any_matcher(int type, sdb_store_matcher_t *m)
                return NULL;
        return M(sdb_object_create("any-matcher", iter_type,
                                MATCHER_ANY, type, m));
-} /* sdb_store_iter_matcher */
+} /* sdb_store_any_matcher */
+
+sdb_store_matcher_t *
+sdb_store_all_matcher(int type, sdb_store_matcher_t *m)
+{
+       if ((type != SDB_SERVICE) && (type != SDB_METRIC)
+                       && (type != SDB_ATTRIBUTE))
+               return NULL;
+       return M(sdb_object_create("all-matcher", iter_type,
+                               MATCHER_ALL, type, m));
+} /* sdb_store_all_matcher */
 
 sdb_store_matcher_t *
 sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
@@ -726,16 +712,5 @@ sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
        return matchers[m->type](m, obj, filter);
 } /* sdb_store_matcher_matches */
 
-int
-sdb_store_scan(sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
-               sdb_store_lookup_cb cb, void *user_data)
-{
-       scan_iter_data_t data = { m, filter, cb, user_data };
-
-       if (! cb)
-               return -1;
-       return sdb_store_iterate(scan_iter, &data);
-} /* sdb_store_scan */
-
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */