index a5bf0267b7e41bd598135ee28048f697ec3d93f7..0db46f84b5d6c28393d8a7d49b8e8dd453471335 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
#include "core/store.h"
+#include <sys/types.h>
+#include <regex.h>
+
#ifdef __cplusplus
extern "C" {
#endif
#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
+/*
+ * matchers
+ */
+
+/* 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,
+};
+
+/* 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;
+ /* type of the matcher */
+ int type;
+};
+#define M(m) ((sdb_store_matcher_t *)(m))
+
+/* infix operator matcher */
+typedef struct {
+ sdb_store_matcher_t super;
+
+ /* left and right hand operands */
+ sdb_store_matcher_t *left;
+ sdb_store_matcher_t *right;
+} op_matcher_t;
+#define OP_M(m) ((op_matcher_t *)(m))
+
+/* 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;
+
+ 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;
+ /* XXX: this needs to be more flexible;
+ * add support for type-specific operators */
+ string_matcher_t value;
+} attr_matcher_t;
+#define ATTR_M(m) ((attr_matcher_t *)(m))
+
#ifdef __cplusplus
} /* extern "C" */
#endif