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_obj {
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_obj_t *parent;
54 };
55 #define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
56 #define STORE_CONST_OBJ(obj) ((const sdb_store_obj_t *)(obj))
58 typedef struct {
59 sdb_store_obj_t super;
61 sdb_data_t value;
62 } sdb_attribute_t;
63 #define ATTR(obj) ((sdb_attribute_t *)(obj))
64 #define CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
66 typedef struct {
67 sdb_store_obj_t super;
69 sdb_llist_t *attributes;
70 } sdb_service_t;
71 #define SVC(obj) ((sdb_service_t *)(obj))
72 #define CONST_SVC(obj) ((const sdb_service_t *)(obj))
74 typedef struct {
75 sdb_store_obj_t super;
77 sdb_llist_t *services;
78 sdb_llist_t *attributes;
79 } sdb_host_t;
80 #define HOST(obj) ((sdb_host_t *)(obj))
81 #define CONST_HOST(obj) ((const sdb_host_t *)(obj))
83 /* shortcuts for accessing service/host attributes */
84 #define _last_update super.last_update
85 #define _interval super.interval
87 /*
88 * conditionals
89 */
91 /* compares a host using the specified conditional */
92 typedef int (*cmp_cb)(sdb_host_t *, sdb_store_cond_t *);
94 struct sdb_store_cond {
95 sdb_object_t super;
96 cmp_cb cmp;
97 };
99 typedef struct {
100 sdb_store_cond_t super;
101 char *name;
102 sdb_data_t value;
103 } attr_cond_t;
104 #define ATTR_C(obj) ((attr_cond_t *)(obj))
106 /*
107 * matchers
108 */
110 /* when adding to this, also update 'matchers' and 'matchers_tostring'
111 * in store_lookup.c */
112 enum {
113 MATCHER_OR,
114 MATCHER_AND,
115 MATCHER_NOT,
116 MATCHER_NAME,
117 MATCHER_ATTR,
118 MATCHER_LT,
119 MATCHER_LE,
120 MATCHER_EQ,
121 MATCHER_GE,
122 MATCHER_GT,
123 };
125 #define MATCHER_SYM(t) \
126 (((t) == MATCHER_OR) ? "OR" \
127 : ((t) == MATCHER_AND) ? "AND" \
128 : ((t) == MATCHER_NOT) ? "NOT" \
129 : ((t) == MATCHER_NAME) ? "NAME" \
130 : ((t) == MATCHER_ATTR) ? "ATTR" \
131 : ((t) == MATCHER_LT) ? "<" \
132 : ((t) == MATCHER_LE) ? "<=" \
133 : ((t) == MATCHER_EQ) ? "=" \
134 : ((t) == MATCHER_GE) ? ">=" \
135 : ((t) == MATCHER_GT) ? ">" \
136 : "UNKNOWN")
138 /* match the name of something */
139 typedef struct {
140 char *name;
141 regex_t *name_re;
142 } string_matcher_t;
144 /* matcher base type */
145 struct sdb_store_matcher {
146 sdb_object_t super;
147 /* type of the matcher */
148 int type;
149 };
150 #define M(m) ((sdb_store_matcher_t *)(m))
152 /* infix operator matcher */
153 typedef struct {
154 sdb_store_matcher_t super;
156 /* left and right hand operands */
157 sdb_store_matcher_t *left;
158 sdb_store_matcher_t *right;
159 } op_matcher_t;
160 #define OP_M(m) ((op_matcher_t *)(m))
162 /* unary operator matcher */
163 typedef struct {
164 sdb_store_matcher_t super;
166 /* operand */
167 sdb_store_matcher_t *op;
168 } uop_matcher_t;
169 #define UOP_M(m) ((uop_matcher_t *)(m))
171 /* match any type of object by it's name */
172 typedef struct {
173 sdb_store_matcher_t super;
175 int obj_type;
176 string_matcher_t name;
177 } name_matcher_t;
178 #define NAME_M(m) ((name_matcher_t *)(m))
180 /* match attributes */
181 typedef struct {
182 sdb_store_matcher_t super;
183 char *name;
184 string_matcher_t value;
185 } attr_matcher_t;
186 #define ATTR_M(m) ((attr_matcher_t *)(m))
188 /* match using conditionals */
189 typedef struct {
190 sdb_store_matcher_t super;
191 sdb_store_cond_t *cond;
192 } cond_matcher_t;
193 #define COND_M(m) ((cond_matcher_t *)(m))
195 #ifdef __cplusplus
196 } /* extern "C" */
197 #endif
199 #endif /* ! SDB_CORE_STORE_H */
201 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */