From 3497f3e7bfedaa643aa89763a650dc581d8d07a2 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 30 Sep 2014 05:43:42 -0700 Subject: [PATCH] store: Added a helper function to parse object type names. --- src/core/store_lookup.c | 12 ++++++++++++ src/include/core/store.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index c3029c7..86acd10 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -857,6 +857,18 @@ sdb_store_isnull_matcher(const char *attr_name) MATCHER_ISNULL, attr_name)); } /* sdb_store_isnull_matcher */ +int +sdb_store_parse_object_type_plural(const char *name) +{ + if (! strcasecmp(name, "hosts")) + return SDB_HOST; + else if (! strcasecmp(name, "services")) + return SDB_SERVICE; + else if (! strcasecmp(name, "metrics")) + return SDB_METRIC; + return -1; +} /* sdb_store_parse_object_type_plural */ + int sdb_store_parse_field_name(const char *name) { diff --git a/src/include/core/store.h b/src/include/core/store.h index 7c94a97..fa974bb 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -397,6 +397,17 @@ sdb_store_ge_matcher(sdb_store_cond_t *cond); sdb_store_matcher_t * sdb_store_gt_matcher(sdb_store_cond_t *cond); +/* + * sdb_store_parse_object_type_plural: + * Parse the type name (plural) of a stored object. + * + * Returns: + * - the object type on success + * - a negative value else + */ +int +sdb_store_parse_object_type_plural(const char *name); + /* * sdb_store_parse_field_name: * Parse the name of a stored object's queryable field. -- 2.30.2