c7d99f9b910ee2abee60b4318c198db39f8ace1e
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"
36 #include "utils/avltree.h"
38 #include <sys/types.h>
39 #include <regex.h>
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
45 struct sdb_store_obj {
46 sdb_object_t super;
48 /* object type */
49 int type;
51 /* common meta information */
52 sdb_time_t last_update;
53 sdb_time_t interval; /* moving average */
54 char **backends;
55 size_t backends_num;
56 sdb_store_obj_t *parent;
57 };
58 #define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
59 #define STORE_CONST_OBJ(obj) ((const sdb_store_obj_t *)(obj))
61 typedef struct {
62 sdb_store_obj_t super;
64 sdb_data_t value;
65 } sdb_attribute_t;
66 #define ATTR(obj) ((sdb_attribute_t *)(obj))
67 #define CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
69 typedef struct {
70 sdb_store_obj_t super;
72 sdb_avltree_t *attributes;
73 } sdb_service_t;
74 #define SVC(obj) ((sdb_service_t *)(obj))
75 #define CONST_SVC(obj) ((const sdb_service_t *)(obj))
77 typedef struct {
78 sdb_store_obj_t super;
80 sdb_avltree_t *services;
81 sdb_avltree_t *attributes;
82 } sdb_host_t;
83 #define HOST(obj) ((sdb_host_t *)(obj))
84 #define CONST_HOST(obj) ((const sdb_host_t *)(obj))
86 /* shortcuts for accessing service/host attributes */
87 #define _last_update super.last_update
88 #define _interval super.interval
90 /*
91 * conditionals
92 */
94 /* compares a host using the specified conditional */
95 typedef int (*cmp_cb)(sdb_host_t *, sdb_store_cond_t *);
97 struct sdb_store_cond {
98 sdb_object_t super;
99 cmp_cb cmp;
100 };
102 typedef struct {
103 sdb_store_cond_t super;
104 char *name;
105 sdb_data_t value;
106 } attr_cond_t;
107 #define ATTR_C(obj) ((attr_cond_t *)(obj))
109 /*
110 * matchers
111 */
113 /* when adding to this, also update 'matchers' and 'matchers_tostring'
114 * in store_lookup.c */
115 enum {
116 MATCHER_OR,
117 MATCHER_AND,
118 MATCHER_NOT,
119 MATCHER_NAME,
120 MATCHER_ATTR,
121 MATCHER_LT,
122 MATCHER_LE,
123 MATCHER_EQ,
124 MATCHER_GE,
125 MATCHER_GT,
126 };
128 #define MATCHER_SYM(t) \
129 (((t) == MATCHER_OR) ? "OR" \
130 : ((t) == MATCHER_AND) ? "AND" \
131 : ((t) == MATCHER_NOT) ? "NOT" \
132 : ((t) == MATCHER_NAME) ? "NAME" \
133 : ((t) == MATCHER_ATTR) ? "ATTR" \
134 : ((t) == MATCHER_LT) ? "<" \
135 : ((t) == MATCHER_LE) ? "<=" \
136 : ((t) == MATCHER_EQ) ? "=" \
137 : ((t) == MATCHER_GE) ? ">=" \
138 : ((t) == MATCHER_GT) ? ">" \
139 : "UNKNOWN")
141 /* match the name of something */
142 typedef struct {
143 char *name;
144 regex_t *name_re;
145 } string_matcher_t;
147 /* matcher base type */
148 struct sdb_store_matcher {
149 sdb_object_t super;
150 /* type of the matcher */
151 int type;
152 };
153 #define M(m) ((sdb_store_matcher_t *)(m))
155 /* infix operator matcher */
156 typedef struct {
157 sdb_store_matcher_t super;
159 /* left and right hand operands */
160 sdb_store_matcher_t *left;
161 sdb_store_matcher_t *right;
162 } op_matcher_t;
163 #define OP_M(m) ((op_matcher_t *)(m))
165 /* unary operator matcher */
166 typedef struct {
167 sdb_store_matcher_t super;
169 /* operand */
170 sdb_store_matcher_t *op;
171 } uop_matcher_t;
172 #define UOP_M(m) ((uop_matcher_t *)(m))
174 /* match any type of object by it's name */
175 typedef struct {
176 sdb_store_matcher_t super;
178 int obj_type;
179 string_matcher_t name;
180 } name_matcher_t;
181 #define NAME_M(m) ((name_matcher_t *)(m))
183 /* match attributes */
184 typedef struct {
185 sdb_store_matcher_t super;
186 char *name;
187 string_matcher_t value;
188 } attr_matcher_t;
189 #define ATTR_M(m) ((attr_matcher_t *)(m))
191 /* match using conditionals */
192 typedef struct {
193 sdb_store_matcher_t super;
194 sdb_store_cond_t *cond;
195 } cond_matcher_t;
196 #define COND_M(m) ((cond_matcher_t *)(m))
198 #ifdef __cplusplus
199 } /* extern "C" */
200 #endif
202 #endif /* ! SDB_CORE_STORE_H */
204 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */