X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fmemstore.c;fp=src%2Fcore%2Fmemstore.c;h=15c4202829159eee3665b74f7d1654b010d8b602;hp=d886a1fb4c131f4d094ba2cbda7f4e0e61bfc30e;hb=637fd9289e84a2eb394d01c4769cbd5276c2b905;hpb=07dada8e5c614f0ef90fed8e86183ba7acd0e6e8 diff --git a/src/core/memstore.c b/src/core/memstore.c index d886a1f..15c4202 100644 --- a/src/core/memstore.c +++ b/src/core/memstore.c @@ -483,6 +483,18 @@ get_host_children(host_t *host, int type) return host->services; } /* get_host_children */ +static sdb_avltree_t * +get_obj_attrs(sdb_memstore_obj_t *obj) +{ + if (obj->type == SDB_HOST) + return HOST(obj)->attributes; + else if (obj->type == SDB_SERVICE) + return SVC(obj)->attributes; + else if (obj->type == SDB_METRIC) + return METRIC(obj)->attributes; + return NULL; +} /* get_obj_attrs */ + /* * store writer API */ @@ -522,10 +534,8 @@ store_attribute(sdb_store_attribute_t *attr, sdb_object_t *user_data) obj.parent_tree = get_host_children(host, SDB_ATTRIBUTE); break; case SDB_SERVICE: - children = get_host_children(host, SDB_SERVICE); - break; case SDB_METRIC: - children = get_host_children(host, SDB_METRIC); + children = get_host_children(host, attr->parent_type); break; default: status = -1; @@ -804,14 +814,17 @@ sdb_memstore_get_host(sdb_memstore_t *store, const char *name) } /* sdb_memstore_get_host */ sdb_memstore_obj_t * -sdb_memstore_get_child(sdb_memstore_obj_t *host, int type, const char *name) +sdb_memstore_get_child(sdb_memstore_obj_t *obj, int type, const char *name) { - sdb_avltree_t *children; + sdb_avltree_t *children = NULL; - if ((! host) || (host->type != SDB_HOST) || (! name)) + if ((! obj) || (! name)) return NULL; - children = get_host_children(HOST(host), type); + if (type & SDB_ATTRIBUTE) + children = get_obj_attrs(obj); + else if (obj->type == SDB_HOST) + children = get_host_children(HOST(obj), type); if (! children) return NULL; return STORE_OBJ(sdb_avltree_lookup(children, name)); @@ -876,23 +889,12 @@ int sdb_memstore_get_attr(sdb_memstore_obj_t *obj, const char *name, sdb_data_t *res, sdb_memstore_matcher_t *filter) { - sdb_avltree_t *tree = NULL; sdb_memstore_obj_t *attr; if ((! obj) || (! name)) return -1; - if (obj->type == SDB_HOST) - tree = HOST(obj)->attributes; - else if (obj->type == SDB_SERVICE) - tree = SVC(obj)->attributes; - else if (obj->type == SDB_METRIC) - tree = METRIC(obj)->attributes; - - if (! tree) - return -1; - - attr = STORE_OBJ(sdb_avltree_lookup(tree, name)); + attr = STORE_OBJ(sdb_avltree_lookup(get_obj_attrs(obj), name)); if (! attr) return -1; if (filter && (! sdb_memstore_matcher_matches(filter, attr, NULL))) {