Code

Added function to get the data type of a meta data entry.
[collectd.git] / src / meta_data.c
index 3a3f5e7918b4c44ba8da80367bf0d2597f6eff15..a7c11c10607352d9cbf0a938a185a54895bfd970 100644 (file)
 
 #include <pthread.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
-
 /*
  * 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;