From: Sebastian Harl Date: Tue, 30 Sep 2014 12:43:42 +0000 (-0700) Subject: store: Added a helper function to parse object type names. X-Git-Tag: sysdb-0.5.0~25 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=3497f3e7bfedaa643aa89763a650dc581d8d07a2 store: Added a helper function to parse object type names. --- 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.