2 * collectd - src/plugin.c
3 * Copyright (C) 2005-2009 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
20 * Sebastian Harl <sh at tokkee.org>
24 #include "utils_complain.h"
34 #include "configfile.h"
35 #include "utils_avltree.h"
36 #include "utils_llist.h"
37 #include "utils_cache.h"
38 #include "utils_threshold.h"
39 #include "filter_chain.h"
48 int (*callback) (void);
49 enum { DONE = 0, TODO = 1, ACTIVE = 2 } needs_read;
51 typedef struct read_func_s read_func_t;
53 struct dispatch_queue_s;
54 typedef struct dispatch_queue_s dispatch_queue_t;
55 struct dispatch_queue_s
58 dispatch_queue_t *next;
64 static llist_t *list_init;
65 static llist_t *list_read;
66 static llist_t *list_write;
67 static llist_t *list_flush;
68 static llist_t *list_shutdown;
69 static llist_t *list_log;
70 static llist_t *list_notification;
72 static fc_chain_t *pre_cache_chain = NULL;
73 static fc_chain_t *post_cache_chain = NULL;
75 static c_avl_tree_t *data_sets;
77 static char *plugindir = NULL;
79 static int read_loop = 0;
80 static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
81 static pthread_cond_t read_cond = PTHREAD_COND_INITIALIZER;
82 static pthread_t *read_threads = NULL;
83 static size_t read_threads_num = 0;
85 static int dispatch_loop = 0;
86 static pthread_mutex_t dispatch_lock = PTHREAD_MUTEX_INITIALIZER;
87 static pthread_cond_t dispatch_cond = PTHREAD_COND_INITIALIZER;
88 static pthread_t *dispatch_threads = NULL;
89 static size_t dispatch_threads_num = 0;
90 static dispatch_queue_t *dispatch_head;
91 static dispatch_queue_t *dispatch_tail;
96 static const char *plugin_get_dir (void)
98 if (plugindir == NULL)
104 static int register_callback (llist_t **list, const char *name, void *callback)
110 && ((*list = llist_create ()) == NULL))
113 le = llist_search (*list, name);
120 le = llentry_create (key, callback);
127 llist_append (*list, le);
131 le->value = callback;
135 } /* int register_callback */
137 static int plugin_unregister (llist_t *list, const char *name)
141 e = llist_search (list, name);
146 llist_remove (list, e);
151 } /* int plugin_unregister */
154 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
155 * object, but it will bitch about a shared object not having a
156 * ``module_register'' symbol..
158 static int plugin_load_file (char *file)
161 void (*reg_handle) (void);
163 DEBUG ("file = %s", file);
166 lt_dlerror (); /* clear errors */
168 if ((dlh = lt_dlopen (file)) == NULL)
170 const char *error = lt_dlerror ();
172 ERROR ("lt_dlopen (%s) failed: %s", file, error);
173 fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
177 if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
179 WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
180 file, lt_dlerror ());
190 static void *plugin_read_thread (void __attribute__((unused)) *args)
197 pthread_mutex_lock (&read_lock);
199 while (read_loop != 0)
201 le = llist_head (list_read);
204 while ((read_loop != 0) && (le != NULL))
206 rf = (read_func_t *) le->value;
208 if (rf->needs_read != TODO)
214 /* We will do this read function */
215 rf->needs_read = ACTIVE;
217 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Handling %s",
218 (unsigned long int) pthread_self (), le->key);
219 pthread_mutex_unlock (&read_lock);
221 status = rf->callback ();
226 if (rf->wait_time < interval_g)
227 rf->wait_time = interval_g;
228 rf->wait_left = rf->wait_time;
229 rf->wait_time = rf->wait_time * 2;
230 if (rf->wait_time > 86400)
231 rf->wait_time = 86400;
233 NOTICE ("read-function of plugin `%s' "
234 "failed. Will suspend it for %i "
235 "seconds.", le->key, rf->wait_left);
240 rf->wait_time = interval_g;
243 pthread_mutex_lock (&read_lock);
245 rf->needs_read = DONE;
247 } /* while (le != NULL) */
249 if ((read_loop != 0) && (done == 0))
251 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Waiting on read_cond.",
252 (unsigned long int) pthread_self ());
253 pthread_cond_wait (&read_cond, &read_lock);
255 } /* while (read_loop) */
257 pthread_mutex_unlock (&read_lock);
261 } /* void *plugin_read_thread */
263 static void *plugin_dispatch_thread (void *arg)
265 pthread_mutex_lock (&dispatch_lock);
267 while ((dispatch_loop != 0) || (dispatch_head != NULL))
269 dispatch_queue_t *qi;
271 if (dispatch_head == NULL)
272 pthread_cond_wait (&dispatch_cond, &dispatch_lock);
274 if (dispatch_head == NULL)
279 if (dispatch_head == dispatch_tail)
281 dispatch_head = NULL;
282 dispatch_tail = NULL;
286 dispatch_head = qi->next;
289 pthread_mutex_unlock (&dispatch_lock);
291 plugin_dispatch_values (qi->vl);
292 sfree (qi->vl->values);
296 pthread_mutex_lock (&dispatch_lock);
299 pthread_mutex_unlock (&dispatch_lock);
302 } /* void *plugin_dispatch_thread */
304 static int plugin_start_threads (size_t num,
305 pthread_t **tlist, size_t *tlist_num,
306 void *(*thread_main) (void *))
309 pthread_t *new_tlist;
310 size_t new_tlist_num;
315 new_tlist = (pthread_t *) calloc (num, sizeof (*new_tlist));
316 if (new_tlist == NULL)
318 ERROR ("plugin: plugin_start_threads: calloc failed.");
323 for (i = 0; i < num; i++)
327 status = pthread_create (new_tlist + new_tlist_num,
328 /* attr = */ NULL, thread_main,
329 /* arg = */ (void *) 0);
332 ERROR ("plugin: plugin_start_threads: "
333 "pthread_create failed.");
340 if (new_tlist_num < 1)
342 ERROR ("plugin: plugin_start_threads: "
343 "Creating threads failed.");
349 *tlist_num = new_tlist_num;
352 } /* int plugin_start_threads */
354 static int plugin_stop_threads (int *loop,
355 pthread_mutex_t *lock, pthread_cond_t *cond,
356 pthread_t **ret_tlist, size_t *ret_tlist_len)
363 tlist_len = *ret_tlist_len;
368 DEBUG ("plugin_stop_threads: Stopping %zu threads.", tlist_len);
370 pthread_mutex_lock (lock);
374 pthread_cond_broadcast (cond);
375 pthread_mutex_unlock (lock);
377 for (i = 0; i < tlist_len; i++)
381 status = pthread_join (tlist[i], NULL);
384 ERROR ("plugin_stop_threads: pthread_join failed.");
394 } /* int plugin_stop_threads */
399 void plugin_set_dir (const char *dir)
401 if (plugindir != NULL)
406 else if ((plugindir = strdup (dir)) == NULL)
409 ERROR ("strdup failed: %s",
410 sstrerror (errno, errbuf, sizeof (errbuf)));
415 int plugin_load (const char *type)
419 char filename[BUFSIZE] = "";
420 char typename[BUFSIZE];
427 DEBUG ("type = %s", type);
429 dir = plugin_get_dir ();
432 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
433 * type when matching the filename */
434 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
435 if ((status < 0) || ((size_t) status >= sizeof (typename)))
437 WARNING ("snprintf: truncated: `%s.so'", type);
440 typename_len = strlen (typename);
442 if ((dh = opendir (dir)) == NULL)
445 ERROR ("opendir (%s): %s", dir,
446 sstrerror (errno, errbuf, sizeof (errbuf)));
450 while ((de = readdir (dh)) != NULL)
452 if (strncasecmp (de->d_name, typename, typename_len))
455 status = ssnprintf (filename, sizeof (filename),
456 "%s/%s", dir, de->d_name);
457 if ((status < 0) || ((size_t) status >= sizeof (filename)))
459 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
463 if (lstat (filename, &statbuf) == -1)
466 WARNING ("stat %s: %s", filename,
467 sstrerror (errno, errbuf, sizeof (errbuf)));
470 else if (!S_ISREG (statbuf.st_mode))
472 /* don't follow symlinks */
476 if (plugin_load_file (filename) == 0)
484 fprintf (stderr, "Unable to load plugin %s.\n", type);
490 if (filename[0] == '\0')
491 fprintf (stderr, "Could not find plugin %s.\n", type);
497 * The `register_*' functions follow
499 int plugin_register_config (const char *name,
500 int (*callback) (const char *key, const char *val),
501 const char **keys, int keys_num)
503 cf_register (name, callback, keys, keys_num);
505 } /* int plugin_register_config */
507 int plugin_register_complex_config (const char *type,
508 int (*callback) (oconfig_item_t *))
510 return (cf_register_complex (type, callback));
511 } /* int plugin_register_complex_config */
513 int plugin_register_init (const char *name,
514 int (*callback) (void))
516 return (register_callback (&list_init, name, (void *) callback));
517 } /* plugin_register_init */
519 int plugin_register_read (const char *name,
520 int (*callback) (void))
524 rf = (read_func_t *) malloc (sizeof (read_func_t));
528 ERROR ("plugin_register_read: malloc failed: %s",
529 sstrerror (errno, errbuf, sizeof (errbuf)));
533 memset (rf, '\0', sizeof (read_func_t));
534 rf->wait_time = interval_g;
536 rf->callback = callback;
537 rf->needs_read = DONE;
539 return (register_callback (&list_read, name, (void *) rf));
540 } /* int plugin_register_read */
542 int plugin_register_write (const char *name,
543 int (*callback) (const data_set_t *ds, const value_list_t *vl))
545 return (register_callback (&list_write, name, (void *) callback));
546 } /* int plugin_register_write */
548 int plugin_register_flush (const char *name,
549 int (*callback) (const int timeout, const char *identifier))
551 return (register_callback (&list_flush, name, (void *) callback));
552 } /* int plugin_register_flush */
554 int plugin_register_shutdown (char *name,
555 int (*callback) (void))
557 return (register_callback (&list_shutdown, name, (void *) callback));
558 } /* int plugin_register_shutdown */
560 int plugin_register_data_set (const data_set_t *ds)
565 if ((data_sets != NULL)
566 && (c_avl_get (data_sets, ds->type, NULL) == 0))
568 NOTICE ("Replacing DS `%s' with another version.", ds->type);
569 plugin_unregister_data_set (ds->type);
571 else if (data_sets == NULL)
573 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
574 if (data_sets == NULL)
578 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
581 memcpy(ds_copy, ds, sizeof (data_set_t));
583 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
585 if (ds_copy->ds == NULL)
591 for (i = 0; i < ds->ds_num; i++)
592 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
594 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
595 } /* int plugin_register_data_set */
597 int plugin_register_log (char *name,
598 void (*callback) (int priority, const char *msg))
600 return (register_callback (&list_log, name, (void *) callback));
601 } /* int plugin_register_log */
603 int plugin_register_notification (const char *name,
604 int (*callback) (const notification_t *notif))
606 return (register_callback (&list_notification, name, (void *) callback));
607 } /* int plugin_register_log */
609 int plugin_unregister_config (const char *name)
611 cf_unregister (name);
613 } /* int plugin_unregister_config */
615 int plugin_unregister_complex_config (const char *name)
617 cf_unregister_complex (name);
619 } /* int plugin_unregister_complex_config */
621 int plugin_unregister_init (const char *name)
623 return (plugin_unregister (list_init, name));
626 int plugin_unregister_read (const char *name)
630 e = llist_search (list_read, name);
635 llist_remove (list_read, e);
643 int plugin_unregister_write (const char *name)
645 return (plugin_unregister (list_write, name));
648 int plugin_unregister_flush (const char *name)
650 return (plugin_unregister (list_flush, name));
653 int plugin_unregister_shutdown (const char *name)
655 return (plugin_unregister (list_shutdown, name));
658 int plugin_unregister_data_set (const char *name)
662 if (data_sets == NULL)
665 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
672 } /* int plugin_unregister_data_set */
674 int plugin_unregister_log (const char *name)
676 return (plugin_unregister (list_log, name));
679 int plugin_unregister_notification (const char *name)
681 return (plugin_unregister (list_notification, name));
684 void plugin_init_all (void)
686 const char *chain_name;
687 int (*callback) (void);
691 /* Init the value cache */
694 chain_name = global_option_get ("PreCacheChain");
695 pre_cache_chain = fc_chain_get_by_name (chain_name);
697 chain_name = global_option_get ("PostCacheChain");
698 post_cache_chain = fc_chain_get_by_name (chain_name);
701 if ((list_init == NULL) && (list_read == NULL))
704 /* Calling all init callbacks before checking if read callbacks
705 * are available allows the init callbacks to register the read
707 le = llist_head (list_init);
710 callback = (int (*) (void)) le->value;
711 status = (*callback) ();
715 ERROR ("Initialization of plugin `%s' "
716 "failed with status %i. "
717 "Plugin will be unloaded.",
719 /* Plugins that register read callbacks from the init
720 * callback should take care of appropriate error
721 * handling themselves. */
722 /* FIXME: Unload _all_ functions */
723 plugin_unregister_read (le->key);
729 /* Start read-threads */
730 if (list_read != NULL)
734 rt = global_option_get ("ReadThreads");
739 plugin_start_threads ((num > 0) ? ((size_t ) num) : 5,
740 &read_threads, &read_threads_num,
746 plugin_start_threads (/* num = */ 1, /* FIXME: Make this number configurable */
747 &dispatch_threads, &dispatch_threads_num,
748 plugin_dispatch_thread);
749 } /* void plugin_init_all */
751 void plugin_read_all (void)
758 if (list_read == NULL)
761 pthread_mutex_lock (&read_lock);
763 le = llist_head (list_read);
766 rf = (read_func_t *) le->value;
768 if (rf->needs_read != DONE)
774 if (rf->wait_left > 0)
775 rf->wait_left -= interval_g;
777 if (rf->wait_left <= 0)
779 rf->needs_read = TODO;
785 DEBUG ("plugin: plugin_read_all: Signalling `read_cond'");
786 pthread_cond_broadcast (&read_cond);
787 pthread_mutex_unlock (&read_lock);
788 } /* void plugin_read_all */
790 /* Read function called when the `-T' command line argument is given. */
791 int plugin_read_all_once (void)
796 int return_status = 0;
798 if (list_read == NULL)
800 NOTICE ("No read-functions are registered.");
804 for (le = llist_head (list_read);
808 rf = (read_func_t *) le->value;
809 status = rf->callback ();
812 NOTICE ("read-function of plugin `%s' failed.",
818 return (return_status);
819 } /* int plugin_read_all_once */
821 int plugin_write (const char *plugin, /* {{{ */
822 const data_set_t *ds, const value_list_t *vl)
824 int (*callback) (const data_set_t *ds, const value_list_t *vl);
831 if (list_write == NULL)
836 ds = plugin_get_ds (vl->type);
839 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
849 le = llist_head (list_write);
852 callback = le->value;
853 status = (*callback) (ds, vl);
862 if ((success == 0) && (failure != 0))
867 else /* plugin != NULL */
869 le = llist_head (list_write);
872 if (strcasecmp (plugin, le->key) == 0)
881 callback = le->value;
882 status = (*callback) (ds, vl);
886 } /* }}} int plugin_write */
888 int plugin_flush (const char *plugin, int timeout, const char *identifier)
890 int (*callback) (int timeout, const char *identifier);
893 if (list_flush == NULL)
896 le = llist_head (list_flush);
900 && (strcmp (plugin, le->key) != 0))
906 callback = (int (*) (int, const char *)) le->value;
907 (*callback) (timeout, identifier);
912 } /* int plugin_flush */
914 void plugin_shutdown_all (void)
916 int (*callback) (void);
919 plugin_stop_threads (&read_loop, &read_lock, &read_cond,
920 &read_threads, &read_threads_num);
922 plugin_stop_threads (&dispatch_loop, &dispatch_lock, &dispatch_cond,
923 &dispatch_threads, &dispatch_threads_num);
925 if (list_shutdown == NULL)
928 le = llist_head (list_shutdown);
931 callback = (int (*) (void)) le->value;
933 /* Advance the pointer before calling the callback allows
934 * shutdown functions to unregister themselves. If done the
935 * other way around the memory `le' points to will be freed
936 * after callback returns. */
941 } /* void plugin_shutdown_all */
943 int plugin_dispatch_values (value_list_t *vl)
946 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
950 if ((vl == NULL) || (*vl->type == '\0')) {
951 ERROR ("plugin_dispatch_values: Invalid value list.");
955 if (list_write == NULL)
956 c_complain_once (LOG_WARNING, &no_write_complaint,
957 "plugin_dispatch_values: No write callback has been "
958 "registered. Please load at least one output plugin, "
959 "if you want the collected data to be stored.");
961 if (data_sets == NULL)
963 ERROR ("plugin_dispatch_values: No data sets registered. "
964 "Could the types database be read? Check "
965 "your `TypesDB' setting!");
969 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
971 INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
976 vl->time = time (NULL);
978 DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
980 "plugin = %s; plugin_instance = %s; "
981 "type = %s; type_instance = %s;",
982 (unsigned int) vl->time, vl->interval,
984 vl->plugin, vl->plugin_instance,
985 vl->type, vl->type_instance);
988 assert (0 == strcmp (ds->type, vl->type));
990 if (0 != strcmp (ds->type, vl->type))
991 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
996 assert (ds->ds_num == vl->values_len);
998 if (ds->ds_num != vl->values_len)
1000 ERROR ("plugin_dispatch_values: ds->type = %s: "
1001 "(ds->ds_num = %i) != "
1002 "(vl->values_len = %i)",
1003 ds->type, ds->ds_num, vl->values_len);
1008 escape_slashes (vl->host, sizeof (vl->host));
1009 escape_slashes (vl->plugin, sizeof (vl->plugin));
1010 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1011 escape_slashes (vl->type, sizeof (vl->type));
1012 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1014 if (pre_cache_chain != NULL)
1016 status = fc_process_chain (ds, vl, pre_cache_chain);
1019 WARNING ("plugin_dispatch_values: Running the "
1020 "pre-cache chain failed with "
1024 else if (status == FC_TARGET_STOP)
1028 /* Update the value cache */
1031 if (post_cache_chain != NULL)
1033 status = fc_process_chain (ds, vl, post_cache_chain);
1036 WARNING ("plugin_dispatch_values: Running the "
1037 "post-cache chain failed with "
1043 fc_default_action (ds, vl);
1046 } /* int plugin_dispatch_values */
1048 int plugin_dispatch_values_async (const value_list_t *vl)
1050 dispatch_queue_t *qi;
1056 if (dispatch_threads_num < 1)
1058 ERROR ("plugin_dispatch_values_async: "
1059 "No dispatch threads have been started!");
1067 qi = (dispatch_queue_t *) malloc (sizeof (*qi));
1070 ERROR ("plugin_dispatch_values_async: malloc failed.");
1073 memset (qi, 0, sizeof (*qi));
1076 qi->vl = (value_list_t *) malloc (sizeof (value_list_t));
1079 ERROR ("plugin_dispatch_values_async: malloc failed.");
1083 memcpy (qi->vl, vl, sizeof (value_list_t));
1084 qi->vl->values = NULL;
1086 qi->vl->values = (value_t *) calloc (qi->vl->values_len,
1088 if (qi->vl->values == NULL)
1090 ERROR ("plugin_dispatch_values_async: malloc failed.");
1096 for (i = 0; i < vl->values_len; i++)
1097 qi->vl->values[i] = vl->values[i];
1099 pthread_mutex_lock (&dispatch_lock);
1101 if (dispatch_tail == NULL)
1108 dispatch_tail->next = qi;
1112 pthread_cond_signal (&dispatch_cond);
1113 pthread_mutex_unlock (&dispatch_lock);
1116 } /* int plugin_dispatch_values_async */
1118 int plugin_dispatch_notification (const notification_t *notif)
1120 int (*callback) (const notification_t *);
1122 /* Possible TODO: Add flap detection here */
1124 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1125 "time = %u; host = %s;",
1126 notif->severity, notif->message,
1127 (unsigned int) notif->time, notif->host);
1129 /* Nobody cares for notifications */
1130 if (list_notification == NULL)
1133 le = llist_head (list_notification);
1136 callback = (int (*) (const notification_t *)) le->value;
1137 (*callback) (notif);
1143 } /* int plugin_dispatch_notification */
1145 void plugin_log (int level, const char *format, ...)
1150 void (*callback) (int, const char *);
1153 if (list_log == NULL)
1157 if (level >= LOG_DEBUG)
1161 va_start (ap, format);
1162 vsnprintf (msg, sizeof (msg), format, ap);
1163 msg[sizeof (msg) - 1] = '\0';
1166 le = llist_head (list_log);
1169 callback = (void (*) (int, const char *)) le->value;
1170 (*callback) (level, msg);
1174 } /* void plugin_log */
1176 const data_set_t *plugin_get_ds (const char *name)
1180 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1182 DEBUG ("No such dataset registered: %s", name);
1187 } /* data_set_t *plugin_get_ds */
1189 static int plugin_notification_meta_add (notification_t *n,
1191 enum notification_meta_type_e type,
1194 notification_meta_t *meta;
1195 notification_meta_t *tail;
1197 if ((n == NULL) || (name == NULL) || (value == NULL))
1199 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1203 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1206 ERROR ("plugin_notification_meta_add: malloc failed.");
1209 memset (meta, 0, sizeof (notification_meta_t));
1211 sstrncpy (meta->name, name, sizeof (meta->name));
1216 case NM_TYPE_STRING:
1218 meta->nm_value.nm_string = strdup ((const char *) value);
1219 if (meta->nm_value.nm_string == NULL)
1221 ERROR ("plugin_notification_meta_add: strdup failed.");
1227 case NM_TYPE_SIGNED_INT:
1229 meta->nm_value.nm_signed_int = *((int64_t *) value);
1232 case NM_TYPE_UNSIGNED_INT:
1234 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1237 case NM_TYPE_DOUBLE:
1239 meta->nm_value.nm_double = *((double *) value);
1242 case NM_TYPE_BOOLEAN:
1244 meta->nm_value.nm_boolean = *((bool *) value);
1249 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1253 } /* switch (type) */
1257 while ((tail != NULL) && (tail->next != NULL))
1266 } /* int plugin_notification_meta_add */
1268 int plugin_notification_meta_add_string (notification_t *n,
1272 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1275 int plugin_notification_meta_add_signed_int (notification_t *n,
1279 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1282 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1286 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1289 int plugin_notification_meta_add_double (notification_t *n,
1293 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1296 int plugin_notification_meta_add_boolean (notification_t *n,
1300 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1303 int plugin_notification_meta_copy (notification_t *dst,
1304 const notification_t *src)
1306 notification_meta_t *meta;
1308 assert (dst != NULL);
1309 assert (src != NULL);
1310 assert (dst != src);
1311 assert ((src->meta == NULL) || (src->meta != dst->meta));
1313 for (meta = src->meta; meta != NULL; meta = meta->next)
1315 if (meta->type == NM_TYPE_STRING)
1316 plugin_notification_meta_add_string (dst, meta->name,
1317 meta->nm_value.nm_string);
1318 else if (meta->type == NM_TYPE_SIGNED_INT)
1319 plugin_notification_meta_add_signed_int (dst, meta->name,
1320 meta->nm_value.nm_signed_int);
1321 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1322 plugin_notification_meta_add_unsigned_int (dst, meta->name,
1323 meta->nm_value.nm_unsigned_int);
1324 else if (meta->type == NM_TYPE_DOUBLE)
1325 plugin_notification_meta_add_double (dst, meta->name,
1326 meta->nm_value.nm_double);
1327 else if (meta->type == NM_TYPE_BOOLEAN)
1328 plugin_notification_meta_add_boolean (dst, meta->name,
1329 meta->nm_value.nm_boolean);
1333 } /* int plugin_notification_meta_copy */
1335 int plugin_notification_meta_free (notification_meta_t *n)
1337 notification_meta_t *this;
1338 notification_meta_t *next;
1342 ERROR ("plugin_notification_meta_free: n == NULL!");
1347 while (this != NULL)
1351 if (this->type == NM_TYPE_STRING)
1353 free ((char *)this->nm_value.nm_string);
1354 this->nm_value.nm_string = NULL;
1362 } /* int plugin_notification_meta_free */