From 9c52b4ff1590251ea5fcefab15c0af655d49624c Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Wed, 9 Dec 2009 13:18:49 +0100 Subject: [PATCH] Added function to get the data type of a meta data entry. --- src/meta_data.c | 31 ++++++++++++++++++++++--------- src/meta_data.h | 10 ++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/meta_data.c b/src/meta_data.c index 3a3f5e79..a7c11c10 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -25,15 +25,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 */ @@ -249,6 +240,28 @@ 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 0; + + 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_delete (meta_data_t *md, const char *key) /* {{{ */ { meta_entry_t *this; diff --git a/src/meta_data.h b/src/meta_data.h index 8e5a7852..7a9afee5 100644 --- a/src/meta_data.h +++ b/src/meta_data.h @@ -24,6 +24,15 @@ #include "collectd.h" +/* + * 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 + struct meta_data_s; typedef struct meta_data_s meta_data_t; @@ -31,6 +40,7 @@ meta_data_t *meta_data_create (void); void meta_data_destroy (meta_data_t *md); int meta_data_exists (meta_data_t *md, const char *key); +int meta_data_type (meta_data_t *md, const char *key); int meta_data_delete (meta_data_t *md, const char *key); int meta_data_add_string (meta_data_t *md, -- 2.30.2