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;
70 plugin_flush_cb callback;
73 typedef struct flush_func_s flush_func_t;
78 static llist_t *list_init;
79 static llist_t *list_read;
80 static llist_t *list_write;
81 static llist_t *list_flush;
82 static llist_t *list_shutdown;
83 static llist_t *list_log;
84 static llist_t *list_notification;
86 static fc_chain_t *pre_cache_chain = NULL;
87 static fc_chain_t *post_cache_chain = NULL;
89 static c_avl_tree_t *data_sets;
91 static char *plugindir = NULL;
93 static int read_loop = 1;
94 static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
95 static pthread_cond_t read_cond = PTHREAD_COND_INITIALIZER;
96 static pthread_t *read_threads = NULL;
97 static int read_threads_num = 0;
102 static const char *plugin_get_dir (void)
104 if (plugindir == NULL)
110 static int register_callback (llist_t **list, const char *name, void *callback)
116 && ((*list = llist_create ()) == NULL))
119 le = llist_search (*list, name);
126 le = llentry_create (key, callback);
133 llist_append (*list, le);
137 le->value = callback;
141 } /* int register_callback */
143 static void plugin_user_data_destroy (user_data_t *ud)
145 if ((ud != NULL) && (ud->data != NULL) && (ud->free_func != NULL))
147 ud->free_func (ud->data);
149 ud->free_func = NULL;
151 } /* void plugin_user_data_destroy */
153 static int plugin_unregister (llist_t *list, const char *name)
157 e = llist_search (list, name);
162 llist_remove (list, e);
167 } /* int plugin_unregister */
170 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
171 * object, but it will bitch about a shared object not having a
172 * ``module_register'' symbol..
174 static int plugin_load_file (char *file)
177 void (*reg_handle) (void);
179 DEBUG ("file = %s", file);
182 lt_dlerror (); /* clear errors */
184 if ((dlh = lt_dlopen (file)) == NULL)
186 const char *error = lt_dlerror ();
188 ERROR ("lt_dlopen (%s) failed: %s", file, error);
189 fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
193 if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
195 WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
196 file, lt_dlerror ());
206 static void *plugin_read_thread (void __attribute__((unused)) *args)
213 pthread_mutex_lock (&read_lock);
215 while (read_loop != 0)
217 le = llist_head (list_read);
220 while ((read_loop != 0) && (le != NULL))
222 rf = (read_func_t *) le->value;
224 if (rf->needs_read != TODO)
230 /* We will do this read function */
231 rf->needs_read = ACTIVE;
233 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Handling %s",
234 (unsigned long int) pthread_self (), le->key);
235 pthread_mutex_unlock (&read_lock);
237 if (rf->type == RF_SIMPLE)
239 status = rf->callback.cb_simple ();
243 assert (rf->type == RF_COMPLEX);
244 status = rf->callback.cb_complex (&rf->udata);
250 if (rf->wait_time < interval_g)
251 rf->wait_time = interval_g;
252 rf->wait_left = rf->wait_time;
253 rf->wait_time = rf->wait_time * 2;
254 if (rf->wait_time > 86400)
255 rf->wait_time = 86400;
257 NOTICE ("read-function of plugin `%s' "
258 "failed. Will suspend it for %i "
259 "seconds.", le->key, rf->wait_left);
264 rf->wait_time = interval_g;
267 pthread_mutex_lock (&read_lock);
269 rf->needs_read = DONE;
271 } /* while (le != NULL) */
273 if ((read_loop != 0) && (done == 0))
275 DEBUG ("[thread #%5lu] plugin: plugin_read_thread: Waiting on read_cond.",
276 (unsigned long int) pthread_self ());
277 pthread_cond_wait (&read_cond, &read_lock);
279 } /* while (read_loop) */
281 pthread_mutex_unlock (&read_lock);
285 } /* void *plugin_read_thread */
287 static void start_read_threads (int num)
291 if (read_threads != NULL)
294 read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
295 if (read_threads == NULL)
297 ERROR ("plugin: start_read_threads: calloc failed.");
301 read_threads_num = 0;
302 for (i = 0; i < num; i++)
304 if (pthread_create (read_threads + read_threads_num, NULL,
305 plugin_read_thread, NULL) == 0)
311 ERROR ("plugin: start_read_threads: pthread_create failed.");
315 } /* void start_read_threads */
317 static void stop_read_threads (void)
321 if (read_threads == NULL)
324 pthread_mutex_lock (&read_lock);
326 DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
327 pthread_cond_broadcast (&read_cond);
328 pthread_mutex_unlock (&read_lock);
330 for (i = 0; i < read_threads_num; i++)
332 if (pthread_join (read_threads[i], NULL) != 0)
334 ERROR ("plugin: stop_read_threads: pthread_join failed.");
336 read_threads[i] = (pthread_t) 0;
338 sfree (read_threads);
339 read_threads_num = 0;
340 } /* void stop_read_threads */
342 static int remove_read_functions (void)
346 if (list_read == NULL)
349 this = llist_head (list_read);
356 rf = (read_func_t *) this->value;
360 plugin_user_data_destroy (&rf->udata);
366 llist_destroy (list_read);
370 } /* }}} int remove_read_functions */
375 void plugin_set_dir (const char *dir)
377 if (plugindir != NULL)
382 else if ((plugindir = strdup (dir)) == NULL)
385 ERROR ("strdup failed: %s",
386 sstrerror (errno, errbuf, sizeof (errbuf)));
391 int plugin_load (const char *type)
395 char filename[BUFSIZE] = "";
396 char typename[BUFSIZE];
403 DEBUG ("type = %s", type);
405 dir = plugin_get_dir ();
408 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
409 * type when matching the filename */
410 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
411 if ((status < 0) || ((size_t) status >= sizeof (typename)))
413 WARNING ("snprintf: truncated: `%s.so'", type);
416 typename_len = strlen (typename);
418 if ((dh = opendir (dir)) == NULL)
421 ERROR ("opendir (%s): %s", dir,
422 sstrerror (errno, errbuf, sizeof (errbuf)));
426 while ((de = readdir (dh)) != NULL)
428 if (strncasecmp (de->d_name, typename, typename_len))
431 status = ssnprintf (filename, sizeof (filename),
432 "%s/%s", dir, de->d_name);
433 if ((status < 0) || ((size_t) status >= sizeof (filename)))
435 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
439 if (lstat (filename, &statbuf) == -1)
442 WARNING ("stat %s: %s", filename,
443 sstrerror (errno, errbuf, sizeof (errbuf)));
446 else if (!S_ISREG (statbuf.st_mode))
448 /* don't follow symlinks */
452 if (plugin_load_file (filename) == 0)
460 fprintf (stderr, "Unable to load plugin %s.\n", type);
466 if (filename[0] == '\0')
467 fprintf (stderr, "Could not find plugin %s.\n", type);
473 * The `register_*' functions follow
475 int plugin_register_config (const char *name,
476 int (*callback) (const char *key, const char *val),
477 const char **keys, int keys_num)
479 cf_register (name, callback, keys, keys_num);
481 } /* int plugin_register_config */
483 int plugin_register_complex_config (const char *type,
484 int (*callback) (oconfig_item_t *))
486 return (cf_register_complex (type, callback));
487 } /* int plugin_register_complex_config */
489 int plugin_register_init (const char *name,
490 int (*callback) (void))
492 return (register_callback (&list_init, name, (void *) callback));
493 } /* plugin_register_init */
495 int plugin_register_read (const char *name,
496 int (*callback) (void))
500 rf = (read_func_t *) malloc (sizeof (read_func_t));
504 ERROR ("plugin_register_read: malloc failed: %s",
505 sstrerror (errno, errbuf, sizeof (errbuf)));
509 memset (rf, 0, sizeof (read_func_t));
510 rf->wait_time = interval_g;
512 rf->type = RF_SIMPLE;
513 rf->callback.cb_simple = callback;
514 rf->needs_read = DONE;
515 rf->udata.data = NULL;
516 rf->udata.free_func = NULL;
518 return (register_callback (&list_read, name, (void *) rf));
519 } /* int plugin_register_read */
521 int plugin_register_complex_read (const char *name,
522 plugin_read_cb callback, user_data_t *user_data)
526 rf = (read_func_t *) malloc (sizeof (read_func_t));
529 ERROR ("plugin_register_complex_read: malloc failed.");
533 memset (rf, 0, sizeof (read_func_t));
534 rf->wait_time = interval_g;
536 rf->type = RF_COMPLEX;
537 rf->callback.cb_complex = callback;
538 rf->needs_read = DONE;
541 if (user_data == NULL)
543 rf->udata.data = NULL;
544 rf->udata.free_func = NULL;
548 rf->udata = *user_data;
551 return (register_callback (&list_read, name, (void *) rf));
552 } /* int plugin_register_complex_read */
554 int plugin_register_write (const char *name,
555 plugin_write_cb callback, user_data_t *user_data)
559 wf = (write_func_t *) malloc (sizeof (*wf));
562 ERROR ("plugin_register_write: malloc failed.");
565 memset (wf, 0, sizeof (*wf));
567 wf->callback = callback;
568 if (user_data == NULL)
570 wf->udata.data = NULL;
571 wf->udata.free_func = NULL;
575 wf->udata = *user_data;
578 return (register_callback (&list_write, name, (void *) wf));
579 } /* int plugin_register_write */
581 int plugin_register_flush (const char *name,
582 plugin_flush_cb callback, user_data_t *user_data)
586 ff = (flush_func_t *) malloc (sizeof (*ff));
589 ERROR ("plugin_register_flush: malloc failed.");
592 memset (ff, 0, sizeof (*ff));
594 ff->callback = callback;
595 if (user_data == NULL)
597 ff->udata.data = NULL;
598 ff->udata.free_func = NULL;
602 ff->udata = *user_data;
605 return (register_callback (&list_flush, name, (void *) ff));
606 } /* int plugin_register_flush */
608 int plugin_register_shutdown (char *name,
609 int (*callback) (void))
611 return (register_callback (&list_shutdown, name, (void *) callback));
612 } /* int plugin_register_shutdown */
614 int plugin_register_data_set (const data_set_t *ds)
619 if ((data_sets != NULL)
620 && (c_avl_get (data_sets, ds->type, NULL) == 0))
622 NOTICE ("Replacing DS `%s' with another version.", ds->type);
623 plugin_unregister_data_set (ds->type);
625 else if (data_sets == NULL)
627 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
628 if (data_sets == NULL)
632 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
635 memcpy(ds_copy, ds, sizeof (data_set_t));
637 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
639 if (ds_copy->ds == NULL)
645 for (i = 0; i < ds->ds_num; i++)
646 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
648 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
649 } /* int plugin_register_data_set */
651 int plugin_register_log (char *name,
652 void (*callback) (int priority, const char *msg))
654 return (register_callback (&list_log, name, (void *) callback));
655 } /* int plugin_register_log */
657 int plugin_register_notification (const char *name,
658 int (*callback) (const notification_t *notif))
660 return (register_callback (&list_notification, name, (void *) callback));
661 } /* int plugin_register_log */
663 int plugin_unregister_config (const char *name)
665 cf_unregister (name);
667 } /* int plugin_unregister_config */
669 int plugin_unregister_complex_config (const char *name)
671 cf_unregister_complex (name);
673 } /* int plugin_unregister_complex_config */
675 int plugin_unregister_init (const char *name)
677 return (plugin_unregister (list_init, name));
680 int plugin_unregister_read (const char *name)
685 e = llist_search (list_read, name);
690 llist_remove (list_read, e);
692 rf = (read_func_t *) e->value;
693 plugin_user_data_destroy (&rf->udata);
702 int plugin_unregister_write (const char *name)
707 e = llist_search (list_write, name);
712 llist_remove (list_write, e);
714 wf = (write_func_t *) e->value;
715 plugin_user_data_destroy (&wf->udata);
724 int plugin_unregister_flush (const char *name)
729 e = llist_search (list_flush, name);
734 llist_remove (list_flush, e);
736 ff = (flush_func_t *) e->value;
737 plugin_user_data_destroy (&ff->udata);
746 int plugin_unregister_shutdown (const char *name)
748 return (plugin_unregister (list_shutdown, name));
751 int plugin_unregister_data_set (const char *name)
755 if (data_sets == NULL)
758 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
765 } /* int plugin_unregister_data_set */
767 int plugin_unregister_log (const char *name)
769 return (plugin_unregister (list_log, name));
772 int plugin_unregister_notification (const char *name)
774 return (plugin_unregister (list_notification, name));
777 void plugin_init_all (void)
779 const char *chain_name;
780 int (*callback) (void);
784 /* Init the value cache */
787 chain_name = global_option_get ("PreCacheChain");
788 pre_cache_chain = fc_chain_get_by_name (chain_name);
790 chain_name = global_option_get ("PostCacheChain");
791 post_cache_chain = fc_chain_get_by_name (chain_name);
794 if ((list_init == NULL) && (list_read == NULL))
797 /* Calling all init callbacks before checking if read callbacks
798 * are available allows the init callbacks to register the read
800 le = llist_head (list_init);
803 callback = (int (*) (void)) le->value;
804 status = (*callback) ();
808 ERROR ("Initialization of plugin `%s' "
809 "failed with status %i. "
810 "Plugin will be unloaded.",
812 /* Plugins that register read callbacks from the init
813 * callback should take care of appropriate error
814 * handling themselves. */
815 /* FIXME: Unload _all_ functions */
816 plugin_unregister_read (le->key);
822 /* Start read-threads */
823 if (list_read != NULL)
827 rt = global_option_get ("ReadThreads");
830 start_read_threads ((num > 0) ? num : 5);
832 } /* void plugin_init_all */
834 void plugin_read_all (void)
841 if (list_read == NULL)
844 pthread_mutex_lock (&read_lock);
846 le = llist_head (list_read);
849 rf = (read_func_t *) le->value;
851 if (rf->needs_read != DONE)
857 if (rf->wait_left > 0)
858 rf->wait_left -= interval_g;
860 if (rf->wait_left <= 0)
862 rf->needs_read = TODO;
868 DEBUG ("plugin: plugin_read_all: Signalling `read_cond'");
869 pthread_cond_broadcast (&read_cond);
870 pthread_mutex_unlock (&read_lock);
871 } /* void plugin_read_all */
873 /* Read function called when the `-T' command line argument is given. */
874 int plugin_read_all_once (void)
879 int return_status = 0;
881 if (list_read == NULL)
883 NOTICE ("No read-functions are registered.");
887 for (le = llist_head (list_read);
891 rf = (read_func_t *) le->value;
893 if (rf->type == RF_SIMPLE)
895 status = rf->callback.cb_simple ();
899 assert (rf->type == RF_COMPLEX);
900 status = rf->callback.cb_complex (&rf->udata);
905 NOTICE ("read-function of plugin `%s' failed.",
911 return (return_status);
912 } /* int plugin_read_all_once */
914 int plugin_write (const char *plugin, /* {{{ */
915 const data_set_t *ds, const value_list_t *vl)
923 if (list_write == NULL)
928 ds = plugin_get_ds (vl->type);
931 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
941 le = llist_head (list_write);
944 write_func_t *wf = le->value;
946 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
947 status = wf->callback (ds, vl, &wf->udata);
956 if ((success == 0) && (failure != 0))
961 else /* plugin != NULL */
964 le = llist_head (list_write);
967 if (strcasecmp (plugin, le->key) == 0)
978 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
979 status = wf->callback (ds, vl, &wf->udata);
983 } /* }}} int plugin_write */
985 int plugin_flush (const char *plugin, int timeout, const char *identifier)
989 if (list_flush == NULL)
992 le = llist_head (list_flush);
998 && (strcmp (plugin, le->key) != 0))
1004 ff = (flush_func_t *) le->value;
1006 ff->callback (timeout, identifier, &ff->udata);
1011 } /* int plugin_flush */
1013 void plugin_shutdown_all (void)
1015 int (*callback) (void);
1018 stop_read_threads ();
1019 remove_read_functions ();
1021 if (list_shutdown == NULL)
1024 le = llist_head (list_shutdown);
1027 callback = (int (*) (void)) le->value;
1029 /* Advance the pointer before calling the callback allows
1030 * shutdown functions to unregister themselves. If done the
1031 * other way around the memory `le' points to will be freed
1032 * after callback returns. */
1037 } /* void plugin_shutdown_all */
1039 int plugin_dispatch_values (value_list_t *vl)
1042 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
1046 if ((vl == NULL) || (*vl->type == '\0')) {
1047 ERROR ("plugin_dispatch_values: Invalid value list.");
1051 if (list_write == NULL)
1052 c_complain_once (LOG_WARNING, &no_write_complaint,
1053 "plugin_dispatch_values: No write callback has been "
1054 "registered. Please load at least one output plugin, "
1055 "if you want the collected data to be stored.");
1057 if (data_sets == NULL)
1059 ERROR ("plugin_dispatch_values: No data sets registered. "
1060 "Could the types database be read? Check "
1061 "your `TypesDB' setting!");
1065 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
1067 INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
1072 vl->time = time (NULL);
1074 DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
1076 "plugin = %s; plugin_instance = %s; "
1077 "type = %s; type_instance = %s;",
1078 (unsigned int) vl->time, vl->interval,
1080 vl->plugin, vl->plugin_instance,
1081 vl->type, vl->type_instance);
1084 assert (0 == strcmp (ds->type, vl->type));
1086 if (0 != strcmp (ds->type, vl->type))
1087 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
1088 ds->type, vl->type);
1092 assert (ds->ds_num == vl->values_len);
1094 if (ds->ds_num != vl->values_len)
1096 ERROR ("plugin_dispatch_values: ds->type = %s: "
1097 "(ds->ds_num = %i) != "
1098 "(vl->values_len = %i)",
1099 ds->type, ds->ds_num, vl->values_len);
1104 escape_slashes (vl->host, sizeof (vl->host));
1105 escape_slashes (vl->plugin, sizeof (vl->plugin));
1106 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1107 escape_slashes (vl->type, sizeof (vl->type));
1108 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1110 if (pre_cache_chain != NULL)
1112 status = fc_process_chain (ds, vl, pre_cache_chain);
1115 WARNING ("plugin_dispatch_values: Running the "
1116 "pre-cache chain failed with "
1120 else if (status == FC_TARGET_STOP)
1124 /* Update the value cache */
1127 if (post_cache_chain != NULL)
1129 status = fc_process_chain (ds, vl, post_cache_chain);
1132 WARNING ("plugin_dispatch_values: Running the "
1133 "post-cache chain failed with "
1139 fc_default_action (ds, vl);
1142 } /* int plugin_dispatch_values */
1144 int plugin_dispatch_notification (const notification_t *notif)
1146 int (*callback) (const notification_t *);
1148 /* Possible TODO: Add flap detection here */
1150 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1151 "time = %u; host = %s;",
1152 notif->severity, notif->message,
1153 (unsigned int) notif->time, notif->host);
1155 /* Nobody cares for notifications */
1156 if (list_notification == NULL)
1159 le = llist_head (list_notification);
1162 callback = (int (*) (const notification_t *)) le->value;
1163 (*callback) (notif);
1169 } /* int plugin_dispatch_notification */
1171 void plugin_log (int level, const char *format, ...)
1176 void (*callback) (int, const char *);
1179 if (list_log == NULL)
1183 if (level >= LOG_DEBUG)
1187 va_start (ap, format);
1188 vsnprintf (msg, sizeof (msg), format, ap);
1189 msg[sizeof (msg) - 1] = '\0';
1192 le = llist_head (list_log);
1195 callback = (void (*) (int, const char *)) le->value;
1196 (*callback) (level, msg);
1200 } /* void plugin_log */
1202 const data_set_t *plugin_get_ds (const char *name)
1206 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1208 DEBUG ("No such dataset registered: %s", name);
1213 } /* data_set_t *plugin_get_ds */
1215 static int plugin_notification_meta_add (notification_t *n,
1217 enum notification_meta_type_e type,
1220 notification_meta_t *meta;
1221 notification_meta_t *tail;
1223 if ((n == NULL) || (name == NULL) || (value == NULL))
1225 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1229 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1232 ERROR ("plugin_notification_meta_add: malloc failed.");
1235 memset (meta, 0, sizeof (notification_meta_t));
1237 sstrncpy (meta->name, name, sizeof (meta->name));
1242 case NM_TYPE_STRING:
1244 meta->nm_value.nm_string = strdup ((const char *) value);
1245 if (meta->nm_value.nm_string == NULL)
1247 ERROR ("plugin_notification_meta_add: strdup failed.");
1253 case NM_TYPE_SIGNED_INT:
1255 meta->nm_value.nm_signed_int = *((int64_t *) value);
1258 case NM_TYPE_UNSIGNED_INT:
1260 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1263 case NM_TYPE_DOUBLE:
1265 meta->nm_value.nm_double = *((double *) value);
1268 case NM_TYPE_BOOLEAN:
1270 meta->nm_value.nm_boolean = *((bool *) value);
1275 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1279 } /* switch (type) */
1283 while ((tail != NULL) && (tail->next != NULL))
1292 } /* int plugin_notification_meta_add */
1294 int plugin_notification_meta_add_string (notification_t *n,
1298 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1301 int plugin_notification_meta_add_signed_int (notification_t *n,
1305 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1308 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1312 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1315 int plugin_notification_meta_add_double (notification_t *n,
1319 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1322 int plugin_notification_meta_add_boolean (notification_t *n,
1326 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1329 int plugin_notification_meta_copy (notification_t *dst,
1330 const notification_t *src)
1332 notification_meta_t *meta;
1334 assert (dst != NULL);
1335 assert (src != NULL);
1336 assert (dst != src);
1337 assert ((src->meta == NULL) || (src->meta != dst->meta));
1339 for (meta = src->meta; meta != NULL; meta = meta->next)
1341 if (meta->type == NM_TYPE_STRING)
1342 plugin_notification_meta_add_string (dst, meta->name,
1343 meta->nm_value.nm_string);
1344 else if (meta->type == NM_TYPE_SIGNED_INT)
1345 plugin_notification_meta_add_signed_int (dst, meta->name,
1346 meta->nm_value.nm_signed_int);
1347 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1348 plugin_notification_meta_add_unsigned_int (dst, meta->name,
1349 meta->nm_value.nm_unsigned_int);
1350 else if (meta->type == NM_TYPE_DOUBLE)
1351 plugin_notification_meta_add_double (dst, meta->name,
1352 meta->nm_value.nm_double);
1353 else if (meta->type == NM_TYPE_BOOLEAN)
1354 plugin_notification_meta_add_boolean (dst, meta->name,
1355 meta->nm_value.nm_boolean);
1359 } /* int plugin_notification_meta_copy */
1361 int plugin_notification_meta_free (notification_meta_t *n)
1363 notification_meta_t *this;
1364 notification_meta_t *next;
1368 ERROR ("plugin_notification_meta_free: n == NULL!");
1373 while (this != NULL)
1377 if (this->type == NM_TYPE_STRING)
1379 free ((char *)this->nm_value.nm_string);
1380 this->nm_value.nm_string = NULL;
1388 } /* int plugin_notification_meta_free */