summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b1d0d9a)
raw | patch | inline | side by side (parent: b1d0d9a)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Jun 2014 15:35:51 +0000 (17:35 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Jun 2014 15:35:51 +0000 (17:35 +0200) |
src/core/store-private.h | patch | blob | history | |
src/core/store_lookup.c | patch | blob | history |
index 42281883295aebd043032aafa31bfc0b1b2d772a..f33768579575524857b9991376b55c2262364439 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
typedef struct {
char *name;
regex_t *name_re;
-} name_matcher_t;
+} string_matcher_t;
/* matcher base type */
struct sdb_store_matcher {
sdb_store_matcher_t super;
int obj_type;
-
- /* match by the name of the object */
- name_matcher_t name;
-} obj_matcher_t;
-#define OBJ_M(m) ((obj_matcher_t *)(m))
+ string_matcher_t name;
+} name_matcher_t;
+#define NAME_M(m) ((name_matcher_t *)(m))
/* match attributes */
typedef struct {
char *name;
/* XXX: this needs to be more flexible;
* add support for type-specific operators */
- name_matcher_t value;
+ string_matcher_t value;
} attr_matcher_t;
#define ATTR_M(m) ((attr_matcher_t *)(m))
index f6905e9a4f65d2d552379edc5e18e95b60b9a9f4..b5c936aae355419eadf52dfd7e1c99110e38701f 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
/* specific matchers */
static int
-match_obj_name(name_matcher_t *m, const char *name)
+match_string(string_matcher_t *m, const char *name)
{
assert(m);
/* matches */ 0, NULL, /* flags = */ 0))
return 0;
return 1;
-} /* match_obj_name */
+} /* match_string */
static char *
-obj_name_tostring(name_matcher_t *m, char *buf, size_t buflen)
+string_tostring(string_matcher_t *m, char *buf, size_t buflen)
{
snprintf(buf, buflen, "{ %s%s%s, %p }",
m->name ? "'" : "", m->name ? m->name : "NULL", m->name ? "'" : "",
m->name_re);
return buf;
-} /* obj_name_tostring */
+} /* string_tostring */
static char *
logical_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
char name[buflen + 1];
assert(m->type == MATCHER_NAME);
snprintf(buf, buflen, "OBJ[%s]{ NAME%s }",
- SDB_STORE_TYPE_TO_NAME(OBJ_M(m)->obj_type),
- obj_name_tostring(&OBJ_M(m)->name, name, sizeof(name)));
+ SDB_STORE_TYPE_TO_NAME(NAME_M(m)->obj_type),
+ string_tostring(&NAME_M(m)->name, name, sizeof(name)));
return buf;
} /* name_tostring */
assert(m->type == MATCHER_ATTR);
snprintf(buf, buflen, "ATTR[%s]{ VALUE%s }", ATTR_M(m)->name,
- obj_name_tostring(&ATTR_M(m)->value, value, sizeof(value)));
+ string_tostring(&ATTR_M(m)->value, value, sizeof(value)));
return buf;
} /* attr_tostring */
if (obj->type != SDB_HOST)
return 0;
- switch (OBJ_M(m)->obj_type) {
+ switch (NAME_M(m)->obj_type) {
case SDB_HOST:
- return match_obj_name(&OBJ_M(m)->name, obj->super.name);
+ return match_string(&NAME_M(m)->name, obj->super.name);
break;
case SDB_SERVICE:
iter = sdb_llist_get_iter(SDB_STORE_OBJ(obj)->children);
while (sdb_llist_iter_has_next(iter)) {
sdb_store_base_t *child = STORE_BASE(sdb_llist_iter_get_next(iter));
- if (match_obj_name(&OBJ_M(m)->name, child->super.name)) {
+ if (match_string(&NAME_M(m)->name, child->super.name)) {
status = 1;
break;
}
if (sdb_data_format(&attr->value, buf, sizeof(buf), SDB_UNQUOTED) <= 0)
return 0;
- if (match_obj_name(&ATTR_M(m)->value, buf)) {
+ if (match_string(&ATTR_M(m)->value, buf)) {
status = 1;
break;
}
* private matcher types
*/
-/* initializes a name matcher consuming two elements from ap */
+/* initializes a string matcher consuming two elements from ap */
static int
-name_matcher_init(name_matcher_t *m, va_list ap)
+string_matcher_init(string_matcher_t *m, va_list ap)
{
const char *name = va_arg(ap, const char *);
const char *name_re = va_arg(ap, const char *);
return -1;
}
return 0;
-} /* name_matcher_init */
+} /* string_matcher_init */
static void
-name_matcher_destroy(name_matcher_t *m)
+string_matcher_destroy(string_matcher_t *m)
{
if (m->name)
free(m->name);
regfree(m->name_re);
free(m->name_re);
}
-} /* name_matcher_destroy */
+} /* string_matcher_destroy */
-/* initializes an object matcher consuming two elements from ap */
+/* initializes a name matcher */
static int
-obj_matcher_init(sdb_object_t *obj, va_list ap)
+name_matcher_init(sdb_object_t *obj, va_list ap)
{
- obj_matcher_t *m = OBJ_M(obj);
+ name_matcher_t *m = NAME_M(obj);
M(obj)->type = MATCHER_NAME;
- return name_matcher_init(&m->name, ap);
-} /* obj_matcher_init */
+ return string_matcher_init(&m->name, ap);
+} /* name_matcher_init */
static void
-obj_matcher_destroy(sdb_object_t *obj)
+name_matcher_destroy(sdb_object_t *obj)
{
- obj_matcher_t *m = OBJ_M(obj);
- name_matcher_destroy(&m->name);
-} /* obj_matcher_destroy */
+ name_matcher_t *m = NAME_M(obj);
+ string_matcher_destroy(&m->name);
+} /* name_matcher_destroy */
static int
attr_matcher_init(sdb_object_t *obj, va_list ap)
if (! attr->name)
return -1;
}
- return name_matcher_init(&attr->value, ap);
+ return string_matcher_init(&attr->value, ap);
} /* attr_matcher_init */
static void
if (attr->name)
free(attr->name);
attr->name = NULL;
- name_matcher_destroy(&attr->value);
+ string_matcher_destroy(&attr->value);
} /* attr_matcher_destroy */
static int
} /* uop_matcher_destroy */
static sdb_type_t name_type = {
- /* size = */ sizeof(obj_matcher_t),
- /* init = */ obj_matcher_init,
- /* destroy = */ obj_matcher_destroy,
+ /* size = */ sizeof(name_matcher_t),
+ /* init = */ name_matcher_init,
+ /* destroy = */ name_matcher_destroy,
};
static sdb_type_t attr_type = {
if (! m)
return NULL;
- OBJ_M(m)->obj_type = type;
+ NAME_M(m)->obj_type = type;
return m;
} /* sdb_store_name_matcher */