X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmeta_data.c;h=6a336c4b67c734b62cf1516c3375b649fd826cac;hb=0af747df59d57fc972b27e98c175f26d873d7814;hp=d7fe2ebdc1b3887fce423820f26ccca20a84e89e;hpb=35f98b6e5c4c30bd7aeb52c7894c5f6e276638da;p=collectd.git diff --git a/src/meta_data.c b/src/meta_data.c index d7fe2ebd..6a336c4b 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -26,15 +26,6 @@ #include /* - * Defines - */ -#define MD_TYPE_STRING 1 -#define MD_TYPE_SIGNED_INT 2 -#define MD_TYPE_UNSIGNED_INT 3 -#define MD_TYPE_DOUBLE 4 -#define MD_TYPE_BOOLEAN 5 - -/* * Data types */ union meta_value_u @@ -249,6 +240,49 @@ int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */ return (0); } /* }}} int meta_data_exists */ +int meta_data_type (meta_data_t *md, const char *key) /* {{{ */ +{ + meta_entry_t *e; + + if ((md == NULL) || (key == NULL)) + return -EINVAL; + + pthread_mutex_lock (&md->lock); + + for (e = md->head; e != NULL; e = e->next) + { + if (strcasecmp (key, e->key) == 0) + { + pthread_mutex_unlock (&md->lock); + return e->type; + } + } + + pthread_mutex_unlock (&md->lock); + return 0; +} /* }}} int meta_data_type */ + +int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ +{ + int i = 0, count = 0; + meta_entry_t *e; + + if ((md == NULL) || (toc == NULL)) + return -EINVAL; + + pthread_mutex_lock (&md->lock); + + for (e = md->head; e != NULL; e = e->next) + ++count; + + *toc = malloc(count * sizeof(**toc)); + for (e = md->head; e != NULL; e = e->next) + (*toc)[i++] = strdup(e->key); + + pthread_mutex_unlock (&md->lock); + return count; +} /* }}} int meta_data_toc */ + int meta_data_delete (meta_data_t *md, const char *key) /* {{{ */ { meta_entry_t *this; @@ -409,7 +443,7 @@ int meta_data_get_string (meta_data_t *md, /* {{{ */ return (-ENOENT); } - if (e->type != MD_TYPE_SIGNED_INT) + if (e->type != MD_TYPE_STRING) { ERROR ("meta_data_get_signed_int: Type mismatch for key `%s'", e->key); pthread_mutex_unlock (&md->lock);