X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmeta_data.c;h=aff3f8e589248b29f836566fd56314cc91b7b148;hb=ba9b76d4be49c6a45b32a508c48e828a583b6dfc;hp=d7fe2ebdc1b3887fce423820f26ccca20a84e89e;hpb=fa9fd186f4e09c24a02d9541c2409d21bf282087;p=collectd.git diff --git a/src/meta_data.c b/src/meta_data.c index d7fe2ebd..aff3f8e5 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 @@ -224,6 +215,7 @@ void meta_data_destroy (meta_data_t *md) /* {{{ */ return; md_entry_free (md->head); + pthread_mutex_destroy (&md->lock); free (md); } /* }}} void meta_data_destroy */ @@ -249,6 +241,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 +444,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);