Code

store: Make matchers more generic and applicable to non-hosts as well.
[sysdb.git] / src / core / store-private.h
index eea43164fed967c4b4e2bdec92e426c10d56e3d0..0df3c7ba041c5eae961e116231c87605e46b0a47 100644 (file)
@@ -33,6 +33,7 @@
 #define SDB_CORE_STORE_PRIVATE_H 1
 
 #include "core/store.h"
+#include "utils/avltree.h"
 
 #include <sys/types.h>
 #include <regex.h>
 extern "C" {
 #endif
 
+/*
+ * core types
+ */
+
 struct sdb_store_obj {
        sdb_object_t super;
 
@@ -68,7 +73,7 @@ typedef struct {
 typedef struct {
        sdb_store_obj_t super;
 
-       sdb_llist_t *attributes;
+       sdb_avltree_t *attributes;
 } sdb_service_t;
 #define SVC(obj) ((sdb_service_t *)(obj))
 #define CONST_SVC(obj) ((const sdb_service_t *)(obj))
@@ -76,8 +81,8 @@ typedef struct {
 typedef struct {
        sdb_store_obj_t super;
 
-       sdb_llist_t *services;
-       sdb_llist_t *attributes;
+       sdb_avltree_t *services;
+       sdb_avltree_t *attributes;
 } sdb_host_t;
 #define HOST(obj) ((sdb_host_t *)(obj))
 #define CONST_HOST(obj) ((const sdb_host_t *)(obj))
@@ -90,8 +95,10 @@ typedef struct {
  * conditionals
  */
 
-/* compares a host using the specified conditional */
-typedef int (*cmp_cb)(sdb_host_t *, sdb_store_cond_t *);
+/* compares an object using the specified conditional and taking the specified
+ * filter into account */
+typedef int (*cmp_cb)(sdb_store_obj_t *, sdb_store_cond_t *,
+               sdb_store_matcher_t *);
 
 struct sdb_store_cond {
        sdb_object_t super;
@@ -101,7 +108,7 @@ struct sdb_store_cond {
 typedef struct {
        sdb_store_cond_t super;
        char *name;
-       sdb_data_t value;
+       sdb_store_expr_t *expr;
 } attr_cond_t;
 #define ATTR_C(obj) ((attr_cond_t *)(obj))
 
@@ -122,6 +129,7 @@ enum {
        MATCHER_EQ,
        MATCHER_GE,
        MATCHER_GT,
+       MATCHER_ISNULL,
 };
 
 #define MATCHER_SYM(t) \
@@ -135,6 +143,7 @@ enum {
                : ((t) == MATCHER_EQ) ? "=" \
                : ((t) == MATCHER_GE) ? ">=" \
                : ((t) == MATCHER_GT) ? ">" \
+               : ((t) == MATCHER_ISNULL) ? "IS NULL" \
                : "UNKNOWN")
 
 /* match the name of something */
@@ -187,6 +196,12 @@ typedef struct {
 } attr_matcher_t;
 #define ATTR_M(m) ((attr_matcher_t *)(m))
 
+typedef struct {
+       sdb_store_matcher_t super;
+       char *attr_name; /* we only support matching attributes */
+} isnull_matcher_t;
+#define ISNULL_M(m) ((isnull_matcher_t *)(m))
+
 /* match using conditionals */
 typedef struct {
        sdb_store_matcher_t super;