Code

store_lookup: Introduce conditional based attribute matchers.
[sysdb.git] / src / core / store-private.h
index 0db46f84b5d6c28393d8a7d49b8e8dd453471335..49ddaf547465f349b8ba57aede974e0388628652 100644 (file)
@@ -77,6 +77,25 @@ typedef struct {
 #define _last_update super.last_update
 #define _interval super.interval
 
+/*
+ * conditionals
+ */
+
+/* compares a store object using the specified conditional */
+typedef int (*cmp_cb)(sdb_store_base_t *, sdb_store_cond_t *);
+
+struct sdb_store_cond {
+       sdb_object_t super;
+       cmp_cb cmp;
+};
+
+typedef struct {
+       sdb_store_cond_t super;
+       char *name;
+       sdb_data_t value;
+} attr_cond_t;
+#define ATTR_C(obj) ((attr_cond_t *)(obj))
+
 /*
  * matchers
  */
@@ -89,8 +108,26 @@ enum {
        MATCHER_NOT,
        MATCHER_NAME,
        MATCHER_ATTR,
+       MATCHER_LT,
+       MATCHER_LE,
+       MATCHER_EQ,
+       MATCHER_GE,
+       MATCHER_GT,
 };
 
+#define MATCHER_SYM(t) \
+       (((t) == MATCHER_OR) ? "OR" \
+               : ((t) == MATCHER_AND) ? "AND" \
+               : ((t) == MATCHER_NOT) ? "NOT" \
+               : ((t) == MATCHER_NAME) ? "NAME" \
+               : ((t) == MATCHER_ATTR) ? "ATTR" \
+               : ((t) == MATCHER_LT) ? "<" \
+               : ((t) == MATCHER_LE) ? "<=" \
+               : ((t) == MATCHER_EQ) ? "=" \
+               : ((t) == MATCHER_GE) ? ">=" \
+               : ((t) == MATCHER_GT) ? ">" \
+               : "UNKNOWN")
+
 /* match the name of something */
 typedef struct {
        char    *name;
@@ -143,6 +180,13 @@ typedef struct {
 } attr_matcher_t;
 #define ATTR_M(m) ((attr_matcher_t *)(m))
 
+/* match using conditionals */
+typedef struct {
+       sdb_store_matcher_t super;
+       sdb_store_cond_t *cond;
+} cond_matcher_t;
+#define COND_M(m) ((cond_matcher_t *)(m))
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif