Code

store_lookup: Added sdb_store_inv_matcher().
[sysdb.git] / src / core / store-private.h
1 /*
2  * SysDB - src/core/store-private.h
3  * Copyright (C) 2012-2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 /*
29  * private data structures used by the store module
30  */
32 #ifndef SDB_CORE_STORE_PRIVATE_H
33 #define SDB_CORE_STORE_PRIVATE_H 1
35 #include "core/store.h"
37 #include <sys/types.h>
38 #include <regex.h>
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 struct sdb_store_base {
45         sdb_object_t super;
47         /* object type */
48         int type;
50         /* common meta information */
51         sdb_time_t last_update;
52         sdb_time_t interval; /* moving average */
53         sdb_store_base_t *parent;
54 };
55 #define STORE_BASE(obj) ((sdb_store_base_t *)(obj))
56 #define STORE_CONST_BASE(obj) ((const sdb_store_base_t *)(obj))
58 typedef struct {
59         sdb_store_base_t super;
61         sdb_data_t value;
62 } sdb_attribute_t;
63 #define SDB_ATTR(obj) ((sdb_attribute_t *)(obj))
64 #define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
66 typedef struct {
67         sdb_store_base_t super;
69         sdb_llist_t *children;
70         sdb_llist_t *attributes;
71 } sdb_store_obj_t;
72 #define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
73 #define SDB_CONST_STORE_OBJ(obj) ((const sdb_store_obj_t *)(obj))
75 enum {
76         SDB_HOST = 1,
77         SDB_SERVICE,
78         SDB_ATTRIBUTE,
79 };
80 #define TYPE_TO_NAME(t) \
81         (((t) == SDB_HOST) ? "host" \
82                 : ((t) == SDB_SERVICE) ? "service" \
83                 : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown")
85 /* shortcuts for accessing the sdb_store_obj_t attributes
86  * of inheriting objects */
87 #define _last_update super.last_update
88 #define _interval super.interval
90 /*
91  * matchers
92  */
94 /* when adding to this, also update 'matchers' in store_lookup.c */
95 enum {
96         MATCHER_OR,
97         MATCHER_AND,
98         MATCHER_NOT,
99         MATCHER_ATTR,
100         MATCHER_SERVICE,
101         MATCHER_HOST,
102 };
104 /* match the name of something */
105 typedef struct {
106         char    *name;
107         regex_t *name_re;
108 } name_matcher_t;
110 /* matcher base type */
111 struct sdb_store_matcher {
112         sdb_object_t super;
113         /* type of the matcher */
114         int type;
115 };
116 #define M(m) ((sdb_store_matcher_t *)(m))
118 /* logical infix operator matcher */
119 typedef struct {
120         sdb_store_matcher_t super;
122         /* left and right hand operands */
123         sdb_store_matcher_t *left;
124         sdb_store_matcher_t *right;
125 } op_matcher_t;
126 #define OP_M(m) ((op_matcher_t *)(m))
128 /* logical unary operator matcher */
129 typedef struct {
130         sdb_store_matcher_t super;
132         /* operand */
133         sdb_store_matcher_t *op;
134 } uop_matcher_t;
135 #define UOP_M(m) ((uop_matcher_t *)(m))
137 /* match any type of object by it's base information */
138 typedef struct {
139         sdb_store_matcher_t super;
141         /* match by the name of the object */
142         name_matcher_t name;
143 } obj_matcher_t;
144 #define OBJ_M(m) ((obj_matcher_t *)(m))
146 /* match attributes */
147 typedef struct {
148         obj_matcher_t super;
149         /* XXX: this needs to be more flexible;
150          *      add support for type-specific operators */
151         name_matcher_t value;
152 } attr_matcher_t;
153 #define ATTR_M(m) ((attr_matcher_t *)(m))
155 /* match services */
156 typedef struct {
157         obj_matcher_t super;
158         /* match by attributes assigned to the service */
159         attr_matcher_t *attr;
160 } service_matcher_t;
161 #define SERVICE_M(m) ((service_matcher_t *)(m))
163 /* match hosts */
164 typedef struct {
165         obj_matcher_t super;
166         /* match by services assigned to the host */
167         service_matcher_t *service;
168         /* match by attributes assigned to the host */
169         attr_matcher_t *attr;
170 } host_matcher_t;
171 #define HOST_M(m) ((host_matcher_t *)(m))
173 #ifdef __cplusplus
174 } /* extern "C" */
175 #endif
177 #endif /* ! SDB_CORE_STORE_H */
179 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */