Code

store: Moved matcher types to store-private.h.
[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_ATTR,
99         MATCHER_SERVICE,
100         MATCHER_HOST,
101 };
103 /* match the name of something */
104 typedef struct {
105         char    *name;
106         regex_t *name_re;
107 } name_matcher_t;
109 /* matcher base type */
110 struct sdb_store_matcher {
111         sdb_object_t super;
112         /* type of the matcher */
113         int type;
114 };
115 #define M(m) ((sdb_store_matcher_t *)(m))
117 /* logical operator matcher */
118 typedef struct {
119         sdb_store_matcher_t super;
121         /* left and right hand operands */
122         sdb_store_matcher_t *left;
123         sdb_store_matcher_t *right;
124 } op_matcher_t;
125 #define OP_M(m) ((op_matcher_t *)(m))
127 /* match any type of object by it's base information */
128 typedef struct {
129         sdb_store_matcher_t super;
131         /* match by the name of the object */
132         name_matcher_t name;
133 } obj_matcher_t;
134 #define OBJ_M(m) ((obj_matcher_t *)(m))
136 /* match attributes */
137 typedef struct {
138         obj_matcher_t super;
139         /* XXX: this needs to be more flexible;
140          *      add support for type-specific operators */
141         name_matcher_t value;
142 } attr_matcher_t;
143 #define ATTR_M(m) ((attr_matcher_t *)(m))
145 /* match services */
146 typedef struct {
147         obj_matcher_t super;
148         /* match by attributes assigned to the service */
149         attr_matcher_t *attr;
150 } service_matcher_t;
151 #define SERVICE_M(m) ((service_matcher_t *)(m))
153 /* match hosts */
154 typedef struct {
155         obj_matcher_t super;
156         /* match by services assigned to the host */
157         service_matcher_t *service;
158         /* match by attributes assigned to the host */
159         attr_matcher_t *attr;
160 } host_matcher_t;
161 #define HOST_M(m) ((host_matcher_t *)(m))
163 #ifdef __cplusplus
164 } /* extern "C" */
165 #endif
167 #endif /* ! SDB_CORE_STORE_H */
169 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */