Code

store: Drop the special IS-NOT-NULL matcher.
[sysdb.git] / src / core / store-private.h
index 1633d42c5672e867bec3de21b10153b6c7931274..1342a5b58fca93508d93f00571753be9b7e3d5db 100644 (file)
@@ -103,10 +103,24 @@ typedef struct {
 #define _last_update super.last_update
 #define _interval super.interval
 
+/*
+ * querying
+ */
+
+struct sdb_store_query {
+       sdb_object_t super;
+       sdb_ast_node_t *ast;
+       sdb_store_matcher_t *matcher;
+       sdb_store_matcher_t *filter;
+};
+#define QUERY(m) ((sdb_store_query_t *)(m))
+
 /*
  * expressions
  */
+
 enum {
+       TYPED_EXPR  = -3, /* obj type stored in data.data.integer */
        ATTR_VALUE  = -2, /* attr name stored in data.data.string */
        FIELD_VALUE = -1, /* field type stored in data.data.integer */
        /*  0: const value (stored in data) */
@@ -117,94 +131,74 @@ struct sdb_store_expr {
        sdb_object_t super;
 
        int type; /* see above */
+       int data_type;
 
        sdb_store_expr_t *left;
        sdb_store_expr_t *right;
 
        sdb_data_t data;
 };
-
-/*
- * conditionals
- */
-
-/* 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;
-       cmp_cb cmp;
-};
-
-typedef struct {
-       sdb_store_cond_t super;
-       char *name;
-       sdb_store_expr_t *expr;
-} attr_cond_t;
-#define ATTR_C(obj) ((attr_cond_t *)(obj))
-
-typedef struct {
-       sdb_store_cond_t super;
-       int field;
-       sdb_store_expr_t *expr;
-} obj_cond_t;
-#define OBJ_C(obj) ((obj_cond_t *)(obj))
+#define CONST_EXPR(v) { SDB_OBJECT_INIT, 0, (v).type, NULL, NULL, (v) }
+#define EXPR_TO_STRING(e) \
+       (((e)->type == TYPED_EXPR) ? "<typed>" \
+               : ((e)->type == ATTR_VALUE) ? "attribute" \
+               : ((e)->type == FIELD_VALUE) ? SDB_FIELD_TO_NAME((e)->data.data.integer) \
+               : ((e)->type == 0) ? "<constant>" \
+               : ((e)->type > 0) ? SDB_DATA_OP_TO_STRING((e)->type) \
+               : "<unknown>")
 
 /*
  * matchers
  */
 
-/* when adding to this, also update 'MATCHER_SYM' below as well as 'matchers'
- * and 'matchers_tostring' in store_lookup.c */
+/* when adding to this, also update 'MATCHER_SYM' below and 'matchers' in
+ * store_lookup.c */
 enum {
        MATCHER_OR,
        MATCHER_AND,
        MATCHER_NOT,
-       MATCHER_NAME,
-       MATCHER_ATTR,
-       MATCHER_SERVICE,
-       MATCHER_METRIC,
-       MATCHER_ATTRIBUTE,
+       MATCHER_ANY,
+       MATCHER_ALL,
+       MATCHER_IN,
+       MATCHER_NIN,
+
+       /* unary operators */
+       MATCHER_ISNULL,
+
+       /* ary operators */
        MATCHER_LT,
        MATCHER_LE,
        MATCHER_EQ,
+       MATCHER_NE,
        MATCHER_GE,
        MATCHER_GT,
-       MATCHER_CMP_LT,
-       MATCHER_CMP_LE,
-       MATCHER_CMP_EQ,
-       MATCHER_CMP_GE,
-       MATCHER_CMP_GT,
        MATCHER_REGEX,
-       MATCHER_ISNULL,
+       MATCHER_NREGEX,
+
+       /* a generic query */
+       MATCHER_QUERY,
 };
 
 #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_SERVICE) ? "SERVICE" \
-               : ((t) == MATCHER_METRIC) ? "METRIC" \
-               : ((t) == MATCHER_ATTRIBUTE) ? "ATTRIBUTE" \
+               : ((t) == MATCHER_ANY) ? "ANY" \
+               : ((t) == MATCHER_ALL) ? "ALL" \
+               : ((t) == MATCHER_IN) ? "IN" \
+               : ((t) == MATCHER_NIN) ? "NOT IN" \
+               : ((t) == MATCHER_ISNULL) ? "IS NULL" \
                : ((t) == MATCHER_LT) ? "<" \
                : ((t) == MATCHER_LE) ? "<=" \
                : ((t) == MATCHER_EQ) ? "=" \
+               : ((t) == MATCHER_NE) ? "!=" \
                : ((t) == MATCHER_GE) ? ">=" \
                : ((t) == MATCHER_GT) ? ">" \
                : ((t) == MATCHER_REGEX) ? "=~" \
-               : ((t) == MATCHER_ISNULL) ? "IS NULL" \
+               : ((t) == MATCHER_NREGEX) ? "!~" \
+               : ((t) == MATCHER_QUERY) ? "QUERY" \
                : "UNKNOWN")
 
-/* match the name of something */
-typedef struct {
-       char    *name;
-       regex_t *name_re;
-} string_matcher_t;
-
 /* matcher base type */
 struct sdb_store_matcher {
        sdb_object_t super;
@@ -232,12 +226,13 @@ typedef struct {
 } uop_matcher_t;
 #define UOP_M(m) ((uop_matcher_t *)(m))
 
-/* child matcher */
+/* iter matcher */
 typedef struct {
        sdb_store_matcher_t super;
+       sdb_store_expr_t *iter;
        sdb_store_matcher_t *m;
-} child_matcher_t;
-#define CHILD_M(m) ((child_matcher_t *)(m))
+} iter_matcher_t;
+#define ITER_M(m) ((iter_matcher_t *)(m))
 
 /* compare operator matcher */
 typedef struct {
@@ -249,36 +244,12 @@ typedef struct {
 } cmp_matcher_t;
 #define CMP_M(m) ((cmp_matcher_t *)(m))
 
-/* match any type of object by it's name */
-typedef struct {
-       sdb_store_matcher_t super;
-
-       int obj_type;
-       string_matcher_t name;
-} name_matcher_t;
-#define NAME_M(m) ((name_matcher_t *)(m))
-
-/* match attributes */
-typedef struct {
-       sdb_store_matcher_t super;
-       char *name;
-       string_matcher_t value;
-} 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 */
+       sdb_store_expr_t *expr;
 } isnull_matcher_t;
 #define ISNULL_M(m) ((isnull_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