X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcore%2Fstore-private.h;h=e501b2cd830169b2b7de01660207c976ca66f089;hb=ed569e21915fe71ead292582a8699d25234cf303;hp=22f6e07c43259671664053e3f88647f4a666c846;hpb=5e3ba235ca69e67baa9945a2c0be8a7270485656;p=sysdb.git diff --git a/src/core/store-private.h b/src/core/store-private.h index 22f6e07..e501b2c 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -66,45 +66,73 @@ typedef struct { typedef struct { sdb_store_base_t super; - sdb_llist_t *children; + sdb_llist_t *services; sdb_llist_t *attributes; } sdb_store_obj_t; #define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj)) #define SDB_CONST_STORE_OBJ(obj) ((const sdb_store_obj_t *)(obj)) -enum { - SDB_HOST = 1, - SDB_SERVICE, - SDB_ATTRIBUTE, -}; -#define TYPE_TO_NAME(t) \ - (((t) == SDB_HOST) ? "host" \ - : ((t) == SDB_SERVICE) ? "service" \ - : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown") - /* shortcuts for accessing the sdb_store_obj_t attributes * of inheriting objects */ #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 */ -/* when adding to this, also update 'matchers' in store_lookup.c */ +/* when adding to this, also update 'matchers' and 'matchers_tostring' + * in store_lookup.c */ enum { MATCHER_OR, MATCHER_AND, + MATCHER_NOT, + MATCHER_NAME, MATCHER_ATTR, - MATCHER_SERVICE, - MATCHER_HOST, + 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; regex_t *name_re; -} name_matcher_t; +} string_matcher_t; /* matcher base type */ struct sdb_store_matcher { @@ -114,7 +142,7 @@ struct sdb_store_matcher { }; #define M(m) ((sdb_store_matcher_t *)(m)) -/* logical operator matcher */ +/* infix operator matcher */ typedef struct { sdb_store_matcher_t super; @@ -124,41 +152,38 @@ typedef struct { } op_matcher_t; #define OP_M(m) ((op_matcher_t *)(m)) -/* match any type of object by it's base information */ +/* unary operator matcher */ +typedef struct { + sdb_store_matcher_t super; + + /* operand */ + sdb_store_matcher_t *op; +} uop_matcher_t; +#define UOP_M(m) ((uop_matcher_t *)(m)) + +/* match any type of object by it's name */ typedef struct { sdb_store_matcher_t super; - /* match by the name of the object */ - name_matcher_t name; -} obj_matcher_t; -#define OBJ_M(m) ((obj_matcher_t *)(m)) + int obj_type; + string_matcher_t name; +} name_matcher_t; +#define NAME_M(m) ((name_matcher_t *)(m)) /* match attributes */ typedef struct { - obj_matcher_t super; - /* XXX: this needs to be more flexible; - * add support for type-specific operators */ - name_matcher_t value; + sdb_store_matcher_t super; + char *name; + string_matcher_t value; } attr_matcher_t; #define ATTR_M(m) ((attr_matcher_t *)(m)) -/* match services */ +/* match using conditionals */ typedef struct { - obj_matcher_t super; - /* match by attributes assigned to the service */ - attr_matcher_t *attr; -} service_matcher_t; -#define SERVICE_M(m) ((service_matcher_t *)(m)) - -/* match hosts */ -typedef struct { - obj_matcher_t super; - /* match by services assigned to the host */ - service_matcher_t *service; - /* match by attributes assigned to the host */ - attr_matcher_t *attr; -} host_matcher_t; -#define HOST_M(m) ((host_matcher_t *)(m)) + 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" */