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"
53 int (*cb_simple) (void);
54 plugin_read_cb cb_complex;
56 enum { DONE = 0, TODO = 1, ACTIVE = 2 } needs_read;
59 typedef struct read_func_s read_func_t;
63 plugin_write_cb callback;
66 typedef struct write_func_s write_func_t;
71 static llist_t *list_init;
72 static llist_t *list_read;
73 static llist_t *list_write;
74 static llist_t *list_flush;
75 static llist_t *list_shutdown;
76 static llist_t *list_log;
77 static llist_t *list_notification;
79 static fc_chain_t *pre_cache_chain = NULL;
80 static fc_chain_t *post_cache_chain = NULL;
82 static c_avl_tree_t *data_sets;
84 static char *plugindir = NULL;
86 static int read_loop = 1;
87 static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
88 static pthread_cond_t read_cond = PTHREAD_COND_INITIALIZER;
89 static pthread_t *read_threads = NULL;
90 static int read_threads_num = 0;
95 static const char *plugin_get_dir (void)
97 if (plugindir == NULL)
103 static int register_callback (llist_t **list, const char *name, void *callback)
109 && ((*list = llist_create ()) == NULL))
112 le = llist_search (*list, name);
119 le = llentry_create (key, callback);
126 llist_append (*list, le);
130 le->value = callback;
134 } /* int register_callback */
136 static void plugin_user_data_destroy (user_data_t *ud)
138 if ((ud != NULL) && (ud->data != NULL) && (ud->free_func != NULL))
140 ud->free_func (ud->data);
142 ud->free_func = NULL;
144 } /* void plugin_user_data_destroy */
146 static int plugin_unregister (llist_t *list, const char *name)
150 e = llist_search (list, name);
155 llist_remove (list, e);
160 } /* int plugin_unregister */
163 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
164 * object, but it will bitch about a shared object not having a
165 * ``module_register'' symbol..
167 static int plugin_load_file (char *file)
170 void (*reg_handle) (void);
172 DEBUG ("file = %s", file);
175 lt_dlerror (); /* clear errors */
177 if ((dlh = lt_dlopen (file)) == NULL)
179 const char *error = lt_dlerror ();
181 ERROR ("lt_dlopen (%s) failed: %s", file, error);
182 fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
186 if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
188 WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
189 file, lt_dlerror ());
199 static void *plugin_read_thread (void __attribute__((unused)) *args)
206 pthread_mutex_lock (&read_lock);
208 while (read_loop != 0)
210 le = llist_head (list_read);
213 while ((read_loop != 0) && (le != NULL))
215 rf = (read_func_t *) le->value;
217 if (rf->needs_read != TODO)
223 /* We will do this read function */
224 rf->needs_read = ACTIVE;
226 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Handling %s",
227 (unsigned long int) pthread_self (), le->key);
228 pthread_mutex_unlock (&read_lock);
230 if (rf->type == RF_SIMPLE)
232 status = rf->callback.cb_simple ();
236 assert (rf->type == RF_COMPLEX);
237 status = rf->callback.cb_complex (&rf->udata);
243 if (rf->wait_time < interval_g)
244 rf->wait_time = interval_g;
245 rf->wait_left = rf->wait_time;
246 rf->wait_time = rf->wait_time * 2;
247 if (rf->wait_time > 86400)
248 rf->wait_time = 86400;
250 NOTICE ("read-function of plugin `%s' "
251 "failed. Will suspend it for %i "
252 "seconds.", le->key, rf->wait_left);
257 rf->wait_time = interval_g;
260 pthread_mutex_lock (&read_lock);
262 rf->needs_read = DONE;
264 } /* while (le != NULL) */
266 if ((read_loop != 0) && (done == 0))
268 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Waiting on read_cond.",
269 (unsigned long int) pthread_self ());
270 pthread_cond_wait (&read_cond, &read_lock);
272 } /* while (read_loop) */
274 pthread_mutex_unlock (&read_lock);
278 } /* void *plugin_read_thread */
280 static void start_read_threads (int num)
284 if (read_threads != NULL)
287 read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
288 if (read_threads == NULL)
290 ERROR ("plugin: start_read_threads: calloc failed.");
294 read_threads_num = 0;
295 for (i = 0; i < num; i++)
297 if (pthread_create (read_threads + read_threads_num, NULL,
298 plugin_read_thread, NULL) == 0)
304 ERROR ("plugin: start_read_threads: pthread_create failed.");
308 } /* void start_read_threads */
310 static void stop_read_threads (void)
314 if (read_threads == NULL)
317 pthread_mutex_lock (&read_lock);
319 DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
320 pthread_cond_broadcast (&read_cond);
321 pthread_mutex_unlock (&read_lock);
323 for (i = 0; i < read_threads_num; i++)
325 if (pthread_join (read_threads[i], NULL) != 0)
327 ERROR ("plugin: stop_read_threads: pthread_join failed.");
329 read_threads[i] = (pthread_t) 0;
331 sfree (read_threads);
332 read_threads_num = 0;
333 } /* void stop_read_threads */
335 static int remove_read_functions (void)
339 if (list_read == NULL)
342 this = llist_head (list_read);
349 rf = (read_func_t *) this->value;
353 plugin_user_data_destroy (&rf->udata);
359 llist_destroy (list_read);
363 } /* }}} int remove_read_functions */
368 void plugin_set_dir (const char *dir)
370 if (plugindir != NULL)
375 else if ((plugindir = strdup (dir)) == NULL)
378 ERROR ("strdup failed: %s",
379 sstrerror (errno, errbuf, sizeof (errbuf)));
384 int plugin_load (const char *type)
388 char filename[BUFSIZE] = "";
389 char typename[BUFSIZE];
396 DEBUG ("type = %s", type);
398 dir = plugin_get_dir ();
401 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
402 * type when matching the filename */
403 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
404 if ((status < 0) || ((size_t) status >= sizeof (typename)))
406 WARNING ("snprintf: truncated: `%s.so'", type);
409 typename_len = strlen (typename);
411 if ((dh = opendir (dir)) == NULL)
414 ERROR ("opendir (%s): %s", dir,
415 sstrerror (errno, errbuf, sizeof (errbuf)));
419 while ((de = readdir (dh)) != NULL)
421 if (strncasecmp (de->d_name, typename, typename_len))
424 status = ssnprintf (filename, sizeof (filename),
425 "%s/%s", dir, de->d_name);
426 if ((status < 0) || ((size_t) status >= sizeof (filename)))
428 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
432 if (lstat (filename, &statbuf) == -1)
435 WARNING ("stat %s: %s", filename,
436 sstrerror (errno, errbuf, sizeof (errbuf)));
439 else if (!S_ISREG (statbuf.st_mode))
441 /* don't follow symlinks */
445 if (plugin_load_file (filename) == 0)
453 fprintf (stderr, "Unable to load plugin %s.\n", type);
459 if (filename[0] == '\0')
460 fprintf (stderr, "Could not find plugin %s.\n", type);
466 * The `register_*' functions follow
468 int plugin_register_config (const char *name,
469 int (*callback) (const char *key, const char *val),
470 const char **keys, int keys_num)
472 cf_register (name, callback, keys, keys_num);
474 } /* int plugin_register_config */
476 int plugin_register_complex_config (const char *type,
477 int (*callback) (oconfig_item_t *))
479 return (cf_register_complex (type, callback));
480 } /* int plugin_register_complex_config */
482 int plugin_register_init (const char *name,
483 int (*callback) (void))
485 return (register_callback (&list_init, name, (void *) callback));
486 } /* plugin_register_init */
488 int plugin_register_read (const char *name,
489 int (*callback) (void))
493 rf = (read_func_t *) malloc (sizeof (read_func_t));
497 ERROR ("plugin_register_read: malloc failed: %s",
498 sstrerror (errno, errbuf, sizeof (errbuf)));
502 memset (rf, 0, sizeof (read_func_t));
503 rf->wait_time = interval_g;
505 rf->type = RF_SIMPLE;
506 rf->callback.cb_simple = callback;
507 rf->needs_read = DONE;
508 rf->udata.data = NULL;
509 rf->udata.free_func = NULL;
511 return (register_callback (&list_read, name, (void *) rf));
512 } /* int plugin_register_read */
514 int plugin_register_complex_read (const char *name,
515 plugin_read_cb callback, user_data_t *user_data)
519 rf = (read_func_t *) malloc (sizeof (read_func_t));
522 ERROR ("plugin_register_complex_read: malloc failed.");
526 memset (rf, 0, sizeof (read_func_t));
527 rf->wait_time = interval_g;
529 rf->type = RF_COMPLEX;
530 rf->callback.cb_complex = callback;
531 rf->needs_read = DONE;
534 if (user_data == NULL)
536 rf->udata.data = NULL;
537 rf->udata.free_func = NULL;
541 rf->udata = *user_data;
544 return (register_callback (&list_read, name, (void *) rf));
545 } /* int plugin_register_complex_read */
547 int plugin_register_write (const char *name,
548 plugin_write_cb callback, user_data_t *user_data)
552 wr = (write_func_t *) malloc (sizeof (*wr));
555 ERROR ("plugin_register_write: malloc failed.");
558 memset (wr, 0, sizeof (*wr));
560 wr->callback = callback;
561 if (user_data == NULL)
563 wr->udata.data = NULL;
564 wr->udata.free_func = NULL;
568 wr->udata = *user_data;
571 return (register_callback (&list_write, name, (void *) wr));
572 } /* int plugin_register_write */
574 int plugin_register_flush (const char *name,
575 int (*callback) (const int timeout, const char *identifier))
577 return (register_callback (&list_flush, name, (void *) callback));
578 } /* int plugin_register_flush */
580 int plugin_register_shutdown (char *name,
581 int (*callback) (void))
583 return (register_callback (&list_shutdown, name, (void *) callback));
584 } /* int plugin_register_shutdown */
586 int plugin_register_data_set (const data_set_t *ds)
591 if ((data_sets != NULL)
592 && (c_avl_get (data_sets, ds->type, NULL) == 0))
594 NOTICE ("Replacing DS `%s' with another version.", ds->type);
595 plugin_unregister_data_set (ds->type);
597 else if (data_sets == NULL)
599 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
600 if (data_sets == NULL)
604 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
607 memcpy(ds_copy, ds, sizeof (data_set_t));
609 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
611 if (ds_copy->ds == NULL)
617 for (i = 0; i < ds->ds_num; i++)
618 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
620 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
621 } /* int plugin_register_data_set */
623 int plugin_register_log (char *name,
624 void (*callback) (int priority, const char *msg))
626 return (register_callback (&list_log, name, (void *) callback));
627 } /* int plugin_register_log */
629 int plugin_register_notification (const char *name,
630 int (*callback) (const notification_t *notif))
632 return (register_callback (&list_notification, name, (void *) callback));
633 } /* int plugin_register_log */
635 int plugin_unregister_config (const char *name)
637 cf_unregister (name);
639 } /* int plugin_unregister_config */
641 int plugin_unregister_complex_config (const char *name)
643 cf_unregister_complex (name);
645 } /* int plugin_unregister_complex_config */
647 int plugin_unregister_init (const char *name)
649 return (plugin_unregister (list_init, name));
652 int plugin_unregister_read (const char *name)
657 e = llist_search (list_read, name);
662 llist_remove (list_read, e);
664 rf = (read_func_t *) e->value;
665 plugin_user_data_destroy (&rf->udata);
674 int plugin_unregister_write (const char *name)
679 e = llist_search (list_write, name);
684 llist_remove (list_write, e);
686 wf = (write_func_t *) e->value;
687 plugin_user_data_destroy (&wf->udata);
696 int plugin_unregister_flush (const char *name)
698 return (plugin_unregister (list_flush, name));
701 int plugin_unregister_shutdown (const char *name)
703 return (plugin_unregister (list_shutdown, name));
706 int plugin_unregister_data_set (const char *name)
710 if (data_sets == NULL)
713 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
720 } /* int plugin_unregister_data_set */
722 int plugin_unregister_log (const char *name)
724 return (plugin_unregister (list_log, name));
727 int plugin_unregister_notification (const char *name)
729 return (plugin_unregister (list_notification, name));
732 void plugin_init_all (void)
734 const char *chain_name;
735 int (*callback) (void);
739 /* Init the value cache */
742 chain_name = global_option_get ("PreCacheChain");
743 pre_cache_chain = fc_chain_get_by_name (chain_name);
745 chain_name = global_option_get ("PostCacheChain");
746 post_cache_chain = fc_chain_get_by_name (chain_name);
749 if ((list_init == NULL) && (list_read == NULL))
752 /* Calling all init callbacks before checking if read callbacks
753 * are available allows the init callbacks to register the read
755 le = llist_head (list_init);
758 callback = (int (*) (void)) le->value;
759 status = (*callback) ();
763 ERROR ("Initialization of plugin `%s' "
764 "failed with status %i. "
765 "Plugin will be unloaded.",
767 /* Plugins that register read callbacks from the init
768 * callback should take care of appropriate error
769 * handling themselves. */
770 /* FIXME: Unload _all_ functions */
771 plugin_unregister_read (le->key);
777 /* Start read-threads */
778 if (list_read != NULL)
782 rt = global_option_get ("ReadThreads");
785 start_read_threads ((num > 0) ? num : 5);
787 } /* void plugin_init_all */
789 void plugin_read_all (void)
796 if (list_read == NULL)
799 pthread_mutex_lock (&read_lock);
801 le = llist_head (list_read);
804 rf = (read_func_t *) le->value;
806 if (rf->needs_read != DONE)
812 if (rf->wait_left > 0)
813 rf->wait_left -= interval_g;
815 if (rf->wait_left <= 0)
817 rf->needs_read = TODO;
823 DEBUG ("plugin: plugin_read_all: Signalling `read_cond'");
824 pthread_cond_broadcast (&read_cond);
825 pthread_mutex_unlock (&read_lock);
826 } /* void plugin_read_all */
828 /* Read function called when the `-T' command line argument is given. */
829 int plugin_read_all_once (void)
834 int return_status = 0;
836 if (list_read == NULL)
838 NOTICE ("No read-functions are registered.");
842 for (le = llist_head (list_read);
846 rf = (read_func_t *) le->value;
848 if (rf->type == RF_SIMPLE)
850 status = rf->callback.cb_simple ();
854 assert (rf->type == RF_COMPLEX);
855 status = rf->callback.cb_complex (&rf->udata);
860 NOTICE ("read-function of plugin `%s' failed.",
866 return (return_status);
867 } /* int plugin_read_all_once */
869 int plugin_write (const char *plugin, /* {{{ */
870 const data_set_t *ds, const value_list_t *vl)
878 if (list_write == NULL)
883 ds = plugin_get_ds (vl->type);
886 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
896 le = llist_head (list_write);
899 write_func_t *wf = le->value;
901 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
902 status = wf->callback (ds, vl, &wf->udata);
911 if ((success == 0) && (failure != 0))
916 else /* plugin != NULL */
919 le = llist_head (list_write);
922 if (strcasecmp (plugin, le->key) == 0)
933 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
934 status = wf->callback (ds, vl, &wf->udata);
938 } /* }}} int plugin_write */
940 int plugin_flush (const char *plugin, int timeout, const char *identifier)
942 int (*callback) (int timeout, const char *identifier);
945 if (list_flush == NULL)
948 le = llist_head (list_flush);
952 && (strcmp (plugin, le->key) != 0))
958 callback = (int (*) (int, const char *)) le->value;
959 (*callback) (timeout, identifier);
964 } /* int plugin_flush */
966 void plugin_shutdown_all (void)
968 int (*callback) (void);
971 stop_read_threads ();
972 remove_read_functions ();
974 if (list_shutdown == NULL)
977 le = llist_head (list_shutdown);
980 callback = (int (*) (void)) le->value;
982 /* Advance the pointer before calling the callback allows
983 * shutdown functions to unregister themselves. If done the
984 * other way around the memory `le' points to will be freed
985 * after callback returns. */
990 } /* void plugin_shutdown_all */
992 int plugin_dispatch_values (value_list_t *vl)
995 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
999 if ((vl == NULL) || (*vl->type == '\0')) {
1000 ERROR ("plugin_dispatch_values: Invalid value list.");
1004 if (list_write == NULL)
1005 c_complain_once (LOG_WARNING, &no_write_complaint,
1006 "plugin_dispatch_values: No write callback has been "
1007 "registered. Please load at least one output plugin, "
1008 "if you want the collected data to be stored.");
1010 if (data_sets == NULL)
1012 ERROR ("plugin_dispatch_values: No data sets registered. "
1013 "Could the types database be read? Check "
1014 "your `TypesDB' setting!");
1018 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
1020 INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
1025 vl->time = time (NULL);
1027 DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
1029 "plugin = %s; plugin_instance = %s; "
1030 "type = %s; type_instance = %s;",
1031 (unsigned int) vl->time, vl->interval,
1033 vl->plugin, vl->plugin_instance,
1034 vl->type, vl->type_instance);
1037 assert (0 == strcmp (ds->type, vl->type));
1039 if (0 != strcmp (ds->type, vl->type))
1040 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
1041 ds->type, vl->type);
1045 assert (ds->ds_num == vl->values_len);
1047 if (ds->ds_num != vl->values_len)
1049 ERROR ("plugin_dispatch_values: ds->type = %s: "
1050 "(ds->ds_num = %i) != "
1051 "(vl->values_len = %i)",
1052 ds->type, ds->ds_num, vl->values_len);
1057 escape_slashes (vl->host, sizeof (vl->host));
1058 escape_slashes (vl->plugin, sizeof (vl->plugin));
1059 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1060 escape_slashes (vl->type, sizeof (vl->type));
1061 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1063 if (pre_cache_chain != NULL)
1065 status = fc_process_chain (ds, vl, pre_cache_chain);
1068 WARNING ("plugin_dispatch_values: Running the "
1069 "pre-cache chain failed with "
1073 else if (status == FC_TARGET_STOP)
1077 /* Update the value cache */
1080 if (post_cache_chain != NULL)
1082 status = fc_process_chain (ds, vl, post_cache_chain);
1085 WARNING ("plugin_dispatch_values: Running the "
1086 "post-cache chain failed with "
1092 fc_default_action (ds, vl);
1095 } /* int plugin_dispatch_values */
1097 int plugin_dispatch_notification (const notification_t *notif)
1099 int (*callback) (const notification_t *);
1101 /* Possible TODO: Add flap detection here */
1103 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1104 "time = %u; host = %s;",
1105 notif->severity, notif->message,
1106 (unsigned int) notif->time, notif->host);
1108 /* Nobody cares for notifications */
1109 if (list_notification == NULL)
1112 le = llist_head (list_notification);
1115 callback = (int (*) (const notification_t *)) le->value;
1116 (*callback) (notif);
1122 } /* int plugin_dispatch_notification */
1124 void plugin_log (int level, const char *format, ...)
1129 void (*callback) (int, const char *);
1132 if (list_log == NULL)
1136 if (level >= LOG_DEBUG)
1140 va_start (ap, format);
1141 vsnprintf (msg, sizeof (msg), format, ap);
1142 msg[sizeof (msg) - 1] = '\0';
1145 le = llist_head (list_log);
1148 callback = (void (*) (int, const char *)) le->value;
1149 (*callback) (level, msg);
1153 } /* void plugin_log */
1155 const data_set_t *plugin_get_ds (const char *name)
1159 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1161 DEBUG ("No such dataset registered: %s", name);
1166 } /* data_set_t *plugin_get_ds */
1168 static int plugin_notification_meta_add (notification_t *n,
1170 enum notification_meta_type_e type,
1173 notification_meta_t *meta;
1174 notification_meta_t *tail;
1176 if ((n == NULL) || (name == NULL) || (value == NULL))
1178 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1182 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1185 ERROR ("plugin_notification_meta_add: malloc failed.");
1188 memset (meta, 0, sizeof (notification_meta_t));
1190 sstrncpy (meta->name, name, sizeof (meta->name));
1195 case NM_TYPE_STRING:
1197 meta->nm_value.nm_string = strdup ((const char *) value);
1198 if (meta->nm_value.nm_string == NULL)
1200 ERROR ("plugin_notification_meta_add: strdup failed.");
1206 case NM_TYPE_SIGNED_INT:
1208 meta->nm_value.nm_signed_int = *((int64_t *) value);
1211 case NM_TYPE_UNSIGNED_INT:
1213 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1216 case NM_TYPE_DOUBLE:
1218 meta->nm_value.nm_double = *((double *) value);
1221 case NM_TYPE_BOOLEAN:
1223 meta->nm_value.nm_boolean = *((bool *) value);
1228 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1232 } /* switch (type) */
1236 while ((tail != NULL) && (tail->next != NULL))
1245 } /* int plugin_notification_meta_add */
1247 int plugin_notification_meta_add_string (notification_t *n,
1251 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1254 int plugin_notification_meta_add_signed_int (notification_t *n,
1258 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1261 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1265 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1268 int plugin_notification_meta_add_double (notification_t *n,
1272 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1275 int plugin_notification_meta_add_boolean (notification_t *n,
1279 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1282 int plugin_notification_meta_copy (notification_t *dst,
1283 const notification_t *src)
1285 notification_meta_t *meta;
1287 assert (dst != NULL);
1288 assert (src != NULL);
1289 assert (dst != src);
1290 assert ((src->meta == NULL) || (src->meta != dst->meta));
1292 for (meta = src->meta; meta != NULL; meta = meta->next)
1294 if (meta->type == NM_TYPE_STRING)
1295 plugin_notification_meta_add_string (dst, meta->name,
1296 meta->nm_value.nm_string);
1297 else if (meta->type == NM_TYPE_SIGNED_INT)
1298 plugin_notification_meta_add_signed_int (dst, meta->name,
1299 meta->nm_value.nm_signed_int);
1300 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1301 plugin_notification_meta_add_unsigned_int (dst, meta->name,
1302 meta->nm_value.nm_unsigned_int);
1303 else if (meta->type == NM_TYPE_DOUBLE)
1304 plugin_notification_meta_add_double (dst, meta->name,
1305 meta->nm_value.nm_double);
1306 else if (meta->type == NM_TYPE_BOOLEAN)
1307 plugin_notification_meta_add_boolean (dst, meta->name,
1308 meta->nm_value.nm_boolean);
1312 } /* int plugin_notification_meta_copy */
1314 int plugin_notification_meta_free (notification_meta_t *n)
1316 notification_meta_t *this;
1317 notification_meta_t *next;
1321 ERROR ("plugin_notification_meta_free: n == NULL!");
1326 while (this != NULL)
1330 if (this->type == NM_TYPE_STRING)
1332 free ((char *)this->nm_value.nm_string);
1333 this->nm_value.nm_string = NULL;
1341 } /* int plugin_notification_meta_free */